Search in sources :

Example 1 with CapabilityDto

use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.

the class AddCapabilityDialog method initLayout.

private void initLayout(WebMarkupContainer container) {
    List<IColumn<CapabilityDto<CapabilityType>, String>> columns = initColumns();
    TablePanel<CapabilityDto<CapabilityType>> table = new TablePanel<>(ID_TABLE, createProvider(), columns);
    table.setOutputMarkupId(true);
    table.setShowPaging(false);
    container.add(table);
    AjaxButton cancelButton = new AjaxButton(ID_CANCEL, createStringResource("addCapabilityDialog.button.cancel")) {

        @Override
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            cancelPerformed(ajaxRequestTarget);
        }
    };
    container.add(cancelButton);
    AjaxButton addButton = new AjaxButton(ID_ADD, createStringResource("addCapabilityDialog.button.Add")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addPerformed(target);
        }
    };
    container.add(addButton);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityType) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) TablePanel(com.evolveum.midpoint.web.component.data.TablePanel)

Example 2 with CapabilityDto

use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.

the class CapabilityStep method editCapabilityPerformed.

@SuppressWarnings("unchecked")
private void editCapabilityPerformed(final AjaxRequestTarget target, CapabilityDto<? extends CapabilityType> capability) {
    dtoModel.getObject().setSelected(capability);
    WebMarkupContainer config = getConfigContainer();
    WebMarkupContainer newConfig;
    CapabilityType capType = capability.getCapability();
    if (capType instanceof ActivationCapabilityType) {
        newConfig = new CapabilityActivationPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ActivationCapabilityType>) capability), parentPage) {

            @Override
            public IModel<List<QName>> createAttributeChoiceModel(final IChoiceRenderer<QName> renderer) {
                LoadableModel<List<QName>> attributeChoiceModel = new LoadableModel<List<QName>>(false) {

                    @Override
                    protected List<QName> load() {
                        List<QName> choices = new ArrayList<>();
                        PrismObject<ResourceType> resourcePrism = resourceModel.getObject();
                        try {
                            ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resourcePrism, getPageBase().getPrismContext());
                            if (schema != null) {
                                ObjectClassComplexTypeDefinition def = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
                                for (ResourceAttributeDefinition attribute : def.getAttributeDefinitions()) {
                                    choices.add(attribute.getName());
                                }
                            }
                        } catch (CommonException | RuntimeException e) {
                            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource schema attributes.", e);
                            getPageBase().error("Couldn't load resource schema attributes" + e);
                        }
                        Collections.sort(choices, new Comparator<QName>() {

                            @Override
                            public int compare(QName o1, QName o2) {
                                String s1 = (String) renderer.getDisplayValue(o1);
                                String s2 = (String) renderer.getDisplayValue(o2);
                                return String.CASE_INSENSITIVE_ORDER.compare(s1, s2);
                            }
                        });
                        return choices;
                    }
                };
                parentPage.registerDependentModel(attributeChoiceModel);
                return attributeChoiceModel;
            }
        };
    } else if (capType instanceof ScriptCapabilityType) {
        newConfig = new CapabilityScriptPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ScriptCapabilityType>) capability), getTable(), parentPage);
    } else if (capType instanceof CredentialsCapabilityType) {
        newConfig = new CapabilityCredentialsPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CredentialsCapabilityType>) capability), getTable(), parentPage);
    } else {
        newConfig = new CapabilityValuePanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CapabilityType>) capability), getTable(), parentPage);
    }
    // TODO other specific capabilities (paged, count, ...)
    newConfig.setOutputMarkupId(true);
    config.replaceWith(newConfig);
    target.add(newConfig);
    target.add(getTable());
}
Also used : RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) IModel(org.apache.wicket.model.IModel) QName(javax.xml.namespace.QName) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) IModel(org.apache.wicket.model.IModel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Model(org.apache.wicket.model.Model) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) PropertyModel(org.apache.wicket.model.PropertyModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel)

Example 3 with CapabilityDto

use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.

the class CapabilityStep method savePerformed.

