Search in sources :

Example 11 with EntryFieldLabel

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

Example 12 with EntryFieldLabel

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;
}
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) EntryFieldLabel(org.jbei.ice.lib.dto.entry.EntryFieldLabel) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO) ZipOutputStream(java.util.zip.ZipOutputStream) PartData(org.jbei.ice.lib.dto.entry.PartData) HashSet(java.util.HashSet)

Aggregations

EntryFieldLabel (org.jbei.ice.lib.dto.entry.EntryFieldLabel)12 PartData (org.jbei.ice.lib.dto.entry.PartData)5 ZipEntry (java.util.zip.ZipEntry)4 HashSet (java.util.HashSet)3 InputStreamWrapper (org.jbei.ice.lib.entry.sequence.InputStreamWrapper)3 Entry (org.jbei.ice.storage.model.Entry)3 CSVWriter (com.opencsv.CSVWriter)2 Path (java.nio.file.Path)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)2 GenbankFormatter (org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter)2 GroupController (org.jbei.ice.lib.group.GroupController)2 Account (org.jbei.ice.storage.model.Account)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ZipInputStream (java.util.zip.ZipInputStream)1 Setting (org.jbei.ice.lib.dto.Setting)1