本文整理汇总了Java中org.fcrepo.kernel.Datastream类的典型用法代码示例。如果您正苦于以下问题:Java Datastream类的具体用法?Java Datastream怎么用?Java Datastream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Datastream类属于org.fcrepo.kernel包,在下文中一共展示了Datastream类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchBinaryFile
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
/**
* Retrieve the binary content of a {@link File}
*
* @param session
* the {@link Session} to use for the operation
* @param entityId
* the {@link IntellectualEntity}'s id
* @param repId
* the {@link Representation}'s id
* @param fileId
* the {@link File}'s id
* @param versionId
* the version id of the {@link File}
* @return a {@link java.io.InputStream} containing the binary file data
* @throws RepositoryException
* if an error occurred while fetching he binary data
*/
public ContentTypeInputStream fetchBinaryFile(final Session session, final String entityId, final String repId, final String fileId, final String versionId)
throws RepositoryException {
final String entityPath, dsPath;
if (versionId == null) {
entityPath = ENTITY_FOLDER + "/" + entityId;
final FedoraObject fo = this.objectService.findOrCreateObject(session, entityPath);
final IdentifierTranslator subjects = new DefaultIdentifierTranslator();
final String uri = subjects.getSubject(entityPath).getURI();
final Model entityModel = SerializationUtils.unifyDatasetModel(fo.getPropertiesDataset(subjects));
dsPath = this.getCurrentVersionPath(entityModel, uri) + "/" + repId + "/" + fileId + "/DATA";
} else {
entityPath = ENTITY_FOLDER + "/" + entityId + "/version-" + versionId;
dsPath = entityPath + "/" + repId + "/" + fileId + "/DATA";
}
final Datastream ds = this.datastreamService.findOrCreateDatastream(session, dsPath);
return new ContentTypeInputStream(ds.getBinary().getMimeType(), ds.getBinary().getContent());
}
示例2: fetchCurrentMetadata
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
/**
* Retrieve the current version of the metadata of an object saved in Fedora
*
* @param session
* the {@link Session} to use for the operation
* @param path
* the path of the object in Fedora
* @return a generic {@link Object} containing the metadata of an arbitrary
* {@link Class}. E.g. ElementContainer for dublin core metadata
* @throws RepositoryException
*/
public Object fetchCurrentMetadata(final Session session, final String path) throws RepositoryException {
String[] ids = path.substring(ENTITY_FOLDER.length() + 1).split("/");
String entityPath = ENTITY_FOLDER + "/" + ids[0];
final FedoraObject entityObject = objectService.findOrCreateObject(session, entityPath);
final IdentifierTranslator subjects = new DefaultIdentifierTranslator();
final String uri = subjects.getSubject(entityPath).getURI();
StringBuilder versionPath = new StringBuilder();
versionPath.append(this.getCurrentVersionPath(SerializationUtils.unifyDatasetModel(entityObject.getPropertiesDataset(subjects)), uri));
for (int i = 1; i < ids.length; i++) {
versionPath.append("/");
versionPath.append(ids[i]);
}
try {
if (!this.datastreamService.exists(session, versionPath.toString())) {
throw new PathNotFoundException("No metadata available for " + path);
}
final Datastream mdDs = this.datastreamService.findOrCreateDatastream(session, versionPath.toString());
return this.marshaller.deserialize(mdDs.getBinary().getContent());
} catch (JAXBException e) {
throw new RepositoryException(e);
}
}
示例3: getItemsFromQueue
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
private List<String> getItemsFromQueue(final Session session) throws RepositoryException {
final FedoraObject queueObject = this.objectService.findOrCreateObject(session, QUEUE_NODE);
final IdentifierTranslator subjects = new DefaultIdentifierTranslator();
final String uri = subjects.getSubject(queueObject.getPath()).getURI();
final Model queueModel = SerializationUtils.unifyDatasetModel(queueObject.getPropertiesDataset(subjects));
final Resource parent = queueModel.createResource(uri);
StmtIterator it = queueModel.listStatements(parent, queueModel.createProperty(namespace(HAS_ITEM)), (RDFNode) null);
List<String> queueItems = new ArrayList<>();
while (it.hasNext()) {
final String itemUri = it.nextStatement().getObject().asLiteral().getString();
final String path = subjects.getPathFromSubject(queueModel.createResource(itemUri));
final Datastream ds = this.datastreamService.findOrCreateDatastream(session, path);
final javax.jcr.Property p = ds.getNode().getProperties(prefix(HAS_INGEST_STATE)).nextProperty();
final String val = p.getValues()[0].getString();
if (val.equals("QUEUED")) {
queueItems.add(path);
}
}
return queueItems;
}
示例4: identify
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
public JAXBElement<OAIPMHtype> identify(final Session session, UriInfo uriInfo) throws RepositoryException,
JAXBException {
if (!this.datastreamService.exists(session, identifyPath)) {
throw new RepositoryException("Identify response can not be found.");
}
final Datastream ds = this.datastreamService.findOrCreateDatastream(session, identifyPath);
final InputStream data = ds.getBinary().getContent();
final IdentifyType id = this.unmarshaller.unmarshal(new StreamSource(data), IdentifyType.class).getValue();
final RequestType req = oaiFactory.createRequestType();
req.setVerb(VerbType.IDENTIFY);
req.setValue(uriInfo.getRequestUri().toASCIIString());
final OAIPMHtype oai = oaiFactory.createOAIPMHtype();
oai.setIdentify(id);
oai.setResponseDate(dataFactory.newXMLGregorianCalendar(new GregorianCalendar()));
oai.setRequest(req);
return oaiFactory.createOAIPMH(oai);
}
示例5: fetchMetadata
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
/**
* Retrieve the metadata of an object saved in Fedora
*
* @param session
* the {@link Session} to use for the operation
* @param path
* the path of the object in Fedora
* @return a generic {@link Object} containing the metadata of an arbitrary
* {@link Class}. E.g. ElementContainer for dublin core metadata
* @throws RepositoryException
*/
public Object fetchMetadata(final Session session, final String path) throws RepositoryException {
try {
if (!this.datastreamService.exists(session, path)) {
return null;
}
final Datastream mdDs = this.datastreamService.findOrCreateDatastream(session, path);
return this.marshaller.deserialize(mdDs.getBinary().getContent());
} catch (JAXBException e) {
throw new RepositoryException(e);
}
}
示例6: queueEntityForIngest
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
/**
* Queue an {@link IntellectualEntity} for asynchronous storage in Fedora
*
* @param session
* the {@link Session} to use for ading the
* {@link IntellectualEntity} to the asynchronous queue
* @param src
* the {@link IntellectualEntity}'s METS representation
* @return the id of the {@link IntellectualEntity} which can be used to
* retrieve the status of the asynchronous storing
* @throws RepositoryException
* if an error occurred while adding the
* {@link IntellectualEntity} to the asynchronous queue
*/
public String queueEntityForIngest(final Session session, final InputStream src) throws RepositoryException {
try {
/* try to deserialize and extraxt an existing id */
IntellectualEntity ie = this.marshaller.deserialize(IntellectualEntity.class, src);
String id = (ie.getIdentifier() == null || ie.getIdentifier().getValue() == null || ie.getIdentifier().getValue().length() == 0) ? UUID
.randomUUID().toString() : ie.getIdentifier().getValue();
/* copy the data to a temporary node */
ByteArrayOutputStream sink = new ByteArrayOutputStream();
this.marshaller.serialize(ie, sink);
final FedoraObject queue = this.objectService.findOrCreateObject(session, QUEUE_NODE);
if (this.objectService.exists(session,ENTITY_FOLDER + "/" + id)) {
throw new RepositoryException("Unable to queue item with id " + id
+ " for ingest since an intellectual entity with that id already esists in the repository");
}
if (this.datastreamService.exists(session, QUEUE_NODE + "/" + id)) {
throw new RepositoryException("Unable to queue item with id " + id + " for ingest since an item with that id is alread in the queue");
}
final Datastream item = this.datastreamService.findOrCreateDatastream(session, QUEUE_NODE + "/" + id);
item.getBinary().setContent(new ByteArrayInputStream(sink.toByteArray()), "text/xml", null, null, datastreamService.getStoragePolicyDecisionPoint());
item.getContentNode().addMixin("scape:async-queue-item");
/* update the ingest queue */
final IdentifierTranslator subjects = new DefaultIdentifierTranslator();
final String queueUri = subjects.getSubject(QUEUE_NODE).getURI();
final String itemUri = subjects.getSubject(item.getPath()).getURI();
final StringBuilder sparql = new StringBuilder("PREFIX scape: <http://scapeproject.eu/model#> ");
sparql.append("INSERT DATA {<" + queueUri + "> " + prefix(HAS_ITEM) + " \"" + itemUri + "\"};");
sparql.append("INSERT DATA {<" + itemUri + "> " + prefix(HAS_INGEST_STATE) + " \"QUEUED\"};");
queue.updatePropertiesDataset(subjects, sparql.toString());
session.save();
return id;
} catch (InvalidChecksumException | JAXBException e) {
throw new RepositoryException(e);
}
}
示例7: addFiles
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
private List<String> addFiles(final Session session, final List<File> files, final String repPath) throws RepositoryException {
if (files == null) {
return Collections.<String>emptyList();
}
final List<String> fileUris = new ArrayList<>(files.size());
final StringBuilder sparql = new StringBuilder("PREFIX scape: <" + SCAPE_NAMESPACE + "> ");
for (File f : files) {
final String fileId = (f.getIdentifier() != null) ? f.getIdentifier().getValue() : UUID.randomUUID().toString();
final String filePath = repPath + "/" + fileId;
URI fileUri = f.getUri();
if (fileUri.getScheme() == null) {
fileUri = URI.create("file:" + fileUri.toASCIIString());
}
/* create a datastream in fedora for this file */
final FedoraObject fileObject = this.objectService.findOrCreateObject(session, filePath);
fileObject.getNode().addMixin("scape:file");
final IdentifierTranslator subjects = new DefaultIdentifierTranslator();
final String uri = subjects.getSubject(fileObject.getPath()).getURI();
/* add the metadata */
if (f.getTechnical() != null) {
addMetadata(session, f.getTechnical(), filePath + "/TECHNICAL");
}
/* add all bitstreams as child objects */
if (f.getBitStreams() != null) {
for (final String bsUri : addBitStreams(session, f.getBitStreams(), "/" + filePath)) {
sparql.append("INSERT DATA {<" + uri + "> " + prefix(HAS_BITSTREAM) + " \"" + bsUri + "\"};");
}
}
String fileName = f.getFilename();
if (fileName == null) {
fileName = f.getUri().toASCIIString().substring(f.getUri().toASCIIString().lastIndexOf('/') + 1);
}
final String mimeType = (f.getMimetype() != null) ? f.getMimetype() : "application/binary";
sparql.append("INSERT DATA {<" + uri + "> " + prefix(HAS_TYPE) + " \"file\"};");
sparql.append("INSERT DATA {<" + uri + "> " + prefix(HAS_FILENAME) + " \"" + fileName + "\"};");
sparql.append("INSERT DATA {<" + uri + "> " + prefix(HAS_MIMETYPE) + " \"" + mimeType + "\"};");
sparql.append("INSERT DATA {<" + uri + "> " + prefix(HAS_INGEST_SOURCE) + " \"" + f.getUri() + "\"};");
if (this.referencedContent) {
/* only write a reference to the file URI as a node property */
sparql.append("INSERT DATA {<" + uri + "> " + prefix(HAS_REFERENCED_CONTENT) + " \"" + fileUri + "\"};");
} else {
/* load the actual binary data into the repo */
LOG.info("reading binary from {}", fileUri.toASCIIString());
try (final InputStream src = fileUri.toURL().openStream()) {
final Datastream fileDs = this.datastreamService.findOrCreateDatastream(session, filePath + "/DATA");
fileDs.getBinary().setContent(src, f.getMimetype(), null, null, datastreamService.getStoragePolicyDecisionPoint());
} catch (IOException | InvalidChecksumException e) {
throw new RepositoryException(e);
}
}
fileUris.add(uri);
fileObject.updatePropertiesDataset(subjects, sparql.toString());
}
return fileUris;
}
示例8: retrievePlan
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
/**
* Retrieve a plan's XML representation stored in Fedora
*
* @param planId
* the id of the plan
* @return a {@link javax.ws.rs.core.Response} which maps to a corresponding HTTP response,
* containing the plan as an XML document
* @throws javax.jcr.RepositoryException
* if an error occurred while fetching the plan from Fedora
*/
@GET
@Path("{id}")
public Response retrievePlan(@PathParam("id")
final String planId) throws RepositoryException {
/* fetch the plan form the repository */
final Datastream ds = this.datastreamService.findOrCreateDatastream(this.session, PLAN_FOLDER + planId + "/plato-xml");
return Response.ok(ds.getBinary().getContent(), ds.getBinary().getMimeType()).build();
}
示例9: retrievePlan
import org.fcrepo.kernel.Datastream; //导入依赖的package包/类
/**
* Retrieve a plan's XML representation stored in Fedora
*
* @param planId
* the id of the plan
* @return a {@link Response} which maps to a corresponding HTTP response,
* containing the plan as an XML document
* @throws RepositoryException
* if an error occurred while fetching the plan from Fedora
*/
@GET
@Path("{id}")
public Response retrievePlan(@PathParam("id")
final String planId) throws RepositoryException {
/* fetch the plan form the repository */
final Datastream ds = this.datastreamService.getDatastream(this.session, PLAN_FOLDER + planId + "/plato-xml");
return Response.ok(ds.getContent(), ds.getMimeType()).build();
}