Example usage for com.liferay.portal.kernel.model Group isCompany

List of usage examples for com.liferay.portal.kernel.model Group isCompany

Introduction

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

Prototype

public boolean isCompany();

Source Link

Usage

From source file:com.liferay.akismet.moderation.util.ModerationUtil.java

License:Open Source License

protected static DynamicQuery buildMBMessageDynamicQuery(long scopeGroupId, boolean discussion)
        throws PortalException {

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(MBMessage.class);

    Group group = GroupLocalServiceUtil.getGroup(scopeGroupId);

    if (!group.isCompany()) {
        Property groupIdProperty = PropertyFactoryUtil.forName("groupId");

        Long[] scopeGroupIds = getChildScopeGroupIds(scopeGroupId);

        dynamicQuery.add(groupIdProperty.in(scopeGroupIds));
    }//ww  w .j  av a  2 s .  com

    Property categoryIdProperty = PropertyFactoryUtil.forName("categoryId");

    if (discussion) {
        dynamicQuery.add(categoryIdProperty.eq(MBCategoryConstants.DISCUSSION_CATEGORY_ID));
    } else {
        dynamicQuery.add(categoryIdProperty.ne(MBCategoryConstants.DISCUSSION_CATEGORY_ID));
    }

    Property statusProperty = PropertyFactoryUtil.forName("status");

    dynamicQuery.add(statusProperty.eq(WorkflowConstants.STATUS_DENIED));

    return dynamicQuery;
}

From source file:com.liferay.akismet.moderation.util.ModerationUtil.java

License:Open Source License

protected static DynamicQuery buildWikiPageDynamicQuery(long scopeGroupId) throws PortalException {

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(WikiPage.class);

    Group group = GroupLocalServiceUtil.getGroup(scopeGroupId);

    if (!group.isCompany()) {
        Property groupIdProperty = PropertyFactoryUtil.forName("groupId");

        Long[] scopeGroupIds = getChildScopeGroupIds(scopeGroupId);

        dynamicQuery.add(groupIdProperty.in(scopeGroupIds));
    }/* w ww  .ja v  a  2  s.co  m*/

    Property summaryProperty = PropertyFactoryUtil.forName("summary");

    dynamicQuery.add(summaryProperty.eq(AkismetConstants.WIKI_PAGE_PENDING_APPROVAL));

    return dynamicQuery;
}

From source file:com.liferay.asset.categories.internal.validator.CardinalityAssetEntryValidator.java

License:Open Source License

@Override
public void validate(long groupId, String className, long classPK, long classTypePK, long[] categoryIds,
        String[] entryNames) throws PortalException {

    List<AssetVocabulary> assetVocabularies = _assetVocabularyLocalService.getGroupVocabularies(groupId, false);

    Group group = _groupLocalService.getGroup(groupId);

    if (!group.isCompany()) {
        Group companyGroup = _groupLocalService.fetchCompanyGroup(group.getCompanyId());

        if (companyGroup != null) {
            assetVocabularies = ListUtil.copy(assetVocabularies);

            assetVocabularies/*from   w  w  w .  ja va2 s  . com*/
                    .addAll(_assetVocabularyLocalService.getGroupVocabularies(companyGroup.getGroupId()));
        }
    }

    long classNameId = _classNameLocalService.getClassNameId(className);

    if (isCategorizable(groupId, classNameId, classPK)) {
        for (AssetVocabulary assetVocabulary : assetVocabularies) {
            validate(classNameId, classTypePK, categoryIds, assetVocabulary);
        }
    }
}

From source file:com.liferay.exportimport.controller.LayoutImportController.java

License:Open Source License

