Search in sources :

Example 21 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class Main method modifyRoleAssignment.

private static void modifyRoleAssignment(ModelPortType modelPort, String userOid, boolean isAdd, String... roleOids) throws FaultMessage {
    ItemDeltaType assignmentDelta = new ItemDeltaType();
    if (isAdd) {
        assignmentDelta.setModificationType(ModificationTypeType.ADD);
    } else {
        assignmentDelta.setModificationType(ModificationTypeType.DELETE);
    }
    assignmentDelta.setPath(ModelClientUtil.createItemPathType("assignment"));
    for (String roleOid : roleOids) {
        assignmentDelta.getValue().add(ModelClientUtil.createRoleAssignment(roleOid));
    }
    ObjectDeltaType deltaType = new ObjectDeltaType();
    deltaType.setObjectType(ModelClientUtil.getTypeQName(UserType.class));
    deltaType.setChangeType(ChangeTypeType.MODIFY);
    deltaType.setOid(userOid);
    deltaType.getItemDelta().add(assignmentDelta);
    ObjectDeltaOperationListType objectDeltaOperationList = modelPort.executeChanges(ModelClientUtil.createDeltaList(deltaType), null);
    for (ObjectDeltaOperationType objectDeltaOperation : objectDeltaOperationList.getDeltaOperation()) {
        if (!OperationResultStatusType.SUCCESS.equals(objectDeltaOperation.getExecutionResult().getStatus())) {
            System.out.println("*** Operation result = " + objectDeltaOperation.getExecutionResult().getStatus() + ": " + objectDeltaOperation.getExecutionResult().getMessage());
        }
    }
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 22 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class TestSanity method addObjectViaModelWS.

private void addObjectViaModelWS(ObjectType objectType, ModelExecuteOptionsType options, Holder<String> oidHolder, Holder<OperationResultType> resultHolder) throws FaultMessage {
    ObjectDeltaListType deltaList = new ObjectDeltaListType();
    ObjectDeltaType objectDelta = new ObjectDeltaType();
    objectDelta.setObjectToAdd(objectType);
    QName type = objectType.asPrismObject().getDefinition().getTypeName();
    objectDelta.setObjectType(type);
    objectDelta.setChangeType(ChangeTypeType.ADD);
    deltaList.getDelta().add(objectDelta);
    ObjectDeltaOperationListType objectDeltaOperationListType = modelWeb.executeChanges(deltaList, options);
    ObjectDeltaOperationType objectDeltaOperationType = getOdoFromDeltaOperationList(objectDeltaOperationListType, objectDelta);
    resultHolder.value = objectDeltaOperationType.getExecutionResult();
    oidHolder.value = ((ObjectType) objectDeltaOperationType.getObjectDelta().getObjectToAdd()).getOid();
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) QName(javax.xml.namespace.QName) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)

Example 23 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class TestExchangeConnectorLow method test220ModifyingNonexistingAccount.

@Test
public void test220ModifyingNonexistingAccount() throws Exception {
    // create shadow with non-existing GUID
    System.out.println("Creating shadow with non-existing GUID...");
    Document doc = ModelClientUtil.getDocumnent();
    String name = "Wrong GUID shadow";
    ShadowType shadow = new ShadowType();
    shadow.setName(ModelClientUtil.createPolyStringType(name, doc));
    shadow.setResourceRef(createObjectReferenceType(ResourceType.class, getResourceOid()));
    shadow.setObjectClass(OC_ACCOUNT);
    shadow.setKind(ShadowKindType.ACCOUNT);
    ShadowAttributesType attributes = new ShadowAttributesType();
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_ICFS, "name"), name, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_ICFS, "uid"), "CN=wrong-GUID," + getContainer(), doc));
    shadow.setAttributes(attributes);
    String oid = createObject(ShadowType.class, shadow, createRaw());
    System.out.println("Done, reading it back...");
    ShadowType shadowReadAgain = getObjectNoFetch(ShadowType.class, oid);
    dumpAttributes(shadowReadAgain);
    System.out.println("Now launching modifyObject operation...");
    ObjectDeltaOperationType odo = modifyObject(ShadowType.class, oid, "attributes/sn", ModificationTypeType.REPLACE, "xxxxxx", null, false);
    OperationResultType r = odo.getExecutionResult();
    System.out.println("Done: " + r.getStatus() + ":" + r.getMessage());
    OperationResultType found = findOperationResult(r, new OperationResultMatcher() {

        @Override
        public boolean match(OperationResultType r) {
            return r.getDetails() != null && r.getDetails().contains("UnknownUidException");
        }
    });
    AssertJUnit.assertNotNull("UnknownUidException was not detected", found);
    System.out.println("======================================================================================================");
    System.out.println("Details: " + found.getDetails());
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test)

Example 24 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class TestExchangeConnectorLow method test140AssignConflictingAddress.

@Test
public void test140AssignConflictingAddress() throws Exception {
    String mail = "pascal@clermont-ferrand.fr";
    System.out.println("Disabling email address policy for Leibniz...");
    modifyShadow(leibnizOid, "attributes/EmailAddressPolicyEnabled", ModificationTypeType.REPLACE, false);
    System.out.println("Done");
    System.out.println("Adding conflicting email addresses to Leibniz...");
    ObjectDeltaOperationType result = modifyObject(ShadowType.class, leibnizOid, "attributes/EmailAddresses", ModificationTypeType.ADD, "smtp:" + mail, null, false);
    System.out.println("Done; result = " + result.getExecutionResult().getStatus() + " / " + result.getExecutionResult().getMessage());
    AssertJUnit.assertEquals("Unexpected operation status when adding conflicting address", OperationResultStatusType.FATAL_ERROR, result.getExecutionResult().getStatus());
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) Test(org.testng.annotations.Test)

Example 25 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType 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;
        }
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) ModelExecuteOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType) ExecuteChangesType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesType) IOException(java.io.IOException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)

Aggregations

ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)28 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)23 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)12 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)12 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)11 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)6 QName (javax.xml.namespace.QName)5 Test (org.testng.annotations.Test)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)3 ModelExecuteOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 MAuditDelta (com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta)2 DeltaConversionOptions (com.evolveum.midpoint.schema.DeltaConversionOptions)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2