Example usage for org.apache.commons.collections CollectionUtils isEqualCollection

List of usage examples for org.apache.commons.collections CollectionUtils isEqualCollection

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils isEqualCollection.

Prototype

public static boolean isEqualCollection(final Collection a, final Collection b) 

Source Link

Document

Returns true iff the given Collection s contain exactly the same elements with exactly the same cardinalities.

Usage

From source file:com.assemblade.server.model.AbstractFolder.java

@Override
public boolean requiresUpdate(Session session, Entry currentEntry) throws StorageException {
    Folder currentFolder = new Folder().getDecorator().decorate(session, currentEntry);
    return !StringUtils.equals(template, currentFolder.getTemplate())
            || !StringUtils.equals(description, currentFolder.getDescription())
            || (inherit != currentFolder.inherit)
            || !CollectionUtils.isEqualCollection(readGroups, currentFolder.readGroups)
            || !CollectionUtils.isEqualCollection(writeGroups, currentFolder.writeGroups);
}

From source file:com.gisgraphy.service.UserSecurityAdvice.java

/**
 * Method to enforce security and only allow administrators to modify users.
 * Regular users are allowed to modify themselves.
 * //from  ww  w . ja  va 2 s.c o  m
 * @param method
 *                the name of the method executed
 * @param args
 *                the arguments to the method
 * @param target
 *                the target class
 * @throws Throwable
 *                 thrown when args[0] is null or not a User object
 */
