use of org.jbei.ice.lib.dto.entry.EntryType in project ice by JBEI.
the class BulkUploadResource method post.
/**
* @return Response with the id of the imported bulk upload
*/
@POST
@Path("file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response post(@FormDataParam("file") InputStream fileInputStream, @FormDataParam("type") String type, @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {
try {
String userId = getUserId();
String fileName = userId + "-" + System.currentTimeMillis() + "-" + contentDispositionHeader.getFileName();
File file = Paths.get(Utils.getConfigValue(ConfigurationKey.DATA_DIRECTORY), "bulk-import", fileName).toFile();
FileUtils.copyInputStreamToFile(fileInputStream, file);
EntryType addType = EntryType.valueOf(type.toUpperCase());
FileBulkUpload bulkUpload = new FileBulkUpload(userId, file.toPath(), addType);
ProcessedBulkUpload processedBulkUpload = bulkUpload.process();
if (processedBulkUpload.isSuccess())
return Response.status(Response.Status.OK).entity(processedBulkUpload).build();
return Response.status(Response.Status.BAD_REQUEST).entity(processedBulkUpload).build();
} catch (IOException e) {
Logger.error(e);
ProcessedBulkUpload processedBulkUpload = new ProcessedBulkUpload();
processedBulkUpload.setUserMessage(e.getCause().getMessage());
processedBulkUpload.setSuccess(false);
return Response.status(Response.Status.BAD_REQUEST).entity(processedBulkUpload).build();
}
}
use of org.jbei.ice.lib.dto.entry.EntryType in project ice by JBEI.
the class BulkUploadControllerTest method testAutoUpdateBulkUpload.
@Test
public void testAutoUpdateBulkUpload() throws Exception {
EntryType type = EntryType.STRAIN;
Account account = AccountCreator.createTestAccount("testAutoUpdateBulkUpload", false);
BulkUploadAutoUpdate autoUpdate = new BulkUploadAutoUpdate(EntryType.STRAIN);
autoUpdate.getKeyValue().put(EntryField.LINKS, "google");
// first auto update. expect it to create a new bulk upload and entry
autoUpdate = controller.autoUpdateBulkUpload(account.getEmail(), autoUpdate, type);
Assert.assertNotNull(autoUpdate);
long entryId = autoUpdate.getEntryId();
long bulkId = autoUpdate.getBulkUploadId();
Assert.assertTrue(entryId > 0);
Assert.assertTrue(bulkId > 0);
BulkUploadInfo bulkUploadInfo = controller.getBulkImport(account.getEmail(), bulkId, 0, 1000);
Assert.assertNotNull(bulkUploadInfo);
EntryDAO dao = DAOFactory.getEntryDAO();
Entry entry = dao.get(entryId);
Assert.assertNotNull(entry);
Assert.assertNotNull(entry.getLinks());
Assert.assertEquals(1, entry.getLinks().size());
autoUpdate = new BulkUploadAutoUpdate(EntryType.PLASMID);
// auto update: expect plasmid and bulk upload with no fields set
autoUpdate = controller.autoUpdateBulkUpload(account.getEmail(), autoUpdate, type);
Assert.assertNotNull(autoUpdate);
entryId = autoUpdate.getEntryId();
bulkId = autoUpdate.getBulkUploadId();
Assert.assertTrue(entryId > 0);
Assert.assertTrue(bulkId > 0);
entry = dao.get(entryId);
Assert.assertNotNull(entry);
}
use of org.jbei.ice.lib.dto.entry.EntryType 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("extractHierarchy") @DefaultValue("false") boolean extractHierarchy, @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, extractHierarchy);
if (info == null)
throw new WebApplicationException(Response.serverError().build());
return Response.status(Response.Status.OK).entity(info).build();
} catch (IOException 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.dto.entry.EntryType in project ice by JBEI.
the class BulkUploadValidation method validateEntry.
protected void validateEntry(Entry entry) {
EntryType type = EntryType.nameToType(entry.getRecordType());
if (type == null)
return;
validateCommonFields(entry);
if (entry.getLinkedEntries() != null) {
for (Entry linked : entry.getLinkedEntries()) {
validateEntry(linked);
}
}
switch(type) {
default:
case PART:
break;
case STRAIN:
validateStrain((Strain) entry);
break;
case PLASMID:
validatePlasmid((Plasmid) entry);
break;
case SEED:
validateSeedFields((ArabidopsisSeed) entry);
break;
case PROTEIN:
break;
}
}
use of org.jbei.ice.lib.dto.entry.EntryType in project ice by JBEI.
the class EntriesAsCSV method getEntryFields.
private EntryFieldLabel[] getEntryFields() {
Set<String> recordTypes = new HashSet<>(dao.getRecordTypes(entries));
List<EntryFieldLabel> fields = EntryFields.getCommonFields();
for (String recordType : recordTypes) {
EntryType type = EntryType.nameToType(recordType);
if (type == null) {
Logger.error("Could not convert entry type " + recordType);
continue;
}
switch(type) {
case SEED:
EntryFields.addArabidopsisSeedHeaders(fields);
break;
case STRAIN:
EntryFields.addStrainHeaders(fields);
break;
case PLASMID:
EntryFields.addPlasmidHeaders(fields);
break;
case PROTEIN:
EntryFields.addProteinHeaders(fields);
break;
}
}
return fields.toArray(new EntryFieldLabel[0]);
}
Aggregations