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());
}
}
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());
}
}
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);
}
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);
}
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);
}
Aggregations