Search in sources :

Example 1 with PipelineItemType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType in project midpoint by Evolveum.

the class PipelineData method prepareXmlData.

public static PipelineDataType prepareXmlData(List<PipelineItem> output, ScriptingExpressionEvaluationOptionsType options) {
    boolean hideResults = options != null && Boolean.TRUE.equals(options.isHideOperationResults());
    PipelineDataType rv = new PipelineDataType();
    if (output != null) {
        for (PipelineItem item : output) {
            PipelineItemType itemType = new PipelineItemType();
            PrismValue value = item.getValue();
            if (value instanceof PrismReferenceValue) {
                // This is a bit of hack: value.getRealValue() would return unserializable object (PRV$1 - does not have type QName)
                ObjectReferenceType ort = new ObjectReferenceType();
                ort.setupReferenceValue((PrismReferenceValue) value);
                itemType.setValue(ort);
            } else {
                itemType.setValue(value.getRealValue());
            }
            if (!hideResults) {
                itemType.setResult(item.getResult().createOperationResultType());
            }
            rv.getItem().add(itemType);
        }
    }
    return rv;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType)

Example 2 with PipelineItemType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType in project midpoint by Evolveum.

the class TestAbstractRestService method extractItemProcessingResults.

private <X extends OperationSpecificData> List<ItemProcessingResult<X>> extractItemProcessingResults(ExecuteScriptResponseType response, Function<Object, X> operationDataExtractor) throws SchemaException {
    List<PipelineItemType> outputItems = response.getOutput().getDataOutput().getItem();
    List<ItemProcessingResult<X>> extractedResults = new ArrayList<>(outputItems.size());
    for (PipelineItemType outputItem : outputItems) {
        ItemProcessingResult<X> extractedResult = new ItemProcessingResult<>();
        Object value = outputItem.getValue();
        if (value instanceof RawType) {
            value = ((RawType) value).getParsedRealValue(Object.class);
        }
        if (value instanceof ObjectType) {
            ObjectType object = (ObjectType) value;
            extractedResult.oid = object.getOid();
            extractedResult.name = PolyString.getOrig(object.getName());
            if (operationDataExtractor != null) {
                extractedResult.data = operationDataExtractor.apply(value);
            }
        } else if (value instanceof Referencable) {
            extractedResult.oid = ((Referencable) value).getOid();
        } else {
            throw new IllegalStateException("Unexpected item value: " + value);
        }
        if (outputItem.getResult() != null) {
            extractedResult.status = outputItem.getResult().getStatus();
            extractedResult.message = outputItem.getResult().getMessage();
        }
        extractedResults.add(extractedResult);
    }
    return extractedResults;
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) ArrayList(java.util.ArrayList) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) PrismObject(com.evolveum.midpoint.prism.PrismObject) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 3 with PipelineItemType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType in project midpoint by Evolveum.

the class TestAbstractRestService method test530ModifyValidToUsingScripting.

@Test
public void test530ModifyValidToUsingScripting() throws Exception {
    WebClient client = prepareClient();
    client.path("/rpc/executeScript");
    when();
    Response response = client.post(getRepoFile(SCRIPT_MODIFY_VALID_TO));
    then();
    displayResponse(response);
    traceResponse(response);
    assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus());
    displayDumpable("Audit", getDummyAuditService());
    getDummyAuditService().assertRecords(4);
    getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
    ExecuteScriptResponseType responseData = response.readEntity(ExecuteScriptResponseType.class);
    displayValue("Response", getPrismContext().xmlSerializer().serializeRealValue(responseData));
    List<PipelineItemType> items = responseData.getOutput().getDataOutput().getItem();
    assertEquals("Wrong # of processed items", 2, items.size());
    List<ItemProcessingResult<OperationSpecificData>> extractedResults = extractItemProcessingResults(responseData, null);
    display("extractedResults", extractedResults);
    assertEquals("Wrong # of extractedResults", 2, extractedResults.size());
    ItemProcessingResult<OperationSpecificData> first = extractedResults.get(0);
    assertEquals("Wrong OID in first result", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", first.oid);
    assertEquals("Wrong status in first result", OperationResultStatusType.FATAL_ERROR, first.status);
    ItemProcessingResult<OperationSpecificData> second = extractedResults.get(1);
    assertEquals("Wrong OID in second result", USER_JACK_OID, second.oid);
    assertEquals("Wrong name in second result", "jack", second.name);
    assertEquals("Wrong status in second result", OperationResultStatusType.SUCCESS, second.status);
    UserType jackAfter = getRepositoryService().getObject(UserType.class, USER_JACK_OID, null, new OperationResult("getObject")).asObjectable();
    display("jack after", jackAfter);
    XMLGregorianCalendar expectedValidTo = XmlTypeConverter.createXMLGregorianCalendar("2018-08-31T00:00:00.000+00:00");
    assertEquals("Wrong validTo", expectedValidTo, jackAfter.getActivation().getValidTo());
}
Also used : Response(javax.ws.rs.core.Response) ExecuteScriptResponseType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptResponseType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.testng.annotations.Test)

