Пример #1
0
  public ArrayList<TraceSequenceAnalysis> getTraceSequences(String userId, long entryId) {
    Entry entry = dao.get(entryId);
    if (entry == null) return null;

    authorization.expectRead(userId, entry);
    List<TraceSequence> sequences = DAOFactory.getTraceSequenceDAO().getByEntry(entry);

    ArrayList<TraceSequenceAnalysis> analysisArrayList = new ArrayList<>();
    if (sequences == null) return analysisArrayList;

    AccountController accountController = new AccountController();

    for (TraceSequence traceSequence : sequences) {
      TraceSequenceAnalysis analysis = traceSequence.toDataTransferObject();
      AccountTransfer accountTransfer = new AccountTransfer();

      String depositor = traceSequence.getDepositor();
      boolean canEdit = canEdit(userId, depositor, entry);
      analysis.setCanEdit(canEdit);

      Account account = accountController.getByEmail(traceSequence.getDepositor());
      if (account != null) {
        accountTransfer.setFirstName(account.getFirstName());
        accountTransfer.setLastName(account.getLastName());
        accountTransfer.setEmail(account.getEmail());
        accountTransfer.setId(account.getId());
      }

      analysis.setDepositor(accountTransfer);
      analysisArrayList.add(analysis);
    }

    return analysisArrayList;
  }
Пример #2
0
  public FolderDetails retrieveVisibleEntries(
      String userId, ColumnField field, boolean asc, int start, int limit) {
    Set<Entry> results;
    FolderDetails details = new FolderDetails();
    Account account = accountController.getByEmail(userId);

    if (authorization.isAdmin(userId)) {
      // no filters
      results = dao.retrieveAllEntries(field, asc, start, limit);
    } else {
      // retrieve groups for account and filter by permission
      Set<Group> accountGroups = new HashSet<>(account.getGroups());
      GroupController controller = new GroupController();
      Group everybodyGroup = controller.createOrRetrievePublicGroup();
      accountGroups.add(everybodyGroup);
      results = dao.retrieveVisibleEntries(account, accountGroups, field, asc, start, limit);
    }

    for (Entry entry : results) {
      PartData info = ModelToInfoFactory.createTableViewData(userId, entry, false);
      details.getEntries().add(info);
    }

    return details;
  }
Пример #3
0
  public UserComment createEntryComment(String userId, long partId, UserComment newComment) {
    Entry entry = dao.get(partId);
    if (entry == null) return null;

    authorization.canRead(userId, entry);
    Account account = accountController.getByEmail(userId);
    Comment comment = new Comment();
    comment.setAccount(account);
    comment.setEntry(entry);
    comment.setBody(newComment.getMessage());
    comment.setCreationTime(new Date());
    comment = commentDAO.create(comment);

    if (newComment.getSamples() != null) {
      SampleDAO sampleDAO = DAOFactory.getSampleDAO();
      for (PartSample partSample : newComment.getSamples()) {
        Sample sample = sampleDAO.get(partSample.getId());
        if (sample == null) continue;
        comment.getSamples().add(sample);
        sample.getComments().add(comment);
      }
    }

    comment = commentDAO.update(comment);
    return comment.toDataTransferObject();
  }
Пример #4
0
  /**
   * Retrieves and sets the default values for the entry. Some of these values (e.g. PI, and Funding
   * Source) are set by individual users as part of their personal preferences
   *
   * @param userId Unique identifier for user requesting the values.
   * @param type entry type
   * @return PartData object with the retrieve part defaults
   */
  public PartData getPartDefaults(String userId, EntryType type) {
    PartData partData = new PartData(type);
    PreferencesController preferencesController = new PreferencesController();

    // pi defaults
    String value =
        preferencesController.getPreferenceValue(
            userId, PreferenceKey.PRINCIPAL_INVESTIGATOR.name());
    if (value != null) {
      Account piAccount = accountController.getByEmail(value);
      if (piAccount == null) {
        partData.setPrincipalInvestigator(value);
      } else {
        partData.setPrincipalInvestigator(piAccount.getFullName());
        partData.setPrincipalInvestigatorEmail(piAccount.getEmail());
        partData.setPrincipalInvestigatorId(piAccount.getId());
      }
    }

    // funding source defaults
    value = preferencesController.getPreferenceValue(userId, PreferenceKey.FUNDING_SOURCE.name());
    if (value != null) {
      partData.setFundingSource(value);
    }

    // owner and creator details
    Account account = accountController.getByEmail(userId);
    if (account != null) {
      partData.setOwner(account.getFullName());
      partData.setOwnerEmail(account.getEmail());
      partData.setCreator(partData.getOwner());
      partData.setCreatorEmail(partData.getOwnerEmail());
    }

    // set the entry type defaults
    return EntryUtil.setPartDefaults(partData);
  }
Пример #5
0
  /**
   * Retrieve the number of entries that is visible to a particular user
   *
   * @param userId user account unique identifier
   * @return Number of entries that user with account referenced in the parameter can read.
   */
  public long getNumberOfVisibleEntries(String userId) {
    Account account = accountController.getByEmail(userId);

    if (account == null) return -1;

    if (authorization.isAdmin(userId)) {
      return dao.getAllEntryCount();
    }

    Set<Group> accountGroups = new HashSet<>(account.getGroups());
    GroupController controller = new GroupController();
    Group everybodyGroup = controller.createOrRetrievePublicGroup();
    accountGroups.add(everybodyGroup);
    return dao.visibleEntryCount(account, accountGroups);
  }
Пример #6
0
  public ArrayList<History> getHistory(String userId, long entryId) {
    Entry entry = dao.get(entryId);
    if (entry == null) return null;

    authorization.expectWrite(userId, entry);
    List<Audit> list = auditDAO.getAuditsForEntry(entry);
    ArrayList<History> result = new ArrayList<>();
    for (Audit audit : list) {
      History history = audit.toDataTransferObject();
      if (history.isLocalUser()) {
        history.setAccount(
            accountController.getByEmail(history.getUserId()).toDataTransferObject());
      }
      result.add(history);
    }
    return result;
  }