Java Code Examples for org.apache.commons.collections4.CollectionUtils#containsAny()

The following examples show how to use org.apache.commons.collections4.CollectionUtils#containsAny() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeUtils.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * PUBLIC: Tests whether two topics should be merged or not,
 * according to XTM rules.
 *
 * @param t1 topicIF; #1 topic to merge
 * @param t2 topicIF; #2 topic to merge
 * @return boolean; true if the topics should be merged, false otherwise.
 */
public static boolean shouldMerge(TopicIF t1, TopicIF t2) {
  // check subject locators
  if (CollectionUtils.containsAny(t1.getSubjectLocators(), t2.getSubjectLocators()))
    return true;
  
  // check subject indicators and source locators
  if (CollectionUtils.containsAny(t1.getSubjectIdentifiers(), t2.getSubjectIdentifiers()) ||
      CollectionUtils.containsAny(t1.getItemIdentifiers(), t2.getSubjectIdentifiers()))
    return true;
  if (CollectionUtils.containsAny(t1.getItemIdentifiers(), t2.getItemIdentifiers()) ||
      CollectionUtils.containsAny(t1.getSubjectIdentifiers(), t2.getItemIdentifiers()))
    return true;

  // should merge if they reify the same object
  ReifiableIF r1 = t1.getReified();
  ReifiableIF r2 = t2.getReified();
  if (r1 != null && Objects.equals(r1, r2))
    return true;

  return false;
}
 
Example 2
Source File: ApiclientJackson2XmlMessageConverter.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@Override
	public boolean canWrite(Class<?> clazz, MediaType mediaType) {
		List<MediaType> consumes = this.supportedMediaTypes.getConsumeMediaTypes();
		if (!consumes.isEmpty()) {
			return CollectionUtils.containsAny(consumes, super.getSupportedMediaTypes());
		}
		
		if(mediaType!=null){
			List<MediaType> mediaTypes = getMediaTypes(clazz);
			if(LangUtils.isNotEmpty(mediaTypes)){
				return mediaTypes.contains(mediaType);
			}
		}
		// xml必须要显式加注解声明,否则返回false
//		return super.canWrite(clazz, mediaType);
		return false;
	}
 
Example 3
Source File: Business.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean readable(EffectivePerson effectivePerson, Stat stat) throws Exception {
	if (null == stat) {
		return false;
	}
	if (effectivePerson.isManager()) {
		return true;
	}
	if (stat.getAvailableIdentityList().isEmpty() && stat.getAvailableUnitList().isEmpty()) {
		return true;
	}
	if (CollectionUtils.containsAny(stat.getAvailableIdentityList(),
			organization().identity().listWithPerson(effectivePerson))) {
		return true;
	}
	if (CollectionUtils.containsAny(stat.getAvailableUnitList(),
			organization().unit().listWithPersonSupNested(effectivePerson))) {
		return true;
	}
	Query query = this.entityManagerContainer().find(stat.getQuery(), Query.class);
	/** 在所属query的管理人员中 */
	if (null != query && ListTools.contains(query.getControllerList(), effectivePerson.getDistinguishedName())) {
		return true;
	}
	if (organization().person().hasRole(effectivePerson, OrganizationDefinition.Manager,
			OrganizationDefinition.QueryManager)) {
		return true;
	}
	return false;
}
 
Example 4
Source File: ApiclientJackson2HttpMessageConverter.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
	List<MediaType> consumes = this.supportedMediaTypes.getConsumeMediaTypes();
	if (!consumes.isEmpty()) {
		return CollectionUtils.containsAny(consumes, super.getSupportedMediaTypes());
	}
	
	if(mediaType!=null){
		List<MediaType> mediaTypes = getMediaTypes(clazz);
		if(LangUtils.isNotEmpty(mediaTypes)){
			return mediaTypes.contains(mediaType);
		}
	}
	return super.canWrite(clazz, mediaType);
}
 
Example 5
Source File: ApiclientJackson2HttpMessageConverter.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
	List<MediaType> produces = this.supportedMediaTypes.getProduceMediaTypes();
	if (!produces.isEmpty()) {
		return CollectionUtils.containsAny(produces, super.getSupportedMediaTypes());
	}
	if (mediaType != null) {
		List<MediaType> mediaTypes = getMediaTypes(type);
		if(LangUtils.isNotEmpty(mediaTypes)){
			return mediaTypes.contains(mediaType);
		}
	}
	return super.canRead(type, contextClass, mediaType);
}
 
