use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoHelper method createBusinessObjectDefinitionEntity.
/**
* Create Business Object Definition Entity
* @param request business object definition create request
* @return Business Object Definition Entity
*/
public BusinessObjectDefinitionEntity createBusinessObjectDefinitionEntity(BusinessObjectDefinitionCreateRequest request) {
// Perform the validation.
validateBusinessObjectDefinitionCreateRequest(request);
// Get the namespace and ensure it exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
// Get the data provider and ensure it exists.
DataProviderEntity dataProviderEntity = dataProviderDaoHelper.getDataProviderEntity(request.getDataProviderName());
// Get business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(request.getNamespace(), request.getBusinessObjectDefinitionName());
// Ensure a business object definition with the specified key doesn't already exist.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
if (businessObjectDefinitionEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create business object definition with name \"%s\" because it already exists for namespace \"%s\".", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace()));
}
// Create a new entity.
businessObjectDefinitionEntity = new BusinessObjectDefinitionEntity();
businessObjectDefinitionEntity.setNamespace(namespaceEntity);
businessObjectDefinitionEntity.setName(request.getBusinessObjectDefinitionName());
businessObjectDefinitionEntity.setDescription(request.getDescription());
businessObjectDefinitionEntity.setDataProvider(dataProviderEntity);
businessObjectDefinitionEntity.setDisplayName(request.getDisplayName());
// Create the attributes if they are specified.
if (!CollectionUtils.isEmpty(request.getAttributes())) {
List<BusinessObjectDefinitionAttributeEntity> attributeEntities = new ArrayList<>();
businessObjectDefinitionEntity.setAttributes(attributeEntities);
for (Attribute attribute : request.getAttributes()) {
BusinessObjectDefinitionAttributeEntity attributeEntity = new BusinessObjectDefinitionAttributeEntity();
attributeEntities.add(attributeEntity);
attributeEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
attributeEntity.setName(attribute.getName());
attributeEntity.setValue(attribute.getValue());
}
}
// Persist the change event entity
saveBusinessObjectDefinitionChangeEvents(businessObjectDefinitionEntity);
// Persist and return the new entity.
return businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationHelperTest method testBuildNamespaceAuthorizationsAssertAuthLookupByUserId.
@Test
public void testBuildNamespaceAuthorizationsAssertAuthLookupByUserId() {
ApplicationUser applicationUser = new ApplicationUser(getClass());
String userId = "userId";
applicationUser.setUserId(userId);
when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
List<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntities = new ArrayList<>();
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = new UserNamespaceAuthorizationEntity();
userNamespaceAuthorizationEntity.setUserId("userNamespaceAuthorizationEntityUserId");
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode("namespace");
userNamespaceAuthorizationEntity.setNamespace(namespaceEntity);
userNamespaceAuthorizationEntities.add(userNamespaceAuthorizationEntity);
when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(any())).thenReturn(userNamespaceAuthorizationEntities);
userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser);
assertEquals(1, applicationUser.getNamespaceAuthorizations().size());
NamespaceAuthorization namespaceAuthorization = IterableUtils.get(applicationUser.getNamespaceAuthorizations(), 0);
assertEquals(namespaceEntity.getCode(), namespaceAuthorization.getNamespace());
verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserId(eq(userId));
verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserIdStartsWith(eq(WildcardHelper.WILDCARD_TOKEN));
verifyNoMoreInteractions(userNamespaceAuthorizationDao, wildcardHelper);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationHelperTest method testBuildNamespaceAuthorizationsAssertWildcardEntityNotAddedIfMatchFails.
@Test
public void testBuildNamespaceAuthorizationsAssertWildcardEntityNotAddedIfMatchFails() {
ApplicationUser applicationUser = new ApplicationUser(getClass());
String userId = "userId";
applicationUser.setUserId(userId);
when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
List<UserNamespaceAuthorizationEntity> wildcardEntities = new ArrayList<>();
UserNamespaceAuthorizationEntity wildcardEntity = new UserNamespaceAuthorizationEntity();
wildcardEntity.setUserId("wildcardEntityUserId");
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode("namespace");
wildcardEntity.setNamespace(namespaceEntity);
wildcardEntities.add(wildcardEntity);
when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserIdStartsWith(any())).thenReturn(wildcardEntities);
when(wildcardHelper.matches(any(), any())).thenReturn(false);
userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser);
assertEquals(0, applicationUser.getNamespaceAuthorizations().size());
verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserId(eq(userId));
verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserIdStartsWith(eq(WildcardHelper.WILDCARD_TOKEN));
verify(wildcardHelper).matches(eq(userId.toUpperCase()), eq(wildcardEntity.getUserId().toUpperCase()));
verifyNoMoreInteractions(userNamespaceAuthorizationDao, wildcardHelper);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method updateStorageUnitNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#notificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration updateStorageUnitNotificationRegistration(NotificationRegistrationKey notificationRegistrationKey, StorageUnitNotificationRegistrationUpdateRequest request) {
// Validate and trim the key.
validateStorageUnitNotificationRegistrationKey(notificationRegistrationKey);
// Validate and trim the request parameters.
validateStorageUnitNotificationRegistrationUpdateRequest(request);
// Retrieve and ensure that a storage unit notification exists with the specified key.
StorageUnitNotificationRegistrationEntity oldStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDaoHelper.getStorageUnitNotificationRegistrationEntity(notificationRegistrationKey);
String oldStorageUnitNotificationRegistrationName = oldStorageUnitNotificationRegistrationEntity.getName();
// Retrieve the namespace with the specified namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
// Get the storage unit notification filter.
StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
// Retrieve and ensure that business object definition exists. Since namespace is specified, retrieve a business object definition by it's key.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
// If specified, retrieve and ensure that file type exists.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
}
// Retrieve and ensure that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
// If specified, retrieve and ensure that new storage unit status exists.
StorageUnitStatusEntity newStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
}
// If specified, retrieve and ensure that old storage unit status exists.
StorageUnitStatusEntity oldStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
}
// TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
for (JobAction jobAction : request.getJobActions()) {
// Ensure that job definition exists.
jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
}
// Retrieve and validate the notification registration status entity.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(request.getNotificationRegistrationStatus());
// Delete the storage unit notification.
storageUnitNotificationRegistrationDao.delete(oldStorageUnitNotificationRegistrationEntity);
// Create a storage unit notification registration entity from the request information.
StorageUnitNotificationRegistrationEntity newStorageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, new NotificationRegistrationKey(namespaceEntity.getCode(), oldStorageUnitNotificationRegistrationName), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
newStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(newStorageUnitNotificationRegistrationEntity);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(newStorageUnitNotificationRegistrationEntity);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method createStorageUnitNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#request?.storageUnitNotificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration createStorageUnitNotificationRegistration(StorageUnitNotificationRegistrationCreateRequest request) {
// Validate and trim the request parameters.
validateStorageUnitNotificationRegistrationCreateRequest(request);
// Get the notification registration key.
NotificationRegistrationKey notificationRegistrationKey = request.getStorageUnitNotificationRegistrationKey();
// Retrieve and ensure that notification registration namespace exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
// Validate the notification event type.
Assert.isTrue(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name().equalsIgnoreCase(request.getStorageUnitEventType()), String.format("Notification event type \"%s\" is not supported for storage unit notification registration.", request.getStorageUnitEventType()));
// Get the storage unit notification filter.
StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
// Retrieve and ensure that business object definition exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
// If specified, retrieve and ensure that file type exists.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
}
// Retrieve and ensure that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
// If specified, retrieve and ensure that new storage unit status exists.
StorageUnitStatusEntity newStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
}
// If specified, retrieve and ensure that old storage unit status exists.
StorageUnitStatusEntity oldStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
}
// TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
for (JobAction jobAction : request.getJobActions()) {
// Ensure that job definition exists.
jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
}
// If specified, retrieve and validate the notification registration status entity. Otherwise, default it to ENABLED.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(StringUtils.isNotBlank(request.getNotificationRegistrationStatus()) ? request.getNotificationRegistrationStatus() : NotificationRegistrationStatusEntity.ENABLED);
// Ensure a storage unit notification with the specified name doesn't already exist for the specified namespace.
StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrationByAltKey(notificationRegistrationKey);
if (storageUnitNotificationRegistrationEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create storage unit notification with name \"%s\" because it already exists for namespace \"%s\".", notificationRegistrationKey.getNotificationName(), notificationRegistrationKey.getNamespace()));
}
// Create a storage unit notification registration entity from the request information.
storageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, request.getStorageUnitNotificationRegistrationKey(), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(storageUnitNotificationRegistrationEntity);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(storageUnitNotificationRegistrationEntity);
}
Aggregations