@Override public ActionResponseDTO<Classpage> createClasspage( Classpage newClasspage, CollectionItem newCollectionItem, String gooruOid, User user) throws Exception { Errors errors = validateClasspage(newClasspage); if (!errors.hasErrors()) { this.getCollectionRepository().save(newClasspage); this.getUserGroupService() .createGroup( newClasspage.getTitle(), newClasspage.getClasspageCode(), "System", user, null); if (gooruOid != null && !gooruOid.isEmpty() && newCollectionItem != null) { CollectionItem collectionItem = new CollectionItem(); collectionItem.setItemType(ShelfType.AddedType.ADDED.getAddedType()); collectionItem.setPlannedEndDate(newCollectionItem.getPlannedEndDate()); collectionItem.setNarration(newCollectionItem.getNarration()); collectionItem = this.createCollectionItem( gooruOid, newClasspage.getGooruOid(), collectionItem, newClasspage.getUser(), CollectionType.COLLECTION.getCollectionType(), false) .getModel(); Set<CollectionItem> collectionItems = new TreeSet<CollectionItem>(); collectionItems.add(collectionItem); newClasspage.setCollectionItems(collectionItems); this.getCollectionRepository().save(newClasspage); } } return new ActionResponseDTO<Classpage>(newClasspage, errors); }
private Errors validateClasspage(Classpage classpage) throws Exception { final Errors errors = new BindException(classpage, CLASSPAGE); if (classpage != null) { rejectIfNullOrEmpty( errors, classpage.getTitle(), TITLE, GL0006, generateErrorMessage(GL0006, TITLE)); } return errors; }
@Override public List<Map<String, String>> inviteUserForClass( List<String> emails, String classCode, User apiCaller) { Classpage classPage = this.getCollectionRepository().getClasspageByCode(classCode); if (classPage == null) { throw new NotFoundException(generateErrorMessage(GL0006, CLASS)); } List<Map<String, String>> invites = new ArrayList<Map<String, String>>(); List<InviteUser> inviteUsers = null; for (String email : emails) { InviteUser inviteUser = this.getInviteRepository().findInviteUserById(email, classPage.getGooruOid(), null); inviteUsers = new ArrayList<InviteUser>(); if (inviteUser == null) { inviteUsers.add(createInviteUserObj(email, classPage.getGooruOid(), CLASS, apiCaller)); } Map<String, String> inviteMap = new HashMap<String, String>(); inviteMap.put(EMAIL_ID, email); inviteMap.put(GOORU_OID, classPage.getGooruOid()); inviteMap.put(STATUS, PENDING); invites.add(inviteMap); Profile profile = this.getUserRepository().getProfile(classPage.getUser(), false); String gender = ""; String noun = ""; if (profile.getGender() != null) { if (profile.getGender().getName().equalsIgnoreCase(FEMALE)) { gender = MS; noun = HER; } else if (profile.getGender().getName().equalsIgnoreCase(MALE)) { gender = MR; noun = HIS; } } this.getMailHandler() .sendMailToInviteUser(inviteMap, classPage.getUser(), classPage.getTitle(), gender, noun); } if (inviteUsers != null) { this.getInviteRepository().saveAll(inviteUsers); } return invites; }
public ActionResponseDTO<Classpage> updateClasspage( Classpage newClasspage, String updateClasspageId, Boolean hasUnrestrictedContentAccess) throws Exception { Classpage classpage = this.getClasspage(updateClasspageId, null, null); Errors errors = validateUpdateClasspage(classpage, newClasspage); if (!errors.hasErrors()) { if (newClasspage.getVocabulary() != null) { classpage.setVocabulary(newClasspage.getVocabulary()); } if (newClasspage.getTitle() != null) { classpage.setTitle(newClasspage.getTitle()); UserGroup userGroup = this.getUserGroupService().findUserGroupByGroupCode(classpage.getClasspageCode()); userGroup.setGroupName(newClasspage.getTitle()); this.getUserRepository().save(userGroup); } if (newClasspage.getDescription() != null) { classpage.setDescription(newClasspage.getDescription()); } if (newClasspage.getNarrationLink() != null) { classpage.setNarrationLink(newClasspage.getNarrationLink()); } if (newClasspage.getEstimatedTime() != null) { classpage.setEstimatedTime(newClasspage.getEstimatedTime()); } if (newClasspage.getNotes() != null) { classpage.setNotes(newClasspage.getNotes()); } if (newClasspage.getGoals() != null) { classpage.setGoals(newClasspage.getGoals()); } if (newClasspage.getKeyPoints() != null) { classpage.setGoals(newClasspage.getKeyPoints()); } if (newClasspage.getLanguage() != null) { classpage.setLanguage(newClasspage.getLanguage()); } if (newClasspage.getGrade() != null) { classpage.setGrade(newClasspage.getGrade()); } if (newClasspage.getSharing() != null) { if (newClasspage.getSharing().equalsIgnoreCase(Sharing.PRIVATE.getSharing()) || newClasspage.getSharing().equalsIgnoreCase(Sharing.PUBLIC.getSharing()) || newClasspage.getSharing().equalsIgnoreCase(Sharing.ANYONEWITHLINK.getSharing())) { classpage.setSharing(newClasspage.getSharing()); } } if (newClasspage.getLastUpdatedUserUid() != null) { classpage.setLastUpdatedUserUid(newClasspage.getLastUpdatedUserUid()); } if (hasUnrestrictedContentAccess) { if (newClasspage.getCreator() != null && newClasspage.getCreator().getPartyUid() != null) { User user = userService.findByGooruId(newClasspage.getCreator().getPartyUid()); classpage.setCreator(user); } if (newClasspage.getUser() != null && newClasspage.getUser().getPartyUid() != null) { User user = userService.findByGooruId(newClasspage.getUser().getPartyUid()); classpage.setUser(user); } } this.getCollectionRepository().save(classpage); } return new ActionResponseDTO<Classpage>(classpage, errors); }