, DigitalObject digitalObject
, boolean includeContent
)
throws DigitalObjectNotStoredException
{
DigitalObject resVal = digitalObject;
try {
_log.log(Level.INFO, "storeDigitalObjectDefinition()" + digitalObject.toString());
openSession();
uri = URI.create(PERMANENT_URI + uri.toString());
_log.log(Level.INFO, "storeDigitalObjectDefinition() uri: " + uri.toString());
Node doNode = createDocumentNode
(uri.toString().concat(DOJCRConstants.JCR_PATH_SEPARATOR + DOJCRConstants.DOJCR));
dumpNode(doNode);
String path = doNode.getPath();
if (doNode.getIndex() > 1)
{
path = doNode.getPath().substring
(0, doNode.getPath().indexOf(DOJCRConstants.NODE_INDEX_BEGIN));
}
_log.log(Level.INFO, "+++ path: " + path);
URI permanentUri = URI.create(path + DOJCRConstants.JCR_PATH_SEPARATOR + doNode.getIndex());
_log.log(Level.INFO, "storeDigitalObjectDefinition() calculated permanentUri: " +
permanentUri.toString());
storeStringValue(doNode, digitalObject.getTitle(), DOJCRConstants.DOJCR_TITLE);
if (permanentUri != null)
storeStringValue(doNode, permanentUri.toString(), DOJCRConstants.DOJCR_PERMANENT_URI);
if (digitalObject.getFormat() != null)
{
storeStringValue
( doNode
, digitalObject.getFormat().toString()
, DOJCRConstants.DOJCR_FORMAT
);
}
if (digitalObject.getManifestationOf() != null)
{
storeStringValue
( doNode
, digitalObject.getManifestationOf().toString()
, DOJCRConstants.DOJCR_MANIFESTATION_OF
);
}
if (digitalObject.getContent() != null)
{
_log.log(Level.INFO, "store content.");
if (includeContent)
{
long contentLen = digitalObject.getContent().length();
_log.log(Level.INFO, "contentLen: " + contentLen);
storeContent
( digitalObject.getContent().getInputStream()
, uri.toString().concat
( DOJCRConstants.JCR_PATH_SEPARATOR
+ DOJCRConstants.DOJCR
+ insertNodeIndexToPath(doNode.getIndex())
)
);
}
}
checkResult (storeMetadataList(digitalObject.getMetadata(), doNode));
checkResult (storeEventsList(digitalObject.getEvents(), doNode));
session.save();
_log.log(Level.INFO, "storing permanentUri: " + permanentUri.toString());
/*try {
_log.log(Level.INFO, "storing digitalObject.content: " + digitalObject.getContent().read().read());
} catch (IOException e) {
e.printStackTrace();
} */
if (digitalObject.getTitle() != null) {
_log.log(Level.INFO, "storing digitalObject.title: " + digitalObject.getTitle());
}
DigitalObject.Builder b = new DigitalObject.Builder(
Content.byReference(URI.create((getResolverPath() + permanentUri)).toURL()));
if (digitalObject.getTitle() != null) b.title(digitalObject.getTitle());
if (permanentUri != null) b.permanentUri(permanentUri);
if (digitalObject.getFormat() != null) b.format(digitalObject.getFormat());
if (digitalObject.getManifestationOf() != null)
b.manifestationOf(digitalObject.getManifestationOf());
if (digitalObject.getMetadata() != null)
b.metadata((Metadata[]) digitalObject.getMetadata().toArray(new Metadata[0]));
if (digitalObject.getEvents() != null)
b.events((Event[]) digitalObject.getEvents().toArray(new Event[0]));
resVal = b.build();
_log.log(Level.INFO, "storing completed. ");
resVal.toString();
} catch (Exception e) {
_log.log(Level.INFO, "storeDigitalObjectDefinition() error: " + e.getMessage(), e);
throw new DigitalObjectNotStoredException("storeDigitalObjectDefinition() error: ", e);
} finally {
closeSession();