Search in sources :

Example 11 with ResourceObjectTypeDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition 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 = ResourceSchemaFactory.getCompleteSchema(resourcePrism);
                            if (schema != null) {
                                // TODO is this OK?
                                ResourceObjectTypeDefinition def = schema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
                                if (def != null) {
                                    for (ResourceAttributeDefinition<?> attribute : def.getAttributeDefinitions()) {
                                        choices.add(attribute.getItemName());
                                    }
                                }
                            }
                        } catch (CommonException | RuntimeException e) {
                            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource schema attributes.", e);
                            getPageBase().error("Couldn't load resource schema attributes" + e);
                        }
                        choices.sort((o1, 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 : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchemaFactory(com.evolveum.midpoint.schema.processor.ResourceSchemaFactory) com.evolveum.midpoint.web.component.wizard.resource.component.capability(com.evolveum.midpoint.web.component.wizard.resource.component.capability) WebModelServiceUtils(com.evolveum.midpoint.gui.api.util.WebModelServiceUtils) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PageResourceWizard(com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard) IModel(org.apache.wicket.model.IModel) Method(java.lang.reflect.Method) Label(org.apache.wicket.markup.html.basic.Label) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) Model(org.apache.wicket.model.Model) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) AttributeModifier(org.apache.wicket.AttributeModifier) com.evolveum.midpoint.xml.ns._public.resource.capabilities_3(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3) InvocationTargetException(java.lang.reflect.InvocationTargetException) ModelService(com.evolveum.midpoint.model.api.ModelService) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) PropertyModel(org.apache.wicket.model.PropertyModel) Item(org.apache.wicket.markup.repeater.Item) Type(java.lang.reflect.Type) SystemException(com.evolveum.midpoint.util.exception.SystemException) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) QName(javax.xml.namespace.QName) DataView(org.apache.wicket.markup.repeater.data.DataView) NotNull(org.jetbrains.annotations.NotNull) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) java.util(java.util) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) CapabilityUtil(com.evolveum.midpoint.schema.CapabilityUtil) Capability(com.evolveum.midpoint.web.component.wizard.resource.dto.Capability) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) JAXBElement(javax.xml.bind.JAXBElement) WizardStep(com.evolveum.midpoint.web.component.wizard.WizardStep) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) CommonException(com.evolveum.midpoint.util.exception.CommonException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ParameterizedType(java.lang.reflect.ParameterizedType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) 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) 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 12 with ResourceObjectTypeDefinition

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

the class FocusProjectionsPanel method addSelectedAccountPerformed.

private void addSelectedAccountPerformed(AjaxRequestTarget target, List<ResourceType> newResources) {
    getPageBase().hideMainPopup(target);
    if (newResources.isEmpty()) {
        warn(getString("pageUser.message.noResourceSelected"));
        return;
    }
    for (ResourceType resource : newResources) {
        try {
            ResourceSchema refinedSchema = getRefinedSchema(resource);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Refined schema for {}\n{}", resource, refinedSchema.debugDump());
            }
            ResourceObjectTypeDefinition accountDefinition = refinedSchema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
            if (accountDefinition == null) {
                error(getString("pageAdminFocus.message.couldntCreateAccountNoAccountSchema", resource.getName()));
                continue;
            }
            // shadow.asPrismContainer().findOrCreateContainer(ShadowType.F_ATTRIBUTES).applyDefinition(accountDefinition.toResourceAttributeContainerDefinition());
            ShadowType shadow = createNewShadow(resource, accountDefinition);
            ShadowWrapper wrapperNew = createShadowWrapper(shadow);
            getProjectionsModel().getObject().add(wrapperNew);
        } catch (Exception ex) {
            error(getString("pageAdminFocus.message.couldntCreateAccount", resource.getName(), ex.getMessage()));
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create account", ex);
        }
    }
    target.add(getMultivalueContainerListPanel());
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) SchemaException(com.evolveum.midpoint.util.exception.SchemaException)

Example 13 with ResourceObjectTypeDefinition

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

the class TypedAssignablePanel method getIntentAvailableValuesModel.

private LoadableModel<List<String>> getIntentAvailableValuesModel() {
    return new LoadableModel<>(true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<String> load() {
            List<String> availableIntentValues = new ArrayList<>();
            if (getResourceTable() != null) {
                List<T> selectedResources = getResourceTable().getSelectedRealObjects();
                if (selectedResources != null && selectedResources.size() > 0) {
                    ResourceType selectedResource = (ResourceType) selectedResources.get(0);
                    try {
                        ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(selectedResource.asPrismObject());
                        if (refinedSchema != null) {
                            ShadowKindType kind = (ShadowKindType) TypedAssignablePanel.this.getKindDropdownComponent().getBaseFormComponent().getModelObject();
                            List<? extends ResourceObjectTypeDefinition> definitions = refinedSchema.getObjectTypeDefinitions(kind);
                            for (ResourceObjectTypeDefinition def : definitions) {
                                availableIntentValues.add(def.getIntent());
                            }
                        }
                    } catch (SchemaException ex) {
                        LOGGER.error("Cannot get refined resource schema for resource {}. {}", selectedResource.getName().getOrig(), ex.getLocalizedMessage());
                    }
                }
            }
            return availableIntentValues;
        }
    };
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) ArrayList(java.util.ArrayList)

Example 14 with ResourceObjectTypeDefinition

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

the class SynchronizationUtils method isPolicyApplicable.

/**
 * Checks if the synchronization policy matches given "parameters" (object class, kind, intent).
 */
public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, @NotNull ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource, boolean strictIntent) throws SchemaException {
    if (objectClassDefinedAndNotMatching(objectClass, synchronizationPolicy.getObjectClass())) {
        return false;
    }
    ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
    Objects.requireNonNull(schema, "No schema defined in resource. Possible configuration problem?");
    ShadowKindType policyKind = requireNonNullElse(synchronizationPolicy.getKind(), ACCOUNT);
    String policyIntent = synchronizationPolicy.getIntent();
    ResourceObjectDefinition policyObjectClass;
    if (StringUtils.isEmpty(policyIntent)) {
        // TODO check this
        policyObjectClass = schema.findObjectDefinition(policyKind, null);
        if (policyObjectClass instanceof ResourceObjectTypeDefinition) {
            policyIntent = ((ResourceObjectTypeDefinition) policyObjectClass).getIntent();
        }
    } else {
        policyObjectClass = schema.findObjectDefinition(policyKind, policyIntent);
    }
    if (policyObjectClass == null) {
        return false;
    }
    // re-check objectClass if wasn't defined
    if (objectClassDefinedAndNotMatching(objectClass, List.of(policyObjectClass.getTypeName()))) {
        return false;
    }
    // kind
    LOGGER.trace("Comparing kinds, policy kind: {}, current kind: {}", policyKind, kind);
    if (kind != null && kind != UNKNOWN && !policyKind.equals(kind)) {
        LOGGER.trace("Kinds don't match, skipping policy {}", synchronizationPolicy);
        return false;
    }
    // intent
    // TODO is the intent always present in shadow at this time? [med]
    LOGGER.trace("Comparing intents, policy intent: {}, current intent: {}", policyIntent, intent);
    if (!strictIntent) {
        if (intent != null && !SchemaConstants.INTENT_UNKNOWN.equals(intent) && !MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
            LOGGER.trace("Intents don't match, skipping policy {}", synchronizationPolicy);
            return false;
        }
    } else {
        if (!MiscSchemaUtil.equalsIntent(intent, policyIntent)) {
            LOGGER.trace("Intents don't match, skipping policy {}", synchronizationPolicy);
            return false;
        }
    }
    return true;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 15 with ResourceObjectTypeDefinition

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

the class SchemaListPanel method loadAllClasses.

private List<ObjectClassDto> loadAllClasses() {
    List<ObjectClassDto> list = new ArrayList<>();
    ResourceSchema schema = loadResourceSchema();
    if (schema == null) {
        return list;
    }
    for (ResourceObjectTypeDefinition definition : schema.getObjectTypeDefinitions()) {
        list.add(new ObjectClassDto(definition));
    }
    Collections.sort(list);
    return list;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) ArrayList(java.util.ArrayList) ObjectClassDto(com.evolveum.midpoint.web.component.wizard.resource.dto.ObjectClassDto)

Aggregations

ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)32 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)14 QName (javax.xml.namespace.QName)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)5 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)3 List (java.util.List)3 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)2 Definition (com.evolveum.midpoint.prism.Definition)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 NotNull (org.jetbrains.annotations.NotNull)2 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)1