Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Tom Mahy
DLAppServiceUtil RepositoryId
December 18, 2012 3:06 AM
Answer

Tom Mahy

Rank: Junior Member

Posts: 38

Join Date: May 2, 2012

Recent Posts

Hi,

Im trying to search the Document library.
im making use of the new api in liferay 6.1 GA2

1SearchContext searchContext = new SearchContext();
2ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
3Group group = GroupLocalServiceUtil.getGroup(themeDisplay.getScopeGroupId());
4Hits hits = DLAppServiceUtil.search(group.getGroupId(), searchContext);


If i run this i get the error :
Caused by: com.liferay.portal.NoSuchGroupException: No Group exists with the key {companyId=0, classNameId=10008, classPK=0}

On the docs page i have :
http://docs.liferay.com/portal/6.1/javadocs-all/com/liferay/portlet/documentlibrary/service/impl/DLAppServiceImpl.html

The repositoryId parameter used by most of the methods is the primary key of the specific repository. If the repository is a default Liferay repository, the repositoryId is the groupId or scopeGroupId. Otherwise, the repositoryId will correspond to values obtained from RepositoryServiceUtil.

as suggested here
http://www.liferay.com/community/forums/-/message_boards/message/7469538?_19_redirect=http%3A%2F%2Fwww.liferay.com%2Fcommunity%2Fforums%2F-%2Fmessage_boards%2Fsearch%3F_19_keywords%3DRepositoryId%26_19_searchCategoryId%3D0%26_19_breadcrumbsCategoryId%3D0%26_19_redirect%3Dhttp%253A%252F%252Fwww.liferay.com%252Fcommunity%252Fforums%252F-%252Fmessage_boards%252Fmessage%252F18700409

i tried doing this :
Hits hits = DLAppServiceUtil.search(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, searchContext);

But i get another error:
Caused by: com.liferay.portal.kernel.repository.RepositoryException: No Repository exists with the primary key 0

What am i doing wrong here ?
Tom Mahy
RE: DLAppServiceUtil RepositoryId
December 18, 2012 3:31 AM
Answer

Tom Mahy

Rank: Junior Member

Posts: 38

Join Date: May 2, 2012

Recent Posts

is also tried the brute approach with

 1SearchContext searchContext = new SearchContext();
 2        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
 3
 4        try {
 5
 6            List<DLFolder> folders = DLFolderLocalServiceUtil.getCompanyFolders(themeDisplay.getCompanyId(), 0, 1);
 7            DLFolder dlFolder = null;
 8
 9            if (folders.size() < 1) {
10
11                long userId = PortalUtil.getUserId(request);
12                long groupId = themeDisplay.getScopeGroupId();
13                long repositoryId = new Long(0);
14                boolean mountPoint = false;
15                long parentFolderId = new Long(0);
16                String name = "_empty";
17                String description = "";
18                ServiceContext serviceContext = new ServiceContext();
19
20                dlFolder = DLFolderLocalServiceUtil.addFolder(userId, groupId, repositoryId, mountPoint, parentFolderId, name, description, serviceContext);
21            } else {
22                dlFolder = folders.get(0);
23            }
24
25            Hits hits = DLAppServiceUtil.search(dlFolder.getRepositoryId(), searchContext);


But i end up with the same problem.

Caused by: com.liferay.portal.kernel.search.SearchException: com.liferay.portal.NoSuchGroupException: No Group exists with the key {companyId=0, classNameId=10008, classPK=0}
Mika Koivisto
RE: DLAppServiceUtil RepositoryId
December 18, 2012 12:26 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1501

Join Date: August 7, 2006

Recent Posts

Use themeDisplay.getScopeGroupId() as the repositoryId and you'll get the default Liferay repository. If you want to search any mounted repositories then you need to figure out what is their repositoryId.
Tom Mahy
RE: DLAppServiceUtil RepositoryId
December 19, 2012 12:45 AM
Answer

Tom Mahy

Rank: Junior Member

Posts: 38

Join Date: May 2, 2012

Recent Posts

So i did this.

1SearchContext searchContext = new SearchContext();
2ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
3Hits hits = DLAppServiceUtil.search(themeDisplay.getScopeGroupId(), searchContext);


If i run this i get the same error :
Caused by: com.liferay.portal.NoSuchGroupException: No Group exists with the key {companyId=0, classNameId=10008, classPK=0}
Mika Koivisto
RE: DLAppServiceUtil RepositoryId
December 20, 2012 10:37 AM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1501

Join Date: August 7, 2006

Recent Posts

Oh I didn't notice before that you were just creating a new instance of SearchContext without populating it. You should create the SearchContext like this:
1SearchContext searchContext = SearchContextFactory.getInstance(request);
Tom Mahy
RE: DLAppServiceUtil RepositoryId
January 8, 2013 1:03 AM
Answer

Tom Mahy

Rank: Junior Member

Posts: 38

Join Date: May 2, 2012

Recent Posts

that works great. Thank you.