Example 6
Source File: RankingDao.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Transactional
public void save(RankingDto dto, long guildId) {
    RankingConfig config = rankingService.getOrCreate(guildId);
    config.setAnnouncementEnabled(dto.isAnnouncementEnabled());
    config.setEnabled(dto.isEnabled());
    config.setResetOnLeave(dto.isResetOnLeave());
    config.setBannedRoles(dto.getBannedRoles());
    config.setIgnoredChannels(ApiMapperService.toLongList(dto.getIgnoredChannels()));
    config.setIgnoredVoiceChannels(ApiMapperService.toLongList(dto.getIgnoredVoiceChannels()));
    config.setCookieEnabled(dto.isCookieEnabled());

    config.setAnnounceTemplate(templateDao.updateOrCreate(dto.getAnnounceTemplate(), config.getAnnounceTemplate()));

    GuildDto guildDto = gatewayService.getGuildInfo(guildId);
    if (guildDto != null && CollectionUtils.containsAny(guildDto.getFeatureSets(), FeatureSet.BONUS)) {
        config.setTextExpMultiplier(dto.getTextExpMultiplier() / 100.0d);
        config.setVoiceExpMultiplier(dto.getVoiceExpMultiplier() / 100.0d);
        config.setVoiceEnabled(dto.isVoiceEnabled());
        config.setMaxVoiceMembers(dto.getMaxVoiceMembers());
    }

    if (dto.getRewards() != null) {
        config.setRewards(dto.getRewards().stream()
                .filter(e -> e.getLevel() != null && e.getLevel() >= 0 && e.getLevel() <= RankingUtils.MAX_LEVEL)
                .collect(Collectors.toList()));
    } else {
        config.setRewards(null);
    }
    rankingService.save(config);
}
 
Example 7
Source File: Business.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean readable(EffectivePerson effectivePerson, Reveal reveal) throws Exception {
	if (null == reveal) {
		return false;
	}
	if (effectivePerson.isManager()) {
		return true;
	}
	if (reveal.getAvailableIdentityList().isEmpty() && reveal.getAvailableUnitList().isEmpty()) {
		return true;
	}
	if (CollectionUtils.containsAny(reveal.getAvailableIdentityList(),
			organization().identity().listWithPerson(effectivePerson))) {
		return true;
	}
	if (CollectionUtils.containsAny(reveal.getAvailableUnitList(),
			organization().unit().listWithPersonSupNested(effectivePerson))) {
		return true;
	}
	Query query = this.entityManagerContainer().find(reveal.getQuery(), Query.class);
	/** 在所属query的管理人员中 */
	if (null != query && ListTools.contains(query.getControllerList(), effectivePerson.getDistinguishedName())) {
		return true;
	}
	if (organization().person().hasRole(effectivePerson, OrganizationDefinition.Manager,
			OrganizationDefinition.QueryManager)) {
		return true;
	}
	return false;
}
 
Example 8
Source File: Business.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean readable(EffectivePerson effectivePerson, View view) throws Exception {
	if (null == view) {
		return false;
	}
	if (effectivePerson.isManager()) {
		return true;
	}
	if (view.getAvailableIdentityList().isEmpty() && view.getAvailableUnitList().isEmpty()) {
		return true;
	}
	if (CollectionUtils.containsAny(view.getAvailableIdentityList(),
			organization().identity().listWithPerson(effectivePerson))) {
		return true;
	}
	if (CollectionUtils.containsAny(view.getAvailableUnitList(),
			organization().unit().listWithPersonSupNested(effectivePerson))) {
		return true;
	}
	Query query = this.entityManagerContainer().find(view.getQuery(), Query.class);
	/** 在所属query的管理人员中 */
	if (null != query && ListTools.contains(query.getControllerList(), effectivePerson.getDistinguishedName())) {
		return true;
	}
	if (organization().person().hasRole(effectivePerson, OrganizationDefinition.Manager,
			OrganizationDefinition.QueryManager)) {
		return true;
	}
	return false;
}
 
Example 9
Source File: Business.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean readable(EffectivePerson effectivePerson, Query query) throws Exception {
	if (null == query) {
		return false;
	}
	if (effectivePerson.isManager()) {
		return true;
	}
	if (StringUtils.equals(effectivePerson.getDistinguishedName(), query.getCreatorPerson())
			|| query.getControllerList().contains(effectivePerson.getDistinguishedName())) {
		return true;
	}
	if (query.getAvailableIdentityList().isEmpty() && query.getAvailableUnitList().isEmpty()) {
		return true;
	}
	if (organization().person().hasRole(effectivePerson, OrganizationDefinition.Manager,
			OrganizationDefinition.QueryManager)) {
		return true;
	}
	if (CollectionUtils.containsAny(query.getAvailableIdentityList(),
			organization().identity().listWithPerson(effectivePerson))) {
		return true;
	}
	if (CollectionUtils.containsAny(query.getAvailableUnitList(),
			organization().unit().listWithPersonSupNested(effectivePerson))) {
		return true;
	}
	return false;
}
 
