60 lines
2.2 KiB
Java
60 lines
2.2 KiB
Java
package eu.dnetlib.manager.wf.workflows.util;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.springframework.beans.BeansException;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.context.ApplicationContextAware;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import eu.dnetlib.errors.WorkflowManagerException;
|
|
import eu.dnetlib.manager.wf.nodes.DefaultJobNode;
|
|
import eu.dnetlib.manager.wf.nodes.ProcessNode;
|
|
import eu.dnetlib.manager.wf.nodes.SuccessNode;
|
|
import eu.dnetlib.manager.wf.workflows.graph.GraphNode;
|
|
import eu.dnetlib.manager.wf.workflows.procs.ProcessAware;
|
|
import eu.dnetlib.manager.wf.workflows.procs.WorkflowProcess;
|
|
|
|
@Component
|
|
public class NodeHelper implements ApplicationContextAware {
|
|
|
|
public static final String beanNamePrefix = "wfNode";
|
|
private static final Log log = LogFactory.getLog(NodeHelper.class);
|
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
public ProcessNode newProcessNode(final GraphNode node, final WorkflowProcess process) throws WorkflowManagerException {
|
|
if (node.isSucessNode()) {
|
|
return new SuccessNode();
|
|
} else if (StringUtils.isBlank(node.getType())) {
|
|
return new DefaultJobNode(node.getName());
|
|
} else {
|
|
|
|
// TODO: Considerare i nodi annotati con WfNode
|
|
final ProcessNode pnode = this.applicationContext.getBean(beanNamePrefix + node.getType(), ProcessNode.class);
|
|
if (pnode != null) {
|
|
pnode.setNodeName(node.getName());
|
|
if (pnode instanceof ProcessAware) {
|
|
((ProcessAware) pnode).setProcess(process);
|
|
}
|
|
return pnode;
|
|
} else {
|
|
log.error("cannot find bean " + beanNamePrefix + node.getType());
|
|
throw new WorkflowManagerException("cannot find bean " + beanNamePrefix + node.getType());
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean isValidType(final String type) {
|
|
return StringUtils.isBlank(type) || this.applicationContext.isPrototype(beanNamePrefix + type) && this.applicationContext
|
|
.isTypeMatch(beanNamePrefix + type, ProcessNode.class);
|
|
}
|
|
|
|
@Override
|
|
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
|
|
this.applicationContext = applicationContext;
|
|
}
|
|
|
|
}
|