Search in sources :

Example 1 with BusinessObjectDefinitionAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionDaoHelper method createBusinessObjectDefinitionEntity.

/**
 * Create Business Object Definition Entity
 * @param request business object definition create request
 * @return Business Object Definition Entity
 */
public BusinessObjectDefinitionEntity createBusinessObjectDefinitionEntity(BusinessObjectDefinitionCreateRequest request) {
    // Perform the validation.
    validateBusinessObjectDefinitionCreateRequest(request);
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
    // Get the data provider and ensure it exists.
    DataProviderEntity dataProviderEntity = dataProviderDaoHelper.getDataProviderEntity(request.getDataProviderName());
    // Get business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(request.getNamespace(), request.getBusinessObjectDefinitionName());
    // Ensure a business object definition with the specified key doesn't already exist.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
    if (businessObjectDefinitionEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create business object definition with name \"%s\" because it already exists for namespace \"%s\".", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace()));
    }
    // Create a new entity.
    businessObjectDefinitionEntity = new BusinessObjectDefinitionEntity();
    businessObjectDefinitionEntity.setNamespace(namespaceEntity);
    businessObjectDefinitionEntity.setName(request.getBusinessObjectDefinitionName());
    businessObjectDefinitionEntity.setDescription(request.getDescription());
    businessObjectDefinitionEntity.setDataProvider(dataProviderEntity);
    businessObjectDefinitionEntity.setDisplayName(request.getDisplayName());
    // Create the attributes if they are specified.
    if (!CollectionUtils.isEmpty(request.getAttributes())) {
        List<BusinessObjectDefinitionAttributeEntity> attributeEntities = new ArrayList<>();
        businessObjectDefinitionEntity.setAttributes(attributeEntities);
        for (Attribute attribute : request.getAttributes()) {
            BusinessObjectDefinitionAttributeEntity attributeEntity = new BusinessObjectDefinitionAttributeEntity();
            attributeEntities.add(attributeEntity);
            attributeEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
            attributeEntity.setName(attribute.getName());
            attributeEntity.setValue(attribute.getValue());
        }
    }
    // Persist the change event entity
    saveBusinessObjectDefinitionChangeEvents(businessObjectDefinitionEntity);
    // Persist and return the new entity.
    return businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
Also used : BusinessObjectDefinitionAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) ArrayList(java.util.ArrayList)

Example 2 with BusinessObjectDefinitionAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionDaoTestHelper method createBusinessObjectDefinitionEntity.

/**
 * Creates and persists a new business object definition entity.
 *
 * @return the newly created business object definition entity
 */
public BusinessObjectDefinitionEntity createBusinessObjectDefinitionEntity(NamespaceEntity namespaceEntity, String businessObjectDefinitionName, DataProviderEntity dataProviderEntity, String businessObjectDefinitionDescription, String displayName, List<Attribute> attributes, List<SampleDataFile> sampleDataFiles) {
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = new BusinessObjectDefinitionEntity();
    businessObjectDefinitionEntity.setNamespace(namespaceEntity);
    businessObjectDefinitionEntity.setDataProvider(dataProviderEntity);
    businessObjectDefinitionEntity.setName(businessObjectDefinitionName);
    businessObjectDefinitionEntity.setDescription(businessObjectDefinitionDescription);
    businessObjectDefinitionEntity.setDisplayName(displayName);
    // Create business object definition attribute entities if they are specified.
    if (!CollectionUtils.isEmpty(attributes)) {
        List<BusinessObjectDefinitionAttributeEntity> attributeEntities = new ArrayList<>();
        businessObjectDefinitionEntity.setAttributes(attributeEntities);
        for (Attribute attribute : attributes) {
            BusinessObjectDefinitionAttributeEntity attributeEntity = new BusinessObjectDefinitionAttributeEntity();
            attributeEntities.add(attributeEntity);
            attributeEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
            attributeEntity.setName(attribute.getName());
            attributeEntity.setValue(attribute.getValue());
        }
    }
    // Create business object definition sample data file entities if they are specified.
    if (!CollectionUtils.isEmpty(sampleDataFiles)) {
        // Create a storage entity if needed.
        StorageEntity storageEntity = storageDao.getStorageByName(AbstractDaoTest.STORAGE_NAME);
        if (storageEntity == null) {
            storageEntity = storageDaoTestHelper.createStorageEntity(AbstractDaoTest.STORAGE_NAME);
        }
        // Create sample data file entities.
        List<BusinessObjectDefinitionSampleDataFileEntity> sampleDataFileEntities = new ArrayList<>();
        businessObjectDefinitionEntity.setSampleDataFiles(sampleDataFileEntities);
        for (SampleDataFile sampleDataFile : sampleDataFiles) {
            BusinessObjectDefinitionSampleDataFileEntity sampleDataFileEntity = new BusinessObjectDefinitionSampleDataFileEntity();
            sampleDataFileEntities.add(sampleDataFileEntity);
            sampleDataFileEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
            sampleDataFileEntity.setDirectoryPath(sampleDataFile.getDirectoryPath());
            sampleDataFileEntity.setFileName(sampleDataFile.getFileName());
            sampleDataFileEntity.setFileSizeBytes(AbstractDaoTest.FILE_SIZE_1_KB);
            sampleDataFileEntity.setStorage(storageEntity);
        }
    }
    return businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
Also used : BusinessObjectDefinitionAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity) SampleDataFile(org.finra.herd.model.api.xml.SampleDataFile) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDefinitionSampleDataFileEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity)

Example 3 with BusinessObjectDefinitionAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceImpl method updateBusinessObjectDefinitionEntity.

/**
 * Update and persist the business object definition per specified update request.
 *
 * @param businessObjectDefinitionEntity the business object definition entity
 * @param request the business object definition update request
 */
private void updateBusinessObjectDefinitionEntity(BusinessObjectDefinitionEntity businessObjectDefinitionEntity, BusinessObjectDefinitionUpdateRequest request) {
    // Update the entity with the new description value.
    businessObjectDefinitionEntity.setDescription(request.getDescription());
    businessObjectDefinitionEntity.setDisplayName(request.getDisplayName());
    // Update the attributes.
    // Load all existing attribute entities in a map with a "lowercase" attribute name as the key for case insensitivity.
    Map<String, BusinessObjectDefinitionAttributeEntity> existingAttributeEntities = new HashMap<>();
    for (BusinessObjectDefinitionAttributeEntity attributeEntity : businessObjectDefinitionEntity.getAttributes()) {
        String mapKey = attributeEntity.getName().toLowerCase();
        if (existingAttributeEntities.containsKey(mapKey)) {
            throw new IllegalStateException(String.format("Found duplicate attribute with name \"%s\" for business object definition {namespace: \"%s\", businessObjectDefinitionName: \"%s\"}.", mapKey, businessObjectDefinitionEntity.getNamespace().getCode(), businessObjectDefinitionEntity.getName()));
        }
        existingAttributeEntities.put(mapKey, attributeEntity);
    }
    // Process the list of attributes to determine that business object definition attribute entities should be created, updated, or deleted.
    List<BusinessObjectDefinitionAttributeEntity> createdAttributeEntities = new ArrayList<>();
    List<BusinessObjectDefinitionAttributeEntity> retainedAttributeEntities = new ArrayList<>();
    if (!CollectionUtils.isEmpty(request.getAttributes())) {
        for (Attribute attribute : request.getAttributes()) {
            // 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.
                BusinessObjectDefinitionAttributeEntity 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.
                BusinessObjectDefinitionAttributeEntity attributeEntity = new BusinessObjectDefinitionAttributeEntity();
                businessObjectDefinitionEntity.getAttributes().add(attributeEntity);
                attributeEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
                attributeEntity.setName(attribute.getName());
                attributeEntity.setValue(attribute.getValue());
                // Add this entity to the list of the newly created business object definition attribute entities.
                retainedAttributeEntities.add(attributeEntity);
            }
        }
    }
    // Remove any of the currently existing attribute entities that did not get onto the retained entities list.
    businessObjectDefinitionEntity.getAttributes().retainAll(retainedAttributeEntities);
    // Add all of the newly created business object definition attribute entities.
    businessObjectDefinitionEntity.getAttributes().addAll(createdAttributeEntities);
    // Persist the change event entity
    saveBusinessObjectDefinitionChangeEvents(businessObjectDefinitionEntity);
    // Persist the entity.
    businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
Also used : BusinessObjectDefinitionAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity) HashMap(java.util.HashMap) Attribute(org.finra.herd.model.api.xml.Attribute) ArrayList(java.util.ArrayList)

Example 4 with BusinessObjectDefinitionAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceImpl method createBusinessObjectDefinitionFromEntity.

/**
 * Creates a business object definition from the persisted entity.
 *
 * @param businessObjectDefinitionEntity the business object definition entity
 *
 * @return the business object definition
 */
