Search in sources :

Example 1 with EscalationType

use of com.tremolosecurity.config.xml.EscalationType in project OpenUnison by TremoloSecurity.

the class ParseWorkflow method createApprovalTask.

private void createApprovalTask(JSONObject node, String path, List<WorkflowTaskType> parent, ParsedWorkflow pw) {
    ApprovalType task = new ApprovalType();
    task.setApprovers(new AzRulesType());
    OptionType[] options = new OptionType[] { new OptionType("emailTemplate", true, OptionType.OptionValueType.STRING), new OptionType("mailAttr", true, OptionType.OptionValueType.STRING), new OptionType("failureEmailSubject", true, OptionType.OptionValueType.STRING), new OptionType("failureEmailMsg", true, OptionType.OptionValueType.STRING), new OptionType("label", true, OptionType.OptionValueType.STRING) };
    for (OptionType ot : options) {
        setAttribute(node, ot, task, ApprovalType.class, pw, path);
        if (pw.getError() != null) {
            return;
        }
    }
    Object o = node.get("approvers");
    node.remove("approvers");
    parseApprovers(path + ".approvers", pw, task.getApprovers(), o, "approvers");
    if (pw.getError() != null) {
        return;
    }
    o = node.get("escalationPolicy");
    if (o != null) {
        node.remove("escalationPolicy");
        task.setEscalationPolicy(new EscalationPolicyType());
        if (!(o instanceof JSONObject)) {
            pw.setErrorPath(path + ".escalationPolicy");
            pw.setError("escalationPolicy must be an object");
            return;
        }
        JSONObject escPolicy = (JSONObject) o;
        o = escPolicy.get("escalations");
        escPolicy.remove("escalations");
        if (o == null) {
            pw.setErrorPath(path + ".escalationPolicy.escalations");
            pw.setError("At least one escalation must be specified");
            return;
        }
        if (!(o instanceof JSONArray)) {
            pw.setErrorPath(path + ".escalationPolicy.escalations");
            pw.setError("escalations must be an array");
            return;
        }
        JSONArray escs = (JSONArray) o;
        int ii = 0;
        OptionType[] escOpts = new OptionType[] { new OptionType("executeAfterTime", true, OptionType.OptionValueType.INT), new OptionType("validateEscalationClass", false, OptionType.OptionValueType.STRING), new OptionType("executeAfterUnits", true, OptionType.OptionValueType.STRING, ParseWorkflow.approversEscUnits) };
        for (Object ox : escs) {
            EscalationType esc = new EscalationType();
            esc.setAzRules(new AzRulesType());
            if (!(ox instanceof JSONObject)) {
                pw.setErrorPath(path + ".escalationPolicy.escalations[" + ii + "]");
                pw.setError("escalation must be an object");
                return;
            }
            JSONObject jesc = (JSONObject) ox;
            for (OptionType ot : escOpts) {
                setAttribute(jesc, ot, esc, EscalationType.class, pw, path + ".escalationPolicy.escalations[" + ii + "]");
                if (pw.getError() != null) {
                    return;
                }
            }
            o = jesc.get("azRules");
            jesc.remove("azRules");
            parseApprovers(path + ".escalationPolicy.escalations[" + ii + "]", pw, esc.getAzRules(), o, "azRules");
            if (pw.getError() != null) {
                return;
            }
            if (!jesc.isEmpty()) {
                pw.setError("Extra JSON keys : " + jesc.toString());
                pw.setErrorPath(path + ".escalationPolicy.escalations[" + ii + "]");
                return;
            }
            task.getEscalationPolicy().getEscalation().add(esc);
            ii++;
        }
        o = escPolicy.get("failure");
        escPolicy.remove("failure");
        if (o != null) {
            if (!(o instanceof JSONObject)) {
                pw.setErrorPath(path + ".escalationPolicy.failure");
                pw.setError("filure must be an object");
                return;
            }
            JSONObject escFailure = (JSONObject) o;
            EscalationFailureType eft = new EscalationFailureType();
            eft.setAzRules(new AzRulesType());
            task.getEscalationPolicy().setEscalationFailure(eft);
            OptionType[] escfOpts = new OptionType[] { new OptionType("action", true, OptionType.OptionValueType.STRING, ParseWorkflow.escalationFailureActions) };
            for (OptionType ot : escfOpts) {
                setAttribute(escFailure, ot, eft, EscalationFailureType.class, pw, path + ".escalationPolicy.failure");
                if (pw.getError() != null) {
                    return;
                }
            }
            o = escFailure.get("azRules");
            escFailure.remove("azRules");
            parseApprovers(path + ".escalationPolicy.failure", pw, eft.getAzRules(), o, "azRules");
            if (pw.getError() != null) {
                return;
            }
            if (!escFailure.isEmpty()) {
                pw.setError("Extra JSON keys : " + escFailure.toString());
                pw.setErrorPath(path + ".escalationPolicy.failure");
                return;
            }
        }
        if (!escPolicy.isEmpty()) {
            pw.setError("Extra JSON keys : " + node.toString());
            pw.setErrorPath(path + ".escalationPolicy");
            return;
        }
    }
    loadSubTasks(node, path, pw, task);
    if (pw.getError() != null) {
        return;
    }
    if (!node.isEmpty()) {
        pw.setError("Extra JSON keys : " + node.toString());
        pw.setErrorPath(path);
        return;
    }
    parent.add(task);
}
Also used : EscalationType(com.tremolosecurity.config.xml.EscalationType) EscalationPolicyType(com.tremolosecurity.config.xml.EscalationPolicyType) JSONObject(org.json.simple.JSONObject) AzRulesType(com.tremolosecurity.config.xml.AzRulesType) ApprovalType(com.tremolosecurity.config.xml.ApprovalType) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) EscalationFailureType(com.tremolosecurity.config.xml.EscalationFailureType)

Aggregations

ApprovalType (com.tremolosecurity.config.xml.ApprovalType)1 AzRulesType (com.tremolosecurity.config.xml.AzRulesType)1 EscalationFailureType (com.tremolosecurity.config.xml.EscalationFailureType)1 EscalationPolicyType (com.tremolosecurity.config.xml.EscalationPolicyType)1 EscalationType (com.tremolosecurity.config.xml.EscalationType)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1