Search in sources :

Example 1 with ExecuteScriptsType

use of com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsType in project midpoint by Evolveum.

the class ModelWebServiceRaw method invokeAllowingFaults.

public DOMSource invokeAllowingFaults(DOMSource request) throws FaultMessage {
    Node rootNode = request.getNode();
    Element rootElement;
    if (rootNode instanceof Document) {
        rootElement = ((Document) rootNode).getDocumentElement();
    } else if (rootNode instanceof Element) {
        rootElement = (Element) rootNode;
    } else {
        throw ws.createIllegalArgumentFault("Unexpected DOM node type: " + rootNode);
    }
    Object requestObject;
    try {
        requestObject = prismContext.parserFor(rootElement).parseRealValue();
    } catch (SchemaException e) {
        throw ws.createIllegalArgumentFault("Couldn't parse SOAP request body because of schema exception: " + e.getMessage());
    }
    Node response;
    Holder<OperationResultType> operationResultTypeHolder = new Holder<>();
    try {
        PrismSerializer<Element> serializer = prismContext.domSerializer().options(SerializationOptions.createSerializeReferenceNames());
        if (requestObject instanceof GetObjectType) {
            GetObjectType g = (GetObjectType) requestObject;
            Holder<ObjectType> objectTypeHolder = new Holder<>();
            ws.getObject(g.getObjectType(), g.getOid(), g.getOptions(), objectTypeHolder, operationResultTypeHolder);
            GetObjectResponseType gr = new GetObjectResponseType();
            gr.setObject(objectTypeHolder.value);
            gr.setResult(operationResultTypeHolder.value);
            response = serializer.serializeAnyData(gr, ModelPort.GET_OBJECT_RESPONSE);
        } else if (requestObject instanceof SearchObjectsType) {
            SearchObjectsType s = (SearchObjectsType) requestObject;
            Holder<ObjectListType> objectListTypeHolder = new Holder<>();
            ws.searchObjects(s.getObjectType(), s.getQuery(), s.getOptions(), objectListTypeHolder, operationResultTypeHolder);
            SearchObjectsResponseType sr = new SearchObjectsResponseType();
            sr.setObjectList(objectListTypeHolder.value);
            sr.setResult(operationResultTypeHolder.value);
            response = serializer.serializeAnyData(sr, ModelPort.SEARCH_OBJECTS_RESPONSE);
        } else if (requestObject instanceof ExecuteChangesType) {
            ExecuteChangesType e = (ExecuteChangesType) requestObject;
            ObjectDeltaOperationListType objectDeltaOperationListType = ws.executeChanges(e.getDeltaList(), e.getOptions());
            ExecuteChangesResponseType er = new ExecuteChangesResponseType();
            er.setDeltaOperationList(objectDeltaOperationListType);
            response = serializer.serializeAnyData(er, ModelPort.EXECUTE_CHANGES_RESPONSE);
        } else if (requestObject instanceof FindShadowOwnerType) {
            FindShadowOwnerType f = (FindShadowOwnerType) requestObject;
            Holder<UserType> userTypeHolder = new Holder<>();
            ws.findShadowOwner(f.getShadowOid(), userTypeHolder, operationResultTypeHolder);
            FindShadowOwnerResponseType fsr = new FindShadowOwnerResponseType();
            fsr.setUser(userTypeHolder.value);
            fsr.setResult(operationResultTypeHolder.value);
            response = serializer.serializeAnyData(fsr, ModelPort.FIND_SHADOW_OWNER_RESPONSE);
        } else if (requestObject instanceof TestResourceType) {
            TestResourceType tr = (TestResourceType) requestObject;
            OperationResultType operationResultType = ws.testResource(tr.getResourceOid());
            TestResourceResponseType trr = new TestResourceResponseType();
            trr.setResult(operationResultType);
            response = serializer.serializeAnyData(trr, ModelPort.TEST_RESOURCE_RESPONSE);
        } else if (requestObject instanceof ExecuteScriptsType) {
            ExecuteScriptsType es = (ExecuteScriptsType) requestObject;
            ExecuteScriptsResponseType esr = ws.executeScripts(es);
            response = serializer.serializeAnyData(esr, ModelPort.EXECUTE_SCRIPTS_RESPONSE);
        } else if (requestObject instanceof ImportFromResourceType) {
            ImportFromResourceType ifr = (ImportFromResourceType) requestObject;
            TaskType taskType = ws.importFromResource(ifr.getResourceOid(), ifr.getObjectClass());
            ImportFromResourceResponseType ifrr = new ImportFromResourceResponseType();
            ifrr.setTask(taskType);
            response = serializer.serializeAnyData(ifrr, ModelPort.IMPORT_FROM_RESOURCE_RESPONSE);
        } else if (requestObject instanceof NotifyChangeType) {
            NotifyChangeType nc = (NotifyChangeType) requestObject;
            TaskType taskType = ws.notifyChange(nc.getChangeDescription());
            NotifyChangeResponseType ncr = new NotifyChangeResponseType();
            ncr.setTask(taskType);
            response = serializer.serializeAnyData(ncr, ModelPort.NOTIFY_CHANGE_RESPONSE);
        } else {
            throw ws.createIllegalArgumentFault("Unsupported request type: " + requestObject);
        }
    } catch (SchemaException e) {
        throwFault(e, operationResultTypeHolder.value);
        // not reached
        return null;
    }
    return new DOMSource(response);
}
Also used : ExecuteChangesResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesResponseType) DOMSource(javax.xml.transform.dom.DOMSource) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ExecuteChangesType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesType) FindShadowOwnerResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.FindShadowOwnerResponseType) Document(org.w3c.dom.Document) FindShadowOwnerType(com.evolveum.midpoint.xml.ns._public.model.model_3.FindShadowOwnerType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GetObjectType(com.evolveum.midpoint.xml.ns._public.model.model_3.GetObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) GetObjectType(com.evolveum.midpoint.xml.ns._public.model.model_3.GetObjectType) ImportFromResourceType(com.evolveum.midpoint.xml.ns._public.model.model_3.ImportFromResourceType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NotifyChangeType(com.evolveum.midpoint.xml.ns._public.model.model_3.NotifyChangeType) GetObjectResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.GetObjectResponseType) Holder(javax.xml.ws.Holder) NotifyChangeResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.NotifyChangeResponseType) TestResourceType(com.evolveum.midpoint.xml.ns._public.model.model_3.TestResourceType) SearchObjectsType(com.evolveum.midpoint.xml.ns._public.model.model_3.SearchObjectsType) ImportFromResourceResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ImportFromResourceResponseType) ExecuteScriptsResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsResponseType) ExecuteScriptsType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsType) SearchObjectsResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.SearchObjectsResponseType) TestResourceResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.TestResourceResponseType) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)