Example 4 with PipelineItemType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType in project midpoint by Evolveum.

the class TestAbstractRestService method test520GeneratePasswordsUsingScripting.

@Test
public void test520GeneratePasswordsUsingScripting() throws Exception {
    WebClient client = prepareClient();
    client.path("/rpc/executeScript");
    when();
    Response response = client.post(getRepoFile(SCRIPT_GENERATE_PASSWORDS));
    then();
    displayResponse(response);
    traceResponse(response);
    assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus());
    ExecuteScriptResponseType responseData = response.readEntity(ExecuteScriptResponseType.class);
    displayValue("Response", getPrismContext().xmlSerializer().serializeRealValue(responseData));
    logger.info("Response: {}", getPrismContext().xmlSerializer().serializeRealValue(responseData));
    List<PipelineItemType> items = responseData.getOutput().getDataOutput().getItem();
    assertEquals("Wrong # of processed items", 2, items.size());
    List<ItemProcessingResult<PasswordGenerationData>> extractedResults = extractItemProcessingResults(responseData, new PasswordGenerationDataExtractor());
    display("extractedResults", extractedResults);
    assertEquals("Wrong # of extractedResults", 2, extractedResults.size());
    ItemProcessingResult<PasswordGenerationData> first = extractedResults.get(0);
    assertEquals("Wrong OID in first result", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", first.oid);
    assertEquals("Wrong status in first result", OperationResultStatusType.FATAL_ERROR, first.status);
    ItemProcessingResult<PasswordGenerationData> second = extractedResults.get(1);
    assertEquals("Wrong OID in second result", USER_JACK_OID, second.oid);
    assertEquals("Wrong name in second result", "jack", second.name);
    logger.info("pwd in second result {}", second.data.password);
    assertNotNull("Missing password in second result", second.data.password);
    assertEquals("Wrong status in second result", OperationResultStatusType.SUCCESS, second.status);
    UserType jackAfter = getRepositoryService().getObject(UserType.class, USER_JACK_OID, null, new OperationResult("getObject")).asObjectable();
    display("jack after", jackAfter);
    assertNotNull("password not set", jackAfter.getCredentials().getPassword().getValue());
    displayDumpable("Audit", getDummyAuditService());
    getDummyAuditService().assertRecords(4);
    getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
}
Also used : Response(javax.ws.rs.core.Response) ExecuteScriptResponseType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptResponseType) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.testng.annotations.Test)

Example 5 with PipelineItemType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType in project midpoint by Evolveum.

the class ModelWebService method prepareXmlData.

public static PipelineDataType prepareXmlData(List<PipelineItem> output, ScriptingExpressionEvaluationOptionsType options) throws JAXBException, SchemaException {
    boolean hideResults = options != null && Boolean.TRUE.equals(options.isHideOperationResults());
    PipelineDataType rv = new PipelineDataType();
    if (output != null) {
        for (PipelineItem item : output) {
            PipelineItemType itemType = new PipelineItemType();
            PrismValue value = item.getValue();
            if (value instanceof PrismReferenceValue) {
                // This is a bit of hack: value.getRealValue() would return unserializable object (PRV$1 - does not have type QName)
                ObjectReferenceType ort = new ObjectReferenceType();
                ort.setupReferenceValue((PrismReferenceValue) value);
                itemType.setValue(ort);
            } else {
                // TODO - ok?
                itemType.setValue(value.getRealValue());
            }
            if (!hideResults) {
                itemType.setResult(item.getResult().createOperationResultType());
            }
            rv.getItem().add(itemType);
        }
    }
    return rv;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Aggregations

PipelineItemType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ExecuteScriptResponseType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptResponseType)2 PipelineDataType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType)2 Response (javax.ws.rs.core.Response)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 Test (org.testng.annotations.Test)2 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 Referencable (com.evolveum.midpoint.prism.Referencable)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)1 ArrayList (java.util.ArrayList)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1