private void savePerformed() {
    Task task = getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES);
    OperationResult result = task.getResult();
    ModelService modelService = getPageBase().getModelService();
    boolean saved = false;
    try {
        PrismObject<ResourceType> oldResource;
        final PrismObject<ResourceType> resourceObject = resourceModel.getObject();
        ResourceType resource = resourceObject.asObjectable();
        List<Object> unsupportedCapabilities = new ArrayList<>();
        if (resource.getCapabilities().getConfigured() != null) {
            for (Object o : resource.getCapabilities().getConfigured().getAny()) {
                CapabilityType capabilityType = CapabilityUtil.asCapabilityType(o);
                if (!Capability.supports(capabilityType.getClass())) {
                    unsupportedCapabilities.add(o);
                }
            }
        }
        // AnyArrayList that is used to implement getAny() is really strange (e.g. doesn't support iterator.remove();
        // and its support for clear() is questionable) -- so let's recreate it altogether
        resource.getCapabilities().setConfigured(new CapabilityCollectionType());
        resource.getCapabilities().getConfigured().getAny().addAll(unsupportedCapabilities);
        ObjectFactory capabilityFactory = new ObjectFactory();
        for (CapabilityDto dto : dtoModel.getObject().getCapabilities()) {
            JAXBElement<? extends CapabilityType> jaxbCapability = createJAXBCapability(dto.getCapability(), capabilityFactory);
            if (jaxbCapability != null) {
                resource.getCapabilities().getConfigured().getAny().add(jaxbCapability);
            }
        }
        oldResource = WebModelServiceUtils.loadObject(ResourceType.class, resource.getOid(), getPageBase(), task, result);
        if (oldResource != null) {
            ObjectDelta<ResourceType> delta = parentPage.computeDiff(oldResource, resourceObject);
            if (!delta.isEmpty()) {
                parentPage.logDelta(delta);
                @SuppressWarnings("unchecked") Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
                modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES), result);
                parentPage.resetModels();
                saved = true;
            }
        }
    } catch (CommonException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save capabilities", e);
        result.recordFatalError("Couldn't save capabilities", e);
    } finally {
        result.computeStatusIfUnknown();
        setResult(result);
    }
    if (parentPage.showSaveResultInPage(saved, result)) {
        getPageBase().showResult(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ModelService(com.evolveum.midpoint.model.api.ModelService) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) PrismObject(com.evolveum.midpoint.prism.PrismObject) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 4 with CapabilityDto

use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.

the class CapabilityStep method getCapabilitiesFromResource.

private List<CapabilityDto<CapabilityType>> getCapabilitiesFromResource(ResourceType resource) {
    List<CapabilityDto<CapabilityType>> capabilityList = new ArrayList<>();
    try {
        Collection<Class<? extends CapabilityType>> nativeClasses = ResourceTypeUtil.getNativeCapabilityClasses(resource);
        List<Object> objects = ResourceTypeUtil.getAllCapabilities(resource);
        for (Object capabilityObject : objects) {
            CapabilityType capability = CapabilityUtil.asCapabilityType(capabilityObject);
            if (Capability.supports(capability.getClass())) {
                capability = fillDefaults(capability);
                capabilityList.add(new CapabilityDto<>(capability, nativeClasses.contains(capability.getClass())));
            } else {
                LOGGER.warn("Capability unsupported by the Resource Wizard: {}", capability);
            }
        }
    } catch (SchemaException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load capabilities", e);
        getPageBase().error(getString("CapabilityStep.message.cantLoadCaps") + e);
    }
    return capabilityList;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 5 with CapabilityDto

use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.

the class CapabilityStep method initLayout.

protected void initLayout() {
    final ListDataProvider<CapabilityDto<CapabilityType>> capabilityProvider = new ListDataProvider<>(this, new PropertyModel<List<CapabilityDto<CapabilityType>>>(dtoModel, CapabilityStepDto.F_CAPABILITIES));
    WebMarkupContainer tableBody = new WebMarkupContainer(ID_CAPABILITY_TABLE);
    tableBody.setOutputMarkupId(true);
    add(tableBody);
    WebMarkupContainer configBody = new WebMarkupContainer(ID_CAPABILITY_CONFIG);
    configBody.setOutputMarkupId(true);
    add(configBody);
    DataView<CapabilityDto<CapabilityType>> capabilityDataView = new DataView<CapabilityDto<CapabilityType>>(ID_CAPABILITY_ROW, capabilityProvider) {

        @Override
        protected void populateItem(final Item<CapabilityDto<CapabilityType>> capabilityRow) {
            final CapabilityDto<CapabilityType> dto = capabilityRow.getModelObject();
            AjaxLink name = new AjaxLink(ID_CAPABILITY_LINK) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    editCapabilityPerformed(target, dto);
                }
            };
            Label label = new Label(ID_CAPABILITY_NAME, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    String rv = dto.getDisplayName();
                    if (Boolean.FALSE.equals(dto.getCapability().isEnabled())) {
                        rv += " " + getString("CapabilityStep.disabled");
                    }
                    return rv;
                }
            });
            name.add(label);
            capabilityRow.add(name);
            Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
            if (dto.getTooltipKey() != null) {
                tooltipLabel.add(new AttributeAppender("data-original-title", getString(dto.getTooltipKey())));
                tooltipLabel.add(new InfoTooltipBehavior());
            } else {
                tooltipLabel.setVisible(false);
            }
            tooltipLabel.setOutputMarkupId(true);
            tooltipLabel.setOutputMarkupPlaceholderTag(true);
            name.add(tooltipLabel);
            AjaxLink deleteLink = new AjaxLink(ID_CAPABILITY_DELETE) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    deleteCapabilityPerformed(target, dto);
                }
            };
            deleteLink.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    return !dto.isAmongNativeCapabilities() && !parentPage.isReadOnly();
                }
            });
            name.add(deleteLink);
            capabilityRow.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<Object>() {

                @Override
                public Object getObject() {
                    return isSelected(capabilityRow.getModelObject()) ? "success" : null;
                }
            }));
        }
    };
    tableBody.add(capabilityDataView);
    AjaxLink addLink = new AjaxLink(ID_CAPABILITY_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addCapabilityPerformed(target);
        }
    };
    parentPage.addEditingVisibleBehavior(addLink);
    add(addLink);
    ModalWindow dialog = new AddCapabilityDialog(DIALOG_SELECT_CAPABILITY, dtoModel) {

        @Override
        protected void addPerformed(AjaxRequestTarget target) {
            addCapabilitiesPerformed(target, getSelectedData());
        }
    };
    add(dialog);
}
Also used : ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Aggregations

CapabilityDto (com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ArrayList (java.util.ArrayList)3 PropertyModel (org.apache.wicket.model.PropertyModel)3 CapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityType)2 ScriptCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)2 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 NonEmptyLoadableModel (com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel)1 ModelService (com.evolveum.midpoint.model.api.ModelService)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)1 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)1 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 CommonException (com.evolveum.midpoint.util.exception.CommonException)1