List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty
public static boolean isEmpty(final Collection<?> coll)
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
@Override public void validateGlacierS3FilesRestored(S3FileTransferRequestParamsDto params) throws RuntimeException { LOGGER.info(// w ww .j av a2s . co m "Checking for already restored Glacier storage class objects... s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={}", params.getS3KeyPrefix(), params.getS3BucketName(), params.getFiles().size()); if (!CollectionUtils.isEmpty(params.getFiles())) { // Initialize a key value pair for the error message in the catch block. String key = params.getFiles().get(0).getPath().replaceAll("\\\\", "/"); try { // Create an S3 client. AmazonS3Client s3Client = getAmazonS3(params); try { for (File file : params.getFiles()) { key = file.getPath().replaceAll("\\\\", "/"); ObjectMetadata objectMetadata = s3Operations.getObjectMetadata(params.getS3BucketName(), key, s3Client); // Fail if a not already restored object is detected. if (BooleanUtils.isNotFalse(objectMetadata.getOngoingRestore())) { throw new IllegalArgumentException(String.format( "Archived Glacier S3 file \"%s\" is not restored. StorageClass {%s}, OngoingRestore flag {%s}, S3 bucket name {%s}", key, objectMetadata.getStorageClass(), objectMetadata.getOngoingRestore(), params.getS3BucketName())); } } } finally { s3Client.shutdown(); } } catch (AmazonServiceException e) { throw new IllegalStateException( String.format("Fail to check restore status for \"%s\" key in \"%s\" bucket. Reason: %s", key, params.getS3BucketName(), e.getMessage()), e); } } }
From source file:org.finra.herd.service.BusinessObjectDataAttributeServiceTest.java
/** * This method is to get coverage for the business object data attribute service methods that have an explicit annotation for transaction propagation. *//*from w w w .j ava2 s . c o m*/ @Test public void testBusinessObjectDataAttributeServiceMethodsNewTransactionPropagation() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a business object data attribute key. BusinessObjectDataAttributeKey businessObjectDataAttributeKey = businessObjectDataAttributeHelper .getBusinessObjectDataAttributeKey(businessObjectDataKey, ATTRIBUTE_NAME_1_MIXED_CASE); // Try to create a business object data attribute when specified business object format does not exist. try { businessObjectDataAttributeServiceImpl.createBusinessObjectDataAttribute( new BusinessObjectDataAttributeCreateRequest(businessObjectDataAttributeKey, ATTRIBUTE_VALUE_1)); fail("Should throw an ObjectNotFoundException when not able to find business object format."); } catch (ObjectNotFoundException e) { assertEquals( businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage( BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage()); } // Try to retrieve a business object data attribute when specified business object data instance does not exist. try { businessObjectDataAttributeServiceImpl.getBusinessObjectDataAttribute(businessObjectDataAttributeKey); fail("Should throw an ObjectNotFoundException when not able to find business object data."); } catch (ObjectNotFoundException e) { assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage( businessObjectDataKey, NO_BDATA_STATUS), e.getMessage()); } // Try to update a business object data attribute when specified business object format does not exist. try { businessObjectDataAttributeServiceImpl.updateBusinessObjectDataAttribute(businessObjectDataAttributeKey, new BusinessObjectDataAttributeUpdateRequest(ATTRIBUTE_VALUE_2)); fail("Should throw an ObjectNotFoundException when not able to find business object format."); } catch (ObjectNotFoundException e) { assertEquals( businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage( BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage()); } // Try to delete a business object data attribute when specified business object format does not exist. try { businessObjectDataAttributeServiceImpl .deleteBusinessObjectDataAttribute(businessObjectDataAttributeKey); fail("Should throw an ObjectNotFoundException when not able to find business object format."); } catch (ObjectNotFoundException e) { assertEquals( businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage( BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage()); } // Try to retrieve keys for all business object data attributes for a non-existing business object data. try { assertTrue(CollectionUtils.isEmpty(businessObjectDataAttributeServiceImpl .getBusinessObjectDataAttributes(businessObjectDataKey).getBusinessObjectDataAttributeKeys())); fail("Should throw an ObjectNotFoundException when not able to find business object data."); } catch (ObjectNotFoundException e) { assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage( businessObjectDataKey, NO_BDATA_STATUS), e.getMessage()); } }
From source file:org.finra.herd.service.helper.AttributeDaoHelper.java
/** * Updates business object data attributes. * * @param businessObjectDataEntity the business object data entity * @param attributes the attributes/*from www . j ava 2 s .c om*/ */ public void updateBusinessObjectDataAttributes(BusinessObjectDataEntity businessObjectDataEntity, final List<Attribute> attributes) { // Load all existing attribute entities in a map with a "lowercase" attribute name as the key for case insensitivity. Map<String, BusinessObjectDataAttributeEntity> existingAttributeEntities = new HashMap<>(); for (BusinessObjectDataAttributeEntity attributeEntity : businessObjectDataEntity.getAttributes()) { String mapKey = attributeEntity.getName().toLowerCase(); if (existingAttributeEntities.containsKey(mapKey)) { throw new IllegalStateException(String.format( "Found duplicate attribute with name \"%s\" for business object data. Business object data: {%s}", mapKey, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } existingAttributeEntities.put(mapKey, attributeEntity); } // Process the list of attributes to determine that business object definition attribute entities should be created, updated, or deleted. List<BusinessObjectDataAttributeEntity> createdAttributeEntities = new ArrayList<>(); List<BusinessObjectDataAttributeEntity> retainedAttributeEntities = new ArrayList<>(); if (!CollectionUtils.isEmpty(attributes)) { for (Attribute attribute : attributes) { // Use a "lowercase" attribute name for case insensitivity. String lowercaseAttributeName = attribute.getName().toLowerCase(); if (existingAttributeEntities.containsKey(lowercaseAttributeName)) { // Check if the attribute value needs to be updated. BusinessObjectDataAttributeEntity attributeEntity = existingAttributeEntities .get(lowercaseAttributeName); if (!StringUtils.equals(attribute.getValue(), attributeEntity.getValue())) { // Update the business object attribute entity. attributeEntity.setValue(attribute.getValue()); } // Add this entity to the list of business object definition attribute entities to be retained. retainedAttributeEntities.add(attributeEntity); } else { // Create a new business object attribute entity. BusinessObjectDataAttributeEntity attributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataEntity.getAttributes().add(attributeEntity); attributeEntity.setBusinessObjectData(businessObjectDataEntity); attributeEntity.setName(attribute.getName()); attributeEntity.setValue(attribute.getValue()); // Add this entity to the list of the newly created business object definition attribute entities. createdAttributeEntities.add(attributeEntity); } } } // Remove any of the currently existing attribute entities that did not get onto the retained entities list. businessObjectDataEntity.getAttributes().retainAll(retainedAttributeEntities); // Add all of the newly created business object definition attribute entities. businessObjectDataEntity.getAttributes().addAll(createdAttributeEntities); }
From source file:org.finra.herd.service.helper.AttributeDaoHelper.java
/** * Validates that attributes are consistent with the business object data attribute definitions. * * @param attributes the list of attributes * @param businessObjectDataAttributeDefinitionEntities the collection of business object data attribute definitions *//*from w w w . ja v a 2s . c o m*/ public void validateAttributesAgainstBusinessObjectDataAttributeDefinitions(final List<Attribute> attributes, final Collection<BusinessObjectDataAttributeDefinitionEntity> businessObjectDataAttributeDefinitionEntities) { // Build a map of the specified attributes in the request where the key is lower case for case insensitive checks. Map<String, String> attributeMap = new HashMap<>(); if (!CollectionUtils.isEmpty(attributes)) { for (Attribute attribute : attributes) { attributeMap.put(attribute.getName().toLowerCase(), attribute.getValue()); } } // Loop through each attribute definition (i.e. the required attributes) and verify that each attribute // definition was specified in the list of attributes and that the specified value has non-blank data. for (BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity : businessObjectDataAttributeDefinitionEntities) { String attributeDefinitionName = attributeDefinitionEntity.getName().toLowerCase(); if (!attributeMap.containsKey(attributeDefinitionName) || StringUtils.isBlank(attributeMap.get(attributeDefinitionName))) { throw new IllegalArgumentException(String.format( "The business object format has a required attribute \"%s\" which was not specified or has a value which is blank.", attributeDefinitionEntity.getName())); } } }
From source file:org.finra.herd.service.helper.AttributeHelper.java
/** * Validates the attributes./*w w w . j a v a 2 s . c o m*/ * * @param attributes the attributes to validate. Null shouldn't be specified. * @return the validated attribute map * @throws IllegalArgumentException if any invalid attributes were found. */ public Map<String, String> validateAttributes(List<Attribute> attributes) throws IllegalArgumentException { // Validate attributes if they are specified. Map<String, String> attributeNameValidationMap = new HashMap<>(); if (!CollectionUtils.isEmpty(attributes)) { for (Attribute attribute : attributes) { attribute.setName( alternateKeyHelper.validateStringParameter("An", "attribute name", attribute.getName())); // Ensure the attribute key isn't a duplicate by using a map with a "lowercase" name as the key for case insensitivity. String validationMapKey = attribute.getName().toLowerCase(); if (attributeNameValidationMap.containsKey(validationMapKey)) { throw new IllegalArgumentException("Duplicate attribute name found: " + attribute.getName()); } attributeNameValidationMap.put(validationMapKey, attribute.getValue()); } } return attributeNameValidationMap; }
From source file:org.finra.herd.service.helper.BusinessObjectDataDaoHelper.java
/** * Retrieves business object data by it's key. If a format version isn't specified, the latest available format version (for this partition value) will be * used. If a business object data version isn't specified, the latest data version based on the specified business object data status is returned. When * both business object data version and business object data status are not specified, the latest data version for each set of partition values will be * used regardless of the status./*from w w w . j a v a 2s. c om*/ * * @param businessObjectDataKey the business object data key * @param businessObjectDataStatus the business object data status. This parameter is ignored when the business object data version is specified. * * @return the business object data */ public BusinessObjectDataEntity getBusinessObjectDataEntityByKeyAndStatus( BusinessObjectDataKey businessObjectDataKey, String businessObjectDataStatus) { // Get the business object data based on the specified parameters. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDao .getBusinessObjectDataByAltKeyAndStatus(businessObjectDataKey, businessObjectDataStatus); // Make sure that business object data exists. if (businessObjectDataEntity == null) { throw new ObjectNotFoundException(String.format( "Business object data {namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", " + "businessObjectFormatFileType: \"%s\", businessObjectFormatVersion: %d, businessObjectDataPartitionValue: \"%s\", " + "businessObjectDataSubPartitionValues: \"%s\", businessObjectDataVersion: %d, businessObjectDataStatus: \"%s\"} doesn't exist.", businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), CollectionUtils.isEmpty(businessObjectDataKey.getSubPartitionValues()) ? "" : StringUtils.join(businessObjectDataKey.getSubPartitionValues(), ","), businessObjectDataKey.getBusinessObjectDataVersion(), businessObjectDataStatus)); } // Return the retrieved business object data entity. return businessObjectDataEntity; }
From source file:org.finra.herd.service.helper.BusinessObjectDataDaoHelper.java
/** * Discovers storage files in the specified S3 storage that match the S3 key prefix. * * @param storageEntity the storage entity * @param s3KeyPrefix the S3 key prefix//from w w w .j a v a 2 s. c o m * * @return the list of discovered storage files */ private List<StorageFile> discoverStorageFiles(StorageEntity storageEntity, String s3KeyPrefix) { // Only S3 storage platform is currently supported for storage file discovery. Assert.isTrue(storageEntity.getStoragePlatform().getName().equals(StoragePlatformEntity.S3), String.format("Cannot discover storage files at \"%s\" storage platform.", storageEntity.getStoragePlatform().getName())); // Get S3 bucket access parameters. S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageEntity); // Retrieve a list of all keys/objects from the S3 bucket matching the specified S3 key prefix. // Since S3 key prefix represents the directory, we add a trailing '/' character to it, unless it is already present. params.setS3KeyPrefix(StringUtils.appendIfMissing(s3KeyPrefix, "/")); // When listing S3 files, we ignore 0 byte objects that represent S3 directories. List<S3ObjectSummary> s3ObjectSummaries = s3Service.listDirectory(params, true); // Fail registration if no storage files were discovered. if (CollectionUtils.isEmpty(s3ObjectSummaries)) { throw new ObjectNotFoundException(String.format("Found no files at \"s3://%s/%s\" location.", params.getS3BucketName(), params.getS3KeyPrefix())); } return storageFileHelper.createStorageFilesFromS3ObjectSummaries(s3ObjectSummaries); }
From source file:org.finra.herd.service.helper.BusinessObjectDataDaoHelper.java
/** * Validates the business object data create request. This method also trims appropriate request parameters. * * @param request the request/*w w w . j a v a 2 s . c o m*/ * @param fileSizeRequired specifies if fileSizeBytes value is required or not * @param businessObjectDataStatusEntity The status entity in the request * * @throws IllegalArgumentException if any validation errors were found. */ private void validateBusinessObjectDataCreateRequest(BusinessObjectDataCreateRequest request, boolean fileSizeRequired, BusinessObjectDataStatusEntity businessObjectDataStatusEntity) { // Validate and trim the request parameters. request.setNamespace(alternateKeyHelper.validateStringParameter("namespace", request.getNamespace())); request.setBusinessObjectDefinitionName(alternateKeyHelper.validateStringParameter( "business object definition name", request.getBusinessObjectDefinitionName())); request.setBusinessObjectFormatUsage(alternateKeyHelper .validateStringParameter("business object format usage", request.getBusinessObjectFormatUsage())); request.setBusinessObjectFormatFileType(alternateKeyHelper.validateStringParameter( "business object format file type", request.getBusinessObjectFormatFileType())); Assert.notNull(request.getBusinessObjectFormatVersion(), "A business object format version must be specified."); request.setPartitionKey( alternateKeyHelper.validateStringParameter("partition key", request.getPartitionKey())); request.setPartitionValue( alternateKeyHelper.validateStringParameter("partition value", request.getPartitionValue())); businessObjectDataHelper.validateSubPartitionValues(request.getSubPartitionValues()); Assert.isTrue(CollectionUtils.isNotEmpty(request.getStorageUnits()), "At least one storage unit must be specified."); for (StorageUnitCreateRequest storageUnit : request.getStorageUnits()) { Assert.notNull(storageUnit, "A storage unit can't be null."); // Validate and trim the storage name. Assert.hasText(storageUnit.getStorageName(), "A storage name is required for each storage unit."); storageUnit.setStorageName(storageUnit.getStorageName().trim()); if (BooleanUtils.isTrue(storageUnit.isDiscoverStorageFiles())) { // The auto-discovery of storage files is enabled, thus a storage directory is required and storage files cannot be specified. Assert.isTrue(storageUnit.getStorageDirectory() != null, "A storage directory must be specified when discovery of storage files is enabled."); Assert.isTrue(CollectionUtils.isEmpty(storageUnit.getStorageFiles()), "Storage files cannot be specified when discovery of storage files is enabled."); } else if (!Boolean.TRUE.equals(businessObjectDataStatusEntity.getPreRegistrationStatus())) { // Since auto-discovery is disabled, a storage directory or at least one storage file are required for each storage unit. Assert.isTrue( storageUnit.getStorageDirectory() != null || CollectionUtils.isNotEmpty(storageUnit.getStorageFiles()), "A storage directory or at least one storage file must be specified for each storage unit."); } // If storageDirectory element is present in the request, we require it to contain a non-empty directoryPath element. if (storageUnit.getStorageDirectory() != null) { Assert.hasText(storageUnit.getStorageDirectory().getDirectoryPath(), "A storage directory path must be specified."); storageUnit.getStorageDirectory() .setDirectoryPath(storageUnit.getStorageDirectory().getDirectoryPath().trim()); } if (CollectionUtils.isNotEmpty(storageUnit.getStorageFiles())) { for (StorageFile storageFile : storageUnit.getStorageFiles()) { Assert.hasText(storageFile.getFilePath(), "A file path must be specified."); storageFile.setFilePath(storageFile.getFilePath().trim()); if (fileSizeRequired) { Assert.notNull(storageFile.getFileSizeBytes(), "A file size must be specified."); } // Ensure row count is not negative. if (storageFile.getRowCount() != null) { Assert.isTrue(storageFile.getRowCount() >= 0, "File \"" + storageFile.getFilePath() + "\" has a row count which is < 0."); } } } } // Validate and trim the parents' keys. validateBusinessObjectDataKeys(request.getBusinessObjectDataParents()); // Validate attributes. attributeHelper.validateAttributes(request.getAttributes()); }
From source file:org.finra.herd.service.helper.BusinessObjectDataInvalidateUnregisteredHelper.java
/** * Constructs a {@link BusinessObjectDataKey} from the given request. The returned key does not contain a data version. * * @param businessObjectDataInvalidateUnregisteredRequest the request with key information * * @return {@link BusinessObjectDataKey} *//* www .jav a 2 s . c o m*/ private BusinessObjectDataKey getBusinessObjectDataKey( BusinessObjectDataInvalidateUnregisteredRequest businessObjectDataInvalidateUnregisteredRequest) { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(); businessObjectDataKey.setNamespace(businessObjectDataInvalidateUnregisteredRequest.getNamespace()); businessObjectDataKey.setBusinessObjectDefinitionName( businessObjectDataInvalidateUnregisteredRequest.getBusinessObjectDefinitionName()); businessObjectDataKey.setBusinessObjectFormatUsage( businessObjectDataInvalidateUnregisteredRequest.getBusinessObjectFormatUsage()); businessObjectDataKey.setBusinessObjectFormatFileType( businessObjectDataInvalidateUnregisteredRequest.getBusinessObjectFormatFileType()); businessObjectDataKey.setBusinessObjectFormatVersion( businessObjectDataInvalidateUnregisteredRequest.getBusinessObjectFormatVersion()); businessObjectDataKey .setPartitionValue(businessObjectDataInvalidateUnregisteredRequest.getPartitionValue()); businessObjectDataKey .setSubPartitionValues(businessObjectDataInvalidateUnregisteredRequest.getSubPartitionValues()); if (CollectionUtils.isEmpty(businessObjectDataInvalidateUnregisteredRequest.getSubPartitionValues())) { businessObjectDataKey.setSubPartitionValues(new ArrayList<>()); } return businessObjectDataKey; }
From source file:org.finra.herd.service.helper.BusinessObjectDataSearchHelper.java
/** * Validates a business object data search key. * * @param businessObjectDataSearchKey the business object data search key *//* w ww .ja va 2 s. c om*/ void validateBusinessObjectDataSearchKey(BusinessObjectDataSearchKey businessObjectDataSearchKey) { Assert.notNull(businessObjectDataSearchKey, "A business object data search key must be specified."); businessObjectDataSearchKey.setNamespace(alternateKeyHelper.validateStringParameter("namespace", businessObjectDataSearchKey.getNamespace())); businessObjectDataSearchKey.setBusinessObjectDefinitionName(alternateKeyHelper.validateStringParameter( "business object definition name", businessObjectDataSearchKey.getBusinessObjectDefinitionName())); if (businessObjectDataSearchKey.getBusinessObjectFormatUsage() != null) { businessObjectDataSearchKey.setBusinessObjectFormatUsage( businessObjectDataSearchKey.getBusinessObjectFormatUsage().trim()); } if (businessObjectDataSearchKey.getBusinessObjectFormatFileType() != null) { businessObjectDataSearchKey.setBusinessObjectFormatFileType( businessObjectDataSearchKey.getBusinessObjectFormatFileType().trim()); } // Validate partition value filters, if specified. if (CollectionUtils.isNotEmpty(businessObjectDataSearchKey.getPartitionValueFilters())) { businessObjectDataHelper.validatePartitionValueFilters( businessObjectDataSearchKey.getPartitionValueFilters(), null, false); // TODO: For now, we only support partition values or partition range in the filter. for (PartitionValueFilter partitionValueFilter : businessObjectDataSearchKey .getPartitionValueFilters()) { List<String> partitionValues = partitionValueFilter.getPartitionValues(); PartitionValueRange partitionValueRange = partitionValueFilter.getPartitionValueRange(); // The partition values array should not be empty and partition vale range start and end value should not be empty // as it is done above at businessObjectDataHelper.validatePartitionValueFilters(). if (CollectionUtils.isEmpty(partitionValues) && partitionValueRange == null) { throw new IllegalArgumentException( "Only partition values or partition range are supported in partition value filter."); } } } // Validate registration date range filter, if specified. if (businessObjectDataSearchKey.getRegistrationDateRangeFilter() != null) { businessObjectDataHelper.validateRegistrationDateRangeFilter( businessObjectDataSearchKey.getRegistrationDateRangeFilter()); } // Validate attribute value filters, if specified. if (CollectionUtils.isNotEmpty(businessObjectDataSearchKey.getAttributeValueFilters())) { for (AttributeValueFilter attributeValueFilter : businessObjectDataSearchKey .getAttributeValueFilters()) { if (attributeValueFilter.getAttributeName() != null) { attributeValueFilter.setAttributeName(attributeValueFilter.getAttributeName().trim()); } if (StringUtils.isBlank(attributeValueFilter.getAttributeName()) && StringUtils.isEmpty(attributeValueFilter.getAttributeValue())) { throw new IllegalArgumentException( "Either attribute name or attribute value filter must be specified."); } } } }