예제 #1
0
  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);
    }
  }
예제 #2
0
  @Override
  @Transactional(
      readOnly = false,
      propagation = Propagation.REQUIRED,
      rollbackFor = Exception.class)
  public void inviteUserForClass(List<String> emails, final String classUid, final User user) {
    final UserClass userClass = this.getClassRepository().getClassById(classUid);
    rejectIfNull(userClass, GL0056, 404, CLASS);
    // To Do, Fix me

    CustomTableValue status =
        this.getCustomTableRepository().getCustomTableValue(INVITE_USER_STATUS, PENDING);
    List<String> emailIds = new ArrayList<String>();
    User creator = getUserRepository().findByGooruId(userClass.getUserUid());
    for (String email : emails) {
      InviteUser inviteUser =
          this.getInviteRepository().findInviteUserById(email, userClass.getPartyUid(), null);
      if (inviteUser == null) {
        inviteUser = new InviteUser(email, userClass.getPartyUid(), CLASS, user, status);
        this.getInviteRepository().save(inviteUser);
        emailIds.add(email);
      }
      try {
        String courseGooruOid = null;
        if (userClass.getCourseContentId() != null) {
          Content content =
              this.getContentRepository().findByContent(userClass.getCourseContentId());
          if (content != null) {
            courseGooruOid = content.getGooruOid();
          }
        }
        if (userClass.getVisibility() != null && !userClass.getVisibility()) {
          this.getMailHandler()
              .sendMailToInviteUser(
                  email,
                  userClass.getPartyUid(),
                  creator,
                  userClass.getName(),
                  user.getUsername(),
                  userClass.getGroupCode(),
                  courseGooruOid);
        } else {
          this.getMailHandler()
              .sendMailToOpenClassUser(
                  email,
                  userClass.getPartyUid(),
                  creator,
                  userClass.getName(),
                  user.getUsername(),
                  userClass.getGroupCode(),
                  courseGooruOid);
        }
      } catch (Exception e) {
        LOGGER.error(ERROR, e);
      }
    }
  }
예제 #3
0
 public void enrichCollectionWithTaxonomyMap(SearchResultContainer collectionResultContainer) {
   if (collectionResultContainer.getSearchResults() != null) {
     for (SearchResult srContainer : collectionResultContainer.getSearchResults()) {
       Content findByContent =
           this.getContentRepository().findContentByGooruId(srContainer.getId());
       if (findByContent != null) {
         Map<Integer, List<Code>> taxonomyMapByCode =
             TaxonomyUtil.getTaxonomyMapByCode(findByContent.getTaxonomySet(), taxonomyService);
         srContainer.setTaxonomyMapByCode(taxonomyMapByCode);
         Integer numberOfQuestions =
             assessmentRepository.getAssessmentQuestionsCount(findByContent.getContentId());
         srContainer.setNumberOfResources(numberOfQuestions);
       }
     }
   }
 }
  public void saveOrUpdate(Object model) {
    if (model instanceof Annotation) {
      if (((Annotation) model).getResource() != null) {
        ((Content) model).setOrganization(((Annotation) model).getResource().getOrganization());
        ((Content) model)
            .setVersion(
                ((Content) model).getVersion() == null ? 1 : ((Content) model).getVersion() + 1);
      }

    } else if (model instanceof OrganizationWrapper
        && ((OrganizationWrapper) model).getOrganization() == null) {
      ((OrganizationWrapper) model).setOrganization(getCurrentUserPrimaryOrganization());
    }

    if (model instanceof Content) {
      ((Content) model).setLastModified(new Date(System.currentTimeMillis()));
      ((Content) model)
          .setVersion(
              ((Content) model).getVersion() == null ? 1 : ((Content) model).getVersion() + 1);
    }

    if (model instanceof CollectionItem) {
      ((CollectionItem) model)
          .getCollection()
          .setLastModified(new Date(System.currentTimeMillis()));
      ((CollectionItem) model)
          .getCollection()
          .setVersion(
              ((CollectionItem) model).getCollection().getVersion() == null
                  ? 1
                  : ((CollectionItem) model).getCollection().getVersion() + 1);
    }

    if (model instanceof User) {
      ((User) model).setLastModifiedOn(new Date(System.currentTimeMillis()));
    }

    getSession().saveOrUpdate(model);
  }
예제 #5
0
  public void deleteCollaborators(
      Content content, List<User> userList, User apiCaller, String predicate) {

    Set<ContentPermission> contentPermissions = content.getContentPermissions();
    Set<ContentPermission> removePermissions = new HashSet<ContentPermission>();

    for (ContentPermission contentPermission : contentPermissions) {
      for (User user : userList) {
        if (user.getPartyUid().equalsIgnoreCase(contentPermission.getParty().getPartyUid())) {
          removePermissions.add(contentPermission);
          break;
        }
      }
    }
    if (removePermissions.size() > 0) {
      contentPermissions.removeAll(removePermissions);
      this.getBaseRepository().removeAll(removePermissions);
    }

    this.getBaseRepository().saveAll(contentPermissions);
    this.getBaseRepository().flush();
  }