Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Document Library API, create/update DL file entry Vadim Golub February 16, 2011 8:51 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee April 19, 2011 6:24 AM
RE: Document Library API, create/update DL file entry Corné Aussems April 19, 2011 6:54 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee April 19, 2011 8:56 AM
RE: Document Library API, create/update DL file entry Corné Aussems April 19, 2011 12:51 PM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee April 19, 2011 1:00 PM
RE: Document Library API, create/update DL file entry Corné Aussems April 19, 2011 1:08 PM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee April 19, 2011 1:12 PM
RE: Document Library API, create/update DL file entry Muhammad Asif June 1, 2011 3:47 PM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee June 2, 2011 12:47 AM
RE: Document Library API, create/update DL file entry ankit yakkundi June 16, 2011 2:44 AM
RE: Document Library API, create/update DL file entry Sarav Veda June 16, 2011 3:16 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee June 16, 2011 3:34 AM
RE: Document Library API, create/update DL file entry ankit yakkundi June 16, 2011 3:36 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee June 16, 2011 3:43 AM
RE: Document Library API, create/update DL file entry ankit yakkundi June 16, 2011 3:48 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee June 16, 2011 3:54 AM
RE: Document Library API, create/update DL file entry Vadim Golub September 20, 2011 7:20 PM
RE: Document Library API, create/update DL file entry Akhilesh Sharma November 28, 2011 1:03 AM
RE: Document Library API, create/update DL file entry Corné Aussems November 28, 2011 1:12 AM
RE: Document Library API, create/update DL file entry Akhilesh Sharma November 28, 2011 3:58 AM
RE: Document Library API, create/update DL file entry Corné Aussems November 28, 2011 4:18 AM
RE: Document Library API, create/update DL file entry Akhilesh Sharma November 28, 2011 10:41 PM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee November 28, 2011 11:58 PM
RE: Document Library API, create/update DL file entry Akhilesh Sharma November 29, 2011 1:19 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee November 29, 2011 1:27 AM
RE: Document Library API, create/update DL file entry Akhilesh Sharma November 29, 2011 4:03 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee November 29, 2011 4:25 AM
RE: Document Library API, create/update DL file entry Akhilesh Sharma November 29, 2011 4:55 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee November 29, 2011 5:02 AM
RE: Document Library API, create/update DL file entry Akhilesh Sharma November 29, 2011 5:13 AM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee November 29, 2011 5:15 AM
RE: Document Library API, create/update DL file entry Akhilesh Sharma November 29, 2011 9:50 PM
RE: Document Library API, create/update DL file entry Jonny Olliff-Lee November 29, 2011 11:54 PM
RE: Document Library API, create/update DL file entry Akhilesh Sharma December 1, 2011 12:55 AM
RE: Document Library API, create/update DL file entry Arun Kulasegaran November 13, 2013 5:59 AM
RE: Document Library API, create/update DL file entry Kumar K May 7, 2013 11:13 PM
Vadim Golub
Document Library API, create/update DL file entry
February 16, 2011 8:51 AM
Answer

Vadim Golub

Rank: New Member

Posts: 5

Join Date: July 9, 2008

Recent Posts

Hello folks,

I've tried to find something on the subj but couldn't find anything (well, apart from source code). Could anyone suggest anything on the way we can use DL services to update and create DL file programmatically?

