コード例 #1
0
ファイル: EntryController.java プロジェクト: chimaerase/ice
  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
ファイル: EntryController.java プロジェクト: chimaerase/ice
  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;
  }
コード例 #3
0
ファイル: EntryController.java プロジェクト: chimaerase/ice
  public PartStatistics retrieveEntryStatistics(String userId, long entryId) {
    Entry entry = dao.get(entryId);
    if (entry == null) return null;

    authorization.expectRead(userId, entry);

    PartStatistics statistics = new PartStatistics();
    statistics.setEntryId(entryId);
    statistics.setCommentCount(commentDAO.getCommentCount(entry));
    int traceSequenceCount = DAOFactory.getTraceSequenceDAO().getTraceSequenceCount(entry);
    statistics.setTraceSequenceCount(traceSequenceCount);
    int sampleCount = DAOFactory.getSampleDAO().getSampleCount(entry);
    statistics.setSampleCount(sampleCount);
    int historyCount = DAOFactory.getAuditDAO().getHistoryCount(entry);
    statistics.setHistoryCount(historyCount);
    int eddCount = DAOFactory.getExperimentDAO().getExperimentCount(entryId);
    statistics.setExperimentalDataCount(eddCount);
    return statistics;
  }
コード例 #4
0
ファイル: EntryController.java プロジェクト: chimaerase/ice
  public boolean addTraceSequence(String userId, long partId, File file, String uploadFileName) {
    Entry entry = dao.get(partId);
    if (entry == null) return false;

    authorization.expectRead(userId, entry);

    FileInputStream inputStream;
    try {
      inputStream = new FileInputStream(file);
    } catch (FileNotFoundException e) {
      Logger.error(e);
      return false;
    }

    if (uploadFileName.toLowerCase().endsWith(".zip")) {
      try (ZipInputStream zis = new ZipInputStream(inputStream)) {
        ZipEntry zipEntry;
        while (true) {
          zipEntry = zis.getNextEntry();

          if (zipEntry != null) {
            if (!zipEntry.isDirectory() && !zipEntry.getName().startsWith("__MACOSX")) {
              ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
              int c;
              while ((c = zis.read()) != -1) {
                byteArrayOutputStream.write(c);
              }

              boolean parsed =
                  parseTraceSequence(
                      userId, entry, zipEntry.getName(), byteArrayOutputStream.toByteArray());
              if (!parsed) {
                String errMsg =
                    ("Could not parse \""
                        + zipEntry.getName()
                        + "\". Only Fasta, GenBank & ABI files are supported.");
                Logger.error(errMsg);
                return false;
              }
            }
          } else {
            break;
          }
        }
      } catch (IOException e) {
        String errMsg = ("Could not parse zip file.");
        Logger.error(errMsg);
        return false;
      }
    } else {
      try {
        boolean parsed =
            parseTraceSequence(userId, entry, uploadFileName, IOUtils.toByteArray(inputStream));
        if (!parsed) {
          String errMsg =
              ("Could not parse \""
                  + uploadFileName
                  + "\". Only Fasta, GenBank & ABI files are supported.");
          Logger.error(errMsg);
          return false;
        }
      } catch (IOException e) {
        Logger.error(e);
        return false;
      }
    }

    return true;
  }
コード例 #5
0
ファイル: EntryController.java プロジェクト: chimaerase/ice
  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;
  }