@Test public void testKeep() throws WorkflowOperationException { operation.setConfiguration("catalog-flavor", "flavor/test"); operation.setConfiguration("catalog-type-collision-behavior", "keep"); operationHandler.start(instance, null); WorkflowOperationResult result = operationHandler.start(instance, null); Assert.assertEquals(Action.CONTINUE, result.getAction()); MediaPackage mp = result.getMediaPackage(); Assert.assertEquals(mp.getCatalogs().length, 2); }
@Override public WorkflowOperationResult start(WorkflowInstance wInst, JobContext context) throws WorkflowOperationException { String catalogName = getConfig(wInst, CFG_KEY_CATALOG_NAME); String catalogPath = getConfig(wInst, CFG_KEY_CATALOG_PATH); String catalogTags = getConfig(wInst, CFG_KEY_CATALOG_TAGS, ""); CatalogTypeCollisionBehavior collBehavior = parseCollisionBehavior( getConfig(wInst, CFG_KEY_CATALOG_TYPE_COLLISION_BEHAVIOR)); MediaPackageElementFlavor catalogFlavor = null; try { catalogFlavor = MediaPackageElementFlavor.parseFlavor( getConfig(wInst, CFG_KEY_CATALOG_FLAVOR)); } catch (IllegalArgumentException e) { throw new WorkflowOperationException("Unknown flavor"); } MediaPackage mp = wInst.getMediaPackage(); if (doesCatalogFlavorExist(catalogFlavor, mp.getCatalogs())) { if (collBehavior == CatalogTypeCollisionBehavior.FAIL) { throw new WorkflowOperationException("Catalog Type already exists and 'fail' was specified"); } else if (collBehavior == CatalogTypeCollisionBehavior.SKIP) { return createResult(mp, Action.CONTINUE); } } File catalogFile = new File(catalogPath); String catalogId = UUID.randomUUID().toString(); URI catalogURI = null; try (InputStream catalogInputStream = FileUtils.openInputStream(catalogFile)) { catalogURI = workspace.put(mp.getIdentifier().toString(), catalogId, catalogName, catalogInputStream); } catch (IOException e) { throw new WorkflowOperationException(e); } MediaPackageElement mpe = mp.add(catalogURI, MediaPackageElement.Type.Catalog, catalogFlavor); mpe.setIdentifier(catalogId); mpe.setMimeType(CATALOG_MIME_TYPE); for (String tag : asList(catalogTags)) { mpe.addTag(tag); } return createResult(mp, Action.CONTINUE); }
AddCatalogWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance wInst, JobContext context) throws WorkflowOperationException { String catalogName = getConfig(wInst, CFG_KEY_CATALOG_NAME); String catalogPath = getConfig(wInst, CFG_KEY_CATALOG_PATH); String catalogTags = getConfig(wInst, CFG_KEY_CATALOG_TAGS, ""); CatalogTypeCollisionBehavior collBehavior = parseCollisionBehavior( getConfig(wInst, CFG_KEY_CATALOG_TYPE_COLLISION_BEHAVIOR)); MediaPackageElementFlavor catalogFlavor = null; try { catalogFlavor = MediaPackageElementFlavor.parseFlavor( getConfig(wInst, CFG_KEY_CATALOG_FLAVOR)); } catch (IllegalArgumentException e) { throw new WorkflowOperationException("Unknown flavor"); } MediaPackage mp = wInst.getMediaPackage(); if (doesCatalogFlavorExist(catalogFlavor, mp.getCatalogs())) { if (collBehavior == CatalogTypeCollisionBehavior.FAIL) { throw new WorkflowOperationException("Catalog Type already exists and 'fail' was specified"); } else if (collBehavior == CatalogTypeCollisionBehavior.SKIP) { return createResult(mp, Action.CONTINUE); } } File catalogFile = new File(catalogPath); String catalogId = UUID.randomUUID().toString(); URI catalogURI = null; try (InputStream catalogInputStream = FileUtils.openInputStream(catalogFile)) { catalogURI = workspace.put(mp.getIdentifier().toString(), catalogId, catalogName, catalogInputStream); } catch (IOException e) { throw new WorkflowOperationException(e); } MediaPackageElement mpe = mp.add(catalogURI, MediaPackageElement.Type.Catalog, catalogFlavor); mpe.setIdentifier(catalogId); mpe.setMimeType(CATALOG_MIME_TYPE); for (String tag : asList(catalogTags)) { mpe.addTag(tag); } return createResult(mp, Action.CONTINUE); } }
AddCatalogWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance wInst, JobContext context) throws WorkflowOperationException { String catalogName = getConfig(wInst, CFG_KEY_CATALOG_NAME); String catalogPath = getConfig(wInst, CFG_KEY_CATALOG_PATH); String catalogTags = getConfig(wInst, CFG_KEY_CATALOG_TAGS, ""); CatalogTypeCollisionBehavior collBehavior = parseCollisionBehavior( getConfig(wInst, CFG_KEY_CATALOG_TYPE_COLLISION_BEHAVIOR)); MediaPackageElementFlavor catalogFlavor = null; try { catalogFlavor = MediaPackageElementFlavor.parseFlavor( getConfig(wInst, CFG_KEY_CATALOG_FLAVOR)); } catch (IllegalArgumentException e) { throw new WorkflowOperationException("Unknown flavor"); } MediaPackage mp = wInst.getMediaPackage(); if (doesCatalogFlavorExist(catalogFlavor, mp.getCatalogs())) { if (collBehavior == CatalogTypeCollisionBehavior.FAIL) { throw new WorkflowOperationException("Catalog Type already exists and 'fail' was specified"); } else if (collBehavior == CatalogTypeCollisionBehavior.SKIP) { return createResult(mp, Action.CONTINUE); } } File catalogFile = new File(catalogPath); String catalogId = UUID.randomUUID().toString(); URI catalogURI = null; try (InputStream catalogInputStream = FileUtils.openInputStream(catalogFile)) { catalogURI = workspace.put(mp.getIdentifier().toString(), catalogId, catalogName, catalogInputStream); } catch (IOException e) { throw new WorkflowOperationException(e); } MediaPackageElement mpe = mp.add(catalogURI, MediaPackageElement.Type.Catalog, catalogFlavor); mpe.setIdentifier(catalogId); mpe.setMimeType(CATALOG_MIME_TYPE); for (String tag : asList(catalogTags)) { mpe.addTag(tag); } return createResult(mp, Action.CONTINUE); }  }
AddCatalogWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance wInst, JobContext context) throws WorkflowOperationException { String catalogName = getConfig(wInst, CFG_KEY_CATALOG_NAME); String catalogPath = getConfig(wInst, CFG_KEY_CATALOG_PATH); String catalogTags = getConfig(wInst, CFG_KEY_CATALOG_TAGS, ""); CatalogTypeCollisionBehavior collBehavior = parseCollisionBehavior( getConfig(wInst, CFG_KEY_CATALOG_TYPE_COLLISION_BEHAVIOR)); MediaPackageElementFlavor catalogFlavor = null; try { catalogFlavor = MediaPackageElementFlavor.parseFlavor( getConfig(wInst, CFG_KEY_CATALOG_FLAVOR)); } catch (IllegalArgumentException e) { throw new WorkflowOperationException("Unknown flavor"); } MediaPackage mp = wInst.getMediaPackage(); if (doesCatalogFlavorExist(catalogFlavor, mp.getCatalogs())) { if (collBehavior == CatalogTypeCollisionBehavior.FAIL) { throw new WorkflowOperationException("Catalog Type already exists and 'fail' was specified"); } else if (collBehavior == CatalogTypeCollisionBehavior.SKIP) { return createResult(mp, Action.CONTINUE); } } File catalogFile = new File(catalogPath); String catalogId = UUID.randomUUID().toString(); URI catalogURI = null; try (InputStream catalogInputStream = FileUtils.openInputStream(catalogFile)) { catalogURI = workspace.put(mp.getIdentifier().toString(), catalogId, catalogName, catalogInputStream); } catch (IOException e) { throw new WorkflowOperationException(e); } MediaPackageElement mpe = mp.add(catalogURI, MediaPackageElement.Type.Catalog, catalogFlavor); mpe.setIdentifier(catalogId); mpe.setMimeType(CATALOG_MIME_TYPE); for (String tag : asList(catalogTags)) { mpe.addTag(tag); } return createResult(mp, Action.CONTINUE); }  void setWorkspace(Workspace workspace); @Override WorkflowOperationResult start(WorkflowInstance wInst, JobContext context); }
AddCatalogWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance wInst, JobContext context) throws WorkflowOperationException { String catalogName = getConfig(wInst, CFG_KEY_CATALOG_NAME); String catalogPath = getConfig(wInst, CFG_KEY_CATALOG_PATH); String catalogTags = getConfig(wInst, CFG_KEY_CATALOG_TAGS, ""); CatalogTypeCollisionBehavior collBehavior = parseCollisionBehavior( getConfig(wInst, CFG_KEY_CATALOG_TYPE_COLLISION_BEHAVIOR)); MediaPackageElementFlavor catalogFlavor = null; try { catalogFlavor = MediaPackageElementFlavor.parseFlavor( getConfig(wInst, CFG_KEY_CATALOG_FLAVOR)); } catch (IllegalArgumentException e) { throw new WorkflowOperationException("Unknown flavor"); } MediaPackage mp = wInst.getMediaPackage(); if (doesCatalogFlavorExist(catalogFlavor, mp.getCatalogs())) { if (collBehavior == CatalogTypeCollisionBehavior.FAIL) { throw new WorkflowOperationException("Catalog Type already exists and 'fail' was specified"); } else if (collBehavior == CatalogTypeCollisionBehavior.SKIP) { return createResult(mp, Action.CONTINUE); } } File catalogFile = new File(catalogPath); String catalogId = UUID.randomUUID().toString(); URI catalogURI = null; try (InputStream catalogInputStream = FileUtils.openInputStream(catalogFile)) { catalogURI = workspace.put(mp.getIdentifier().toString(), catalogId, catalogName, catalogInputStream); } catch (IOException e) { throw new WorkflowOperationException(e); } MediaPackageElement mpe = mp.add(catalogURI, MediaPackageElement.Type.Catalog, catalogFlavor); mpe.setIdentifier(catalogId); mpe.setMimeType(CATALOG_MIME_TYPE); for (String tag : asList(catalogTags)) { mpe.addTag(tag); } return createResult(mp, Action.CONTINUE); }  void setWorkspace(Workspace workspace); @Override WorkflowOperationResult start(WorkflowInstance wInst, JobContext context);  }