/** * get the fedora describe xml. * * @return The HttpMethod after the service call . * @throws Exception If the service call fails. */ public String describeFedora() throws Exception { com.yourmediashelf.fedora.client.FedoraClient restClient = getFedoraRestClient(); FedoraResponse response = com.yourmediashelf.fedora.client.FedoraClient.describeRepository() .xml(true) .execute(restClient); return toString(response.getEntityInputStream()); }
/** * get a binary datastream as String. * * @param id the id of the resource. * @param componentId the id of the component. * @return The Stream as String. * @throws Exception If the service call fails. */ public String getDatastreamDissimination(final String id, final String componentId) throws Exception { com.yourmediashelf.fedora.client.FedoraClient restClient = getFedoraRestClient(); FedoraResponse response = com.yourmediashelf.fedora.client.FedoraClient.getDatastreamDissemination(id, componentId) .execute(restClient); return toString(response.getEntityInputStream()); }
/** * get a resource xml. * * @param id the id of the resource. * @return The FOXML as String. * @throws Exception If the service call fails. */ public String export(final String id) throws Exception { com.yourmediashelf.fedora.client.FedoraClient restClient = getFedoraRestClient(); FedoraResponse response = com.yourmediashelf.fedora.client.FedoraClient.export(id) .format(Constants.FOXML_FORMAT) .context("public") .execute(restClient); return toString(response.getEntityInputStream()); }
protected void naiveGetDatastreams(Set<String> pids, Set<String> dsids) throws Exception { FedoraResponse response = null; for (String pid : pids) { for (String dsid : dsids) { response = getDatastreamDissemination(pid, dsid).execute(); assertEquals(200, response.getStatus()); response.getEntity(String.class); response.close(); } } }
/** * purgeRelationship should be idempotent with respect to the returned HTTP status code. The * response body however, should indicate "false" for successive deletes of the same resource. * * @throws Exception */ @Test public void testIdempotency() throws Exception { FedoraResponse response = null; Model model = null; Statement s = null; String subject = String.format("info:fedora/%s", testPid); String predicate = "urn:foo/p"; String object = "你好"; // first add a relationship response = addRelationship(testPid).predicate(predicate).object(object, true).execute(); assertEquals(200, response.getStatus()); // verify it was added response = getRelationships(testPid).predicate(predicate).execute(); assertEquals(200, response.getStatus()); model = ModelFactory.createDefaultModel(); model.read(response.getEntityInputStream(), null, FileUtils.langXML); StmtIterator it = model.listStatements(); while (it.hasNext()) { s = it.next(); assertEquals(subject, s.getSubject().toString()); assertEquals(predicate, s.getPredicate().toString()); assertEquals(object, s.getObject().toString()); } // now delete it response = purgeRelationship(testPid).predicate(predicate).object(object, true).execute(); assertEquals(200, response.getStatus()); assertEquals("true", response.getEntity(String.class)); // verify it's gone response = getRelationships(testPid).predicate(predicate).execute(); assertEquals(200, response.getStatus()); model = ModelFactory.createDefaultModel(); model.read(response.getEntityInputStream(), null, FileUtils.langXML); it = model.listStatements(); while (it.hasNext()) { s = it.next(); assertFalse(predicate.equals(s.getPredicate().toString())); assertFalse(object.equals(s.getObject().toString())); } response = purgeRelationship(testPid).predicate(predicate).object(object, true).execute(); assertEquals(200, response.getStatus()); assertEquals("false", response.getEntity(String.class)); }