Skip to content

Commit

Permalink
Merge branch '5.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
hplahar committed Jan 11, 2017
2 parents eb458ab + 5c2a1c2 commit 5927769
Show file tree
Hide file tree
Showing 17 changed files with 419 additions and 214 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.jbei</groupId>
<artifactId>ice</artifactId>
<packaging>war</packaging>
<version>5.2.0</version>
<version>5.2.1</version>
<name>ice</name>
<description>Inventory of Composable Elements (ICE) for Synthetic Biology</description>
<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected PartData doUpdate(String userId, Entry entry, PartData data) {
}
} else {
// linking to existing
EntryLinks entryLinks = new EntryLinks(userId, entry.getId());
EntryLinks entryLinks = new EntryLinks(userId, Long.toString(entry.getId()));
entryLinks.addLink(linkedPartData, LinkType.CHILD);
}

Expand Down Expand Up @@ -515,7 +515,7 @@ public boolean createEntries(String userId, long draftId, List<PartWithSample> d
if (linked.getId() != 0) {
Entry linkedEntry = entryDAO.get(linked.getId());
if (linkedEntry != null && entryAuthorization.canWriteThoroughCheck(userId, entry)) {
EntryLinks links = new EntryLinks(userId, entry.getId());
EntryLinks links = new EntryLinks(userId, Long.toString(entry.getId()));
links.addLink(linked, LinkType.CHILD);
}
}
Expand Down Expand Up @@ -548,7 +548,7 @@ public boolean createEntries(String userId, long draftId, List<PartWithSample> d
if (partSample == null)
continue;

sampleService.createSample(userId, entry.getId(), partSample, null);
sampleService.createSample(userId, Long.toString(entry.getId()), partSample, null);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jbei/ice/lib/config/SiteSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class SiteSettings implements IDataTransferModel {

private String version = "5.2.0";
private String version = "5.2.1";
private String assetName;
private boolean hasLogo;
private boolean hasLoginMessage;
Expand Down
95 changes: 0 additions & 95 deletions src/main/java/org/jbei/ice/lib/entry/EntryController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.jbei.ice.lib.entry;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.jbei.ice.lib.access.PermissionException;
import org.jbei.ice.lib.access.PermissionsController;
import org.jbei.ice.lib.account.AccountController;
import org.jbei.ice.lib.account.TokenHash;
import org.jbei.ice.lib.common.logging.Logger;
import org.jbei.ice.lib.dto.DNASequence;
import org.jbei.ice.lib.dto.access.AccessPermission;
import org.jbei.ice.lib.dto.comment.UserComment;
import org.jbei.ice.lib.dto.entry.*;
Expand All @@ -21,10 +19,7 @@
import org.jbei.ice.storage.hibernate.dao.*;
import org.jbei.ice.storage.model.*;

import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
* ABI to manipulate {@link Entry}s.
Expand All @@ -39,13 +34,11 @@ public class EntryController extends HasEntry {
private PermissionsController permissionsController;
private AccountController accountController;
private final EntryAuthorization authorization;
private final SequenceAnalysisController sequenceAnalysisController;

public EntryController() {
dao = DAOFactory.getEntryDAO();
commentDAO = DAOFactory.getCommentDAO();
permissionsController = new PermissionsController();
sequenceAnalysisController = new SequenceAnalysisController();
accountController = new AccountController();
authorization = new EntryAuthorization();
sequenceDAO = DAOFactory.getSequenceDAO();
Expand Down Expand Up @@ -426,92 +419,4 @@ protected PartData retrieveEntryDetails(String userId, Entry entry) throws Permi

return partData;
}

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;
}

// uploads trace sequence file and builds or rebuilds alignment
private boolean parseTraceSequence(String userId, Entry entry, String fileName, byte[] bytes) {
DNASequence dnaSequence = sequenceAnalysisController.parse(bytes);
if (dnaSequence == null || dnaSequence.getSequence() == null) {
String errMsg = ("Could not parse \"" + fileName
+ "\". Only Fasta, GenBank & ABI files are supported.");
Logger.error(errMsg);
return false;
}

TraceSequence traceSequence = sequenceAnalysisController.uploadTraceSequence(
entry, fileName, userId, dnaSequence.getSequence().toLowerCase(), new ByteArrayInputStream(bytes));

if (traceSequence == null)
return false;

Sequence sequence = DAOFactory.getSequenceDAO().getByEntry(entry);
if (sequence == null)
return true;
sequenceAnalysisController.buildOrRebuildAlignment(traceSequence, sequence);
return true;
}
}
9 changes: 3 additions & 6 deletions src/main/java/org/jbei/ice/lib/entry/EntryLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jbei.ice.lib.dto.entry.EntryType;
import org.jbei.ice.lib.dto.entry.PartData;
import org.jbei.ice.storage.DAOFactory;
import org.jbei.ice.storage.hibernate.dao.EntryDAO;
import org.jbei.ice.storage.hibernate.dao.SequenceDAO;
import org.jbei.ice.storage.model.Entry;

Expand All @@ -19,17 +18,15 @@
*
* @author Hector Plahar
*/
public class EntryLinks {
public class EntryLinks extends HasEntry {

private final EntryDAO entryDAO;
private final SequenceDAO sequenceDAO;
private final Entry entry;
private final EntryAuthorization entryAuthorization;
private final String userId;

public EntryLinks(String userId, long partId) {
this.entryDAO = DAOFactory.getEntryDAO();
this.entry = this.entryDAO.get(partId);
public EntryLinks(String userId, String partId) {
this.entry = super.getEntry(partId);
if (this.entry == null)
throw new IllegalArgumentException("Could not retrieve part with id " + partId);
this.userId = userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;

/**
* Handler for sample requests
Expand Down Expand Up @@ -106,7 +104,7 @@ public UserSamples getRequests(String userId, int start, int limit, String sort,

for (Request request : results) {
SampleRequest sampleRequest = request.toDataTransferObject();
ArrayList<PartSample> location = sampleService.retrieveEntrySamples(userId, request.getEntry().getId());
ArrayList<PartSample> location = sampleService.retrieveEntrySamples(userId, Long.toString(request.getEntry().getId()));
sampleRequest.setLocation(location);
samples.getRequests().add(sampleRequest);
}
Expand Down Expand Up @@ -192,7 +190,8 @@ public ByteArrayOutputStream generateCSVFile(String userId, ArrayList<Long> ids)
try (CSVWriter writer = new CSVWriter(streamWriter)) {
SampleService sampleService = new SampleService();

for (long id : ids) {
Set<Long> idSet = new HashSet<>(ids);
for (long id : idSet) {
Request request = dao.get(id);
if (request == null)
continue;
Expand All @@ -201,7 +200,7 @@ public ByteArrayOutputStream generateCSVFile(String userId, ArrayList<Long> ids)
Entry entry = request.getEntry();
line[0] = entry.getName();

ArrayList<PartSample> samples = sampleService.retrieveEntrySamples(userId, request.getEntry().getId());
ArrayList<PartSample> samples = sampleService.retrieveEntrySamples(userId, Long.toString(request.getEntry().getId()));
String plate = null;
String well = null;

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/jbei/ice/lib/entry/sample/SampleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jbei.ice.lib.dto.sample.PartSample;
import org.jbei.ice.lib.dto.sample.SampleType;
import org.jbei.ice.lib.entry.EntryAuthorization;
import org.jbei.ice.lib.entry.HasEntry;
import org.jbei.ice.lib.utils.Utils;
import org.jbei.ice.storage.DAOException;
import org.jbei.ice.storage.DAOFactory;
Expand All @@ -23,7 +24,7 @@
*
* @author Hector Plahar
*/
public class SampleService {
public class SampleService extends HasEntry {

private final SampleDAO dao;
private final StorageDAO storageDAO;
Expand All @@ -48,8 +49,8 @@ protected Storage createStorage(String userId, String name, SampleType sampleTyp
return storage;
}

public PartSample createSample(String userId, long entryId, PartSample partSample, String strainNamePrefix) {
Entry entry = DAOFactory.getEntryDAO().get(entryId);
public PartSample createSample(String userId, String entryId, PartSample partSample, String strainNamePrefix) {
Entry entry = super.getEntry(entryId);
if (entry == null) {
Logger.error("Could not retrieve entry with id " + entryId + ". Skipping sample creation");
return null;
Expand Down Expand Up @@ -214,8 +215,8 @@ protected Storage createChildrenStorage(StorageLocation currentLocation, Storage
}


public ArrayList<PartSample> retrieveEntrySamples(String userId, long entryId) {
Entry entry = DAOFactory.getEntryDAO().get(entryId);
public ArrayList<PartSample> retrieveEntrySamples(String userId, String entryId) {
Entry entry = super.getEntry(entryId);
if (entry == null)
return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
import org.jbei.ice.lib.search.blast.BlastPlus;
import org.jbei.ice.lib.utils.Utils;
import org.jbei.ice.storage.DAOFactory;
import org.jbei.ice.storage.hibernate.dao.TraceSequenceDAO;
import org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO;
import org.jbei.ice.storage.hibernate.dao.TraceSequenceDAO;
import org.jbei.ice.storage.model.*;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
Expand All @@ -39,56 +38,6 @@ public SequenceAnalysisController() {
shotgunDao = DAOFactory.getShotgunSequenceDAO();
}

/**
* Create a new {@link TraceSequence} record and associated with the {@link Entry} entry.
* <p>
* Creates a database record and write the inputStream to disk.
*
* @param entry
* @param filename
* @param depositor
* @param sequence
* @param uuid
* @param date
* @param inputStream
* @return Saved traceSequence
*/
public TraceSequence importTraceSequence(Entry entry, String filename, String depositor, String sequence,
String uuid, Date date, InputStream inputStream) {
if (entry == null) {
throw new IllegalArgumentException("Failed to save trace sequence with null entry!");
}

if (filename == null || filename.isEmpty()) {
throw new IllegalArgumentException("Failed to save trace sequence without filename!");
}

if (sequence == null || sequence.isEmpty()) {
throw new IllegalArgumentException("Failed to save trace sequence without sequence!");
}

TraceSequence traceSequence = new TraceSequence(entry, uuid, filename, depositor, sequence, date);
File tracesDir = Paths.get(Utils.getConfigValue(ConfigurationKey.DATA_DIRECTORY), TRACES_DIR_NAME).toFile();
return traceDao.create(tracesDir, traceSequence, inputStream);
}

/**
* Create a new {@link TraceSequence} record and associated with the {@link Entry} entry.
* <p>
* Unlike importTraceSequence this method auto generates uuid and timestamp.
*
* @param entry entry information
* @param filename name of the file uploaded by the user
* @param depositor email user depositing the information
* @param sequence sequence string
* @param inputStream input stream for uploaded file
* @return Saved traceSequence
*/
public TraceSequence uploadTraceSequence(Entry entry, String filename, String depositor,
String sequence, InputStream inputStream) {
return importTraceSequence(entry, filename, depositor, sequence, Utils.generateUUID(), new Date(), inputStream);
}

/**
* Remove a {@link TraceSequence} from the database and disk.
*
Expand Down Expand Up @@ -166,7 +115,6 @@ public DNASequence parse(byte[] bytes) {

// Trying to parse as Fasta, Genbank, etc
DNASequence dnaSequence = GeneralParser.getInstance().parse(bytes);

if (dnaSequence == null) {
// Trying to parse as ABI

Expand Down Expand Up @@ -215,7 +163,7 @@ public void buildOrRebuildAlignment(TraceSequence traceSequence, Sequence sequen
String entrySequenceString = sequence.getSequence();

int entrySequenceLength = entrySequenceString.length();
boolean isCircular = (sequence.getEntry() instanceof Plasmid) && ((Plasmid) sequence.getEntry()).getCircular();
boolean isCircular = (sequence.getEntry().getRecordType().equalsIgnoreCase("plasmid")) && ((Plasmid) sequence.getEntry()).getCircular();

if (isCircular) {
entrySequenceString += entrySequenceString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ public FeaturedDNASequence updateSequence(String userId, long entryId, FeaturedD
if (!deleteSequence(userId, entryId))
return null;

// sequence = update(userId, sequence);
BlastPlus.scheduleBlastIndexRebuildTask(true);
sequence = save(userId, sequence);
if (sequence != null)
return sequenceToDNASequence(sequence);
return null;
if (sequence == null)
return null;

BlastPlus.scheduleBlastIndexRebuildTask(true);
SequenceAnalysisController sequenceAnalysisController = new SequenceAnalysisController();
sequenceAnalysisController.rebuildAllAlignments(entry);
return sequenceToDNASequence(sequence);
}

/**
Expand Down
Loading

0 comments on commit 5927769

Please sign in to comment.