Search in sources :

Example 1 with ResourceAttributeDefinitionType

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

the class ResourceDetailsTabPanel method determineIfSourceOrTarget.

private SourceTarget determineIfSourceOrTarget(ResourceType resource) {
    if (resource.getSchemaHandling() != null && CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) {
        boolean hasOutbound = false;
        boolean hasInbound = false;
        for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling().getObjectType()) {
            if (CollectionUtils.isEmpty(resourceObjectTypeDefinition.getAttribute())) {
                continue;
            }
            if (hasInbound && hasOutbound) {
                return SourceTarget.SOURCE_TARGET;
            }
            for (ResourceAttributeDefinitionType attr : resourceObjectTypeDefinition.getAttribute()) {
                if (hasInbound && hasOutbound) {
                    return SourceTarget.SOURCE_TARGET;
                }
                if (!hasOutbound) {
                    hasOutbound = isOutboundDefined(attr);
                }
                if (!hasInbound) {
                    hasInbound = isInboundDefined(attr);
                }
            }
        // TODO: what about situation that we have only
        }
        if (hasOutbound) {
            return SourceTarget.TARGET;
        }
        if (hasInbound) {
            return SourceTarget.SOURCE;
        }
    }
    return SourceTarget.NOT_DEFINED;
}
Also used : ResourceObjectTypeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType)

Example 2 with ResourceAttributeDefinitionType

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

the class Construction method evaluateAttributes.

private void evaluateAttributes(Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    attributeMappings = new ArrayList<>();
    // assignments.size(), assignments});
    for (ResourceAttributeDefinitionType attribudeDefinitionType : getConstructionType().getAttribute()) {
        QName attrName = ItemPathUtil.getOnlySegmentQName(attribudeDefinitionType.getRef());
        if (attrName == null) {
            throw new SchemaException("No attribute name (ref) in attribute definition in account construction in " + getSource());
        }
        if (!attribudeDefinitionType.getInbound().isEmpty()) {
            throw new SchemaException("Cannot process inbound section in definition of attribute " + attrName + " in account construction in " + getSource());
        }
        MappingType outboundMappingType = attribudeDefinitionType.getOutbound();
        if (outboundMappingType == null) {
            throw new SchemaException("No outbound section in definition of attribute " + attrName + " in account construction in " + getSource());
        }
        Mapping<? extends PrismPropertyValue<?>, ? extends PrismPropertyDefinition<?>> attributeMapping = evaluateAttribute(attribudeDefinitionType, task, result);
        if (attributeMapping != null) {
            attributeMappings.add(attributeMapping);
        }
    }
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType)

Example 3 with ResourceAttributeDefinitionType

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

the class TestConsistencyMechanism method test511AssignAccountMorgan.

/**
 * assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
 * account should be linked to the user.
 */
@Test
public void test511AssignAccountMorgan() throws Exception {
    // GIVEN
    openDJController.assumeRunning();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    // prepare new OU in opendj
    openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILE);
    PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
    display("User Morgan: ", user);
    ExpressionType expression = new ExpressionType();
    ObjectFactory of = new ObjectFactory();
    RawType raw = new RawType(prismContext.xnodeFactory().primitive("uid=morgan,ou=users,dc=example,dc=com").frozen(), prismContext);
    JAXBElement<?> val = of.createValue(raw);
    expression.getExpressionEvaluator().add(val);
    MappingType mapping = new MappingType();
    mapping.setExpression(expression);
    ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
    attrDefType.setRef(new ItemPathType(ItemPath.create(getOpenDjSecondaryIdentifierQName())));
    attrDefType.setOutbound(mapping);
    ConstructionType construction = new ConstructionType();
    construction.getAttribute().add(attrDefType);
    construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo, prismContext));
    AssignmentType assignment = new AssignmentType();
    assignment.setConstruction(construction);
    // noinspection unchecked
    ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, assignment.asPrismContainerValue());
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    when();
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    then();
    result.computeStatus();
    // assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
    PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
    display("User morgan after", userMorgan);
    UserType userMorganType = userMorgan.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
    String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    provisioningService.applyDefinition(accountShadow, task, result);
    assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertShadowModel(accountModel, accountOid, "uid=morgan,ou=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    ResourceAttribute<?> attributes = ShadowUtil.getAttribute(accountModel, new QName(MidPointConstants.NS_RI, "uid"));
    assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) 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) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 4 with ResourceAttributeDefinitionType

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

