Search in sources :

Example 71 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class InputLogicParser method parse.

public String parse(Element root, String opt, String min, String wait) {
    StringBuffer parsedString = new StringBuffer();
    Namespace ns = root.getNamespace();
    if (root.getName().equals(COMBINE)) {
        parsedString.append("(");
        parsedString.append(processCombinedNode(root, getOpt(root.getName()), getMin(root, min), getWait(root, wait)));
        parsedString.append(")");
    } else if (root.getName().equals(AND) || root.getName().equals(OR)) {
        parsedString.append("(");
        parsedString.append(parseAllChildren(root, opt, getOpt(root.getName()), getMin(root, min), getWait(root, wait)));
        parsedString.append(")");
    } else if (root.getChild(COORD_INPUT_EVENTS_DATA_IN, ns) != null) {
        parsedString.append("(");
        parsedString.append(processChildNode(root, getOpt(root.getName()), getMin(root, min), getWait(root, wait)));
        parsedString.append(")");
    } else if (root.getName().equals(COORD_INPUT_EVENTS_DATA_IN)) {
        parsedString.append(parseDataInNode(root, min, wait));
    }
    return parsedString.toString();
}
Also used : Namespace(org.jdom.Namespace)

Example 72 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class InputLogicParser method processCombinedNode.

/**
 * Process combined node.
 *
 * @param root the root
 * @param opt the opt
 * @param min the min
 * @param wait the wait
 * @return the string
 */
@SuppressWarnings("unchecked")
private String processCombinedNode(final Element root, final String opt, final String min, final String wait) {
    StringBuffer parsedString = new StringBuffer();
    Namespace ns = root.getNamespace();
    List<Element> childrens = root.getChildren(COORD_INPUT_EVENTS_DATA_IN, ns);
    parsedString.append("dependencyBuilder.combine(");
    for (int i = 0; i < childrens.size(); i++) {
        String nestedChildDataName = childrens.get(i).getAttributeValue("dataset");
        parsedString.append("\"" + nestedChildDataName + "\"");
        if (i < childrens.size() - 1) {
            parsedString.append(",");
        }
    }
    parsedString.append(")");
    appendMin(root, min, parsedString);
    appendWait(root, wait, parsedString);
    parsedString.append(".build()");
    return parsedString.toString();
}
Also used : Element(org.jdom.Element) Namespace(org.jdom.Namespace)

Example 73 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class ForTestingActionExecutor method end.

public void end(Context context, WorkflowAction action) throws ActionExecutorException {
    Element eConf = getConfiguration(action.getConf());
    Namespace ns = eConf.getNamespace();
    String error = eConf.getChild("error", ns).getText().trim();
    if ("end.transient".equals(error)) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.TRANSIENT, TEST_ERROR, "end");
    }
    if ("end.non-transient".equals(error)) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.NON_TRANSIENT, TEST_ERROR, "end");
    }
    if ("end.error".equals(error)) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, TEST_ERROR, "end");
    }
    String signalValue = eConf.getChild("signal-value", ns).getText().trim();
    String externalStatus = action.getExternalStatus();
    WorkflowAction.Status status = null;
    if (externalStatus.equals("ok")) {
        status = WorkflowAction.Status.OK;
    } else {
        status = WorkflowAction.Status.ERROR;
    }
    if (signalValue.equals("based_on_action_status")) {
        signalValue = status.toString();
    }
    boolean callSetEndData = true;
    Element setEndData = eConf.getChild("avoid-set-end-data", ns);
    if (null != setEndData) {
        if (setEndData.getText().trim().equals("true")) {
            callSetEndData = false;
        }
    }
    if (callSetEndData) {
        context.setEndData(status, signalValue);
    }
}
Also used : WorkflowAction(org.apache.oozie.client.WorkflowAction) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) Namespace(org.jdom.Namespace)

Example 74 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class ForTestingActionExecutor method start.

