Search in sources :

Example 1 with RelationDefinitionType

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

the class AssignExecutor method parseParameters.

@Override
AssignParameters parseParameters(ActionExpressionType action, PipelineData input, ExecutionContext context, OperationResult result) throws SchemaException, ScriptExecutionException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    AssignParameters parameters = new AssignParameters();
    // Dynamic parameters
    Collection<ObjectReferenceType> dynamicRoleRefs = getRolesParameter(action, input, context, result);
    Collection<ObjectReferenceType> dynamicResourceRefs = getResourcesParameter(action, input, context, result);
    Collection<QName> relationSpecifications = getRelationsParameter(action, input, context, result);
    QName relationSpecification = MiscUtil.extractSingleton(relationSpecifications, () -> new IllegalArgumentException("Using 'relation' as a multivalued parameter is not allowed"));
    if (PrismConstants.Q_ANY.matches(relationSpecification)) {
        throw new IllegalArgumentException("Using 'q:any' as relation specification is not allowed");
    }
    QName relationOverride;
    if (relationSpecification != null) {
        List<RelationDefinitionType> relationDefinitions = relationRegistry.getRelationDefinitions();
        relationOverride = relationDefinitions.stream().filter(definition -> prismContext.relationMatches(relationSpecification, definition.getRef())).findFirst().orElseThrow(() -> new IllegalArgumentException("Relation matching '" + relationSpecification + "' not found")).getRef();
    } else {
        relationOverride = null;
    }
    // Static parameters
    Collection<ObjectReferenceType> staticTargetRefs;
    Collection<ObjectReferenceType> staticResourceRefs;
    Collection<ConstructionType> staticConstructions;
    if (action instanceof AssignActionExpressionType) {
        staticTargetRefs = ((AssignActionExpressionType) action).getTargetRef();
        staticResourceRefs = ((AssignActionExpressionType) action).getResourceRef();
        staticConstructions = ((AssignActionExpressionType) action).getConstruction();
    } else {
        staticTargetRefs = emptyList();
        staticResourceRefs = emptyList();
        staticConstructions = emptyList();
    }
    // Consolidation
    Task task = context.getTask();
    parameters.targetRefs.addAll(resolve(staticTargetRefs, relationOverride, task, result));
    parameters.targetRefs.addAll(resolve(dynamicRoleRefs, relationOverride, task, result));
    QName defaultRelation = relationRegistry.getDefaultRelation();
    parameters.constructions.addAll(staticConstructions);
    parameters.constructions.addAll(resourceRefsToConstructions(resolve(staticResourceRefs, defaultRelation, task, result)));
    parameters.constructions.addAll(resourceRefsToConstructions(resolve(dynamicResourceRefs, defaultRelation, task, result)));
    return parameters;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) AssignActionExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.AssignActionExpressionType)

Example 2 with RelationDefinitionType

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

the class TestRelationRegistry method test120ReplacedAllRelations.

