use of org.finra.herd.model.jpa.JobDefinitionEntity 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);
}
Aggregations