Search in sources :

Example 1 with CustomDdlEntity

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

the class CustomDdlServiceImpl method createCustomDdl.

/**
 * Creates a new custom DDL.
 *
 * @param request the information needed to create a custom DDL
 *
 * @return the newly created custom DDL information
 */
@NamespacePermission(fields = "#request.customDdlKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public CustomDdl createCustomDdl(CustomDdlCreateRequest request) {
    // Validate and trim the key.
    customDdlHelper.validateCustomDdlKey(request.getCustomDdlKey());
    // Validate and trim the DDL.
    Assert.hasText(request.getDdl(), "DDL must be specified.");
    request.setDdl(request.getDdl().trim());
    // Get the business object format and ensure it exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getCustomDdlKey().getNamespace(), request.getCustomDdlKey().getBusinessObjectDefinitionName(), request.getCustomDdlKey().getBusinessObjectFormatUsage(), request.getCustomDdlKey().getBusinessObjectFormatFileType(), request.getCustomDdlKey().getBusinessObjectFormatVersion()));
    // Ensure a custom DDL with the specified name doesn't already exist for the specified business object format.
    CustomDdlEntity customDdlEntity = customDdlDao.getCustomDdlByKey(request.getCustomDdlKey());
    if (customDdlEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create custom DDL with name \"%s\" because it already exists for the business object format {%s}.", request.getCustomDdlKey().getCustomDdlName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
    }
    // Create a custom DDL entity from the request information.
    customDdlEntity = createCustomDdlEntity(businessObjectFormatEntity, request);
    // Persist the new entity.
    customDdlEntity = customDdlDao.saveAndRefresh(customDdlEntity);
    // Create and return the custom DDL object from the persisted entity.
    return createCustomDdlFromEntity(customDdlEntity);
}
Also used : CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 2 with CustomDdlEntity

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

the class CustomDdlServiceImpl method getCustomDdl.

/**
 * Gets an existing custom DDL by key.
 *
 * @param customDdlKey the custom DDL key
 *
 * @return the custom DDL information
 */
@NamespacePermission(fields = "#customDdlKey.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public CustomDdl getCustomDdl(CustomDdlKey customDdlKey) {
    // Validate and trim the key.
    customDdlHelper.validateCustomDdlKey(customDdlKey);
    // Retrieve and ensure that a custom DDL exists with the specified key.
    CustomDdlEntity customDdlEntity = customDdlDaoHelper.getCustomDdlEntity(customDdlKey);
    // Create and return the custom DDL object from the persisted entity.
    return createCustomDdlFromEntity(customDdlEntity);
}
Also used : CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 3 with CustomDdlEntity

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

the class CustomDdlServiceImpl method createCustomDdlEntity.

/**
 * Creates a new custom DDL entity from the business object format entity and the request information.
 *
 * @param businessObjectFormatEntity the business object format entity
 * @param request the custom DDL create request
 *
 * @return the newly created custom DDL entity
 */
private CustomDdlEntity createCustomDdlEntity(BusinessObjectFormatEntity businessObjectFormatEntity, CustomDdlCreateRequest request) {
    // Create a new entity.
    CustomDdlEntity customDdlEntity = new CustomDdlEntity();
    customDdlEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    customDdlEntity.setCustomDdlName(request.getCustomDdlKey().getCustomDdlName());
    customDdlEntity.setDdl(request.getDdl());
    return customDdlEntity;
}
Also used : CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity)

Example 4 with CustomDdlEntity

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

the class CustomDdlServiceTest method testUpdateCustomDdl.

@Test
public void testUpdateCustomDdl() {
    // Create and persist a custom DDL entity.
    CustomDdlEntity customDdlEntity = customDdlDaoTestHelper.createCustomDdlEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME, TEST_DDL);
    // Update the custom DDL.
    CustomDdl updatedCustomDdl = customDdlService.updateCustomDdl(new CustomDdlKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME), customDdlServiceTestHelper.createCustomDdlUpdateRequest(TEST_DDL_2));
    // Validate the returned object.
    customDdlServiceTestHelper.validateCustomDdl(customDdlEntity.getId(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME, TEST_DDL_2, updatedCustomDdl);
}
Also used : CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) CustomDdl(org.finra.herd.model.api.xml.CustomDdl) CustomDdlKey(org.finra.herd.model.api.xml.CustomDdlKey) Test(org.junit.Test)

Example 5 with CustomDdlEntity

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

the class CustomDdlServiceTest method testUpdateCustomDdlUpperCaseParameters.

@Test
public void testUpdateCustomDdlUpperCaseParameters() {
    // Create and persist a custom DDL entity using lower case values.
    CustomDdlEntity customDdlEntity = customDdlDaoTestHelper.createCustomDdlEntity(NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, CUSTOM_DDL_NAME.toLowerCase(), TEST_DDL.toLowerCase());
    // Update the custom DDL using upper case input parameters.
    CustomDdl updatedCustomDdl = customDdlService.updateCustomDdl(new CustomDdlKey(NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, CUSTOM_DDL_NAME.toUpperCase()), customDdlServiceTestHelper.createCustomDdlUpdateRequest(TEST_DDL_2.toUpperCase()));
    // Validate the returned object.
    customDdlServiceTestHelper.validateCustomDdl(customDdlEntity.getId(), NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, CUSTOM_DDL_NAME.toLowerCase(), TEST_DDL_2.toUpperCase(), updatedCustomDdl);
}
Also used : CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) CustomDdl(org.finra.herd.model.api.xml.CustomDdl) CustomDdlKey(org.finra.herd.model.api.xml.CustomDdlKey) Test(org.junit.Test)

Aggregations

CustomDdlEntity (org.finra.herd.model.jpa.CustomDdlEntity)23 CustomDdlKey (org.finra.herd.model.api.xml.CustomDdlKey)16 Test (org.junit.Test)13 CustomDdl (org.finra.herd.model.api.xml.CustomDdl)12 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)5 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)3 ArrayList (java.util.ArrayList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)2 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 HashMap (java.util.HashMap)1 Tuple (javax.persistence.Tuple)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 BusinessObjectDataDdl (org.finra.herd.model.api.xml.BusinessObjectDataDdl)1 BusinessObjectFormatDdl (org.finra.herd.model.api.xml.BusinessObjectFormatDdl)1 StorageEntity (org.finra.herd.model.jpa.StorageEntity)1 DdlGenerator (org.finra.herd.service.helper.DdlGenerator)1