Example usage for com.liferay.portal.kernel.util SetUtil intersect

List of usage examples for com.liferay.portal.kernel.util SetUtil intersect

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util SetUtil intersect.

Prototype

public static Set<Long> intersect(long[] array1, long[] array2) 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_0.UpgradeDynamicDataMapping.java

License:Open Source License

protected DDMForm getDDMForm(long structureId) throws Exception {
    DDMForm ddmForm = _ddmForms.get(structureId);

    if (ddmForm != null) {
        return ddmForm;
    }//from w  ww  .j  a  va2s. co m

    try (PreparedStatement ps = connection.prepareStatement(
            "select parentStructureId, definition, storageType from " + "DDMStructure where structureId = ?")) {

        ps.setLong(1, structureId);

        try (ResultSet rs = ps.executeQuery()) {
            if (rs.next()) {
                long parentStructureId = rs.getLong("parentStructureId");
                String definition = rs.getString("definition");
                String storageType = rs.getString("storageType");

                if (storageType.equals("expando") || storageType.equals("xml")) {

                    ddmForm = _ddmFormXSDDeserializer.deserialize(definition);
                } else {
                    ddmForm = _ddmFormJSONDeserializer.deserialize(definition);
                }

                try {
                    validateDDMFormFieldNames(ddmForm);
                } catch (MustNotDuplicateFieldName mndfn) {
                    throw new UpgradeException(String.format(
                            "The field name '%s' from structure ID %d is " + "defined more than once",
                            mndfn.getFieldName(), structureId));
                }

                if (parentStructureId > 0) {
                    DDMForm parentDDMForm = getDDMForm(parentStructureId);

                    Set<String> commonDDMFormFieldNames = SetUtil
                            .intersect(getDDMFormFieldsNames(parentDDMForm), getDDMFormFieldsNames(ddmForm));

                    if (!commonDDMFormFieldNames.isEmpty()) {
                        throw new UpgradeException(
                                "Duplicate DDM form field names: " + StringUtil.merge(commonDDMFormFieldNames));
                    }
                }

                _ddmForms.put(structureId, ddmForm);

                return ddmForm;
            }
        }

        throw new UpgradeException("Unable to find dynamic data mapping structure with ID " + structureId);
    }
}

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMStructureLocalServiceImpl.java

License:Open Source License

protected void validate(DDMForm parentDDMForm, DDMForm ddmForm) throws PortalException {

    Set<String> commonDDMFormFieldNames = SetUtil.intersect(getDDMFormFieldsNames(parentDDMForm),
            getDDMFormFieldsNames(ddmForm));

    if (!commonDDMFormFieldNames.isEmpty()) {
        throw new StructureDuplicateElementException(
                "Duplicate DDM form field names: " + StringUtil.merge(commonDDMFormFieldNames));
    }//from   ww w  .  j a  va  2  s  . co m
}

From source file:com.liferay.dynamic.data.mapping.validator.internal.DDMFormLayoutValidatorImpl.java

License:Open Source License

private void _validateDDMFormFieldNames(DDMFormLayout ddmFormLayout) throws DDMFormLayoutValidationException {

    Set<String> ddmFormFieldNames = new HashSet<>();

    for (DDMFormLayoutPage ddmFormLayoutPage : ddmFormLayout.getDDMFormLayoutPages()) {

        for (DDMFormLayoutRow ddmFormLayoutRow : ddmFormLayoutPage.getDDMFormLayoutRows()) {

            for (DDMFormLayoutColumn ddmFormLayoutColumn : ddmFormLayoutRow.getDDMFormLayoutColumns()) {

                Set<String> intersectDDMFormFieldNames = SetUtil.intersect(ddmFormFieldNames,
                        ddmFormLayoutColumn.getDDMFormFieldNames());

                if (!intersectDDMFormFieldNames.isEmpty()) {
                    throw new MustNotDuplicateFieldName(intersectDDMFormFieldNames);
                }//from   w w  w . j  ava2  s.c o  m

                ddmFormFieldNames.addAll(ddmFormLayoutColumn.getDDMFormFieldNames());
            }
        }
    }
}

From source file:com.liferay.social.activity.service.test.SocialRelationLocalServiceTest.java

License:Open Source License

@Test
public void testGetMultipleGroups() throws Exception {
    User dlc3User = UserLocalServiceUtil.getUserByScreenName(TestPropsValues.getCompanyId(), "dlc3");

    List<User> groupUsers = UserLocalServiceUtil.getGroupUsers(TestPropsValues.getGroupId());

    GroupLocalServiceUtil.addUserGroup(dlc3User.getUserId(), TestPropsValues.getGroupId());

    User dlc4User = UserLocalServiceUtil.getUserByScreenName(TestPropsValues.getCompanyId(), "dlc4");

    GroupLocalServiceUtil.addUserGroup(dlc4User.getUserId(), TestPropsValues.getGroupId());

    Set<Long> groupIds = SetUtil.intersect(dlc3User.getGroupIds(), dlc4User.getGroupIds());

    List<User> users = UserLocalServiceUtil.searchSocial(TestPropsValues.getCompanyId(),
            ArrayUtil.toArray(groupIds.toArray(new Long[groupIds.size()])), "dlc", QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);/*from   ww  w.  j  a va 2s.c o  m*/

    users = ListUtil.remove(users, groupUsers);

    Assert.assertEquals(users.toString(), 2, users.size());

    GroupLocalServiceUtil.deleteUserGroup(dlc3User.getUserId(), TestPropsValues.getGroupId());
    GroupLocalServiceUtil.deleteUserGroup(dlc4User.getUserId(), TestPropsValues.getGroupId());
}