Search in sources :

Example 6 with ResourceAssociationDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.

the class ShadowAssociationWrapperFactoryImpl method createWrapperInternal.

@Override
protected PrismContainerWrapper<ShadowAssociationType> createWrapperInternal(PrismContainerValueWrapper<?> parent, PrismContainer<ShadowAssociationType> childContainer, ItemStatus status, WrapperContext ctx) {
    OperationResult parentResult = ctx.getResult();
    if (isNotShadow(ctx, parentResult)) {
        return super.createWrapperInternal(parent, childContainer, status, ctx);
    }
    if (isNotAssociation(childContainer)) {
        parentResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Association for " + childContainer.getComplexTypeDefinition().getTypeClass() + " is not supported");
        LOGGER.debug("Association for {} is not supported", childContainer.getComplexTypeDefinition().getTypeClass());
        return super.createWrapperInternal(parent, childContainer, status, ctx);
    }
    if (ctx.getObject() == null) {
        return super.createWrapperInternal(parent, childContainer, status, ctx);
    }
    ShadowType shadow = (ShadowType) ctx.getObject().asObjectable();
    PrismObject<ResourceType> resource = loadResource(shadow, ctx);
    if (resource == null) {
        return super.createWrapperInternal(parent, childContainer, status, ctx);
    }
    Collection<ResourceAssociationDefinition> resourceAssociationDefinitions = loadRefinedAssociationDefinitions(resource, shadow, parentResult);
    if (resourceAssociationDefinitions == null) {
        return super.createWrapperInternal(parent, childContainer, status, ctx);
    }
    ctx.setResource(resource.asObjectable());
    ctx.setRefinedAssociationDefinitions(resourceAssociationDefinitions);
    ShadowAssociationWrapperImpl associationWrapper = createShadowAssociationWrapper(parent, childContainer, shadow, status, ctx);
    if (associationWrapper == null) {
        return super.createWrapperInternal(parent, childContainer, status, ctx);
    }
    return associationWrapper;
}
Also used : ShadowAssociationWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 7 with ResourceAssociationDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.

the class ShadowAssociationWrapperFactoryImpl method createValuesWrapper.

@Override
protected List<PrismContainerValueWrapper<ShadowAssociationType>> createValuesWrapper(PrismContainerWrapper<ShadowAssociationType> itemWrapper, PrismContainer<ShadowAssociationType> item, WrapperContext context) throws SchemaException {
    if (!(itemWrapper instanceof ShadowAssociationWrapperImpl)) {
        return super.createValuesWrapper(itemWrapper, item, context);
    }
    ShadowAssociationWrapperImpl associationWrapper = (ShadowAssociationWrapperImpl) itemWrapper;
    PrismContainerValueWrapper<ShadowAssociationType> shadowValueWrapper = createContainerValueWrapper(associationWrapper, associationWrapper.getItem().createNewValue(), ItemStatus.ADDED == associationWrapper.getStatus() ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, context);
    Collection<PrismReferenceWrapper> shadowReferences = new ArrayList<>();
    for (ResourceAssociationDefinition def : context.getRefinedAssociationDefinitions()) {
        PrismReference shadowAss = fillInShadowReference(def, item);
        PrismReferenceWrapper shadowReference = (PrismReferenceWrapper) referenceWrapperFactory.createWrapper(shadowValueWrapper, shadowAss, shadowAss.isEmpty() ? ItemStatus.ADDED : ItemStatus.NOT_CHANGED, context);
        shadowReference.setFilter(WebComponentUtil.createAssociationShadowRefFilter(def, getPrismContext(), context.getResource().getOid()));
        shadowReferences.add(shadowReference);
    }
    shadowValueWrapper.getItems().addAll((Collection) shadowReferences);
    setupExpanded(shadowValueWrapper);
    return Collections.singletonList(shadowValueWrapper);
}
Also used : PrismReferenceWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismReferenceWrapper) ShadowAssociationWrapperImpl(com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl) ArrayList(java.util.ArrayList) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 8 with ResourceAssociationDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.

