List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty
public static boolean isNotEmpty(final Collection<?> coll)
From source file:org.finra.herd.service.impl.BusinessObjectDataStorageUnitServiceImpl.java
/** * Validates the business object definition column create request. This method also trims the request parameters. * * @param request the business object data storage unit create request *//* w w w.ja va2 s .com*/ protected void validateBusinessObjectDataStorageUnitCreateRequest( BusinessObjectDataStorageUnitCreateRequest request) { Assert.notNull(request, "A business object data storage unit create request must be specified."); storageUnitHelper.validateBusinessObjectDataStorageUnitKey(request.getBusinessObjectDataStorageUnitKey()); if (BooleanUtils.isTrue(request.isDiscoverStorageFiles())) { // The auto-discovery of storage files is enabled, thus a storage directory is required and storage files cannot be specified. Assert.isTrue(request.getStorageDirectory() != null, "A storage directory must be specified when discovery of storage files is enabled."); Assert.isTrue(CollectionUtils.isEmpty(request.getStorageFiles()), "Storage files cannot be specified when discovery of storage files is enabled."); } else { // Since auto-discovery is disabled, a storage directory or at least one storage file are required for each storage unit. Assert.isTrue( request.getStorageDirectory() != null || CollectionUtils.isNotEmpty(request.getStorageFiles()), "A storage directory or at least one storage file must be specified when discovery of storage files is not enabled."); } // If storageDirectory element is present in the request, we require it to contain a non-empty directoryPath element. if (request.getStorageDirectory() != null) { Assert.hasText(request.getStorageDirectory().getDirectoryPath(), "A storage directory path must be specified."); request.getStorageDirectory().setDirectoryPath(request.getStorageDirectory().getDirectoryPath().trim()); } // Validate a list of storage files, if specified. if (CollectionUtils.isNotEmpty(request.getStorageFiles())) { storageFileHelper.validateCreateRequestStorageFiles(request.getStorageFiles()); } }
From source file:org.finra.herd.service.impl.BusinessObjectDefinitionColumnServiceImpl.java
/** * Creates a business object definition column from the persisted entity. * * @param businessObjectDefinitionColumnEntity the business object definition column entity * @param includeId boolean value indicating whether or not to include the id * @param fields set of field parameters to include on the business object definition column * * @return the business object definition column *//* w ww. j a v a 2 s. c o m*/ private BusinessObjectDefinitionColumn createBusinessObjectDefinitionColumnFromEntity( BusinessObjectDefinitionColumnEntity businessObjectDefinitionColumnEntity, boolean includeId, Set<String> fields, Boolean includeBusinessObjectDefinitionColumnUpdateHistory) { BusinessObjectDefinitionColumn businessObjectDefinitionColumn = new BusinessObjectDefinitionColumn(); if (includeId) { businessObjectDefinitionColumn.setId(businessObjectDefinitionColumnEntity.getId()); } businessObjectDefinitionColumn.setBusinessObjectDefinitionColumnKey( getBusinessObjectDefinitionColumnKey(businessObjectDefinitionColumnEntity)); if (fields.contains(DESCRIPTION_FIELD)) { businessObjectDefinitionColumn.setDescription(businessObjectDefinitionColumnEntity.getDescription()); } if (fields.contains(SCHEMA_COLUMN_NAME_FIELD) && CollectionUtils.isNotEmpty(businessObjectDefinitionColumnEntity.getSchemaColumns())) { businessObjectDefinitionColumn.setSchemaColumnName( IterableUtils.get(businessObjectDefinitionColumnEntity.getSchemaColumns(), 0).getName()); } // Add change events. final List<BusinessObjectDefinitionColumnChangeEvent> businessObjectDefinitionColumnChangeEvents = Lists .newArrayList(); if (BooleanUtils.isTrue(includeBusinessObjectDefinitionColumnUpdateHistory)) { businessObjectDefinitionColumnEntity.getChangeEvents().forEach( businessObjectDefinitionColumnChangeEventEntity -> businessObjectDefinitionColumnChangeEvents .add(new BusinessObjectDefinitionColumnChangeEvent( businessObjectDefinitionColumnChangeEventEntity.getDescription(), HerdDateUtils.getXMLGregorianCalendarValue( businessObjectDefinitionColumnChangeEventEntity.getCreatedOn()), businessObjectDefinitionColumnChangeEventEntity.getCreatedBy()))); } businessObjectDefinitionColumn .setBusinessObjectDefinitionColumnChangeEvents(businessObjectDefinitionColumnChangeEvents); return businessObjectDefinitionColumn; }
From source file:org.finra.herd.service.impl.Ec2OnDemandPricingUpdateServiceImpl.java
/** * {@inheritDoc}/* ww w .j a va 2 s. co m*/ * <p/> * This implementation executes non-transactionally, suspends the current transaction if one exists. */ @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) public List<Ec2OnDemandPricing> getEc2OnDemandPricing(String ec2PricingListUrl) { // Create a list of EC2 on-demand pricing entries. List<Ec2OnDemandPricing> ec2OnDemandPricingEntries = new ArrayList<>(); // Get JSON object from the specified URL. JSONObject jsonObject = urlHelper.parseJsonObjectFromUrl(ec2PricingListUrl); // Get products from the JSON object. JSONObject products = jsonHelper.getKeyValue(jsonObject, JSON_KEY_NAME_PRODUCTS, JSONObject.class); // Create a set to validate uniqueness of EC2 on-demand pricing keys. Set<Ec2OnDemandPricingKey> uniqueEc2OnDemandPricingKeys = new HashSet<>(); // Process all products. for (Object key : products.keySet()) { JSONObject current = jsonHelper.getKeyValue(products, key, JSONObject.class); String sku = jsonHelper.getKeyValue(current, JSON_KEY_NAME_SKU, String.class); JSONObject attributes = jsonHelper.getKeyValue(current, JSON_KEY_NAME_ATTRIBUTES, JSONObject.class); Object location = attributes.get(JSON_ATTRIBUTE_NAME_LOCATION); Object operatingSystem = attributes.get(JSON_ATTRIBUTE_NAME_OPERATING_SYSTEM); Object instanceType = attributes.get(JSON_ATTRIBUTE_NAME_INSTANCE_TYPE); Object tenancy = attributes.get(JSON_ATTRIBUTE_NAME_TENANCY); Object usageType = attributes.get(JSON_ATTRIBUTE_NAME_USAGE_TYPE); Object preInstalledSoftware = attributes.get(JSON_ATTRIBUTE_NAME_PRE_INSTALLED_SOFTWARE); // Validate the parameters and create an EC2 on-demand pricing entry. Ec2OnDemandPricing ec2OnDemandPricing = createEc2OnDemandPricingEntry(sku, location, operatingSystem, instanceType, tenancy, usageType, preInstalledSoftware); // Check if this EC2 on-demand pricing entry got created (the relative parameters passed validation checks). if (ec2OnDemandPricing != null) { // Get the EC2 on-demand pricing key. Ec2OnDemandPricingKey ec2OnDemandPricingKey = ec2OnDemandPricing.getEc2OnDemandPricingKey(); // Validate that this key is unique. if (!uniqueEc2OnDemandPricingKeys.add(ec2OnDemandPricingKey)) { throw new IllegalArgumentException(String.format( "Found duplicate EC2 on-demand pricing entry for \"%s\" AWS region and \"%s\" EC2 instance type.", ec2OnDemandPricingKey.getRegionName(), ec2OnDemandPricingKey.getInstanceType())); } // Add this EC2 on-demand pricing entry to the result list. ec2OnDemandPricingEntries.add(ec2OnDemandPricing); } } // Continue the processing only when the result list is not empty. if (CollectionUtils.isNotEmpty(ec2OnDemandPricingEntries)) { // Get terms from the JSON object. JSONObject terms = jsonHelper.getKeyValue(jsonObject, JSON_KEY_NAME_TERMS, JSONObject.class); // Get on-demand information from the terms. JSONObject onDemand = jsonHelper.getKeyValue(terms, JSON_KEY_NAME_ON_DEMAND, JSONObject.class); // Populate pricing information. for (Ec2OnDemandPricing ec2OnDemandPricing : ec2OnDemandPricingEntries) { String sku = ec2OnDemandPricing.getSku(); JSONObject current = jsonHelper.getKeyValue(onDemand, sku, JSONObject.class); JSONObject pricingWrapper = jsonHelper.getKeyValue(current, sku + JSON_SKU_WRAPPER_SUFFIX, JSONObject.class); JSONObject priceDimensions = jsonHelper.getKeyValue(pricingWrapper, JSON_KEY_NAME_PRICE_DIMENSIONS, JSONObject.class); JSONObject innerPricingWrapper = jsonHelper.getKeyValue(priceDimensions, sku + JSON_SKU_WRAPPER_SUFFIX + JSON_PRICE_DIMENSIONS_WRAPPER_SUFFIX, JSONObject.class); JSONObject pricePerUnit = jsonHelper.getKeyValue(innerPricingWrapper, JSON_KEY_NAME_PRICE_PER_UNIT, JSONObject.class); String pricePerUnitValue = jsonHelper.getKeyValue(pricePerUnit, JSON_PRICE_PER_UNIT_WRAPPER, String.class); try { ec2OnDemandPricing.setPricePerHour(new BigDecimal(pricePerUnitValue)); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Failed to convert \"%s\" value to %s.", pricePerUnitValue, BigDecimal.class.getName()), e); } } } return ec2OnDemandPricingEntries; }
From source file:org.finra.herd.service.impl.IndexSearchServiceImpl.java
@Override public IndexSearchResponse indexSearch(final IndexSearchRequest request, final Set<String> fields, final Set<String> match) { // Validate the search response fields validateSearchResponseFields(fields); // Validate the search response match validateSearchMatchFields(match);/*from w w w . j a va 2 s .co m*/ // Validate the search request validateIndexSearchRequest(request); Set<String> facetFields = new HashSet<>(); if (CollectionUtils.isNotEmpty(request.getFacetFields())) { facetFields.addAll(validateFacetFields(new HashSet<>(request.getFacetFields()))); //set the facets fields after validation request.setFacetFields(new ArrayList<>(facetFields)); } // Fetch the current active indexes String bdefActiveIndex = searchIndexDaoHelper .getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name()); String tagActiveIndex = searchIndexDaoHelper .getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name()); return indexSearchDao.indexSearch(request, fields, match, bdefActiveIndex, tagActiveIndex); }
From source file:org.finra.herd.service.impl.NamespaceIamRoleAuthorizationServiceImpl.java
/** * Asserts that no NamespaceIamRoleAuthorizationEntities exist for the given namespace. Throws a AlreadyExistsException if any * NamespaceIamRoleAuthorizationEntity exist. * * @param namespaceEntity The namespace entity *//*from ww w.ja va 2s.c o m*/ private void assertNamespaceIamRoleAuthorizationNotExist(NamespaceEntity namespaceEntity) { if (CollectionUtils .isNotEmpty(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity))) { throw new AlreadyExistsException( String.format("Namespace IAM role authorizations with namespace \"%s\" already exist", namespaceEntity.getCode())); } }
From source file:org.finra.herd.service.impl.NotificationMessagePublishingServiceImpl.java
/** * Adds a notification message to the database queue. * * @param notificationMessage the notification message *//*ww w . j a v a 2 s . c om*/ protected void addNotificationMessageToDatabaseQueueImpl(NotificationMessage notificationMessage) { // Get a message type entity and ensure it exists. MessageTypeEntity messageTypeEntity = messageTypeDaoHelper .getMessageTypeEntity(notificationMessage.getMessageType()); // Create and persist a notification message entity. NotificationMessageEntity notificationMessageEntity = new NotificationMessageEntity(); notificationMessageEntity.setMessageType(messageTypeEntity); notificationMessageEntity.setMessageDestination(notificationMessage.getMessageDestination()); notificationMessageEntity.setMessageText(notificationMessage.getMessageText()); if (CollectionUtils.isNotEmpty(notificationMessage.getMessageHeaders())) { notificationMessageEntity .setMessageHeaders(jsonHelper.objectToJson(notificationMessage.getMessageHeaders())); } notificationMessageDao.saveAndRefresh(notificationMessageEntity); }
From source file:org.finra.herd.service.impl.StoragePolicySelectorServiceImpl.java
/** * Sends storage policy selections to the specified AWS SQS queue. * * @param sqsQueueName the SQS queue name to send storage policy selections to * @param storagePolicySelections the list of storage policy selections *///from w w w . j a v a 2 s . c o m private void sendStoragePolicySelectionToSqsQueue(String sqsQueueName, List<StoragePolicySelection> storagePolicySelections) { if (CollectionUtils.isNotEmpty(storagePolicySelections)) { AwsParamsDto awsParamsDto = awsHelper.getAwsParamsDto(); for (StoragePolicySelection storagePolicySelection : storagePolicySelections) { String messageText = null; try { messageText = jsonHelper.objectToJson(storagePolicySelection); sqsDao.sendMessage(awsParamsDto, sqsQueueName, messageText, null); } catch (Exception e) { // Log the error and throw the exception up. LOGGER.error( "Failed to publish message to the JMS queue. jmsQueueName=\"{}\" jmsMessagePayload={}", sqsQueueName, messageText); throw new IllegalStateException(e.getMessage(), e); } } } }
From source file:org.finra.herd.service.impl.TagServiceImpl.java
@Override public TagSearchResponse searchTags(TagSearchRequest request, Set<String> fields) { // Validate and trim the request parameters. validateTagSearchRequest(request);/* w ww . j a v a2 s.c om*/ // Validate and trim the search response fields. validateSearchResponseFields(fields); // Prepare the result list. List<TagEntity> tagEntities = new ArrayList<>(); // If search key is specified, use it to retrieve the tags. if (CollectionUtils.isNotEmpty(request.getTagSearchFilters()) && request.getTagSearchFilters().get(0) != null) { // Get the tag search key. TagSearchKey tagSearchKey = request.getTagSearchFilters().get(0).getTagSearchKeys().get(0); // Retrieve and ensure that a tag type exists for the specified tag type code. TagTypeEntity tagTypeEntity = tagTypeDaoHelper .getTagTypeEntity(new TagTypeKey(tagSearchKey.getTagTypeCode())); // Retrieve the tags. tagEntities.addAll(tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, tagSearchKey.getParentTagCode(), tagSearchKey.isIsParentTagNull())); } // The search key is not specified, so select all tags registered in the system. else { // Retrieve the tags. tagEntities.addAll(tagDao.getTags()); } // Build the list of tags. List<Tag> tags = new ArrayList<>(); for (TagEntity tagEntity : tagEntities) { tags.add(createTagFromEntity(tagEntity, false, fields.contains(DISPLAY_NAME_FIELD), fields.contains(SEARCH_SCORE_MULTIPLIER_FIELD), fields.contains(DESCRIPTION_FIELD), false, false, false, fields.contains(PARENT_TAG_KEY_FIELD), fields.contains(HAS_CHILDREN_FIELD))); } // Build and return the tag search response. return new TagSearchResponse(tags); }
From source file:org.finra.herd.service.impl.TagServiceImpl.java
/** * Validate the tag search request. This method also trims the request parameters. * * @param tagSearchRequest the tag search request *//* w w w .jav a2 s . c om*/ private void validateTagSearchRequest(TagSearchRequest tagSearchRequest) { Assert.notNull(tagSearchRequest, "A tag search request must be specified."); // Continue validation if the list of tag search filters is not empty. if (CollectionUtils.isNotEmpty(tagSearchRequest.getTagSearchFilters()) && tagSearchRequest.getTagSearchFilters().get(0) != null) { // Validate that there is only one tag search filter. Assert.isTrue(CollectionUtils.size(tagSearchRequest.getTagSearchFilters()) == 1, "At most one tag search filter must be specified."); // Get the tag search filter. TagSearchFilter tagSearchFilter = tagSearchRequest.getTagSearchFilters().get(0); // Validate that exactly one tag search key is specified. Assert.isTrue( CollectionUtils.size(tagSearchFilter.getTagSearchKeys()) == 1 && tagSearchFilter.getTagSearchKeys().get(0) != null, "Exactly one tag search key must be specified."); // Get the tag search key. TagSearchKey tagSearchKey = tagSearchFilter.getTagSearchKeys().get(0); tagSearchKey.setTagTypeCode( alternateKeyHelper.validateStringParameter("tag type code", tagSearchKey.getTagTypeCode())); if (tagSearchKey.getParentTagCode() != null) { tagSearchKey.setParentTagCode(tagSearchKey.getParentTagCode().trim()); } // Fail validation when parent tag code is specified along with the isParentTagNull flag set to true. Assert.isTrue( StringUtils.isBlank(tagSearchKey.getParentTagCode()) || BooleanUtils.isNotTrue(tagSearchKey.isIsParentTagNull()), "A parent tag code can not be specified when isParentTagNull flag is set to true."); } }
From source file:org.finra.herd.service.systemjobs.Ec2OnDemandPricingUpdateSystemJob.java
@Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { // Log that the system job is started. LOGGER.info("Started system job. systemJobName=\"{}\"", JOB_NAME); // Create an empty list of EC2 on-demand pricing entries. List<Ec2OnDemandPricing> ec2OnDemandPricingEntries = null; // Get the parameter values. String ec2PricingListUrl = parameterHelper.getParameterValue(parameters, ConfigurationValue.EC2_ON_DEMAND_PRICING_UPDATE_JOB_EC2_PRICING_LIST_URL); // Log the parameter values. LOGGER.info("systemJobName={} {}={}", JOB_NAME, ConfigurationValue.EC2_ON_DEMAND_PRICING_UPDATE_JOB_EC2_PRICING_LIST_URL, ec2PricingListUrl); // Retrieve the EC2 on-demand pricing information from AWS. try {/*w w w . java2 s . co m*/ // Retrieve the EC2 on-demand pricing information from AWS. ec2OnDemandPricingEntries = ec2OnDemandPricingUpdateService.getEc2OnDemandPricing(ec2PricingListUrl); // Log the number of storage units selected for processing. LOGGER.info("Retrieved {} EC2 on-demand pricing records from AWS. systemJobName=\"{}\"", ec2OnDemandPricingEntries.size(), JOB_NAME); } catch (Exception e) { // Log the exception. LOGGER.error("Failed to retrieve EC2 on-demand pricing information from AWS. systemJobName=\"{}\"", JOB_NAME, e); } // If pricing information was retrieved, update the EC2 on-demand pricing configured in the system. if (CollectionUtils.isNotEmpty(ec2OnDemandPricingEntries)) { try { // Update the EC2 on-demand pricing configured in the system per retrieved pricing information. ec2OnDemandPricingUpdateService.updateEc2OnDemandPricing(ec2OnDemandPricingEntries); } catch (Exception e) { // Log the exception. LOGGER.error("Failed to update EC2 on-demand pricing. systemJobName=\"{}\"", JOB_NAME, e); } } // Log that the system job is ended. LOGGER.info("Completed system job. systemJobName=\"{}\"", JOB_NAME); }