Search in sources :

Example 41 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestJaxbConstruction method createFilter.

private MapXNode createFilter() {
    MapXNode filter = new MapXNode();
    MapXNode equalsElement = new MapXNode();
    filter.put(new QName(SchemaConstantsGenerated.NS_QUERY, "equal"), equalsElement);
    PrimitiveXNode<ItemPathType> pathElement = new PrimitiveXNode<>(new ItemPathType(new ItemPath(new QName("name"))));
    equalsElement.put(new QName(SchemaConstantsGenerated.NS_QUERY, "path"), pathElement);
    PrimitiveXNode<String> valueElement = new PrimitiveXNode<>("čučoriedka");
    equalsElement.put(new QName(SchemaConstantsGenerated.NS_QUERY, "value"), valueElement);
    return filter;
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) QName(javax.xml.namespace.QName) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 42 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class SchemaDebugUtil method prettyPrint.

public static String prettyPrint(PropertyReferenceListType reflist) {
    if (reflist == null) {
        return "null";
    }
    StringBuilder sb = new StringBuilder("[");
    Iterator<ItemPathType> iterator = reflist.getProperty().iterator();
    while (iterator.hasNext()) {
        ItemPathType xpath = iterator.next();
        sb.append(xpath.toString());
        if (iterator.hasNext()) {
            sb.append(",");
        }
    }
    sb.append("]");
    return sb.toString();
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType)

Example 43 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class ModelWebServiceTest method nonExistingUidModify.

@Test(expectedExceptions = FaultMessage.class)
public void nonExistingUidModify() throws FaultMessage, ObjectNotFoundException, SchemaException, JAXBException, IOException {
    final String oid = "1";
    ObjectDeltaType objectDeltaType = new ObjectDeltaType();
    objectDeltaType.setChangeType(ChangeTypeType.MODIFY);
    objectDeltaType.setObjectType(UserType.COMPLEX_TYPE);
    objectDeltaType.setOid(oid);
    ItemDeltaType mod1 = new ItemDeltaType();
    mod1.setModificationType(ModificationTypeType.ADD);
    //        ItemDeltaType.Value value = new ItemDeltaType.Value();
    //        value.getAny().add(DOMUtil.createElement(DOMUtil.getDocument(), new QName(SchemaConstants.NS_C, "fullName")));
    mod1.setPath(new ItemPathType(new ItemPath(UserType.F_FULL_NAME)));
    objectDeltaType.getItemDelta().add(mod1);
    when(repositoryService.getObject(any(Class.class), eq(oid), any(Collection.class), any(OperationResult.class))).thenThrow(new ObjectNotFoundException("Oid '" + oid + "' not found."));
    final UserType user = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
    setSecurityContext(user);
    ObjectDeltaListType deltaListType = new ObjectDeltaListType();
    deltaListType.getDelta().add(objectDeltaType);
    try {
        modelService.executeChanges(deltaListType, null);
    } catch (FaultMessage ex) {
        ModelTUtil.assertObjectNotFoundFault(ex);
    } finally {
        SecurityContextHolder.getContext().setAuthentication(null);
    }
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 44 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestModelServiceContract method test191ModifyUserJackModifyAssignment.

/**
     * We try to modify an assignment of the account and see whether changes will be recorded in the account itself.
     *
     */
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
    final String TEST_NAME = "test191ModifyUserJackModifyAssignment";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    //PrismPropertyDefinition definition = getAssignmentDefinition().findPropertyDefinition(new QName(SchemaConstantsGenerated.NS_COMMON, "accountConstruction"));
    PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
    RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(dummyResource, prismContext);
    // This explicitly parses the schema, therefore ...
    assertResourceSchemaParseCountIncrement(1);
    RefinedObjectClassDefinition accountDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
    PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new QName("http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME));
    assertNotNull("gossip attribute definition not found", gossipDefinition);
    ConstructionType accountConstruction = createAccountConstruction(RESOURCE_DUMMY_OID, null);
    ResourceAttributeDefinitionType radt = new ResourceAttributeDefinitionType();
    radt.setRef(new ItemPathType(new ItemPath(gossipDefinition.getName())));
    MappingType outbound = new MappingType();
    radt.setOutbound(outbound);
    ExpressionType expression = new ExpressionType();
    outbound.setExpression(expression);
    MappingType value = new MappingType();
    PrismProperty<String> property = gossipDefinition.instantiate();
    property.add(new PrismPropertyValue<String>("q"));
    List evaluators = expression.getExpressionEvaluator();
    Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property, null);
    ObjectFactory of = new ObjectFactory();
    for (JAXBElement<RawType> obj : collection) {
        evaluators.add(of.createValue(obj.getValue()));
    }
    value.setExpression(expression);
    radt.setOutbound(value);
    accountConstruction.getAttribute().add(radt);
    PrismObject<UserType> jackBefore = getUserFromRepo(USER_JACK_OID);
    assertEquals("Wrong # of assignments", 1, jackBefore.asObjectable().getAssignment().size());
    Long assignmentId = jackBefore.asObjectable().getAssignment().get(0).getId();
    ObjectDelta<UserType> accountAssignmentUserDelta = createReplaceAccountConstructionUserDelta(USER_JACK_OID, assignmentId, accountConstruction);
    deltas.add(accountAssignmentUserDelta);
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
    display("User before change execution", userJackOld);
    display("Deltas to execute execution", deltas);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    // First fetch: initial account read
    // Second fetch: fetchback after modification to correctly process inbound
    assertShadowFetchOperationCountIncrement(2);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack, "Jack Sparrow");
    accountJackOid = getSingleLinkOid(userJack);
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
    assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
    // Check account in dummy resource
    assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
    DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
    display(dummyAccount.debugDump());
    assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "q");
    //assertEquals("Missing or incorrect attribute value", "soda", dummyAccount.getAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, String.class));
    assertDummyScriptsModify(userJack, true);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecutionDeltas = dummyAuditService.getExecutionDeltas();
    assertEquals("Wrong number of execution deltas", 2, auditExecutionDeltas.size());
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    assertScriptCompileIncrement(0);
    assertSteadyResources();
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) List(java.util.List) ArrayList(java.util.ArrayList) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) QName(javax.xml.namespace.QName) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) JAXBElement(javax.xml.bind.JAXBElement) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 45 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestModelWebServiceNegative method createShadowReplaceChange.

