/** * Gets a job definition key using namespace and name of the the job definition extracted from the specified process definition key using the Regex * pattern. * * @param processDefinitionKey the process definition key * * @return the job definition key */ public JobDefinitionAlternateKeyDto getJobDefinitionKey(String processDefinitionKey) { return getJobDefinitionKey(processDefinitionKey, getNamespaceAndJobNameRegexPattern()); }
/** * Gets a job definition key using namespace and name of the the job definition extracted from the specified process definition key using the Regex * pattern. * * @param processDefinitionKey the process definition key * * @return the job definition key */ public JobDefinitionAlternateKeyDto getJobDefinitionKey(String processDefinitionKey) { return getJobDefinitionKey(processDefinitionKey, getNamespaceAndJobNameRegexPattern()); }
/** * 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); }
/** * 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); }
@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")); }
@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)); }
@Test public void testGetJobDefinitionKeyInvalidProcessDefinitionKey() { // Set up test values. String testProcessDefinitionKey = "INVALID_PROCESS_DEFINITION_KEY"; // Get the regex pattern. Pattern pattern = jobDefinitionHelper.getNamespaceAndJobNameRegexPattern(); // Try to get the job definition key when process definition key not match the expected pattern. try { jobDefinitionHelper.getJobDefinitionKey(testProcessDefinitionKey, pattern); fail(); } catch (IllegalArgumentException e) { assertEquals( String.format("Process definition key \"%s\" does not match the expected pattern \"%s\".", testProcessDefinitionKey, pattern.toString()), e.getMessage()); } }
/** * Retrieves application user per last updater of the current process instance's job definition. * * @param execution the delegate execution * * @return the application user */ protected ApplicationUser getApplicationUser(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); return applicationUser; }
/** * Retrieves application user per last updater of the current process instance's job definition. * * @param execution the delegate execution * * @return the application user */ protected ApplicationUser getApplicationUser(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); return applicationUser; }
.getJobDefinitionKey(processDefinitionIdToKeyMap.get(historicProcessInstance.getProcessDefinitionId()), pattern);
.getJobDefinitionKey(processDefinitionIdToKeyMap.get(historicProcessInstance.getProcessDefinitionId()), pattern);