Example usage for java.util List containsAll

List of usage examples for java.util List containsAll

Introduction

In this page you can find the example usage for java.util List containsAll.

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

Returns true if this list contains all of the elements of the specified collection.

Usage

From source file:org.infoscoop.service.PortalAdminsService.java

/**
 * @param adminsList//www.  ja v  a 2 s.c o m
 * @throws Exception 
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public synchronized void updatePortalAdmins(Map adminsMap) throws Exception {
    if (adminsMap == null)
        return;

    boolean myIdExists = true;
    ISPrincipal p = SecurityController.getPrincipalByType("UIDPrincipal");

    List getNotAllowDeleteRoleIds = adminRoleDAO.getNotAllowDeleteRoleIds();

    adminRoleDAO.delete();

    List rolesList = (List) adminsMap.get("roles");
    List roleIdList = new ArrayList();

    // insert roles
    for (Iterator ite = rolesList.iterator(); ite.hasNext();) {
        Map map = (Map) ite.next();
        String roleId = (String) map.get("id");
        String name = (String) map.get("name");
        String permission = (String) map.get("permission");

        adminRoleDAO.insert(roleId, name, permission, !getNotAllowDeleteRoleIds.contains(roleId));
        roleIdList.add(roleId);
    }

    Map adminsData = new SequencedHashMap();
    List adminsList = (List) adminsMap.get("admins");
    String myRoleId = "";
    for (Iterator ite = adminsList.iterator(); ite.hasNext();) {
        Map map = (Map) ite.next();
        String uid = (String) map.get("uid");
        String roleId = (String) map.get("roleId");

        if (p.getName().equals(uid)) {
            myRoleId = roleId;
            myIdExists = true;
        }

        if (uid != null && roleId != null) {
            adminsData.put(uid, roleId);
        }
    }

    if (!myIdExists)
        throw new Exception("Same ID as oneself cannot be deleted.");

    portalAdminsDAO.delete();

    // insert admins
    for (Iterator ite = adminsData.keySet().iterator(); ite.hasNext();) {
        String uid = (String) ite.next();
        String roleId = (String) adminsData.get(uid);
        roleId = (roleIdList.contains(roleId)) ? roleId : null;

        portalAdminsDAO.insert(uid, roleId);
    }

    if (!roleIdList.contains(myRoleId) || !roleIdList.containsAll(getNotAllowDeleteRoleIds)) {
        throw new Exception("The roll that cannot be deleted is contained.");
    }

}

From source file:com.atlassian.jira.bc.group.DefaultGroupService.java

/**
 * This method is used to do the "meat" of the validation to see if a child can be removed from either
 * a group or a list of groups./*from   ww  w  .j  a va  2s . c  o  m*/
 *
 * @param jiraServiceContext the context containing user and an error collection
 * @param childToRemove the group to remove from the group(s)
 * @param allSelectedGroups the selected list of groups, this only really makes sense when doing a
 * bulk delete.
 * @param groupsToLeave are the groups to remove the child from.
 * @param isAll indicates if the child should be removed from the allSelectedGroups, also indicates
 * what type of error messages to show.
 * @return true if all the validation succeeds, false otherwise.
 */
boolean validateCanRemoveGroupFromGroups(final JiraServiceContext jiraServiceContext, final Group childToRemove,
        final List allSelectedGroups, final List groupsToLeave, final boolean isAll) {
    final User currentUser = jiraServiceContext.getLoggedInUser();
    final I18nHelper i18n = jiraServiceContext.getI18nBean();
    final ErrorCollection errorCollection = jiraServiceContext.getErrorCollection();

    // First validate that all the groups exist
    if (!validateGroupNamesExist(groupsToLeave, errorCollection, i18n)) {
        return false;
    }

    // We need validate that the current group is part of the selected groups if not removing from All selected groups
    if (!isAll && (allSelectedGroups != null) && !allSelectedGroups.containsAll(groupsToLeave)) {
        errorCollection.addErrorMessage(i18n.getText("admin.editnestedgroups.error.group.group.not.selected",
                childToRemove.getName(), (String) groupsToLeave.get(0)));
        return false;
    }

    // case where the user is not in the group(s)
    if (!isGroupInGroups(childToRemove, new HashSet(groupsToLeave))) {
        // We need to know about the all flag so we can possibly give the right error message
        if (isAll) {
            if (groupsToLeave.size() == 1) {
                errorCollection
                        .addErrorMessage(i18n.getText("admin.editnestedgroups.error.group.not.member.of.group",
                                childToRemove.getName(), (String) groupsToLeave.get(0)));
            } else {
                errorCollection.addErrorMessage(i18n.getText(
                        "admin.editnestedgroups.error.group.not.member.of.all", childToRemove.getName()));
            }
        } else {
            errorCollection
                    .addErrorMessage(i18n.getText("admin.editnestedgroups.error.group.not.member.of.group",
                            childToRemove.getName(), (String) groupsToLeave.get(0)));
        }
        return false;
    }
    // Validate that all the provided groupNames are not admin
    if (!validateGroupNamesNotAdmin(groupsToLeave, errorCollection, i18n)) {
        return false;
    }

    return true;
}

