Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.portal.service.impl;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.Property;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.dao.orm.QueryDefinition;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.DuplicateOrganizationException;
import com.liferay.portal.kernel.exception.OrganizationNameException;
import com.liferay.portal.kernel.exception.OrganizationParentException;
import com.liferay.portal.kernel.exception.OrganizationTypeException;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.RequiredOrganizationException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Company;
import com.liferay.portal.kernel.model.Country;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.GroupConstants;
import com.liferay.portal.kernel.model.ListTypeConstants;
import com.liferay.portal.kernel.model.Organization;
import com.liferay.portal.kernel.model.OrganizationConstants;
import com.liferay.portal.kernel.model.Region;
import com.liferay.portal.kernel.model.ResourceConstants;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.RoleConstants;
import com.liferay.portal.kernel.model.SystemEventConstants;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.model.UserGroupRole;
import com.liferay.portal.kernel.search.BaseModelSearchResult;
import com.liferay.portal.kernel.search.Document;
import com.liferay.portal.kernel.search.Hits;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.IndexerRegistryUtil;
import com.liferay.portal.kernel.search.QueryConfig;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.kernel.search.SearchException;
import com.liferay.portal.kernel.search.Sort;
import com.liferay.portal.kernel.security.auth.CompanyThreadLocal;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.systemevent.SystemEvent;
import com.liferay.portal.kernel.transaction.TransactionCommitCallbackUtil;
import com.liferay.portal.kernel.tree.TreeModelTasksAdapter;
import com.liferay.portal.kernel.tree.TreePathUtil;
import com.liferay.portal.kernel.util.ArrayUtil;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.MapUtil;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.ServiceProxyFactory;
import com.liferay.portal.kernel.util.SetUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.comparator.OrganizationIdComparator;
import com.liferay.portal.kernel.util.comparator.OrganizationNameComparator;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.service.base.OrganizationLocalServiceBaseImpl;
import com.liferay.portal.util.PropsValues;
import com.liferay.portlet.usersadmin.search.OrganizationUsersSearcher;
import com.liferay.users.admin.kernel.file.uploads.UserFileUploadsSettings;
import com.liferay.users.admin.kernel.organization.types.OrganizationTypesSettings;
import com.liferay.users.admin.kernel.util.UsersAdminUtil;
import com.liferay.util.dao.orm.CustomSQLUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Provides the local service for accessing, adding, deleting, and updating
* organizations.
*
* @author Brian Wing Shun Chan
* @author Jorge Ferrer
* @author Julio Camarero
* @author Hugo Huijser
* @author Juan Fernández
* @author Marco Leo
*/
public class OrganizationLocalServiceImpl
extends OrganizationLocalServiceBaseImpl {
/**
* Adds the organization to the group.
*
* @param groupId the primary key of the group
* @param organizationId the primary key of the organization
*/
@Override
public void addGroupOrganization(long groupId, long organizationId) {
super.addGroupOrganization(groupId, organizationId);
try {
reindexUsers(organizationId);
}
catch (PortalException pe) {
throw new SystemException(pe);
}
}
/**
* Adds the organization to the group.
*
* @param groupId the primary key of the group
* @param organization the organization
*/
@Override
public void addGroupOrganization(long groupId, Organization organization) {
super.addGroupOrganization(groupId, organization);
try {
reindexUsers(organization);
}
catch (PortalException pe) {
throw new SystemException(pe);
}
}
/**
* Adds the organizations to the group.
*
* @param groupId the primary key of the group
* @param organizations the organizations
*/
@Override
public void addGroupOrganizations(
long groupId, List organizations) {
super.addGroupOrganizations(groupId, organizations);
try {
reindexUsers(organizations);
}
catch (PortalException pe) {
throw new SystemException(pe);
}
}
/**
* Adds the organizations to the group.
*
* @param groupId the primary key of the group
* @param organizationIds the primary keys of the organizations
*/
@Override
public void addGroupOrganizations(long groupId, long[] organizationIds) {
super.addGroupOrganizations(groupId, organizationIds);
try {
reindexUsers(organizationIds);
}
catch (PortalException pe) {
throw new SystemException(pe);
}
}
/**
* Adds an organization.
*
*
* This method handles the creation and bookkeeping of the organization
* including its resources, metadata, and internal data structures. It is
* not necessary to make a subsequent call to {@link
* #addOrganizationResources(long, Organization)}.
*
*
* @param userId the primary key of the creator/owner of the organization
* @param parentOrganizationId the primary key of the organization's parent
* organization
* @param name the organization's name
* @param site whether the organization is to be associated with a main
* site
* @return the organization
*/
@Override
public Organization addOrganization(
long userId, long parentOrganizationId, String name, boolean site)
throws PortalException {
String[] types = getTypes();
return addOrganization(
userId, parentOrganizationId, name, types[0], 0, 0,
ListTypeConstants.ORGANIZATION_STATUS_DEFAULT, StringPool.BLANK,
site, null);
}
/**
* Adds an organization.
*
*
* This method handles the creation and bookkeeping of the organization
* including its resources, metadata, and internal data structures. It is
* not necessary to make a subsequent call to {@link
* #addOrganizationResources(long, Organization)}.
*
*
* @param userId the primary key of the creator/owner of the organization
* @param parentOrganizationId the primary key of the organization's parent
* organization
* @param name the organization's name
* @param type the organization's type
* @param regionId the primary key of the organization's region
* @param countryId the primary key of the organization's country
* @param statusId the organization's workflow status
* @param comments the comments about the organization
* @param site whether the organization is to be associated with a main
* site
* @param serviceContext the service context to be applied (optionally
* null). Can set asset category IDs, asset tag names,
* and expando bridge attributes for the organization.
* @return the organization
*/
@Override
public Organization addOrganization(
long userId, long parentOrganizationId, String name, String type,
long regionId, long countryId, long statusId, String comments,
boolean site, ServiceContext serviceContext)
throws PortalException {
// Organization
User user = userPersistence.findByPrimaryKey(userId);
parentOrganizationId = getParentOrganizationId(
user.getCompanyId(), parentOrganizationId);
validate(
user.getCompanyId(), parentOrganizationId, name, type, countryId,
statusId);
long organizationId = counterLocalService.increment();
Organization organization = organizationPersistence.create(
organizationId);
if (serviceContext != null) {
organization.setUuid(serviceContext.getUuid());
}
organization.setCompanyId(user.getCompanyId());
organization.setUserId(user.getUserId());
organization.setUserName(user.getFullName());
organization.setParentOrganizationId(parentOrganizationId);
organization.setTreePath(organization.buildTreePath());
organization.setName(name);
organization.setType(type);
organization.setRecursable(true);
organization.setRegionId(regionId);
organization.setCountryId(countryId);
organization.setStatusId(statusId);
organization.setComments(comments);
organization.setExpandoBridgeAttributes(serviceContext);
organizationPersistence.update(organization);
// Group
long parentGroupId = GroupConstants.DEFAULT_PARENT_GROUP_ID;
if (parentOrganizationId !=
OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID) {
Organization parentOrganization =
organizationPersistence.fetchByPrimaryKey(parentOrganizationId);
if (parentOrganization != null) {
Group parentGroup = parentOrganization.getGroup();
if (site && parentGroup.isSite()) {
parentGroupId = parentOrganization.getGroupId();
}
}
}
Group group = groupLocalService.addGroup(
userId, parentGroupId, Organization.class.getName(), organizationId,
GroupConstants.DEFAULT_LIVE_GROUP_ID, getLocalizationMap(name),
null, GroupConstants.TYPE_SITE_PRIVATE, false,
GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, null, site, true,
null);
// Role
Role role = roleLocalService.getRole(
organization.getCompanyId(), RoleConstants.ORGANIZATION_OWNER);
userGroupRoleLocalService.addUserGroupRoles(
userId, group.getGroupId(), new long[] {role.getRoleId()});
// Resources
addOrganizationResources(userId, organization);
// Asset
if (serviceContext != null) {
updateAsset(
userId, organization, serviceContext.getAssetCategoryIds(),
serviceContext.getAssetTagNames());
}
// Indexer
if ((serviceContext == null) || serviceContext.isIndexingEnabled()) {
Indexer indexer =
IndexerRegistryUtil.nullSafeGetIndexer(Organization.class);
indexer.reindex(organization);
}
return organization;
}
/**
* Adds a resource for each type of permission available on the
* organization.
*
* @param userId the primary key of the creator/owner of the organization
* @param organization the organization
*/
@Override
public void addOrganizationResources(long userId, Organization organization)
throws PortalException {
String name = Organization.class.getName();
resourceLocalService.addResources(
organization.getCompanyId(), 0, userId, name,
organization.getOrganizationId(), false, false, false);
}
/**
* Assigns the password policy to the organizations, removing any other
* currently assigned password policies.
*
* @param passwordPolicyId the primary key of the password policy
* @param organizationIds the primary keys of the organizations
*/
@Override
public void addPasswordPolicyOrganizations(
long passwordPolicyId, long[] organizationIds) {
passwordPolicyRelLocalService.addPasswordPolicyRels(
passwordPolicyId, Organization.class.getName(), organizationIds);
}
/**
* Deletes the organization's logo.
*
* @param organizationId the primary key of the organization
*/
@Override
public void deleteLogo(long organizationId) throws PortalException {
Organization organization = getOrganization(organizationId);
PortalUtil.updateImageId(organization, false, null, "logoId", 0, 0, 0);
}
/**
* Deletes the organization. The organization's associated resources and
* assets are also deleted.
*
* @param organizationId the primary key of the organization
* @return the deleted organization
*/
@Override
public Organization deleteOrganization(long organizationId)
throws PortalException {
Organization organization = organizationPersistence.findByPrimaryKey(
organizationId);
return organizationLocalService.deleteOrganization(organization);
}
/**
* Deletes the organization. The organization's associated resources and
* assets are also deleted.
*
* @param organization the organization
* @return the deleted organization
*/
@Override
@SystemEvent(type = SystemEventConstants.TYPE_DELETE)
public Organization deleteOrganization(Organization organization)
throws PortalException {
if (!CompanyThreadLocal.isDeleteInProcess()) {
LinkedHashMap params = new LinkedHashMap<>();
params.put(
"usersOrgs", Long.valueOf(organization.getOrganizationId()));
int count1 = organizationPersistence.countByC_P(
organization.getCompanyId(), organization.getOrganizationId());
int count2 = userFinder.countByKeywords(
organization.getCompanyId(), null,
WorkflowConstants.STATUS_APPROVED, params);
if ((count1 > 0) || (count2 > 0)) {
throw new RequiredOrganizationException();
}
}
// Asset
assetEntryLocalService.deleteEntry(
Organization.class.getName(), organization.getOrganizationId());
// Addresses
addressLocalService.deleteAddresses(
organization.getCompanyId(), Organization.class.getName(),
organization.getOrganizationId());
// Email addresses
emailAddressLocalService.deleteEmailAddresses(
organization.getCompanyId(), Organization.class.getName(),
organization.getOrganizationId());
// Expando
expandoRowLocalService.deleteRows(organization.getOrganizationId());
// Password policy relation
passwordPolicyRelLocalService.deletePasswordPolicyRel(
Organization.class.getName(), organization.getOrganizationId());
// Phone
phoneLocalService.deletePhones(
organization.getCompanyId(), Organization.class.getName(),
organization.getOrganizationId());
// Website
websiteLocalService.deleteWebsites(
organization.getCompanyId(), Organization.class.getName(),
organization.getOrganizationId());
// Group
Group group = organization.getGroup();
if (group.isSite()) {
group.setSite(false);
groupPersistence.update(group);
}
groupLocalService.deleteGroup(group);
// Resources
String name = Organization.class.getName();
resourceLocalService.deleteResource(
organization.getCompanyId(), name,
ResourceConstants.SCOPE_INDIVIDUAL,
organization.getOrganizationId());
// Organization
organizationPersistence.remove(organization);
return organization;
}
/**
* Returns the organization with the name.
*
* @param companyId the primary key of the organization's company
* @param name the organization's name
* @return the organization with the name, or null if no
* organization could be found
*/
@Override
public Organization fetchOrganization(long companyId, String name) {
return organizationPersistence.fetchByC_N(companyId, name);
}
@Override
public String[] getChildrenTypes(String type) {
return _organizationTypesSettings.getChildrenTypes(type);
}
@Override
public List getGroupUserOrganizations(
long groupId, long userId)
throws PortalException {
long[] groupOrganizationIds =
groupPersistence.getOrganizationPrimaryKeys(groupId);
if (groupOrganizationIds.length == 0) {
return Collections.emptyList();
}
long[] userOrganizationIds = userPersistence.getOrganizationPrimaryKeys(
userId);
if (userOrganizationIds.length == 0) {
return Collections.emptyList();
}
Set organizationIds = SetUtil.intersect(
groupOrganizationIds, userOrganizationIds);
if (organizationIds.isEmpty()) {
return Collections.emptyList();
}
List organizations = new ArrayList<>(
organizationIds.size());
for (Long organizationId : organizationIds) {
organizations.add(
organizationPersistence.findByPrimaryKey(organizationId));
}
return organizations;
}
@Override
public List getNoAssetOrganizations() {
return organizationFinder.findO_ByNoAssets();
}
/**
* Returns the organization with the name.
*
* @param companyId the primary key of the organization's company
* @param name the organization's name
* @return the organization with the name
*/
@Override
public Organization getOrganization(long companyId, String name)
throws PortalException {
return organizationPersistence.findByC_N(companyId, name);
}
/**
* Returns the primary key of the organization with the name.
*
* @param companyId the primary key of the organization's company
* @param name the organization's name
* @return the primary key of the organization with the name, or
* 0 if the organization could not be found
*/
@Override
public long getOrganizationId(long companyId, String name) {
Organization organization = organizationPersistence.fetchByC_N(
companyId, name);
if (organization != null) {
return organization.getOrganizationId();
}
return 0;
}
@Override
public List getOrganizations(
long userId, int start, int end,
OrderByComparator obc)
throws PortalException {
User user = userPersistence.findByPrimaryKey(userId);
List organizations = ListUtil.copy(
userPersistence.getOrganizations(userId));
Iterator iterator = organizations.iterator();
while (iterator.hasNext()) {
Organization organization = iterator.next();
if (organization.getCompanyId() != user.getCompanyId()) {
iterator.remove();
}
}
if (organizations.isEmpty()) {
return organizations;
}
if (obc == null) {
obc = new OrganizationNameComparator(true);
}
Collections.sort(organizations, obc);
return ListUtil.subList(organizations, start, end);
}
/**
* Returns all the organizations belonging to the parent organization.
*
* @param companyId the primary key of the organization's company
* @param parentOrganizationId the primary key of the organization's parent
* organization
* @return the organizations belonging to the parent organization
*/
@Override
public List getOrganizations(
long companyId, long parentOrganizationId) {
return getOrganizations(
companyId, parentOrganizationId, QueryUtil.ALL_POS,
QueryUtil.ALL_POS);
}
/**
* Returns a range of all the organizations belonging to the parent
* organization.
*
*
* Useful when paginating results. Returns a maximum of end -
* start instances. start and end are not
* primary keys, they are indexes in the result set. Thus, 0
* refers to the first result in the set. Setting both start
* and end to {@link QueryUtil#ALL_POS} will return the full
* result set.
*
*
* @param companyId the primary key of the organization's company
* @param parentOrganizationId the primary key of the organization's parent
* organization
* @param start the lower bound of the range of organizations to return
* @param end the upper bound of the range of organizations to return (not
* inclusive)
* @return the range of organizations belonging to the parent organization
* @see com.liferay.portal.kernel.service.persistence.OrganizationPersistence#findByC_P(
* long, long, int, int)
*/
@Override
public List getOrganizations(
long companyId, long parentOrganizationId, int start, int end) {
if (parentOrganizationId ==
OrganizationConstants.ANY_PARENT_ORGANIZATION_ID) {
return organizationPersistence.findByCompanyId(
companyId, start, end);
}
return organizationPersistence.findByC_P(
companyId, parentOrganizationId, start, end);
}
@Override
public List getOrganizations(
long companyId, long parentOrganizationId, String name, int start,
int end) {
if (Validator.isNull(name)) {
return organizationPersistence.findByC_P(
companyId, parentOrganizationId, start, end);
}
return organizationPersistence.findByC_P_LikeN(
companyId, parentOrganizationId, name, start, end);
}
@Override
public List getOrganizations(
long companyId, String treePath) {
return organizationPersistence.findByC_T(companyId, treePath);
}
/**
* Returns the organizations with the primary keys.
*
* @param organizationIds the primary keys of the organizations
* @return the organizations with the primary keys
*/
@Override
public List getOrganizations(long[] organizationIds)
throws PortalException {
List organizations = new ArrayList<>(
organizationIds.length);
for (long organizationId : organizationIds) {
Organization organization = getOrganization(organizationId);
organizations.add(organization);
}
return organizations;
}
/**
* Returns all the organizations and users belonging to the parent
* organization.
*
* @param companyId the primary key of the organization and user's company
* @param parentOrganizationId the primary key of the organization and
* user's parent organization
* @param status the user's workflow status
* @param start the lower bound of the range of organizations and users to
* return
* @param end the upper bound of the range of organizations and users to
* return (not inclusive)
* @param obc the comparator to order the organizations and users
* (optionally null)
* @return the organizations and users belonging to the parent organization
*/
@Override
public List