public HarvestResource() { storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); harvestFileMapService = (HarvestFileMapService) ApplicationContextProvider.getApplicationContext() .getBean("harvestFileMapService"); }
/** * Initial load of the authorized key map * * @throws IOException */ public HarvestFileMapService() throws IOException { storage = (SpringStorageWrapper)ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); }
public TokenBasedVerifier() { apiKeyTokenService = (ApiKeyTokenService)ApplicationContextProvider.getApplicationContext().getBean("apiKeyTokenService"); }
public ObjectResource() { harvestFileMapService = (HarvestFileMapService) ApplicationContextProvider.getApplicationContext() .getBean("harvestFileMapService"); gson = new GsonBuilder().create(); }
private void setConfig(JsonSimple config) throws AccessControlException { log.debug("Access control getting config..."); this.config = config; if (!ApplicationContextProvider.getApplicationContext().containsBean("hibernateAccessControlService")) { throw new AccessControlException("hibernateAccessControlService bean not available, please check your Spring configuration."); } hibernateService = (HibernateAccessControlService) ApplicationContextProvider.getApplicationContext().getBean("hibernateAccessControlService"); }
@ApiOperation(value = "Delete an existing ReDBox object", tags = "object") @ApiResponses({ @ApiResponse(code = 200, message = "The object is deleted"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Delete public String deleteObjectResource() throws IOException, PluginException, MessagingException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); Indexer indexer = (Indexer) ApplicationContextProvider.getApplicationContext().getBean("fascinatorIndexer"); String oid = getAttribute("oid"); storage.removeObject(oid); indexer.remove(oid); return getSuccessResponseString(oid); } }
.getApplicationContext().getBean("fascinatorRoleManager");
.authenticate(token); HibernateUserService hibernateAuthUserService = (HibernateUserService) ApplicationContextProvider .getApplicationContext().getBean( "hibernateAuthUserService"); log.debug("Auth manager adding user through hibernate...");
private String findStorageId(String harvestId, String packageType) throws IndexerException, IOException { Indexer indexer = (Indexer) ApplicationContextProvider.getApplicationContext().getBean("fascinatorIndexer"); SearchRequest request = new SearchRequest("harvestId:\"" + harvestId + "\""); request.addParam("fq", "packageType:" + packageType); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); indexer.search(request, byteArrayOutputStream); SolrResult results = new SolrResult(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); int rows = results.getRows(); if (rows == 0) { return null; } else { return results.getResults().get(0).getString(null, "storage_id"); } }
if (ApplicationContextProvider.getApplicationContext() != null) { scriptingServices = ApplicationContextProvider .getApplicationContext().getBean("scriptingServices", ScriptingServices.class);
@ApiOperation(value = "Search ReDBox's search index", tags = "search") @ApiResponses({ @ApiResponse(code = 200, message = "Search results returned"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Get public Representation searchIndex() throws IndexerException, IOException{ Indexer indexer = (Indexer) ApplicationContextProvider.getApplicationContext().getBean("fascinatorIndexer"); String query = getQueryValue("q"); String responseFormat = getQueryValue("wt"); //default solr response to json if(StringUtils.isBlank(responseFormat)) { responseFormat = "json"; } SearchRequest request = new SearchRequest(query); request.addParam("wt", responseFormat); Form form = getQuery(); Iterator<Parameter> formInterator = form.iterator(); while(formInterator.hasNext()) { Parameter param = formInterator.next(); if(!"q".equals(param.getName()) && !"wt".equals(param.getName())){ request.addParam(param.getName(), param.getValue()); } } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); indexer.search(request, byteArrayOutputStream); return new StringRepresentation(new String(byteArrayOutputStream.toByteArray(),Charset.forName("utf-8"))); }
@ApiOperation(value = "gets the record's Object Metadata", tags="objectmeta") @ApiResponses({ @ApiResponse(code = 200, message = "The object metadata is returned"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Get("json") public String getMetadataResource() throws StorageException, IOException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); Properties metadata = digitalObject.getMetadata(); JsonObject jsonObject = new JsonObject(); for (Object keyObject : metadata.keySet()) { jsonObject.put((String) keyObject, metadata.getProperty((String) keyObject)); } return new JsonSimple(jsonObject).toString(true); }
@ApiOperation(value = "updates the record's Object Metadata", tags="objectmeta") @ApiImplicitParams({ @ApiImplicitParam(name = "skipReindex", value="Skip the reindex process. Useful if you are batching many changes to a ReDBox object at once.", required = false, allowMultiple = false, defaultValue = "false", dataType = "string") }) @ApiResponses({ @ApiResponse(code = 200, message = "The object metadata is updated"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Post("json") public String updateMetadataResource(JsonRepresentation data) throws IOException, PluginException, MessagingException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); JsonSimple metadataJson = new JsonSimple(data.getText()); JsonObject metadataObject = metadataJson.getJsonObject(); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); Properties metadata = digitalObject.getMetadata(); for (Object key : metadataObject.keySet()) { metadata.setProperty((String) key, (String) metadataObject.get(key)); } ByteArrayOutputStream output = new ByteArrayOutputStream(); metadata.store(output, null); ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); StorageUtils.createOrUpdatePayload(digitalObject, "TF-OBJ-META", input); reindex(oid); return getSuccessResponseString(oid); }
@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()); }
@ApiOperation(value = "Search ReDBox's search index", tags = "search") @ApiResponses({ @ApiResponse(code = 200, message = "Search results returned"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Get public JsonRepresentation searchIndex() throws IndexerException, IOException{ Indexer indexer = (Indexer) ApplicationContextProvider.getApplicationContext().getBean("fascinatorIndexer"); String indexName = getAttribute("index"); String query = getQueryValue("q"); SearchRequest request = new SearchRequest(query); Form form = getQuery(); Iterator<Parameter> formInterator = form.iterator(); while(formInterator.hasNext()) { Parameter param = formInterator.next(); if(!"q".equals(param.getName())){ request.addParam(param.getName(), param.getValue()); } } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); indexer.searchByIndex(request, byteArrayOutputStream,indexName); return new JsonRepresentation(new JsonSimple(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())).toString()); }
@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()); } }
@ApiOperation(value = "updates the record's metadata", tags = "recordmeta") @ApiImplicitParams({ @ApiImplicitParam(name = "skipReindex", value = "Skip the reindex process. Useful if you are batching many changes to a ReDBox object at once.", required = false, allowMultiple = false, defaultValue = "false", dataType = "string") }) @ApiResponses({ @ApiResponse(code = 200, message = "The record's metadata is updated"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Post("json") public String updateMetadataResource(JsonRepresentation data) throws IOException, PluginException, MessagingException { JsonSimpleConfig config = new JsonSimpleConfig(); Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); JsonSimple metadataJson = new JsonSimple(data.getText()); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); String payloadId; if ("mint".equals(config.getString(null, "system"))) { payloadId = "metadata.json"; } else { payloadId = findTfPackagePayload(digitalObject); } StorageUtils.createOrUpdatePayload(digitalObject, payloadId, IOUtils.toInputStream(metadataJson.toString(true), "UTF-8")); reindex(oid); return getSuccessResponseString(oid); }
@ApiOperation(value = "Delete a datastream in a ReDBox object", tags = "datastream") @ApiImplicitParams({ @ApiImplicitParam(name = "skipReindex", value="Skip the reindex process. Useful if you are batching many changes to a ReDBox object at once.", required = false, allowMultiple = false, defaultValue = "false", dataType = "string"), @ApiImplicitParam(name = "datastreamId", value="The identifier of the datastream", required = true, allowMultiple = false, dataType = "string") }) @Delete public String deleteDatastream() throws FileUploadException, IOException, PluginException, MessagingException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); String payloadId = getQueryValue("datastreamId"); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); try { @SuppressWarnings("unused") Payload payload = digitalObject.getPayload(payloadId); } catch (StorageException e) { throw new ResourceException(404, e, "Datastream does not exist in the object"); } digitalObject.removePayload(payloadId); reindex(oid); return getSuccessResponseString(oid); }
@SuppressWarnings("unchecked") @ApiOperation(value = "List datastreams in an object", tags = "datastream") @ApiResponses({ @ApiResponse(code = 200, message = "The datastreams are listed"), @ApiResponse(code = 500, message = "Oid does not exist in storage", response = StorageException.class) }) @Get("json") public JsonRepresentation getDatastreamList() throws StorageException, IOException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); JsonObject responseObject = getSuccessResponse(oid); JSONArray dataStreamIds = new JSONArray(); dataStreamIds.addAll(digitalObject.getPayloadIdList()); responseObject.put("datastreamIds", dataStreamIds); return new JsonRepresentation(new JsonSimple(responseObject).toString(true)); }
@ApiOperation(value = "Create or update a datastream in a ReDBox object", tags = "datastream") @ApiImplicitParams({ @ApiImplicitParam(name = "skipReindex", value="Skip the reindex process. Useful if you are batching many changes to a ReDBox object at once.", required = false, allowMultiple = false, defaultValue = "false", dataType = "string"), @ApiImplicitParam(name = "datastreamId", value="The identifier of the datastream", required = true, allowMultiple = false, dataType = "string") }) @ApiResponses({ @ApiResponse(code = 200, message = "The datastream is created or updated"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Post public String updateDatastream(Representation entity) throws FileUploadException, IOException, PluginException, MessagingException { if (entity != null && MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); String payloadId = getQueryValue("datastreamId"); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(1000240); RestletFileUpload upload = new RestletFileUpload(factory); FileItemIterator fileIterator = upload.getItemIterator(entity); while (fileIterator.hasNext()) { FileItemStream fi = fileIterator.next(); StorageUtils.createOrUpdatePayload(digitalObject, payloadId, fi.openStream()); } reindex(oid); return getSuccessResponseString(oid); } else { throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE); } }