Search in sources :

Example 6 with BusinessObjectDefinitionEntity

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

the class BusinessObjectDefinitionServiceImpl method getBusinessObjectDefinitionImpl.

/**
 * Gets a business object definition for the specified key.
 *
 * @param businessObjectDefinitionKey the business object definition key
 * @param includeBusinessObjectDefinitionUpdateHistory a flag to include change event information or not
 *
 * @return the business object definition.
 */
protected BusinessObjectDefinition getBusinessObjectDefinitionImpl(BusinessObjectDefinitionKey businessObjectDefinitionKey, Boolean includeBusinessObjectDefinitionUpdateHistory) {
    // Perform validation and trim.
    businessObjectDefinitionHelper.validateBusinessObjectDefinitionKey(businessObjectDefinitionKey);
    // Retrieve and ensure that a business object definition already exists with the specified key.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
    // Create and return the business object definition object from the persisted entity.
    return createBusinessObjectDefinitionFromEntity(businessObjectDefinitionEntity, includeBusinessObjectDefinitionUpdateHistory);
}
Also used : BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)

Example 7 with BusinessObjectDefinitionEntity

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

the class BusinessObjectDefinitionTagServiceImpl method getBusinessObjectDefinitionTagsByBusinessObjectDefinition.

@Override
public BusinessObjectDefinitionTagKeys getBusinessObjectDefinitionTagsByBusinessObjectDefinition(BusinessObjectDefinitionKey businessObjectDefinitionKey) {
    // Validate the business object definition key.
    businessObjectDefinitionHelper.validateBusinessObjectDefinitionKey(businessObjectDefinitionKey);
    // Get the business object definition entity and ensure it exists.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
    // Retrieve and return a list of business object definition tag keys.
    return new BusinessObjectDefinitionTagKeys(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity(businessObjectDefinitionEntity));
}
Also used : BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDefinitionTagKeys(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKeys)

Example 8 with BusinessObjectDefinitionEntity

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

the class BusinessObjectDefinitionTagServiceImpl method createBusinessObjectDefinitionTag.

@NamespacePermission(fields = "#request.businessObjectDefinitionTagKey.businessObjectDefinitionKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionTag createBusinessObjectDefinitionTag(BusinessObjectDefinitionTagCreateRequest request) {
    // Validate and trim the business object definition tag create request.
    validateBusinessObjectDefinitionTagCreateRequest(request);
    // Get the business object definition entity and ensure it exists.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(request.getBusinessObjectDefinitionTagKey().getBusinessObjectDefinitionKey());
    // Get the tag entity and ensure it exists.
    TagEntity tagEntity = tagDaoHelper.getTagEntity(request.getBusinessObjectDefinitionTagKey().getTagKey());
    // Ensure a business object definition tag for the specified business object definition and tag doesn't already exist.
    if (businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByParentEntities(businessObjectDefinitionEntity, tagEntity) != null) {
        throw new AlreadyExistsException(String.format("Tag with tag type \"%s\" and code \"%s\" already exists for business object definition {%s}.", request.getBusinessObjectDefinitionTagKey().getTagKey().getTagTypeCode(), request.getBusinessObjectDefinitionTagKey().getTagKey().getTagCode(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(request.getBusinessObjectDefinitionTagKey().getBusinessObjectDefinitionKey())));
    }
    // Create and persist a business object definition tag entity.
    BusinessObjectDefinitionTagEntity businessObjectDefinitionTagEntity = createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagEntity);
    // Notify the search index that a business object definition must be updated.
    searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
    // Create and return the business object definition tag object from the persisted entity.
    return createBusinessObjectDefinitionTagFromEntity(businessObjectDefinitionTagEntity);
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 9 with BusinessObjectDefinitionEntity

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

the class StorageUnitNotificationRegistrationServiceImpl method updateStorageUnitNotificationRegistration.

@NamespacePermissions({ @NamespacePermission(fields = "#notificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration updateStorageUnitNotificationRegistration(NotificationRegistrationKey notificationRegistrationKey, StorageUnitNotificationRegistrationUpdateRequest request) {
    // Validate and trim the key.
    validateStorageUnitNotificationRegistrationKey(notificationRegistrationKey);
    // Validate and trim the request parameters.
    validateStorageUnitNotificationRegistrationUpdateRequest(request);
    // Retrieve and ensure that a storage unit notification exists with the specified key.
    StorageUnitNotificationRegistrationEntity oldStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDaoHelper.getStorageUnitNotificationRegistrationEntity(notificationRegistrationKey);
    String oldStorageUnitNotificationRegistrationName = oldStorageUnitNotificationRegistrationEntity.getName();
    // Retrieve the namespace with the specified namespace code.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
    // Retrieve and validate the notification event type entity.
    NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
    // Get the storage unit notification filter.
    StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
    // Retrieve and ensure that business object definition exists. Since namespace is specified, retrieve a business object definition by it's key.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
    // If specified, retrieve and ensure that file type exists.
    FileTypeEntity fileTypeEntity = null;
    if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
        fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
    }
    // Retrieve and ensure that storage exists.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
    // If specified, retrieve and ensure that new storage unit status exists.
    StorageUnitStatusEntity newStorageUnitStatus = null;
    if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
        newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
    }
    // If specified, retrieve and ensure that old storage unit status exists.
    StorageUnitStatusEntity oldStorageUnitStatus = null;
    if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
        oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
    }
    // TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
    for (JobAction jobAction : request.getJobActions()) {
        // Ensure that job definition exists.
        jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
    }
    // Retrieve and validate the notification registration status entity.
    NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(request.getNotificationRegistrationStatus());
    // Delete the storage unit notification.
    storageUnitNotificationRegistrationDao.delete(oldStorageUnitNotificationRegistrationEntity);
    // Create a storage unit notification registration entity from the request information.
    StorageUnitNotificationRegistrationEntity newStorageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, new NotificationRegistrationKey(namespaceEntity.getCode(), oldStorageUnitNotificationRegistrationName), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
    // Persist the new entity.
    newStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(newStorageUnitNotificationRegistrationEntity);
    // Create and return the storage unit notification object from the persisted entity.
    return createStorageUnitNotificationFromEntity(newStorageUnitNotificationRegistrationEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) JobAction(org.finra.herd.model.api.xml.JobAction) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) StorageUnitNotificationFilter(org.finra.herd.model.api.xml.StorageUnitNotificationFilter) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) NamespacePermissions(org.finra.herd.model.annotation.NamespacePermissions)