Example 2 with ExecuteScriptsType

use of com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsType in project midpoint by Evolveum.

the class RunScript method main.

/**
	 * @param args
	 */
public static void main(String[] args) {
    try {
        Options options = new Options();
        options.addOption(OPT_HELP, "help", false, "Print this help information");
        options.addOption(OPT_SCRIPT, "script", true, "Script file (XML for the moment)");
        options.addOption(OPT_URL, true, "Endpoint URL (default: " + DEFAULT_ENDPOINT_URL + ")");
        options.addOption(OPT_USER, "user", true, "User name (default: " + ADM_USERNAME + ")");
        options.addOption(OPT_PASSWORD, "password", true, "Password");
        options.addOption(OPT_FILE_FOR_DATA, "file-for-data", true, "Name of the file to write resulting XML data into");
        options.addOption(OPT_FILE_FOR_CONSOLE, "file-for-console", true, "Name of the file to write resulting console output into");
        options.addOption(OPT_FILE_FOR_RESULT, "file-for-result", true, "Name of the file to write operation result into");
        options.addOption(OPT_HIDE_DATA, "hide-data", false, "Don't display data output");
        options.addOption(OPT_HIDE_SCRIPT, "hide-script", false, "Don't display input script");
        options.addOption(OPT_HIDE_CONSOLE, "hide-console", false, "Don't display console output");
        options.addOption(OPT_HIDE_RESULT, "hide-result", false, "Don't display detailed operation result (default: showing if not SUCCESS)");
        options.addOption(OPT_SHOW_RESULT, "show-result", false, "Always show detailed operation result (default: showing if not SUCCESS)");
        options.addOption(OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator().withDescription("use value for given property").create("D"));
        CommandLineParser parser = new GnuParser();
        CommandLine cmdline = parser.parse(options, args);
        if (!cmdline.hasOption(OPT_SCRIPT) || cmdline.hasOption("h")) {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("runscript", options);
            System.exit(0);
        }
        ExecuteScriptsType request = new ExecuteScriptsType();
        String script = readXmlFile(cmdline.getOptionValue(OPT_SCRIPT));
        script = replaceParameters(script, cmdline.getOptionProperties("D"));
        // todo fix this hack
        request.setMslScripts(script);
        ExecuteScriptsOptionsType optionsType = new ExecuteScriptsOptionsType();
        // todo fix this hack
        optionsType.setOutputFormat(OutputFormatType.MSL);
        request.setOptions(optionsType);
        if (!cmdline.hasOption(OPT_HIDE_SCRIPT)) {
            System.out.println("\nScript to execute:\n" + script);
        }
        System.out.println("=================================================================");
        ModelPortType modelPort = createModelPort(cmdline);
        ExecuteScriptsResponseType response = modelPort.executeScripts(request);
        System.out.println("=================================================================");
        for (SingleScriptOutputType output : response.getOutputs().getOutput()) {
            if (!cmdline.hasOption(OPT_HIDE_DATA)) {
                System.out.println("Data:\n" + output.getMslData());
                System.out.println("-----------------------------------------------------------------");
            }
            if (cmdline.hasOption(OPT_FILE_FOR_DATA)) {
                IOUtils.write(output.getMslData(), new FileOutputStream(cmdline.getOptionValue(OPT_FILE_FOR_DATA)), "UTF-8");
            }
            if (!cmdline.hasOption(OPT_HIDE_CONSOLE)) {
                System.out.println("Console output:\n" + output.getTextOutput());
            }
            if (cmdline.hasOption(OPT_HIDE_CONSOLE)) {
                IOUtils.write(output.getMslData(), new FileWriter(cmdline.getOptionValue(OPT_FILE_FOR_CONSOLE)));
            }
        }
        System.out.println("=================================================================");
        System.out.println("Operation result: " + getResultStatus(response.getResult()));
        if (!cmdline.hasOption(OPT_HIDE_RESULT) && (cmdline.hasOption(OPT_SHOW_RESULT) || response.getResult() == null || response.getResult().getStatus() != OperationResultStatusType.SUCCESS)) {
            System.out.println("\n\n" + marshalResult(response.getResult()));
        }
        if (cmdline.hasOption(OPT_FILE_FOR_RESULT)) {
            IOUtils.write(marshalResult(response.getResult()), new FileWriter(cmdline.getOptionValue(OPT_FILE_FOR_RESULT)));
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : Options(org.apache.commons.cli.Options) ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) FileWriter(java.io.FileWriter) GnuParser(org.apache.commons.cli.GnuParser) SingleScriptOutputType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.SingleScriptOutputType) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) ExecuteScriptsResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsResponseType) FileOutputStream(java.io.FileOutputStream) ExecuteScriptsType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsType) CommandLineParser(org.apache.commons.cli.CommandLineParser) ExecuteScriptsOptionsType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptsOptionsType)

