use of org.jbei.ice.lib.dto.entry.EntryFieldLabel in project ice by JBEI.
the class RemoteEntriesAsCSV method getCSVHeaders.
protected String[] getCSVHeaders(List<EntryFieldLabel> fields) {
String[] headers = new String[fields.size() + 4];
headers[0] = "Registry";
headers[1] = "Created";
headers[2] = "Part ID";
int i = 2;
for (EntryFieldLabel field : fields) {
i += 1;
headers[i] = field.getLabel();
}
headers[i + 1] = "Sequence File";
return headers;
}
use of org.jbei.ice.lib.dto.entry.EntryFieldLabel 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<EntryFieldLabel> 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<Long> 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;
}
Aggregations