List of usage examples for org.apache.commons.collections CollectionUtils containsAny
public static boolean containsAny(final Collection coll1, final Collection coll2)
true
iff at least one element is in both collections. From source file:org.squashtest.tm.domain.milestone.Milestone.java
public boolean isOneVersionAlreadyBound(RequirementVersion version) { // check that no other version of this requirement is bound already to this milestone Collection<RequirementVersion> allVersions = new ArrayList<>( version.getRequirement().getRequirementVersions()); CollectionUtils.filter(allVersions, new Predicate() { @Override// w ww . j av a2 s. c o m public boolean evaluate(Object reqV) { return ((RequirementVersion) reqV).getMilestones().contains(Milestone.this); } }); return CollectionUtils.containsAny(requirementVersions, allVersions); }
From source file:org.surfnet.oaaas.resource.resourceserver.ResourceServerResource.java
/** * Delete all scopes from clients that are not valid anymore with the new * resource server//from ww w . j a va 2s.com * * @param newScopes the newly saved scopes * @param oldScopes the scopes from the existing resource server * @param clients the clients of the resource server */ @SuppressWarnings("unchecked") protected void pruneClientScopes(final List<String> newScopes, List<String> oldScopes, Set<Client> clients) { if (!newScopes.containsAll(oldScopes)) { subtract(oldScopes, newScopes); Collection<String> outdatedScopes = subtract(oldScopes, newScopes); LOG.info("Resource server has updated scopes. Will remove all outdated scopes from clients: {}", outdatedScopes); for (Client c : clients) { final List<String> clientScopes = c.getScopes(); if (CollectionUtils.containsAny(clientScopes, outdatedScopes)) { ArrayList<String> prunedScopes = new ArrayList<String>(subtract(clientScopes, outdatedScopes)); LOG.info( "Client scopes of client {} were: {}. After pruning (because resourceServer has new scopes): {}", new Object[] { c.getClientId(), c.getScopes(), prunedScopes }); c.setScopes(prunedScopes); } } } }
From source file:org.trnltk.morphology.lexicon.ImmutableRootGenerator.java
public HashSet<ImmutableRoot> generate(final Lexeme lexeme) { if (CollectionUtils.containsAny(lexeme.getAttributes(), MODIFIERS_TO_WATCH)) { return this.generateModifiedRootNodes(lexeme); } else {//w ww . j a va2 s .com Set<PhoneticAttribute> phoneticAttributes = phoneticsAnalyzer .calculatePhoneticAttributes(lexeme.getLemmaRoot(), lexeme.getAttributes()); final ImmutableRoot root = new ImmutableRoot(lexeme.getLemmaRoot(), lexeme, Sets.immutableEnumSet(phoneticAttributes), null); return Sets.newHashSet(root); } }
From source file:org.trnltk.morphology.lexicon.ImmutableRootGenerator.java
private HashSet<ImmutableRoot> generateModifiedRootNodes(final Lexeme lexeme) { final Set<LexemeAttribute> lexemeAttributes = lexeme.getAttributes(); if (lexemeAttributes.contains(LexemeAttribute.Special)) return this.handleSpecialRoots(lexeme); if (lexemeAttributes.contains(LexemeAttribute.EndsWithAyn)) { //kind of hack, didn't like it :( // if the word ends with Ayn // create roots with that attribute, and without that attribute // when creating with that attribute, add a VowelStart expectation final HashSet<ImmutableRoot> immutableRoots = new HashSet<ImmutableRoot>(); final EnumSet<LexemeAttribute> lexemeAttributesWithoutAyn = EnumSet.copyOf(lexemeAttributes); lexemeAttributesWithoutAyn.remove(LexemeAttribute.EndsWithAyn); final Lexeme lexemeWithoutAttrEndsWithAyn = new ImmutableLexeme(lexeme.getLemma(), lexeme.getLemmaRoot(), lexeme.getPrimaryPos(), lexeme.getSecondaryPos(), Sets.immutableEnumSet(lexemeAttributesWithoutAyn)); final HashSet<ImmutableRoot> rootsWithoutAynApplied = this .generateModifiedRootNodes(lexemeWithoutAttrEndsWithAyn); immutableRoots.addAll(rootsWithoutAynApplied); for (ImmutableRoot immutableRoot : rootsWithoutAynApplied) { final ImmutableSet<PhoneticAttribute> phoneticAttributesWithoutAynApplied = immutableRoot .getPhoneticAttributes(); final HashSet<PhoneticAttribute> phoneticAttributesWithAynApplied = Sets .newHashSet(phoneticAttributesWithoutAynApplied); phoneticAttributesWithAynApplied.remove(PhoneticAttribute.LastLetterVowel); phoneticAttributesWithAynApplied.add(PhoneticAttribute.LastLetterConsonant); final ImmutableRoot immutableRootWithAynApplied = new ImmutableRoot(immutableRoot.getSequence(), immutableRoot.getLexeme(), Sets.immutableEnumSet(phoneticAttributesWithAynApplied), Sets.immutableEnumSet(PhoneticExpectation.VowelStart)); immutableRoots.add(immutableRootWithAynApplied); }/*from w w w . java 2 s.com*/ // just before returning, set correct lexeme again final HashSet<ImmutableRoot> immutableRootsWithCorrectLexemeAttr = new HashSet<ImmutableRoot>(); for (ImmutableRoot immutableRoot : immutableRoots) { immutableRootsWithCorrectLexemeAttr.add(new ImmutableRoot(immutableRoot.getSequence(), lexeme, immutableRoot.getPhoneticAttributes(), immutableRoot.getPhoneticExpectations())); } return immutableRootsWithCorrectLexemeAttr; } final String lemmaRoot = lexeme.getLemmaRoot(); String modifiedRootStr = lexeme.getLemmaRoot(); final EnumSet<PhoneticAttribute> originalPhoneticAttrs = phoneticsAnalyzer .calculatePhoneticAttributes(lexeme.getLemmaRoot(), null); final EnumSet<PhoneticAttribute> modifiedPhoneticAttrs = phoneticsAnalyzer .calculatePhoneticAttributes(lexeme.getLemmaRoot(), null); final EnumSet<PhoneticExpectation> originalPhoneticExpectations = EnumSet.noneOf(PhoneticExpectation.class); final EnumSet<PhoneticExpectation> modifiedPhoneticExpectations = EnumSet.noneOf(PhoneticExpectation.class); if (CollectionUtils.containsAny(lexemeAttributes, Sets.immutableEnumSet(LexemeAttribute.Voicing, LexemeAttribute.VoicingOpt))) { final TurkicLetter lastLetter = TurkishAlphabet .getLetter(modifiedRootStr.charAt(modifiedRootStr.length() - 1)); final TurkicLetter voicedLastLetter = lemmaRoot.endsWith("nk") ? TurkishAlphabet.L_g : TurkishAlphabet.voice(lastLetter); Validate.notNull(voicedLastLetter); modifiedRootStr = modifiedRootStr.substring(0, modifiedRootStr.length() - 1) + voicedLastLetter.charValue(); modifiedPhoneticAttrs.remove(PhoneticAttribute.LastLetterVoicelessStop); if (!lexemeAttributes.contains(LexemeAttribute.VoicingOpt)) { originalPhoneticExpectations.add(PhoneticExpectation.ConsonantStart); } modifiedPhoneticExpectations.add(PhoneticExpectation.VowelStart); } if (lexemeAttributes.contains(LexemeAttribute.Doubling)) { modifiedRootStr += modifiedRootStr.charAt(modifiedRootStr.length() - 1); originalPhoneticExpectations.add(PhoneticExpectation.ConsonantStart); modifiedPhoneticExpectations.add(PhoneticExpectation.VowelStart); } if (lexemeAttributes.contains(LexemeAttribute.LastVowelDrop)) { modifiedRootStr = modifiedRootStr.substring(0, modifiedRootStr.length() - 2) + modifiedRootStr.charAt(modifiedRootStr.length() - 1); if (!PrimaryPos.Verb.equals(lexeme.getPrimaryPos())) originalPhoneticExpectations.add(PhoneticExpectation.ConsonantStart); modifiedPhoneticExpectations.add(PhoneticExpectation.VowelStart); } if (lexemeAttributes.contains(LexemeAttribute.InverseHarmony)) { originalPhoneticAttrs.add(PhoneticAttribute.LastVowelFrontal); originalPhoneticAttrs.remove(PhoneticAttribute.LastVowelBack); modifiedPhoneticAttrs.add(PhoneticAttribute.LastVowelFrontal); modifiedPhoneticAttrs.remove(PhoneticAttribute.LastVowelBack); } if (lexemeAttributes.contains(LexemeAttribute.ProgressiveVowelDrop)) { modifiedRootStr = modifiedRootStr.substring(0, modifiedRootStr.length() - 1); if (this.hasVowel(modifiedRootStr)) { modifiedPhoneticAttrs.clear(); modifiedPhoneticAttrs.addAll(phoneticsAnalyzer.calculatePhoneticAttributes(modifiedRootStr, null)); } modifiedPhoneticExpectations.add(PhoneticExpectation.VowelStart); } ImmutableRoot originalRoot = new ImmutableRoot(lexeme.getLemmaRoot(), lexeme, Sets.immutableEnumSet(originalPhoneticAttrs), Sets.immutableEnumSet(originalPhoneticExpectations)); ImmutableRoot modifiedRoot = new ImmutableRoot(modifiedRootStr, lexeme, Sets.immutableEnumSet(modifiedPhoneticAttrs), Sets.immutableEnumSet(modifiedPhoneticExpectations)); if (originalRoot.equals(modifiedRoot)) return Sets.newHashSet(originalRoot); else return Sets.newHashSet(originalRoot, modifiedRoot); }
From source file:org.trnltk.morphology.lexicon.LexemeCreator.java
private void inferVerbMorphemicAttributes(TurkicLetter lastLetter, int vowelCount, HashSet<LexemeAttribute> lexemeAttributes) { if (lastLetter.isVowel()) { lexemeAttributes.add(LexemeAttribute.ProgressiveVowelDrop); lexemeAttributes.add(LexemeAttribute.Passive_In); }/*from w w w .ja va 2s .com*/ if (vowelCount > 1 && !lexemeAttributes.contains(LexemeAttribute.Aorist_A)) lexemeAttributes.add(LexemeAttribute.Aorist_I); if (vowelCount == 1 && !lexemeAttributes.contains(LexemeAttribute.Aorist_I)) lexemeAttributes.add(LexemeAttribute.Aorist_A); if (lastLetter.equals(TurkishAlphabet.L_l)) lexemeAttributes.add(LexemeAttribute.Passive_In); if (!CollectionUtils.containsAny(lexemeAttributes, LexemeAttribute.CAUSATIVES)) { if (lastLetter.isVowel() || ((lastLetter.equals(TurkishAlphabet.L_l) || lastLetter.equals(TurkishAlphabet.L_r)) && vowelCount > 1)) { lexemeAttributes.add(LexemeAttribute.Causative_t); } else if (lastLetter.equals(TurkishAlphabet.L_t) && vowelCount < 2) { lexemeAttributes.add(LexemeAttribute.Causative_Ir); } else { lexemeAttributes.add(LexemeAttribute.Causative_dIr); } } if (lexemeAttributes.contains(LexemeAttribute.ProgressiveVowelDrop)) lexemeAttributes.add(LexemeAttribute.NoVoicing); if (!lexemeAttributes.contains(LexemeAttribute.Voicing) && !lexemeAttributes.contains(LexemeAttribute.NoVoicing)) lexemeAttributes.add(LexemeAttribute.NoVoicing); }
From source file:org.trnltk.morphology.morphotactics.suffixformspecifications.DoesntHaveLexemeAttributes.java
@Override public boolean isSatisfiedBy(MorphemeContainer morphemeContainer) { Validate.notNull(morphemeContainer); Collection<SuffixTransition> suffixTransitions = morphemeContainer.getSuffixTransitions(); // filter out free suffixTransitions, zero suffixTransitions and suffixTransitions with empty suffix forms // since all those three don't change the phonetic attributes of a string suffixTransitions = Collections2.filter(suffixTransitions, new Predicate<SuffixTransition>() { @Override/*from www . j a v a 2s.co m*/ public boolean apply(SuffixTransition input) { return !(input.getSuffixFormApplication().getSuffixForm() .getSuffix() instanceof FreeTransitionSuffix) && !(input.getSuffixFormApplication().getSuffixForm() .getSuffix() instanceof ZeroTransitionSuffix) && !(input.getSuffixFormApplication().getSuffixForm() .getSuffix() instanceof ConditionalFreeTransitionSuffix) && StringUtils.isNotEmpty(input.getSuffixFormApplication().getActualSuffixForm()); // The str " " would change the phonetics! } }); if (CollectionUtils.isNotEmpty(suffixTransitions)) return true; final Set<LexemeAttribute> morphemeContainerLexemeAttributes = morphemeContainer.getRoot().getLexeme() .getAttributes(); if (CollectionUtils.isEmpty(morphemeContainerLexemeAttributes)) return false; return !CollectionUtils.containsAny(morphemeContainerLexemeAttributes, this.lexemeAttributes); // cannot have even one }
From source file:org.trnltk.testutil.testmatchers.ParseResultsDontExistMatcher.java
@Override public boolean matchesSafely(Collection<String> item) { return CollectionUtils.isNotEmpty(item) && !CollectionUtils.containsAny(item, expectedParseResults); }
From source file:org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.java
/** * http://tools.ietf.org/html/rfc6749#section-4.1.2 * <p/>//from ww w. j a va2 s . c o m * 4.1.2.1. Error Response * <p/> * If the request fails due to a missing, invalid, or mismatching * redirection URI, or if the client identifier is missing or invalid, * the authorization server SHOULD inform the resource owner of the * error and MUST NOT automatically redirect the user-agent to the * invalid redirection URI. * <p/> * If the resource owner denies the access request or if the request * fails for reasons other than a missing or invalid redirection URI, * the authorization server informs the client by adding the following * parameters to the query component of the redirection URI using the * "application/x-www-form-urlencoded" format * * @param clientId * @param req * @return * @throws OAuthSystemException * @throws OAuthProblemException */ private String handleOAuthAuthorizationRequest(String clientId, HttpServletRequest req) throws OAuthSystemException, OAuthProblemException { OAuth2ClientValidationResponseDTO clientDTO = null; String redirectUri = req.getParameter("redirect_uri"); String pkceChallengeCode = null; String pkceChallengeMethod = null; boolean isPKCESupportEnabled = EndpointUtil.getOAuth2Service().isPKCESupportEnabled(); if (StringUtils.isBlank(clientId)) { if (log.isDebugEnabled()) { log.debug("Client Id is not present in the authorization request"); } return EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, "Client Id is not present in the " + "authorization request", null); } else if (StringUtils.isBlank(redirectUri)) { if (log.isDebugEnabled()) { log.debug("Redirect URI is not present in the authorization request"); } return EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, "Redirect URI is not present in the" + " authorization request", null); } else { clientDTO = validateClient(clientId, redirectUri); } if (!clientDTO.isValidClient()) { return EndpointUtil.getErrorPageURL(clientDTO.getErrorCode(), clientDTO.getErrorMsg(), null); } // Now the client is valid, redirect him to the authorization page. OAuthAuthzRequest oauthRequest = new CarbonOAuthAuthzRequest(req); OAuth2Parameters params = new OAuth2Parameters(); params.setClientId(clientId); params.setRedirectURI(clientDTO.getCallbackURL()); params.setResponseType(oauthRequest.getResponseType()); params.setResponseMode(oauthRequest.getParam(RESPONSE_MODE)); params.setScopes(oauthRequest.getScopes()); if (params.getScopes() == null) { // to avoid null pointers Set<String> scopeSet = new HashSet<String>(); scopeSet.add(""); params.setScopes(scopeSet); } params.setState(oauthRequest.getState()); params.setApplicationName(clientDTO.getApplicationName()); pkceChallengeCode = req.getParameter(OAuthConstants.OAUTH_PKCE_CODE_CHALLENGE); pkceChallengeMethod = req.getParameter(OAuthConstants.OAUTH_PKCE_CODE_CHALLENGE_METHOD); // Validate PKCE parameters if (isPKCESupportEnabled) { // Check if PKCE is mandatory for the application if (clientDTO.isPkceMandatory()) { if (pkceChallengeCode == null || !OAuth2Util.validatePKCECodeChallenge(pkceChallengeCode, pkceChallengeMethod)) { return EndpointUtil.getErrorPageURL( OAuth2ErrorCodes.INVALID_REQUEST, "PKCE is mandatory for this application. " + "PKCE Challenge is not provided " + "or is not upto RFC 7636 specification.", null); } } //Check if the code challenge method value is neither "plain" or "s256", if so return error if (pkceChallengeCode != null && pkceChallengeMethod != null) { if (!OAuthConstants.OAUTH_PKCE_PLAIN_CHALLENGE.equals(pkceChallengeMethod) && !OAuthConstants.OAUTH_PKCE_S256_CHALLENGE.equals(pkceChallengeMethod)) { return EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, "Unsupported PKCE Challenge Method", null); } } // Check if "plain" transformation algorithm is disabled for the application if (pkceChallengeCode != null && !clientDTO.isPkceSupportPlain()) { if (pkceChallengeMethod == null || OAuthConstants.OAUTH_PKCE_PLAIN_CHALLENGE.equals(pkceChallengeMethod)) { return EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, "This application does not " + "support \"plain\" transformation algorithm.", null); } } // If PKCE challenge code was sent, check if the code challenge is upto specifications if (pkceChallengeCode != null && !OAuth2Util.validatePKCECodeChallenge(pkceChallengeCode, pkceChallengeMethod)) { return EndpointUtil.getErrorPageURL(OAuth2ErrorCodes.INVALID_REQUEST, "Code challenge used is not up to " + "RFC 7636 specifications.", null); } } params.setPkceCodeChallenge(pkceChallengeCode); params.setPkceCodeChallengeMethod(pkceChallengeMethod); // OpenID Connect specific request parameters params.setNonce(oauthRequest.getParam(OAuthConstants.OAuth20Params.NONCE)); params.setDisplay(oauthRequest.getParam(OAuthConstants.OAuth20Params.DISPLAY)); params.setIDTokenHint(oauthRequest.getParam(OAuthConstants.OAuth20Params.ID_TOKEN_HINT)); params.setLoginHint(oauthRequest.getParam(OAuthConstants.OAuth20Params.LOGIN_HINT)); if (StringUtils.isNotEmpty(oauthRequest.getParam(MultitenantConstants.TENANT_DOMAIN))) { params.setTenantDomain(oauthRequest.getParam(MultitenantConstants.TENANT_DOMAIN)); } else { params.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); } if (StringUtils.isNotBlank(oauthRequest.getParam("acr_values")) && !"null".equals(oauthRequest.getParam("acr_values"))) { String[] acrValues = oauthRequest.getParam("acr_values").split(" "); LinkedHashSet list = new LinkedHashSet(); for (String acrValue : acrValues) { list.add(acrValue); } params.setACRValues(list); } if (StringUtils.isNotBlank(oauthRequest.getParam("claims"))) { params.setEssentialClaims(oauthRequest.getParam("claims")); } String prompt = oauthRequest.getParam(OAuthConstants.OAuth20Params.PROMPT); params.setPrompt(prompt); /** * The prompt parameter can be used by the Client to make sure * that the End-User is still present for the current session or * to bring attention to the request. If this parameter contains * none with any other value, an error is returned * * http://openid.net/specs/openid-connect-messages- * 1_0-14.html#anchor6 * * prompt : none * The Authorization Server MUST NOT display any authentication or * consent user interface pages. An error is returned if the * End-User is not already authenticated or the Client does not have * pre-configured consent for the requested scopes. This can be used * as a method to check for existing authentication and/or consent. * * prompt : login * The Authorization Server MUST prompt the End-User for * reauthentication. * * Error : login_required * The Authorization Server requires End-User authentication. This * error MAY be returned when the prompt parameter in the * Authorization Request is set to none to request that the * Authorization Server should not display any user interfaces to * the End-User, but the Authorization Request cannot be completed * without displaying a user interface for user authentication. * */ boolean forceAuthenticate = false; boolean checkAuthentication = false; // prompt values = {none, login, consent, select_profile} String[] arrPrompt = new String[] { OAuthConstants.Prompt.NONE, OAuthConstants.Prompt.LOGIN, OAuthConstants.Prompt.CONSENT, OAuthConstants.Prompt.SELECT_ACCOUNT }; List lstPrompt = Arrays.asList(arrPrompt); boolean contains_none = (OAuthConstants.Prompt.NONE).equals(prompt); String[] prompts; if (StringUtils.isNotBlank(prompt)) { prompts = prompt.trim().split("\\s"); List lstPrompts = Arrays.asList(prompts); if (!CollectionUtils.containsAny(lstPrompts, lstPrompt)) { if (log.isDebugEnabled()) { log.debug("Invalid prompt variables passed with the authorization request" + prompt); } OAuthProblemException ex = OAuthProblemException.error(OAuth2ErrorCodes.INVALID_REQUEST, "Invalid prompt variables passed with the authorization request"); return EndpointUtil.getErrorRedirectURL(ex, params); } if (prompts.length > 1) { if (lstPrompts.contains(OAuthConstants.Prompt.NONE)) { if (log.isDebugEnabled()) { log.debug( "Invalid prompt variable combination. The value 'none' cannot be used with others " + "prompts. Prompt: " + prompt); } OAuthProblemException ex = OAuthProblemException.error(OAuth2ErrorCodes.INVALID_REQUEST, "Invalid prompt variable combination. The value \'none\' cannot be used with others prompts."); return EndpointUtil.getErrorRedirectURL(ex, params); } else if (lstPrompts.contains(OAuthConstants.Prompt.LOGIN) && (lstPrompts.contains(OAuthConstants.Prompt.CONSENT))) { forceAuthenticate = true; checkAuthentication = false; } } else { if ((OAuthConstants.Prompt.LOGIN).equals(prompt)) { // prompt for authentication checkAuthentication = false; forceAuthenticate = true; } else if (contains_none) { checkAuthentication = true; forceAuthenticate = false; } else if ((OAuthConstants.Prompt.CONSENT).equals(prompt)) { checkAuthentication = false; forceAuthenticate = false; } } } String sessionDataKey = UUIDGenerator.generateUUID(); SessionDataCacheKey cacheKey = new SessionDataCacheKey(sessionDataKey); SessionDataCacheEntry sessionDataCacheEntryNew = new SessionDataCacheEntry(); sessionDataCacheEntryNew.setoAuth2Parameters(params); sessionDataCacheEntryNew.setQueryString(req.getQueryString()); if (req.getParameterMap() != null) { sessionDataCacheEntryNew.setParamMap(new ConcurrentHashMap<String, String[]>(req.getParameterMap())); } SessionDataCache.getInstance().addToCache(cacheKey, sessionDataCacheEntryNew); try { req.setAttribute(FrameworkConstants.RequestParams.FLOW_STATUS, AuthenticatorFlowStatus.SUCCESS_COMPLETED); req.setAttribute(FrameworkConstants.SESSION_DATA_KEY, sessionDataKey); return EndpointUtil.getLoginPageURL(clientId, sessionDataKey, forceAuthenticate, checkAuthentication, oauthRequest.getScopes(), req.getParameterMap()); } catch (IdentityOAuth2Exception e) { if (log.isDebugEnabled()) { log.debug("Error while retrieving the login page url.", e); } throw new OAuthSystemException("Error when encoding login page URL"); } }
From source file:org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.java
private AddOnChangesResult calculateChanges(Set<AddOn> selectedAddOns, boolean updating) { Set<AddOn> oldVersions = new HashSet<>(); Set<AddOn> uninstalls = new HashSet<>(); Set<AddOn> newVersions = new HashSet<>(); Set<AddOn> installs = new HashSet<>(); if (updating) { for (AddOn update : selectedAddOns) { AddOn oldVersion = installedAddOns.getAddOn(update.getId()); oldVersions.add(oldVersion); }/*from w ww. ja v a2 s.com*/ } boolean newerJavaVersion = false; for (AddOn addOn : selectedAddOns) { newerJavaVersion |= addDependencies(addOn, selectedAddOns, oldVersions, newVersions, installs); } Set<AddOn> remainingInstalledAddOns = new HashSet<>(); for (AddOn addOn : installedAddOns.getAddOns()) { if (!contains(selectedAddOns, addOn) && !contains(newVersions, addOn)) { remainingInstalledAddOns.add(addOn); } } Set<AddOn> expectedInstalledAddOns = new HashSet<>(remainingInstalledAddOns); expectedInstalledAddOns.addAll(selectedAddOns); expectedInstalledAddOns.addAll(installs); expectedInstalledAddOns.addAll(newVersions); for (AddOn addOn : remainingInstalledAddOns) { if (addOn.calculateRunRequirements(expectedInstalledAddOns).hasDependencyIssue()) { uninstalls.add(addOn); } } for (Iterator<AddOn> it = uninstalls.iterator(); it.hasNext();) { AddOn addOn = it.next(); AddOn addOnUpdate = availableAddOns.getAddOn(addOn.getId()); if (addOnUpdate != null && !addOnUpdate.equals(addOn)) { it.remove(); oldVersions.add(addOn); newVersions.add(addOnUpdate); newerJavaVersion |= addDependencies(addOnUpdate, selectedAddOns, oldVersions, newVersions, installs); } } for (Iterator<AddOn> it = uninstalls.iterator(); it.hasNext();) { AddOn addOn = it.next(); if (contains(installs, addOn) || contains(newVersions, addOn) || (addOn.calculateRunRequirements(installedAddOns.getAddOns()).hasDependencyIssue() && !containsAny(addOn.getIdsAddOnDependencies(), uninstalls))) { it.remove(); } } if (updating) { newVersions.addAll(selectedAddOns); } else { installs.addAll(selectedAddOns); } expectedInstalledAddOns = new HashSet<>(remainingInstalledAddOns); expectedInstalledAddOns.removeAll(uninstalls); expectedInstalledAddOns.removeAll(oldVersions); expectedInstalledAddOns.addAll(installs); expectedInstalledAddOns.addAll(newVersions); Set<Extension> unloadExtensions = new HashSet<>(); Set<Extension> softUnloadExtensions = new HashSet<>(); Set<AddOn> optionalAddOns = new HashSet<>(); for (AddOn addOn : expectedInstalledAddOns) { List<String> extensionsWithDeps = addOn.getExtensionsWithDeps(); for (Extension extension : addOn.getLoadedExtensionsWithDeps()) { AddOn.AddOnRunRequirements requirements = addOn.calculateExtensionRunRequirements(extension, expectedInstalledAddOns); AddOn.ExtensionRunRequirements extReqs = requirements.getExtensionRequirements().get(0); if (!extReqs.isRunnable()) { unloadExtensions.add(extension); } else if (CollectionUtils.containsAny(extReqs.getDependencies(), oldVersions)) { softUnloadExtensions.add(extension); } extensionsWithDeps.remove(extReqs.getClassname()); } for (String classname : extensionsWithDeps) { AddOn.AddOnRunRequirements requirements = addOn.calculateExtensionRunRequirements(classname, availableAddOns.getAddOns()); AddOn.ExtensionRunRequirements extReqs = requirements.getExtensionRequirements().get(0); if (extReqs.isRunnable()) { optionalAddOns.addAll(extReqs.getDependencies()); } } } optionalAddOns.removeAll(installs); optionalAddOns.removeAll(newVersions); optionalAddOns.removeAll(remainingInstalledAddOns); return new AddOnChangesResult(selectedAddOns, oldVersions, uninstalls, newVersions, installs, newerJavaVersion, optionalAddOns, unloadExtensions, softUnloadExtensions); }
From source file:pl.edu.icm.cermine.metadata.extraction.enhancers.AbstractSimpleEnhancer.java
@Override public void enhanceMetadata(BxDocument document, Element metadata, Set<EnhancedField> enhancedFields) { Set<EnhancedField> fieldsToEnhance = getEnhancedFields(); if (!CollectionUtils.containsAny(enhancedFields, fieldsToEnhance) && enhanceMetadata(document, metadata)) { enhancedFields.addAll(fieldsToEnhance); }// w w w.j a v a2 s . c o m }