Search in sources :

Example 11 with ShadowKindType

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

the class ResourceTypeAssignmentPopupTabPanel method getSelectedAssignmentsMap.

@Override
protected Map<String, AssignmentType> getSelectedAssignmentsMap() {
    Map<String, AssignmentType> assignmentList = new HashMap<>();
    List<ResourceType> selectedObjects = getSelectedObjectsList();
    ShadowKindType kind = getKindValue();
    String intent = getIntentValue();
    selectedObjects.forEach(selectedObject -> {
        AssignmentType newConstructionAssignment = ObjectTypeUtil.createAssignmentWithConstruction(selectedObject.asPrismObject(), kind, intent, getPageBase().getPrismContext());
        if (isEntitlementAssignment()) {
            NameItemPathSegment segment = getAssociationValue() != null ? new NameItemPathSegment(getAssociationValue().getName()) : null;
            if (segment != null) {
                ResourceObjectAssociationType association = new ResourceObjectAssociationType();
                association.setRef(new ItemPathType(ItemPath.create(segment)));
                newConstructionAssignment.getConstruction().getAssociation().add(association);
            }
        }
        assignmentList.put(selectedObject.getOid(), newConstructionAssignment);
    });
    return assignmentList;
}
Also used : HashMap(java.util.HashMap) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ResourceObjectAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectAssociationType)

Example 12 with ShadowKindType

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

the class TestEnergy method setKindIntent.

@SuppressWarnings("SameParameterValue")
private void setKindIntent(String shadowName, ShadowKindType kind, String intent, OperationResult result) throws CommonException {
    QName groupOcName = RESOURCE_AD.controller.getGroupObjectClass();
    PrismObject<ResourceType> ad = getObject(ResourceType.class, RESOURCE_AD.oid);
    PrismObject<ShadowType> shadow = findShadowByName(groupOcName, shadowName, ad, result);
    repositoryService.modifyObject(ShadowType.class, shadow.getOid(), prismContext.deltaFor(ShadowType.class).item(ShadowType.F_KIND).replace(kind).item(ShadowType.F_INTENT).replace(intent).asItemDeltas(), null, result);
}
Also used : QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Example 13 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType 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 14 with ShadowKindType

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

the class ConstructionDetailsPanelChainedModel method initModels.

private void initModels() {
    resourceModel = new LoadableDetachableModel<PrismObject<ResourceType>>() {

        @Override
        protected PrismObject<ResourceType> load() {
            ObjectReferenceType resourceRef = getModelObject().getResourceRef();
            Task loadResourceTask = getPageBase().createSimpleTask(OPERATION_LOAD_RESOURCE);
            OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCE);
            PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(resourceRef, getPageBase(), loadResourceTask, result);
            result.computeStatusIfUnknown();
            if (!result.isAcceptable()) {
                LOGGER.error("Cannot find resource referenced from construction. {}", result.getMessage());
                result.recordPartialError("Could not find resource referenced from construction.");
                return null;
            }
            return resource;
        }
    };
    kindModel = new IModel<ShadowKindType>() {

        @Override
        public ShadowKindType getObject() {
            return getModelObject().getKind();
        }

        @Override
        public void setObject(ShadowKindType shadowKindType) {
            getModelObject().setKind(shadowKindType);
        }

        @Override
        public void detach() {
        }
    };
    intentChoicesModel = new ChainingModel<String>(kindModel) {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            List<String> availableIntentValues = new ArrayList<>();
            try {
                if (resourceModel.getObject() == null) {
                    return availableIntentValues.toString();
                }
                ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resourceModel.getObject());
                if (refinedSchema != null) {
                    ShadowKindType kind = ((IModel<ShadowKindType>) super.getChainedModel()).getObject();
                    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.toString();
        }

        @Override
        public void setObject(String o) {
            super.setObject(o);
        }
    };
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with ShadowKindType

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

the class ResourceObjectDefinitionResolver method getDefinitionForShadow.

/**
 * Returns appropriate {@link ResourceObjectDefinition} for given shadow. We are not too strict here.
 * Unknown kind/intent values are ignored (treated like null). Intent without kind is ignored.
 *
 * Takes auxiliary object classes defined in the shadow into account.
 *
 * Note: we could be even more relaxed (in the future):
 *
 * 1. Currently the consistency between kind, intent, and OC is checked. We could avoid this.
 * 2. The {@link ResourceSchema#findObjectDefinition(ShadowKindType, String, QName)} method used throws an exception
 * when it cannot decide among various definitions for given kind (when intent and OC is null). We could be more
 * permissive and return any of them.
 */
@Nullable
public static ResourceObjectDefinition getDefinitionForShadow(@NotNull ResourceSchema resourceSchema, @NotNull ShadowType shadow) {
    QName objectClassName = shadow.getObjectClass();
    ShadowKindType kind;
    String intent;
    // Ignoring "UNKNOWN" values
    if (shadow.getKind() == null || shadow.getKind() == ShadowKindType.UNKNOWN) {
        kind = null;
        intent = null;
    } else {
        kind = shadow.getKind();
        if (SchemaConstants.INTENT_UNKNOWN.equals(shadow.getIntent())) {
            intent = null;
        } else {
            intent = shadow.getIntent();
        }
    }
    ResourceObjectDefinition structuralDefinition;
    if (kind != null) {
        structuralDefinition = resourceSchema.findObjectDefinition(kind, intent, objectClassName);
    } else if (objectClassName != null) {
        structuralDefinition = resourceSchema.findDefinitionForObjectClass(objectClassName);
    } else {
        structuralDefinition = null;
    }
    if (structuralDefinition != null) {
        return addAuxiliaryObjectClasses(structuralDefinition, shadow.getAuxiliaryObjectClass(), resourceSchema);
    } else {
        return null;
    }
}
Also used : QName(javax.xml.namespace.QName) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)33 QName (javax.xml.namespace.QName)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)8 ArrayList (java.util.ArrayList)7 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 List (java.util.List)5 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 NotNull (org.jetbrains.annotations.NotNull)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)3