Search in sources :

Example 56 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class TagTypeServiceTest method testCreateTagTypeDisplayNameAlreadyExists.

@Test
public void testCreateTagTypeDisplayNameAlreadyExists() {
    // Create and persist a tag type entity.
    tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Try to create a duplicate tag type instance (uses the same display name).
    try {
        tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE_2), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2));
        fail();
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Display name \"%s\" already exists for tag type \"%s\".", TAG_TYPE_DISPLAY_NAME, TAG_TYPE), e.getMessage());
    }
}
Also used : TagTypeCreateRequest(org.finra.herd.model.api.xml.TagTypeCreateRequest) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 57 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class TagTypeServiceTest method testCreateTagTypeTagTypeAlreadyExists.

@Test
public void testCreateTagTypeTagTypeAlreadyExists() {
    // Create and persist a tag type entity.
    tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Try to create a duplicate tag type instance (uses the same tag type code).
    try {
        tagTypeService.createTagType(new TagTypeCreateRequest(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2));
        fail();
    } catch (AlreadyExistsException e) {
        assertEquals(String.format("Unable to create tag type with code \"%s\" because it already exists.", TAG_TYPE), e.getMessage());
    }
}
Also used : TagTypeCreateRequest(org.finra.herd.model.api.xml.TagTypeCreateRequest) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 58 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class JobDefinitionServiceImpl method createJobDefinition.

/**
 * Creates a new business object definition.
 *
 * @param request the business object definition create request.
 * @param enforceAsync True to enforce first task is async, false to ignore
 *
 * @return the created business object definition.
 */
@NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public JobDefinition createJobDefinition(JobDefinitionCreateRequest request, boolean enforceAsync) throws Exception {
    // Perform the validation.
    validateJobDefinitionCreateRequest(request);
    if (enforceAsync) {
        assertFirstTaskIsAsync(activitiHelper.constructBpmnModelFromXmlAndValidate(request.getActivitiJobXml()));
    }
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
    // Ensure a job definition with the specified name doesn't already exist.
    JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(request.getNamespace(), request.getJobName());
    if (jobDefinitionEntity != null) {
        throw new AlreadyExistsException("Unable to create job definition with name \"" + request.getJobName() + "\" because it already exists for namespace \"" + request.getNamespace() + "\".");
    }
    // Create the new process definition.
    ProcessDefinition processDefinition = createProcessDefinition(request.getNamespace(), request.getJobName(), request.getActivitiJobXml());
    // Create a job definition entity from the request information.
    jobDefinitionEntity = createOrUpdateJobDefinitionEntity(null, namespaceEntity, request.getJobName(), request.getDescription(), processDefinition.getId(), request.getParameters(), request.getS3PropertiesLocation());
    // Persist the new entity.
    jobDefinitionEntity = jobDefinitionDao.saveAndRefresh(jobDefinitionEntity);
    // Create and return the job definition from the persisted entity.
    return createJobDefinitionFromEntity(jobDefinitionEntity);
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 59 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class TagServiceImpl method createTag.

@Override
public Tag createTag(TagCreateRequest request) {
    // Validate and trim the request parameters.
    validateTagCreateRequest(request);
    // Get the tag type and ensure it exists.
    TagTypeEntity tagTypeEntity = tagTypeDaoHelper.getTagTypeEntity(new TagTypeKey(request.getTagKey().getTagTypeCode()));
    // Validate that the tag entity does not already exist.
    if (tagDao.getTagByKey(request.getTagKey()) != null) {
        throw new AlreadyExistsException(String.format("Unable to create tag with tag type code \"%s\" and tag code \"%s\" because it already exists.", request.getTagKey().getTagTypeCode(), request.getTagKey().getTagCode()));
    }
    // List of tag entities to update in the search index
    List<TagEntity> tagEntities = new ArrayList<>();
    // Validate that the specified display name does not already exist for the specified tag type
    tagDaoHelper.assertDisplayNameDoesNotExistForTag(request.getTagKey().getTagTypeCode(), request.getDisplayName());
    TagEntity parentTagEntity = null;
    if (request.getParentTagKey() != null) {
        parentTagEntity = tagDaoHelper.getTagEntity(request.getParentTagKey());
        // Add the parent tag entity to the list of tag entities to update in the search index
        tagEntities.add(parentTagEntity);
    }
    // Create and persist a new tag entity from the information in the request.
    TagEntity tagEntity = createTagEntity(request, tagTypeEntity, parentTagEntity);
    // Notify the tag search index that a tag must be created.
    tagEntities.add(tagEntity);
    searchIndexUpdateHelper.modifyTagsInSearchIndex(tagEntities, SEARCH_INDEX_UPDATE_TYPE_CREATE);
    // Create and return the tag object from the persisted entity.
    return createTagFromEntity(tagEntity);
}
Also used : TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) ArrayList(java.util.ArrayList)

Example 60 with AlreadyExistsException

use of org.finra.herd.model.AlreadyExistsException in project herd by FINRAOS.

the class UserNamespaceAuthorizationServiceImpl method createUserNamespaceAuthorization.

@NamespacePermission(fields = "#request?.userNamespaceAuthorizationKey?.namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public UserNamespaceAuthorization createUserNamespaceAuthorization(UserNamespaceAuthorizationCreateRequest request) {
    // Validate and trim the request parameters.
    validateUserNamespaceAuthorizationCreateRequest(request);
    // Get the user namespace authorization key.
    UserNamespaceAuthorizationKey key = request.getUserNamespaceAuthorizationKey();
    // Ensure a user namespace authorization with the specified name doesn't already exist for the specified namespace.
    UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key);
    if (userNamespaceAuthorizationEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create user namespace authorization with user id \"%s\" and namespace \"%s\" because it already exists.", key.getUserId(), key.getNamespace()));
    }
    // Retrieve and ensure that namespace exists with the specified user namespace authorization namespace code.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(key.getNamespace());
    // Create and persist a new user namespace authorization entity from the request information.
    userNamespaceAuthorizationEntity = createUserNamespaceAuthorizationEntity(key.getUserId(), namespaceEntity, request.getNamespacePermissions());
    // Create and return the user namespace authorization object from the persisted entity.
    return createUserNamespaceAuthorizationFromEntity(userNamespaceAuthorizationEntity);
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Aggregations

AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)62 Test (org.junit.Test)35 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)12 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)11 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)9 ArrayList (java.util.ArrayList)7 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)7 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)6 StorageEntity (org.finra.herd.model.jpa.StorageEntity)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)5 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)5 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)4 StorageFile (org.finra.herd.model.api.xml.StorageFile)4 TagKey (org.finra.herd.model.api.xml.TagKey)4 NamespacePermissions (org.finra.herd.model.annotation.NamespacePermissions)3 AttributeValueListKey (org.finra.herd.model.api.xml.AttributeValueListKey)3 BusinessObjectDataCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest)3 RelationalTableRegistrationCreateRequest (org.finra.herd.model.api.xml.RelationalTableRegistrationCreateRequest)3 TagTypeKey (org.finra.herd.model.api.xml.TagTypeKey)3