use of com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesType 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);
}
use of com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesType in project midpoint by Evolveum.
the class Upload method uploadFile.
private static void uploadFile(File file, CommandLine cmdline, ModelPortType modelPort) {
System.out.println("Uploading file " + file);
Object content;
try {
content = unmarshalFile(file);
} catch (JAXBException | FileNotFoundException e) {
System.err.println("Cannot read " + file + ": " + e.getMessage());
e.printStackTrace();
error = true;
return;
}
if (content == null) {
System.err.println("Nothing to be uploaded.");
error = true;
return;
}
if (!(content instanceof ObjectType)) {
System.err.println("Expected an ObjectType to be uploaded; found " + content.getClass());
error = true;
return;
}
ObjectType objectType = (ObjectType) content;
ObjectDeltaType objectDeltaType = new ObjectDeltaType();
objectDeltaType.setChangeType(ChangeTypeType.ADD);
objectDeltaType.setObjectType(ModelClientUtil.getTypeQName(objectType.getClass()));
objectDeltaType.setObjectToAdd(objectType);
ObjectDeltaListType objectDeltaListType = new ObjectDeltaListType();
objectDeltaListType.getDelta().add(objectDeltaType);
ModelExecuteOptionsType optionsType = new ModelExecuteOptionsType();
optionsType.setIsImport(true);
optionsType.setReevaluateSearchFilters(true);
optionsType.setRaw(true);
optionsType.setOverwrite(true);
ExecuteChangesType executeChangesType = new ExecuteChangesType();
executeChangesType.setDeltaList(objectDeltaListType);
executeChangesType.setOptions(optionsType);
ObjectDeltaOperationListType response;
try {
response = modelPort.executeChanges(objectDeltaListType, optionsType);
} catch (Exception e) {
System.err.println("Got exception when trying to execute the changes " + e.getMessage());
error = true;
return;
}
System.out.println("-----------------------------------------------------------------");
if (response == null) {
System.err.println("Unexpected empty response");
error = true;
return;
}
OperationResultType overallResult = new OperationResultType();
boolean allSuccess = true;
for (ObjectDeltaOperationType objectDeltaOperation : response.getDeltaOperation()) {
if (objectDeltaOperation.getObjectDelta() != null) {
ObjectDeltaType delta = objectDeltaOperation.getObjectDelta();
System.out.print(delta.getChangeType() + " delta with OID " + delta.getOid() + " ");
}
OperationResultType resultType = objectDeltaOperation.getExecutionResult();
System.out.println("resulted in " + getResultStatus(resultType));
if (resultType == null || resultType.getStatus() != OperationResultStatusType.SUCCESS) {
allSuccess = false;
error = true;
}
overallResult.getPartialResults().add(resultType);
}
if (!cmdline.hasOption(OPT_HIDE_RESULT) && (cmdline.hasOption(OPT_SHOW_RESULT) || !allSuccess)) {
System.out.println("\n\n" + marshalResult(overallResult));
}
if (cmdline.hasOption(OPT_FILE_FOR_RESULT)) {
String filename = cmdline.getOptionValue(OPT_FILE_FOR_RESULT);
try {
FileWriter fileWriter = new FileWriter(filename, true);
IOUtils.write(marshalResult(overallResult), fileWriter);
} catch (IOException e) {
System.err.println("Couldn't write operation result to file " + filename + ": " + e.getMessage());
e.printStackTrace();
error = true;
}
}
}
Aggregations