Example 10
Source File: ApplicationFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean allowRead(EffectivePerson effectivePerson, List<String> roles, List<String> identities,
		List<String> units, Application application) throws Exception {
	if (null == application) {
		return false;
	}
	if (effectivePerson.isManager()) {
		return true;
	}
	if (StringUtils.equals(effectivePerson.getDistinguishedName(), application.getCreatorPerson())
			|| application.getControllerList().contains(effectivePerson.getDistinguishedName())) {
		return true;
	}
	if (application.getAvailableIdentityList().isEmpty() && application.getAvailableUnitList().isEmpty()) {
		return true;
	}
	if (this.business().organization().person().hasRole(effectivePerson, OrganizationDefinition.Manager,
			OrganizationDefinition.ProcessPlatformManager)) {
		return true;
	}
	if (CollectionUtils.containsAny(application.getAvailableIdentityList(), identities)) {
		return true;
	}
	if (CollectionUtils.containsAny(application.getAvailableUnitList(), units)) {
		return true;
	}
	return false;
}
 
Example 11
Source File: ListTools.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public static <T> boolean containsAny(List<T> list, List<T> other) throws Exception {
	if ((null == list) || (null == other)) {
		return false;
	}
	return CollectionUtils.containsAny(list, other);
}
 
Example 12
Source File: StudioAbstractAccessDecisionVoter.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
protected boolean hasAnyPermission(String siteId, String path, String user, Set<String> permissions) {
    Set<String> userPermissions = securityService.getUserPermissions(siteId, path, user, null);
    return CollectionUtils.isEmpty(permissions) ||
            (CollectionUtils.isNotEmpty(userPermissions)
                    && CollectionUtils.containsAny(userPermissions, permissions));
}
 
Example 13
Source File: LifestreetAdapter.java    From prebid-server-java with Apache License 2.0 4 votes vote down vote up
private static boolean containsAnyAllowedMediaType(AdUnitBidWithParams<LifestreetParams> adUnitBidWithParams) {
    return CollectionUtils.containsAny(adUnitBidWithParams.getAdUnitBid().getMediaTypes(), ALLOWED_MEDIA_TYPES);
}
 
Example 14
Source File: UserAuthorityGroup.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean hasCriticalAuthorities()
{
    return authorities != null && CollectionUtils.containsAny( authorities, Sets.newHashSet( CRITICAL_AUTHS ) );
}
 
Example 15
Source File: UserServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
@HasPermission(type = DefaultPermission.class, action = "delete_users")
public void deleteUsers(List<Long> userIds, List<String> usernames)
        throws ServiceLayerException, AuthenticationException, UserNotFoundException {
    User currentUser = getCurrentUser();

    if (CollectionUtils.containsAny(userIds, Arrays.asList(currentUser.getId())) ||
            CollectionUtils.containsAny(usernames, Arrays.asList(currentUser.getUsername()))) {
        throw new ServiceLayerException("Cannot delete self.");
    }

    generalLockService.lock(REMOVE_SYSTEM_ADMIN_MEMBER_LOCK);
    try {
        try {
            Group g = groupServiceInternal.getGroupByName(SYSTEM_ADMIN_GROUP);
            List<User> members =
                    groupServiceInternal.getGroupMembers(g.getId(), 0, Integer.MAX_VALUE, StringUtils.EMPTY);
            if (CollectionUtils.isNotEmpty(members)) {
                List<User> membersAfterRemove = new ArrayList<User>();
                membersAfterRemove.addAll(members);
                members.forEach(m -> {
                    if (CollectionUtils.isNotEmpty(userIds)) {
                        if (userIds.contains(m.getId())) {
                            membersAfterRemove.remove(m);
                        }
                    }
                    if (CollectionUtils.isNotEmpty(usernames)) {
                        if (usernames.contains(m.getUsername())) {
                            membersAfterRemove.remove(m);
                        }
                    }
                });
                if (CollectionUtils.isEmpty(membersAfterRemove)) {
                    throw new ServiceLayerException("Removing all members of the System Admin group is not allowed." +
                            " We must have at least one system administrator.");
                }
            }
        } catch (GroupNotFoundException e) {
            throw new ServiceLayerException("The System Admin group is not found.", e);
        }

        List<User> toDelete = userServiceInternal.getUsersByIdOrUsername(userIds, usernames);
        userServiceInternal.deleteUsers(userIds, usernames);
        SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_DELETE);
        auditLog.setActorId(getCurrentUser().getUsername());
        auditLog.setPrimaryTargetId(siteFeed.getSiteId());
        auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
        auditLog.setPrimaryTargetValue(siteFeed.getName());
        List<AuditLogParameter> paramters = new ArrayList<AuditLogParameter>();
        for (User deletedUser : toDelete) {
            AuditLogParameter paramter = new AuditLogParameter();
            paramter.setTargetId(Long.toString(deletedUser.getId()));
            paramter.setTargetType(TARGET_TYPE_USER);
            paramter.setTargetValue(deletedUser.getUsername());
            paramters.add(paramter);
        }
        auditLog.setParameters(paramters);
        auditServiceInternal.insertAuditLog(auditLog);
    } finally {
        generalLockService.unlock(REMOVE_SYSTEM_ADMIN_MEMBER_LOCK);
    }
}
 
