Creating behavior to validate the file signature

cancel
Showing results for 
Search instead for 
Did you mean: 
kiranmaik
Member II

Creating behavior to validate the file signature

I am trying to fetch the content of the uploded document  but I am getting the contentReader value as null.How to get the uploaded document content on onCreateNode method?Below is the code snippet that I  was implemented 

public void onCreateNode(ChildAssociationRef parentChildAssocRef) {
logger.info("Inside onCreateNode");
NodeRef parentFolderRef = parentChildAssocRef.getParentRef();
NodeRef docRef = parentChildAssocRef.getChildRef();
System.out.println("onCreateNode NodeRef "+docRef);
ContentReader reader = this.getContentService().getReader(docRef, ContentModel.PROP_CONTENT);
System.out.println("onCreateNode Reader "+reader);
}

 

2 Replies
angelborroy
Alfresco Employee

Re: Creating behavior to validate the file signature

This behaviour validates electronic signatures on a file:

https://github.com/keensoft/alfresco-esign-cert/blob/master/esign-cert-repo/src/main/java/es/keensof...

I guess you should listen to "onContentUpdate" policy instead of "onCreateNode" one.

Hyland Developer Evangelist
kiranmaik
Member II

Re: Creating behavior to validate the file signature

I changed the NotificationFrequency to TRANSACTION_COMMIT in onCreateNode then I am not getting the contentReader value as null but while to am trying to fetch the content as a stream object then I am facing issue as ContentIOException.

Caused by: org.alfresco.service.cmr.repository.ContentIOException: 00190021 Failed to open stream onto channel:
dms-impl-acs_1 | accessor: ContentAccessor[ contentUrl=store://2021/1/19/18/47/7d2e073a-43b0-4e7d-8caa-aa180047be66.bin, mimetype=image/png, size=158162, encoding=UTF-8, locale=en_GB]

Below is the code snippet

public void onCreateNode(ChildAssociationRef parentChildAssocRef) {
logger.info("Inside onCreateNode");
NodeRef parentFolderRef = parentChildAssocRef.getParentRef();
NodeRef docRef = parentChildAssocRef.getChildRef();
System.out.println("onCreateNode NodeRef "+docRef);
ContentReader reader = this.getContentService().getReader(docRef, ContentModel.PROP_CONTENT);
System.out.println("onCreateNode Reader "+reader);
InputStream originalInputStream = reader.getContentInputStream();
System.out.println("originalInputStream "+originalInputStream);
}