ConfigureByDublinCoreTermWOH extends ResumableWorkflowOperationHandlerBase { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation(); String configuredCatalog = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCCATALOG_PROPERTY)); String configuredDCTerm = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCTERM_PROPERTY)); String configuredDefaultValue = StringUtils.trimToNull(currentOperation.getConfiguration(DEFAULT_VALUE_PROPERTY)); String configuredMatchValue = StringUtils.trimToEmpty(currentOperation.getConfiguration(MATCH_VALUE_PROPERTY)); Catalog[] catalogs = mediaPackage .getCatalogs(new MediaPackageElementFlavor("dublincore", StringUtils.lowerCase(configuredCatalog))); if (catalogs != null && catalogs.length > 0) { Boolean foundValue = false; EName dcterm = new EName(TERMS_NS_URI, configuredDCTerm); for (Catalog catalog : catalogs) { DublinCoreCatalog dc = DublinCoreUtil.loadDublinCore(workspace, catalog); List<DublinCoreValue> values = dc.get(dcterm); if (values.isEmpty()) { if (configuredDefaultValue != null) { foundValue = configuredDefaultValue.equals(configuredMatchValue); } } else { foundValue = values.contains(DublinCoreValue.mk(configuredMatchValue)); } } if (foundValue) { Map<String, String> properties = new HashMap<>(); for (String key : currentOperation.getConfigurationKeys()) { if (DCCATALOG_PROPERTY.equals(key) || DCTERM_PROPERTY.equals(key) || DEFAULT_VALUE_PROPERTY.equals(key) || MATCH_VALUE_PROPERTY.equals(key)) { continue; } String value = currentOperation.getConfiguration(key); properties.put(key, value); logger.info("Configuration key '{}' of workflow {} is set to value '{}'", key, workflowInstance.getId(), value); } return createResult(mediaPackage, properties, Action.CONTINUE, 0); } } return createResult(mediaPackage, Action.CONTINUE); }  void setWorkspace(Workspace workspace); @Override WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context); static final String DCCATALOG_PROPERTY; static final String DCTERM_PROPERTY; static final String DEFAULT_VALUE_PROPERTY; static final String MATCH_VALUE_PROPERTY; static final String COPY_PROPERTY; }
@Test public void testMatchPresentDCTerm() throws Exception { operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCTERM_PROPERTY, "publisher"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.MATCH_VALUE_PROPERTY, "University of Opencast"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.COPY_PROPERTY, "false"); operation.setConfiguration("newConfigProperty", "true"); WorkflowOperationResult result = operationHandler.start(instance, null); Map<String, String> properties = result.getProperties(); Assert.assertTrue(properties.containsKey("newConfigProperty")); Assert.assertEquals("true", properties.get("newConfigProperty")); }
@Test public void testMatchPresentDCTermOverwriteProperty() throws Exception { operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCTERM_PROPERTY, "publisher"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.MATCH_VALUE_PROPERTY, "University of Opencast"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.COPY_PROPERTY, "false"); operation.setConfiguration("oldConfigProperty", "bar"); WorkflowOperationResult result = operationHandler.start(instance, null); Map<String, String> properties = result.getProperties(); Assert.assertTrue(properties.containsKey("oldConfigProperty")); Assert.assertEquals("bar", properties.get("oldConfigProperty")); }
@Test public void testMatchDefaultDCTerm() throws Exception { operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCTERM_PROPERTY, "source"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.DEFAULT_VALUE_PROPERTY, "Timbuktu"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.MATCH_VALUE_PROPERTY, "Timbuktu"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.COPY_PROPERTY, "false"); operation.setConfiguration("newConfigProperty", "true"); WorkflowOperationResult result = operationHandler.start(instance, null); Map<String, String> properties = result.getProperties(); Assert.assertTrue(properties.containsKey("newConfigProperty")); Assert.assertEquals("true", properties.get("newConfigProperty")); }
@Test public void testMisMatchDefaultDCTerm() throws Exception { operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCTERM_PROPERTY, "source"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.DEFAULT_VALUE_PROPERTY, "Cairo"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.MATCH_VALUE_PROPERTY, "Timbuktu"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.COPY_PROPERTY, "false"); operation.setConfiguration("newConfigProperty", "true"); WorkflowOperationResult result = operationHandler.start(instance, null); Map<String, String> properties = result.getProperties(); Assert.assertTrue(properties == null); }
@Test public void testMissingNoDefaultDCTerm() throws Exception { operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCTERM_PROPERTY, "source"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.MATCH_VALUE_PROPERTY, "Timbuktu"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.COPY_PROPERTY, "false"); operation.setConfiguration("newConfigProperty", "true"); WorkflowOperationResult result = operationHandler.start(instance, null); Map<String, String> properties = result.getProperties(); Assert.assertTrue(properties == null); }
@Test public void testNoMatchConfiguredDCTerm() throws Exception { operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.DCTERM_PROPERTY, "source"); operation.setConfiguration(ConfigureByDublinCoreTermWOH.COPY_PROPERTY, "false"); WorkflowOperationResult result = operationHandler.start(instance, null); Map<String, String> properties = result.getProperties(); Assert.assertTrue(properties == null); }