Example 3 with ExecuteScriptsType

use of com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsType in project midpoint by Evolveum.

the class BulkAction method executeAction.

@Override
protected void executeAction() throws Exception {
    ModelPortType port = createModelPort();
    try {
        ExecuteScriptsOptionsType options = new ExecuteScriptsOptionsType();
        options.setExecuteAsynchronously(getParams().isAsync());
        options.setObjectLimit(getParams().getLimit());
        options.setOutputFormat(getParams().getOutput());
        ExecuteScriptsType parameters = new ExecuteScriptsType();
        parameters.setOptions(options);
        parameters.setMslScripts(getParams().getMslScript());
        //todo implement xml support
        //parameters.setXmlScripts(xml);
        ExecuteScriptsResponseType response = port.executeScripts(parameters);
    //todo implement
    } catch (FaultMessage ex) {
        handleError("Couldn't execute scripts", ex);
    }
}
Also used : FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) ExecuteScriptsResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsResponseType) ExecuteScriptsType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsType) ExecuteScriptsOptionsType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptsOptionsType)

Aggregations

ExecuteScriptsResponseType (com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsResponseType)3 ExecuteScriptsType (com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsType)3 ExecuteScriptsOptionsType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptsOptionsType)2 ModelPortType (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)1 SingleScriptOutputType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.SingleScriptOutputType)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)1 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)1 FaultMessage (com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage)1 ExecuteChangesResponseType (com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesResponseType)1 ExecuteChangesType (com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesType)1 FindShadowOwnerResponseType (com.evolveum.midpoint.xml.ns._public.model.model_3.FindShadowOwnerResponseType)1 FindShadowOwnerType (com.evolveum.midpoint.xml.ns._public.model.model_3.FindShadowOwnerType)1 GetObjectResponseType (com.evolveum.midpoint.xml.ns._public.model.model_3.GetObjectResponseType)1 GetObjectType (com.evolveum.midpoint.xml.ns._public.model.model_3.GetObjectType)1 ImportFromResourceResponseType (com.evolveum.midpoint.xml.ns._public.model.model_3.ImportFromResourceResponseType)1 ImportFromResourceType (com.evolveum.midpoint.xml.ns._public.model.model_3.ImportFromResourceType)1 NotifyChangeResponseType (com.evolveum.midpoint.xml.ns._public.model.model_3.NotifyChangeResponseType)1