Fórum

add file programmatically into liferay

thumbnail
elias saliba, modificado 11 Anos atrás.

add file programmatically into liferay

New Member Postagens: 24 Data de Entrada: 16/07/12 Postagens Recentes
please help,

i'am creating a liferay portlet where i can upload document files and images. the upload process works well but every document or file uploaded have the status draft, and don't appears in the workflow tasks. how can i programmatically add a file with status Pending??

here is my code:

DLFileEntry dlFileEntry=DLFileEntryLocalServiceUtil.addFileEntry(themeDisplay.getUserId(),10179, repId, folId, fileName+".png", MimeTypesUtil.getContentType(fin), fileTitle, fileDesc, "sss",
entryType.getFileEntryTypeId()
,fieldsMap
,fin
,null
,fin.length()
,serviceContext);
thumbnail
Jignesh Vachhani, modificado 11 Anos atrás.

RE: add file programmatically into liferay

Liferay Master Postagens: 803 Data de Entrada: 10/03/08 Postagens Recentes
I haven't tried but as i have seen code of DLFileEntryLocalServiceImpl class and in that you just try to replace below code in public DLFileEntry addFileEntry( method

DLFileVersion dlFileVersion = addFileVersion(
user, dlFileEntry, serviceContext.getModifiedDate(now), extension,
mimeType, title, description, null, StringPool.BLANK,
fileEntryTypeId, fieldsMap, DLFileEntryConstants.VERSION_DEFAULT,
size, WorkflowConstants.STATUS_PENDING, serviceContext);

You can override this class using ext or hook.
thumbnail
Paul ., modificado 11 Anos atrás.

RE: add file programmatically into liferay

Liferay Master Postagens: 522 Data de Entrada: 29/08/11 Postagens Recentes
check out
com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.updateStatus(....)
thumbnail
elias saliba, modificado 11 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 24 Data de Entrada: 16/07/12 Postagens Recentes
thank you for your help but your solutions doesn't work.
do you have another solutions??
thumbnail
elias saliba, modificado 11 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 24 Data de Entrada: 16/07/12 Postagens Recentes
help me out please,

the main problem is that when i upload a file programmatically, its status is draft. and the file don't appear in the list of workflow. how can i change this??
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: add file programmatically into liferay

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
So did you try updateStatus as Paul suggested.
thumbnail
elias saliba, modificado 11 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 24 Data de Entrada: 16/07/12 Postagens Recentes
Hitoshi Ozawa:
So did you try updateStatus as Paul suggested.



yes hitoshi i tried it :

DLFileEntry dlFileEntryUpdated = DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), dlFileEntry.getFileVersion().getFileVersionId() ,WorkflowConstants.ACTION_PUBLISH, null, serviceContext);

the status of the file has been changed to "(pending)" but the problem is that i can't approve the file in the workflow..
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: add file programmatically into liferay

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Did you start workflow?

WorkflowHandlerRegistryUtil.startWorkflowInstance
thumbnail
elias saliba, modificado 11 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 24 Data de Entrada: 16/07/12 Postagens Recentes
Hitoshi Ozawa:
Did you start workflow?

WorkflowHandlerRegistryUtil.startWorkflowInstance



no can you explain to me what is the necessity of this?? thank you
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: add file programmatically into liferay

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
I think you can't approve it because you haven't started a workflow instance and assigned userId to it.
If you have "Liferay in Action" I think there's an explanation in it.
thumbnail
elias saliba, modificado 11 Anos atrás.

RE: add file programmatically into liferay (Resposta)

New Member Postagens: 24 Data de Entrada: 16/07/12 Postagens Recentes
i found the solution....
thank you all for your help. i added a file an then updated programmatically with the same values, and it works!

DLFileEntryLocalServiceUtil.updateFileEntry(...);
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: add file programmatically into liferay

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Sorry for misguiding you. Good to hear that you have it working now. :-)
thumbnail
elias saliba, modificado 11 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 24 Data de Entrada: 16/07/12 Postagens Recentes
Hitoshi Ozawa:
Sorry for misguiding you. Good to hear that you have it working now. :-)


no Hitoshi you didn't misguided me. thank you for your help it's a pleasure:-)
sandip niyogi, modificado 11 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 12 Data de Entrada: 11/01/12 Postagens Recentes
hello ,
can you please tell me how to add files programatically in liferay document library
i have tried all the possible solution getting the value in dlfolder
then trying to add it through addfileentry.

"ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
String title = "Jit" + StringPool.UNDERLINE + file.getName();
DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
actionRequest);
till this much it is working fine
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, groupId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId ,fieldsMap, file, null, file.length(), serviceContext);
HERE THE PROBLEM STARTS
Can plese help me out with this that will be a great help .
THANKS IN ADVANCE
thumbnail
elias saliba, modificado 11 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 24 Data de Entrada: 16/07/12 Postagens Recentes
sandip niyogi:
hello ,
can you please tell me how to add files programatically in liferay document library
i have tried all the possible solution getting the value in dlfolder
then trying to add it through addfileentry.

"ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
String title = "Jit" + StringPool.UNDERLINE + file.getName();
DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
actionRequest);
till this much it is working fine
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, groupId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId ,fieldsMap, file, null, file.length(), serviceContext);
HERE THE PROBLEM STARTS
Can plese help me out with this that will be a great help .
THANKS IN ADVANCE




you have to add a file and the update it without changing anything. here is the code->

DLFileEntry dlFileEntry=DLFileEntryLocalServiceUtil.addFileEntry(userId,10179, repId, folId, fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, "sss",
entryType.getFileEntryTypeId()
,fieldsMap
,fileInfo.getFile()
,null
,fileInfo.getFile().length()
,serviceContext);

DLFileEntryLocalServiceUtil.updateFileEntry(userId, dlFileEntry.getFileEntryId(), fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, comment, true, dlFileEntry.getFileEntryTypeId(), fieldsMap, fileInfo.getFile(), null, fileInfo.getFile().length(), serviceContext);
sandip niyogi, modificado 11 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 12 Data de Entrada: 11/01/12 Postagens Recentes
thank you for the help it is working now
Natasa Bulatovic, modificado 10 Anos atrás.

RE: add file programmatically into liferay

Junior Member Postagens: 28 Data de Entrada: 07/06/11 Postagens Recentes
Thank you all, if this thread did not exist, i was lost to dig in again into source code for a very simple operation.
@LiferayDevelopers: why does one needs to call both methods?
The problem i had (until i finally called update method again): file was created, could even set it to Published, but could never update it again.

Tricky and time consuming ... Please do something to change it .

Best
Natasa
Joan Fluvia, modificado 10 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 13 Data de Entrada: 06/11/13 Postagens Recentes
I did as mentioned: addFileEntry and then the updateFileEntry and the file is uploading as published correctly.
But when I try to access it directly with the URL: http://localhost:8080/documents/....pdf/...
It says that I have to log in (If I log in I can see it).
So I check the permissions in the DocumentLibrary and the permissions are ok. And just after checking the permissions (without saving, only clicking the permissions button) then I can access the file with the URL without asking me to log in. Anyone else with the same issue?

The way I initilize the ServiceContext is this:

public ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

I have a script that simulates clicking the permissions button for every document in the DocumentLibrary. But if someone offers a better approach...

Thanks,
Joan
Eric Smith, modificado 10 Anos atrás.

RE: add file programmatically into liferay

Junior Member Postagens: 66 Data de Entrada: 28/08/12 Postagens Recentes
Thanks Elias, this post saved me 1+ days of headaches.
Alfresco_Liferay developer, modificado 9 Anos atrás.

RE: add file programmatically into liferay

New Member Postagens: 18 Data de Entrada: 22/09/14 Postagens Recentes
Hi

I am new in liferay. please can any one copy aste whole logic of uploading file. I didn't know from where can i get my group id, folder id etc...
please help me..

Thank you
thumbnail
Enrique Valdes Lacasa, modificado 8 Anos atrás.

RE: add file programmatically into liferay

Junior Member Postagens: 92 Data de Entrada: 29/07/14 Postagens Recentes
elias saliba:
sandip niyogi:
hello ,
can you please tell me how to add files programatically in liferay document library
i have tried all the possible solution getting the value in dlfolder
then trying to add it through addfileentry.

"ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
String title = "Jit" + StringPool.UNDERLINE + file.getName();
DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
actionRequest);
till this much it is working fine
DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, groupId, folderId, fileName, mimeType, fileName, StringPool.BLANK, StringPool.BLANK, fileEntryTypeId ,fieldsMap, file, null, file.length(), serviceContext);
HERE THE PROBLEM STARTS
Can plese help me out with this that will be a great help .
THANKS IN ADVANCE




you have to add a file and the update it without changing anything. here is the code->

DLFileEntry dlFileEntry=DLFileEntryLocalServiceUtil.addFileEntry(userId,10179, repId, folId, fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, "sss",
entryType.getFileEntryTypeId()
,fieldsMap
,fileInfo.getFile()
,null
,fileInfo.getFile().length()
,serviceContext);

DLFileEntryLocalServiceUtil.updateFileEntry(userId, dlFileEntry.getFileEntryId(), fileName+".png", MimeTypesUtil.getContentType(fileInfo.getFile()), fileTitle, fileDesc, comment, true, dlFileEntry.getFileEntryTypeId(), fieldsMap, fileInfo.getFile(), null, fileInfo.getFile().length(), serviceContext);


Thank you Elias. This worked for me. As you said, the files were uploaded with the Draft status, since I guess they weren't added to the DB without calling the updateFileEntry() method. Your suggestions saved me a few hours, thanks!
domenico fiorilli, modificado 7 Anos atrás.

RE: add file programmatically into liferay

New Member Mensagem: 1 Data de Entrada: 21/01/16 Postagens Recentes
Hi all, I noticed that when I try an update of the file, metadata fields are not written to the database, in fact, if I try to exec my web services, its metadata fields are null.

Someone help me please?

Thank you