Search in sources :

Example 81 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class ObjectRetriever method applyShadowAttributeDefinitions.

private void applyShadowAttributeDefinitions(Class<? extends RAnyValue> anyValueType, PrismObject<?> object, Session session) throws SchemaException {
    PrismContainer<?> attributes = object.findContainer(ShadowType.F_ATTRIBUTES);
    Query query = session.getNamedQuery("getDefinition." + anyValueType.getSimpleName());
    query.setParameter("oid", object.getOid());
    query.setParameter("ownerType", RObjectExtensionType.ATTRIBUTES);
    @SuppressWarnings({ "unchecked", "raw" }) List<Integer> identifiers = query.list();
    if (identifiers == null || identifiers.isEmpty()) {
        return;
    }
    for (Integer extItemId : identifiers) {
        if (extItemId == null) {
            // could break raw reading.
            continue;
        }
        RExtItem extItem = extItemDictionary.getItemById(extItemId);
        if (extItem == null) {
            continue;
        }
        ItemName name = RUtil.stringToQName(extItem.getName());
        Item item = attributes.findItem(name);
        if (item != null && item.getDefinition() == null) {
            MutableItemDefinition<?> def = createDynamicDefinition(extItem, name);
            // noinspection unchecked
            item.applyDefinition(def, true);
        }
    }
}
Also used : Query(org.hibernate.query.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) NativeQuery(org.hibernate.query.NativeQuery) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 82 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class TestLdapAssociationPerformance method test100AddUsers.

@Test
public void test100AddUsers() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    // WHEN
    when();
    resetPerformanceCollectors();
    long startMillis = System.currentTimeMillis();
    IntegrationTestTools.setSilentConsole(true);
    generateObjects(UserType.class, NUMBER_OF_GENERATED_USERS, GENERATED_USER_NAME_FORMAT, null, (user, i) -> {
        user.fullName(String.format(GENERATED_USER_FULL_NAME_FORMAT, i)).givenName(String.format(GENERATED_USER_GIVEN_NAME_FORMAT, i)).familyName(String.format(GENERATED_USER_FAMILY_NAME_FORMAT, i));
        PrismProperty<Object> memberOf;
        try {
            memberOf = user.asPrismObject().createExtension().getValue().findOrCreateProperty(new ItemName("memberOf"));
            for (int roleIndex = 0; roleIndex < NUMBER_OF_GENERATED_ROLES; roleIndex++) {
                memberOf.addRealValue(String.format(GENERATED_ROLE_NAME_FORMAT, roleIndex));
            }
        } catch (SchemaException e) {
            throw new AssertionError(e.getMessage(), e);
        }
    }, user -> addObject(user, task, result), result);
    IntegrationTestTools.setSilentConsole(false);
    // THEN
    then();
    long endMillis = System.currentTimeMillis();
    recordDuration((endMillis - startMillis));
    PerformanceInformation performanceInformation = getRepoPerformanceMonitor().getThreadLocalPerformanceInformation();
    dumpRepoSnapshotPerUser(performanceInformation);
    dumpGlobalCachePerformanceData();
    result.computeStatus();
    assertSuccess(result);
    // dumpLdap();
    assertLdapConnectorInstances(1);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) OperationPerformanceInformation(com.evolveum.midpoint.repo.api.perf.OperationPerformanceInformation) PerformanceInformation(com.evolveum.midpoint.repo.api.perf.PerformanceInformation) ItemName(com.evolveum.midpoint.prism.path.ItemName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) Test(org.testng.annotations.Test)

Example 83 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class TestResourceSchema method assertSimpleSchema.

