Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
python shi
When add a document, how to specified it document type?
7 de Novembro de 2012 19:55
Resposta

python shi

Ranking: New Member

Mensagens: 11

Data de entrada: 2 de Julho de 2012

Mensagens 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.
Tejas Kanani
RE: When add a document, how to specified it document type?
7 de Novembro de 2012 20:34
Resposta

Tejas Kanani

Ranking: Liferay Master

Mensagens: 655

Data de entrada: 6 de Janeiro de 2009

Mensagens 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
python shi
RE: When add a document, how to specified it document type?
7 de Novembro de 2012 21:36
Resposta

python shi

Ranking: New Member

Mensagens: 11

Data de entrada: 2 de Julho de 2012

Mensagens 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.
Tejas Kanani
RE: When add a document, how to specified it document type?
7 de Novembro de 2012 22:53
Resposta

Tejas Kanani

Ranking: Liferay Master

Mensagens: 655

Data de entrada: 6 de Janeiro de 2009

Mensagens 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".
python shi
RE: When add a document, how to specified it document type?
7 de Novembro de 2012 23:13
Resposta

python shi

Ranking: New Member

Mensagens: 11

Data de entrada: 2 de Julho de 2012

Mensagens recentes

I have solved this problem, set userId in ServiceContext it well, serviceContext.setUserId(user.getUserId()).

Thanks.
Tejas Kanani
RE: When add a document, how to specified it document type?
8 de Novembro de 2012 04:35
Resposta

Tejas Kanani

Ranking: Liferay Master

Mensagens: 655

Data de entrada: 6 de Janeiro de 2009

Mensagens 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
python shi
RE: When add a document, how to specified it document type?
20 de Novembro de 2012 00:34
Resposta

python shi

Ranking: New Member

Mensagens: 11

Data de entrada: 2 de Julho de 2012

Mensagens recentes

OK, Thanks your help.