示例#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 List<PartData> retrieveOwnerEntries(
      String userId, String ownerEmail, ColumnField sort, boolean asc, int start, int limit) {
    List<Entry> entries;
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);

    if (authorization.isAdmin(userId) || account.getEmail().equals(ownerEmail)) {
      entries = dao.retrieveOwnerEntries(ownerEmail, sort, asc, start, limit);
    } else {
      Set<Group> accountGroups = new HashSet<>(account.getGroups());
      GroupController controller = new GroupController();
      Group everybodyGroup = controller.createOrRetrievePublicGroup();
      accountGroups.add(everybodyGroup);
      // retrieve entries for user that can be read by others
      entries =
          dao.retrieveUserEntries(account, ownerEmail, accountGroups, sort, asc, start, limit);
    }

    ArrayList<PartData> data = new ArrayList<>();
    for (Entry entry : entries) {
      PartData info = ModelToInfoFactory.createTableViewData(userId, entry, false);
      info.setViewCount(DAOFactory.getAuditDAO().getHistoryCount(entry));
      data.add(info);
    }
    return data;
  }
示例#3
0
  private static Set<Link> getLinks(ArrayList<String> linkList, Entry entry) {
    Set<Link> existingLinks = entry.getLinks();
    Set<Link> links = new HashSet<>();

    if (existingLinks == null) existingLinks = new HashSet<>();

    if (linkList == null) return existingLinks;

    for (int i = 0; i < linkList.size(); i++) {
      String currentItem = linkList.get(i);
      Link link;

      if (existingLinks.size() > i) {
        link = (Link) existingLinks.toArray()[i];
      } else {
        link = new Link();
        existingLinks.add(link);
      }
      link.setLink(currentItem);
      link.setEntry(entry);
      links.add(link);
    }

    return links;
  }
示例#4
0
  private static Set<SelectionMarker> getSelectionMarkers(
      ArrayList<String> markerStr, Entry entry) {
    Set<SelectionMarker> existingMarkers = entry.getSelectionMarkers();
    Set<SelectionMarker> markers = new HashSet<>();

    if (existingMarkers == null) existingMarkers = new HashSet<>();

    if (markerStr != null) {
      int itemLength = markerStr.size();

      for (int i = 0; i < itemLength; i++) {
        String currentItem = markerStr.get(i);
        SelectionMarker marker;

        if (existingMarkers.size() > i) {
          marker = (SelectionMarker) existingMarkers.toArray()[i];
        } else {
          marker = new SelectionMarker();
          existingMarkers.add(marker);
        }

        marker.setName(currentItem);
        marker.setEntry(entry);
        markers.add(marker);
      }
    } else return null;

    return markers;
  }
示例#5
0
  public ArrayList<UserComment> retrieveEntryComments(String userId, long partId) {
    Entry entry = dao.get(partId);
    if (entry == null) return null;

    authorization.expectRead(userId, entry);

    // comments
    ArrayList<Comment> comments = commentDAO.retrieveComments(entry);
    ArrayList<UserComment> userComments = new ArrayList<>();

    for (Comment comment : comments) {
      userComments.add(comment.toDataTransferObject());
    }
    return userComments;
  }
示例#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;
  }
示例#7
0
  public List<PartData> getEntriesSharedWithUser(
      String userId, ColumnField field, boolean asc, int start, int limit) {
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    GroupController groupController = new GroupController();
    Group publicGroup = groupController.createOrRetrievePublicGroup();
    Set<Group> accountGroups = account.getGroups();
    accountGroups.remove(publicGroup);
    List<Entry> entries =
        dao.sharedWithUserEntries(account, accountGroups, field, asc, start, limit);

    ArrayList<PartData> data = new ArrayList<>();
    for (Entry entry : entries) {
      PartData info = ModelToInfoFactory.createTableViewData(userId, entry, false);
      info.setViewCount(DAOFactory.getAuditDAO().getHistoryCount(entry));
      data.add(info);
    }
    return data;
  }
示例#8
0
  protected PartData retrieveEntryDetails(String userId, Entry entry) {
    // user must be able to read if not public entry
    if (!permissionsController.isPubliclyVisible(entry)) authorization.expectRead(userId, entry);

    PartData partData = ModelToInfoFactory.getInfo(entry);
    if (partData == null) return null;
    boolean hasSequence = sequenceDAO.hasSequence(entry.getId());

    partData.setHasSequence(hasSequence);
    boolean hasOriginalSequence = sequenceDAO.hasOriginalSequence(entry.getId());
    partData.setHasOriginalSequence(hasOriginalSequence);

    // permissions
    partData.setCanEdit(authorization.canWriteThoroughCheck(userId, entry));
    partData.setPublicRead(permissionsController.isPubliclyVisible(entry));

    // create audit event if not owner
    // todo : remote access check
    if (userId != null
        && authorization.getOwner(entry) != null
        && !authorization.getOwner(entry).equalsIgnoreCase(userId)) {
      try {
        Audit audit = new Audit();
        audit.setAction(AuditType.READ.getAbbrev());
        audit.setEntry(entry);
        audit.setUserId(userId);
        audit.setLocalUser(true);
        audit.setTime(new Date(System.currentTimeMillis()));
        auditDAO.create(audit);
      } catch (Exception e) {
        Logger.error(e);
      }
    }

    // retrieve more information about linked entries if any (default only contains id)
    if (partData.getLinkedParts() != null) {
      ArrayList<PartData> newLinks = new ArrayList<>();
      for (PartData link : partData.getLinkedParts()) {
        Entry linkedEntry = dao.get(link.getId());
        if (!authorization.canRead(userId, linkedEntry)) continue;

        link = ModelToInfoFactory.createTipView(linkedEntry);
        Sequence sequence = sequenceDAO.getByEntry(linkedEntry);
        if (sequence != null) {
          link.setBasePairCount(sequence.getSequence().length());
          link.setFeatureCount(sequence.getSequenceFeatures().size());
        }

        newLinks.add(link);
      }
      partData.getLinkedParts().clear();
      partData.getLinkedParts().addAll(newLinks);
    }

    // check if there is a parent available
    List<Entry> parents = dao.getParents(entry.getId());
    if (parents == null) return partData;

    for (Entry parent : parents) {
      if (!authorization.canRead(userId, parent)) continue;

      if (parent.getVisibility() != Visibility.OK.getValue()
          && !authorization.canWriteThoroughCheck(userId, entry)) continue;

      EntryType type = EntryType.nameToType(parent.getRecordType());
      PartData parentData = new PartData(type);
      parentData.setId(parent.getId());
      parentData.setName(parent.getName());
      parentData.setVisibility(Visibility.valueToEnum(parent.getVisibility()));
      partData.getParents().add(parentData);
    }

    return partData;
  }