// TODO: more negative tests
private ObjectDeltaType createShadowReplaceChange(String oid, String path, final String value, QName type) {
    ObjectDeltaType objectChange = new ObjectDeltaType();
    objectChange.setOid(oid);
    objectChange.setChangeType(ChangeTypeType.MODIFY);
    objectChange.setObjectType(ObjectTypes.SHADOW.getTypeQName());
    ItemDeltaType itemDeltaType = new ItemDeltaType();
    itemDeltaType.setModificationType(ModificationTypeType.REPLACE);
    ItemPathType itemPath = new ItemPathType(path);
    itemDeltaType.setPath(itemPath);
    PrimitiveXNode<String> xnode = new PrimitiveXNode<>();
    ValueParser<String> valueParser = new ValueParser<String>() {

        @Override
        public String parse(QName typeName, XNodeProcessorEvaluationMode mode) throws SchemaException {
            return value;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }

        @Override
        public String getStringValue() {
            return value;
        }

        @Override
        public Map<String, String> getPotentiallyRelevantNamespaces() {
            throw new UnsupportedOperationException();
        }
    };
    xnode.setValueParser(valueParser);
    if (type != null) {
        xnode.setExplicitTypeDeclaration(true);
        xnode.setTypeQName(type);
    }
    RawType rawValue = new RawType(xnode, prismContext);
    itemDeltaType.getValue().add(rawValue);
    objectChange.getItemDelta().add(itemDeltaType);
    return objectChange;
}
Also used : XNodeProcessorEvaluationMode(com.evolveum.midpoint.prism.marshaller.XNodeProcessorEvaluationMode) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ValueParser(com.evolveum.midpoint.prism.xnode.ValueParser) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Aggregations

ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)36 QName (javax.xml.namespace.QName)20 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 ArrayList (java.util.ArrayList)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)10 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 Test (org.testng.annotations.Test)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)6 List (java.util.List)5 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)4 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)4 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)3