/** * Asserts that no NamespaceIamRoleAuthorizationEntities exist for the given namespace. Throws a AlreadyExistsException if any * NamespaceIamRoleAuthorizationEntity exist. * * @param namespaceEntity The namespace entity */ private void assertNamespaceIamRoleAuthorizationNotExist(NamespaceEntity namespaceEntity) { if (CollectionUtils.isNotEmpty(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity))) { throw new AlreadyExistsException(String.format("Namespace IAM role authorizations with namespace \"%s\" already exist", namespaceEntity.getCode())); } }
/** * Asserts that no NamespaceIamRoleAuthorizationEntities exist for the given namespace. Throws a AlreadyExistsException if any * NamespaceIamRoleAuthorizationEntity exist. * * @param namespaceEntity The namespace entity */ private void assertNamespaceIamRoleAuthorizationNotExist(NamespaceEntity namespaceEntity) { if (CollectionUtils.isNotEmpty(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity))) { throw new AlreadyExistsException(String.format("Namespace IAM role authorizations with namespace \"%s\" already exist", namespaceEntity.getCode())); } }
/** * Gets a tag type entity by its display name and ensure it doesn't already exist. * * @param displayName the tag display name (case insensitive) * * @throws AlreadyExistsException if the tag type entity already exists */ public void assertTagTypeDisplayNameDoesNotExist(String displayName) throws AlreadyExistsException { TagTypeEntity tagTypeEntity = tagTypeDao.getTagTypeByDisplayName(displayName); if (tagTypeEntity != null) { throw new AlreadyExistsException(String.format("Display name \"%s\" already exists for tag type \"%s\".", displayName, tagTypeEntity.getCode())); } } }
/** * Gets a tag type entity by its display name and ensure it doesn't already exist. * * @param displayName the tag display name (case insensitive) * * @throws AlreadyExistsException if the tag type entity already exists */ public void assertTagTypeDisplayNameDoesNotExist(String displayName) throws AlreadyExistsException { TagTypeEntity tagTypeEntity = tagTypeDao.getTagTypeByDisplayName(displayName); if (tagTypeEntity != null) { throw new AlreadyExistsException(String.format("Display name \"%s\" already exists for tag type \"%s\".", displayName, tagTypeEntity.getCode())); } } }
/** * Gets a global Attribute Definition entity and checks if it already exists. * * @param globalAttributeDefinitionKey the global Attribute Definition key (case insensitive) * * @throws AlreadyExistsException if the global Attribute Definition entity already exist */ public void validateGlobalAttributeDefinitionNoExists(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) throws AlreadyExistsException { // Validate that the global attribute definition entity does not already exist. if (globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey) != null) { throw new AlreadyExistsException(String.format("Unable to create global attribute definition with global attribute definition level \"%s\" and " + "global attribute definition name \"%s\" because it already exists.", globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel(), globalAttributeDefinitionKey.getGlobalAttributeDefinitionName())); } }
/** * Gets a global Attribute Definition entity and checks if it already exists. * * @param globalAttributeDefinitionKey the global Attribute Definition key (case insensitive) * * @throws AlreadyExistsException if the global Attribute Definition entity already exist */ public void validateGlobalAttributeDefinitionNoExists(GlobalAttributeDefinitionKey globalAttributeDefinitionKey) throws AlreadyExistsException { // Validate that the global attribute definition entity does not already exist. if (globalAttributeDefinitionDao.getGlobalAttributeDefinitionByKey(globalAttributeDefinitionKey) != null) { throw new AlreadyExistsException(String.format("Unable to create global attribute definition with global attribute definition level \"%s\" and " + "global attribute definition name \"%s\" because it already exists.", globalAttributeDefinitionKey.getGlobalAttributeDefinitionLevel(), globalAttributeDefinitionKey.getGlobalAttributeDefinitionName())); } }
/** * Ensures that a tag entity does not exist for a specified tag type code and display name. * * @param tagCode the specified tag type code. * @param displayName the specified display name. */ public void assertDisplayNameDoesNotExistForTag(String tagCode, String displayName) { TagEntity tagEntity = tagDao.getTagByTagTypeAndDisplayName(tagCode, displayName); if (tagEntity != null) { throw new AlreadyExistsException(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", displayName, tagEntity.getTagType().getCode(), tagEntity.getTagCode())); } }
/** * Ensures that a tag entity does not exist for a specified tag type code and display name. * * @param tagCode the specified tag type code. * @param displayName the specified display name. */ public void assertDisplayNameDoesNotExistForTag(String tagCode, String displayName) { TagEntity tagEntity = tagDao.getTagByTagTypeAndDisplayName(tagCode, displayName); if (tagEntity != null) { throw new AlreadyExistsException(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", displayName, tagEntity.getTagType().getCode(), tagEntity.getTagCode())); } }
@Test public void testExceptionThrowableConstructor() throws Exception { Exception exception = new Exception(TEST_MESSAGE_2); AlreadyExistsException alreadyExistsException = new AlreadyExistsException(exception); assertTrue(alreadyExistsException.getCause().getMessage().equals(TEST_MESSAGE_2)); } }
@Test public void testExceptionMessageConstructor() throws Exception { AlreadyExistsException exception = new AlreadyExistsException(TEST_MESSAGE_1); assertTrue(exception.getMessage().equals(TEST_MESSAGE_1)); }
@Test public void testExceptionMessageAndThrowableConstructor() throws Exception { Exception exception = new Exception(TEST_MESSAGE_2); AlreadyExistsException alreadyExistsException = new AlreadyExistsException(TEST_MESSAGE_1, exception); assertTrue(alreadyExistsException.getMessage().equals(TEST_MESSAGE_1)); assertTrue(alreadyExistsException.getCause().getMessage().equals(TEST_MESSAGE_2)); }
@Override public SecurityFunction createSecurityFunction(SecurityFunctionCreateRequest request) { // Perform the validation. validateSecurityFunctionCreateRequest(request); // Ensure a security function with the specified security function name doesn't already exist. SecurityFunctionEntity securityFunctionEntity = securityFunctionDao.getSecurityFunctionByName(request.getSecurityFunctionName()); if (securityFunctionEntity != null) { throw new AlreadyExistsException( String.format("Unable to create security function \"%s\" because it already exists.", request.getSecurityFunctionName())); } // Create a security function entity from the request information. securityFunctionEntity = createSecurityFunctionEntity(request); // Persist the new entity. securityFunctionEntity = securityFunctionDao.saveAndRefresh(securityFunctionEntity); // Create and return the security function object from the persisted entity. return createSecurityFunctionFromEntity(securityFunctionEntity); }
@Override public FileType createFileType(FileTypeCreateRequest fileTypeCreateRequest) { // Perform the validation. validateFileTypeCreateRequest(fileTypeCreateRequest); // Ensure a file type with the specified file type code doesn't already exist. FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(fileTypeCreateRequest.getFileTypeCode()); if (fileTypeEntity != null) { throw new AlreadyExistsException( String.format("Unable to create file type \"%s\" because it already exists.", fileTypeCreateRequest.getFileTypeCode())); } // Create a file type entity from the request information. fileTypeEntity = createFileTypeEntity(fileTypeCreateRequest); // Persist the new entity. fileTypeEntity = fileTypeDao.saveAndRefresh(fileTypeEntity); // Create and return the file type object from the persisted entity. return createFileTypeFromEntity(fileTypeEntity); }
@Override public SecurityFunction createSecurityFunction(SecurityFunctionCreateRequest request) { // Perform the validation. validateSecurityFunctionCreateRequest(request); // Ensure a security function with the specified security function name doesn't already exist. SecurityFunctionEntity securityFunctionEntity = securityFunctionDao.getSecurityFunctionByName(request.getSecurityFunctionName()); if (securityFunctionEntity != null) { throw new AlreadyExistsException( String.format("Unable to create security function \"%s\" because it already exists.", request.getSecurityFunctionName())); } // Create a security function entity from the request information. securityFunctionEntity = createSecurityFunctionEntity(request); // Persist the new entity. securityFunctionEntity = securityFunctionDao.saveAndRefresh(securityFunctionEntity); // Create and return the security function object from the persisted entity. return createSecurityFunctionFromEntity(securityFunctionEntity); }
@Override public FileType createFileType(FileTypeCreateRequest fileTypeCreateRequest) { // Perform the validation. validateFileTypeCreateRequest(fileTypeCreateRequest); // Ensure a file type with the specified file type code doesn't already exist. FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(fileTypeCreateRequest.getFileTypeCode()); if (fileTypeEntity != null) { throw new AlreadyExistsException( String.format("Unable to create file type \"%s\" because it already exists.", fileTypeCreateRequest.getFileTypeCode())); } // Create a file type entity from the request information. fileTypeEntity = createFileTypeEntity(fileTypeCreateRequest); // Persist the new entity. fileTypeEntity = fileTypeDao.saveAndRefresh(fileTypeEntity); // Create and return the file type object from the persisted entity. return createFileTypeFromEntity(fileTypeEntity); }
@Test public void testAlreadyExists() throws Exception { validateErrorInformation(exceptionHandler.handleConflictException(new AlreadyExistsException(MESSAGE)), HttpStatus.CONFLICT); }
@Test public void testExceptionNoArgConstructor() throws Exception { AlreadyExistsException exception = new AlreadyExistsException(); assertTrue(exception.getMessage() == null); }
@Override public TagType createTagType(TagTypeCreateRequest request) { // Validate and trim the request parameters. validateTagTypeCreateRequest(request); // Validate the tag type does not already exist in the database. if (tagTypeDao.getTagTypeByKey(request.getTagTypeKey()) != null) { throw new AlreadyExistsException( String.format("Unable to create tag type with code \"%s\" because it already exists.", request.getTagTypeKey().getTagTypeCode())); } // Validate the display name does not already exist in the database tagTypeDaoHelper.assertTagTypeDisplayNameDoesNotExist(request.getDisplayName()); // Create and persist a new tag type entity from the request information. TagTypeEntity tagTypeEntity = createTagTypeEntity(request); // Create and return the tag type object from the persisted entity. return createTagTypeFromEntity(tagTypeEntity); }
@Override public TagType createTagType(TagTypeCreateRequest request) { // Validate and trim the request parameters. validateTagTypeCreateRequest(request); // Validate the tag type does not already exist in the database. if (tagTypeDao.getTagTypeByKey(request.getTagTypeKey()) != null) { throw new AlreadyExistsException( String.format("Unable to create tag type with code \"%s\" because it already exists.", request.getTagTypeKey().getTagTypeCode())); } // Validate the display name does not already exist in the database tagTypeDaoHelper.assertTagTypeDisplayNameDoesNotExist(request.getDisplayName()); // Create and persist a new tag type entity from the request information. TagTypeEntity tagTypeEntity = createTagTypeEntity(request); // Create and return the tag type object from the persisted entity. return createTagTypeFromEntity(tagTypeEntity); }
@Override public ExternalInterface createExternalInterface(ExternalInterfaceCreateRequest request) { // Perform the validation. validateExternalInterfaceCreateRequest(request); // Ensure an external interface with the specified external interface name doesn't already exist. ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDao.getExternalInterfaceByName(request.getExternalInterfaceKey().getExternalInterfaceName()); if (externalInterfaceEntity != null) { throw new AlreadyExistsException(String .format("Unable to create external interface \"%s\" because it already exists.", request.getExternalInterfaceKey().getExternalInterfaceName())); } // Create an external interface entity from the request information. externalInterfaceEntity = createExternalInterfaceEntity(request); // Persist the new entity. externalInterfaceEntity = externalInterfaceDao.saveAndRefresh(externalInterfaceEntity); // Create and return the external interface object from the persisted entity. return createExternalInterfaceFromEntity(externalInterfaceEntity); }