public void start(Context context, WorkflowAction action) throws ActionExecutorException {
    Element eConf = getConfiguration(action.getConf());
    Namespace ns = eConf.getNamespace();
    String error = eConf.getChild("error", ns).getText().trim();
    if ("start.transient".equals(error)) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.TRANSIENT, TEST_ERROR, "start");
    }
    if ("start.non-transient".equals(error)) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.NON_TRANSIENT, TEST_ERROR, "start");
    }
    if ("start.error".equals(error)) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, TEST_ERROR, "start");
    }
    String externalStatus = eConf.getChild("external-status", ns).getText().trim();
    Element externalChildIds = eConf.getChild("external-childIds", ns);
    String runningMode = "sync";
    Element runningModeElement = eConf.getChild("running-mode", ns);
    if (null != runningModeElement) {
        runningMode = runningModeElement.getText().trim();
    }
    if (runningMode.equals("async")) {
        context.setStartData("blah", "blah", "blah");
        return;
    }
    if (runningMode.equals("async-error")) {
        context.setStartData("blah", "blah", "blah");
        context.setExecutionData(externalStatus, null);
        if (null != externalChildIds) {
            context.setExternalChildIDs(externalChildIds.getText());
        }
        throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, TEST_ERROR, "start");
    }
    boolean callSetExecutionData = true;
    Element setStartData = eConf.getChild("avoid-set-execution-data", ns);
    if (null != setStartData) {
        if (setStartData.getText().trim().equals("true")) {
            callSetExecutionData = false;
        }
    }
    if (callSetExecutionData) {
        context.setExecutionData(externalStatus, null);
    }
    if (null != externalChildIds) {
        context.setExternalChildIDs(externalChildIds.getText());
    }
}
Also used : Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) Namespace(org.jdom.Namespace)

Example 75 with Namespace

use of org.jdom.Namespace in project dna by leifeld.

the class Exporter method exportGraphml.

/**
 * Export filter for graphML files.
 *
 * @param matrix                 Input {@link Matrix}.
 * @param twoMode                Indicates whether the network is a two-mode network.
 * @param statementType          The statement type on which the network is based.
 * @param outfile                Name of the output file.
 * @param var1                   Name of the first variable (the rows of the matrix).
 * @param var2                   Name of the second variable (the columns of the matrix).
 * @param frequencies1           The number of statements in which the row node is involved (after filtering).
 * @param frequencies2           The number of statements in which the column node is involved (after filtering).
 * @param attributes             An ArrayList of {@link AttributeVector}s containing all attribute vectors in the database.
 * @param qualifierAggregation   A String denoting the qualifier aggregation. Valid values are "ignore", "combine", "subtract", "congruence", and "conflict".
 * @param qualifierBinary        Indicates whether the qualifier is a binary variable.
 */