the class ShadowAssociationWrapperFactoryImpl method loadRefinedAssociationDefinitions.

private Collection<ResourceAssociationDefinition> loadRefinedAssociationDefinitions(PrismObject<ResourceType> resource, ShadowType shadow, OperationResult parentResult) {
    OperationResult result = parentResult.createMinorSubresult(CREATE_ASSOCIATION_WRAPPER);
    ResourceSchema refinedResourceSchema;
    try {
        refinedResourceSchema = ResourceSchemaFactory.getCompleteSchema(resource);
    } catch (SchemaException e) {
        LOGGER.error("Cannot get refined schema for {}, {}", resource, e.getMessage(), e);
        result.recordPartialError("Could not get fined schema for " + resource, e);
        return null;
    }
    ShadowKindType kind = shadow.getKind();
    String shadowIntent = shadow.getIntent();
    ResourceObjectDefinition oc = refinedResourceSchema.findObjectDefinition(kind, shadowIntent);
    if (oc == null) {
        LOGGER.debug("Association for {}/{} not supported by resource {}", kind, shadowIntent, resource);
        result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Association for " + kind + "/" + shadowIntent + " not supported by resource " + resource);
        return null;
    }
    Collection<ResourceAssociationDefinition> resourceAssociationDefinitions = oc.getAssociationDefinitions();
    if (CollectionUtils.isEmpty(resourceAssociationDefinitions)) {
        result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Association for " + kind + "/" + shadowIntent + " not supported by resource " + resource);
        LOGGER.debug("Association for {}/{} not supported by resource {}", kind, shadowIntent, resource);
        return null;
    }
    result.computeStatusIfUnknown();
    return resourceAssociationDefinitions;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Example 9 with ResourceAssociationDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.

the class ResourceTypeAssignmentPopupTabPanel method initParametersPanel.

@Override
protected void initParametersPanel(Fragment parametersPanel) {
    initModels();
    WebMarkupContainer kindContainer = new WebMarkupContainer(ID_KIND_CONTAINER);
    kindContainer.setOutputMarkupId(true);
    parametersPanel.add(kindContainer);
    DropDownChoicePanel<ShadowKindType> kindSelector = WebComponentUtil.createEnumPanel(ShadowKindType.class, ID_KIND, WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), Model.of(), ResourceTypeAssignmentPopupTabPanel.this, true);
    kindSelector.setOutputMarkupId(true);
    kindSelector.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            kindValueUpdatePerformed(target);
        }
    });
    kindSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0;
        }
    });
    kindSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    kindSelector.setOutputMarkupPlaceholderTag(true);
    kindContainer.add(kindSelector);
    WebMarkupContainer intentContainer = new WebMarkupContainer(ID_INTENT_CONTAINER);
    intentContainer.setOutputMarkupId(true);
    parametersPanel.add(intentContainer);
    DropDownChoicePanel<String> intentSelector = new DropDownChoicePanel<String>(ID_INTENT, Model.of(), intentValues, true);
    intentSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getKindValue() != null && getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0;
        }
    });
    intentSelector.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            intentValueUpdatePerformed(target);
        }
    });
    intentSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    intentSelector.setOutputMarkupId(true);
    intentSelector.setOutputMarkupPlaceholderTag(true);
    intentContainer.add(intentSelector);
    WebMarkupContainer associationContainer = new WebMarkupContainer(ID_ASSOCIATION_CONTAINER);
    associationContainer.setOutputMarkupId(true);
    associationContainer.add(new VisibleBehaviour(() -> isEntitlementAssignment()));
    parametersPanel.add(associationContainer);
    DropDownChoicePanel<ResourceAssociationDefinition> associationSelector = new DropDownChoicePanel<>(ID_ASSOCIATION, Model.of(), associationValuesModel, new IChoiceRenderer<ResourceAssociationDefinition>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getDisplayValue(ResourceAssociationDefinition refinedAssociationDefinition) {
            return WebComponentUtil.getAssociationDisplayName(refinedAssociationDefinition);
        }

        @Override
        public String getIdValue(ResourceAssociationDefinition refinedAssociationDefinition, int index) {
            return Integer.toString(index);
        }

        @Override
        public ResourceAssociationDefinition getObject(String id, IModel<? extends List<? extends ResourceAssociationDefinition>> choices) {
            return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
        }
    }, true);
    associationSelector.setOutputMarkupId(true);
    associationSelector.getBaseFormComponent().add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getSelectedObjectsList() != null && getSelectedObjectsList().size() > 0 && getKindValue() != null && StringUtils.isNotEmpty(getIntentValue());
        }
    });
    associationSelector.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    associationSelector.setOutputMarkupPlaceholderTag(true);
    associationContainer.add(associationSelector);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) EmptyOnChangeAjaxFormUpdatingBehavior(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 10 with ResourceAssociationDefinition

use of com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition in project midpoint by Evolveum.

the class ResourceAttributeRefPanelFactory method getChoicesList.

private List<ItemName> getChoicesList(PrismPropertyPanelContext<ItemPathType> ctx) {
    PrismPropertyWrapper<?> wrapper = ctx.unwrapWrapperModel();
    // attribute/ref
    if (wrapper == null) {
        return Collections.emptyList();
    }
    // attribute value
    if (wrapper.getParent() == null) {
        return Collections.emptyList();
    }
    // attribute
    ItemWrapper<?, ?> attributeWrapper = wrapper.getParent().getParent();
    if (attributeWrapper == null) {
        return Collections.emptyList();
    }
    PrismContainerValueWrapper<?> itemWrapper = attributeWrapper.getParent();
    if (itemWrapper == null) {
        return Collections.emptyList();
    }
    if (!(itemWrapper instanceof ConstructionValueWrapper)) {
        return Collections.emptyList();
    }
    ConstructionValueWrapper constructionWrapper = (ConstructionValueWrapper) itemWrapper;
    try {
        ResourceSchema schema = constructionWrapper.getRefinedSchema();
        if (schema == null) {
            return new ArrayList<>();
        }
        ResourceObjectDefinition rOcd = schema.findObjectDefinition(constructionWrapper.getKind(), constructionWrapper.getIntent());
        if (rOcd == null) {
            return Collections.emptyList();
        }
        if (ConstructionType.F_ASSOCIATION.equivalent(attributeWrapper.getItemName())) {
            Collection<ResourceAssociationDefinition> associationDefs = rOcd.getAssociationDefinitions();
            return associationDefs.stream().map(ResourceAssociationDefinition::getName).collect(Collectors.toList());
        }
        Collection<? extends ResourceAttributeDefinition<?>> attrDefs = rOcd.getAttributeDefinitions();
        return attrDefs.stream().map(a -> a.getItemName()).collect(Collectors.toList());
    } catch (SchemaException e) {
        LOGGER.warn("Cannot get resource attribute definitions");
    }
    return Collections.emptyList();
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ArrayList(java.util.ArrayList) PrismPropertyWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) IModel(org.apache.wicket.model.IModel) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Serializable(java.io.Serializable) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) List(java.util.List) Component(org.springframework.stereotype.Component) ItemName(com.evolveum.midpoint.prism.path.ItemName) PostConstruct(javax.annotation.PostConstruct) AutoCompleteQNamePanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Collections(java.util.Collections) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ConstructionValueWrapper(com.evolveum.midpoint.gui.impl.prism.wrapper.ConstructionValueWrapper) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ArrayList(java.util.ArrayList) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)

Aggregations

ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)15 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)5 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)4 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ShadowAssociationWrapperImpl (com.evolveum.midpoint.gui.impl.prism.wrapper.ShadowAssociationWrapperImpl)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)2 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)2 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 IModel (org.apache.wicket.model.IModel)2 NotNull (org.jetbrains.annotations.NotNull)2 AutoCompleteQNamePanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel)1 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)1 PrismContainerValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)1 PrismPropertyWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper)1