@Test
public void test120ReplacedAllRelations() throws SchemaException, IOException {
    PrismObject<SystemConfigurationType> sysconfigObject = prismContext.parseObject(SYSCONFIG_REPLACED_ALL_RELATIONS_FILE);
    relationRegistry.applyRelationsConfiguration(sysconfigObject.asObjectable());
    assertEquals("Wrong # of relations", 4, relationRegistry.getRelationDefinitions().size());
    RelationDefinitionType orgDefaultDef = relationRegistry.getRelationDefinition(SchemaConstants.ORG_DEFAULT);
    RelationDefinitionType defaultDef = relationRegistry.getRelationDefinition(unqualify(SchemaConstants.ORG_DEFAULT));
    assertNull("Definition for 'org:default' relation exists", orgDefaultDef);
    assertNull("Definition for 'default' relation exists", defaultDef);
    RelationDefinitionType testKinderManagerDef = relationRegistry.getRelationDefinition(TEST_KINDER_MANAGER);
    RelationDefinitionType kinderManagerDef = relationRegistry.getRelationDefinition(unqualify(TEST_KINDER_MANAGER));
    RelationDefinitionType testExtraDef = relationRegistry.getRelationDefinition(TEST_EXTRA);
    RelationDefinitionType extraDef = relationRegistry.getRelationDefinition(unqualify(TEST_EXTRA));
    RelationDefinitionType nullDef = relationRegistry.getRelationDefinition(null);
    RelationDefinitionType testApproverDef = relationRegistry.getRelationDefinition(TEST_APPROVER);
    RelationDefinitionType approverDef = relationRegistry.getRelationDefinition(unqualify(TEST_APPROVER));
    assertNotNull("No definition for 'test:kinderManager' relation", testKinderManagerDef);
    assertEquals("'test:kinderManager' and 'kinderManager' definitions differ", testKinderManagerDef, kinderManagerDef);
    assertNotNull("No definition for 'test:extra' relation", testExtraDef);
    assertEquals("'test:extra' and 'extra' definitions differ", testExtraDef, extraDef);
    assertEquals("'test:extra' and null definitions differ", testExtraDef, nullDef);
    assertNotNull("No definition for 'test:approverDef' relation", testApproverDef);
    assertEquals("'test:approver' and 'approver' definitions differ", testApproverDef, approverDef);
    assertTrue("'test:kinderManager' is not of MANAGER kind", relationRegistry.isManager(TEST_KINDER_MANAGER));
    assertTrue("'kinderManager' is not of MANAGER kind", relationRegistry.isManager(unqualify(TEST_KINDER_MANAGER)));
    assertFalse("'null' is of MANAGER kind", relationRegistry.isManager(null));
    assertFalse("'test:extra' is of MANAGER kind", relationRegistry.isManager(TEST_EXTRA));
    assertFalse("'test:approver' is of MANAGER kind", relationRegistry.isManager(TEST_APPROVER));
    assertFalse("'approver' is of MANAGER kind", relationRegistry.isManager(unqualify(TEST_APPROVER)));
    assertFalse("'test:kinderManager' is of MEMBER kind", relationRegistry.isMember(TEST_KINDER_MANAGER));
    assertFalse("'kinderManager' is of MEMBER kind", relationRegistry.isMember(unqualify(TEST_KINDER_MANAGER)));
    assertTrue("'test:extra' is not of MEMBER kind", relationRegistry.isMember(TEST_EXTRA));
    assertTrue("'null' is not of MEMBER kind", relationRegistry.isMember(null));
    assertFalse("'test:approver' is of MEMBER kind", relationRegistry.isMember(TEST_APPROVER));
    assertFalse("'approver' is of MEMBER kind", relationRegistry.isMember(unqualify(TEST_APPROVER)));
    assertTrue("'test:approver' is not of APPROVER kind", relationRegistry.isApprover(TEST_APPROVER));
    assertTrue("'approver' is not of APPROVER kind", relationRegistry.isApprover(unqualify(TEST_APPROVER)));
    assertEquals("Wrong default relation", TEST_EXTRA, relationRegistry.getDefaultRelation());
    assertEquals("Wrong default MEMBER relation", TEST_EXTRA, relationRegistry.getDefaultRelationFor(RelationKindType.MEMBER));
    assertEquals("Wrong default MANAGER relation", TEST_KINDER_MANAGER, relationRegistry.getDefaultRelationFor(RelationKindType.MANAGER));
    assertEquals("Wrong default META relation", SchemaConstants.ORG_META, relationRegistry.getDefaultRelationFor(RelationKindType.META));
    Set<QName> ALIASES_FOR_DEFAULT = new HashSet<>(Arrays.asList(TEST_EXTRA, unqualify(TEST_EXTRA), null));
    assertEquals("Wrong aliases for 'test:extra'", ALIASES_FOR_DEFAULT, new HashSet<>(relationRegistry.getAliases(TEST_EXTRA)));
    assertEquals("Wrong aliases for 'extra'", ALIASES_FOR_DEFAULT, new HashSet<>(relationRegistry.getAliases(unqualify(TEST_EXTRA))));
    assertEquals("Wrong aliases for 'null'", ALIASES_FOR_DEFAULT, new HashSet<>(relationRegistry.getAliases(null)));
    Set<QName> ALIASES_FOR_ORG_MANAGER = new HashSet<>(singleton(SchemaConstants.ORG_MANAGER));
    assertEquals("Wrong aliases for 'org:manager'", ALIASES_FOR_ORG_MANAGER, new HashSet<>(relationRegistry.getAliases(SchemaConstants.ORG_MANAGER)));
    Set<QName> ALIASES_FOR_KINDER_MANAGER = new HashSet<>(Arrays.asList(TEST_KINDER_MANAGER, unqualify(TEST_KINDER_MANAGER)));
    assertEquals("Wrong aliases for 'test:kinderManager'", ALIASES_FOR_KINDER_MANAGER, new HashSet<>(relationRegistry.getAliases(TEST_KINDER_MANAGER)));
    assertEquals("Wrong aliases for 'manager'", ALIASES_FOR_KINDER_MANAGER, new HashSet<>(relationRegistry.getAliases(unqualify(TEST_KINDER_MANAGER))));
    Set<QName> ALIASES_FOR_TEST_APPROVER = new HashSet<>(Arrays.asList(TEST_APPROVER, unqualify(TEST_APPROVER)));
    assertEquals("Wrong aliases for 'test:approver'", ALIASES_FOR_TEST_APPROVER, new HashSet<>(relationRegistry.getAliases(TEST_APPROVER)));
    assertEquals("Wrong aliases for 'approver'", ALIASES_FOR_TEST_APPROVER, new HashSet<>(relationRegistry.getAliases(unqualify(TEST_APPROVER))));
    Set<QName> RELATIONS_FOR_MEMBER = new HashSet<>(singleton(TEST_EXTRA));
    assertEquals("Wrong relations for MEMBER kind", RELATIONS_FOR_MEMBER, new HashSet<>(relationRegistry.getAllRelationsFor(RelationKindType.MEMBER)));
    Set<QName> RELATIONS_FOR_MANAGER = new HashSet<>(singleton(TEST_KINDER_MANAGER));
    assertEquals("Wrong relations for MANAGER kind", RELATIONS_FOR_MANAGER, new HashSet<>(relationRegistry.getAllRelationsFor(RelationKindType.MANAGER)));
    assertFalse("'org:default' is processed on login", relationRegistry.isProcessedOnLogin(SchemaConstants.ORG_DEFAULT));
    assertFalse("'default' is processed on login", relationRegistry.isProcessedOnLogin(unqualify(SchemaConstants.ORG_DEFAULT)));
    assertTrue("'null' is not processed on login", relationRegistry.isProcessedOnLogin(null));
    assertFalse("'org:manager' is processed on login", relationRegistry.isProcessedOnLogin(SchemaConstants.ORG_MANAGER));
    assertTrue("'org:meta' is not processed on login", relationRegistry.isProcessedOnLogin(SchemaConstants.ORG_META));
    assertFalse("'test:approver' is processed on login", relationRegistry.isProcessedOnLogin(TEST_APPROVER));
    assertTrue("'null' is not processed on recompute", relationRegistry.isProcessedOnRecompute(null));
    assertTrue("'org:meta' is not processed on recompute", relationRegistry.isProcessedOnRecompute(SchemaConstants.ORG_META));
    assertFalse("'test:approver' is processed on recompute", relationRegistry.isProcessedOnRecompute(TEST_APPROVER));
    assertFalse("'org:default' is stored into parentOrgRef", relationRegistry.isStoredIntoParentOrgRef(SchemaConstants.ORG_DEFAULT));
    assertTrue("'null' is not stored into parentOrgRef", relationRegistry.isStoredIntoParentOrgRef(null));
    assertTrue("'null' is not automatically matched", relationRegistry.isAutomaticallyMatched(null));
    // overridden
    assertTrue("'org:meta' is not automatically matched", relationRegistry.isAutomaticallyMatched(SchemaConstants.ORG_META));
    assertTrue("'test:kinderManager' is not automatically matched", relationRegistry.isAutomaticallyMatched(TEST_KINDER_MANAGER));
    assertTrue("'kinderManager' is not automatically matched", relationRegistry.isAutomaticallyMatched(unqualify(TEST_KINDER_MANAGER)));
    assertFalse("'org:approver' is automatically matched", relationRegistry.isAutomaticallyMatched(SchemaConstants.ORG_APPROVER));
}
Also used : RelationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType) QName(javax.xml.namespace.QName) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 3 with RelationDefinitionType

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