protected void validateFile(long companyId, long groupId, Map<String, String[]> parameterMap,
        ZipReader zipReader) throws Exception {

    // XML/*from   ww  w .  j  a va2  s .  c  o m*/

    String xml = zipReader.getEntryAsString("/manifest.xml");

    if (xml == null) {
        throw new LARFileException(LARFileException.TYPE_MISSING_MANIFEST);
    }

    Element rootElement = null;

    try {
        Document document = SAXReaderUtil.read(xml);

        rootElement = document.getRootElement();
    } catch (Exception e) {
        throw new LARFileException(LARFileException.TYPE_INVALID_MANIFEST, e);
    }

    // Bundle compatibility

    Element headerElement = rootElement.element("header");

    int importBuildNumber = GetterUtil.getInteger(headerElement.attributeValue("build-number"));

    if (importBuildNumber < ReleaseInfo.RELEASE_7_0_0_BUILD_NUMBER) {
        int buildNumber = ReleaseInfo.getBuildNumber();

        if (buildNumber != importBuildNumber) {
            throw new LayoutImportException(LayoutImportException.TYPE_WRONG_BUILD_NUMBER,
                    new Object[] { importBuildNumber, buildNumber });
        }
    } else {
        BiPredicate<Version, Version> majorVersionBiPredicate = (currentVersion, importVersion) -> Objects
                .equals(currentVersion.getMajor(), importVersion.getMajor());

        BiPredicate<Version, Version> minorVersionBiPredicate = (currentVersion, importVersion) -> {
            int currentMinorVersion = GetterUtil.getInteger(currentVersion.getMinor(), -1);
            int importedMinorVersion = GetterUtil.getInteger(importVersion.getMinor(), -1);

            if (((currentMinorVersion == -1) && (importedMinorVersion == -1))
                    || (currentMinorVersion < importedMinorVersion)) {

                return false;
            }

            return true;
        };

        BiPredicate<Version, Version> manifestVersionBiPredicate = (currentVersion, importVersion) -> {
            BiPredicate<Version, Version> versionBiPredicate = majorVersionBiPredicate
                    .and(minorVersionBiPredicate);

            return versionBiPredicate.test(currentVersion, importVersion);
        };

        String importSchemaVersion = GetterUtil.getString(headerElement.attributeValue("schema-version"),
                "1.0.0");

        if (!manifestVersionBiPredicate.test(
                Version.getInstance(ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION),
                Version.getInstance(importSchemaVersion))) {

            throw new LayoutImportException(LayoutImportException.TYPE_WRONG_LAR_SCHEMA_VERSION,
                    new Object[] { importSchemaVersion, ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION });
        }
    }

    // Type

    String larType = headerElement.attributeValue("type");

    String[] expectedLARTypes = { "layout-prototype", "layout-set", "layout-set-prototype" };

    Stream<String> stream = Stream.of(expectedLARTypes);

    if (stream.noneMatch(lt -> lt.equals(larType))) {
        throw new LARTypeException(larType, expectedLARTypes);
    }

    Group group = _groupLocalService.fetchGroup(groupId);

    String layoutsImportMode = MapUtil.getString(parameterMap, PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE);

    if (larType.equals("layout-prototype") && !group.isLayoutPrototype()
            && !layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

        throw new LARTypeException(LARTypeException.TYPE_LAYOUT_PROTOTYPE);
    }

    if (larType.equals("layout-set")) {
        if (group.isLayoutPrototype() || group.isLayoutSetPrototype()) {
            throw new LARTypeException(LARTypeException.TYPE_LAYOUT_SET);
        }

        long sourceCompanyGroupId = GetterUtil.getLong(headerElement.attributeValue("company-group-id"));
        long sourceGroupId = GetterUtil.getLong(headerElement.attributeValue("group-id"));

        boolean companySourceGroup = false;

        if (sourceCompanyGroupId == sourceGroupId) {
            companySourceGroup = true;
        }

        if (group.isCompany() ^ companySourceGroup) {
            throw new LARTypeException(LARTypeException.TYPE_COMPANY_GROUP);
        }
    }

    if (larType.equals("layout-set-prototype") && !group.isLayoutSetPrototype()
            && !layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

        throw new LARTypeException(LARTypeException.TYPE_LAYOUT_SET_PROTOTYPE);
    }

    // Portlets compatibility

    List<Element> portletElements = fetchPortletElements(rootElement);

    for (Element portletElement : portletElements) {
        String portletId = GetterUtil.getString(portletElement.attributeValue("portlet-id"));

        if (Validator.isNull(portletId)) {
            continue;
        }

        String schemaVersion = GetterUtil.getString(portletElement.attributeValue("schema-version"));

        PortletDataHandler portletDataHandler = _portletDataHandlerProvider.provide(companyId, portletId);

        if (portletDataHandler == null) {
            continue;
        }

        if (!portletDataHandler.validateSchemaVersion(schemaVersion)) {
            throw new LayoutImportException(LayoutImportException.TYPE_WRONG_PORTLET_SCHEMA_VERSION,
                    new Object[] { schemaVersion, portletId, portletDataHandler.getSchemaVersion() });
        }
    }

    // Available locales

    List<Locale> sourceAvailableLocales = Arrays.asList(
            LocaleUtil.fromLanguageIds(StringUtil.split(headerElement.attributeValue("available-locales"))));

    for (Locale sourceAvailableLocale : sourceAvailableLocales) {
        if (!LanguageUtil.isAvailableLocale(groupId, sourceAvailableLocale)) {

            LocaleException le = new LocaleException(LocaleException.TYPE_EXPORT_IMPORT);

            le.setSourceAvailableLocales(sourceAvailableLocales);
            le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales(groupId));

            throw le;
        }
    }

    // Layout prototypes validity

    Element layoutsElement = rootElement.element(Layout.class.getSimpleName());

    validateLayoutPrototypes(companyId, headerElement, layoutsElement);
}

