コード例 #1
0
 @Override
 public ProfileSummary createProfile(Profile profile) {
   User loggedInUser = userService.getLoggedInUser();
   if (profile.getUserId() != null && profile.getUserId() == loggedInUser.getId()
       || authService.isUserAuthorized(ROLE_ADMIN, profile.getOrganizationId())) {
     return profilePersister.create(profile);
   } else {
     throw new NotAuthorizedException();
   }
 }
コード例 #2
0
  @Override
  public StoryExport<StoryTellerCsv> exportStoryTellers(
      int profileId, Integer collectionId, Integer questionnaireId, int window) {
    try {
      int windowSize = 75;
      User user = userService.getUserForProfile(profileId);
      Profile userProfile = profilePersister.get(profileId);
      int organizationContext = userProfile.getOrganizationId();

      int accessMode = ACCESS_MODE_PRIVILEGED;
      if (authService.isSuperUser(user)) {
        accessMode = ACCESS_MODE_ROOT;
      }

      List<StoryTellerCsv> storyTellers = new ArrayList<StoryTellerCsv>();
      try {
        StoryTellersParams countParams =
            new StoryTellersParams(
                0,
                1,
                StorySortField.CREATED_OLD,
                false,
                collectionId,
                questionnaireId,
                accessMode,
                userService.getEffectiveSubject(user),
                null);
        int countStories = storyService.getStorytellerCount(countParams);

        // window starts at 0; bail out if we're asked for a window beyond what's available
        if (window * windowSize >= countStories) {
          return new StoryExport<StoryTellerCsv>(storyTellers, countStories);
        }

        try {
          SolrQuery sQuery = new SolrQuery("*:*");
          if (collectionId != null) {
            sQuery.addFilterQuery("collections:" + collectionId);
            sQuery.setSort("lastStoryDateByCollection_" + collectionId, SolrQuery.ORDER.desc);
          }

          if (questionnaireId != null) {
            sQuery.addFilterQuery("questionnaires:" + questionnaireId);
            sQuery.setSort("lastStoryDateByCollection_" + questionnaireId, SolrQuery.ORDER.desc);
          }

          if (!authService.isSuperUser(user)) {
            sQuery.addFilterQuery("readAuths:" + organizationContext);
          }

          sQuery.setRows(windowSize);
          sQuery.setStart(window * windowSize);

          QueryResponse result = solrPersonServer.query(sQuery);

          if (result.getResults().getNumFound() > 0) {
            for (SolrDocument entries : result.getResults()) {
              ProfileDocument doc = new ProfileDocument(entries);
              Profile profile = profilePersister.get(doc.getId());
              StoryTellerCsv storyTellerCsv = new StoryTellerCsv(doc, profile);

              storyTellers.add(storyTellerCsv);
            }
          }

          return new StoryExport<StoryTellerCsv>(storyTellers, countStories);
        } catch (Exception e) {
          throw new GeneralException(e);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      return new StoryExport<StoryTellerCsv>(storyTellers, 0);
    } catch (NotLoggedInException e) {
      throw new GeneralException(e);
    }
  }