Search in sources :

Example 1 with EntryType

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();
    }
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType) IOException(java.io.IOException) File(java.io.File)

Example 2 with EntryType

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);
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) EntryType(org.jbei.ice.lib.dto.entry.EntryType) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO) Test(org.junit.Test)

Example 3 with EntryType

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());
    }
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) IOException(java.io.IOException)

Example 4 with EntryType

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;
    }
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType)

Example 5 with EntryType

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]);
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType) EntryFieldLabel(org.jbei.ice.lib.dto.entry.EntryFieldLabel) HashSet(java.util.HashSet)

Aggregations

EntryType (org.jbei.ice.lib.dto.entry.EntryType)12 IOException (java.io.IOException)3 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)3 PartSequence (org.jbei.ice.lib.entry.sequence.PartSequence)3 File (java.io.File)2 HashSet (java.util.HashSet)2 EntryFieldLabel (org.jbei.ice.lib.dto.entry.EntryFieldLabel)2 PartData (org.jbei.ice.lib.dto.entry.PartData)2 SampleRequest (org.jbei.ice.lib.dto.sample.SampleRequest)2 SearchQuery (org.jbei.ice.lib.dto.search.SearchQuery)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 javax.ws.rs (javax.ws.rs)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1