the class IndexedRelationDefinitions method computeDefaultRelationByKind.

private Map<RelationKindType, QName> computeDefaultRelationByKind() {
    Map<RelationKindType, QName> rv = new HashMap<>();
    for (RelationKindType kind : RelationKindType.values()) {
        Set<QName> relationNames = relationsByKind.get(kind);
        if (relationNames.isEmpty()) {
            LOGGER.warn("No relations defined for kind {}, please define at least one", kind);
            continue;
        }
        Set<QName> defaultRelationNames = new HashSet<>();
        Set<QName> userDefinedDefaultRelationNames = new HashSet<>();
        for (QName relationName : relationNames) {
            RelationDefinitionType definition = relationDefinitionsByRelationName.get(relationName);
            assert definition != null;
            if (definition.getDefaultFor() == kind) {
                defaultRelationNames.add(relationName);
                if (BooleanUtils.isNotTrue(definition.isStaticallyDefined())) {
                    userDefinedDefaultRelationNames.add(relationName);
                }
            }
        }
        QName chosen;
        if (defaultRelationNames.size() > 1) {
            if (userDefinedDefaultRelationNames.size() == 1) {
                // i.e. we ignore statically defined relations here
                chosen = userDefinedDefaultRelationNames.iterator().next();
            } else if (userDefinedDefaultRelationNames.size() > 1) {
                // i.e. we choose only from user-defined relations
                chosen = userDefinedDefaultRelationNames.iterator().next();
                LOGGER.error("More than one default relation set up for kind '{}': {}. Please choose one! Temporarily selecting '{}'", kind, defaultRelationNames, chosen);
            } else {
                throw new AssertionError("Multiple default relations set up for kind '" + kind + "' among statically defined relations: " + defaultRelationNames);
            }
        } else if (defaultRelationNames.size() == 1) {
            chosen = defaultRelationNames.iterator().next();
        } else {
            // maybe we could select org:xxx here but let's not bother now
            chosen = relationNames.iterator().next();
            LOGGER.warn("No default relation set up for kind '{}'. Please choose one! Temporarily selecting '{}'", kind, chosen);
        }
        rv.put(kind, chosen);
    }
    return rv;
}
Also used : RelationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType) HashSetValuedHashMap(org.apache.commons.collections4.multimap.HashSetValuedHashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) QName(javax.xml.namespace.QName) RelationKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationKindType)

