Hi!
Hope to get help on an issue that I've been trying to solve for some time
now.
In our CR, we have Nodes that have Binary content (jcr:data) that contain
our
document data. When I check out the Parent node, the binary content is
emptied
in the CR.
To retrieve the content, we use a Resouce class:
@Node(jcrType = "nt:resource")
public class Resource {
@Field(jcrName = "jcr:mimeType")
private String mimeType;
@Field(jcrName = "jcr:data")
private InputStream data;
@Field(jcrName = "jcr:lastModified")
private Calendar lastModified;
@Field(jcrName = "jcr:encoding")
private String encoding;
...
}
The service method is as follows:
public DocumentWrapperDto checkOut(AdminDocumentIdDto documentId) throws
RepositoryException, CheckoutException {
ocm = new ObjectContentManagerImpl(session.getSession(), mapper);
AdminDocumentPath path = documentId.getPath();
String userId = session.getSession().getUserID();
String docInPath = path.getPathAsString();
log.debug("Checking out document: " + docInPath + " as user " + userId);
if (!ocm.objectExists(docInPath)) {
log.error("Document " + docInPath + " does not exist!");
throw new CheckoutException("Document " + docInPath + " does not
exist!");
}
VersionedDocument document = (VersionedDocument)
ocm.getObject(docInPath);
// Check that the document has the right status (modify)
if (document.getStatus() != DocumentStatus.MODIFY) {
log.error("The Document being checked out does not have status
Modify...");
throw new CheckoutException("The Document being checked out does not
have status Modify...");
}
// Get node as well in order to all meta information.
Node node =
session.getSession().getRootNode().getNode(path.toRelative().getPathAsString());
if (node.isCheckedOut() && (!userId.equals(document.getCheckedOutBy())
&& document.getCheckedOutBy() != null)) {
log.error("Document is already checked out by another user: " +
document.getCheckedOutBy());
throw new CheckoutException("Document is already checked out by
another user: " + document.getCheckedOutBy());
}
// Add the contents and metadata to the dto
DocumentDTO docDto = new DocumentDTO();
docDto.setFilename(document.getName());
docDto.setDocumentId(document.getDocumentId());
DocumentContentDto docContentDto = new DocumentContentDto();
String strContent = document.getContent().getDataAsString();
docContentDto.setDocumentContent(strContent);
// Check out the document node
document.setCheckedOutBy(userId);
//document.setStatus(DocumentStatus.STATUS_CHECKED_OUT);
ocm.checkout(docInPath);
this.updateRepositoryObject(document);
log.debug("Document is now checked out by " + userId);
// Add the Dto:s to the wrapper object and return
DocumentWrapperDto wrapperDto = new DocumentWrapperDto();
wrapperDto.setDocumentDto(docDto);
wrapperDto.setDocumentContentDto(docContentDto);
return wrapperDto;
}
Test method for the above service:
@Test
public void checkOutSafetyInformationDocumentSuccessful() throws
CheckoutException, RepositoryException, OrganisationDAOException,
NotLoggedInException {
// Create a JCR Session
this.createSession("aco", "aco");
SafetyInformationDocument sid = new SafetyInformationDocument();
AdminDocumentPath adminDocumentPath = new
PathFactory().getPathToProductDocument("ACO", "ADVitaminSkydsinfo",
sid.getClass());
DocumentWrapperDto docDto =
this.checkOutSafetyInformationDocument(adminDocumentPath);
Assert.assertNotNull(docDto);
Assert.assertEquals(docDto.getDocumentDto().getFilename(),
"ADVitaminSkydsinfo");
Assert.assertEquals("<safety-information>",
docDto.getDocumentContentDto().getDocumentContent().substring(139, 159));
}
SafetyInformationdocument is a Versioned Document and contains the Resouce
node
I sent in my previous query.
I've been using 1.5.0 of the OCM. Is this a caveat/bug of some sort?
Cheers,
/Eje