public void before(Method method, Object[] args, Object target) throws Throwable {
    SecurityContext ctx = SecurityContextHolder.getContext();

    if (ctx.getAuthentication() != null) {
        Authentication auth = ctx.getAuthentication();
        boolean administrator = false;
        GrantedAuthority[] roles = auth.getAuthorities();
        for (GrantedAuthority role1 : roles) {
            if (role1.getAuthority().equals(Constants.ADMIN_ROLE)) {
                administrator = true;
                break;
            }
        }

        User user = (User) args[0];

        AuthenticationTrustResolver resolver = new AuthenticationTrustResolverImpl();
        // allow new users to signup - this is OK b/c Signup doesn't allow
        // setting of roles
        boolean signupUser = resolver.isAnonymous(auth);

        if (!signupUser) {
            User currentUser = getCurrentUser(auth);

            if (user.getId() != null && !user.getId().equals(currentUser.getId()) && !administrator) {
                log.warn("Access Denied: '" + currentUser.getUsername() + "' tried to modify '"
                        + user.getUsername() + "'!");
                throw new AccessDeniedException(ACCESS_DENIED);
            } else if (user.getId() != null && user.getId().equals(currentUser.getId()) && !administrator) {
                // get the list of roles the user is trying add
                Set<String> userRoles = new HashSet<String>();
                if (user.getRoles() != null) {
                    for (Object o : user.getRoles()) {
                        Role role = (Role) o;
                        userRoles.add(role.getName());
                    }
                }

                // get the list of roles the user currently has
                Set<String> authorizedRoles = new HashSet<String>();
                for (GrantedAuthority role : roles) {
                    authorizedRoles.add(role.getAuthority());
                }

                // if they don't match - access denied
                // regular users aren't allowed to change their roles
                if (!CollectionUtils.isEqualCollection(userRoles, authorizedRoles)) {
                    log.warn("Access Denied: '" + currentUser.getUsername()
                            + "' tried to change their role(s)!");
                    throw new AccessDeniedException(ACCESS_DENIED);
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Registering new user '" + user.getUsername() + "'");
            }
        }
    }
}

From source file:com.tesora.dve.sql.schema.cache.NonMTCachedPlan.java

private boolean keysMatch(ListSet<TableKey> allTableKeys) {
    return CollectionUtils.isEqualCollection(Arrays.asList(tks), Arrays.asList(buildTableKeySet(allTableKeys)));
}

From source file:com.doculibre.constellio.wicket.panels.admin.stats.CollectionStatsPanel.java

public CollectionStatsPanel(String id, final String collectionName) {
    super(id);//from  www .j av  a 2 s  .  c  o m

    endDate = new Date();
    startDate = DateUtils.addMonths(endDate, -1);

    Form form = new Form("form") {
        @Override
        protected void onSubmit() {
            statsPanel.replaceWith(statsPanel = new CollectionStatsReportPanel(statsPanel.getId(),
                    collectionName, statsType, startDate, endDate, rows, includeFederatedCollections));
        }
    };
    add(form);

    IModel queryExcludeRegexpsModel = new Model() {
        @Override
        public Object getObject() {
            String result;
            AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = adminCollectionPanel.getCollection();
            CollectionStatsFilter statsFilter = collection.getStatsFilter();
            if (statsFilter != null) {
                StringBuffer sb = new StringBuffer();
                Set<String> existingRegexps = statsFilter.getQueryExcludeRegexps();
                for (String existingRegexp : existingRegexps) {
                    sb.append(existingRegexp);
                    sb.append("\n");
                }
                result = sb.toString();
            } else {
                result = null;
            }
            return result;
        }

        @Override
        public void setObject(Object object) {
            String queryExcludeRegexpsStr = (String) object;
            String[] newRegexpsArray = StringUtils.split(queryExcludeRegexpsStr, "\n");
            List<String> newRegexps = new ArrayList<String>();
            for (String newRegexp : newRegexpsArray) {
                newRegexps.add(newRegexp.trim());
            }

            AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent(
                    AdminCollectionPanel.class);
            RecordCollection collection = adminCollectionPanel.getCollection();
            CollectionStatsFilter statsFilter = collection.getStatsFilter();
            if (statsFilter == null) {
                statsFilter = new CollectionStatsFilter();
                statsFilter.setRecordCollection(collection);
                collection.setStatsFilter(statsFilter);
            }

            Set<String> existingRegexps = statsFilter.getQueryExcludeRegexps();
            if (!CollectionUtils.isEqualCollection(existingRegexps, newRegexps)) {
                RecordCollectionServices collectionServices = ConstellioSpringUtils
                        .getRecordCollectionServices();
                EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager();
                if (!entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().begin();
                }
                existingRegexps.clear();
                existingRegexps.addAll(newRegexps);
                collectionServices.makePersistent(collection, false);

                entityManager.getTransaction().commit();
            }
        }
    };

    form.add(new TextArea("queryExcludeRegexps", queryExcludeRegexpsModel));
    form.add(new DateTextField("startDate", new PropertyModel(this, "startDate"), "yyyy-MM-dd")
            .add(new DatePicker()));
    form.add(new DateTextField("endDate", new PropertyModel(this, "endDate"), "yyyy-MM-dd")
            .add(new DatePicker()));
    form.add(new TextField("rows", new PropertyModel(this, "rows"), Integer.class));
    form.add(new CheckBox("includeFederatedCollections",
            new PropertyModel(this, "includeFederatedCollections")) {
        @Override
        public boolean isVisible() {
            boolean visible = super.isVisible();
            if (visible) {
                AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent(
                        AdminCollectionPanel.class);
                RecordCollection collection = adminCollectionPanel.getCollection();
                visible = collection.isFederationOwner();
            }
            return visible ? visible : false;
        }
    });

    form.add(new DropDownChoice("statsType", new PropertyModel(this, "statsType"), StatsConstants.ALL_STATS,
            new StringResourceChoiceRenderer("statsType", this)));

    form.add(new Label("title", new PropertyModel(this, "statsType")));
    statsPanel = new AjaxLazyLoadPanel("statsPanel") {
        @Override
        public Component getLazyLoadComponent(String markupId) {
            return new CollectionStatsReportPanel(markupId, collectionName, statsType, startDate, endDate, rows,
                    includeFederatedCollections);
        }
    };
    form.add(statsPanel);
}

From source file:com.epam.cme.core.services.impl.DefaultCompatibilityServiceIntegrationTest.java

protected void assertCompatibileListIsCorrect(final List<? extends ProductModel> returnedProducts,
        final Set<String> expectedCodes) {
    Assert.assertEquals(expectedCodes.size(), returnedProducts.size());
    final List<String> returnedCodes = (List<String>) CollectionUtils.collect(returnedProducts,
            new Transformer() {

                @Override/*from  ww  w  .j a v  a 2 s.c  om*/
                public Object transform(final Object product) {
                    final String productCode = ((ProductModel) product).getCode();
                    return productCode;
                }

            });

    Assert.assertTrue(CollectionUtils.isEqualCollection(expectedCodes, returnedCodes));
}

From source file:com.baidu.rigel.biplatform.ma.model.meta.FactTableMetaDefine.java

/**
 * {@inheritDoc}/*w  w w  .ja  v  a2  s.  com*/
 */
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    FactTableMetaDefine other = (FactTableMetaDefine) obj;
    if (columns == null) {
        if (other.columns != null) {
            return false;
        }
    } else if (!CollectionUtils.isEqualCollection(columns, other.columns)) {
        return false;
    }
    if (cubeId == null) {
        if (other.cubeId != null) {
            return false;
        }
    } else if (!cubeId.equals(other.cubeId)) {
        return false;
    }
    if (mutilple != other.mutilple) {
        return false;
    }
    if (name == null) {
        if (other.name != null) {
            return false;
        }
    } else if (!name.equals(other.name)) {
        return false;
    }
    if (regExp == null) {
        if (other.regExp != null) {
            return false;
        }
    } else if (!regExp.equals(other.regExp)) {
        return false;
    }
    if (regExpTables == null) {
        if (other.regExpTables != null) {
            return false;
        }
    } else if (!CollectionUtils.isEqualCollection(regExpTables, other.regExpTables)) {
        return false;
    }
    if (schemaId == null) {
        if (other.schemaId != null) {
            return false;
        }
    } else if (!schemaId.equals(other.schemaId)) {
        return false;
    }
    return true;
}

