
com.liferay.knowledge.base.service.impl.KBFolderLocalServiceImpl Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.knowledge.base.service.impl;
import aQute.bnd.annotation.ProviderType;
import com.liferay.knowledge.base.constants.KBFolderConstants;
import com.liferay.knowledge.base.exception.DuplicateKBFolderNameException;
import com.liferay.knowledge.base.exception.InvalidKBFolderNameException;
import com.liferay.knowledge.base.exception.KBFolderParentException;
import com.liferay.knowledge.base.exception.NoSuchFolderException;
import com.liferay.knowledge.base.model.KBFolder;
import com.liferay.knowledge.base.service.base.KBFolderLocalServiceBaseImpl;
import com.liferay.knowledge.base.util.KnowledgeBaseUtil;
import com.liferay.portal.kernel.dao.orm.QueryDefinition;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import java.util.Date;
import java.util.List;
/**
* @author Brian Wing Shun Chan
*/
@ProviderType
public class KBFolderLocalServiceImpl extends KBFolderLocalServiceBaseImpl {
@Override
public KBFolder addKBFolder(
long userId, long groupId, long parentResourceClassNameId,
long parentResourcePrimKey, String name, String description,
ServiceContext serviceContext)
throws PortalException {
// KB folder
User user = userLocalService.getUser(userId);
Date now = new Date();
validateName(groupId, parentResourcePrimKey, name);
validateParent(parentResourceClassNameId, parentResourcePrimKey);
long kbFolderId = counterLocalService.increment();
KBFolder kbFolder = kbFolderPersistence.create(kbFolderId);
kbFolder.setUuid(serviceContext.getUuid());
kbFolder.setGroupId(groupId);
kbFolder.setCompanyId(user.getCompanyId());
kbFolder.setUserId(userId);
kbFolder.setUserName(user.getFullName());
kbFolder.setCreateDate(now);
kbFolder.setModifiedDate(now);
kbFolder.setParentKBFolderId(parentResourcePrimKey);
kbFolder.setName(name);
kbFolder.setUrlTitle(
getUniqueUrlTitle(
groupId, parentResourcePrimKey, kbFolderId, name));
kbFolder.setDescription(description);
kbFolderPersistence.update(kbFolder);
// Resources
if (serviceContext.isAddGroupPermissions() ||
serviceContext.isAddGuestPermissions()) {
addKBFolderResources(
kbFolder, serviceContext.isAddGroupPermissions(),
serviceContext.isAddGuestPermissions());
}
else {
addKBFolderResources(
kbFolder, serviceContext.getGroupPermissions(),
serviceContext.getGuestPermissions());
}
return kbFolder;
}
@Override
public KBFolder deleteKBFolder(long kbFolderId) throws PortalException {
KBFolder kbFolder = kbFolderPersistence.findByPrimaryKey(kbFolderId);
kbArticleLocalService.deleteKBArticles(
kbFolder.getGroupId(), kbFolder.getKbFolderId());
List childKBFolders = kbFolderPersistence.findByG_P(
kbFolder.getGroupId(), kbFolder.getKbFolderId());
for (KBFolder childKBFolder : childKBFolders) {
deleteKBFolder(childKBFolder.getKbFolderId());
}
return kbFolderPersistence.remove(kbFolder);
}
@Override
public KBFolder fetchFirstChildKBFolder(long groupId, long kbFolderId)
throws PortalException {
return fetchFirstChildKBFolder(groupId, kbFolderId, null);
}
@Override
public KBFolder fetchFirstChildKBFolder(
long groupId, long kbFolderId, OrderByComparator obc)
throws PortalException {
return kbFolderPersistence.fetchByG_P_First(groupId, kbFolderId, obc);
}
@Override
public KBFolder fetchKBFolder(long kbFolderId) {
return kbFolderPersistence.fetchByPrimaryKey(kbFolderId);
}
@Override
public KBFolder fetchKBFolder(String uuid, long groupId) {
return kbFolderPersistence.fetchByUUID_G(uuid, groupId);
}
@Override
public KBFolder fetchKBFolderByUrlTitle(
long groupId, long parentKbFolderId, String urlTitle)
throws PortalException {
return kbFolderPersistence.fetchByG_P_UT(
groupId, parentKbFolderId, urlTitle);
}
@Override
public KBFolder getKBFolderByUrlTitle(
long groupId, long parentKbFolderId, String urlTitle)
throws PortalException {
return kbFolderPersistence.findByG_P_UT(
groupId, parentKbFolderId, urlTitle);
}
@Override
public List getKBFolders(
long groupId, long parentKBFolderId, int start, int end)
throws PortalException {
return kbFolderPersistence.findByG_P(
groupId, parentKBFolderId, start, end);
}
@Override
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy