Fórum

Bulk loading of files and folders into the Document Library

thumbnail
Bruce Altner, modificado 13 Anos atrás.

Bulk loading of files and folders into the Document Library

New Member Postagens: 20 Data de Entrada: 20/02/09 Postagens Recentes
Greetings:

We are migrating a customer's home-grown DMS into the Liferay document library. The existing repository contains hundreds of documents and a deeply-nested folder structure. It is too labor-intensive to load manually so we are using the document library API to load the folders and documents programmatically, e.g., via DLFolderServiceUtil and related classes in a service portlet.

Loading the folders has gone smoothly and I now have the entire structure of empty folders ready to be loaded with documents. The approach I am taking for this includes uploading the files into the appropriate folders, followed by registering them in the database tables, as shown below:


//Add file to the Liferay Content Repository within the right folder
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
File file = uploadRequest.getFile("docroot" + fileName);
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(), actionRequest);
			
// Add file entry
ThemeDisplay themedisplay = new ThemeDisplay();
DLFolderPermission.check(themedisplay.getPermissionChecker(), folderId, ActionKeys.ADD_DOCUMENT);
DLFileEntry entry = DLFileEntryLocalServiceUtil.addFileEntry(userId, folderId, fileName, title,description, extraSettings, file, serviceContext);


Notice that although I am executing this code in a portlet's processAction code block, I am not using an upload form, which would send the multipart form data that I apparently need. Here is the exception that is being thrown:


org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null


So my question is how to send the upload request as a multipart form without actually using an upload widget. Is it just a matter of setting the content type in the header?

Thanks!
Bruce
thumbnail
jelmer kuperus, modificado 13 Anos atrás.

RE: Bulk loading of files and folders into the Document Library

Liferay Legend Postagens: 1191 Data de Entrada: 10/03/10 Postagens Recentes
Have you considered using the webdav functionality for this
thumbnail
Bruce Altner, modificado 13 Anos atrás.

RE: Bulk loading of files and folders into the Document Library

New Member Postagens: 20 Data de Entrada: 20/02/09 Postagens Recentes
Yes, in fact that was my first thought. Unfortunately the source documents are stored in a single directory (flat), with the repository structure specified in a database. So I can't just drag them all in.

I may come back to this approach eventually if I can't make the DLFileEntry approach work. If I can set up the folder structure in Liferay I should be able to do it on my local file system too...hmmm.

Anyway, thanks for the suggestion.
thumbnail
jelmer kuperus, modificado 13 Anos atrás.

RE: Bulk loading of files and folders into the Document Library

Liferay Legend Postagens: 1191 Data de Entrada: 10/03/10 Postagens Recentes
I am not sure what you are trying to do, but personally i'd build the structure you want on your own disk first, then drag the files to the correct folder via webdav. That seems easiest by far


But if you want to go the other route DLFilEntryLocalService has a method addFileEntry that accepts a file
thumbnail
Bruce Altner, modificado 13 Anos atrás.

RE: Bulk loading of files and folders into the Document Library

New Member Postagens: 20 Data de Entrada: 20/02/09 Postagens Recentes
I am happy to report success, using the code provided above (except that I didn't need the UploadPortletRequest object). All files were uploaded and entered into the DL properly. DLFilEntryLocalService's addFileEntry method was used.

WebDAV was not a good solution in this case because of the document metadata. Each document and folder included a description, and the docs had formal titles as well, which would not have conveyed via dragging the structure into a WebDAV client.

Thanks for the tips.
Stephen Regenscheit, modificado 9 Anos atrás.

RE: Bulk loading of files and folders into the Document Library

New Member Postagens: 6 Data de Entrada: 11/06/14 Postagens Recentes
hey bruce since you seem to have some experience in liferay dms i send oyu a friendrequest emoticon would be nice if you would allow me to tap your knowledge about this emoticon
thumbnail
Bruce Altner, modificado 13 Anos atrás.

RE: Bulk loading of files and folders into the Document Library

New Member Postagens: 20 Data de Entrada: 20/02/09 Postagens Recentes
Actually, I may have solved the multipart form problem by simply calling my action from a form using an actionUrl instead of an actionLink. I'm not getting the same error now but I am getting something equally annoying: the compiler cannot find a Liferay class that it should be able to find:


org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, _java_: 205: unable to resolve class com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission

This is strange because I've been importing classes from the com.liferay packages all weekend and things have worked fine. And I have this one on my system. In fact, to avoid this issue I manually stuffed the compiled class into a jar and put it into my portlet's lib directory. That stopped the complaints about not being able to find DLFolderPermission but instead gave me an unresolved compilation error:


16:44:02,561 ERROR [jsp:165] java.lang.Error: Unresolved compilation problem: 
 at com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil.getFolder(DLFolderLocalServiceUtil.java:214)
 at com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission.contains(DLFolderPermission.java:88)
 at com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission.check(DLFolderPermission.java:56)


Is this a classLoader issue? The package specified in the import statement is correct. There is something very strange going on with this particular class (Liferay 5.2.3 CE).

Thanks.