Example 10 with BusinessObjectDefinitionEntity

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

the class StorageUnitNotificationRegistrationServiceImpl method createStorageUnitNotificationRegistration.

@NamespacePermissions({ @NamespacePermission(fields = "#request?.storageUnitNotificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration createStorageUnitNotificationRegistration(StorageUnitNotificationRegistrationCreateRequest request) {
    // Validate and trim the request parameters.
    validateStorageUnitNotificationRegistrationCreateRequest(request);
    // Get the notification registration key.
    NotificationRegistrationKey notificationRegistrationKey = request.getStorageUnitNotificationRegistrationKey();
    // Retrieve and ensure that notification registration namespace exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
    // Retrieve and validate the notification event type entity.
    NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
    // Validate the notification event type.
    Assert.isTrue(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name().equalsIgnoreCase(request.getStorageUnitEventType()), String.format("Notification event type \"%s\" is not supported for storage unit notification registration.", request.getStorageUnitEventType()));
    // Get the storage unit notification filter.
    StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
    // Retrieve and ensure that business object definition exists.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
    // If specified, retrieve and ensure that file type exists.
    FileTypeEntity fileTypeEntity = null;
    if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
        fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
    }
    // Retrieve and ensure that storage exists.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
    // If specified, retrieve and ensure that new storage unit status exists.
    StorageUnitStatusEntity newStorageUnitStatus = null;
    if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
        newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
    }
    // If specified, retrieve and ensure that old storage unit status exists.
    StorageUnitStatusEntity oldStorageUnitStatus = null;
    if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
        oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
    }
    // TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
    for (JobAction jobAction : request.getJobActions()) {
        // Ensure that job definition exists.
        jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
    }
    // If specified, retrieve and validate the notification registration status entity. Otherwise, default it to ENABLED.
    NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(StringUtils.isNotBlank(request.getNotificationRegistrationStatus()) ? request.getNotificationRegistrationStatus() : NotificationRegistrationStatusEntity.ENABLED);
    // Ensure a storage unit notification with the specified name doesn't already exist for the specified namespace.
    StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrationByAltKey(notificationRegistrationKey);
    if (storageUnitNotificationRegistrationEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create storage unit notification with name \"%s\" because it already exists for namespace \"%s\".", notificationRegistrationKey.getNotificationName(), notificationRegistrationKey.getNamespace()));
    }
    // Create a storage unit notification registration entity from the request information.
    storageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, request.getStorageUnitNotificationRegistrationKey(), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
    // Persist the new entity.
    storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(storageUnitNotificationRegistrationEntity);
    // Create and return the storage unit notification object from the persisted entity.
    return createStorageUnitNotificationFromEntity(storageUnitNotificationRegistrationEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) JobAction(org.finra.herd.model.api.xml.JobAction) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) StorageUnitNotificationFilter(org.finra.herd.model.api.xml.StorageUnitNotificationFilter) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) NamespacePermissions(org.finra.herd.model.annotation.NamespacePermissions)

Aggregations

BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)164 Test (org.junit.Test)78 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)75 ArrayList (java.util.ArrayList)54 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)40 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)39 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)38 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)33 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)32 Predicate (javax.persistence.criteria.Predicate)31 StorageEntity (org.finra.herd.model.jpa.StorageEntity)23 Attribute (org.finra.herd.model.api.xml.Attribute)19 BusinessObjectDefinitionCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest)15 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)15 TagEntity (org.finra.herd.model.jpa.TagEntity)15 SearchIndexUpdateDto (org.finra.herd.model.dto.SearchIndexUpdateDto)13 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)12 BusinessObjectDefinitionTagEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity)12 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)12 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)10