use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class JobServiceImpl method createAndStartJob.
@NamespacePermission(fields = "#request?.namespace", permissions = NamespacePermissionEnum.EXECUTE)
@Override
public Job createAndStartJob(JobCreateRequest request) throws Exception {
// Perform the validation.
validateJobCreateRequest(request);
// Get the namespace and ensure it exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
// Get the job definition and ensure it exists.
JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(request.getNamespace(), request.getJobName());
if (jobDefinitionEntity == null) {
throw new ObjectNotFoundException("Job definition with name \"" + request.getJobName() + "\" doesn't exist for namespace \"" + request.getNamespace() + "\".");
}
// Build the parameters map
Map<String, Object> mergedParameters = getParameters(jobDefinitionEntity, request);
// Create a process instance holder to check for a handle to the process instance once it is created.
String processDefinitionId = jobDefinitionEntity.getActivitiId();
ProcessDefinition processDefinition = activitiService.getProcessDefinitionById(processDefinitionId);
Assert.notNull(processDefinition, "No process definition found for Id: " + processDefinitionId);
Assert.isTrue(!processDefinition.isSuspended(), "Cannot start process instance for process definition Id: " + processDefinitionId + " because it is suspended.");
ProcessInstance processInstance = activitiService.startProcessInstanceByProcessDefinitionId(processDefinitionId, mergedParameters);
// If we get here, we have a newly created process instance. Log to know it was created successfully.
LOGGER.info("Created process instance with Id: " + processInstance.getProcessInstanceId() + " for process definition Id: " + processDefinitionId + " with merged parameters: " + mergedParameters);
// Create and return the job object.
return createJobFromRequest(namespaceEntity.getCode(), jobDefinitionEntity.getName(), mergedParameters, processInstance.getProcessInstanceId());
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceImpl method deleteNamespaceIamRoleAuthorization.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public NamespaceIamRoleAuthorization deleteNamespaceIamRoleAuthorization(String namespace) {
Assert.hasText(namespace, "Namespace must be specified");
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespace.trim());
List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = getNamespaeIamRoleAuthorizationEntities(namespaceEntity);
NamespaceIamRoleAuthorization result = new NamespaceIamRoleAuthorization(namespaceEntity.getCode(), new ArrayList<>());
for (NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity : namespaceIamRoleAuthorizationEntities) {
namespaceIamRoleAuthorizationDao.delete(namespaceIamRoleAuthorizationEntity);
result.getIamRoles().add(new IamRole(namespaceIamRoleAuthorizationEntity.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getDescription()));
}
return result;
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceImpl method getNamespaceIamRoleAuthorization.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.READ)
@Override
public NamespaceIamRoleAuthorization getNamespaceIamRoleAuthorization(String namespace) {
Assert.hasText(namespace, "Namespace must be specified");
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespace.trim());
List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = getNamespaeIamRoleAuthorizationEntities(namespaceEntity);
NamespaceIamRoleAuthorization result = new NamespaceIamRoleAuthorization(namespaceEntity.getCode(), new ArrayList<>());
for (NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity : namespaceIamRoleAuthorizationEntities) {
result.getIamRoles().add(new IamRole(namespaceIamRoleAuthorizationEntity.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getDescription()));
}
return result;
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class BusinessObjectDefinitionSubjectMatterExpertServiceImpl method createBusinessObjectDefinitionSubjectMatterExpert.
@NamespacePermission(fields = "#request.businessObjectDefinitionSubjectMatterExpertKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionSubjectMatterExpert createBusinessObjectDefinitionSubjectMatterExpert(BusinessObjectDefinitionSubjectMatterExpertCreateRequest request) {
// Validate and trim the business object definition subject matter expert create request.
validateBusinessObjectDefinitionSubjectMatterExpertCreateRequest(request);
// Get the business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(request.getBusinessObjectDefinitionSubjectMatterExpertKey().getNamespace(), request.getBusinessObjectDefinitionSubjectMatterExpertKey().getBusinessObjectDefinitionName());
// Get the business object definition and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
// Ensure a business object definition subject matter expert with the specified name doesn't already exist for the business object definition.
if (businessObjectDefinitionSubjectMatterExpertDao.getBusinessObjectDefinitionSubjectMatterExpert(businessObjectDefinitionEntity, request.getBusinessObjectDefinitionSubjectMatterExpertKey().getUserId()) != null) {
throw new AlreadyExistsException(String.format("Unable to create business object definition subject matter expert with user id \"%s\" " + "because it already exists for the business object definition {%s}.", request.getBusinessObjectDefinitionSubjectMatterExpertKey().getUserId(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
}
// Create a business object definition subject matter expert entity from the request information.
BusinessObjectDefinitionSubjectMatterExpertEntity businessObjectDefinitionSubjectMatterExpertEntity = createBusinessObjectDefinitionSubjectMatterExpertEntity(businessObjectDefinitionEntity, request);
// Persist the new entity.
businessObjectDefinitionSubjectMatterExpertEntity = businessObjectDefinitionSubjectMatterExpertDao.saveAndRefresh(businessObjectDefinitionSubjectMatterExpertEntity);
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create and return the business object definition subject matter expert object from the persisted entity.
return createBusinessObjectDefinitionSubjectMatterExpertFromEntity(businessObjectDefinitionSubjectMatterExpertEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method createBusinessObjectFormat.
@PublishNotificationMessages
@NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectFormat createBusinessObjectFormat(BusinessObjectFormatCreateRequest request) {
// Perform the validation of the request parameters, except for the alternate key.
validateBusinessObjectFormatCreateRequest(request);
// Get business object format key from the request.
BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(request);
// Get the business object definition and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName()));
// Get business object format file type and ensure it exists.
FileTypeEntity fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(request.getBusinessObjectFormatFileType());
// Get the latest format version for this business format, if it exists.
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
// If the latest version exists, perform the additive schema validation and update the latest entity.
if (latestVersionBusinessObjectFormatEntity != null) {
// Get the latest version business object format model object.
BusinessObjectFormat latestVersionBusinessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(latestVersionBusinessObjectFormatEntity);
// If the latest version format has schema, check the new format version schema is "additive" to the previous format version.
if (latestVersionBusinessObjectFormat.getSchema() != null) {
validateNewSchemaIsAdditiveToOldSchema(request.getSchema(), latestVersionBusinessObjectFormat.getSchema());
}
// Update the latest entity.
latestVersionBusinessObjectFormatEntity.setLatestVersion(false);
businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity);
}
// Create a business object format entity from the request information.
Integer businessObjectFormatVersion = latestVersionBusinessObjectFormatEntity == null ? 0 : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatVersion() + 1;
BusinessObjectFormatEntity newBusinessObjectFormatEntity = createBusinessObjectFormatEntity(request, businessObjectDefinitionEntity, fileTypeEntity, businessObjectFormatVersion, null);
// latest version format is the descriptive format for the bdef, update the bdef descriptive format to the newly created one
if (latestVersionBusinessObjectFormatEntity != null && latestVersionBusinessObjectFormatEntity.equals(businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat())) {
businessObjectDefinitionEntity.setDescriptiveBusinessObjectFormat(newBusinessObjectFormatEntity);
businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
// latest version business object exists, carry the retention information to the new entity
if (latestVersionBusinessObjectFormatEntity != null) {
// for each of the previous version's child, remove the parent link to the previous version and set the parent to the new version
for (BusinessObjectFormatEntity childFormatEntity : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatChildren()) {
childFormatEntity.getBusinessObjectFormatParents().remove(latestVersionBusinessObjectFormatEntity);
childFormatEntity.getBusinessObjectFormatParents().add(newBusinessObjectFormatEntity);
newBusinessObjectFormatEntity.getBusinessObjectFormatChildren().add(childFormatEntity);
businessObjectFormatDao.saveAndRefresh(childFormatEntity);
}
// for each of the previous version's parent, remove the child link to the previous version and set the child link to the new version
for (BusinessObjectFormatEntity parentFormatEntity : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatParents()) {
parentFormatEntity.getBusinessObjectFormatChildren().remove(latestVersionBusinessObjectFormatEntity);
parentFormatEntity.getBusinessObjectFormatChildren().add(newBusinessObjectFormatEntity);
newBusinessObjectFormatEntity.getBusinessObjectFormatParents().add(parentFormatEntity);
businessObjectFormatDao.saveAndRefresh(parentFormatEntity);
}
// mark the latest version business object format
latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatParents(null);
latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatChildren(null);
// carry the retention information from the latest entity to the new entity
newBusinessObjectFormatEntity.setRetentionPeriodInDays(latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays());
newBusinessObjectFormatEntity.setRecordFlag(latestVersionBusinessObjectFormatEntity.isRecordFlag());
newBusinessObjectFormatEntity.setRetentionType(latestVersionBusinessObjectFormatEntity.getRetentionType());
businessObjectFormatDao.saveAndRefresh(newBusinessObjectFormatEntity);
// reset the retention information of the latest version business object format
latestVersionBusinessObjectFormatEntity.setRetentionType(null);
latestVersionBusinessObjectFormatEntity.setRecordFlag(null);
latestVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(null);
businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity);
}
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create a version change notification to be sent on create business object format event.
messageNotificationEventService.processBusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatHelper.getBusinessObjectFormatKey(newBusinessObjectFormatEntity), latestVersionBusinessObjectFormatEntity != null ? latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatVersion().toString() : "");
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(newBusinessObjectFormatEntity);
}
Aggregations