use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.
the class ModifyTest method test031ModifyUserOnExistingAccountTest.
// MID-3483
@Test(enabled = false)
public void test031ModifyUserOnExistingAccountTest() throws Exception {
final String TEST_NAME = "test031ModifyUserOnExistingAccountTest";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TEST_NAME);
//add account
PrismObject<ShadowType> account = prismContext.parseObject(ACCOUNT_FILE);
repositoryService.addObject(account, null, result);
//add user
File userFile = new File(TEST_DIR, "modify-user.xml");
PrismObject<UserType> user = prismContext.parseObject(userFile);
String userOid = user.getOid();
String oid = repositoryService.addObject(user, null, result);
assertEquals(userOid, oid);
PrismObject<UserType> userOld = repositoryService.getObject(UserType.class, oid, null, result);
ObjectDeltaType objectDeltaType = PrismTestUtil.parseAnyValue(MODIFY_USER_ADD_LINK);
ObjectDelta<Objectable> objectDelta = DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
Collection<? extends ItemDelta<?, ?>> deltas = objectDelta.getModifications();
// WHEN
repositoryService.modifyObject(UserType.class, oid, deltas, getModifyOptions(), result);
PropertyDelta.applyTo(deltas, userOld);
PrismObject<UserType> userNew = repositoryService.getObject(UserType.class, oid, null, result);
ObjectDelta<UserType> delta = userOld.diff(userNew);
LOGGER.debug("Modify diff \n{}", delta.debugDump(3));
AssertJUnit.assertTrue("Modify was unsuccessful, diff size: " + delta.getModifications().size(), delta.isEmpty());
AssertJUnit.assertTrue("User is not equivalent.", userOld.equivalent(userNew));
}
use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method deleteUser.
protected void deleteUser(String oid) throws FaultMessage {
ObjectDeltaType deltaType = new ObjectDeltaType();
deltaType.setObjectType(ModelClientUtil.getTypeQName(UserType.class));
deltaType.setChangeType(ChangeTypeType.DELETE);
deltaType.setOid(oid);
ObjectDeltaListType deltaListType = new ObjectDeltaListType();
deltaListType.getDelta().add(deltaType);
ModelExecuteOptionsType executeOptionsType = new ModelExecuteOptionsType();
executeOptionsType.setRaw(true);
modelPort.executeChanges(deltaListType, executeOptionsType);
}
use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method deleteObject.
protected void deleteObject(Class objectClass, String oid, boolean ignoreFailures, ModelExecuteOptionsType executeOptionsType) throws FaultMessage {
System.out.println("Deleting " + objectClass.getSimpleName() + " " + oid);
ObjectDeltaType deltaType = new ObjectDeltaType();
deltaType.setObjectType(ModelClientUtil.getTypeQName(objectClass));
deltaType.setChangeType(ChangeTypeType.DELETE);
deltaType.setOid(oid);
ObjectDeltaListType deltaListType = new ObjectDeltaListType();
deltaListType.getDelta().add(deltaType);
if (!ignoreFailures) {
modelPort.executeChanges(deltaListType, executeOptionsType);
} else {
try {
modelPort.executeChanges(deltaListType, executeOptionsType);
} catch (Exception e) {
System.err.println("Cannot remove " + oid + ": " + e.getMessage());
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType 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;
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method createUser.
protected String createUser(UserType userType) throws FaultMessage {
ObjectDeltaType deltaType = new ObjectDeltaType();
deltaType.setObjectType(ModelClientUtil.getTypeQName(UserType.class));
deltaType.setChangeType(ChangeTypeType.ADD);
deltaType.setObjectToAdd(userType);
ObjectDeltaListType deltaListType = new ObjectDeltaListType();
deltaListType.getDelta().add(deltaType);
ObjectDeltaOperationListType operationListType = modelPort.executeChanges(deltaListType, null);
String oid = ModelClientUtil.getOidFromDeltaOperationList(operationListType, deltaType);
return oid;
}
Aggregations