Fórumok
How to get document and media webdav url in workflow
Nandakumaran Kasinathan, módosítva 8 év-val korábban
How to get document and media webdav url in workflow
New Member Bejegyzések: 12 Csatlakozás dátuma: 2015.04.16. Legújabb bejegyzések
Hi
I am new to Liferay and using 6.2. My requirement is to copy the file from document and media section to a local folder in the server (e.g: D:\temp). To achieve this I am trying to get the physical path of the file.
I have created a single approval workflow and have mapped it to a folder in document media. In the approval script section I have written the below code.
String className = (String)workflowContext.get( WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME);
WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className);
AssetRendererFactory assetRendererFactory = workflowHandler.getAssetRendererFactory();
long classPK = GetterUtil.getLong((String)workflowContext.get (WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
long userId = GetterUtil.getLong((String)workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
long groupId = GetterUtil.getLong((String)workflowContext.get (WorkflowConstants.CONTEXT_GROUP_ID));
long companyId = GetterUtil.getLong((String)workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
ServiceContext serviceContext = (ServiceContext)workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
Map<String, Serializable> serviceContextAttb = serviceContext.getAttributes();
String repositoryId = serviceContextAttb.get("repositoryId").toString();
String folderId = serviceContextAttb.get("folderId").toString();
String sourceFileName = serviceContextAttb.get("sourceFileName").toString();
// File URL
sourceFilePath = "http://localhost:8080/documents/"+repositoryId+"/"+folderId+"/"+sourceFileName;
With the values from serviceContextAttb i am able to frame the file url. But using this url I can download the file and then copy the file. On searching over net and forum I goth the below code to get the file. But I am getting file not found exception. So I looked the API to confirm if file name has to be passed as last parameter. But there is no explanation for that.
try {
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntryByName(companyId, userId, sourceFileName);
out.println("1--dlFileEntry: "+ dlFileEntry);
} catch (PortalException e2) {
out.println("Error in workflow, error was: " +e2.getMessage());
e2.printStackTrace();
} catch (SystemException e2) {
e2.printStackTrace();
}
Please help to get the file physical path or the webdav url.
Thanks,
Nanda
I am new to Liferay and using 6.2. My requirement is to copy the file from document and media section to a local folder in the server (e.g: D:\temp). To achieve this I am trying to get the physical path of the file.
I have created a single approval workflow and have mapped it to a folder in document media. In the approval script section I have written the below code.
String className = (String)workflowContext.get( WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME);
WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className);
AssetRendererFactory assetRendererFactory = workflowHandler.getAssetRendererFactory();
long classPK = GetterUtil.getLong((String)workflowContext.get (WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
long userId = GetterUtil.getLong((String)workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
long groupId = GetterUtil.getLong((String)workflowContext.get (WorkflowConstants.CONTEXT_GROUP_ID));
long companyId = GetterUtil.getLong((String)workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
ServiceContext serviceContext = (ServiceContext)workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
Map<String, Serializable> serviceContextAttb = serviceContext.getAttributes();
String repositoryId = serviceContextAttb.get("repositoryId").toString();
String folderId = serviceContextAttb.get("folderId").toString();
String sourceFileName = serviceContextAttb.get("sourceFileName").toString();
// File URL
sourceFilePath = "http://localhost:8080/documents/"+repositoryId+"/"+folderId+"/"+sourceFileName;
With the values from serviceContextAttb i am able to frame the file url. But using this url I can download the file and then copy the file. On searching over net and forum I goth the below code to get the file. But I am getting file not found exception. So I looked the API to confirm if file name has to be passed as last parameter. But there is no explanation for that.
try {
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntryByName(companyId, userId, sourceFileName);
out.println("1--dlFileEntry: "+ dlFileEntry);
} catch (PortalException e2) {
out.println("Error in workflow, error was: " +e2.getMessage());
e2.printStackTrace();
} catch (SystemException e2) {
e2.printStackTrace();
}
Please help to get the file physical path or the webdav url.
Thanks,
Nanda
Shinn Lok, módosítva 8 év-val korábban
RE: How to get document and media webdav url in workflow
Junior Member Bejegyzések: 89 Csatlakozás dátuma: 2011.01.14. Legújabb bejegyzésekDLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntryByName(companyId, userId, sourceFileName);
The second parameter should be folderId.
Nandakumaran Kasinathan, módosítva 8 év-val korábban
RE: How to get document and media webdav url in workflow
New Member Bejegyzések: 12 Csatlakozás dátuma: 2015.04.16. Legújabb bejegyzések
Hi Shinn,
Thanks for pointing out. But still getting the same error message. Can you please let me know what this function does. Does it check the database?
If database, which table?
com.liferay.portlet.documentlibrary.NoSuchFileEntryException: No DLFileEntry exists with the key {groupId=21327, folderId=24311, name=26018696.xml}
at com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistenceImpl.findByG_F_N(DLFileEntryPersistenceImpl.java:8883)
at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.getFileEntryByName(DLFileEntryLocalServiceImpl.java:1220)
Thanks for pointing out. But still getting the same error message. Can you please let me know what this function does. Does it check the database?
If database, which table?
com.liferay.portlet.documentlibrary.NoSuchFileEntryException: No DLFileEntry exists with the key {groupId=21327, folderId=24311, name=26018696.xml}
at com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistenceImpl.findByG_F_N(DLFileEntryPersistenceImpl.java:8883)
at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.getFileEntryByName(DLFileEntryLocalServiceImpl.java:1220)
Shinn Lok, módosítva 8 év-val korábban
RE: How to get document and media webdav url in workflow
Junior Member Bejegyzések: 89 Csatlakozás dátuma: 2011.01.14. Legújabb bejegyzések
I think what you're looking for is:
DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName)
Nandakumaran Kasinathan, módosítva 8 év-val korábban
RE: How to get document and media webdav url in workflow
New Member Bejegyzések: 12 Csatlakozás dátuma: 2015.04.16. Legújabb bejegyzések
will try with the new method.
Nandakumaran Kasinathan, módosítva 8 év-val korábban
RE: How to get document and media webdav url in workflow
New Member Bejegyzések: 12 Csatlakozás dátuma: 2015.04.16. Legújabb bejegyzésekShinn Lok:
I think what you're looking for is:DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName)
Thanks. This class method returned the FileEntry object. Next i am getting the content stream of the file as show below, now my entire code is not getting executed at all. No exception captured and displayed.Am i doing something wrong.
import java.io.InputStream;
try {
FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderIdLong, sourceFileName);
out.println("1--fileEntry: "+ fileEntry);
InputStream in = fileEntry.getContentStream();
out.println("2--in: "+ in);
in.close();
} catch (PortalException e2) {
out.println("Error in workflow, error was: " +e2.getMessage());
e2.printStackTrace();
} catch (SystemException e2) {
e2.printStackTrace();
}
Nandakumaran Kasinathan, módosítva 8 év-val korábban
RE: How to get document and media webdav url in workflow
New Member Bejegyzések: 12 Csatlakozás dátuma: 2015.04.16. Legújabb bejegyzések
Got the contentStream by passing the version.
FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderIdLong, sourceFileName);
String stFileVersion = fileEntry.getVersion();
InputStream inStream = fileEntry.getContentStream(stFileVersion);
Now how do i get the webdav URL of the file.
FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderIdLong, sourceFileName);
String stFileVersion = fileEntry.getVersion();
InputStream inStream = fileEntry.getContentStream(stFileVersion);
Now how do i get the webdav URL of the file.
Nagaraju Uppalapati, módosítva 8 év-val korábban
RE: How to get document and media webdav url in workflow
New Member Bejegyzések: 24 Csatlakozás dátuma: 2015.06.29. Legújabb bejegyzések
Hi Nanda,
Take a look at DLUtil.getWebDavURL
Take a look at DLUtil.getWebDavURL