All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.tsl2.nano.specification.documentconsumer.WorkflowConsumer Maven / Gradle / Ivy

Go to download

TSL2 Framework Specification (Pools of descripted and runnable Actions and Rules, Generic Tree)

The newest version!
package de.tsl2.nano.specification.documentconsumer;

import java.io.File;
import java.util.Scanner;

import de.tsl2.nano.core.ENV;
import de.tsl2.nano.core.util.FileUtil;
import de.tsl2.nano.specification.PFlow;
import de.tsl2.nano.specification.Pool;
import de.tsl2.nano.specification.Workflow;

public class WorkflowConsumer extends SimpleDocumentTag {

	@Override
	public void after(File t, String toBeConsumed) {
		String flowFileName = (String) ENV.get("flowfilename");
		flowFileName = createFlow(flowFileName, toBeConsumed);
		Workflow.main(new String[] {flowFileName, (String) ENV.get("schedule"), (String) ENV.get("queryname")});
	}

	private String createFlow(String flowFileName, String toBeConsumed) {
		Scanner sc = new Scanner(toBeConsumed);
		StringBuilder flow = new StringBuilder();
		boolean start = false;
		while(sc.hasNext()) {
			String l = sc.nextLine();
			if (start || l.trim().startsWith("START")) {
				start = true;
				flow.append(l + "\n");
				if (l.trim().endsWith("END"))
					break;
			}
		}
		String path = ENV.get(Pool.class).getDirectory(PFlow.class) + flowFileName;
		FileUtil.writeBytes(flow.toString().getBytes(), path, false);
		ENV.get(Pool.class).add(PFlow.load(FileUtil.userDirFile(path)));
		return path;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy