public List<HashMap<String, String>> getSubscribtionUserList(String gooruOid) { List<ShelfItem> shelfItemList = shelfService.getShelfSubscribeUserList(gooruOid); List<HashMap<String, String>> subscriptions = new ArrayList<HashMap<String, String>>(); if (shelfItemList != null) { for (ShelfItem shelfItem : shelfItemList) { User user = this.getUserRepository().findByGooruId(shelfItem.getShelf().getUserId()); if (user != null) { if (shelfItem .getResource() .getUser() .getGooruUId() .equalsIgnoreCase(user.getGooruUId())) { continue; } HashMap<String, String> hMap = new HashMap<String, String>(); hMap.put(SUBSCRIBED_ON, shelfItem.getCreatedOn().toString()); hMap.put(CONT_USER_ID, shelfItem.getResource().getUser().getGooruUId()); hMap.put(CONT_FIRSTNAME, user.getFirstName()); hMap.put(CONT_LASTNAME, user.getLastName()); hMap.put(SCB_USER_ID, shelfItem.getShelf().getUserId()); subscriptions.add(hMap); } } } return subscriptions; }
public void addNewCollaborators( Content content, List<User> userList, User apiCaller, String predicate, boolean addToShelf) { Set<ContentPermission> contentPermissions = content.getContentPermissions(); if (contentPermissions == null) { contentPermissions = new HashSet<ContentPermission>(); } if (userList != null && userList.size() > 0) { Date date = new Date(); for (User user : userList) { if (!user.getGooruUId().equals(content.getUser().getGooruUId())) { boolean newFlag = true; for (ContentPermission contentPermission : contentPermissions) { if (contentPermission.getParty().getPartyUid().equals(user.getPartyUid())) { newFlag = false; break; } } if (newFlag) { ContentPermission contentPerm = new ContentPermission(); contentPerm.setParty(user); contentPerm.setContent(content); contentPerm.setPermission(EDIT); contentPerm.setValidFrom(date); contentPermissions.add(contentPerm); } } } } if (contentPermissions != null && contentPermissions.size() > 0) { content.setContentPermissions(contentPermissions); } }
private Map<String, Object> getLastCollectionModifyUser(String userUid) { Map<String, Object> lastUserModifiedMap = null; final User lastUserModified = this.getUserService().findByGooruId(userUid); if (lastUserModified != null) { lastUserModifiedMap = new HashMap<String, Object>(); lastUserModifiedMap.put(USER_NAME, lastUserModified.getUsername()); lastUserModifiedMap.put(GOORU_UID, lastUserModified.getGooruUId()); } return lastUserModifiedMap; }
@Override public Classpage getClasspage(String collectionId, User user, String merge) { Classpage classpage = this.getCollectionRepository().getClasspageByGooruOid(collectionId, null); if (classpage != null && merge != null) { Map<String, Object> permissions = new HashMap<String, Object>(); Boolean isMember = false; String status = NOTINVITED; InviteUser inviteUser = null; String mailId = null; UserGroup userGroup = this.getUserGroupService().findUserGroupByGroupCode(classpage.getClasspageCode()); if (userGroup != null && !user.getGooruUId().equalsIgnoreCase(ANONYMOUS)) { isMember = this.getUserRepository() .getUserGroupMemebrByGroupUid(userGroup.getPartyUid(), user.getPartyUid()) != null ? true : false; if (isMember) { status = ACTIVE; } if (user.getIdentities().size() > 0) { mailId = user.getIdentities().iterator().next().getExternalId(); } inviteUser = this.getInviteRepository().findInviteUserById(mailId, collectionId); if (!isMember && inviteUser == null && classpage.getSharing().equalsIgnoreCase(PUBLIC)) { inviteUser = this.getInviteService().createInviteUserObj(mailId, collectionId, CLASS, user); this.getInviteRepository().save(inviteUser); this.getInviteRepository().flush(); } if (inviteUser != null) { status = PENDING; } } if (merge.contains(PERMISSIONS)) { permissions.put( PERMISSIONS, this.getContentService().getContentPermission(collectionId, user)); } permissions.put(STATUS, status); classpage.setMeta(permissions); } return classpage; }
@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); }
public void updateCollaborators( Resource resource, List<User> userList, User apiCaller, String predicate, boolean addToShelf) { Set<ContentPermission> contentPermissions = resource.getContentPermissions(); List<User> newUsers = new ArrayList<User>(); if (contentPermissions == null) { contentPermissions = new HashSet<ContentPermission>(); } if (userList != null && userList.size() > 0) { Date date = new Date(); for (User user : userList) { if (!user.getGooruUId().equals(resource.getUser().getGooruUId())) { boolean newFlag = true; for (ContentPermission contentPermission : contentPermissions) { if (contentPermission.getParty().getPartyUid().equals(user.getPartyUid())) { newFlag = false; break; } } if (newFlag) { ContentPermission contentPerm = new ContentPermission(); contentPerm.setParty(user); contentPerm.setContent(resource); contentPerm.setPermission(EDIT); contentPerm.setValidFrom(date); contentPermissions.add(contentPerm); if (!newUsers.contains(user)) { newUsers.add(user); } if (addToShelf) { this.getShelfService().addCollaboratorShelf(contentPerm); } } } } if (addToShelf) { if (newUsers.size() > 0) { sendMailToCollabrators(newUsers, resource, apiCaller); } } } Set<ContentPermission> removePermissions = new HashSet<ContentPermission>(); for (ContentPermission contentPermission : contentPermissions) { boolean remove = true; if (userList != null) { for (User user : userList) { if (user.getPartyUid().equals(contentPermission.getParty().getPartyUid())) { remove = false; break; } } } if (remove) { removePermissions.add(contentPermission); } } if (removePermissions.size() > 0) { this.getShelfService().removeCollaboratorShelf(removePermissions); contentPermissions.removeAll(removePermissions); this.getBaseRepository().removeAll(removePermissions); } this.getBaseRepository().save(resource); }