private BusinessObjectDefinition createBusinessObjectDefinitionFromEntity(BusinessObjectDefinitionEntity businessObjectDefinitionEntity, Boolean includeBusinessObjectDefinitionUpdateHistory) {
    // Create a business object definition.
    BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition();
    businessObjectDefinition.setId(businessObjectDefinitionEntity.getId());
    businessObjectDefinition.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
    businessObjectDefinition.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
    businessObjectDefinition.setDescription(businessObjectDefinitionEntity.getDescription());
    businessObjectDefinition.setDataProviderName(businessObjectDefinitionEntity.getDataProvider().getName());
    businessObjectDefinition.setDisplayName(businessObjectDefinitionEntity.getDisplayName());
    // Add attributes.
    List<Attribute> attributes = new ArrayList<>();
    businessObjectDefinition.setAttributes(attributes);
    for (BusinessObjectDefinitionAttributeEntity attributeEntity : businessObjectDefinitionEntity.getAttributes()) {
        attributes.add(new Attribute(attributeEntity.getName(), attributeEntity.getValue()));
    }
    if (businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat() != null) {
        BusinessObjectFormatEntity descriptiveFormatEntity = businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat();
        DescriptiveBusinessObjectFormat descriptiveBusinessObjectFormat = new DescriptiveBusinessObjectFormat();
        businessObjectDefinition.setDescriptiveBusinessObjectFormat(descriptiveBusinessObjectFormat);
        descriptiveBusinessObjectFormat.setBusinessObjectFormatUsage(descriptiveFormatEntity.getUsage());
        descriptiveBusinessObjectFormat.setBusinessObjectFormatFileType(descriptiveFormatEntity.getFileType().getCode());
        descriptiveBusinessObjectFormat.setBusinessObjectFormatVersion(descriptiveFormatEntity.getBusinessObjectFormatVersion());
    }
    // Add sample data files.
    List<SampleDataFile> sampleDataFiles = new ArrayList<>();
    businessObjectDefinition.setSampleDataFiles(sampleDataFiles);
    for (BusinessObjectDefinitionSampleDataFileEntity sampleDataFileEntity : businessObjectDefinitionEntity.getSampleDataFiles()) {
        sampleDataFiles.add(new SampleDataFile(sampleDataFileEntity.getDirectoryPath(), sampleDataFileEntity.getFileName()));
    }
    // Add auditable fields.
    businessObjectDefinition.setCreatedByUserId(businessObjectDefinitionEntity.getCreatedBy());
    businessObjectDefinition.setLastUpdatedByUserId(businessObjectDefinitionEntity.getUpdatedBy());
    businessObjectDefinition.setLastUpdatedOn(HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionEntity.getUpdatedOn()));
    // Add change events.
    final List<BusinessObjectDefinitionChangeEvent> businessObjectDefinitionChangeEvents = new ArrayList<>();
    if (BooleanUtils.isTrue(includeBusinessObjectDefinitionUpdateHistory)) {
        businessObjectDefinitionEntity.getChangeEvents().forEach(businessObjectDefinitionChangeEventEntity -> {
            DescriptiveBusinessObjectFormatUpdateRequest descriptiveBusinessObjectFormatUpdateRequest = null;
            if (businessObjectDefinitionChangeEventEntity.getFileType() != null) {
                descriptiveBusinessObjectFormatUpdateRequest = new DescriptiveBusinessObjectFormatUpdateRequest(businessObjectDefinitionChangeEventEntity.getUsage(), businessObjectDefinitionChangeEventEntity.getFileType());
            }
            businessObjectDefinitionChangeEvents.add(new BusinessObjectDefinitionChangeEvent(businessObjectDefinitionChangeEventEntity.getDisplayName(), businessObjectDefinitionChangeEventEntity.getDescription(), descriptiveBusinessObjectFormatUpdateRequest, HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionChangeEventEntity.getCreatedOn()), businessObjectDefinitionChangeEventEntity.getCreatedBy()));
        });
    }
    businessObjectDefinition.setBusinessObjectDefinitionChangeEvents(businessObjectDefinitionChangeEvents);
    return businessObjectDefinition;
}
Also used : BusinessObjectDefinition(org.finra.herd.model.api.xml.BusinessObjectDefinition) BusinessObjectDefinitionAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity) SampleDataFile(org.finra.herd.model.api.xml.SampleDataFile) Attribute(org.finra.herd.model.api.xml.Attribute) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDefinitionSampleDataFileEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity) DescriptiveBusinessObjectFormat(org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat) BusinessObjectDefinitionChangeEvent(org.finra.herd.model.api.xml.BusinessObjectDefinitionChangeEvent) DescriptiveBusinessObjectFormatUpdateRequest(org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormatUpdateRequest)

Aggregations

ArrayList (java.util.ArrayList)4 Attribute (org.finra.herd.model.api.xml.Attribute)4 BusinessObjectDefinitionAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity)4 SampleDataFile (org.finra.herd.model.api.xml.SampleDataFile)2 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)2 BusinessObjectDefinitionSampleDataFileEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity)2 HashMap (java.util.HashMap)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)1 BusinessObjectDefinitionChangeEvent (org.finra.herd.model.api.xml.BusinessObjectDefinitionChangeEvent)1 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)1 DescriptiveBusinessObjectFormat (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat)1 DescriptiveBusinessObjectFormatUpdateRequest (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormatUpdateRequest)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1 DataProviderEntity (org.finra.herd.model.jpa.DataProviderEntity)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1 StorageEntity (org.finra.herd.model.jpa.StorageEntity)1