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; }
public boolean deleteTraceSequence(String userId, long entryId, long traceId) { Entry entry = dao.get(entryId); if (entry == null) return false; TraceSequenceDAO traceSequenceDAO = DAOFactory.getTraceSequenceDAO(); TraceSequence traceSequence = traceSequenceDAO.get(traceId); if (traceSequence == null || !canEdit(userId, traceSequence.getDepositor(), entry)) return false; try { new SequenceAnalysisController().removeTraceSequence(traceSequence); } catch (Exception e) { Logger.error(e); return false; } return true; }
/** * Convert {@link TraceData} value object into {@link TraceSequence} object with the given * depositor and {@link Entry}. * * @param traceData TraceData object to convert. * @param depositor Depositor email. * @param entry Entry to associate. * @return TraceSequence object. */ public static TraceSequence traceDataToTraceSequence( TraceData traceData, String depositor, Entry entry) { TraceSequence resultTraceSequence = new TraceSequence(); if (traceData == null) { return resultTraceSequence; } resultTraceSequence.setFilename(traceData.getFilename()); resultTraceSequence.setSequence(traceData.getSequence()); resultTraceSequence.setEntry(entry); resultTraceSequence.setDepositor(depositor); TraceSequenceAlignment traceSequenceAlignment = new TraceSequenceAlignment(); resultTraceSequence.setTraceSequenceAlignment(traceSequenceAlignment); if (traceData.getScore() >= 0) { traceSequenceAlignment.setScore(traceData.getScore()); traceSequenceAlignment.setStrand(traceData.getStrand()); traceSequenceAlignment.setQueryStart(traceData.getQueryStart()); traceSequenceAlignment.setQueryEnd(traceData.getQueryEnd()); traceSequenceAlignment.setSubjectStart(traceData.getSubjectStart()); traceSequenceAlignment.setSubjectEnd(traceData.getSubjectEnd()); traceSequenceAlignment.setQueryAlignment(traceData.getQueryAlignment()); traceSequenceAlignment.setSubjectAlignment(traceData.getSubjectAlignment()); } return resultTraceSequence; }
/** * Convert {@link TraceSequence} to {@link TraceData} value object. * * @param traceSequence TraceSequence to convert. * @return TraceData object. */ public static TraceData traceSequenceToTraceData(TraceSequence traceSequence) { TraceData resultTraceData = new TraceData(); if (traceSequence == null) { return resultTraceData; } resultTraceData.setFilename(traceSequence.getFilename()); resultTraceData.setSequence(traceSequence.getSequence()); if (traceSequence.getTraceSequenceAlignment() != null) { resultTraceData.setScore(traceSequence.getTraceSequenceAlignment().getScore()); resultTraceData.setStrand(traceSequence.getTraceSequenceAlignment().getStrand()); resultTraceData.setQueryStart(traceSequence.getTraceSequenceAlignment().getQueryStart()); resultTraceData.setQueryEnd(traceSequence.getTraceSequenceAlignment().getQueryEnd()); resultTraceData.setSubjectStart(traceSequence.getTraceSequenceAlignment().getSubjectStart()); resultTraceData.setSubjectEnd(traceSequence.getTraceSequenceAlignment().getSubjectEnd()); resultTraceData.setQueryAlignment( traceSequence.getTraceSequenceAlignment().getQueryAlignment()); resultTraceData.setSubjectAlignment( traceSequence.getTraceSequenceAlignment().getSubjectAlignment()); } return resultTraceData; }