From source file:com.thoughtworks.go.plugin.access.configrepo.contract.CRPipeline.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/*  ww w  . j ava2s .c  o m*/
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    CRPipeline that = (CRPipeline) o;

    if (label_template != null ? !label_template.equals(that.label_template) : that.label_template != null) {
        return false;
    }
    if (name != null ? !name.equals(that.name) : that.name != null) {
        return false;
    }
    if (group != null ? !group.equals(that.group) : that.group != null) {
        return false;
    }
    if (timer != null ? !timer.equals(that.timer) : that.timer != null) {
        return false;
    }
    if (tracking_tool != null ? !tracking_tool.equals(that.tracking_tool) : that.tracking_tool != null) {
        return false;
    }
    if (mingle != null ? !mingle.equals(that.mingle) : that.mingle != null) {
        return false;
    }
    if (materials != null ? !CollectionUtils.isEqualCollection(materials, that.materials)
            : that.materials != null) {
        return false;
    }
    if (stages != null ? !CollectionUtils.isEqualCollection(stages, that.stages) : that.stages != null) {
        return false;
    }
    if (environment_variables != null
            ? !CollectionUtils.isEqualCollection(environment_variables, that.environment_variables)
            : that.environment_variables != null) {
        return false;
    }

    return true;
}

From source file:com.qrmedia.pattern.dynamicenum.StaticResourceBackedDynamicEnumTest.java

@Test
public void range_singleton() {
    assertTrue(CollectionUtils.isEqualCollection(Arrays.asList(Integer.valueOf(2)),
            agents.range(Integer.valueOf(2), Integer.valueOf(2))));
}

From source file:info.magnolia.cms.util.WebXmlUtil.java

/**
 * Returns:/* w w  w .  j a  va 2 s .c o m*/
 * +1 if all mandatory dispatchers are present and no additional unsupported dispatcher is present, or this filter class isn't registered.
 * 0  if all mandatory dispatchers are present but additional unsupported dispatchers are present.
 * -1  if not all mandatory dispatchers are present.
 */
public int checkFilterDispatchersConfiguration(String filterClass, List mandatoryDispatchers,
        List optionalDispatchers) {
    final Element filterEl = getFilterElement(filterClass);
    if (filterEl != null) {
        final String filterName = filterEl.getTextNormalize();
        final String filterMappingXPathExpr = "/webxml:web-app/webxml:filter-mapping[webxml:filter-name='"
                + filterName + "']/webxml:dispatcher";
        final List dispatchersEl = getElementsFromXPath(filterMappingXPathExpr);
        final List registeredDispatchers = new ArrayList();
        final Iterator it = dispatchersEl.iterator();
        while (it.hasNext()) {
            final Element dispatcherEl = (Element) it.next();
            registeredDispatchers.add(dispatcherEl.getTextNormalize());
        }
        registeredDispatchers.removeAll(optionalDispatchers);
        if (CollectionUtils.isEqualCollection(mandatoryDispatchers, registeredDispatchers)) {
            return 1;
        } else if (CollectionUtils.isSubCollection(mandatoryDispatchers, registeredDispatchers)) {
            return 0;
        } else {
            return -1;
        }

    }
    return 1;
}

From source file:de.hybris.platform.cms2.servicelayer.services.admin.impl.DefaultCMSAdminRestrictionServiceIntegrationTest.java

/**
 * Test method for// w  ww.  j  a  v  a 2s . c o  m
 * {@link de.hybris.platform.cms2.servicelayer.services.admin.impl.DefaultCMSAdminRestrictionService#getProducts(de.hybris.platform.cms2.model.restrictions.CMSProductRestrictionModel, de.hybris.platform.cms2.model.preview.PreviewDataModel)}
 * .
 */
@Test
public void shouldGetProductsForRestriction() {
    // given
    final List<ProductModel> products = new ArrayList<ProductModel>();
    products.add(productService.getProductForCode("testProduct0"));
    products.add(productService.getProductForCode("testProduct1"));
    products.add(productService.getProductForCode("testProduct2"));
    final CMSProductRestrictionModel productRestriction = modelService.create(CMSProductRestrictionModel.class);
    productRestriction.setUid("FooBar");
    productRestriction.setProducts(products);
    modelService.save(productRestriction);

    // when
    final List<ProductModel> restrictedProducts = cmsAdminRestrictionService.getProducts(productRestriction,
            previewContext);

    // then
    assertThat(restrictedProducts).hasSize(3);
    assertThat(CollectionUtils.isEqualCollection(restrictedProducts, products)).isTrue();
    final CatalogVersionAssertion testProduct0 = new CatalogVersionAssertion(restrictedProducts.get(0));
    final CatalogVersionAssertion testProduct1 = new CatalogVersionAssertion(restrictedProducts.get(1));
    final CatalogVersionAssertion testProduct2 = new CatalogVersionAssertion(restrictedProducts.get(2));
    assertThat(testProduct0).hasSameCatalogVersion(getCatalogVersion());
    assertThat(testProduct1).hasSameCatalogVersion(getCatalogVersion());
    assertThat(testProduct2).hasSameCatalogVersion(getCatalogVersion());
}