List of usage examples for org.apache.commons.collections4 MapUtils isNotEmpty
public static boolean isNotEmpty(final Map<?, ?> map)
From source file:org.craftercms.profile.services.impl.ProfileServiceImpl.java
@Override public Profile updateProfile(final String profileId, final String username, final String password, final String email, final Boolean enabled, final Set<String> roles, final Map<String, Object> attributes, String... attributesToReturn) throws ProfileException { if (StringUtils.isNotEmpty(email) && !EmailUtils.validateEmail(email)) { throw new InvalidEmailAddressException(email); }/*from w w w .j a v a2s . c om*/ Profile profile = updateProfile(profileId, profileUpdater -> { if (StringUtils.isNotEmpty(username)) { profileUpdater.setUsername(username); } if (StringUtils.isNotEmpty(password)) { profileUpdater.setPassword(CryptoUtils.hashPassword(password)); } if (StringUtils.isNotEmpty(email)) { profileUpdater.setEmail(email); } if (enabled != null) { profileUpdater.setEnabled(enabled); } if (roles != null) { profileUpdater.setRoles(roles); } if (MapUtils.isNotEmpty(attributes)) { String tenantName = profileUpdater.getProfile().getTenant(); rejectAttributesIfActionNotAllowed(tenantName, attributes.keySet(), AttributeAction.WRITE_ATTRIBUTE); profileUpdater.addAttributes(attributes); } }, attributesToReturn); logger.debug(LOG_KEY_PROFILE_UPDATED, profile); return profile; }
From source file:org.craftercms.profile.services.impl.ProfileServiceImpl.java
protected Profile filterAttributes(Profile profile, String[] attributesToReturn) { if (ArrayUtils.isNotEmpty(attributesToReturn) && MapUtils.isNotEmpty(profile.getAttributes())) { Iterator<String> keyIter = profile.getAttributes().keySet().iterator(); while (keyIter.hasNext()) { String key = keyIter.next(); if (!ArrayUtils.contains(attributesToReturn, key)) { keyIter.remove();/*from ww w .j a v a 2 s.c o m*/ } } } return profile; }
From source file:org.craftercms.profile.services.impl.ProfileServiceRestClient.java
@Override public Profile createProfile(String tenantName, String username, String password, String email, boolean enabled, Set<String> roles, Map<String, Object> attributes, String verificationUrl) throws ProfileException { MultiValueMap<String, String> params = createBaseParams(); HttpUtils.addValue(PARAM_TENANT_NAME, tenantName, params); HttpUtils.addValue(PARAM_USERNAME, username, params); HttpUtils.addValue(PARAM_PASSWORD, password, params); HttpUtils.addValue(PARAM_EMAIL, email, params); HttpUtils.addValue(PARAM_ENABLED, enabled, params); HttpUtils.addValues(PARAM_ROLE, roles, params); if (MapUtils.isNotEmpty(attributes)) { HttpUtils.addValue(PARAM_ATTRIBUTES, serializeAttributes(attributes), params); }//from w ww.j a va2 s . co m HttpUtils.addValue(PARAM_VERIFICATION_URL, verificationUrl, params); String url = getAbsoluteUrl(BASE_URL_PROFILE + URL_PROFILE_CREATE); return doPostForObject(url, params, Profile.class); }
From source file:org.craftercms.profile.services.impl.ProfileServiceRestClient.java
@Override public Profile updateProfile(String profileId, String username, String password, String email, Boolean enabled, Set<String> roles, Map<String, Object> attributes, String... attributesToReturn) throws ProfileException { MultiValueMap<String, String> params = createBaseParams(); HttpUtils.addValue(PARAM_USERNAME, username, params); HttpUtils.addValue(PARAM_PASSWORD, password, params); HttpUtils.addValue(PARAM_EMAIL, email, params); HttpUtils.addValue(PARAM_ENABLED, enabled, params); // Send empty role to indicate that all roles should be deleted if (roles != null && roles.isEmpty()) { HttpUtils.addValue(PARAM_ROLE, "", params); } else {/*from ww w . j a va2 s . co m*/ HttpUtils.addValues(PARAM_ROLE, roles, params); } if (MapUtils.isNotEmpty(attributes)) { HttpUtils.addValue(PARAM_ATTRIBUTES, serializeAttributes(attributes), params); } HttpUtils.addValues(PARAM_ATTRIBUTE_TO_RETURN, attributesToReturn, params); String url = getAbsoluteUrl(BASE_URL_PROFILE + URL_PROFILE_UPDATE); return doPostForObject(url, params, Profile.class, profileId); }
From source file:org.craftercms.security.processors.impl.UrlAccessRestrictionCheckingProcessor.java
/** * Matches the request URL against the keys of the {@code restriction} map, which are ANT-style path patterns. If * a key matches, the value is interpreted as a Spring EL expression, the expression is executed, and if it returns * true, the processor chain is continued, if not an {@link AccessDeniedException} is thrown. * * @param context the context which holds the current request and response * @param processorChain the processor chain, used to call the next processor *//*w w w . j a v a 2 s. c o m*/ public void processRequest(RequestContext context, RequestSecurityProcessorChain processorChain) throws Exception { Map<String, Expression> urlRestrictions = getUrlRestrictions(); if (MapUtils.isNotEmpty(urlRestrictions)) { HttpServletRequest request = context.getRequest(); String requestUrl = getRequestUrl(context.getRequest()); logger.debug("Checking access restrictions for URL {}", requestUrl); for (Map.Entry<String, Expression> entry : urlRestrictions.entrySet()) { String urlPattern = entry.getKey(); Expression expression = entry.getValue(); if (pathMatcher.match(urlPattern, requestUrl)) { logger.debug("Checking restriction [{} => {}]", requestUrl, expression.getExpressionString()); if (isAccessAllowed(request, expression)) { logger.debug("Restriction [{}' => {}] evaluated to true for user: access allowed", requestUrl, expression.getExpressionString()); break; } else { throw new AccessDeniedException( "Restriction ['" + requestUrl + "' => " + expression.getExpressionString() + "] evaluated to false " + "for user: access denied"); } } } } processorChain.processRequest(context); }
From source file:org.dspace.app.rest.converter.DiscoverResultConverter.java
private void addSearchResults(final DiscoverResult searchResult, final SearchResultsRest resultsRest) { for (DSpaceObject dspaceObject : CollectionUtils.emptyIfNull(searchResult.getDspaceObjects())) { SearchResultEntryRest resultEntry = new SearchResultEntryRest(); //Convert the DSpace Object to its REST model resultEntry.setDspaceObject(convertDSpaceObject(dspaceObject)); //Add hit highlighting for this DSO if present DiscoverResult.DSpaceObjectHighlightResult highlightedResults = searchResult .getHighlightedResults(dspaceObject); if (highlightedResults != null && MapUtils.isNotEmpty(highlightedResults.getHighlightResults())) { for (Map.Entry<String, List<String>> metadataHighlight : highlightedResults.getHighlightResults() .entrySet()) {/* w w w .j a va 2s . c o m*/ resultEntry.addHitHighlights(metadataHighlight.getKey(), metadataHighlight.getValue()); } } resultsRest.addSearchResult(resultEntry); } }
From source file:org.eclipse.sw360.exporter.ReleaseHelper.java
private boolean addAdditionalData() { return MapUtils.isNotEmpty(releaseToShortenedStringsMap); }
From source file:org.esbtools.gateway.resubmit.service.JmsResubmitService.java
private ResubmitResponse enqueue(final ResubmitRequest resubmitRequest) { ResubmitResponse resubmitResponse = new ResubmitResponse(); try {// w ww . j a v a 2 s . co m LOGGER.info("Sending message {}", resubmitRequest.getPayload()); jmsResubmitConfiguration.getBroker().send(resubmitRequest.getDestination(), new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { Message message = session.createTextMessage(resubmitRequest.getPayload()); if (MapUtils.isNotEmpty(resubmitRequest.getHeaders())) { for (Map.Entry<String, String> header : resubmitRequest.getHeaders().entrySet()) { LOGGER.info("Adding header key={}, value{}", header.getKey(), header.getValue()); message.setStringProperty(header.getKey(), header.getValue()); } } return message; } }); resubmitResponse.setStatus(GatewayResponse.Status.Success); } catch (RuntimeException e) { LOGGER.error("An error occurred when enqueuing the resubmit message: {}", resubmitRequest, e); throw new ResubmitFailedException(resubmitRequest); } LOGGER.info("{}", resubmitResponse); return resubmitResponse; }
From source file:org.finra.herd.dao.helper.EmrVpcPricingStateFormatter.java
/** * Formats a EMR VPC pricing state into a human readable string. * //from w w w. j ava 2 s . c o m * @param emrVpcPricingState EMR VPC pricing state * @return Formatted string */ public String format(EmrVpcPricingState emrVpcPricingState) { StringBuilder builder = new StringBuilder(); builder.append(String.format("Subnet IP Availability:%n")); for (Map.Entry<String, Integer> subnet : emrVpcPricingState.getSubnetAvailableIpAddressCounts() .entrySet()) { builder.append(String.format("\t%s=%s%n", subnet.getKey(), subnet.getValue())); } Map<String, Map<String, BigDecimal>> spotPricesPerAvailabilityZone = emrVpcPricingState .getSpotPricesPerAvailabilityZone(); if (MapUtils.isNotEmpty(spotPricesPerAvailabilityZone)) { builder.append(String.format("Spot Prices:%n")); for (Map.Entry<String, Map<String, BigDecimal>> availabilityZone : spotPricesPerAvailabilityZone .entrySet()) { builder.append(String.format("\t%s%n", availabilityZone.getKey())); for (Map.Entry<String, BigDecimal> instanceType : availabilityZone.getValue().entrySet()) { builder.append(String.format("\t\t%s=$%s%n", instanceType.getKey(), instanceType.getValue())); } } } Map<String, Map<String, BigDecimal>> onDemandPricesPerAvailabilityZone = emrVpcPricingState .getOnDemandPricesPerAvailabilityZone(); if (MapUtils.isNotEmpty(onDemandPricesPerAvailabilityZone)) { builder.append(String.format("On-Demand Prices:%n")); for (Map.Entry<String, Map<String, BigDecimal>> availabilityZone : onDemandPricesPerAvailabilityZone .entrySet()) { builder.append(String.format("\t%s%n", availabilityZone.getKey())); for (Map.Entry<String, BigDecimal> instanceType : availabilityZone.getValue().entrySet()) { builder.append(String.format("\t\t%s=$%s%n", instanceType.getKey(), instanceType.getValue())); } } } return builder.toString(); }
From source file:org.finra.herd.dao.impl.IndexSearchDaoImpl.java
/** * Extracts highlighted content from a given {@link SearchHit} * * @param searchHit a given {@link SearchHit} from the elasticsearch results * @param preTag the specified pre-tag for highlighting * @param postTag the specified post-tag for highlighting * * @return {@link Highlight} a cleaned highlighted content *///from w w w . ja v a2s .c om private Highlight extractHighlightedContent(SearchResult.Hit<Map, Void> searchHit, String preTag, String postTag) { Highlight highlightedContent = new Highlight(); List<Field> highlightFields = new ArrayList<>(); // make sure there is highlighted content in the search hit if (MapUtils.isNotEmpty(searchHit.highlight)) { Set<String> keySet = searchHit.highlight.keySet(); for (String key : keySet) { Field field = new Field(); // Extract the field-name field.setFieldName(key); List<String> cleanFragments = new ArrayList<>(); // Extract fragments which have the highlighted content List<String> fragments = searchHit.highlight.get(key); for (String fragment : fragments) { cleanFragments.add(HerdStringUtils.stripHtml(fragment, preTag, postTag)); } field.setFragments(cleanFragments); highlightFields.add(field); } } highlightedContent.setFields(highlightFields); return highlightedContent; }