From source file:org.nuxeo.ecm.platform.usermanager.UserManagerImpl.java

@Override
public String[] getUsersForPermission(String perm, ACP acp, DocumentModel context) {
    PermissionProvider permissionProvider = Framework.getService(PermissionProvider.class);
    // using a hashset to avoid duplicates
    HashSet<String> usernames = new HashSet<String>();

    ACL merged = acp.getMergedACLs("merged");
    // The list of permission that is has "perm" as its (compound)
    // permission
    ArrayList<ACE> filteredACEbyPerm = new ArrayList<ACE>();

    List<String> currentPermissions = getLeafPermissions(perm);

    for (ACE ace : merged.getACEs()) {
        // Checking if the permission contains the permission we want to
        // check (we use the security service method for coumpound
        // permissions)
        List<String> acePermissions = getLeafPermissions(ace.getPermission());

        // Everything is a special permission (not compound)
        if (SecurityConstants.EVERYTHING.equals(ace.getPermission())) {
            acePermissions = Arrays.asList(permissionProvider.getPermissions());
        }//from ww  w.  jav a2  s  .  c  om

        if (acePermissions.containsAll(currentPermissions)) {
            // special case: everybody perm grant false, don't take in
            // account the previous ace
            if (SecurityConstants.EVERYONE.equals(ace.getUsername()) && !ace.isGranted()) {
                break;
            }
            filteredACEbyPerm.add(ace);
        }
    }

    for (ACE ace : filteredACEbyPerm) {
        String aceUsername = ace.getUsername();
        List<String> users = null;
        // If everyone, add/remove all the users
        if (SecurityConstants.EVERYONE.equals(aceUsername)) {
            users = getUserIds();
        }
        // if a group, add/remove all the user from the group (and
        // subgroups)
        if (users == null) {
            NuxeoGroup group;
            group = getGroup(aceUsername, context);
            if (group != null) {
                users = getUsersInGroupAndSubGroups(aceUsername, context);
            }

        }
        // otherwise, add the user
        if (users == null) {
            users = new ArrayList<String>();
            users.add(aceUsername);
        }
        if (ace.isGranted()) {
            usernames.addAll(users);
        } else {
            usernames.removeAll(users);
        }
    }
    return usernames.toArray(new String[usernames.size()]);
}

From source file:com.atlassian.jira.bc.group.DefaultGroupService.java

/**
 * This method is used to do the "meat" of the validation to see if a user can be removed from either
 * a group or a list of groups./*  w w  w. j av  a  2  s.com*/
 *
 * @param jiraServiceContext the context containing user and an error collection
 * @param userToRemove the user to remove from the group(s)
 * @param allSelectedGroups the selected list of groups, this only really makes sense when doing a
 * bulk delete.
 * @param groupsToLeave are the groups to remove the user from.
 * @param isAll indicates if the user should be removed from the allSelectedGroups, also indicates
 * what type of error messages to show.
 * @return true if all the validation succeeds, false otherwise.
 */