So I need something like that (I'm ok with fetching the file):
1
2DLFileEntry file = getFile();
3if (null != file) {
4    DLLocalServiceUtil.updateFile(...);
5} else {
6    DLLocalServiceUtil.addFile(...);
7}


But there are too many parameters I am not sure about like portletId (I'm trying to use the functionality for administrative reasons to store the configuration so the portlet is not important), fileEntryId (if we're just creating the file how can we know the entry ID), repositoryId (is it a folder ID or not), etc.

I would be thankful if someone will show how to use that API or give some reference where I can find that.

Thanks in advance.
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
April 19, 2011 6:24 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Hey Vadim,

Are you still having this issue? I've managed to add & delete files from the DL, but updating is still eluding me.

If you are still having issues let me know and I will post my code.
Corné Aussems
RE: Document Library API, create/update DL file entry
April 19, 2011 6:54 AM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1270

Join Date: October 3, 2006

Recent Posts

 1
 2public DLFileEntry addOrOverwriteFile(final File file, final long folderId, final long userId,
 3            final String fileName, final String title, final String sourceName, final String description)
 4            throws VDNassert {
 5        DLFileEntry fileEntry = null;
 6        try {
 7            String extraSettings = null;// ?
 8 ServiceContext serviceContext = new ServiceContext();
 9try{
10 fileEntry = DLFileEntryLocalServiceUtil.getFileEntryByTitle(folderId, fileName);
11 if (fileEntry == null)
12    throw new NoSuchFileEntryException();
13  fileEntry = DLFileEntryLocalServiceUtil.updateFileEntry(userId, folderId, 0, fileEntry.getName(),fileName, title, description, extraSettings, file, serviceContext);
14} catch (NoSuchFileEntryException noSuchFileEntryException) {
15  fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, folderId, fileName, FileUtil.stripExtension(fileName), description, extraSettings, file, serviceContext);
16
17        } catch (Exception e) {
18            logger.error("addOrOverwriteFile(File, long, long, String, String, String, String)", e); //$NON-NLS-1$
19            VDNassert.always(e.getMessage());
20        } finally {
21        }
22        return fileEntry;


BTW
DLFileEntryLocalServiceUtil.addOrOverwriteFileEntry
was buggy to me but could be a good learning start
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
April 19, 2011 8:56 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Thank you Corné!

Although I'm still having issues with updateFileEntry:

1DLFileEntryLocalServiceUtil.updateFileEntry(realUserId, folderId, folderId, fileEntry.getName(), fileEntry.getName(), filename, description, "", fileObject, serviceContext);


I want the updated file to be in the same folder, and I want it to have the same name. However when this runs I get a NoSuchFileException and then the name of the file (which after looking at the database is the right file name).

Any ideas as to where I am going wrong?

Thanks.
Corné Aussems
RE: Document Library API, create/update DL file entry
April 19, 2011 12:51 PM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1270

Join Date: October 3, 2006

Recent Posts

when you look closely at the signature you will see that you have mistaken a parameter


[url=http://docs.liferay.com/portal/5.0/javadocs/portal-impl/com/liferay/portlet/documentlibrary/service/impl/DLFileEntryLocalServiceImpl.html#updateFileEntry(long, long, long, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String[], java.lang.String, java.io.File)]http://docs.liferay.com/portal/5.0/javadocs/portal-impl/com/liferay/portlet/documentlibrary/service/impl/DLFileEntryLocalServiceImpl.html.

long newFolderId should be 0; don't ask me why?

Or are we talking about Liferay 6.0?

[url=http://docs.liferay.com/portal/6.0/javadocs/com/liferay/portlet/documentlibrary/service/DLFileEntryLocalServiceUtil.html#updateFileEntry(long, long, long, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, java.lang.String, java.io.File, com.liferay.portal.service.ServiceContext)]http://docs.liferay.com/portal/6.0/javadocs/com/liferay/portlet/documentlibrary/service/DLFileEntryLocalServiceUtil.html.
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
April 19, 2011 1:00 PM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Thanks Corné, that sounds like it could be my problem! We are talking Liferay 5! emoticon

Sorry if it's a stupid question, but how did you know about the "0" for newFolderId? Is it documented somewhere, or just something you picked up along the way?

Thanks again!
Corné Aussems
RE: Document Library API, create/update DL file entry
April 19, 2011 1:08 PM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1270

Join Date: October 3, 2006

Recent Posts

Thats the power of opensource.emoticon
I just step through the code and find out
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
April 19, 2011 1:12 PM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Hidden in plain sight! emoticon Next time I'll check the source first! Thanks again for your help!
Muhammad Asif
RE: Document Library API, create/update DL file entry
June 1, 2011 3:47 PM
Answer

Muhammad Asif

Rank: New Member

Posts: 24

Join Date: April 11, 2011

Recent Posts

i have created DLLocalService.addFile and i also have created DLFileEntryLocalService.addFileEntry but still it is not showing up in Document Library

Can you please tell what else should I do?
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
June 2, 2011 12:47 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Muhammad Asif:
i have created DLLocalService.addFile and i also have created DLFileEntryLocalService.addFileEntry but still it is not showing up in Document Library

Can you please tell what else should I do?


Hi!

Here's my code for adding to the Document Library:
 1
 2ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
 3long realUserId = themeDisplay.getRealUserId();
 4long groupId = themeDisplay.getLayout().getGroupId();
 5ServiceContext serviceContext = new ServiceContext();
 6serviceContext.setScopeGroupId(groupId);
 7
 8String filename = "MyFileToUpload.txt";
 9File file = new File("/path/to/file/" + filename);
10
11// Create the folder to add the files to
12DLFolder folder = DLFolderLocalServiceUtil.addFolder(realUserId, groupId, 0, folderName, "Folder for files", serviceContext);
13DLFileEntryLocalServiceUtil.addFileEntry(realUserId, folder.getFolderId(), filename, filename, "", "", file, serviceContext);


That's the barebones of adding file to the Document Library. You'll need validation to see if the file already exists etc but that should get you started. Let me know if there is anything else you need to know / understand.

- Jonny (http://twitter.com/DevJonny)
ankit yakkundi
RE: Document Library API, create/update DL file entry
June 16, 2011 2:44 AM
Answer

ankit yakkundi

Rank: Regular Member

Posts: 221

Join Date: March 4, 2010

Recent Posts

Hi..
I am using liferay 6.
Can you send me complete code for uploading the files onto document library..
Following is my requirement:-
A schedular has to be created which will generate reports and generated reports PDF's would be added into DL thorugh API

Any idea or suggestions are welcome..
Thanks in advance..
Sarav Veda
RE: Document Library API, create/update DL file entry
June 16, 2011 3:16 AM
Answer

Sarav Veda

Rank: New Member

Posts: 10

Join Date: March 29, 2011

Recent Posts

I believe your scheduler will run out of the Liferay environment, if that is the case you should look in Tunnel web service of Liferay which will provide you the API access to do file operations.

Thanks.
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
June 16, 2011 3:34 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

ankit yakkundi:
Hi..
I am using liferay 6.
Can you send me complete code for uploading the files onto document library..
Following is my requirement:-
A schedular has to be created which will generate reports and generated reports PDF's would be added into DL thorugh API

Any idea or suggestions are welcome..
Thanks in advance..


Hi Ankit,

The code I posted above is more or less complete (for Liferay 5), without de-generalising the code. I would suggest that you try that code out and post back any issues you run into or questions you have.

Are you using the Quartz scheduler?

Jonny

Sarav Veda:

I believe your scheduler will run out of the Liferay environment, if that is the case you should look in Tunnel web service of Liferay which will provide you the API access to do file operations.
Thanks.


If Ankit is using Quartz this runs as a task from within Liferay so Tunnel Web Service is of no use unfortunately.
ankit yakkundi
RE: Document Library API, create/update DL file entry
June 16, 2011 3:36 AM
Answer

ankit yakkundi

Rank: Regular Member

Posts: 221

Join Date: March 4, 2010

Recent Posts

hi..
thanks for the reply..

i wanted to know how it will connect to liferay and from where it will get the request.
what i am trying for starter is i will start liferay server. i will mention the folder and file name and run my java class. the file which i am mentioning in the java has to be added into liferay's document library.
once it is working then i will start with schuler and integrating it with liferay.
following tis the code.

import java.io.File;

import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portlet.documentlibrary.model.DLFolder;
import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;


public class dL {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long realUserId = themeDisplay.getRealUserId();
long groupId = themeDisplay.getLayout().getGroupId();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);

String filename = "report.pdf";
File file = new File("/oss/" + filename);

String folderName;
// Create the folder to add the files to
DLFolder folder = DLFolderLocalServiceUtil.addFolder(realUserId, groupId, 0, folderName, "Folder for files", serviceContext);
DLFileEntryLocalServiceUtil.addFileEntry(realUserId, folder.getFolderId(), groupId, filename, filename, "", "", folderName, file, serviceContext);

}

}


Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
June 16, 2011 3:43 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Hi Ankit,

Right I see where you are coming from now. They way I'd suggest you do this is by creating a Liferay Portlet to perform the task you are trying to accomplish. Then all the required code will be run by that portlet, the request will come from when the portlet is loaded on a page etc.

Does that make sense?
ankit yakkundi
RE: Document Library API, create/update DL file entry
June 16, 2011 3:48 AM
Answer

ankit yakkundi

Rank: Regular Member

Posts: 221

Join Date: March 4, 2010

Recent Posts

thanks for the reply..
it means that i have to create a struts portlet.
can you please tell me what i need to do ie what modification i need to make in the code which i sent to you.
then what i would be showing in the portlet???
since i have to show something in the portlet.
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
June 16, 2011 3:54 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Well if you're using Liferay's Plugins-SDK you can get that to generate all the base code for the portlet for you! emoticon

If the code you've got there is placed in the doView method of the portlet then it will run as soon as the portlet is rendered (but nothing actually needs to be displayed to the user if you don't want it to.

The only other thing would be to change your actionRequest variable to renderRequest (if the code is in the doView method).

However if the file you're trying to upload is not being generated by Liferay then you might be better off using Tunnel Web Services as suggest by Sarav! When I have done this I was generating a file from within Liferay, then adding it to the Document Library.
Vadim Golub
RE: Document Library API, create/update DL file entry
September 20, 2011 7:20 PM
Answer

Vadim Golub

Rank: New Member

Posts: 5

Join Date: July 9, 2008

Recent Posts

I accidentally saw this chain and it seems that I started an avalanche emoticon however long ago..
Anyway, if someone is still interested in how I managed to implement the subj in Liferay, here are excerpts from my code:

 1
 2private static final String DEFAULT_COMMUNITY_NAME = "Guest";
 3
 4// ...
 5        try {
 6            if (null != file) {
 7                // update DL file
 8                updateDLFile(file, content);
 9            } else {
10                DLFolder folder = findFolder(communityName, folderName);
11               
12                // create the folder if it doesn't exist
13                if (null == folder) {
14                    folder = createDLFolder(folderName);
15                }
16               
17                // create teh file
18                createDLFile(folder, fileName, content);
19            }
20// ...
21
22        private void updateDLFile(DLFileEntry file, byte[] content) throws Exception {
23        long userId = UserLocalServiceUtil.getDefaultUserId(PortalUtil.getDefaultCompanyId());
24        String[] tagsEntries = TagsEntryLocalServiceUtil.getEntryNames(DLFileEntry.class.getName(), file.getFileEntryId());
25        ServiceContext serviceContext = new ServiceContext();
26        serviceContext.setTagsEntries(tagsEntries);
27       
28        DLFileEntryLocalServiceUtil.updateFileEntry(userId, file.getFolderId(), file.getFolderId(),
29                file.getName(), file.getName(), file.getTitle(), file.getDescription(),
30                file.getExtraSettings(), content, serviceContext);
31    }
32   
33    private DLFolder createDLFolder(String folderName) throws Exception {
34        long userId = UserLocalServiceUtil.getDefaultUserId(PortalUtil.getDefaultCompanyId());
35        // community equals group for guest so we can use it to get group ID which is required to add a folder
36        long groupId = GroupLocalServiceUtil.getGroup(PortalUtil.getDefaultCompanyId(), DEFAULT_COMMUNITY_NAME).getGroupId();
37       
38        ServiceContext serviceContext = new ServiceContext();
39
40        serviceContext.setAddCommunityPermissions(true);
41        serviceContext.setAddGuestPermissions(true);
42       
43        return DLFolderLocalServiceUtil.addFolder(userId, groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
44                folderName, StringPool.BLANK, serviceContext);
45    }
46   
47    private DLFileEntry createDLFile(DLFolder folder, String fileName, byte[] content) throws Exception {
48        if (null == folder) {
49            return null;
50        }
51       
52        long folderId = folder.getFolderId();
53        String name = fileName + "." +MyDLFileExtension.CONFIG_FILES_EXTENSION.toString();
54        String title = fileName + "." + MyDLFileExtension.CONFIG_FILES_EXTENSION.toString();
55        String description = StringPool.BLANK;
56        String extraSettings = StringPool.BLANK;
57       
58        ServiceContext serviceContext = new ServiceContext();
59
60        serviceContext.setAddCommunityPermissions(true);
61        serviceContext.setAddGuestPermissions(true);
62       
63        return DLFileEntryLocalServiceUtil.addFileEntry(folder.getUserId(), folderId, name, title, description, extraSettings,
64                content, serviceContext);
65    }


Few notes though..
1. Be careful with permissions. In my case the app creates a folder under guest so that anyone can access it.
2. Default community name is 'Guest' which I got from the source and didn't see any other way to get it. I need it in order to get the default group ID which I cannot get because usually group ID is being fetched from request and in my case request didn't necessarily existed at the point when JCR was required..
3. I read communityName from outside so it didn't came from request.

Hope it helps someone.. Back in the days it could save me a day or two emoticon
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
November 28, 2011 1:03 AM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

hello folks,
i am new to the liferay and i wanted to add folder to the document library using java code how can i do this.
please reply.
regards
Akhilesh
Corné Aussems
RE: Document Library API, create/update DL file entry
November 28, 2011 1:12 AM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1270

Join Date: October 3, 2006

Recent Posts

Akhilesh Sharma:
hello folks,
i am new to the liferay and i wanted to add folder to the document library using java code how can i do this.
please reply.
regards
Akhilesh



Hi Akhilesh,

You better do not post on old threads.
Chances are people not answering them.

Here is a snippet for 6.0.6
1   
2  ServiceContext serviceContext = new ServiceContext();
3  DLFolderLocalServiceUtil.addFolder(userId, groupId , folderId, name, description, serviceContext);
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
November 28, 2011 3:58 AM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

thanks for your reply. my actionRequest is coming null. what can i do so it will not come null. i am trying this since last 4 days please help me if you have code then please paste here. i will be very thankfull to you.
regards
Akhilesh
Corné Aussems
RE: Document Library API, create/update DL file entry
November 28, 2011 4:18 AM
Answer

Corné Aussems

Rank: Liferay Legend

Posts: 1270

Join Date: October 3, 2006

Recent Posts

You need to be more elaborate on your issue
Maybe the Forum guidelines are of help.

Let us know your LR version and show your code and logs.
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
November 28, 2011 10:41 PM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

thanks for reply Corné Aussems.
but i am still getting error on 'actionRequest'
i am using liferay 6.0 on tomcat 6.0
following is my code:

public class DL
{
public static void main(String[] args)
{

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long groupId = themeDisplay.getScopeGroupId();
long userId = themeDisplay.getUserId();
ServiceContext folderServiceContext = new ServiceContext();
DLFolder dlFolder = DLFolderLocalServiceUtil.addFolder(userId, groupId, 0, "VIEW", "VIEW", folderServiceContext);
DLFolderLocalServiceUtil.addFolderResources(dlFolder, new String[]{"VIEW"}, new String[]{"VIEW"});
}
}

thanks in advance
regards
Akhilesh
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
November 28, 2011 11:58 PM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Hi Akhilesh,

Right the problem with your code is that you're trying to run this as a standalone piece of code. The ActionRequest comes from the processAction method of a portlet. All this should be done with in the code of a Liferay portlet, so that you can access ActionRequest.

Does this make sense?

Regards,
Jonny
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
November 29, 2011 1:19 AM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

thanks for reply Jonny
i am writing this class inside /My-Flex-Life-portlet/docroot/WEB-INF/src that is my portlet and for getting actionRequest ihave to override GenericPortlet class
or what?
do i need to write all my code inside processAction method by overriding it.
please tell me what modification required in my code.
regards
Akhilesh
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
November 29, 2011 1:27 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Yes you will need to EXTEND GenericPortlet, and then OVERRIDE the ProcessAction method.

No I wouldn't suggest writing everything in the processAction method as this is not a good way to write MVC code. Think of the class that extends GenericPortlet as the Controller of your MVC architecture.
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
November 29, 2011 4:03 AM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

thanks for your help Jonny
i wanted to know that how processAction method works is it called automatically ? if yes than in which condition it will be called automatically?
can i call it explicitly?
regards
Akhilesh
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
November 29, 2011 4:25 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

processAction is called usually when a form is submitted or some sort of action happens on a JSP page, for example:

1
2<form action="<portlet:actionURL name='fm'></portlet:actionURL>" method="post" id="banner" name="<portlet:namespace />fm">
3        <input type="submit" name="save" id="save" value="Save" onclick="document.<portlet:namespace />fm.submit();">
4</form>


When the button "Save" is clicked by a user, the portlet will enter the "Action" phase of it's Lifecycle and processAction will be invoked. I don't think you can invoke it manually.

However! If you want to access the Document Library in the Render Phase i.e. in the doView() method, than you can get the ThemeDisplay with the following code:

1ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);


Does that help? What exactly are you trying to achieve?
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
November 29, 2011 4:55 AM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

Thanks Jonny,
we have created project management kind of stuff. in which as soon as a new project is added
a new folder must be created in document library with that project name. so that the project related document can be managed inside that.

this is my class:-
ublic class DL extends GenericPortlet {

@Override
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
// TODO Auto-generated method stub
super.processAction(request, response);



ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
long groupId = themeDisplay.getScopeGroupId();
long userId = themeDisplay.getUserId();
ServiceContext folderServiceContext;
try {
folderServiceContext = ServiceContextFactory.getInstance(DLFolder.class.getName(), request);
DLFolder dlFolder = DLFolderLocalServiceUtil.addFolder(userId, groupId, 0, "VIEW", "VIEW", folderServiceContext);
DLFolderLocalServiceUtil.addFolderResources(dlFolder, new String[]{"VIEW"}, new String[]{"VIEW"});
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
for using this class in jsp page do i need to register it in portlet.xml or web.xml.
and in jsp page how i will refer this DL.java
thanks and regards
Akhilesh
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
November 29, 2011 5:02 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

I think you should look around for some resources about how to do those things (there are loads of Liferay portlet examples all over the internet, Google is your friend). In particular how to create Liferay (or any kind) of portlets, how they are set up, and how they work. Then if you have more specific questions create a new forum post for them.

Have you used an IDE (e.g. Eclipse + Liferay IDE plugin) or the create.bat file to generate your portlet code?
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
November 29, 2011 5:13 AM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

i am using eclipse helios
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
November 29, 2011 5:15 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Then I would suggest you install the Liferay IDE that you can find here on Sourceforge.
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
November 29, 2011 9:50 PM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

Hi Jonny,
i modified my code according to your suggestions. but when i am clicking on the submit button nothing is happening.
Please help me my deadline is very near.
here is my code:
view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.ActionRequest"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="javax.portlet.PortletPreferences" %>


<portlet:defineObjects />
<form action="<portlet:actionURL><portlet:param name="fm" value="mainview"/></portlet:actionURL>" method="post" id="banner" name="<portlet:namespace />fm">
<input type="submit" name="save" id="save" value="Save" onclick="document.<portlet:namespace />fm.submit();">
</form>
DL.java
public class DL extends GenericPortlet {

@Override
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
// TODO Auto-generated method stub
super.processAction(request, response);



ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
long groupId = themeDisplay.getScopeGroupId();
long userId = themeDisplay.getUserId();
ServiceContext folderServiceContext;
try {
folderServiceContext = ServiceContextFactory.getInstance(DLFolder.class.getName(), request);
DLFolder dlFolder = DLFolderLocalServiceUtil.addFolder(userId, groupId, 0, "VIEW", "VIEW", folderServiceContext);
DLFolderLocalServiceUtil.addFolderResources(dlFolder, new String[]{"VIEW"}, new String[]{"VIEW"});
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
portlet.xml
<portlet>
<portlet-name>CreateFolder</portlet-name>
<display-name>CreateFolder</display-name>
<portlet-class>javax.portlet.GenericPortlet</portlet-class>
<init-param>
<name>view-jsp</name>
<value>/view.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>CreateFolder</title>
<short-title>CreateFolder</short-title>
<keywords>CreateFolder</keywords>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
do i need to register DL.java class in portlet.xml
Regards
Akhilesh
Jonny Olliff-Lee
RE: Document Library API, create/update DL file entry
November 29, 2011 11:54 PM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Looks like your problem could be with this line:

1<portlet-class>javax.portlet.GenericPortlet</portlet-class>


This should be pointing to the sub-class of Generic Portlet i.e. DL.java. Also I'd remove the two lines:

1// TODO Auto-generated method stub
2super.processAction(request, response);


As I don't believe they are needed, and may actually cause you issues (like you're code not running).

Question: Did you create all these files from scratch? Or did you use Liferay's create.bat / create.sh script that generates all the necessary files for you?
Akhilesh Sharma
RE: Document Library API, create/update DL file entry
December 1, 2011 12:55 AM
Answer

Akhilesh Sharma

Rank: New Member

Posts: 12

Join Date: November 28, 2011

Recent Posts

Thanks a lot jonny
my problem is solved. i was missing the portlet-class .
thank you very much
regards
Akhilesh
Kumar K
RE: Document Library API, create/update DL file entry
May 7, 2013 11:13 PM
Answer

Kumar K

Rank: New Member

Posts: 19

Join Date: January 25, 2013

Recent Posts

Hi,

I am able to add documents to document library. But added documents are not visible in liferay document library But the file entries are there in dlfileentry table. Any help?
Arun Kulasegaran
RE: Document Library API, create/update DL file entry
November 13, 2013 5:59 AM
Answer

Arun Kulasegaran

Rank: New Member

Posts: 8

Join Date: August 23, 2013

Recent Posts

Hi,
I`m new to liferay... I want to update a document by the users in the workflow of the doucument .. Is it possible? Its urgent....PLZ Help..
I'm using Liferay 6.1.1 CE and kaleo workflow..