本文整理汇总了Java中org.fcrepo.client.FcrepoOperationFailedException类的典型用法代码示例。如果您正苦于以下问题:Java FcrepoOperationFailedException类的具体用法?Java FcrepoOperationFailedException怎么用?Java FcrepoOperationFailedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FcrepoOperationFailedException类属于org.fcrepo.client包,在下文中一共展示了FcrepoOperationFailedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterBinaryReferences
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
/**
* Filter out the binary resource references from the model
* @param uri the URI for the resource
* @param model the RDF Model of the resource
* @return the RDF model with no binary references
* @throws FcrepoOperationFailedException
* @throws IOException
*/
private void filterBinaryReferences(final URI uri, final Model model) throws IOException,
FcrepoOperationFailedException {
final List<Statement> removeList = new ArrayList<>();
for (final StmtIterator it = model.listStatements(); it.hasNext();) {
final Statement s = it.nextStatement();
final RDFNode obj = s.getObject();
if (obj.isResource() && obj.toString().startsWith(repositoryRoot.toString())
&& !s.getPredicate().toString().equals(REPOSITORY_NAMESPACE + "hasTransactionProvider")) {
try (final FcrepoResponse resp = client().head(URI.create(obj.toString())).disableRedirects()
.perform()) {
checkValidResponse(resp, URI.create(obj.toString()), config.getUsername());
final List<URI> linkHeaders = resp.getLinkHeaders("type");
if (linkHeaders.contains(binaryURI)) {
removeList.add(s);
}
}
}
}
model.remove(removeList);
}
示例2: writeResponse
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
void writeResponse(final URI uri, final InputStream in, final List<URI> describedby, final File file)
throws IOException, FcrepoOperationFailedException {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
try (OutputStream out = new FileOutputStream(file)) {
copy(in, out);
logger.info("Exported {} to {}", uri, file.getAbsolutePath());
if (md5FileMap != null) {
md5FileMap.put(file, new String(encodeHex(md5.digest())));
}
if (sha1FileMap != null) {
sha1FileMap.put(file, new String(encodeHex(sha1.digest())));
}
if (sha256FileMap != null) {
sha256FileMap.put(file, new String(encodeHex(sha256.digest())));
}
}
if (describedby != null) {
for (final Iterator<URI> it = describedby.iterator(); it.hasNext(); ) {
exportDescription(it.next(), uri);
}
}
}
示例3: importBinary
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
private FcrepoResponse importBinary(final URI binaryURI, final Model model)
throws FcrepoOperationFailedException, IOException {
final String contentType = model.getProperty(createResource(binaryURI.toString()), HAS_MIME_TYPE).getString();
final File binaryFile = fileForBinaryURI(binaryURI, external(contentType));
final FcrepoResponse binaryResponse = binaryBuilder(binaryURI, binaryFile, contentType, model).perform();
if (binaryResponse.getStatusCode() == 201 || binaryResponse.getStatusCode() == 204) {
logger.info("Imported binary: {}", binaryURI);
importLogger.info("import {} to {}", binaryFile.getAbsolutePath(), binaryURI);
successCount.incrementAndGet();
final URI descriptionURI = binaryResponse.getLinkHeaders("describedby").get(0);
return client().put(descriptionURI).body(modelToStream(sanitize(model)), config.getRdfLanguage())
.preferLenient().perform();
} else if (binaryResponse.getStatusCode() == 410 && config.overwriteTombstones()) {
deleteTombstone(binaryResponse);
return binaryBuilder(binaryURI, binaryFile, contentType, model).perform();
} else {
logger.error("Error while importing {} ({}): {}", binaryFile.getAbsolutePath(),
binaryResponse.getStatusCode(), IOUtils.toString(binaryResponse.getBody()));
return null;
}
}
示例4: binaryBuilder
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
private PutBuilder binaryBuilder(final URI binaryURI, final File binaryFile, final String contentType,
final Model model) throws FcrepoOperationFailedException, IOException {
final InputStream contentStream;
if (external(contentType)) {
contentStream = new ByteArrayInputStream(new byte[]{});
} else {
contentStream = new FileInputStream(binaryFile);
}
PutBuilder builder = client().put(binaryURI).filename(null)
.body(contentStream, contentType)
.ifUnmodifiedSince(currentTimestamp());
if (!external(contentType)) {
if (sha1FileMap != null) {
// Use the bagIt checksum
final String checksum = sha1FileMap.get(binaryFile.getAbsolutePath());
logger.debug("Using Bagit checksum ({}) for file ({}): {}", checksum, binaryFile.getPath(), binaryURI);
builder = builder.digest(checksum);
} else {
builder = builder.digest(model.getProperty(createResource(binaryURI.toString()), HAS_MESSAGE_DIGEST)
.getObject().toString().replaceAll(".*:",""));
}
}
return builder;
}
示例5: sanitize
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
/**
* Removes statements from the provided model that affect triples that need not be (and indeed
* cannot be) modified directly through PUT, POST or PATCH requests to fedora.
*
* Certain triples included in a resource from fedora cannot be explicitly stored, but because
* they're derived from other content that *can* be stored will still appear identical when the
* other RDF and content is ingested. Examples include those properties that reflect innate
* characteristics of binary resources like file size and message digest, Or triples that
* represent characteristics of rdf resources like the number of children, whether it has
* versions and some of the types.
*
* @param model the RDF statements about an exported resource
* @return the provided model updated to omit statements that may not be updated directly through
* the fedora API
* @throws IOException
* @throws FcrepoOperationFailedException
*/
private Model sanitize(final Model model) throws IOException, FcrepoOperationFailedException {
final List<Statement> remove = new ArrayList<>();
for (final StmtIterator it = model.listStatements(); it.hasNext(); ) {
final Statement s = it.nextStatement();
if ((s.getPredicate().getNameSpace().equals(REPOSITORY_NAMESPACE) && !relaxedPredicate(s.getPredicate()))
|| s.getSubject().getURI().endsWith("fcr:export?format=jcr/xml")
|| s.getSubject().getURI().equals(REPOSITORY_NAMESPACE + "jcr/xml")
|| s.getPredicate().equals(DESCRIBEDBY)
|| s.getPredicate().equals(CONTAINS)
|| s.getPredicate().equals(HAS_MESSAGE_DIGEST)
|| s.getPredicate().equals(HAS_SIZE)
|| (s.getPredicate().equals(RDF_TYPE) && forbiddenType(s.getResource()))) {
remove.add(s);
} else if (s.getObject().isResource()) {
// make sure that referenced repository objects exist
final String obj = s.getResource().toString();
if (obj.startsWith(repositoryRoot.toString())) {
ensureExists(URI.create(obj));
}
}
}
return model.remove(remove);
}
示例6: makePlaceholder
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
private void makePlaceholder(final URI uri) throws IOException, FcrepoOperationFailedException {
ensureExists(parent(uri));
final FcrepoResponse response;
if (fileForBinaryURI(uri, false).exists() || fileForBinaryURI(uri, true).exists()) {
response = client().put(uri).body(new ByteArrayInputStream(new byte[]{})).perform();
} else if (fileForContainerURI(uri).exists()) {
response = client().put(uri).body(new ByteArrayInputStream(
"<> a <http://www.w3.org/ns/ldp#Container> .".getBytes()), "text/turtle").perform();
} else {
return;
}
if (response.getStatusCode() != 201) {
logger.error("Unexpected response when creating {} ({}): {}", uri,
response.getStatusCode(), response.getBody());
}
}
示例7: isRepositoryRoot
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
/**
* Utility method to determine whether the current uri is repository root or not. The repository root is the
* container with type fcrepo:RepositoryRoot
* @param uri the URI for the resource
* @param client the FcrepoClient to query the repository
* @param config the Config for import/export
* @throws IOException if there is a error with the network connection
* @throws FcrepoOperationFailedException if there is a error with Fedora
* @return True if the URI is the root of the repository
*/
public static boolean isRepositoryRoot(final URI uri, final FcrepoClient client, final Config config)
throws IOException, FcrepoOperationFailedException {
final String userName = config.getUsername();
final String rdfLanguage = config.getRdfLanguage();
try (FcrepoResponse response = client.head(uri).disableRedirects().perform()) {
checkValidResponse(response, uri, userName);
// The repository root will not be a binary
if (response.getLinkHeaders("type").contains(URI.create(NON_RDF_SOURCE.getURI()))) {
return false;
}
try (FcrepoResponse resp = client.get(uri).accept(rdfLanguage).disableRedirects()
.perform()) {
final Model model = createDefaultModel().read(resp.getBody(), null, rdfLanguage);
if (model.contains(null, RDF_TYPE, REPOSITORY_ROOT)) {
return true;
}
}
}
return false;
}
示例8: testExportBinaryAndDescription
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
@Test
public void testExportBinaryAndDescription() throws Exception, FcrepoOperationFailedException {
final String basedir = exportDirectory + "/1";
final Config binaryArgs = new Config();
binaryArgs.setMode("export");
binaryArgs.setBaseDirectory(basedir);
binaryArgs.setIncludeBinaries(true);
binaryArgs.setPredicates(predicates);
binaryArgs.setRdfLanguage("application/ld+json");
binaryArgs.setResource(resource3);
when(headResponse.getLinkHeaders(eq("type"))).thenReturn(binaryLinks);
when(headResponse.getLinkHeaders(eq("describedby"))).thenReturn(describedbyLinks);
final ExporterWrapper exporter = new ExporterWrapper(binaryArgs, clientBuilder);
exporter.run();
Assert.assertTrue(exporter.wroteFile(new File(basedir + "/rest/file1" + BINARY_EXTENSION)));
Assert.assertTrue(exporter.wroteFile(new File(basedir + "/rest/file1/fcr%3Ametadata.jsonld")));
Assert.assertTrue(exporter.wroteFile(new File(basedir + "/rest/alt_description.jsonld")));
}
示例9: testExportApTrustBag
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
@Test
public void testExportApTrustBag() throws Exception, FcrepoOperationFailedException {
final Config bagArgs = createAptrustBagConfig();
bagArgs.setBagConfigPath("src/test/resources/configs/bagit-config.yml");
final ExporterWrapper exporter = new ExporterWrapper(bagArgs, clientBuilder);
when(headResponse.getLinkHeaders(eq("type"))).thenReturn(binaryLinks);
when(headResponse.getLinkHeaders(eq("describedby"))).thenReturn(describedbyLinks);
when(headResponse.getContentType()).thenReturn("image/tiff");
exporter.run();
Assert.assertTrue(exporter.wroteFile(new File(exportDirectory + "/data/rest/file1" + BINARY_EXTENSION)));
Assert.assertTrue(exporter.wroteFile(new File(exportDirectory + "/data/rest/file1/fcr%3Ametadata.jsonld")));
Assert.assertTrue(exporter.wroteFile(new File(exportDirectory + "/data/rest/alt_description.jsonld")));
final File baginfo = new File(exportDirectory + "/aptrust-info.txt");
Assert.assertTrue(baginfo.exists());
final List<String> baginfoLines = readLines(baginfo, UTF_8);
Assert.assertTrue(baginfoLines.contains("Access: Restricted"));
Assert.assertTrue(baginfoLines.contains("Title: My Title"));
}
示例10: testExportNoBinaryAndDescription
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
@Test
public void testExportNoBinaryAndDescription() throws Exception, FcrepoOperationFailedException {
final String basedir = exportDirectory + "/3";
final Config noBinaryArgs = new Config();
noBinaryArgs.setMode("export");
noBinaryArgs.setBaseDirectory(basedir);
noBinaryArgs.setIncludeBinaries(false);
noBinaryArgs.setPredicates(predicates);
noBinaryArgs.setRdfLanguage("application/ld+json");
noBinaryArgs.setResource(resource3);
final ExporterWrapper exporter = new ExporterWrapper(noBinaryArgs, clientBuilder);
when(headResponse.getContentType()).thenReturn("image/tiff");
exporter.run();
Assert.assertFalse(exporter.wroteFile(new File(basedir + "/rest/file1" + BINARY_EXTENSION)));
Assert.assertFalse(exporter.wroteFile(new File(basedir + "/rest/file1/fcr%3Ametadata.jsonld")));
Assert.assertFalse(exporter.wroteFile(new File(basedir + "/rest/alt_description.jsonld")));
}
示例11: testExportBagCustomTags
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
@Test
public void testExportBagCustomTags() throws Exception, FcrepoOperationFailedException {
final String basedir = exportDirectory + "/10";
final Config bagArgs = new Config();
bagArgs.setMode("export");
bagArgs.setBaseDirectory(basedir);
bagArgs.setIncludeBinaries(true);
bagArgs.setPredicates(predicates);
bagArgs.setRdfLanguage("application/ld+json");
bagArgs.setResource(resource3);
bagArgs.setBagProfile("default");
bagArgs.setBagConfigPath("src/test/resources/configs/bagit-config-custom-tagfile.yml");
final ExporterWrapper exporter = new ExporterWrapper(bagArgs, clientBuilder);
when(headResponse.getContentType()).thenReturn("image/tiff");
exporter.run();
final File customTags = new File(basedir + "/foo-info.txt");
Assert.assertTrue(customTags.exists());
final List<String> customLines = readLines(customTags, UTF_8);
Assert.assertTrue(customLines.contains("Foo: Bar"));
Assert.assertTrue(customLines.contains("Baz: Quux"));
}
示例12: mockGetResponse
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
/**
* Mocks a successful GET request response
*
* @param client client
* @param uri uri of destination being mocked
* @param typeLinks type links
* @param describedbyLinks described by links
* @param body body of response
* @throws FcrepoOperationFailedException client failures
*/
public static void mockGetResponse(final FcrepoClient client, final URI uri, final List<URI> typeLinks,
final List<URI> describedbyLinks, final String body) throws FcrepoOperationFailedException {
final GetBuilder getBuilder = mock(GetBuilder.class);
final FcrepoResponse getResponse = mock(FcrepoResponse.class);
when(client.get(eq(uri))).thenReturn(getBuilder);
when(getBuilder.accept(isA(String.class))).thenReturn(getBuilder);
when(getBuilder.disableRedirects()).thenReturn(getBuilder);
when(getBuilder.perform()).thenReturn(getResponse);
when(getResponse.getBody()).thenAnswer(new Answer<InputStream>() {
@Override
public InputStream answer(final InvocationOnMock invocation) throws Throwable {
return new ByteArrayInputStream(body.getBytes());
}
});
when(getResponse.getUrl()).thenReturn(uri);
when(getResponse.getLinkHeaders(eq("describedby"))).thenReturn(describedbyLinks);
when(getResponse.getStatusCode()).thenReturn(200);
when(getResponse.getLinkHeaders(eq("type"))).thenReturn(typeLinks);
}
示例13: incomingInterceptHeaderTest
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
@Test
public void incomingInterceptHeaderTest() throws Exception {
registerExtension(testResource("objects/extension_InterceptingModalityIT.ttl"));
registerService(testResource("objects/service_InterceptingServiceIT.ttl"));
final URI objectContainer_intercept = routing.of(REQUEST_URI).interceptUriFor(objectContainer);
// Have our extension service set an implausible If-Match header for the request
onServiceRequest(ex -> {
if (MODALITY_INTERCEPT_INCOMING.equals(ex.getIn().getHeader(HTTP_HEADER_MODALITY))) {
ex.getOut().setHeader("If-Match", "shall not match");
}
});
final URI object = postFromTestResource("objects/object_InterceptingServiceIT.ttl",
objectContainer_intercept);
try {
client.get(object).perform();
fail("Should have failed on If-Match mismatch");
} catch (final FcrepoOperationFailedException e) {
// expected
}
}
示例14: outgoingErrorTest
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
@Test
public void outgoingErrorTest() throws Exception {
registerExtension(testResource("objects/extension_InterceptingModalityIT.ttl"));
registerService(testResource("objects/service_InterceptingServiceIT.ttl"));
final URI objectContainer_intercept = routing.of(REQUEST_URI).interceptUriFor(objectContainer);
// Give our request a specific body
onServiceRequest(ex -> {
ex.setOut(ex.getIn());
if (MODALITY_INTERCEPT_OUTGOING.equals(ex.getIn().getHeader(HTTP_HEADER_MODALITY))) {
ex.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 418);
}
});
final URI object = postFromTestResource("objects/object_InterceptingServiceIT.ttl",
objectContainer_intercept);
try {
client.get(object).accept("application/n-triples").perform();
} catch (final FcrepoOperationFailedException e) {
assertEquals(418, e.getStatusCode());
}
}
示例15: process
import org.fcrepo.client.FcrepoOperationFailedException; //导入依赖的package包/类
/**
* Define how message exchanges are processed.
*
* @param exchange the InOut message exchange
* @throws FcrepoOperationFailedException when the underlying HTTP request results in an error
*/
@Override
public void process(final Exchange exchange) throws FcrepoOperationFailedException {
if (exchange.isTransacted()) {
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(final TransactionStatus status) {
final DefaultTransactionStatus st = (DefaultTransactionStatus)status;
final FcrepoTransactionObject tx = (FcrepoTransactionObject)st.getTransaction();
try {
doRequest(exchange, tx.getSessionId());
} catch (FcrepoOperationFailedException ex) {
throw new TransactionSystemException(
"Error executing fcrepo request in transaction: ", ex);
}
}
});
} else {
doRequest(exchange, null);
}
}