Java Code Examples for org.apache.commons.collections.MapUtils#isNotEmpty()
The following examples show how to use
org.apache.commons.collections.MapUtils#isNotEmpty() .
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: EntityREST.java From atlas with Apache License 2.0 | 6 votes |
private Map<String, Object> getAttributes(HttpServletRequest request) { Map<String, Object> attributes = new HashMap<>(); if (MapUtils.isNotEmpty(request.getParameterMap())) { for (Map.Entry<String, String[]> e : request.getParameterMap().entrySet()) { String key = e.getKey(); if (key != null && key.startsWith(PREFIX_ATTR)) { String[] values = e.getValue(); String value = values != null && values.length > 0 ? values[0] : null; attributes.put(key.substring(PREFIX_ATTR.length()), value); } } } return attributes; }
Example 2
Source File: VoFulfilmentServiceImpl.java From yes-cart with Apache License 2.0 | 6 votes |
@Override public void fillShopSummaryDetails(final VoShopSummary summary, final long shopId, final String lang) throws Exception { if (federationFacade.isShopAccessibleByCurrentManager(summary.getShopId())) { final Map<WarehouseDTO, Boolean> all = dtoWarehouseService.findAllByShopId(shopId); for (final Map.Entry<WarehouseDTO, Boolean> dto : all.entrySet()) { String name = dto.getKey().getName(); if (MapUtils.isNotEmpty(dto.getKey().getDisplayNames()) && dto.getKey().getDisplayNames().get(lang) != null) { name = dto.getKey().getDisplayNames().get(lang); } summary.getFulfilmentCentres().add(MutablePair.of(name, dto.getValue())); } } else { throw new AccessDeniedException("Access is denied"); } }
Example 3
Source File: AtlasNotificationMapper.java From ranger with Apache License 2.0 | 6 votes |
static private List<RangerTagDef> getTagDefs(RangerAtlasEntityWithTags entityWithTags) { List<RangerTagDef> ret = new ArrayList<>(); if (entityWithTags != null && CollectionUtils.isNotEmpty(entityWithTags.getTags())) { Map<String, String> tagNames = new HashMap<>(); for (EntityNotificationWrapper.RangerAtlasClassification tag : entityWithTags.getTags()) { if (!tagNames.containsKey(tag.getName())) { tagNames.put(tag.getName(), tag.getName()); RangerTagDef tagDef = new RangerTagDef(tag.getName(), "Atlas"); if (MapUtils.isNotEmpty(tag.getAttributes())) { for (String attributeName : tag.getAttributes().keySet()) { tagDef.getAttributeDefs().add(new RangerTagAttributeDef(attributeName, entityWithTags.getTagAttributeType(tag.getName(), attributeName))); } } ret.add(tagDef); } } } return ret; }
Example 4
Source File: ProducerManager.java From DDMQ with Apache License 2.0 | 6 votes |
public void initProducer() throws Exception { if (configManager.getCarreraConfig().isUseKafka() && MapUtils.isNotEmpty(configManager.getCarreraConfig().getKafkaConfigurationMap())) { // Kafka for (Map.Entry<String, KafkaConfiguration> kafkaConfig : configManager.getCarreraConfig().getKafkaConfigurationMap().entrySet()) { ClusterProducer kafkaProducer = new KafkaClusterProducer(configManager, kafkaConfig.getKey()); kafkaProducer.initProducer(); producersOfCluster.put(kafkaConfig.getKey(), kafkaProducer); } } if (configManager.getCarreraConfig().isUseRocketmq() && MapUtils.isNotEmpty(configManager.getCarreraConfig().getRocketmqConfigurationMap())) { // RocketMQ for (Map.Entry<String, RocketmqConfiguration> rmqConfig : configManager.getCarreraConfig().getRocketmqConfigurationMap().entrySet()) { ClusterProducer rmqProducer = new RmqClusterProducer(configManager, rmqConfig.getKey()); rmqProducer.initProducer(); producersOfCluster.put(rmqConfig.getKey(), rmqProducer); } } }
Example 5
Source File: AtlasStruct.java From atlas with Apache License 2.0 | 6 votes |
public static StringBuilder dumpObjects(Map<?, ?> objects, StringBuilder sb) { if (sb == null) { sb = new StringBuilder(); } if (MapUtils.isNotEmpty(objects)) { int i = 0; for (Map.Entry<?, ?> e : objects.entrySet()) { if (i > 0) { sb.append(", "); } sb.append(e.getKey()).append(":").append(e.getValue()); i++; } } return sb; }
Example 6
Source File: AtlasObjectIdConverter.java From atlas with Apache License 2.0 | 6 votes |
private boolean hasAnyAssignedAttribute(org.apache.atlas.v1.model.instance.Referenceable rInstance) { boolean ret = false; Map<String, Object> attributes = rInstance.getValues(); if (MapUtils.isNotEmpty(attributes)) { for (Map.Entry<String, Object> attribute : attributes.entrySet()) { if (attribute.getValue() != null) { ret = true; break; } } } return ret; }
Example 7
Source File: AtlasTypeUtil.java From atlas with Apache License 2.0 | 6 votes |
public static AtlasObjectId getAtlasObjectId(AtlasEntity entity, AtlasTypeRegistry typeRegistry) { String typeName = entity.getTypeName(); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); Map<String, Object> uniqAttributes = null; if (entityType != null && MapUtils.isNotEmpty(entityType.getUniqAttributes())) { for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) { Object attrValue = entity.getAttribute(attribute.getName()); if (attrValue != null) { if (uniqAttributes == null) { uniqAttributes = new HashMap<>(); } uniqAttributes.put(attribute.getName(), attrValue); } } } return new AtlasObjectId(entity.getGuid(), typeName, uniqAttributes); }
Example 8
Source File: KeyCloakServiceImpl.java From sunbird-lms-service with MIT License | 6 votes |
@Override public String getEmailVerifiedUpdatedFlag(String userId) { String fedUserId = getFederatedUserId(userId); UserResource resource = keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(fedUserId); UserRepresentation user = resource.toRepresentation(); Map<String, List<String>> map = user.getAttributes(); List<String> list = null; if (MapUtils.isNotEmpty(map)) { list = map.get(JsonKey.EMAIL_VERIFIED_UPDATED); } if (CollectionUtils.isNotEmpty(list)) { return list.get(0); } else { return ""; } }
Example 9
Source File: ServiceREST.java From ranger with Apache License 2.0 | 6 votes |
private void patchAssociatedTagServiceInSecurityZoneInfos(ServicePolicies servicePolicies) { if (servicePolicies != null && MapUtils.isNotEmpty(servicePolicies.getSecurityZones())) { // Get list of zones that associated tag-service (if any) is associated with List<String> zonesInAssociatedTagService = new ArrayList<>(); String tagServiceName = servicePolicies.getTagPolicies() != null ? servicePolicies.getTagPolicies().getServiceName() : null; if (StringUtils.isNotEmpty(tagServiceName)) { try { RangerService tagService = svcStore.getServiceByName(tagServiceName); if (tagService != null && tagService.getIsEnabled()) { zonesInAssociatedTagService = daoManager.getXXSecurityZoneDao().findZonesByTagServiceName(tagServiceName); } } catch (Exception exception) { LOG.warn("Could not get service associated with [" + tagServiceName + "]", exception); } } if (CollectionUtils.isNotEmpty(zonesInAssociatedTagService)) { for (Map.Entry<String, ServicePolicies.SecurityZoneInfo> entry : servicePolicies.getSecurityZones().entrySet()) { String zoneName = entry.getKey(); ServicePolicies.SecurityZoneInfo securityZoneInfo = entry.getValue(); securityZoneInfo.setContainsAssociatedTagService(zonesInAssociatedTagService.contains(zoneName)); } } } }
Example 10
Source File: HelpPrinter.java From FortifyBugTrackerUtility with MIT License | 6 votes |
public HelpPrinter build(int indent) { if ( MapUtils.isNotEmpty(map) ) { int maxKeyLength = map.keySet().stream().max(Comparator.comparingInt(String::length)).get().length(); for ( Map.Entry<String, String[]> entry : map.entrySet() ) { int newIndent = indent; String key = entry.getKey(); for ( String value : entry.getValue() ) { if ( newIndent==indent ) { hp.append(indent, StringUtils.rightPad(key+": ", maxKeyLength+2)+value); newIndent = indent+maxKeyLength+2; } else { hp.append(newIndent, value); } } } } return hp; }
Example 11
Source File: FeedServiceImpl.java From sunbird-lms-service with MIT License | 6 votes |
@Override public Response update(Feed feed) { ProjectLogger.log("FeedServiceImpl:update method called : ", LoggerEnum.INFO.name()); Map<String, Object> feedData = feed.getData(); Map<String, Object> dbMap = mapper.convertValue(feed, Map.class); try { if (MapUtils.isNotEmpty(feed.getData())) { dbMap.put(JsonKey.FEED_DATA, mapper.writeValueAsString(feed.getData())); } } catch (Exception ex) { ProjectLogger.log("FeedServiceImpl:update Exception occurred while mapping.", ex); } dbMap.remove(JsonKey.CREATED_ON); dbMap.put(JsonKey.UPDATED_ON, new Timestamp(Calendar.getInstance().getTimeInMillis())); Response response = saveFeed(dbMap); // update data to ES dbMap.put(JsonKey.FEED_DATA, feedData); dbMap.put(JsonKey.UPDATED_ON, Calendar.getInstance().getTimeInMillis()); getESInstance().update(ProjectUtil.EsType.userfeed.getTypeName(), feed.getId(), dbMap); return response; }
Example 12
Source File: RangerDefaultPolicyResourceMatcher.java From ranger with Apache License 2.0 | 5 votes |
@Override public boolean isMatch(RangerAccessResource resource, Map<String, Object> evalContext) { RangerPerfTracer perf = null; if(RangerPerfTracer.isPerfTraceEnabled(PERF_POLICY_RESOURCE_MATCHER_MATCH_LOG)) { perf = RangerPerfTracer.getPerfTracer(PERF_POLICY_RESOURCE_MATCHER_MATCH_LOG, "RangerDefaultPolicyResourceMatcher.grantRevokeMatch()"); } /* * There is already API to get the delegateAdmin permissions for a map of policyResources. * That implementation should be reused for figuring out delegateAdmin permissions for a resource as well. */ Map<String, RangerPolicyResource> policyResources = null; for (RangerResourceDef resourceDef : serviceDef.getResources()) { String resourceName = resourceDef.getName(); Object resourceValue = resource.getValue(resourceName); if (resourceValue instanceof String) { String strValue = (String) resourceValue; if (policyResources == null) { policyResources = new HashMap<>(); } policyResources.put(resourceName, new RangerPolicyResource(strValue)); } else if (resourceValue != null) { // return false for any other type of resourceValue policyResources = null; break; } } final boolean ret = MapUtils.isNotEmpty(policyResources) && isMatch(policyResources, evalContext); RangerPerfTracer.log(perf); return ret; }
Example 13
Source File: RunProcessRunnerFromSpringConfig.java From FortifyBugTrackerUtility with MIT License | 5 votes |
/** * Update default values for CLI options based on the cliOptionsDefaultValuesFromConfig bean. * @param optionDefinitions */ private void updateCLIOptionDefinitionsDefaultValues(CLIOptionDefinitions optionDefinitions) { Context cliOptionsDefaultValuesFromConfig = getCLIOptionsDefaultValuesFromConfig(); if ( MapUtils.isNotEmpty(cliOptionsDefaultValuesFromConfig) ) { for ( Map.Entry<String, Object> entry : cliOptionsDefaultValuesFromConfig.entrySet() ) { CLIOptionDefinition def = optionDefinitions.getCLIOptionDefinitionByName(entry.getKey()); if ( def != null ) { def.defaultValue((String)entry.getValue()); } } } }
Example 14
Source File: KeyUtil.java From framework with Apache License 2.0 | 5 votes |
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param template * @param method * @param args * @return String * @throws FrameworkException <br> */ public static String getLockKey(final String template, final Method method, final Object[] args) throws FrameworkException { if (CommonUtil.isNotEmpty(args)) { Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Map<String, Object> paramMap = new TreeMap<String, Object>(); for (int i = 0; i < parameterAnnotations.length; i++) { for (Annotation annotation : parameterAnnotations[i]) { if (annotation instanceof Key) { paramMap.put(((Key) annotation).value(), args[i]); break; } } } if (MapUtils.isNotEmpty(paramMap)) { StringBuilder sb = new StringBuilder(); if (StringUtils.isNotEmpty(template)) { sb.append(GlobalConstants.UNDERLINE) .append(VelocityParseFactory.parse(CommonUtil.getTransactionID(), template, paramMap)); } else { for (Entry<String, Object> entry : paramMap.entrySet()) { sb.append(GlobalConstants.UNDERLINE) .append(entry.getValue() == null ? GlobalConstants.BLANK : entry.getValue()); } } return sb.toString(); } } return GlobalConstants.BLANK; }
Example 15
Source File: RangerAuthContext.java From ranger with Apache License 2.0 | 5 votes |
public Set<String> getRolesForUserAndGroups(String user, Set<String> groups) { RangerRolesUtil rolesUtil = this.rolesUtil; Map<String, Set<String>> userRoleMapping = rolesUtil.getUserRoleMapping(); Map<String, Set<String>> groupRoleMapping = rolesUtil.getGroupRoleMapping(); Set<String> allRoles = new HashSet<>(); if (MapUtils.isNotEmpty(userRoleMapping) && StringUtils.isNotEmpty(user)) { Set<String> userRoles = userRoleMapping.get(user); if (CollectionUtils.isNotEmpty(userRoles)) { allRoles.addAll(userRoles); } } if (MapUtils.isNotEmpty(groupRoleMapping)) { if (CollectionUtils.isNotEmpty(groups)) { for (String group : groups) { Set<String> groupRoles = groupRoleMapping.get(group); if (CollectionUtils.isNotEmpty(groupRoles)) { allRoles.addAll(groupRoles); } } } Set<String> publicGroupRoles = groupRoleMapping.get(RangerPolicyEngine.GROUP_PUBLIC); if (CollectionUtils.isNotEmpty(publicGroupRoles)) { allRoles.addAll(publicGroupRoles); } } return allRoles; }
Example 16
Source File: AtlasStructFormatConverter.java From incubator-atlas with Apache License 2.0 | 5 votes |
protected Map<String, Object> fromV2ToV1(AtlasStructType structType, Map<String, Object> attributes, ConverterContext context) throws AtlasBaseException { Map<String, Object> ret = null; if (MapUtils.isNotEmpty(attributes)) { ret = new HashMap<>(); // Only process the requested/set attributes for (String attrName : attributes.keySet()) { AtlasAttribute attr = structType.getAttribute(attrName); if (attr == null) { LOG.warn("ignored unknown attribute {}.{}", structType.getTypeName(), attrName); continue; } AtlasType attrType = attr.getAttributeType(); Object v2Value = attributes.get(attr.getName()); Object v1Value; AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory()); v1Value = attrConverter.fromV2ToV1(v2Value, attrType, context); ret.put(attr.getName(), v1Value); } } return ret; }
Example 17
Source File: AtlasInstanceConverter.java From atlas with Apache License 2.0 | 4 votes |
public CreateUpdateEntitiesResult toCreateUpdateEntitiesResult(EntityMutationResponse reponse) { CreateUpdateEntitiesResult ret = null; if (reponse != null) { Map<EntityOperation, List<AtlasEntityHeader>> mutatedEntities = reponse.getMutatedEntities(); Map<String, String> guidAssignments = reponse.getGuidAssignments(); ret = new CreateUpdateEntitiesResult(); if (MapUtils.isNotEmpty(guidAssignments)) { ret.setGuidMapping(new GuidMapping(guidAssignments)); } if (MapUtils.isNotEmpty(mutatedEntities)) { EntityResult entityResult = new EntityResult(); for (Map.Entry<EntityOperation, List<AtlasEntityHeader>> e : mutatedEntities.entrySet()) { switch (e.getKey()) { case CREATE: List<AtlasEntityHeader> createdEntities = mutatedEntities.get(EntityOperation.CREATE); if (CollectionUtils.isNotEmpty(createdEntities)) { Collections.reverse(createdEntities); entityResult.set(EntityResult.OP_CREATED, getGuids(createdEntities)); } break; case UPDATE: List<AtlasEntityHeader> updatedEntities = mutatedEntities.get(EntityOperation.UPDATE); if (CollectionUtils.isNotEmpty(updatedEntities)) { Collections.reverse(updatedEntities); entityResult.set(EntityResult.OP_UPDATED, getGuids(updatedEntities)); } break; case PARTIAL_UPDATE: List<AtlasEntityHeader> partialUpdatedEntities = mutatedEntities.get(EntityOperation.PARTIAL_UPDATE); if (CollectionUtils.isNotEmpty(partialUpdatedEntities)) { Collections.reverse(partialUpdatedEntities); entityResult.set(EntityResult.OP_UPDATED, getGuids(partialUpdatedEntities)); } break; case DELETE: List<AtlasEntityHeader> deletedEntities = mutatedEntities.get(EntityOperation.DELETE); if (CollectionUtils.isNotEmpty(deletedEntities)) { Collections.reverse(deletedEntities); entityResult.set(EntityResult.OP_DELETED, getGuids(deletedEntities)); } break; } } ret.setEntityResult(entityResult); } } return ret; }
Example 18
Source File: ClaimUtil.java From carbon-identity with Apache License 2.0 | 4 votes |
public static Map<String, Object> getClaimsFromUserStore(OAuth2TokenValidationResponseDTO tokenResponse) throws UserInfoEndpointException { String username = tokenResponse.getAuthorizedUser(); String tenantDomain = MultitenantUtils.getTenantDomain(tokenResponse.getAuthorizedUser()); UserRealm realm; List<String> claimURIList = new ArrayList<>(); Map<String, Object> mappedAppClaims = new HashMap<>(); try { realm = IdentityTenantUtil.getRealm(tenantDomain, username); if (realm == null) { log.warn("No valid tenant domain provider. Empty claim returned back"); return new HashMap<>(); } Map<String, String> spToLocalClaimMappings; UserStoreManager userstore = realm.getUserStoreManager(); // need to get all the requested claims Map<String, String> requestedLocalClaimMap = ClaimManagerHandler.getInstance() .getMappingsMapFromOtherDialectToCarbon(SP_DIALECT, null, tenantDomain, true); if (MapUtils.isNotEmpty(requestedLocalClaimMap)) { for (String s : requestedLocalClaimMap.keySet()) { claimURIList.add(s); } if (log.isDebugEnabled()) { log.debug("Requested number of local claims: " + claimURIList.size()); } spToLocalClaimMappings = ClaimManagerHandler.getInstance().getMappingsMapFromOtherDialectToCarbon (SP_DIALECT, null, tenantDomain, false); Map<String, String> userClaims = userstore.getUserClaimValues(MultitenantUtils.getTenantAwareUsername (username), claimURIList.toArray(new String[claimURIList.size()]), null); if (log.isDebugEnabled()) { log.debug("User claims retrieved from user store: " + userClaims.size()); } if (MapUtils.isEmpty(userClaims)) { return new HashMap<>(); } for (Map.Entry<String, String> entry : spToLocalClaimMappings.entrySet()) { String value = userClaims.get(entry.getValue()); if (value != null) { mappedAppClaims.put(entry.getKey(), value); if (log.isDebugEnabled() && IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) { log.debug("Mapped claim: key - " + entry.getKey() + " value -" + value); } } } } } catch (Exception e) { if(e instanceof UserStoreException){ if (e.getMessage().contains("UserNotFound")) { if (log.isDebugEnabled()) { log.debug("User " + username + " not found in user store"); } } } else { log.error("Error while retrieving the claims from user store for " + username, e); throw new UserInfoEndpointException("Error while retrieving the claims from user store for " + username); } } return mappedAppClaims; }
Example 19
Source File: AtlasEntityStoreV1Test.java From incubator-atlas with Apache License 2.0 | 4 votes |
private void validateAttribute(AtlasEntityExtInfo entityExtInfo, Object actual, Object expected, AtlasType attributeType, String attrName) throws AtlasBaseException, AtlasException { switch(attributeType.getTypeCategory()) { case OBJECT_ID_TYPE: Assert.assertTrue(actual instanceof AtlasObjectId); String guid = ((AtlasObjectId) actual).getGuid(); Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(guid), "expected assigned guid. found " + guid); break; case PRIMITIVE: case ENUM: Assert.assertEquals(actual, expected); break; case MAP: AtlasMapType mapType = (AtlasMapType) attributeType; AtlasType valueType = mapType.getValueType(); Map actualMap = (Map) actual; Map expectedMap = (Map) expected; if (MapUtils.isNotEmpty(expectedMap)) { Assert.assertTrue(MapUtils.isNotEmpty(actualMap)); // deleted entries are included in the attribute; hence use >= Assert.assertTrue(actualMap.size() >= expectedMap.size()); for (Object key : expectedMap.keySet()) { validateAttribute(entityExtInfo, actualMap.get(key), expectedMap.get(key), valueType, attrName); } } break; case ARRAY: AtlasArrayType arrType = (AtlasArrayType) attributeType; AtlasType elemType = arrType.getElementType(); List actualList = (List) actual; List expectedList = (List) expected; if (CollectionUtils.isNotEmpty(expectedList)) { Assert.assertTrue(CollectionUtils.isNotEmpty(actualList)); //actual list could have deleted entities. Hence size may not match. Assert.assertTrue(actualList.size() >= expectedList.size()); for (int i = 0; i < expectedList.size(); i++) { validateAttribute(entityExtInfo, actualList.get(i), expectedList.get(i), elemType, attrName); } } break; case STRUCT: AtlasStruct expectedStruct = (AtlasStruct) expected; AtlasStruct actualStruct = (AtlasStruct) actual; validateEntity(entityExtInfo, actualStruct, expectedStruct); break; default: Assert.fail("Unknown type category"); } }
Example 20
Source File: ConsumeSubscriptionBaseBo.java From DDMQ with Apache License 2.0 | 4 votes |
private boolean containsFormHttpIgnoreJson() { return MapUtils.isNotEmpty(this.getExtraParams()) && "true".equalsIgnoreCase(this.getExtraParams().get(SUB_FLAG_ACTION_FORMPARAMS_HTTP_IGNORE_JSON)); }