/** * Get a playload in JsonSimple format from the payload instance * * @param payload : Payload object * @return JsonSimple or null */ public JsonSimple getPayloadJsonSimple(Payload payload) { JsonSimple jsonSimple = null; if (payload == null) { return null; } try { jsonSimple = new JsonSimple(payload.open()); } catch (Exception e) { log.error("Failed to retrive payload. ID of payload: {}, more: {}", payload.getId(), e.getMessage()); } return jsonSimple; }
/***** * Parse an XML document stored in a payload * * @param payload holding the document * @return Document object after parsing */ public Document getXmlDocument(Payload payload) { try { Document doc = getXmlDocument(payload.open()); payload.close(); return doc; } catch (StorageException ex) { log.error("Failed to access payload", ex); } return null; }
/***** * Parse RDF data stored in a payload * * @param payload containing the data * @return Model object after parsing */ public Model getRdfModel(Payload payload) { try { Model model = getRdfModel(payload.open()); payload.close(); return model; } catch (StorageException ioe) { log.info("Failed to read payload stream", ioe); } return null; }
/** * Retrieve the payload from storage and return as a byte array. * * @param object Our digital object. * @param pid The payload ID to retrieve. * @return byte[] The byte array containing payload data * @throws Exception on any errors */ private byte[] getBytes(DigitalObject object, String pid) throws Exception { // These can happily throw exceptions higher Payload payload = object.getPayload(pid); InputStream in = payload.open(); byte[] result = null; // But here, the payload must receive // a close before throwing the error try { result = IOUtils.toByteArray(in); } catch (Exception ex) { throw ex; } finally { payload.close(); } return result; }
/** * Retrieve the payload from storage and return as a byte array. * * @param object : Our digital object. * @param pid : The payload ID to retrieve. * @return byte[] : The byte array containing payload data * @throws Exception on any errors */ private byte[] getBytes(DigitalObject object, String pid) throws Exception { // These can happily throw exceptions higher Payload payload = object.getPayload(pid); InputStream in = payload.open(); byte[] result = null; // But here, the payload must receive // a close before throwing the error try { result = IOUtils.toByteArray(in); } catch (Exception ex) { throw ex; } finally { payload.close(); } return result; }
return new JsonSimple(payload.open()); } catch (IOException ex) { log.error("Error parsing data '{}': ", pid, ex);
configFile = File.createTempFile("reharvest", ".json"); OutputStream out = new FileOutputStream(configFile); IOUtils.copy(payload.open(), out); out.close(); payload.close();
return new JsonSimple(payload.open()); } catch (IOException ex) { log.error("Error parsing data '{}': ", oid, ex);
InputStream in = payload.open(); FileOutputStream out = null;
InputStream in = payload.open(); FileOutputStream out = null;
/** * Get the stored data from storage for the indicated object. * * @param oid The object we want */ private JsonSimple getDataFromStorage(String oid) { // Get our data from Storage Payload payload = null; try { DigitalObject object = storage.getObject(oid); payload = object.getPayload(DATA_PAYLOAD_ID); } catch (StorageException ex) { log.error("Error accessing object '{}' in storage: ", oid, ex); return null; } // Parse the JSON try { try { return new JsonSimple(payload.open()); } catch (IOException ex) { log.error("Error parsing data '{}': ", oid, ex); return null; } finally { payload.close(); } } catch (StorageException ex) { log.error("Error accessing data '{}' in storage: ", oid, ex); return null; } }
return FormDataParser.parse(payload.open()); } catch (IOException ex) { log.error("Error parsing data '{}': ", oid, ex);
return new JsonSimple(payload.open()); } catch (IOException ex) { log.error("Error parsing workflow '{}': ", oid, ex);
Payload payload = object.getPayload(configPid); try { return new JsonSimple(payload.open()); } catch (IOException ex) { log.error("Error accessing config '{}' in storage: ",
Payload payload = object.getPayload(configPid); try { return new JsonSimple(payload.open()); } catch (IOException ex) { log.error("Error accessing config '{}' in storage: ",
Payload payload = object.getPayload(object.getSourceId()); log.debug("First time parsing config file: '{}'", oid); configFile = new JsonSimpleConfig(payload.open()); payload.close(); cacheConfig(oid, configFile);
@ApiOperation(value = "gets the record's metadata", tags = "recordmeta") @ApiResponses({ @ApiResponse(code = 200, message = "The record's metadata is returned"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Get("json") public String getMetadataResource() throws StorageException, IOException { JsonSimpleConfig config = new JsonSimpleConfig(); Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); String payloadId; if ("mint".equals(config.getString(null, "system"))) { payloadId = "metadata.json"; } else { payloadId = findTfPackagePayload(digitalObject); } Payload payload = digitalObject.getPayload(payloadId); JsonSimple metadataObject = new JsonSimple(payload.open()); return gson.toJson(metadataObject.getJsonObject()); }
/** * Creates a copy of the specified payload * * @param payload payload to copy */ public GenericPayload(Payload payload) { if (payload != null) { setId(payload.getId()); setLabel(payload.getLabel()); setContentType(payload.getContentType()); setType(payload.getType()); try { setInputStream(payload.open()); } catch (StorageException e) { log.error( "Error accessing input stream during payload creation", e); } } metaChanged = false; }
try { Payload workflowPayload = in.getPayload("workflow.metadata"); workflow = new JsonSimple(workflowPayload.open()); workflowPayload.close(); } catch (StorageException ex) {
@ApiOperation(value = "Get a datastream from a ReDBox object", tags = "datastream") @ApiImplicitParams({ @ApiImplicitParam(name = "datastreamId", value="The identifier of the datastream", required = true, allowMultiple = false, dataType = "string") }) @ApiResponses({ @ApiResponse(code = 200, message = "The datastream is retrieved"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Get("application/octet-stream") public Representation getDatastream() throws IOException { try { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); String payloadId = getQueryValue("datastreamId"); if (payloadId != null) { DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); Payload payload = digitalObject.getPayload(payloadId); return new ByteArrayRepresentation(IOUtils.toByteArray(payload.open())); } else { throw new ResourceException(400, "Call requires a datastreamId value"); } } catch (StorageException e) { throw new ResourceException(500, e, e.getMessage()); } }