the class ResourceCarefulAntUtil method createNewSchemaHandling.

private static SchemaHandlingType createNewSchemaHandling(File resourceFile, int iteration, PrismContext prismContext) throws SchemaException {
    PrismObject<ResourceType> resource = parseResource(resourceFile, prismContext);
    SchemaHandlingType schemaHandling = resource.asObjectable().getSchemaHandling();
    ResourceObjectTypeDefinitionType accountType = schemaHandling.getObjectType().iterator().next();
    List<ResourceAttributeDefinitionType> attrDefs = accountType.getAttribute();
    ResourceAttributeDefinitionType attributeDefinitionType = attrDefs.get(rnd.nextInt(attrDefs.size()));
    attributeDefinitionType.setDescription(Integer.toString(iteration));
    return schemaHandling;
}
Also used : SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) ResourceObjectTypeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Example 5 with ResourceAttributeDefinitionType

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

the class ValueDisplayUtil method toStringValue.

private static String toStringValue(Object value) {
    // todo i18n
    String defaultStr = "(a value of type " + value.getClass().getSimpleName() + ")";
    if (value instanceof String) {
        return (String) value;
    } else if (value instanceof PolyString) {
        return ((PolyString) value).getOrig();
    } else if (value instanceof ProtectedStringType) {
        // todo i18n
        return "(protected string)";
    } else if (value instanceof Boolean || value instanceof Integer || value instanceof Long) {
        return value.toString();
    } else if (value instanceof XMLGregorianCalendar) {
        // todo fix
        return ((XMLGregorianCalendar) value).toGregorianCalendar().getTime().toLocaleString();
    } else if (value instanceof Date) {
        // todo fix
        return ((Date) value).toLocaleString();
    } else if (value instanceof LoginEventType) {
        LoginEventType loginEventType = (LoginEventType) value;
        if (loginEventType.getTimestamp() != null) {
            // todo fix
            return loginEventType.getTimestamp().toGregorianCalendar().getTime().toLocaleString();
        } else {
            return "";
        }
    } else if (value instanceof ScheduleType) {
        return SchemaDebugUtil.prettyPrint((ScheduleType) value);
    } else if (value instanceof ApprovalSchemaType) {
        ApprovalSchemaType approvalSchemaType = (ApprovalSchemaType) value;
        return approvalSchemaType.getName() + (approvalSchemaType.getDescription() != null ? (": " + approvalSchemaType.getDescription()) : "") + " (...)";
    } else if (value instanceof ConstructionType) {
        ConstructionType ct = (ConstructionType) value;
        Object resource = (ct.getResourceRef() != null ? ct.getResourceRef().getOid() : null);
        return "resource object" + (resource != null ? " on " + resource : "") + (ct.getDescription() != null ? ": " + ct.getDescription() : "");
    } else if (value instanceof Enum) {
        return value.toString();
    } else if (value instanceof ResourceAttributeDefinitionType) {
        ResourceAttributeDefinitionType radt = (ResourceAttributeDefinitionType) value;
        ItemPathType ref = radt.getRef();
        String path;
        if (ref != null) {
            path = ref.getItemPath().toString();
        } else {
            path = "(null)";
        }
        StringBuilder sb = new StringBuilder();
        MappingType mappingType = radt.getOutbound();
        if (mappingType != null) {
            if (mappingType.getExpression() == null) {
                sb.append("Empty mapping for ").append(path);
            } else {
                sb.append(path).append(" = ");
                boolean first = true;
                for (JAXBElement<?> evaluator : mappingType.getExpression().getExpressionEvaluator()) {
                    if (first) {
                        first = false;
                    } else {
                        sb.append(", ");
                    }
                    if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) {
                        RawType raw = (RawType) evaluator.getValue();
                        try {
                            sb.append(raw.extractString("(a complex value)"));
                        } catch (RuntimeException e) {
                            sb.append("(an invalid value)");
                        }
                    } else {
                        sb.append("(a complex expression)");
                    }
                }
            }
            if (mappingType.getStrength() != null) {
                sb.append(" (").append(mappingType.getStrength().value()).append(")");
            }
        } else {
            sb.append("Empty mapping for ").append(path);
        }
        return sb.toString();
    } else if (value instanceof QName) {
        QName qname = (QName) value;
        return qname.getLocalPart();
    // if (StringUtils.isNotEmpty(qname.getNamespaceURI())) {
    // return qname.getLocalPart() + " (in " + qname.getNamespaceURI() + ")";
    // } else {
    // return qname.getLocalPart();
    // }
    } else if (value instanceof Number) {
        return String.valueOf(value);
    } else if (value instanceof byte[]) {
        return "(binary data)";
    } else if (value instanceof RawType) {
        try {
            Object parsedValue = ((RawType) value).getValue();
            return toStringValue(parsedValue);
        } catch (SchemaException e) {
            return PrettyPrinter.prettyPrint(value);
        }
    } else if (value instanceof ItemPathType) {
        ItemPath itemPath = ((ItemPathType) value).getItemPath();
        StringBuilder sb = new StringBuilder();
        itemPath.getSegments().forEach(segment -> {
            if (ItemPath.isName(segment)) {
                sb.append(PrettyPrinter.prettyPrint(ItemPath.toName(segment)));
            } else if (ItemPath.isVariable(segment)) {
                sb.append(PrettyPrinter.prettyPrint(ItemPath.toVariableName(segment)));
            } else {
                sb.append(segment.toString());
            }
            sb.append("; ");
        });
        return sb.toString();
    } else if (value instanceof ExpressionType) {
        StringBuilder expressionString = new StringBuilder();
        if (((ExpressionType) value).getExpressionEvaluator() != null && ((ExpressionType) value).getExpressionEvaluator().size() > 0) {
            ((ExpressionType) value).getExpressionEvaluator().forEach(evaluator -> {
                if (evaluator.getValue() instanceof RawType) {
                    expressionString.append(PrettyPrinter.prettyPrint(evaluator.getValue()));
                    expressionString.append("; ");
                } else if (evaluator.getValue() instanceof SearchObjectExpressionEvaluatorType) {
                    SearchObjectExpressionEvaluatorType evaluatorValue = (SearchObjectExpressionEvaluatorType) evaluator.getValue();
                    if (evaluatorValue.getFilter() != null) {
                        DebugUtil.debugDumpMapMultiLine(expressionString, evaluatorValue.getFilter().getFilterClauseXNode().toMap(), 0, false, null);
                        // TODO temporary hack: removing namespace part of the QName
                        while (expressionString.indexOf("}") >= 0 && expressionString.indexOf("{") >= 0 && expressionString.indexOf("}") - expressionString.indexOf("{") > 0) {
                            expressionString.replace(expressionString.indexOf("{"), expressionString.indexOf("}") + 1, "");
                        }
                    }
                } else {
                    expressionString.append(defaultStr);
                }
            });
        }
        return expressionString.toString();
    } else {
        return defaultStr;
    }
}
Also used : com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Date(java.util.Date) JAXBElement(javax.xml.bind.JAXBElement) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) DebugUtil(com.evolveum.midpoint.util.DebugUtil) PrettyPrinter(com.evolveum.midpoint.util.PrettyPrinter) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) QNameUtil(com.evolveum.midpoint.util.QNameUtil) QName(javax.xml.namespace.QName) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Date(java.util.Date) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

QName (javax.xml.namespace.QName)6 ResourceAttributeDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)4 JAXBElement (javax.xml.bind.JAXBElement)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)3 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)3 Test (org.testng.annotations.Test)3 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 PropertyLimitationsType (com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyLimitationsType)2 ResourceObjectTypeDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType)2 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)1 Mapping (com.evolveum.midpoint.model.common.mapping.Mapping)1 PrismReference (com.evolveum.midpoint.prism.PrismReference)1