Search in sources :

Example 1 with PartnerEntries

use of org.jbei.ice.lib.dto.web.PartnerEntries in project ice by JBEI.

the class RemoteEntries method getPublicEntries.

public PartnerEntries getPublicEntries(long remoteId, int offset, int limit, String sort, boolean asc) {
    if (!hasRemoteAccessEnabled())
        return null;
    RemotePartner partner = this.remotePartnerDAO.get(remoteId);
    if (partner == null)
        return null;
    FolderDetails details;
    try {
        final String restPath = "rest/folders/public/entries";
        HashMap<String, Object> queryParams = new HashMap<>();
        queryParams.put("offset", offset);
        queryParams.put("limit", limit);
        queryParams.put("asc", asc);
        queryParams.put("sort", sort);
        details = this.remoteContact.getFolderEntries(partner.getUrl(), restPath, queryParams, partner.getApiKey());
        if (details == null)
            return null;
    } catch (Exception e) {
        Logger.error(e);
        return null;
    }
    Results<PartData> results = new Results<>();
    results.setData(details.getEntries());
    results.setResultCount(details.getCount());
    return new PartnerEntries(partner.toDataTransferObject(), results);
}
Also used : HashMap(java.util.HashMap) Results(org.jbei.ice.lib.dto.common.Results) RemotePartner(org.jbei.ice.storage.model.RemotePartner) PartData(org.jbei.ice.lib.dto.entry.PartData) PartnerEntries(org.jbei.ice.lib.dto.web.PartnerEntries) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PermissionException(org.jbei.ice.lib.access.PermissionException)

Example 2 with PartnerEntries

use of org.jbei.ice.lib.dto.web.PartnerEntries in project ice by JBEI.

the class PartnerResource method getWebEntries.

/**
     * Retrieves entries for specified partner using the specified paging parameters
     *
     * @param partnerId unique identifier for registry partner whose entries are being retrieved
     * @param offset    record retrieve offset paging parameter
     * @param limit     maximum number of entries to retrieve
     * @param sort      field to sort on
     * @param asc       sort order
     * @return Response with public entries from registry partners
     */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entries")
public Response getWebEntries(@PathParam("id") final long partnerId, @DefaultValue("0") @QueryParam("offset") final int offset, @DefaultValue("15") @QueryParam("limit") final int limit, @DefaultValue("created") @QueryParam("sort") final String sort, @DefaultValue("false") @QueryParam("asc") final boolean asc) {
    requireUserId();
    RemoteEntries remoteEntries = new RemoteEntries();
    PartnerEntries entries = remoteEntries.getPublicEntries(partnerId, offset, limit, sort, asc);
    return super.respond(Response.Status.OK, entries);
}
Also used : PartnerEntries(org.jbei.ice.lib.dto.web.PartnerEntries)

Example 3 with PartnerEntries

use of org.jbei.ice.lib.dto.web.PartnerEntries 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)

Aggregations

PartnerEntries (org.jbei.ice.lib.dto.web.PartnerEntries)3 PartData (org.jbei.ice.lib.dto.entry.PartData)2 CSVWriter (com.opencsv.CSVWriter)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 PermissionException (org.jbei.ice.lib.access.PermissionException)1 Results (org.jbei.ice.lib.dto.common.Results)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)1 GroupController (org.jbei.ice.lib.group.GroupController)1 EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)1 RemotePartner (org.jbei.ice.storage.model.RemotePartner)1