Fórum

When add a document, how to specified it document type?

thumbnail
python shi, modificado 11 Anos atrás.

When add a document, how to specified it document type?

New Member Postagens: 11 Data de Entrada: 03/07/12 Postagens Recentes
I call the method
DLAppServiceUtil.addFileEntry(repositoryId, folderId, file.getName(),
mimeType, title, description, "log", file, serviceContext);
to add a document success, but it just a basic document, how to specified it document type?


Thanks.
thumbnail
Tejas Kanani, modificado 11 Anos atrás.

RE: When add a document, how to specified it document type?

Liferay Master Postagens: 654 Data de Entrada: 06/01/09 Postagens Recentes
Hi python,

You'll have to pass document type Id in "fileEntryTypeId" parameter name and need to set it in serviceContext object as attributes which is the last parameter in the function.
serviceContext.setAttributes(attributes);
in which attributes is Map<String, Serializable> attributes = new HashMap<String, Serializable>();

You may also need to set metadata field values which you have created in your custom document type. Check how Liferay OOTB stores it.

Hope this might help you.

Thanks,
Tejas
thumbnail
python shi, modificado 11 Anos atrás.

RE: When add a document, how to specified it document type?

New Member Postagens: 11 Data de Entrada: 03/07/12 Postagens Recentes
Hi, Tejas,
Thank you for your reply first, but still not success.
I create a custom type "Shipment Pre-alert" in document library, then to do this[
code]//set file entry type
long fileEntryTypeId = DLFileEntryTypeLocalServiceUtil.getFileEntryType(groupId, type).getFileEntryTypeId();
Map<String, Serializable> attributes = new HashMap<String, Serializable>();
attributes.put("fileEntryTypeId", fileEntryTypeId);
serviceContext.setAttributes(attributes);
but it occur exception: {"exception":"com.liferay.portlet.dynamicdatamapping.StorageException: com.liferay.portal.NoSuchUserException: No User exists with the primary key 0"}
What's problem? and what is the "dynamicdatamapping".




Thanks,
python.
thumbnail
Tejas Kanani, modificado 11 Anos atrás.

RE: When add a document, how to specified it document type?

Liferay Master Postagens: 654 Data de Entrada: 06/01/09 Postagens Recentes
You need to debug through below classes to check what exactly is causing this.
debug addFileEntry method of class
com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl -->
public DLFileEntry addFileEntry(
long userId, long groupId, long repositoryId, long folderId,
String sourceFileName, String mimeType, String title,
String description, String changeLog, long fileEntryTypeId,
Map<String, Fields> fieldsMap, File file, InputStream is, long size,
ServiceContext serviceContext)
throws PortalException, SystemException

You should get exact problem.

And regarding
what is the "dynamicdatamapping".

As I've mentioned you might also need to provide metadata field values which you have configured for your custom type "Shipment Pre-alert".
thumbnail
python shi, modificado 11 Anos atrás.

RE: When add a document, how to specified it document type?

New Member Postagens: 11 Data de Entrada: 03/07/12 Postagens Recentes
I have solved this problem, set userId in ServiceContext it well, serviceContext.setUserId(user.getUserId()).

Thanks.
thumbnail
Tejas Kanani, modificado 11 Anos atrás.

RE: When add a document, how to specified it document type?

Liferay Master Postagens: 654 Data de Entrada: 06/01/09 Postagens Recentes
That is great ...

Just want to add one more thing over here.
For commonly used variables you can use below method to prepare serviceContext which will fill all the basic properties like userId, companyId, scopeGroupId, etc ..
ServiceContext serviceContext = ServiceContextFactory.getInstance(HttpServletRequest / PortletRequest);


For more details on which all properties it's filling for you, just check out com.liferay.portal.service.ServiceContextFactory class.

Thanks,
Tejas
thumbnail
python shi, modificado 11 Anos atrás.

RE: When add a document, how to specified it document type?

New Member Postagens: 11 Data de Entrada: 03/07/12 Postagens Recentes
OK, Thanks your help.