Search in sources :

Example 31 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class EmrClusterDefinitionServiceImpl method getEmrClusterDefinition.

@NamespacePermission(fields = "#emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public EmrClusterDefinitionInformation getEmrClusterDefinition(EmrClusterDefinitionKey emrClusterDefinitionKey) throws Exception {
    // Perform validate and trim of the EMR cluster definition key.
    emrClusterDefinitionHelper.validateEmrClusterDefinitionKey(emrClusterDefinitionKey);
    // Retrieve and ensure that a EMR cluster definition exists with the specified key.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey);
    // Create and return the EMR cluster definition object from the persisted entity.
    return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
Also used : EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 32 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class EmrClusterDefinitionServiceImpl method createEmrClusterDefinition.

@NamespacePermission(fields = "#request?.emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public EmrClusterDefinitionInformation createEmrClusterDefinition(EmrClusterDefinitionCreateRequest request) throws Exception {
    // Perform validate and trim of the EMR cluster definition key.
    emrClusterDefinitionHelper.validateEmrClusterDefinitionKey(request.getEmrClusterDefinitionKey());
    // Validate the EMR cluster definition configuration.
    emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(request.getEmrClusterDefinition());
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getEmrClusterDefinitionKey().getNamespace());
    namespaceIamRoleAuthorizationHelper.checkPermissions(namespaceEntity, request.getEmrClusterDefinition().getServiceIamRole(), request.getEmrClusterDefinition().getEc2NodeIamProfileName());
    // Ensure a EMR cluster definition with the specified name doesn't already exist.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(request.getEmrClusterDefinitionKey());
    if (emrClusterDefinitionEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create EMR cluster definition with name \"%s\" for namespace \"%s\" because it already exists.", request.getEmrClusterDefinitionKey().getEmrClusterDefinitionName(), request.getEmrClusterDefinitionKey().getNamespace()));
    }
    // Create a EMR cluster definition entity from the request information.
    emrClusterDefinitionEntity = createEmrClusterDefinitionEntity(namespaceEntity, request);
    // Persist the new entity.
    emrClusterDefinitionEntity = emrClusterDefinitionDao.saveAndRefresh(emrClusterDefinitionEntity);
    // Create and return the EMR cluster definition object from the persisted entity.
    return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 33 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class EmrClusterDefinitionServiceImpl method updateEmrClusterDefinition.

@NamespacePermission(fields = "#emrClusterDefinitionKey?.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public EmrClusterDefinitionInformation updateEmrClusterDefinition(EmrClusterDefinitionKey emrClusterDefinitionKey, EmrClusterDefinitionUpdateRequest request) throws Exception {
    // Perform validate and trim of the EMR cluster definition key.
    emrClusterDefinitionHelper.validateEmrClusterDefinitionKey(emrClusterDefinitionKey);
    // Validate the EMR cluster definition configuration.
    emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(request.getEmrClusterDefinition());
    // Retrieve and ensure that a EMR cluster definition already exists with the specified name.
    EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey);
    namespaceIamRoleAuthorizationHelper.checkPermissions(emrClusterDefinitionEntity.getNamespace(), request.getEmrClusterDefinition().getServiceIamRole(), request.getEmrClusterDefinition().getEc2NodeIamProfileName());
    // Log the existing EMR cluster definition before the update.
    LOGGER.info("Logging EMR cluster definition before the update. emrClusterDefinition={}", xmlHelper.objectToXml(createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity), true));
    // Convert EMR cluster configuration to the XML representation.
    String emrClusterConfiguration = xmlHelper.objectToXml(request.getEmrClusterDefinition());
    // Update the EMR cluster definition entity.
    emrClusterDefinitionEntity.setConfiguration(emrClusterConfiguration);
    // Persist and refresh the entity.
    emrClusterDefinitionEntity = emrClusterDefinitionDao.saveAndRefresh(emrClusterDefinitionEntity);
    // Create and return the EMR cluster definition object from the persisted entity.
    return createEmrClusterDefinitionFromEntity(emrClusterDefinitionEntity);
}
Also used : EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 34 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class AllowedAttributeValueServiceImpl method deleteAllowedAttributeValues.

