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;
}
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;
}
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());
}
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);
}
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;
}
Aggregations