private String getParentCollection( Long collectionId, String collectionType, String gooruOid, Collection targetCollection) { CollectionItem lesson = this.getCollectionDao().getParentCollection(collectionId); reject( !(lesson.getCollection().getGooruOid().equalsIgnoreCase(targetCollection.getGooruOid())), GL0111, 404, lesson.getCollection().getCollectionType()); if (lesson.getCollection().getCollectionType().equalsIgnoreCase(LESSON)) { updateContentMetaDataSummary(lesson.getCollection().getContentId(), collectionType, DELETE); } return targetCollection.getCollectionType(); }
private String moveCollection(String collectionId, Collection targetCollection, User user) { CollectionItem sourceCollectionItem = getCollectionDao().getCollectionItemById(collectionId, user); rejectIfNull(sourceCollectionItem, GL0056, 404, COLLECTION); // need to put validation for collaborator CollectionItem collectionItem = new CollectionItem(); if (sourceCollectionItem.getItemType() != null) { collectionItem.setItemType(sourceCollectionItem.getItemType()); } String collectionType = getParentCollection( sourceCollectionItem.getContent().getContentId(), sourceCollectionItem.getContent().getContentType().getName(), collectionId, targetCollection); String contentType = null; if (collectionType.equalsIgnoreCase(LESSON)) { contentType = sourceCollectionItem.getContent().getContentType().getName(); } createCollectionItem(collectionItem, targetCollection, sourceCollectionItem.getContent(), user); resetSequence( sourceCollectionItem.getCollection().getGooruOid(), sourceCollectionItem.getCollectionItemId(), user.getPartyUid(), COLLECTION); getCollectionDao().remove(sourceCollectionItem); getAsyncExecutor().deleteFromCache(V2_ORGANIZE_DATA + user.getPartyUid() + "*"); return contentType; }
@Override @Transactional( readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void deleteCollectionItem(String collectionId, String collectionItemId, String userUid) { CollectionItem collectionItem = this.getCollectionDao().getCollectionItem(collectionItemId); rejectIfNull(collectionItem, GL0056, 404, _COLLECTION_ITEM); Resource resource = this.getResourceBoService().getResource(collectionItem.getContent().getGooruOid()); rejectIfNull(resource, GL0056, 404, RESOURCE); String contentType = resource.getContentType().getName(); Long collectionContentId = collectionItem.getCollection().getContentId(); this.resetSequence( collectionId, collectionItem.getCollectionItemId(), userUid, COLLECTION_ITEM); getCollectionEventLog() .collectionItemEventLog(collectionId, collectionItem, userUid, contentType, null, DELETE); if (contentType.equalsIgnoreCase(QUESTION)) { getCollectionDao().remove(resource); } else { getCollectionDao().remove(collectionItem); } updateCollectionMetaDataSummary(collectionContentId, RESOURCE, contentType); }
@Override public ActionResponseDTO<CollectionItem> createClasspageItem( String assignmentGooruOid, String classpageGooruOid, CollectionItem collectionItem, User user, String type) throws Exception { Classpage classpage = null; if (type != null && type.equalsIgnoreCase(CollectionType.USER_CLASSPAGE.getCollectionType())) { if (classpageGooruOid != null) { classpage = this.getClasspage(classpageGooruOid, null, null); } else { classpage = this.getCollectionRepository() .getUserShelfByClasspageGooruUid( user.getGooruUId(), CollectionType.USER_CLASSPAGE.getCollectionType()); } if (classpage == null) { classpage = new Classpage(); classpage.setTitle(MY_CLASSPAGE); classpage.setCollectionType(CollectionType.USER_CLASSPAGE.getCollectionType()); classpage.setClasspageCode(BaseUtil.base48Encode(7)); classpage.setGooruOid(UUID.randomUUID().toString()); ContentType contentType = (ContentType) this.getCollectionRepository().get(ContentType.class, ContentType.RESOURCE); classpage.setContentType(contentType); ResourceType resourceType = (ResourceType) this.getCollectionRepository() .get(ResourceType.class, ResourceType.Type.CLASSPAGE.getType()); classpage.setResourceType(resourceType); classpage.setLastModified(new Date(System.currentTimeMillis())); classpage.setCreatedOn(new Date(System.currentTimeMillis())); classpage.setSharing(Sharing.PRIVATE.getSharing()); classpage.setUser(user); classpage.setOrganization(user.getPrimaryOrganization()); classpage.setCreator(user); classpage.setDistinguish(Short.valueOf(ZERO)); classpage.setRecordSource(NOT_ADDED); classpage.setIsFeatured(0); this.getCollectionRepository().save(classpage); } collectionItem.setItemType(ShelfType.AddedType.SUBSCRIBED.getAddedType()); } else { classpage = this.getClasspage(classpageGooruOid, null, null); collectionItem.setItemType(ShelfType.AddedType.ADDED.getAddedType()); } Collection collection = this.getCollectionRepository() .getCollectionByGooruOid(assignmentGooruOid, classpage.getUser().getGooruUId()); Errors errors = validateClasspageItem(classpage, collection, collectionItem); if (collection != null) { if (!errors.hasErrors()) { collectionItem.setCollection(classpage); collectionItem.setResource(collection); int sequence = collectionItem.getCollection().getCollectionItems() != null ? collectionItem.getCollection().getCollectionItems().size() + 1 : 1; collectionItem.setItemSequence(sequence); this.getCollectionRepository().save(collectionItem); } } else { throw new Exception("invalid assignmentId -" + assignmentGooruOid); } return new ActionResponseDTO<CollectionItem>(collectionItem, 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); } }