Message Boards

DLFileEntryLocalServiceUtil.updateFileEntry is saving the file as a draft

Carlos Barreiro, modified 3 Years ago.

DLFileEntryLocalServiceUtil.updateFileEntry is saving the file as a draft

New Member Posts: 16 Join Date: 11/25/19 Recent Posts

Hello, I need to put some DDMFormValues to a set of files that are already uploaded on my instance, and I found a way to do that with the DLFileEntryLocalServiceUtil.updateFileEntry method, as one of the parameters is a map with the DDMFormValues.

I've created a component that calls that method for each of the files that I need to update, and it's putting the metadata values, but the file is saved as a Draft, and the file entry's tags have been removed.

I suppose that maybe the tags should be in the DDMFormValues' map, but, how can I save the file as approved?

A portion of code of a try that i'm doing with a file: (I'm using DXP 7.1)

DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(43432);
			File file = DLFileEntryLocalServiceUtil.getFile(dlFileEntry.getFileEntryId(), dlFileEntry.getVersion(), false);
			InputStream is = DLFileEntryLocalServiceUtil.getFileAsStream(dlFileEntry.getFileEntryId(), dlFileEntry.getVersion());
			
			ServiceContext serviceContext = new ServiceContext();
			DLFileEntry dlFileEntryUpdated = DLFileEntryLocalServiceUtil.updateFileEntry(dlFileEntry.getUserId(), dlFileEntry.getFileEntryId(), dlFileEntry.getFileName(), dlFileEntry.getMimeType(), dlFileEntry.getTitle(), dlFileEntry.getDescription(), "TEST", false, dlFileEntry.getFileEntryTypeId(), ddmFormValuesMap, file, null, dlFileEntry.getSize(), serviceContext);

Thanks and regards!

thumbnail
Mohammed Yasin, modified 3 Years ago.

RE: DLFileEntryLocalServiceUtil.updateFileEntry is saving the file as a dra (Answer)

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts

Hi,

You can use DLApplocalservice instead of DLFileEntryLocalService for saving the file.       

Ex.

DLAppLocalServiceUtil.updateFileEntry(userId, fileEntryId, sourceFileName, mimeType, title, description, changeLog, majorVersion, file, serviceContext)


 

 

Carlos Barreiro, modified 3 Years ago.

RE: RE: DLFileEntryLocalServiceUtil.updateFileEntry is saving the file as a

New Member Posts: 16 Join Date: 11/25/19 Recent Posts

Hello Mohammed! Thanks for the suggestion. In this case, how could I set the DDMFormValues of the fileEntry? It doesn't appear in the parameter list, and they are the only reason of the update :( 

thumbnail
Mohammed Yasin, modified 3 Years ago.

RE: RE: DLFileEntryLocalServiceUtil.updateFileEntry is saving the file as a

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts

You can set DDMFormValues in ServiceContext object with name as below

serviceContext.setAttribute(DDMFormValues.class.getName() + StringPool.POUND +
						ddmStructure.getStructureId(), ddmFormValues);

 

Carlos Barreiro, modified 3 Years ago.

RE: RE: DLFileEntryLocalServiceUtil.updateFileEntry is saving the file as a

New Member Posts: 16 Join Date: 11/25/19 Recent Posts

Thank you Mohammed, that solved the problem I was facing. However later I had other problems with the DDMFormValues and finally changed them for expando fields, that to me are less problematic to work with. Anyway, thanks for your help!

Regards