jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eyji (Eje) Thorarinsson" <e...@thorarinssons.net>
Subject Re: Binary resouces checked out using OCM
Date Mon, 18 May 2009 10:39:36 GMT
Hi Luís!

Thanks for your reply. Are you using the latest 1.5.3 version of the OCM or
1.5.0? Do you see any differences in the way I check out the code from
yours?

BR,
/Eje

2009/5/18 Luís Tiago Rico <tiagorico@gmail.com>

> I've been using OCM with binary resources and I have no problems using it.
> So, I don't think this is bug!
>
>
>
> -----Original Message-----
> From: eyji67@gmail.com [mailto:eyji67@gmail.com] On Behalf Of Eyji (Eje)
> Thorarinsson
> Sent: segunda-feira, 18 de Maio de 2009 11:17
> To: users@jackrabbit.apache.org
> Subject: Binary resouces checked out using OCM
>
> 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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message