Example usage for com.liferay.portal.kernel.model Company hasCompanyMx

List of usage examples for com.liferay.portal.kernel.model Company hasCompanyMx

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Company hasCompanyMx.

Prototype

public boolean hasCompanyMx(String emailAddress);

Source Link

Usage

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java

License:Open Source License

protected void checkAddUserPermission(long creatorUserId, long companyId, String emailAddress, long[] groupIds,
        long[] organizationIds, long[] roleIds, long[] userGroupIds, ServiceContext serviceContext)
        throws PortalException {

    Company company = CompanyLocalServiceUtil.getCompany(companyId);

    // Check if user has an according right assigned with add user permission; Either he owns the right itself, by his roles or by his user roles
    User creator = this.getGuestOrUser();

    long[] userIds = new long[] { creatorUserId };

    // Adding user must be member of everything he adds
    ServicePermissionUtil.checkMembership(userIds, groupIds, organizationIds, roleIds, userGroupIds);

    if (groupIds != null && groupIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_TO_PAGE);
        angularGroupService.checkGroups(0, groupIds);
    }// w w  w.  j  av a  2 s  . com

    if (organizationIds != null && organizationIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ORGANIZATION);
        angularOrganizationService.checkOrganizations(0, organizationIds);
    }

    if (roleIds != null && roleIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ROLE);
        angularRoleService.checkRoles(0, roleIds);
    }

    if (userGroupIds != null && userGroupIds.length > 0) {
        PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER_GROUP);
        angularUserGroupService.checkUserGroupIds(0, userGroupIds);
    }

    boolean anonymousUser = ParamUtil.getBoolean(serviceContext, "anonymousUser");

    long defaultUserId = userLocalService.getDefaultUserId(companyId);

    if (((creatorUserId != 0) && (creatorUserId != defaultUserId))
            || (!company.isStrangers() && !anonymousUser)) {
        ServicePermissionUtil.checkAllPersonalPermissions(creator, ActionKeys.ADD_USER, companyId,
                getPermissionChecker(), User.class.getName());
    }

    if ((creatorUserId == 0) || (creatorUserId == defaultUserId)) {
        if (!company.isStrangersWithMx() && company.hasCompanyMx(emailAddress)) {

            throw new UserEmailAddressException.MustNotUseCompanyMx(emailAddress);
        }
    }
}