Example 4 with RelationDefinitionType

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

the class IndexedRelationDefinitions method initializeRelationDefinitionsByRelationName.

/**
 * Removes duplicate definitions as well.
 */
@NotNull
private Map<QName, RelationDefinitionType> initializeRelationDefinitionsByRelationName(List<RelationDefinitionType> definitions) {
    Map<QName, RelationDefinitionType> map = new HashMap<>();
    ListValuedMap<String, QName> expansions = new ArrayListValuedHashMap<>();
    for (Iterator<RelationDefinitionType> iterator = definitions.iterator(); iterator.hasNext(); ) {
        RelationDefinitionType definition = iterator.next();
        if (map.containsKey(definition.getRef())) {
            LOGGER.error("Duplicate relation definition for '{}'; ignoring: {}", definition.getRef(), definition);
            iterator.remove();
        } else {
            map.put(definition.getRef(), definition);
            expansions.put(definition.getRef().getLocalPart(), definition.getRef());
        }
    }
    // add entries for unqualified versions of the relation names
    for (String unqualified : expansions.keySet()) {
        List<QName> names = expansions.get(unqualified);
        if (names.contains(new QName(unqualified))) {
            // cannot expand unqualified if the expanded value is also unqualified
            continue;
        }
        assert !names.isEmpty();
        assert names.stream().allMatch(QNameUtil::isQualified);
        @NotNull QName chosenExpansion;
        if (names.size() == 1) {
            chosenExpansion = names.get(0);
        } else {
            QName nameInOrgNamespace = names.stream().filter(n -> SchemaConstants.NS_ORG.equals(n.getNamespaceURI())).findFirst().orElse(null);
            if (nameInOrgNamespace != null) {
                // org:xxx expansion will be the default one
                chosenExpansion = nameInOrgNamespace;
            } else {
                chosenExpansion = names.get(0);
                LOGGER.warn("Multiple resolutions of unqualified relation name '{}' ({}); " + "using the first one as default: '{}'. Please reconsider this as it could lead to " + "unpredictable behavior.", unqualified, names, chosenExpansion);
            }
        }
        assert QNameUtil.isQualified(chosenExpansion);
        map.put(new QName(unqualified), map.get(chosenExpansion));
    }
    return map;
}
Also used : RelationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType) HashSetValuedHashMap(org.apache.commons.collections4.multimap.HashSetValuedHashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) QName(javax.xml.namespace.QName) QNameUtil(com.evolveum.midpoint.util.QNameUtil) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with RelationDefinitionType

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