From source file:com.liferay.exportimport.resources.importer.internal.util.BaseImporter.java

License:Open Source License

@Override
public boolean isCompanyGroup() throws Exception {
    Group group = GroupLocalServiceUtil.fetchGroup(groupId);

    if (group == null) {
        return false;
    }//from w  w w  .j av a2s  . c  o m

    return group.isCompany();
}

From source file:com.liferay.exportimport.staging.StagingImpl.java

License:Open Source License

protected void validateRemoteGroup(long groupId, long remoteGroupId, String remoteAddress, int remotePort,
        String remotePathContext, boolean secureConnection) throws PortalException {

    if (remoteGroupId <= 0) {
        RemoteOptionsException roe = new RemoteOptionsException(RemoteOptionsException.REMOTE_GROUP_ID);

        roe.setRemoteGroupId(remoteGroupId);

        throw roe;
    }//from   w  w  w.j  a v a  2  s  .  c om

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    User user = permissionChecker.getUser();

    String remoteURL = buildRemoteURL(remoteAddress, remotePort, remotePathContext, secureConnection);

    HttpPrincipal httpPrincipal = new HttpPrincipal(remoteURL, user.getLogin(), user.getPassword(),
            user.getPasswordEncrypted());

    try {
        currentThread.setContextClassLoader(PortalClassLoaderUtil.getClassLoader());

        // Ping the remote host and verify that the remote group exists in
        // the same company as the remote user

        GroupServiceHttp.checkRemoteStagingGroup(httpPrincipal, remoteGroupId);

        // Ensure that the local group and the remote group are not the same
        // group and that they are either both company groups or both not
        // company groups

        Group group = _groupLocalService.getGroup(groupId);

        Group remoteGroup = GroupServiceHttp.getGroup(httpPrincipal, remoteGroupId);

        if (group.isCompany() ^ isCompanyGroup(httpPrincipal, remoteGroup)) {

            RemoteExportException ree = new RemoteExportException(RemoteExportException.INVALID_GROUP);

            ree.setGroupId(remoteGroupId);

            throw ree;
        }
    } catch (NoSuchGroupException nsge) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(nsge, nsge);
        }

        RemoteExportException ree = new RemoteExportException(RemoteExportException.NO_GROUP);

        ree.setGroupId(remoteGroupId);

        throw ree;
    } catch (PrincipalException pe) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        RemoteExportException ree = new RemoteExportException(RemoteExportException.NO_PERMISSIONS);

        ree.setGroupId(remoteGroupId);

        throw ree;
    } catch (RemoteAuthException rae) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(rae, rae);
        }

        rae.setURL(remoteURL);

        throw rae;
    } catch (SystemException se) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(se, se);
        }

        RemoteExportException ree = new RemoteExportException(RemoteExportException.BAD_CONNECTION,
                se.getMessage());

        ree.setURL(remoteURL);

        throw ree;
    } finally {
        currentThread.setContextClassLoader(contextClassLoader);
    }
}

