/** * Gets the Regex pattern to match the namespace and job name from a process definition key. * * @return the Regex pattern */ public Pattern getNamespaceAndJobNameRegexPattern() { // Get the job definition template (e.g. ~namespace~.~jobName~) and Regex escape all periods (e.g. ~namespace~\\.~jobName~). String jobDefinitionTemplate = getActivitiJobDefinitionTemplate().replaceAll("\\.", "\\\\."); // Change the tokens to named capture groups (e.g. (?<namespace>.*)\\.(?<jobName>.*)). jobDefinitionTemplate = jobDefinitionTemplate.replaceAll(getNamespaceToken(), "(?<namespace>.*)"); jobDefinitionTemplate = jobDefinitionTemplate.replaceAll(getJobNameToken(), "(?<jobName>.*)"); // Compile the Regex pattern. return Pattern.compile(jobDefinitionTemplate); }
/** * Gets the Regex pattern to match the namespace and job name from a process definition key. * * @return the Regex pattern */ public Pattern getNamespaceAndJobNameRegexPattern() { // Get the job definition template (e.g. ~namespace~.~jobName~) and Regex escape all periods (e.g. ~namespace~\\.~jobName~). String jobDefinitionTemplate = getActivitiJobDefinitionTemplate().replaceAll("\\.", "\\\\."); // Change the tokens to named capture groups (e.g. (?<namespace>.*)\\.(?<jobName>.*)). jobDefinitionTemplate = jobDefinitionTemplate.replaceAll(getNamespaceToken(), "(?<namespace>.*)"); jobDefinitionTemplate = jobDefinitionTemplate.replaceAll(getJobNameToken(), "(?<jobName>.*)"); // Compile the Regex pattern. return Pattern.compile(jobDefinitionTemplate); }
/** * Returns Activiti Id constructed according to the template defined. * * @param namespaceCd the namespace code value * @param jobName the job name value * * @return the Activiti Id */ public String buildActivitiIdString(String namespaceCd, String jobName) { // Populate a map with the tokens mapped to actual database values. Map<String, String> pathToTokenValueMap = new HashMap<>(); pathToTokenValueMap.put(getNamespaceToken(), namespaceCd); pathToTokenValueMap.put(getJobNameToken(), jobName); // The Activiti Id will start as the template. String activitiId = getActivitiJobDefinitionTemplate(); // Substitute the tokens with the actual database values. for (Map.Entry<String, String> mapEntry : pathToTokenValueMap.entrySet()) { activitiId = activitiId.replaceAll(mapEntry.getKey(), mapEntry.getValue()); } // Return the final Activiti Id. return activitiId; }
/** * Returns Activiti Id constructed according to the template defined. * * @param namespaceCd the namespace code value * @param jobName the job name value * * @return the Activiti Id */ public String buildActivitiIdString(String namespaceCd, String jobName) { // Populate a map with the tokens mapped to actual database values. Map<String, String> pathToTokenValueMap = new HashMap<>(); pathToTokenValueMap.put(getNamespaceToken(), namespaceCd); pathToTokenValueMap.put(getJobNameToken(), jobName); // The Activiti Id will start as the template. String activitiId = getActivitiJobDefinitionTemplate(); // Substitute the tokens with the actual database values. for (Map.Entry<String, String> mapEntry : pathToTokenValueMap.entrySet()) { activitiId = activitiId.replaceAll(mapEntry.getKey(), mapEntry.getValue()); } // Return the final Activiti Id. return activitiId; }
@Test public void testGetActivitiJobDefinitionTemplateUsingDefaultActivitiIdTemplate() { assertEquals("~namespace~.~jobName~", jobDefinitionHelper.getActivitiJobDefinitionTemplate()); }
@Test public void testGetActivitiJobDefinitionTemplateUsingConfiguredActivitiIdTemplate() throws Exception { // Set up test values. String testActivitiIdTemplate = "testActivitiIdTemplate"; // Override configuration. Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey(), testActivitiIdTemplate); modifyPropertySourceInEnvironment(overrideMap); try { assertEquals(testActivitiIdTemplate, jobDefinitionHelper.getActivitiJobDefinitionTemplate()); } finally { // Restore the property sources so we don't affect other tests. restorePropertySourceInEnvironment(); } }