Combination View Flat View Tree View
Threads [ Previous | Next ]
python shi
When add a document, how to specified it document type?
November 7, 2012 7:55 PM
Answer

python shi

Rank: New Member

Posts: 11

Join Date: July 2, 2012

Recent Posts

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?
November 7, 2012 8:34 PM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

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?
November 7, 2012 9:36 PM
Answer

python shi

Rank: New Member

Posts: 11

Join Date: July 2, 2012

Recent Posts

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?
November 7, 2012 10:53 PM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

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?
November 7, 2012 11:13 PM
Answer

python shi

Rank: New Member

Posts: 11

Join Date: July 2, 2012

Recent Posts

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?
November 8, 2012 4:35 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

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?
November 20, 2012 12:34 AM
Answer

python shi

Rank: New Member

Posts: 11

Join Date: July 2, 2012

Recent Posts

OK, Thanks your help.