@Override public WorkflowValidationResult validate(WorkflowRepresentation representation) { WorkflowValidationResultImplementation result = new WorkflowValidationResultImplementation(); if (representation.getName() == "" || representation.getName() == null) { result.notValid(); result.addError("Name of WorkflowRepresentation missing"); } validateActionRepresentation(representation.getRoot(), result); return result; }
@Override public void createWorkflow(String name) { if (workflows.containsKey(name)) { LOGGER.info("Creation of Workflow with same name failed"); throw new IllegalArgumentException("Workflow with same name already exists"); } else { LOGGER.info("Creating Workflow " + name); WorkflowRepresentation workflow = new WorkflowRepresentation(); workflow.setName(name); workflows.put(name, workflow); currentWorkflow = workflow; } }
@Override public void removeCurrentWorkflow() throws PersistenceException { final HashMap<String, String> metadata = new HashMap<String, String>(); metadata.put("name", getCurrentWorkflow().getName()); configPersistence.remove(metadata); workflows.remove(this.getCurrentWorkflow().getName()); currentWorkflow = null; }
@Override public void persist(ConfigItem<WorkflowRepresentation> config) throws PersistenceException { LOGGER.info("Persisting Workflow " + config.getContent().getName()); WorkflowRepresentation content = config.getContent(); String marshallWorkflow = converter.marshallWorkflow(content); File file = new File(folder, content.getName()); try { FileWriter writer = new FileWriter(file); writer.write(marshallWorkflow); writer.close(); } catch (IOException e) { throw new PersistenceException(e); } }
public static Process build(WorkflowRepresentation workflow) { Process process = new Process("RuleFlow", workflow.getName(), workflow.getName(), RuleBaseElementId.DEFAULT_RULE_PACKAGE); process.addNode(new Start()); processAction(process, workflow.getRoot(), 1); addEndConnections(process); return process; }
@Override public void loadWorkflowsFromDatabase() throws PersistenceException { try { List<ConfigItem<WorkflowRepresentation>> load = configPersistence.load(new HashMap<String, String>()); for (ConfigItem<WorkflowRepresentation> configItem : load) { final WorkflowRepresentation content = configItem.getContent(); workflows.put(content.getName(), content); } } catch (InvalidConfigurationException e) { LOGGER.error("Invalid Configuration: " + e.getMessage()); throw new PersistenceException(e); } }
@Override public void saveCurrentWorkflow() throws PersistenceException { ConfigItem<WorkflowRepresentation> workflowRepresentation = new ConfigItem<WorkflowRepresentation>(); workflowRepresentation.setContent(getCurrentWorkflow()); try { LOGGER.debug("Saving workflow " + getCurrentWorkflow().getName()); configPersistence.persist(workflowRepresentation); } catch (InvalidConfigurationException e) { LOGGER.error("Invalid Configuration: " + e.getMessage()); throw new PersistenceException(e); } }