Search in sources :

Example 11 with ConstructionType

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

the class ConstructionDetailsPanelChainedModel method initLayout.

private void initLayout() {
    CompoundPropertyModel constrModel = new CompoundPropertyModel(getModel()) {

        @Override
        public Object getObject() {
            Object o = super.getObject();
            return o;
        }

        @Override
        public void setObject(Object o) {
            super.setObject(o);
        }
    };
    Form<ConstructionType> form = new Form<ConstructionType>(ID_FORM, constrModel);
    form.setOutputMarkupId(true);
    DropDownChoice kindChoice = new DropDownChoice<>("kind", Model.ofList(Arrays.asList(ShadowKindType.values())));
    kindChoice.setOutputMarkupId(true);
    kindChoice.add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {

        @Override
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
        // ajaxRequestTarget.add(form);
        }
    });
    // kindChoice.add(new AjaxEventBehavior("blur") {
    // @Override
    // protected void onEvent(AjaxRequestTarget ajaxRequestTarget) {
    // ajaxRequestTarget.add(form);
    // }
    // });
    form.add(kindChoice);
    DropDownChoice intentDropdown = new DropDownChoice<>("intent", new IModel<List<String>>() {

        @Override
        public List<String> getObject() {
            List<String> availableIntentValues = new ArrayList<>();
            try {
                if (resourceModel.getObject() == null) {
                    return availableIntentValues;
                }
                ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resourceModel.getObject());
                if (refinedSchema != null) {
                    ConstructionType m = (ConstructionType) constrModel.getObject();
                    ShadowKindType kind = m.getKind();
                    List<? extends ResourceObjectTypeDefinition> definitions = refinedSchema.getObjectTypeDefinitions(kind);
                    for (ResourceObjectTypeDefinition def : definitions) {
                        if (def.getIntent() != null) {
                            availableIntentValues.add(def.getIntent());
                        }
                    }
                }
            } catch (SchemaException ex) {
                LOGGER.error("Cannot get refined resource schema for resource {}. {}", resourceModel.getObject().getName().getOrig(), ex.getLocalizedMessage());
            }
            return availableIntentValues;
        }

        @Override
        public void setObject(List<String> o) {
        // 
        }

        @Override
        public void detach() {
        }
    });
    intentDropdown.setOutputMarkupId(true);
    form.add(intentDropdown);
    add(form);
// DropDownChoice kindDropDown = new DropDownChoice<ShadowKindType>(ID_KIND_FIELD, kindModel, Model.ofList(Arrays.asList(ShadowKindType.values()))){
// @Override
// protected void onSelectionChanged(ShadowKindType newSelection) {
// if (newSelection == null){
// ConstructionDetailsPanelChainedModel.this.getModelObject().setKind(null);
// return;
// }
// if (newSelection instanceof ShadowKindType){
// ConstructionDetailsPanelChainedModel.this.getModelObject().setKind((ShadowKindType) newSelection);
// }
// }
// };
// kindDropDown.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// 
// kindDropDown.setOutputMarkupId(true);
// add(kindDropDown);
// 
// TextField intentDropDown = new TextField(ID_INTENT_FIELD, intentChoicesModel);
// DropDownChoicePanel intentDropDown = new DropDownChoicePanel(ID_INTENT_FIELD,
// PropertyModel.of(getModel(), ConstructionType.F_INTENT.getLocalPart()), intentChoicesModel);
// intentDropDown.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// intentDropDown.setOutputMarkupId(true);
// add(intentDropDown);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Form(org.apache.wicket.markup.html.form.Form) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) PrismObject(com.evolveum.midpoint.prism.PrismObject) ArrayList(java.util.ArrayList) List(java.util.List) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 12 with ConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType 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)

Example 13 with ConstructionType

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

the class ConstructionWrapperFactory method createContainerValueWrapper.

@Override
public PrismContainerValueWrapper<ConstructionType> createContainerValueWrapper(PrismContainerWrapper<ConstructionType> objectWrapper, PrismContainerValue<ConstructionType> objectValue, ValueStatus status, WrapperContext context) {
    ConstructionValueWrapper constructionValueWrapper = new ConstructionValueWrapper(objectWrapper, objectValue, status);
    ConstructionType constructionType = objectValue.asContainerable();
    if (constructionType.getResourceRef() != null) {
        PrismObject resource = constructionType.getResourceRef().asReferenceValue().getObject();
        if (resource != null) {
            constructionValueWrapper.setResource(resource);
            return constructionValueWrapper;
        }
    }
    setupResource(constructionValueWrapper, constructionType, context);
    return constructionValueWrapper;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType)

Example 14 with ConstructionType

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

the class AssignmentTablePanel method addSelectedResourceAssignPerformed.

protected void addSelectedResourceAssignPerformed(ResourceType resource) {
    AssignmentType assignment = new AssignmentType();
    ConstructionType construction = new ConstructionType();
    assignment.setConstruction(construction);
    try {
        getPageBase().getPrismContext().adopt(assignment, UserType.class, new ItemPath(UserType.F_ASSIGNMENT));
    } catch (SchemaException e) {
        error(getString("Could not create assignment", resource.getName(), e.getMessage()));
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create assignment", e);
        return;
    }
    construction.setResource(resource);
    List<AssignmentEditorDto> assignments = getAssignmentModel().getObject();
    AssignmentEditorDto dto = new AssignmentEditorDto(UserDtoStatus.ADD, assignment, getPageBase());
    assignments.add(dto);
    dto.setMinimized(true);
    dto.setShowEmpty(true);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with ConstructionType

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

the class ConsistencyTest 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.
	 * @throws Exception
	 */
@Test
public void test511AssignAccountMorgan() throws Exception {
    final String TEST_NAME = "test511AssignAccountMorgan";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    openDJController.assumeRunning();
    Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    //prepare new OU in opendj
    Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
    PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
    display("User Morgan: ", user);
    PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
    ExpressionType expression = new ExpressionType();
    ObjectFactory of = new ObjectFactory();
    RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), 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(new ItemPath(getOpenDjSecondaryIdentifierQName())));
    attrDefType.setOutbound(mapping);
    ConstructionType construction = new ConstructionType();
    construction.getAttribute().add(attrDefType);
    construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
    AssignmentType assignment = new AssignmentType();
    assignment.setConstruction(construction);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    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);
    assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,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=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
    assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account        
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) 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) Entry(org.opends.server.types.Entry) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

ConstructionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType)17 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)11 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 Test (org.testng.annotations.Test)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 QName (javax.xml.namespace.QName)5 ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)4 MetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)3 ArrayList (java.util.ArrayList)3 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)2