From source file:com.liferay.flags.internal.messaging.FlagsRequestMessageListener.java

License:Open Source License

protected Set<User> getRecipients(long companyId, long groupId) throws PortalException {

    Set<User> recipients = new LinkedHashSet<>();

    List<String> roleNames = new ArrayList<>();

    Group group = _groupLocalService.getGroup(groupId);

    if (group.isSite()) {
        roleNames.add(RoleConstants.SITE_ADMINISTRATOR);
        roleNames.add(RoleConstants.SITE_OWNER);
    }//from w  ww  .java2s  . c o  m

    if (group.isCompany()) {
        roleNames.add(RoleConstants.ADMINISTRATOR);
    } else if (group.isOrganization()) {
        roleNames.add(RoleConstants.ORGANIZATION_ADMINISTRATOR);
        roleNames.add(RoleConstants.ORGANIZATION_OWNER);
    }

    for (String roleName : roleNames) {
        Role role = _roleLocalService.getRole(companyId, roleName);

        List<UserGroupRole> userGroupRoles = _userGroupRoleLocalService.getUserGroupRolesByGroupAndRole(groupId,
                role.getRoleId());

        for (UserGroupRole userGroupRole : userGroupRoles) {
            recipients.add(userGroupRole.getUser());
        }
    }

    if (recipients.isEmpty()) {
        Role role = _roleLocalService.getRole(companyId, RoleConstants.ADMINISTRATOR);

        recipients.addAll(_userLocalService.getRoleUsers(role.getRoleId()));
    }

    return recipients;
}

From source file:com.liferay.layout.admin.web.internal.portlet.GroupPagesControlPanelEntry.java

License:Open Source License

@Override
protected boolean hasAccessPermissionDenied(PermissionChecker permissionChecker, Group group, Portlet portlet)
        throws Exception {

    if (group.isCompany()) {
        return true;
    }//from  w  w  w.j  a v  a2  s . c om

    return super.hasAccessPermissionDenied(permissionChecker, group, portlet);
}

From source file:com.liferay.roles.admin.internal.exportimport.data.handler.ImportExportPermissionConversionFilter.java

License:Open Source License

@Override
public boolean accept(Role role, ResourcePermission resourcePermission) {
    int scope = resourcePermission.getScope();

    if ((scope == ResourceConstants.SCOPE_COMPANY) || (scope == ResourceConstants.SCOPE_GROUP_TEMPLATE)) {

        return true;
    } else if (resourcePermission.getScope() == ResourceConstants.SCOPE_GROUP) {

        Group group = GroupLocalServiceUtil.fetchGroup(Long.valueOf(resourcePermission.getPrimKey()));

        if (group.isCompany() || group.isUserPersonalSite()) {
            return true;
        }/*from ww w . j  a va2 s.c o  m*/
    }

    return false;
}

From source file:com.liferay.roles.admin.internal.exportimport.data.handler.ImportExportPermissionConversionFilter.java

License:Open Source License

@Override
public boolean accept(Role role, ResourceTypePermission resourceTypePermission) {

    if (role.getType() != RoleConstants.TYPE_REGULAR) {
        return true;
    } else if (resourceTypePermission.isCompanyScope()) {
        return true;
    }/*  w  w  w. j  a  va 2  s . co m*/

    Group group = GroupLocalServiceUtil.fetchGroup(resourceTypePermission.getGroupId());

    if ((group != null) && (group.isCompany() || group.isUserPersonalSite())) {

        return true;
    }

    return false;
}