Search in sources :

Example 6 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO in project ice by JBEI.

the class FolderController method getPublicEntries.

/**
     * Retrieves entries that are made available publicly
     *
     * @param sort   order of retrieval for the entries
     * @param offset start of retrieval
     * @param limit  maximum number of entries to retrieve
     * @param asc    whether to retrieve the entries in ascending order
     * @return wrapper around the retrieved entries
     */
public FolderDetails getPublicEntries(ColumnField sort, int offset, int limit, boolean asc) {
    Group publicGroup = new GroupController().createOrRetrievePublicGroup();
    Set<Group> groups = new HashSet<>();
    groups.add(publicGroup);
    EntryDAO entryDAO = DAOFactory.getEntryDAO();
    List<Entry> results = entryDAO.retrieveVisibleEntries(null, groups, sort, asc, offset, limit, null);
    long visibleCount = entryDAO.visibleEntryCount(null, groups, null);
    FolderDetails details = new FolderDetails();
    details.setCount(visibleCount);
    for (Entry entry : results) {
        try {
            PartData info = ModelToInfoFactory.createTableViewData(null, entry, false);
            info.setPublicRead(true);
            details.getEntries().add(info);
        } catch (Exception e) {
            Logger.error(e);
        }
    }
    return details;
}
Also used : Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) PartData(org.jbei.ice.lib.dto.entry.PartData) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PermissionException(org.jbei.ice.lib.access.PermissionException) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

Example 7 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO 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 8 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO in project ice by JBEI.

the class RemoteEntriesAsCSV method writeList.

private boolean writeList(List<RemotePartner> partners) throws IOException {
    Path tmpPath = Paths.get(Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY));
    File tmpFile = File.createTempFile("remote-ice-", ".csv", tmpPath.toFile());
    csvPath = tmpFile.toPath();
    FileWriter fileWriter = new FileWriter(tmpFile);
    List<EntryField> fields = getEntryFields();
    String[] headers = getCSVHeaders(fields);
    // csv file headers
    File tmpZip = File.createTempFile("zip-", ".zip", tmpPath.toFile());
    FileOutputStream fos = new FileOutputStream(tmpZip);
    try (CSVWriter writer = new CSVWriter(fileWriter);
        ZipOutputStream zos = new ZipOutputStream(fos)) {
        writer.writeNext(headers);
        // go through partners
        for (RemotePartner partner : partners) {
            try {
                Logger.info("Retrieving from " + partner.getUrl());
                PartnerEntries partnerEntries = remoteEntries.getPublicEntries(partner.getId(), 0, Integer.MAX_VALUE, null, true);
                Results<PartData> webEntries = partnerEntries.getEntries();
                if (webEntries == null || webEntries.getData() == null) {
                    Logger.error("Could not retrieve entries for " + partner.getUrl());
                    continue;
                }
                Logger.info("Obtained " + webEntries.getResultCount() + " from " + partner.getUrl());
                // go through entries for each partner and write to the zip file
                writeDataEntries(partner, webEntries.getData(), fields, writer, zos);
            } catch (Exception e) {
                Logger.warn("Exception retrieving entries " + e.getMessage());
            }
        }
        // write local entries
        if (this.includeLocal) {
            Logger.info("Retrieving local public entries");
            Group publicGroup = new GroupController().createOrRetrievePublicGroup();
            Set<Group> groups = new HashSet<>();
            groups.add(publicGroup);
            EntryDAO entryDAO = DAOFactory.getEntryDAO();
            List<Entry> results = entryDAO.retrieveVisibleEntries(null, groups, ColumnField.CREATED, true, 0, Integer.MAX_VALUE, null);
            writeLocalEntries(results, fields, writer, zos);
        }
        // write the csv file to the zip
        writeZip(tmpZip, zos);
    }
    return true;
}
Also used : Path(java.nio.file.Path) GroupController(org.jbei.ice.lib.group.GroupController) PartnerEntries(org.jbei.ice.lib.dto.web.PartnerEntries) CSVWriter(com.opencsv.CSVWriter) EntryField(org.jbei.ice.lib.dto.entry.EntryField) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO) ZipEntry(java.util.zip.ZipEntry) ZipOutputStream(java.util.zip.ZipOutputStream) PartData(org.jbei.ice.lib.dto.entry.PartData) HashSet(java.util.HashSet)

Example 9 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO in project ice by JBEI.

the class RemoteTransferTest method testGetPartsForTransfer.

@Test
public void testGetPartsForTransfer() throws Exception {
    EntryDAO dao = DAOFactory.getEntryDAO();
    Account account = AccountCreator.createTestAccount("testGetPartsForTransfer", false);
    Strain strain = TestEntryCreator.createTestStrain(account);
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
    strain.getLinkedEntries().add(plasmid);
    DAOFactory.getEntryDAO().update(strain);
    strain = (Strain) DAOFactory.getEntryDAO().get(strain.getId());
    Assert.assertTrue(strain.getLinkedEntries().size() == 1);
    Plasmid plasmid2 = TestEntryCreator.createTestPlasmid(account);
    strain.getLinkedEntries().add(plasmid2);
    dao.update(strain);
    Plasmid plasmid3 = TestEntryCreator.createTestPlasmid(account);
    Strain strain2 = TestEntryCreator.createTestStrain(account);
    strain2.getLinkedEntries().add(plasmid2);
    strain2.getLinkedEntries().add(plasmid3);
    dao.update(strain2);
    ArrayList<Long> ids = new ArrayList<>();
    ids.add(plasmid.getId());
    ids.add(plasmid2.getId());
    ids.add(plasmid3.getId());
    ids.add(strain.getId());
    ids.add(strain2.getId());
    List<PartData> data = transfer.getPartsForTransfer(ids);
    TransferredParts parts = new TransferredParts();
    Assert.assertEquals(data.size(), 2);
    for (PartData datum : data) {
        // both should have 2 linked entries with 1 in common
        Assert.assertEquals(datum.getLinkedParts().size(), 2);
        // transfer
        datum.setRecordId("");
        PartData transferred = parts.receiveTransferredEntry(datum);
        Assert.assertNotNull(transferred);
    }
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) ArrayList(java.util.ArrayList) PartData(org.jbei.ice.lib.dto.entry.PartData) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Aggregations

EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)9 Entry (org.jbei.ice.storage.model.Entry)5 PermissionException (org.jbei.ice.lib.access.PermissionException)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 GroupController (org.jbei.ice.lib.group.GroupController)3 Account (org.jbei.ice.storage.model.Account)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ShotgunSequenceDAO (org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO)2 Group (org.jbei.ice.storage.model.Group)2 Test (org.junit.Test)2 CSVWriter (com.opencsv.CSVWriter)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 ShotgunSequenceDTO (org.jbei.ice.lib.dto.ShotgunSequenceDTO)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1 EntryType (org.jbei.ice.lib.dto.entry.EntryType)1