Search in sources :

Example 16 with ResourceType

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

the class SynchronizationUtils method isPolicyApplicable.

public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    List<QName> policyObjectClasses = synchronizationPolicy.getObjectClass();
    if (policyObjectClasses == null || policyObjectClasses.isEmpty()) {
        String policyIntent = synchronizationPolicy.getIntent();
        ShadowKindType policyKind = synchronizationPolicy.getKind();
        ObjectClassComplexTypeDefinition policyObjectClass = null;
        RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
        if (schema == null) {
            throw new SchemaException("No schema defined in resource. Possible configuration problem?");
        }
        if (policyKind == null && policyIntent == null) {
            policyObjectClass = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
        }
        if (policyKind != null) {
            if (StringUtils.isEmpty(policyIntent)) {
                policyObjectClass = schema.findDefaultObjectClassDefinition(policyKind);
            } else {
                policyObjectClass = schema.findObjectClassDefinition(policyKind, policyIntent);
            }
        }
        if (policyObjectClass != null && !policyObjectClass.getTypeName().equals(objectClass)) {
            return false;
        }
    }
    if (policyObjectClasses != null && !policyObjectClasses.isEmpty()) {
        if (!QNameUtil.contains(policyObjectClasses, objectClass)) {
            return false;
        }
    }
    // kind
    ShadowKindType policyKind = synchronizationPolicy.getKind();
    if (policyKind != null && kind != null && !policyKind.equals(kind)) {
        return false;
    }
    // intent
    // TODO is the intent always present in shadow at this time? [med]
    String policyIntent = synchronizationPolicy.getIntent();
    if (policyIntent != null && intent != null && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
        return false;
    }
    return true;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 17 with ResourceType

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

the class TestRefinedSchema method testParseFromResourceSimple.

@Test
public void testParseFromResourceSimple() throws JAXBException, SchemaException, SAXException, IOException {
    System.out.println("\n===[ testParseFromResourceSimple ]===\n");
    // GIVEN
    PrismContext prismContext = createInitializedPrismContext();
    PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_SIMPLE_FILE);
    ResourceType resourceType = resource.asObjectable();
    // WHEN
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);
    // THEN
    assertNotNull("Refined schema is null", rSchema);
    System.out.println("Refined schema");
    System.out.println(rSchema.debugDump());
    assertRefinedSchema(resourceType, rSchema, null, LayerType.SCHEMA, false);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Test(org.testng.annotations.Test)

Example 18 with ResourceType

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

the class ExpressionHandlerImplTest method testEvaluateExpression.

@SuppressWarnings("unchecked")
@Test
public void testEvaluateExpression() throws Exception {
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_FOLDER, "account.xml"));
    ShadowType accountType = account.asObjectable();
    PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(TEST_FOLDER_COMMON, "resource-dummy.xml"));
    ResourceType resourceType = resource.asObjectable();
    accountType.setResource(resourceType);
    ObjectSynchronizationType synchronization = resourceType.getSynchronization().getObjectSynchronization().get(0);
    for (ConditionalSearchFilterType filter : synchronization.getCorrelation()) {
        MapXNode clauseXNode = filter.getFilterClauseXNode();
        // key = q:equal, value = map (path + expression)
        RootXNode expressionNode = ((MapXNode) clauseXNode.getSingleSubEntry("filter value").getValue()).getEntryAsRoot(new QName(SchemaConstants.NS_C, "expression"));
        ExpressionType expression = PrismTestUtil.getPrismContext().parserFor(expressionNode).parseRealValue(ExpressionType.class);
        LOGGER.debug("Expression: {}", SchemaDebugUtil.prettyPrint(expression));
        OperationResult result = new OperationResult("testCorrelationRule");
        String name = expressionHandler.evaluateExpression(accountType, expression, "test expression", null, result);
        LOGGER.info(result.debugDump());
        assertEquals("Wrong expression result", "hbarbossa", name);
    }
}
Also used : ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) File(java.io.File) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) Test(org.testng.annotations.Test)

Example 19 with ResourceType

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

the class TestDependencies method initDummy.

private void initDummy(String name, Task initTask, OperationResult initResult) throws FileNotFoundException, ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ConnectException, SchemaViolationException, ConflictException, ExpressionEvaluationException {
    String resourceOid = getDummyOid(name);
    DummyResourceContoller resourceCtl = DummyResourceContoller.create(name.toUpperCase());
    resourceCtl.extendSchemaPirate();
    PrismObject<ResourceType> resource = importAndGetObjectFromFile(ResourceType.class, getDummFile(name), resourceOid, initTask, initResult);
    resourceCtl.setResource(resource);
}
Also used : ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) DummyResourceContoller(com.evolveum.midpoint.test.DummyResourceContoller)

Example 20 with ResourceType

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

the class TestExpressionFunctions method testgetResourceIcfConfigurationPropertyValueStringPort.

@Test
public void testgetResourceIcfConfigurationPropertyValueStringPort() throws Exception {
    final String TEST_NAME = "testgetResourceIcfConfigurationPropertyValueStringPort";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    BasicExpressionFunctions f = createBasicFunctions();
    PrismObject<ResourceType> resource = PrismTestUtil.parseObject(RESOURCE_OPENDJ_FILE);
    // WHEN
    int val = f.getResourceIcfConfigurationPropertyValue(resource.asObjectable(), "port");
    // THEN
    assertEquals("Wrong value of ICF configuration property", 10389, val);
}
Also used : BasicExpressionFunctions(com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctions) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Aggregations

ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)252 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)199 Test (org.testng.annotations.Test)165 Task (com.evolveum.midpoint.task.api.Task)115 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)58 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)54 PrismObject (com.evolveum.midpoint.prism.PrismObject)50 QName (javax.xml.namespace.QName)45 ArrayList (java.util.ArrayList)37 Element (org.w3c.dom.Element)34 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)33 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)30 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)28 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)27 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)26 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)26 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)25 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)24 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)23 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)23