/**
 * Deletes specified allowed attribute values from an existing attribute value list which is identified by name.
 *
 * @param request the information needed to delete the allowed attribute values
 *
 * @return the allowed attribute values that got deleted
 */
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public AllowedAttributeValuesInformation deleteAllowedAttributeValues(AllowedAttributeValuesDeleteRequest request) {
    // Perform request validation and trim request parameters.
    validateAllowedAttributeValuesDeleteRequest(request);
    // Retrieve and ensure that a attribute value list exists with the specified name.
    AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(request.getAttributeValueListKey());
    // Load all existing allowed attribute value entities into a map for quick access.
    Map<String, AllowedAttributeValueEntity> allowedAttributeValueEntityMap = getAllowedAttributeValueEntityMap(attributeValueListEntity.getAllowedAttributeValues());
    // Build a list of all allowed attribute value entities to be deleted.
    Collection<AllowedAttributeValueEntity> deletedAllowedAttributeValueEntities = new ArrayList<>();
    for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
        // Find the relative allowed attribute entity.
        AllowedAttributeValueEntity allowedAttributeValueEntity = allowedAttributeValueEntityMap.get(allowedAttributeValue);
        if (allowedAttributeValueEntity != null) {
            deletedAllowedAttributeValueEntities.add(allowedAttributeValueEntity);
        } else {
            throw new ObjectNotFoundException(String.format("Allowed attribute value \"%s\" doesn't exist in \"%s\" attribute value list.", allowedAttributeValue, attributeValueListEntity.getName()));
        }
    }
    // Perform the actual deletion.
    for (AllowedAttributeValueEntity allowedAttributeValueEntity : deletedAllowedAttributeValueEntities) {
        attributeValueListEntity.getAllowedAttributeValues().remove(allowedAttributeValueEntity);
    }
    allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
    return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, deletedAllowedAttributeValueEntities);
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ArrayList(java.util.ArrayList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 35 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class AllowedAttributeValueServiceImpl method createAllowedAttributeValues.

/**
 * Creates a list of allowed attribute values for an existing attribute value list key.
 *
 * @param request the information needed to create the allowed attribute values
 *
 * @return the newly created allowed attribute values
 */
@NamespacePermission(fields = "#request.attributeValueListKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public AllowedAttributeValuesInformation createAllowedAttributeValues(AllowedAttributeValuesCreateRequest request) {
    // Perform request validation and trim request parameters.
    validateAllowedAttributeValuesCreateRequest(request);
    // Retrieve and ensure that a attribute value list exists with the specified name.
    AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(request.getAttributeValueListKey());
    // Load all existing allowed attribute value entities into a map for quick access.
    Map<String, AllowedAttributeValueEntity> allowedAttributeValueEntityMap = getAllowedAttributeValueEntityMap(attributeValueListEntity.getAllowedAttributeValues());
    // Fail if any of the allowed attribute values to be created already exist.
    for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
        if (allowedAttributeValueEntityMap.containsKey(allowedAttributeValue)) {
            throw new AlreadyExistsException(String.format("Allowed attribute value \"%s\" already exists in \"%s\" attribute value list.", allowedAttributeValue, attributeValueListEntity.getName()));
        }
    }
    // Create and persist the allowed attribute value entities.
    Collection<AllowedAttributeValueEntity> createdAllowedAttributeValueEntities = new ArrayList<>();
    for (String allowedAttributeValue : request.getAllowedAttributeValues()) {
        AllowedAttributeValueEntity allowedAttributeValueEntity = new AllowedAttributeValueEntity();
        createdAllowedAttributeValueEntities.add(allowedAttributeValueEntity);
        allowedAttributeValueEntity.setAttributeValueList(attributeValueListEntity);
        allowedAttributeValueEntity.setAllowedAttributeValue(allowedAttributeValue);
        allowedAttributeValueDao.saveAndRefresh(allowedAttributeValueEntity);
    }
    allowedAttributeValueDao.saveAndRefresh(attributeValueListEntity);
    return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, createdAllowedAttributeValueEntities);
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) ArrayList(java.util.ArrayList) AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Aggregations

NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)63 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)10 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)10 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)10 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)9 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)5 CustomDdlEntity (org.finra.herd.model.jpa.CustomDdlEntity)5 Credentials (com.amazonaws.services.securitytoken.model.Credentials)4 ArrayList (java.util.ArrayList)4 PublishNotificationMessages (org.finra.herd.model.annotation.PublishNotificationMessages)4 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)4 IamRole (org.finra.herd.model.api.xml.IamRole)4 NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)4 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)4 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)4 UserNamespaceAuthorizationEntity (org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3