private void assertSimpleSchema(ResourceSchema schema, String filename) {
    assertNotNull(schema);
    System.out.println("Parsed schema from " + filename + ":");
    System.out.println(schema.debugDump());
    ResourceObjectClassDefinition accDef = schema.findObjectClassDefinition(new ItemName(MidPointConstants.NS_RI, "AccountObjectClass"));
    assertEquals("Wrong account objectclass", new ItemName(MidPointConstants.NS_RI, "AccountObjectClass"), accDef.getTypeName());
    assertTrue("Not a default account", accDef.isDefaultAccountDefinition());
    PrismPropertyDefinition<String> loginAttrDef = accDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "login"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "login"), loginAttrDef.getItemName());
    assertEquals(DOMUtil.XSD_STRING, loginAttrDef.getTypeName());
    assertFalse("Ignored while it should not be", loginAttrDef.isIgnored());
    PrismPropertyDefinition<Integer> groupAttrDef = accDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "group"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "group"), groupAttrDef.getItemName());
    assertEquals(DOMUtil.XSD_INT, groupAttrDef.getTypeName());
    assertFalse("Ignored while it should not be", groupAttrDef.isIgnored());
    PrismPropertyDefinition<String> ufoAttrDef = accDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "ufo"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "ufo"), ufoAttrDef.getItemName());
    assertTrue("Not ignored as it should be", ufoAttrDef.isIgnored());
    ResourceObjectClassDefinition groupDef = schema.findObjectClassDefinition(new ItemName(MidPointConstants.NS_RI, "GroupObjectClass"));
    assertEquals("Wrong group objectclass", new ItemName(MidPointConstants.NS_RI, "GroupObjectClass"), groupDef.getTypeName());
    assertFalse("Default group but it should not be", groupDef.isDefaultAccountDefinition());
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 84 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName 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.
 *
 * We also check the metadata.channel migration for both the object and the assignment (MID-6547).
 */
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
    PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
    ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(dummyResource);
    // This explicitly parses the schema, therefore ...
    assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 1);
    ResourceObjectTypeDefinition accountDefinition = refinedSchema.findObjectTypeDefinitionRequired(ShadowKindType.ACCOUNT, null);
    PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new ItemName("http://midpoint.evolveum.com/xml/ns/public/resource/instance-3", 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(gossipDefinition.getItemName()));
    MappingType outbound = new MappingType();
    radt.setOutbound(outbound);
    ExpressionType expression = new ExpressionType();
    outbound.setExpression(expression);
    MappingType value = new MappingType();
    // noinspection unchecked
    PrismProperty<String> property = gossipDefinition.instantiate();
    property.addRealValue("q");
    List evaluators = expression.getExpressionEvaluator();
    Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property);
    ObjectFactory of = new ObjectFactory();
    for (JAXBElement<RawType> obj : collection) {
        // noinspection unchecked
        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);
    // Set user and assignment create channel to legacy value.
    repositoryService.modifyObject(UserType.class, jackBefore.getOid(), deltaFor(UserType.class).item(UserType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace(Channel.USER.getLegacyUri()).item(UserType.F_ASSIGNMENT, assignmentId, AssignmentType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace(Channel.USER.getLegacyUri()).asItemDeltas(), result);
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
    display("User before change execution", userJackOld);
    display("Deltas to execute execution", deltas);
    when();
    modelService.executeChanges(deltas, null, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    // First fetch: initial account read
    // Second fetch: fetchback after modification to correctly process inbound
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 2);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack, "Jack Sparrow");
    accountJackOid = getSingleLinkOid(userJack);
    // MID-6547 (channel URI migration)
    assertThat(userJack.asObjectable().getMetadata().getCreateChannel()).isEqualTo(Channel.USER.getUri());
    assertThat(userJack.asObjectable().getAssignment().get(0).getMetadata().getCreateChannel()).isEqualTo(Channel.USER.getUri());
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, SelectorOptions.createCollection(GetOperationOptions.createRaw()), 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");
    assertDummyScriptsModify(userJack, true);
    // Check audit
    displayDumpable("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();
    assertCounterIncrement(InternalCounters.SCRIPT_COMPILE_COUNT, 0);
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) List(java.util.List) ArrayList(java.util.ArrayList) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) JAXBElement(javax.xml.bind.JAXBElement) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) Test(org.testng.annotations.Test)

Example 85 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class TestResources method assertConfigurationPropertyDefinition.

private void assertConfigurationPropertyDefinition(PrismContainerDefinition<Containerable> containerDefinition, String propertyLocalName, QName expectedType, int expectedMinOccurs, int expectedMaxOccurs, String expectedDisplayName, String expectedHelp) {
    ItemName propName = new ItemName(containerDefinition.getTypeName().getNamespaceURI(), propertyLocalName);
    PrismPropertyDefinition<?> propDef = containerDefinition.findPropertyDefinition(propName);
    assertConfigurationPropertyDefinition(propDef, expectedType, expectedMinOccurs, expectedMaxOccurs, expectedDisplayName, expectedHelp);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Aggregations

ItemName (com.evolveum.midpoint.prism.path.ItemName)89 Test (org.testng.annotations.Test)24 QName (javax.xml.namespace.QName)19 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 NotNull (org.jetbrains.annotations.NotNull)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 Task (com.evolveum.midpoint.task.api.Task)6 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)5 MUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser)5 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)5 Element (org.w3c.dom.Element)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)4 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)4 ArrayList (java.util.ArrayList)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3