Foros de discusión

How to get document and media webdav url in workflow

Nandakumaran Kasinathan, modificado hace 8 años.

How to get document and media webdav url in workflow

New Member Mensajes: 12 Fecha de incorporación: 16/04/15 Mensajes recientes
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
thumbnail
Shinn Lok, modificado hace 8 años.

RE: How to get document and media webdav url in workflow

Junior Member Mensajes: 89 Fecha de incorporación: 14/01/11 Mensajes recientes
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntryByName(companyId, userId, sourceFileName);


The second parameter should be folderId.
Nandakumaran Kasinathan, modificado hace 8 años.

RE: How to get document and media webdav url in workflow

New Member Mensajes: 12 Fecha de incorporación: 16/04/15 Mensajes recientes
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)
thumbnail
Shinn Lok, modificado hace 8 años.

RE: How to get document and media webdav url in workflow

Junior Member Mensajes: 89 Fecha de incorporación: 14/01/11 Mensajes recientes
I think what you're looking for is:


DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName)
Nandakumaran Kasinathan, modificado hace 8 años.

RE: How to get document and media webdav url in workflow

New Member Mensajes: 12 Fecha de incorporación: 16/04/15 Mensajes recientes
will try with the new method.
Nandakumaran Kasinathan, modificado hace 8 años.

RE: How to get document and media webdav url in workflow

New Member Mensajes: 12 Fecha de incorporación: 16/04/15 Mensajes recientes
Shinn 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, modificado hace 8 años.

RE: How to get document and media webdav url in workflow

New Member Mensajes: 12 Fecha de incorporación: 16/04/15 Mensajes recientes
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.
Nagaraju Uppalapati, modificado hace 8 años.

RE: How to get document and media webdav url in workflow

New Member Mensajes: 24 Fecha de incorporación: 29/06/15 Mensajes recientes
Hi Nanda,

Take a look at DLUtil.getWebDavURL