Example 16
Source File: AppnexusAdapter.java    From prebid-server-java with Apache License 2.0 4 votes vote down vote up
private static boolean containsAnyAllowedMediaType(AdUnitBidWithParams<AppnexusParams> adUnitBidWithParams) {
    return CollectionUtils.containsAny(adUnitBidWithParams.getAdUnitBid().getMediaTypes(), ALLOWED_MEDIA_TYPES);
}
 
Example 17
Source File: PulsepointAdapter.java    From prebid-server-java with Apache License 2.0 4 votes vote down vote up
private static boolean containsAnyAllowedMediaType(
        AdUnitBidWithParams<NormalizedPulsepointParams> adUnitBidWithParams) {
    return CollectionUtils.containsAny(adUnitBidWithParams.getAdUnitBid().getMediaTypes(), ALLOWED_MEDIA_TYPES);
}
 
Example 18
Source File: PermissionUtil.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Check whether the provided {@link net.dv8tion.jda.api.entities.Member Member} can use the specified {@link net.dv8tion.jda.api.entities.Emote Emote}.
 *
 * <p>If the specified Member is not in the emote's guild or the emote provided is fake this will return false.
 * Otherwise it will check if the emote is restricted to any roles and if that is the case if the Member has one of these.
 *
 * <p>In the case of an {@link net.dv8tion.jda.api.entities.Emote#isAnimated() animated} Emote, this will
 * check if the issuer is the currently logged in account, and then check if the account has
 * {@link net.dv8tion.jda.api.entities.SelfUser#isNitro() nitro}, and return false if it doesn't.
 * <br>For other accounts, this method will not take into account whether the emote is animated, as there is
 * no real way to check if the Member can interact with them.
 *
 * <br><b>Note</b>: This is not checking if the issuer owns the Guild or not.
 *
 * @param  issuer
 *         The member that tries to interact with the Emote
 * @param  emote
 *         The emote that is the target interaction
 *
 * @throws IllegalArgumentException
 *         if any of the provided parameters is {@code null}
 *         or the provided entities are not from the same guild
 *
 * @return True, if the issuer can interact with the emote
 */
public static boolean canInteract(Member issuer, Emote emote)
{
    Checks.notNull(issuer, "Issuer Member");
    Checks.notNull(emote,  "Target Emote");

    if (!issuer.getGuild().equals(emote.getGuild()))
        throw new IllegalArgumentException("The issuer and target are not in the same Guild");

    return emote.canProvideRoles() && (emote.getRoles().isEmpty() // Emote restricted to roles -> check if the issuer has them
        || CollectionUtils.containsAny(issuer.getRoles(), emote.getRoles()));
}
 
Example 19
Source File: User.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Indicates whether this user can manage the given user group.
 *
 * @param userGroup the user group to test.
 * @return true if the given user group can be managed by this user, false if not.
 */
public boolean canManage( UserGroup userGroup )
{
    return userGroup != null && CollectionUtils.containsAny( groups, userGroup.getManagedByGroups() );
}
 
Example 20
Source File: User.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Indicates whether this user is managed by the given user group.
 *
 * @param userGroup the user group to test.
 * @return true if the given user group is managed by this user, false if not.
 */
public boolean isManagedBy( UserGroup userGroup )
{
    return userGroup != null && CollectionUtils.containsAny( groups, userGroup.getManagedGroups() );
}