use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class BulkUploadController method addSequence.
public SequenceInfo addSequence(String userId, long bulkUploadId, long entryId, String sequenceString, String fileName) {
BulkUpload upload = dao.get(bulkUploadId);
if (upload == null)
return null;
authorization.expectWrite(userId, upload);
PartSequence partSequence = new PartSequence(userId, Long.toString(entryId));
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(sequenceString.getBytes(StandardCharsets.UTF_8));
return partSequence.parseSequenceFile(inputStream, fileName);
} catch (IOException e) {
Logger.error(e);
return null;
}
}
use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class FileResource method uploadSequence.
/**
* this creates an entry if an id is not specified in the form data
*/
@POST
@Path("sequence")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response uploadSequence(@FormDataParam("file") InputStream fileInputStream, @FormDataParam("entryRecordId") String recordId, @FormDataParam("entryType") String entryType, @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {
try {
final String fileName = contentDispositionHeader.getFileName();
String userId = getUserId();
PartSequence partSequence;
if (StringUtils.isEmpty(recordId)) {
if (entryType == null) {
entryType = "PART";
}
EntryType type = EntryType.nameToType(entryType);
partSequence = new PartSequence(userId, type);
} else {
partSequence = new PartSequence(userId, recordId);
}
SequenceInfo info = partSequence.parseSequenceFile(fileInputStream, fileName);
if (info == null)
throw new WebApplicationException(Response.serverError().build());
return Response.status(Response.Status.OK).entity(info).build();
} catch (Exception e) {
Logger.error(e);
ErrorResponse response = new ErrorResponse();
response.setMessage(e.getMessage());
throw new WebApplicationException(Response.serverError().entity(response).build());
}
}
use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class Entries method copy.
/**
* Creates a copy of referenced part
*
* @param sourceId unique identifier for part acting as source of copy. Can be the part id, uuid or id
* @return wrapper around the id and record id of the newly created entry
* @throws IllegalArgumentException if the source part for the copy cannot be located using the identifier
*/
public PartData copy(String sourceId) {
Entry entry = getEntry(sourceId);
if (entry == null)
throw new IllegalArgumentException("Could not retrieve entry \"" + sourceId + "\" for copy");
// check permission (expecting read permission)
authorization.expectRead(userId, entry);
Sequence sequence = null;
if (sequenceDAO.hasSequence(entry.getId())) {
sequence = sequenceDAO.getByEntry(entry);
}
// copy to data model and back ??
PartData partData = ModelToInfoFactory.getInfo(entry);
entry = InfoToModelFactory.infoToEntry(partData);
// create entry
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
entry.setName(entry.getName() + " (copy)");
entry.setRecordId(Utils.generateUUID());
entry.setVersionId(entry.getRecordId());
entry.setOwnerEmail(account.getEmail());
entry.setOwner(account.getFullName());
entry = createEntry(account, entry, new ArrayList<>());
// check sequence
if (sequence != null) {
PartSequence partSequence = new PartSequence(userId, sourceId);
new PartSequence(userId, entry.getPartNumber()).save(partSequence.get(true));
}
PartData copy = new PartData(EntryType.nameToType(entry.getRecordType()));
copy.setId(entry.getId());
copy.setRecordId(entry.getRecordId());
return copy;
}
use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class BulkUploadResource method deleteEntrySequence.
/**
* @param uploadId
* @param entryId
* @return OK response if sequence is deleted
*/
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entry/{entryId}/sequence")
public Response deleteEntrySequence(@PathParam("id") long uploadId, @PathParam("entryId") String entryId) {
String userId = getUserId();
PartSequence partSequence = new PartSequence(userId, entryId);
partSequence.delete();
return Response.ok().build();
}
use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.
the class PartResource method getSequence.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/sequence")
public Response getSequence(@PathParam("id") final String partId, @DefaultValue("false") @QueryParam("remote") boolean isRemote, @QueryParam("token") String remoteUserToken, @QueryParam("userId") String remoteUserId, @QueryParam("folderId") long fid, @DefaultValue("true") @QueryParam("annotations") boolean includeAnnotations) {
final FeaturedDNASequence sequence;
final String userId = getUserId();
Sequences sequences = new Sequences(userId);
if (isRemote) {
// entry exists remotely
sequence = remoteEntries.getSequence(userId, fid, partId);
} else {
// what request is being responded to (local or remote)
if (StringUtils.isEmpty(userId)) {
RegistryPartner partner = requireWebPartner();
if (StringUtils.isEmpty(remoteUserToken) || fid == 0) {
sequence = new PartSequence(userId, partId).get(includeAnnotations);
} else {
sequence = sequences.getRequestedSequence(partner, remoteUserId, remoteUserToken, partId, fid);
}
} else {
// user id can be null if partId is public
sequence = new PartSequence(userId, partId).get(includeAnnotations);
}
}
return Response.status(Response.Status.OK).entity(sequence).build();
}
Aggregations