the class IndexedRelationDefinitions method validateDefinitions.

private List<RelationDefinitionType> validateDefinitions(@NotNull List<RelationDefinitionType> definitions) {
    List<RelationDefinitionType> validatedDefinitions = new ArrayList<>(definitions.size());
    boolean memberRelationExists = false;
    for (RelationDefinitionType definition : definitions) {
        if (definition.getRef() == null) {
            LOGGER.error("Relation definition with null ref; ignoring: {}", definition);
        } else {
            if (QNameUtil.isUnqualified(definition.getRef())) {
                LOGGER.warn("Unqualified relation name '{}'; please fix it as soon as possible; in {}", definition.getRef(), definition);
            }
            validatedDefinitions.add(definition);
            if (!memberRelationExists && definition.getKind().contains(RelationKindType.MEMBER)) {
                memberRelationExists = true;
            }
        }
    }
    if (!memberRelationExists) {
        LOGGER.error("No 'member' relation was defined. This would be a fatal condition, so we define one.");
        validatedDefinitions.add(RelationRegistryImpl.createRelationDefinitionFromStaticDefinition(RelationTypes.MEMBER));
    }
    return validatedDefinitions;
}
Also used : RelationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType)

Aggregations

RelationDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType)7 QName (javax.xml.namespace.QName)7 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)3 Test (org.testng.annotations.Test)3 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)2 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)2 HashSetValuedHashMap (org.apache.commons.collections4.multimap.HashSetValuedHashMap)2 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)1 QNameIChoiceRenderer (com.evolveum.midpoint.gui.impl.component.input.QNameIChoiceRenderer)1 Task (com.evolveum.midpoint.task.api.Task)1 QNameUtil (com.evolveum.midpoint.util.QNameUtil)1 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)1 SearchSpecialItemPanel (com.evolveum.midpoint.web.component.search.SearchSpecialItemPanel)1 EnableBehaviour (com.evolveum.midpoint.web.component.util.EnableBehaviour)1 DisplayType (com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType)1 RelationKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.RelationKindType)1 RelationSearchItemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.RelationSearchItemConfigurationType)1 AssignActionExpressionType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.AssignActionExpressionType)1 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)1 ArrayList (java.util.ArrayList)1