use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.
the class JobDefinitionHelper method getJobDefinitionKey.
/**
* Gets a job definition key using namespace and name of the the job definition extracted from the specified process definition key and the Regex pattern.
*
* @param processDefinitionKey the process definition key
* @param regexPattern the Regex pattern
*
* @return the job definition key
*/
public JobDefinitionAlternateKeyDto getJobDefinitionKey(String processDefinitionKey, Pattern regexPattern) {
// Create a job definition key.
JobDefinitionAlternateKeyDto jobDefinitionKey = new JobDefinitionAlternateKeyDto();
// Use the Regex pattern to match the namespace and job name from a process definition key.
Matcher matcher = regexPattern.matcher(processDefinitionKey);
if (matcher.find()) {
jobDefinitionKey.setNamespace(matcher.group("namespace"));
jobDefinitionKey.setJobName(matcher.group("jobName"));
} else {
// against the database. The check is here for robustness, but should not be expected to be covered as part of tests.
throw new IllegalArgumentException(String.format("Process definition key \"%s\" does not match the expected pattern \"%s\".", processDefinitionKey, regexPattern.toString()));
}
return jobDefinitionKey;
}
use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.
the class JobServiceImpl method checkPermissions.
/**
* Checks the namespace permissions for the current user for the given process definition key.
*
* @param processDefinitionKey The process definition key
* @param permissions The list of permissions the current user must have
*/
private void checkPermissions(String processDefinitionKey, NamespacePermissionEnum[] permissions) {
// Get the job definition key.
JobDefinitionAlternateKeyDto jobDefinitionKey = jobDefinitionHelper.getJobDefinitionKey(processDefinitionKey);
// Checks the permissions against the namespace.
namespaceSecurityHelper.checkPermission(jobDefinitionKey.getNamespace(), permissions);
}
use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.
the class BaseJavaDelegate method setSecurityContext.
/**
* Sets the security context per last updater of the current process instance's job definition.
*
* @param execution the current execution context
*/
protected void setSecurityContext(DelegateExecution execution) {
String processDefinitionId = execution.getProcessDefinitionId();
// Get process definition by process definition ID from Activiti.
ProcessDefinition processDefinition = activitiService.getProcessDefinitionById(processDefinitionId);
// Validate that we retrieved the process definition from Activiti.
if (processDefinition == null) {
throw new ObjectNotFoundException(String.format("Failed to find Activiti process definition for processDefinitionId=\"%s\".", processDefinitionId));
}
// Retrieve the process definition key.
String processDefinitionKey = processDefinition.getKey();
// Get the job definition key.
JobDefinitionAlternateKeyDto jobDefinitionKey = jobDefinitionHelper.getJobDefinitionKey(processDefinitionKey);
// Get the job definition from the Herd repository and validate that it exists.
JobDefinitionEntity jobDefinitionEntity = jobDefinitionDaoHelper.getJobDefinitionEntity(jobDefinitionKey.getNamespace(), jobDefinitionKey.getJobName());
// Set the security context per last updater of the job definition.
String updatedByUserId = jobDefinitionEntity.getUpdatedBy();
ApplicationUser applicationUser = new ApplicationUser(getClass());
applicationUser.setUserId(updatedByUserId);
userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser);
SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken(new SecurityUserWrapper(updatedByUserId, "", true, true, true, true, Collections.emptyList(), applicationUser), null));
}
use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.
the class JobDefinitionHelperTest method testGetJobDefinitionKey.
@Test
public void testGetJobDefinitionKey() {
// Set up test values.
String testProcessDefinitionKey = String.format("%s.%s", NAMESPACE, JOB_NAME);
// Validate the happy path scenario.
assertEquals(new JobDefinitionAlternateKeyDto(NAMESPACE, JOB_NAME), jobDefinitionHelper.getJobDefinitionKey(testProcessDefinitionKey));
}
use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.
the class JobServiceGetJobsTest method before.
@Before
public void before() {
initMocks(this);
when(herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.JOBS_QUERY_MAX_RESULTS)).thenReturn(1);
when(jobDefinitionHelper.getJobDefinitionKey(eq("a.b"), any())).thenReturn(new JobDefinitionAlternateKeyDto("a", "b"));
}
Aggregations