How to implement condition based file upload in DocLib ?How to implement condition based file upload in DocLib ?https://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1146379822024-03-29T05:56:45Z2024-03-29T05:56:45ZRE: How to implement condition based file upload in DocLib ?Rajesh Chaurasiahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1146414542019-08-07T13:44:46Z2019-08-07T13:44:46ZHi Olaf <br /><br />Thanks for the prompt and relevant response.<br />Rajesh Chaurasia2019-08-07T13:44:46ZRE: How to implement condition based file upload in DocLib ?Olaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1146401232019-08-07T12:49:57Z2019-08-07T12:49:57Z<div class="quote-title">Rajesh Chaurasia:</div><blockquote><br />Hi Olaf ,<br /><br />Will it be fine if instead of null i return an empty DLFileEntry object , or show a error message in ui that document was not uploaded ? In which case if you can let em know how to do that at Service wrapper level.<br /></blockquote><br />The ServiceWrapper can't show an error message in the UI, as it's the service, and can be called from anywhere, with or without UI. <br />You'd have to identify the UI that you'd like to show the message.<br /><br />An alternative to the null return might be to throw an exception. AFAIK there's no "empty" DLFileEntry object. I'd expect it to have an id and a persistent backend (or to be able to be persisted later).Olaf Kock2019-08-07T12:49:57ZRE: How to implement condition based file upload in DocLib ?Olaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1146398062019-08-07T12:48:08Z2019-08-07T12:48:08Z<div class="quote-title">Rajesh Chaurasia:</div><blockquote><br />Hi Olaf<br />Thanks for your reply ,<br /><br />isOcrCompliantUpload is a method i added to class that i used to override the wrapper.It checks for ocr text string and returns true or false on return .<br /><br /><br /></blockquote>I'd rather expect sourceFileName to be just the name of the file originally uploaded, and have nothing to do with the temporary file that you find. The binary content is probably in the <strong>file</strong> or <strong>inputStream</strong> parameter.Olaf Kock2019-08-07T12:48:08ZRE: How to implement condition based file upload in DocLib ?Rajesh Chaurasiahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1146393322019-08-07T12:32:47Z2019-08-07T12:32:47ZHi Olaf ,<br /><br />Will it be fine if instead of null i return an empty DLFileEntry object , or show a error message in ui that document was not uploaded ? In which case if you can let em know how to do that at Service wrapper level.Rajesh Chaurasia2019-08-07T12:32:47ZRE: How to implement condition based file upload in DocLib ?Rajesh Chaurasiahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1146383052019-08-07T12:12:57Z2019-08-07T12:12:57ZHi Olaf<br />Thanks for your reply ,<br /><br />isOcrCompliantUpload is a method i added to class that i used to override the wrapper.It checks for ocr text string and returns true or false on return .<br /><br />public boolean isOcrCompliantUpload(String keywordmatchtofailupload,String pathOfDir,String sourceFileName) {<br /> Ocr.setUp(); // one time setup<br /> Ocr ocr = new Ocr(); // create a new OCR engine<br /> ocr.startEngine("eng", Ocr.SPEED_FASTEST); // English<br /> String sOcrMatch = ocr.recognize(new File[] {new File( pathOfDir+sourceFileName)},Ocr.RECOGNIZE_TYPE_ALL, Ocr.OUTPUT_FORMAT_PLAINTEXT); // PLAINTEXT | XML | PDF | RTF<br /> System.out.println("sOcrMatch: " + sOcrMatch);<br /> ocr.stopEngine();<br /> if(null!=sOcrMatch && sOcrMatch.contains(keywordmatchtofailupload) ) {<br /> return Boolean.TRUE;<br /> }<br /> return Boolean.FALSE;<br /> }Rajesh Chaurasia2019-08-07T12:12:57ZRE: How to implement condition based file upload in DocLib ?Olaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1146369942019-08-07T12:02:04Z2019-08-07T12:02:04Z<html><head></head><body><div class="quote-title">Rajesh Chaurasia:</div><blockquote><br><br><pre><code>@Override
&nbsp;&nbsp; &nbsp;public com.liferay.document.library.kernel.model.DLFileEntry addFileEntry(long userId, long groupId,
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;long repositoryId, long folderId, String sourceFileName, String mimeType, String title, String description,
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String changeLog, long fileEntryTypeId,
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;java.util.Map<string, com.liferay.dynamic.data.mapping.kernel.ddmformvalues> ddmFormValuesMap,
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;java.io.File file, java.io.InputStream is, long size,
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;com.liferay.portal.kernel.service.ServiceContext serviceContext)
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throws com.liferay.portal.kernel.exception.PortalException {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(isOcrCompliantUpload(PropsUtil.get(OCR_MATCH_STRING),PropsUtil.get(OCR_WORK_DIR),sourceFileName)) {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return super.addFileEntry(userId, groupId, repositoryId, folderId, sourceFileName, mimeType, title, description, changeLog, fileEntryTypeId, ddmFormValuesMap, file, is, size, serviceContext);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}else {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return null; --&gt; this is erroneous for me , i want to know what should be the return type in this case , it shouldnt be null ?
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}
&nbsp;&nbsp; &nbsp;}</string,></code></pre><br><br>Is this abbreviated? I'm wondering why <pre><code>isOcrCompliantUpload</code></pre> doesn't reference the <em>file</em> or <em>inputStream</em> parameter, and what would be OCR'ed in that case. <br>But if you deny creating that file, and don't create any file in the backend, you can't create and return an "empty" document (as that would create a document, which you don't want). Thus <em>null</em> seems fine to me.<br><br>However: Liferay also uploads images for use in illustrating your web content to the Document Library. Make sure that you don't deny their upload. You may want to apply the described limitation to a specific site or folder. Which brings me to an alternative method: You can also implement this functionality as a workflow, with a scripted approval step that would decouple the OCR process from the upload itself, providing the opportunity to manually override if necessary.</blockquote></body></html>Olaf Kock2019-08-07T12:02:04ZHow to implement condition based file upload in DocLib ?Rajesh Chaurasiahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1146379812019-08-07T11:43:59Z2019-08-07T11:43:59Zhi All,<br /><br />I have a use case where i want to upload a documents(s) based on OCR match ie if there is a specific text present in document i am uploading , only then the document should get uploaded.I have been able to do it for a document when there is match , in which case i safely upload the document.But i need to know what should i return in case of no match in which case i am return null , causing incorrect page to show with ui anomalies.I used a service wrapper and overided the folllowing:<br /><br />@Component(immediate = true, property = {}, service = ServiceWrapper.class)<br />public class DocumentOcrBasedUpload extends <strong>DLFileEntryLocalServiceWrapper<br /><br /></strong>@Override<br /> public com.liferay.document.library.kernel.model.DLFileEntry addFileEntry(long userId, long groupId,<br /> long repositoryId, long folderId, String sourceFileName, String mimeType, String title, String description,<br /> String changeLog, long fileEntryTypeId,<br /> java.util.Map<String, com.liferay.dynamic.data.mapping.kernel.DDMFormValues> ddmFormValuesMap,<br /> java.io.File file, java.io.InputStream is, long size,<br /> com.liferay.portal.kernel.service.ServiceContext serviceContext)<br /> throws com.liferay.portal.kernel.exception.PortalException {<br /> <br /> if(isOcrCompliantUpload(PropsUtil.get(OCR_MATCH_STRING),PropsUtil.get(OCR_WORK_DIR),sourceFileName)) {<br /> return super.addFileEntry(userId, groupId, repositoryId, folderId, sourceFileName, mimeType, title, description,