/** * Gets a security function entity and ensure it exists. * * @param securityFunctionName the security function name (case insensitive) * * @return the security function entity */ public SecurityFunctionEntity getSecurityFunctionEntity(String securityFunctionName) { SecurityFunctionEntity securityFunctionEntity = securityFunctionDao.getSecurityFunctionByName(securityFunctionName); if (securityFunctionEntity == null) { throw new ObjectNotFoundException(String.format("Security function with name \"%s\" doesn't exist.", securityFunctionName)); } return securityFunctionEntity; } }
/** * Gets record retention type entity form retention type code * * @param retentionTypeCode retention type code * * @return the retention type entity */ public RetentionTypeEntity getRecordRetentionTypeEntity(String retentionTypeCode) { RetentionTypeEntity recordRetentionTypeEntity = retentionTypeDao.getRetentionTypeByCode(retentionTypeCode); if (recordRetentionTypeEntity == null) { throw new ObjectNotFoundException(String.format("Record retention type with code \"%s\" doesn't exist.", retentionTypeCode)); } return recordRetentionTypeEntity; } }
/** * Gets a security role entity and ensure it exists. * * @param securityRoleName the security role name (case insensitive) * * @return the security role entity */ public SecurityRoleEntity getSecurityRoleEntity(String securityRoleName) { SecurityRoleEntity securityRoleEntity = securityRoleDao.getSecurityRoleByName(securityRoleName); if (securityRoleEntity == null) { throw new ObjectNotFoundException(String.format("Security role with name \"%s\" doesn't exist.", securityRoleName)); } return securityRoleEntity; } }
/** * Gets a message type entity by its code and ensure it exists. * * @param code the message type code (case insensitive) * * @return the message type entity */ public MessageTypeEntity getMessageTypeEntity(String code) { MessageTypeEntity messageTypeEntity = messageTypeDao.getMessageTypeByCode(code); if (messageTypeEntity == null) { throw new ObjectNotFoundException(String.format("Message type with code \"%s\" doesn't exist.", code)); } return messageTypeEntity; } }
/** * Gets a storage entity based on the storage name and makes sure that it exists. * * @param storageName the storage name (case insensitive) * * @return the storage entity * @throws ObjectNotFoundException if the storage entity doesn't exist */ public StorageEntity getStorageEntity(String storageName) throws ObjectNotFoundException { StorageEntity storageEntity = storageDao.getStorageByName(storageName); if (storageEntity == null) { throw new ObjectNotFoundException(String.format("Storage with name \"%s\" doesn't exist.", storageName)); } return storageEntity; }
/** * Gets an external interface entity and ensure it exists. * * @param externalInterfaceName the external interface name (case insensitive) * * @return the external interface entity */ public ExternalInterfaceEntity getExternalInterfaceEntity(String externalInterfaceName) { ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDao.getExternalInterfaceByName(externalInterfaceName); if (externalInterfaceEntity == null) { throw new ObjectNotFoundException(String.format("External interface with name \"%s\" doesn't exist.", externalInterfaceName)); } return externalInterfaceEntity; } }
/** * Gets a security function entity and ensure it exists. * * @param securityFunctionName the security function name (case insensitive) * * @return the security function entity */ public SecurityFunctionEntity getSecurityFunctionEntity(String securityFunctionName) { SecurityFunctionEntity securityFunctionEntity = securityFunctionDao.getSecurityFunctionByName(securityFunctionName); if (securityFunctionEntity == null) { throw new ObjectNotFoundException(String.format("Security function with name \"%s\" doesn't exist.", securityFunctionName)); } return securityFunctionEntity; } }
/** * Gets a search index entity by its key and ensure it exists. * * @param searchIndexKey the search index key (case sensitive) * * @return the search index entity * @throws org.finra.herd.model.ObjectNotFoundException if the search index entity doesn't exist */ public SearchIndexEntity getSearchIndexEntity(SearchIndexKey searchIndexKey) throws ObjectNotFoundException { SearchIndexEntity searchIndexEntity = searchIndexDao.getSearchIndexByKey(searchIndexKey); if (searchIndexEntity == null) { throw new ObjectNotFoundException(String.format("Search index with name \"%s\" doesn't exist.", searchIndexKey.getSearchIndexName())); } return searchIndexEntity; }
private SecurityRoleEntity getSecurityRoleEntityByName(SecurityRoleKey securityRoleKey) { SecurityRoleEntity securityRoleEntity = securityRoleDao.getSecurityRoleByName(securityRoleKey.getSecurityRoleName()); if (securityRoleEntity == null) { throw new ObjectNotFoundException(String.format("Security role with name \"%s\" doesn't exist.", securityRoleKey.getSecurityRoleName())); } return securityRoleEntity; } }
private SecurityRoleEntity getSecurityRoleEntityByName(SecurityRoleKey securityRoleKey) { SecurityRoleEntity securityRoleEntity = securityRoleDao.getSecurityRoleByName(securityRoleKey.getSecurityRoleName()); if (securityRoleEntity == null) { throw new ObjectNotFoundException(String.format("Security role with name \"%s\" doesn't exist.", securityRoleKey.getSecurityRoleName())); } return securityRoleEntity; } }
@Override public void validateS3File(S3FileTransferRequestParamsDto params, Long fileSizeInBytes) throws RuntimeException { ObjectMetadata objectMetadata = getObjectMetadata(params); if (objectMetadata == null) { throw new ObjectNotFoundException(String.format("File not found at s3://%s/%s location.", params.getS3BucketName(), params.getS3KeyPrefix())); } Assert.isTrue(fileSizeInBytes == null || Objects.equals(fileSizeInBytes, objectMetadata.getContentLength()), String .format("Specified file size (%d bytes) does not match to the actual file size (%d bytes) reported by S3 for s3://%s/%s file.", fileSizeInBytes, objectMetadata.getContentLength(), params.getS3BucketName(), params.getS3KeyPrefix())); }
@Override public void validateS3File(S3FileTransferRequestParamsDto params, Long fileSizeInBytes) throws RuntimeException { ObjectMetadata objectMetadata = getObjectMetadata(params); if (objectMetadata == null) { throw new ObjectNotFoundException(String.format("File not found at s3://%s/%s location.", params.getS3BucketName(), params.getS3KeyPrefix())); } Assert.isTrue(fileSizeInBytes == null || Objects.equals(fileSizeInBytes, objectMetadata.getContentLength()), String .format("Specified file size (%d bytes) does not match to the actual file size (%d bytes) reported by S3 for s3://%s/%s file.", fileSizeInBytes, objectMetadata.getContentLength(), params.getS3BucketName(), params.getS3KeyPrefix())); }
@Override public SubjectMatterExpert getSubjectMatterExpert(SubjectMatterExpertKey subjectMatterExpertKey) { // Validate and trim the subject matter expert key. validateSubjectMatterExpertKey(subjectMatterExpertKey); // Get the information for the subject matter expert. SubjectMatterExpertContactDetails subjectMatterExpertContactDetails = subjectMatterExpertDao.getSubjectMatterExpertByKey(subjectMatterExpertKey); if (subjectMatterExpertContactDetails == null) { throw new ObjectNotFoundException( String.format("The subject matter expert with user id \"%s\" does not exist.", subjectMatterExpertKey.getUserId())); } // Create and return the subject matter expert. return new SubjectMatterExpert(subjectMatterExpertKey, subjectMatterExpertContactDetails); }
@Override public SubjectMatterExpert getSubjectMatterExpert(SubjectMatterExpertKey subjectMatterExpertKey) { // Validate and trim the subject matter expert key. validateSubjectMatterExpertKey(subjectMatterExpertKey); // Get the information for the subject matter expert. SubjectMatterExpertContactDetails subjectMatterExpertContactDetails = subjectMatterExpertDao.getSubjectMatterExpertByKey(subjectMatterExpertKey); if (subjectMatterExpertContactDetails == null) { throw new ObjectNotFoundException( String.format("The subject matter expert with user id \"%s\" does not exist.", subjectMatterExpertKey.getUserId())); } // Create and return the subject matter expert. return new SubjectMatterExpert(subjectMatterExpertKey, subjectMatterExpertContactDetails); }
@Test public void testExceptionThrowableConstructor() throws Exception { Exception exception = new Exception(TEST_MESSAGE_2); ObjectNotFoundException ObjectNotFoundException = new ObjectNotFoundException(exception); assertTrue(ObjectNotFoundException.getCause().getMessage().equals(TEST_MESSAGE_2)); } }
@Test public void testExceptionMessageAndThrowableConstructor() throws Exception { Exception exception = new Exception(TEST_MESSAGE_2); ObjectNotFoundException ObjectNotFoundException = new ObjectNotFoundException(TEST_MESSAGE_1, exception); assertTrue(ObjectNotFoundException.getMessage().equals(TEST_MESSAGE_1)); assertTrue(ObjectNotFoundException.getCause().getMessage().equals(TEST_MESSAGE_2)); }
@Test public void testExceptionMessageConstructor() throws Exception { ObjectNotFoundException exception = new ObjectNotFoundException(TEST_MESSAGE_1); assertTrue(exception.getMessage().equals(TEST_MESSAGE_1)); }
@Test(expected = ObjectNotFoundException.class) public void testGetStoragePlatformInvalidName() throws Exception { ObjectNotFoundException exception = new ObjectNotFoundException("not found"); String platform = "invalid" + getRandomSuffix(); when(storagePlatformService.getStoragePlatform(platform)).thenThrow(exception); storagePlatformRestController.getStoragePlatform(platform); }
@Test public void testExceptionNoArgConstructor() throws Exception { ObjectNotFoundException exception = new ObjectNotFoundException(); assertTrue(exception.getMessage() == null); }
@Test public void testHandleNotFound() throws Exception { validateErrorInformation(exceptionHandler.handleNotFoundException(new ObjectNotFoundException(MESSAGE)), HttpStatus.NOT_FOUND); }