boolean validateCanRemoveUserFromGroups(final JiraServiceContext jiraServiceContext, final User userToRemove,
        final List allSelectedGroups, final List groupsToLeave, final boolean isAll) {
    final User currentUser = jiraServiceContext.getLoggedInUser();
    final I18nHelper i18n = jiraServiceContext.getI18nBean();
    final ErrorCollection errorCollection = jiraServiceContext.getErrorCollection();

    // First validate that all the groups exist
    if (!validateGroupNamesExist(groupsToLeave, errorCollection, i18n)) {
        return false;
    }

    // We need validate that the current group is part of the selected groups if not removing from All selected groups
    if (!isAll && (allSelectedGroups != null) && !allSelectedGroups.containsAll(groupsToLeave)) {
        errorCollection.addErrorMessage(i18n.getText("admin.bulkeditgroups.error.user.group.not.selected",
                userToRemove.getName(), (String) groupsToLeave.get(0)));
        return false;
    }

    // If we are removing the current user do validation to ensure we are not removing our administration rights
    if ((currentUser != null) && currentUser.equals(userToRemove)
            && areOnlyGroupsGrantingUserAdminPermissionsBulk(jiraServiceContext, groupsToLeave)) {
        return false;
    }

    // Need to validate that they are not trying to leave groups they do not have permission to leave
    if (!getGroupNamesUserCanSee(currentUser).containsAll(groupsToLeave)) {
        errorCollection.addErrorMessage(i18n.getText("admin.errors.cannot.leave.user.groups.not.visible"));
        return false;
    }

    // case where the user is not in the group(s)
    if (!isUserInGroups(userToRemove, new HashSet(groupsToLeave))) {
        // We need to know about the all flag so we can possibly give the right error message
        if (isAll) {
            if (groupsToLeave.size() == 1) {
                errorCollection
                        .addErrorMessage(i18n.getText("admin.bulkeditgroups.error.user.not.member.of.group",
                                userToRemove.getName(), (String) groupsToLeave.get(0)));
            } else {
                errorCollection.addErrorMessage(i18n
                        .getText("admin.bulkeditgroups.error.user.not.member.of.all", userToRemove.getName()));
            }
        } else {
            errorCollection.addErrorMessage(i18n.getText("admin.bulkeditgroups.error.user.not.member.of.group",
                    userToRemove.getName(), (String) groupsToLeave.get(0)));
        }
        return false;
    }

    return true;
}

From source file:org.apache.carbondata.hadoop.api.CarbonTableInputFormat.java

/**
 * Return segment list after filtering out valid segments and segments set by user by
 * `INPUT_SEGMENT_NUMBERS` in job configuration
 *//*w  ww .ja  v a2s  . c  o m*/
private List<Segment> getFilteredSegment(JobContext job, List<Segment> validSegments,
        boolean validationRequired, ReadCommittedScope readCommittedScope) {
    Segment[] segmentsToAccess = getSegmentsToAccess(job, readCommittedScope);
    List<Segment> segmentToAccessSet = new ArrayList<>(new HashSet<>(Arrays.asList(segmentsToAccess)));
    List<Segment> filteredSegmentToAccess = new ArrayList<>();
    if (segmentsToAccess.length == 0 || segmentsToAccess[0].getSegmentNo().equalsIgnoreCase("*")) {
        filteredSegmentToAccess.addAll(validSegments);
    } else {
        for (Segment validSegment : validSegments) {
            int index = segmentToAccessSet.indexOf(validSegment);
            if (index > -1) {
                // In case of in progress reading segment, segment file name is set to the property itself
                if (segmentToAccessSet.get(index).getSegmentFileName() != null
                        && validSegment.getSegmentFileName() == null) {
                    filteredSegmentToAccess.add(segmentToAccessSet.get(index));
                } else {
                    filteredSegmentToAccess.add(validSegment);
                }
            }
        }
        if (filteredSegmentToAccess.size() != segmentToAccessSet.size() && !validationRequired) {
            for (Segment segment : segmentToAccessSet) {
                if (!filteredSegmentToAccess.contains(segment)) {
                    filteredSegmentToAccess.add(segment);
                }
            }
        }
        if (!filteredSegmentToAccess.containsAll(segmentToAccessSet)) {
            List<Segment> filteredSegmentToAccessTemp = new ArrayList<>(filteredSegmentToAccess);
            filteredSegmentToAccessTemp.removeAll(segmentToAccessSet);
            LOG.info("Segments ignored are : " + Arrays.toString(filteredSegmentToAccessTemp.toArray()));
        }
    }
    return filteredSegmentToAccess;
}

From source file:org.finra.herd.service.helper.HerdHelper.java

