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