private void exportGraphml(Matrix mt, boolean twoMode, StatementType statementType, String outfile, String var1, String var2, int[] frequencies1, int[] frequencies2, ArrayList<AttributeVector> attributes, String qualifierAggregation, boolean qualifierBinary) {
    // extract attributes
    String[] rn = mt.getRownames();
    String[] cn = mt.getColnames();
    String[] names;
    String[] variables;
    int[] frequencies;
    if (twoMode == true) {
        names = new String[rn.length + cn.length];
        variables = new String[names.length];
        frequencies = new int[names.length];
    } else {
        names = new String[rn.length];
        variables = new String[rn.length];
        frequencies = new int[rn.length];
    }
    for (int i = 0; i < rn.length; i++) {
        names[i] = rn[i];
        variables[i] = var1;
        frequencies[i] = frequencies1[i];
    }
    if (twoMode == true) {
        for (int i = 0; i < cn.length; i++) {
            names[i + rn.length] = cn[i];
            variables[i + rn.length] = var2;
            frequencies[i + rn.length] = frequencies2[i];
        }
    }
    int[] id = new int[names.length];
    String[] color = new String[names.length];
    String[] type = new String[names.length];
    String[] alias = new String[names.length];
    String[] notes = new String[names.length];
    for (int i = 0; i < attributes.size(); i++) {
        if (attributes.get(i).getStatementTypeId() == statementType.getId() && attributes.get(i).getVariable().equals(var1)) {
            for (int j = 0; j < rn.length; j++) {
                if (rn[j].equals(attributes.get(i).getValue())) {
                    id[j] = attributes.get(i).getId();
                    color[j] = String.format("#%02X%02X%02X", attributes.get(i).getColor().getRed(), attributes.get(i).getColor().getGreen(), attributes.get(i).getColor().getBlue());
                    type[j] = attributes.get(i).getType();
                    alias[j] = attributes.get(i).getAlias();
                    notes[j] = attributes.get(i).getNotes();
                }
            }
        } else if (attributes.get(i).getStatementTypeId() == statementType.getId() && attributes.get(i).getVariable().equals(var2) && twoMode == true) {
            for (int j = 0; j < cn.length; j++) {
                if (cn[j].equals(attributes.get(i).getValue())) {
                    id[j + rn.length] = attributes.get(i).getId();
                    color[j + rn.length] = String.format("#%02X%02X%02X", attributes.get(i).getColor().getRed(), attributes.get(i).getColor().getGreen(), attributes.get(i).getColor().getBlue());
                    type[j + rn.length] = attributes.get(i).getType();
                    alias[j + rn.length] = attributes.get(i).getAlias();
                    notes[j + rn.length] = attributes.get(i).getNotes();
                }
            }
        }
    }
    // set up graph structure
    Namespace xmlns = Namespace.getNamespace("http://graphml.graphdrawing.org/xmlns");
    Element graphml = new Element("graphml", xmlns);
    Namespace visone = Namespace.getNamespace("visone", "http://visone.info/xmlns");
    graphml.addNamespaceDeclaration(visone);
    Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    graphml.addNamespaceDeclaration(xsi);
    Namespace yNs = Namespace.getNamespace("y", "http://www.yworks.com/xml/graphml");
    graphml.addNamespaceDeclaration(yNs);
    Attribute attSchema = new Attribute("schemaLocation", "http://graphml.graphdrawing.org/xmlns/graphml http://www.yworks.com/xml/schema/graphml/1.0/ygraphml.xsd ", xsi);
    graphml.setAttribute(attSchema);
    org.jdom.Document document = new org.jdom.Document(graphml);
    Comment dataSchema = new Comment(" data schema ");
    graphml.addContent(dataSchema);
    Element keyVisoneNode = new Element("key", xmlns);
    keyVisoneNode.setAttribute(new Attribute("for", "node"));
    keyVisoneNode.setAttribute(new Attribute("id", "d0"));
    keyVisoneNode.setAttribute(new Attribute("yfiles.type", "nodegraphics"));
    graphml.addContent(keyVisoneNode);
    Element keyVisoneEdge = new Element("key", xmlns);
    keyVisoneEdge.setAttribute(new Attribute("for", "edge"));
    keyVisoneEdge.setAttribute(new Attribute("id", "e0"));
    keyVisoneEdge.setAttribute(new Attribute("yfiles.type", "edgegraphics"));
    graphml.addContent(keyVisoneEdge);
    Element keyVisoneGraph = new Element("key", xmlns);
    keyVisoneGraph.setAttribute(new Attribute("for", "graph"));
    keyVisoneGraph.setAttribute(new Attribute("id", "prop"));
    keyVisoneGraph.setAttribute(new Attribute("visone.type", "properties"));
    graphml.addContent(keyVisoneGraph);
    Element keyId = new Element("key", xmlns);
    keyId.setAttribute(new Attribute("id", "id"));
    keyId.setAttribute(new Attribute("for", "node"));
    keyId.setAttribute(new Attribute("attr.name", "id"));
    keyId.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyId);
    Element keyName = new Element("key", xmlns);
    keyName.setAttribute(new Attribute("id", "name"));
    keyName.setAttribute(new Attribute("for", "node"));
    keyName.setAttribute(new Attribute("attr.name", "name"));
    keyName.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyName);
    Element keyType = new Element("key", xmlns);
    keyType.setAttribute(new Attribute("id", "type"));
    keyType.setAttribute(new Attribute("for", "node"));
    keyType.setAttribute(new Attribute("attr.name", "type"));
    keyType.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyType);
    Element keyAlias = new Element("key", xmlns);
    keyAlias.setAttribute(new Attribute("id", "alias"));
    keyAlias.setAttribute(new Attribute("for", "node"));
    keyAlias.setAttribute(new Attribute("attr.name", "alias"));
    keyAlias.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyAlias);
    Element keyNote = new Element("key", xmlns);
    keyNote.setAttribute(new Attribute("id", "note"));
    keyNote.setAttribute(new Attribute("for", "node"));
    keyNote.setAttribute(new Attribute("attr.name", "note"));
    keyNote.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyNote);
    Element keyVariable = new Element("key", xmlns);
    keyVariable.setAttribute(new Attribute("id", "variable"));
    keyVariable.setAttribute(new Attribute("for", "node"));
    keyVariable.setAttribute(new Attribute("attr.name", "variable"));
    keyVariable.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyVariable);
    Element keyFrequency = new Element("key", xmlns);
    keyFrequency.setAttribute(new Attribute("id", "frequency"));
    keyFrequency.setAttribute(new Attribute("for", "node"));
    keyFrequency.setAttribute(new Attribute("attr.name", "frequency"));
    keyFrequency.setAttribute(new Attribute("attr.type", "int"));
    graphml.addContent(keyFrequency);
    Element keyWeight = new Element("key", xmlns);
    keyWeight.setAttribute(new Attribute("id", "weight"));
    keyWeight.setAttribute(new Attribute("for", "edge"));
    keyWeight.setAttribute(new Attribute("attr.name", "weight"));
    keyWeight.setAttribute(new Attribute("attr.type", "double"));
    graphml.addContent(keyWeight);
    Element graphElement = new Element("graph", xmlns);
    graphElement.setAttribute(new Attribute("edgedefault", "undirected"));
    graphElement.setAttribute(new Attribute("id", "DNA"));
    int numEdges = rn.length * cn.length;
    if (twoMode == false) {
        numEdges = (numEdges / 2) - rn.length;
    }
    int numNodes = rn.length;
    if (twoMode == true) {
        numNodes = numNodes + cn.length;
    }
    graphElement.setAttribute(new Attribute("parse.edges", String.valueOf(numEdges)));
    graphElement.setAttribute(new Attribute("parse.nodes", String.valueOf(numNodes)));
    graphElement.setAttribute(new Attribute("parse.order", "free"));
    Element properties = new Element("data", xmlns);
    properties.setAttribute(new Attribute("key", "prop"));
    Element labelAttribute = new Element("labelAttribute", visone);
    labelAttribute.setAttribute("edgeLabel", "weight");
    labelAttribute.setAttribute("nodeLabel", "name");
    properties.addContent(labelAttribute);
    graphElement.addContent(properties);
    // add nodes
    Comment nodes = new Comment(" nodes ");
    graphElement.addContent(nodes);
    for (int i = 0; i < names.length; i++) {
        Element node = new Element("node", xmlns);
        node.setAttribute(new Attribute("id", "n" + id[i]));
        Element idElement = new Element("data", xmlns);
        idElement.setAttribute(new Attribute("key", "id"));
        idElement.setText(String.valueOf(id[i]));
        node.addContent(idElement);
        Element nameElement = new Element("data", xmlns);
        nameElement.setAttribute(new Attribute("key", "name"));
        nameElement.setText(names[i]);
        node.addContent(nameElement);
        Element typeElement = new Element("data", xmlns);
        typeElement.setAttribute(new Attribute("key", "type"));
        typeElement.setText(type[i]);
        node.addContent(typeElement);
        Element aliasElement = new Element("data", xmlns);
        aliasElement.setAttribute(new Attribute("key", "alias"));
        aliasElement.setText(alias[i]);
        node.addContent(aliasElement);
        Element notesElement = new Element("data", xmlns);
        notesElement.setAttribute(new Attribute("key", "notes"));
        notesElement.setText(notes[i]);
        node.addContent(notesElement);
        Element variableElement = new Element("data", xmlns);
        variableElement.setAttribute(new Attribute("key", "variable"));
        variableElement.setText(variables[i]);
        node.addContent(variableElement);
        Element frequency = new Element("data", xmlns);
        frequency.setAttribute(new Attribute("key", "frequency"));
        frequency.setText(String.valueOf(frequencies[i]));
        node.addContent(frequency);
        Element vis = new Element("data", xmlns);
        vis.setAttribute(new Attribute("key", "d0"));
        Element visoneShapeNode = new Element("shapeNode", visone);
        Element yShapeNode = new Element("ShapeNode", yNs);
        Element geometry = new Element("Geometry", yNs);
        geometry.setAttribute(new Attribute("height", "20.0"));
        geometry.setAttribute(new Attribute("width", "20.0"));
        geometry.setAttribute(new Attribute("x", String.valueOf(Math.random() * 800)));
        geometry.setAttribute(new Attribute("y", String.valueOf(Math.random() * 600)));
        yShapeNode.addContent(geometry);
        Element fill = new Element("Fill", yNs);
        fill.setAttribute(new Attribute("color", color[i]));
        fill.setAttribute(new Attribute("transparent", "false"));
        yShapeNode.addContent(fill);
        Element borderStyle = new Element("BorderStyle", yNs);
        borderStyle.setAttribute(new Attribute("color", "#000000"));
        borderStyle.setAttribute(new Attribute("type", "line"));
        borderStyle.setAttribute(new Attribute("width", "1.0"));
        yShapeNode.addContent(borderStyle);
        Element nodeLabel = new Element("NodeLabel", yNs);
        nodeLabel.setAttribute(new Attribute("alignment", "center"));
        nodeLabel.setAttribute(new Attribute("autoSizePolicy", "content"));
        nodeLabel.setAttribute(new Attribute("backgroundColor", "#FFFFFF"));
        nodeLabel.setAttribute(new Attribute("fontFamily", "Dialog"));
        nodeLabel.setAttribute(new Attribute("fontSize", "12"));
        nodeLabel.setAttribute(new Attribute("fontStyle", "plain"));
        nodeLabel.setAttribute(new Attribute("hasLineColor", "false"));
        nodeLabel.setAttribute(new Attribute("height", "19.0"));
        nodeLabel.setAttribute(new Attribute("modelName", "eight_pos"));
        nodeLabel.setAttribute(new Attribute("modelPosition", "n"));
        nodeLabel.setAttribute(new Attribute("textColor", "#000000"));
        nodeLabel.setAttribute(new Attribute("visible", "true"));
        nodeLabel.setText(names[i]);
        yShapeNode.addContent(nodeLabel);
        Element shape = new Element("Shape", yNs);
        if (i < rn.length) {
            shape.setAttribute(new Attribute("type", "ellipse"));
        } else {
            shape.setAttribute(new Attribute("type", "roundrectangle"));
        }
        yShapeNode.addContent(shape);
        visoneShapeNode.addContent(yShapeNode);
        vis.addContent(visoneShapeNode);
        node.addContent(vis);
        graphElement.addContent(node);
    }
    // add edges
    double[][] m = mt.getMatrix();
    Comment edges = new Comment(" edges ");
    graphElement.addContent(edges);
    for (int i = 0; i < rn.length; i++) {
        for (int j = 0; j < cn.length; j++) {
            if (m[i][j] != 0.0 && (twoMode == true || (twoMode == false && i < j))) {
                // only lower triangle is used for one-mode networks
                Element edge = new Element("edge", xmlns);
                int currentId = id[i];
                edge.setAttribute(new Attribute("source", "n" + String.valueOf(currentId)));
                if (twoMode == true) {
                    currentId = id[j + rn.length];
                } else {
                    currentId = id[j];
                }
                edge.setAttribute(new Attribute("target", "n" + String.valueOf(currentId)));
                Element weight = new Element("data", xmlns);
                weight.setAttribute(new Attribute("key", "weight"));
                weight.setText(String.valueOf(m[i][j]));
                edge.addContent(weight);
                Element visEdge = new Element("data", xmlns);
                visEdge.setAttribute("key", "e0");
                Element visPolyLineEdge = new Element("polyLineEdge", visone);
                Element yPolyLineEdge = new Element("PolyLineEdge", yNs);
                Element yLineStyle = new Element("LineStyle", yNs);
                if (qualifierAggregation.equals("combine") && qualifierBinary == true) {
                    if (m[i][j] == 1.0) {
                        yLineStyle.setAttribute("color", "#00ff00");
                    } else if (m[i][j] == 2.0) {
                        yLineStyle.setAttribute("color", "#ff0000");
                    } else if (m[i][j] == 3.0) {
                        yLineStyle.setAttribute("color", "#0000ff");
                    }
                } else if (qualifierAggregation.equals("subtract")) {
                    if (m[i][j] < 0) {
                        yLineStyle.setAttribute("color", "#ff0000");
                    } else if (m[i][j] > 0) {
                        yLineStyle.setAttribute("color", "#00ff00");
                    }
                } else if (qualifierAggregation.equals("conflict")) {
                    yLineStyle.setAttribute("color", "#ff0000");
                } else if (qualifierAggregation.equals("congruence")) {
                    yLineStyle.setAttribute("color", "#00ff00");
                } else {
                    yLineStyle.setAttribute("color", "#000000");
                }
                yLineStyle.setAttribute(new Attribute("type", "line"));
                yLineStyle.setAttribute(new Attribute("width", "2.0"));
                yPolyLineEdge.addContent(yLineStyle);
                visPolyLineEdge.addContent(yPolyLineEdge);
                visEdge.addContent(visPolyLineEdge);
                edge.addContent(visEdge);
                graphElement.addContent(edge);
            }
        }
    }
    graphml.addContent(graphElement);
    // write to file
    File dnaFile = new File(outfile);
    try {
        FileOutputStream outStream = new FileOutputStream(dnaFile);
        XMLOutputter outToFile = new XMLOutputter();
        Format format = Format.getPrettyFormat();
        format.setEncoding("utf-8");
        outToFile.setFormat(format);
        outToFile.output(document, outStream);
        outStream.flush();
        outStream.close();
    } catch (IOException e) {
        System.err.println("Cannot save \"" + dnaFile + "\":" + e.getMessage());
    }
}
Also used : Comment(org.jdom.Comment) XMLOutputter(org.jdom.output.XMLOutputter) Attribute(org.jdom.Attribute) Element(org.jdom.Element) IOException(java.io.IOException) Document(dna.dataStructures.Document) Namespace(org.jdom.Namespace) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Format(org.jdom.output.Format) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

Namespace (org.jdom.Namespace)102 Element (org.jdom.Element)85 IOException (java.io.IOException)24 XConfiguration (org.apache.oozie.util.XConfiguration)19 StringReader (java.io.StringReader)15 Configuration (org.apache.hadoop.conf.Configuration)15 JDOMException (org.jdom.JDOMException)15 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)13 ArrayList (java.util.ArrayList)12 Path (org.apache.hadoop.fs.Path)11 Document (org.jdom.Document)11 List (java.util.List)9 File (java.io.File)7 HashMap (java.util.HashMap)6 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6 SAXBuilder (org.jdom.input.SAXBuilder)6 XMLOutputter (org.jdom.output.XMLOutputter)6 Writer (java.io.Writer)5 Attribute (org.jdom.Attribute)5 Format (org.jdom.output.Format)5