/**
 * Validate a list of S3 files per storage unit information.
 *
 * @param storageName the storage name// w  w  w.  j a va 2s .  c o m
 * @param storageFiles the list of storage files
 * @param actualS3Files the list of the actual S3 files
 * @param s3KeyPrefix the S3 key prefix that was prepended to the S3 file paths, when they were uploaded to S3
 */
public void validateS3Files(String storageName, List<StorageFile> storageFiles, List<String> actualS3Files,
        String s3KeyPrefix) {
    // Validate that all files match the expected S3 key prefix and build a list of registered S3 files.
    List<String> registeredS3Files = new ArrayList<>();
    if (!CollectionUtils.isEmpty(storageFiles)) {
        for (StorageFile storageFile : storageFiles) {
            Assert.isTrue(storageFile.getFilePath().startsWith(s3KeyPrefix), String.format(
                    "Storage file S3 key prefix \"%s\" does not match the expected S3 key prefix \"%s\".",
                    storageFile.getFilePath(), s3KeyPrefix));
            registeredS3Files.add(storageFile.getFilePath());
        }
    }

    // Validate that all files exist in S3 managed bucket.
    if (!actualS3Files.containsAll(registeredS3Files)) {
        registeredS3Files.removeAll(actualS3Files);
        throw new IllegalStateException(
                String.format("Registered file \"%s\" does not exist in \"%s\" storage.",
                        registeredS3Files.get(0), storageName));
    }

    // Validate that no other files in S3 managed bucket have the same S3 key prefix.
    if (!registeredS3Files.containsAll(actualS3Files)) {
        actualS3Files.removeAll(registeredS3Files);
        throw new IllegalStateException(String.format(
                "Found S3 file \"%s\" in \"%s\" storage not registered with this business object data.",
                actualS3Files.get(0), storageName));
    }
}

From source file:org.finra.dm.service.helper.DmHelper.java

/**
 * Validate a list of S3 files per storage unit information.
 *
 * @param storageUnit the storage unit that contains S3 files to be validated
 * @param actualS3Files the list of the actual S3 files
 * @param s3KeyPrefix the S3 key prefix that was prepended to the S3 file paths, when they were uploaded to S3
 *//* ww  w.j  a v  a2  s . c  o  m*/
public void validateS3Files(StorageUnit storageUnit, List<String> actualS3Files, String s3KeyPrefix) {
    // Validate that all files match the expected S3 key prefix and build a list of registered S3 files.
    List<String> registeredS3Files = new ArrayList<>();
    if (!CollectionUtils.isEmpty(storageUnit.getStorageFiles())) {
        for (StorageFile storageFile : storageUnit.getStorageFiles()) {
            Assert.isTrue(storageFile.getFilePath().startsWith(s3KeyPrefix), String.format(
                    "Storage file S3 key prefix \"%s\" does not match the expected S3 key prefix \"%s\".",
                    storageFile.getFilePath(), s3KeyPrefix));
            registeredS3Files.add(storageFile.getFilePath());
        }
    }

    // Validate that all files exist in S3 managed bucket.
    if (!actualS3Files.containsAll(registeredS3Files)) {
        registeredS3Files.removeAll(actualS3Files);
        throw new IllegalStateException(
                String.format("Registered file \"%s\" does not exist in \"%s\" storage.",
                        registeredS3Files.get(0), storageUnit.getStorage().getName()));
    }

    // Validate that no other files in S3 managed bucket have the same S3 key prefix.
    if (!registeredS3Files.containsAll(actualS3Files)) {
        actualS3Files.removeAll(registeredS3Files);
        throw new IllegalStateException(String.format(
                "Found S3 file \"%s\" in \"%s\" storage not registered with this business object data.",
                actualS3Files.get(0), storageUnit.getStorage().getName()));
    }
}

From source file:org.openecomp.sdc.be.components.impl.GroupBusinessLogic.java

/**
 * Verify that the artifact members belongs to the component
 * /* w w w.j  av  a2 s  .c  o  m*/
 * @param component
 * @param artifacts
 * @return
 */
