private CollectionItem createCollection( User user, Collection collection, Collection parentCollection) { CollectionItem collectionItem = createCollection(collection, parentCollection, user); if (collection.getSharing() != null && !collection .getCollectionType() .equalsIgnoreCase(ResourceType.Type.ASSESSMENT_URL.getType()) && collection.getSharing().equalsIgnoreCase(PUBLIC)) { collection.setSharing(Sharing.ANYONEWITHLINK.getSharing()); } if (collection.getSharing() != null && !collection .getCollectionType() .equalsIgnoreCase(ResourceType.Type.ASSESSMENT_URL.getType()) && collection.getSharing().equalsIgnoreCase(PUBLIC)) { collection.setPublishStatusId(Constants.PUBLISH_PENDING_STATUS_ID); collection.setSharing(Sharing.ANYONEWITHLINK.getSharing()); } createCollectionSettings(collection); if (!collection .getCollectionType() .equalsIgnoreCase(ResourceType.Type.ASSESSMENT_URL.getType())) { getIndexHandler() .setReIndexRequest( collection.getGooruOid(), IndexProcessor.INDEX, SCOLLECTION, null, false, false); } return collectionItem; }
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); }
@Override @Transactional( readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void updateCollection( String parentId, String collectionId, Collection newCollection, User user) { boolean hasUnrestrictedContentAccess = this.getOperationAuthorizer().hasUnrestrictedContentAccess(collectionId, user); // TO-Do add validation for collection type and collaborator validation Collection collection = getCollectionDao().getCollection(collectionId); if (newCollection.getSharing() != null && (newCollection.getSharing().equalsIgnoreCase(Sharing.PRIVATE.getSharing()) || newCollection.getSharing().equalsIgnoreCase(Sharing.PUBLIC.getSharing()) || newCollection.getSharing().equalsIgnoreCase(Sharing.ANYONEWITHLINK.getSharing()))) { if (!newCollection.getSharing().equalsIgnoreCase(PUBLIC)) { collection.setPublishStatusId(null); } if (!collection .getCollectionType() .equalsIgnoreCase(ResourceType.Type.ASSESSMENT_URL.getType()) && newCollection.getSharing().equalsIgnoreCase(PUBLIC) && !userService.isContentAdmin(user)) { collection.setPublishStatusId(Constants.PUBLISH_PENDING_STATUS_ID); newCollection.setSharing(collection.getSharing()); } if (collection .getCollectionType() .equalsIgnoreCase(ResourceType.Type.ASSESSMENT_URL.getType()) || newCollection.getSharing().equalsIgnoreCase(PUBLIC) && userService.isContentAdmin(user)) { collection.setPublishStatusId(Constants.PUBLISH_REVIEWED_STATUS_ID); } collection.setSharing(newCollection.getSharing()); } if (newCollection.getSettings() != null) { updateCollectionSettings(collection, newCollection); } if (newCollection.getLanguageObjective() != null) { collection.setLanguageObjective(newCollection.getLanguageObjective()); } if (hasUnrestrictedContentAccess) { if (newCollection.getCreator() != null && newCollection.getCreator().getPartyUid() != null) { User creatorUser = getUserService().findByGooruId(newCollection.getCreator().getPartyUid()); collection.setCreator(creatorUser); } if (newCollection.getUser() != null && newCollection.getUser().getPartyUid() != null) { User ownerUser = getUserService().findByGooruId(newCollection.getUser().getPartyUid()); collection.setUser(ownerUser); } if (newCollection.getNetwork() != null) { collection.setNetwork(newCollection.getNetwork()); } } if (newCollection.getPosition() != null) { CollectionItem parentCollectionItem = this.getCollectionDao().getCollectionItemById(collectionId, user); if (parentId == null) { parentId = parentCollectionItem.getCollection().getGooruOid(); } Collection parentCollection = getCollectionDao().getCollectionByUser(parentId, user.getPartyUid()); this.resetSequence( parentCollection, parentCollectionItem.getCollectionItemId(), newCollection.getPosition(), user.getPartyUid(), COLLECTION); } if (newCollection.getMediaFilename() != null) { String folderPath = Collection.buildResourceFolder(collection.getContentId()); this.getGooruImageUtil() .imageUpload(newCollection.getMediaFilename(), folderPath, COLLECTION_IMAGE_DIMENSION); StringBuilder basePath = new StringBuilder(folderPath); basePath.append(File.separator).append(newCollection.getMediaFilename()); collection.setImagePath(basePath.toString()); } updateCollection(collection, newCollection, user); Map<String, Object> data = generateCollectionMetaData(collection, newCollection, user); if (data != null && data.size() > 0) { ContentMeta contentMeta = this.getContentRepository().getContentMeta(collection.getContentId()); updateContentMeta(contentMeta, data); } }