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