private Either<Boolean, ResponseFormat> verifyArtifactsBelongsToComponent(Component component,
        List<String> artifacts, String context) {

    if (artifacts == null || true == artifacts.isEmpty()) {
        return Either.left(true);
    }

    Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
    if (deploymentArtifacts == null || true == deploymentArtifacts.isEmpty()) {
        BeEcompErrorManager.getInstance().logInvalidInputError(context,
                "No deployment artifact found under component " + component.getNormalizedName(),
                ErrorSeverity.INFO);
        return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
    }

    List<String> currentArtifacts = deploymentArtifacts.values().stream().map(p -> p.getUniqueId())
            .collect(Collectors.toList());
    log.debug("The deployment artifacts of component {} are {}", component.getNormalizedName(),
            deploymentArtifacts);
    if (false == currentArtifacts.containsAll(artifacts)) {
        BeEcompErrorManager.getInstance().logInvalidInputError(context,
                "Not all artifacts belongs to component " + component.getNormalizedName(), ErrorSeverity.INFO);
        return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
    }

    return Either.left(true);

}

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

protected RootClass createTableMapping(Mappings mappings,
        com.manydesigns.portofino.model.database.Table aTable) {

    Table tab = mappings.addTable(escapeName(aTable.getSchemaName()), null, escapeName(aTable.getTableName()),
            null, false);//from w  ww.jav  a 2  s  .co m
    //tab.setName(escapeName(aTable.getTableName()));
    //tab.setSchema(escapeName(aTable.getSchemaName()));
    mappings.addTableBinding(aTable.getSchemaName(), null, aTable.getTableName(), aTable.getTableName(), null);

    RootClass clazz = new RootClass();
    clazz.setEntityName(aTable.getActualEntityName());
    clazz.setJpaEntityName(aTable.getActualEntityName());
    if (aTable.getJavaClass() != null) {
        clazz.setClassName(aTable.getJavaClass());
        clazz.setProxyInterfaceName(aTable.getJavaClass());
    }
    clazz.setLazy(LAZY);
    clazz.setTable(tab);
    //clazz.setNodeName(aTable.getTableName());

    List<com.manydesigns.portofino.model.database.Column> columnList = new ArrayList<com.manydesigns.portofino.model.database.Column>();

    for (com.manydesigns.portofino.model.database.Column modelColumn : aTable.getColumns()) {
        int jdbcType = modelColumn.getJdbcType();
        Class javaType = modelColumn.getActualJavaType();

        //First param = null ==> doesn't really set anything, just check
        boolean hibernateTypeOk = setHibernateType(null, modelColumn, javaType, jdbcType);
        if (hibernateTypeOk) {
            columnList.add(modelColumn);
        } else {
            logger.error(
                    "Cannot find Hibernate type for table: {}, column: {}, jdbc type: {}, type name: {}. Skipping column.",
                    new Object[] { aTable.getQualifiedName(), modelColumn.getColumnName(), jdbcType,
                            javaType != null ? javaType.getName() : null });
        }
    }

    //Primary keys
    List<com.manydesigns.portofino.model.database.Column> columnPKList = aTable.getPrimaryKey().getColumns();

    if (!columnList.containsAll(columnPKList)) {
        logger.error("Primary key refers to some invalid columns, skipping table {}",
                aTable.getQualifiedName());
        return null;
    }

    if (columnPKList.size() > 1) {
        createPKComposite(mappings, aTable, aTable.getPrimaryKey().getPrimaryKeyName(), clazz, tab,
                columnPKList);
    } else {
        createPKSingle(mappings, aTable, aTable.getPrimaryKey().getPrimaryKeyName(), clazz, tab, columnPKList);
    }

    //Other columns
    columnList.removeAll(columnPKList);

    for (com.manydesigns.portofino.model.database.Column column : columnList) {
        Column col = createColumn(mappings, tab, column);
        if (col != null) {
            clazz.addProperty(createProperty(column, col.getValue()));
        }
    }

    return clazz;
}

From source file:org.finra.dm.dao.DmDaoTest.java

@Test
public void testGetStorages() {
    // Create and persist storage entities.
    for (StorageKey key : getTestStorageKeys()) {
        createStorageEntity(key.getStorageName());
    }//w  ww. j  a v  a 2  s.c om

    // Retrieve a list of storage keys.
    List<StorageKey> resultStorageKeys = dmDao.getStorages();

    // Validate the returned object.
    assertNotNull(resultStorageKeys);
    assertTrue(resultStorageKeys.containsAll(getTestStorageKeys()));
}