Search in sources :

Example 26 with ResourceObjectDefinition

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

the class ResourceDetailsTabPanel method getTaskFor.

private List<TaskType> getTaskFor(List<PrismObject<TaskType>> tasks, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    List<TaskType> syncTasks = new ArrayList<>();
    for (PrismObject<TaskType> task : tasks) {
        ShadowKindType taskKindValue = null;
        String taskIntentValue = null;
        QName taskObjectClassValue = null;
        @Nullable ResourceObjectSetType resourceSet = ResourceObjectSetUtil.fromTask(task.asObjectable());
        if (!Objects.isNull(resourceSet)) {
            taskKindValue = resourceSet.getKind();
            taskIntentValue = resourceSet.getIntent();
            taskObjectClassValue = resourceSet.getObjectclass();
        }
        // is not accessible in admin-gui)
        if (taskObjectClassValue == null) {
            ResourceObjectDefinition taskObjectClassDef = null;
            ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
            if (schema == null) {
                throw new SchemaException("No schema defined in resource. Possible configuration problem?");
            }
            if (taskKindValue == null && taskIntentValue == null) {
                // TODO ok?
                taskObjectClassDef = schema.findObjectDefinition(ShadowKindType.ACCOUNT, null);
            }
            if (taskKindValue != null) {
                if (StringUtils.isEmpty(taskIntentValue)) {
                    // TODO ok?
                    taskObjectClassDef = schema.findObjectDefinition(taskKindValue, null);
                } else {
                    taskObjectClassDef = schema.findObjectDefinition(taskKindValue, taskIntentValue);
                }
            }
            if (taskObjectClassDef != null) {
                taskObjectClassValue = taskObjectClassDef.getTypeName();
            }
        }
        if (SynchronizationUtils.isPolicyApplicable(taskObjectClassValue, taskKindValue, taskIntentValue, synchronizationPolicy, resource, true)) {
            syncTasks.add(task.asObjectable());
        }
    }
    return syncTasks;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with ResourceObjectDefinition

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

the class ResourceContentTabPanel method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    final Form mainForm = new MidpointForm(ID_MAIN_FORM);
    mainForm.setOutputMarkupId(true);
    mainForm.addOrReplace(initTable(getModel()));
    add(mainForm);
    AutoCompleteTextPanel<String> intent = new AutoCompleteTextPanel<String>(ID_INTENT, new PropertyModel<>(resourceContentSearch, "intent"), String.class, false, null) {

        private static final long serialVersionUID = 1L;

        @Override
        public Iterator<String> getIterator(String input) {
            ResourceSchema refinedSchema;
            try {
                refinedSchema = ResourceSchemaFactory.getCompleteSchema(getModelObject());
                if (refinedSchema != null) {
                    return refinedSchema.getIntentsForKind(getKind()).iterator();
                } else {
                    return Collections.emptyIterator();
                }
            } catch (SchemaException e) {
                return Collections.emptyIterator();
            }
        }
    };
    intent.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(get(ID_REAL_OBJECT_CLASS));
            updateResourceContentSearch();
            mainForm.addOrReplace(initTable(getModel()));
            target.add(mainForm);
        }
    });
    intent.setOutputMarkupId(true);
    intent.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isUseObjectClass();
        }
    });
    add(intent);
    Label realObjectClassLabel = new Label(ID_REAL_OBJECT_CLASS, new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            ResourceObjectDefinition ocDef;
            try {
                ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(getModelObject());
                if (refinedSchema == null) {
                    return "NO SCHEMA DEFINED";
                }
                ocDef = refinedSchema.findObjectDefinition(getKind(), getIntent());
                if (ocDef != null) {
                    return ocDef.getObjectClassDefinition().getTypeName().getLocalPart();
                }
            } catch (SchemaException e) {
            }
            return "NOT FOUND";
        }
    });
    realObjectClassLabel.setOutputMarkupId(true);
    add(realObjectClassLabel);
    AutoCompleteQNamePanel objectClassPanel = new AutoCompleteQNamePanel(ID_OBJECT_CLASS, new PropertyModel<>(resourceContentSearch, "objectClass")) {

        private static final long serialVersionUID = 1L;

        @Override
        public Collection<QName> loadChoices() {
            return createObjectClassChoices(getModel());
        }

        @Override
        protected void onChange(AjaxRequestTarget target) {
            LOGGER.trace("Object class panel update: {}", isUseObjectClass());
            updateResourceContentSearch();
            mainForm.addOrReplace(initTable(getModel()));
            target.add(mainForm);
        }
    };
    objectClassPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isUseObjectClass();
        }
    });
    add(objectClassPanel);
    AjaxLink<Boolean> repoSearch = new AjaxLink<Boolean>(ID_REPO_SEARCH, new PropertyModel<>(resourceContentSearch, "resourceSearch")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            isRepoSearch = true;
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT).setResourceSearch(Boolean.FALSE);
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT).setResourceSearch(Boolean.FALSE);
            resourceContentSearch.getObject().setResourceSearch(Boolean.FALSE);
            updateResourceContentSearch();
            mainForm.addOrReplace(initRepoContent(ResourceContentTabPanel.this.getModel()));
            target.add(getParent().addOrReplace(mainForm));
            target.add(this);
            target.add(getParent().get(ID_RESOURCE_SEARCH).add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            if (!getModelObject().booleanValue())
                add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
        }
    };
    add(repoSearch);
    AjaxLink<Boolean> resourceSearch = new AjaxLink<Boolean>(ID_RESOURCE_SEARCH, new PropertyModel<>(resourceContentSearch, "resourceSearch")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            isRepoSearch = false;
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT).setResourceSearch(Boolean.TRUE);
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT).setResourceSearch(Boolean.TRUE);
            updateResourceContentSearch();
            resourceContentSearch.getObject().setResourceSearch(Boolean.TRUE);
            mainForm.addOrReplace(initResourceContent(ResourceContentTabPanel.this.getModel()));
            target.add(getParent().addOrReplace(mainForm));
            target.add(this.add(AttributeModifier.append("class", " active")));
            target.add(getParent().get(ID_REPO_SEARCH).add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            getModelObject().booleanValue();
            if (getModelObject().booleanValue())
                add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
        }
    };
    add(resourceSearch);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Form(org.apache.wicket.markup.html.form.Form) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) QName(javax.xml.namespace.QName) Label(org.apache.wicket.markup.html.basic.Label) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AutoCompleteQNamePanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 28 with ResourceObjectDefinition

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

the class AssociationFromLinkExpressionEvaluator method evaluate.

@Override
public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> evaluate(ExpressionEvaluationContext context, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    checkEvaluatorProfile(context);
    String desc = context.getContextDescription();
    AbstractRoleType thisRole = getRelevantRole(context);
    LOGGER.trace("Evaluating association from link {} on: {}", expressionEvaluatorBean.getDescription(), thisRole);
    // noinspection unchecked
    TypedValue<ResourceObjectDefinition> rAssocTargetDefTypedValue = context.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
    if (rAssocTargetDefTypedValue == null || rAssocTargetDefTypedValue.getValue() == null) {
        throw new ExpressionEvaluationException("No association target object class definition variable in " + desc + "; the expression may be used in a wrong place. It is only supposed to create an association.");
    }
    ResourceObjectDefinition associationTargetDef = (ResourceObjectDefinition) rAssocTargetDefTypedValue.getValue();
    ShadowDiscriminatorType projectionDiscriminator = expressionEvaluatorBean.getProjectionDiscriminator();
    if (projectionDiscriminator == null) {
        throw new ExpressionEvaluationException("No projectionDiscriminator in " + desc);
    }
    ShadowKindType kind = projectionDiscriminator.getKind();
    if (kind == null) {
        throw new ExpressionEvaluationException("No kind in projectionDiscriminator in " + desc);
    }
    String intent = projectionDiscriminator.getIntent();
    PrismContainer<ShadowAssociationType> output = outputDefinition.instantiate();
    QName assocName = context.getMappingQName();
    String resourceOid = associationTargetDef.getResourceOid();
    List<String> candidateShadowOidList = new ArrayList<>();
    // Always process the first role (myself) regardless of recursion setting
    gatherCandidateShadowsFromAbstractRole(thisRole, candidateShadowOidList);
    if (thisRole instanceof OrgType && matchesForRecursion((OrgType) thisRole)) {
        gatherCandidateShadowsFromAbstractRoleRecurse((OrgType) thisRole, candidateShadowOidList, null, desc, context, result);
    }
    LOGGER.trace("Candidate shadow OIDs: {}", candidateShadowOidList);
    selectMatchingShadows(candidateShadowOidList, output, resourceOid, kind, intent, assocName, context, result);
    return ItemDeltaUtil.toDeltaSetTriple(output, null, prismContext);
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) ShadowDiscriminatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorType)

Example 29 with ResourceObjectDefinition

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

the class ResourceContentResourcePanel method createAttributeDefinitionList.

private <T extends ObjectType> List<SearchItemDefinition> createAttributeDefinitionList() {
    List<SearchItemDefinition> map = new ArrayList<>();
    ResourceObjectDefinition ocDef = null;
    try {
        if (getKind() != null) {
            ocDef = getDefinitionByKind();
        } else if (getObjectClass() != null) {
            ocDef = getDefinitionByObjectClass();
        }
    } catch (SchemaException e) {
        warn("Could not get determine object class definition");
        return map;
    }
    if (ocDef == null) {
        return map;
    }
    for (ResourceAttributeDefinition def : ocDef.getAttributeDefinitions()) {
        map.add(new SearchItemDefinition(ItemPath.create(ShadowType.F_ATTRIBUTES, getAttributeName(def)), def, null));
    }
    return map;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ArrayList(java.util.ArrayList) SearchItemDefinition(com.evolveum.midpoint.web.component.search.SearchItemDefinition)

Example 30 with ResourceObjectDefinition

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

the class ResourceContentPanel method getTasksForKind.

private List<TaskType> getTasksForKind(List<PrismObject<TaskType>> tasks) {
    List<TaskType> tasksForKind = new ArrayList<>();
    for (PrismObject<TaskType> task : tasks) {
        ShadowKindType taskKindValue;
        @Nullable ResourceObjectSetType resourceSet = ResourceObjectSetUtil.fromTask(task.asObjectable());
        if (!java.util.Objects.isNull(resourceSet)) {
            taskKindValue = resourceSet.getKind();
            if (Objects.isNull(taskKindValue)) {
                QName taskObjectClass = resourceSet.getObjectclass();
                if (Objects.isNull(taskObjectClass)) {
                    LOGGER.warn("Bad task definition. Task {} doesn't contain definition either of objectClass or kind/intent", task.getOid());
                    continue;
                }
                QName objectClass = getObjectClass();
                if (Objects.isNull(objectClass)) {
                    LOGGER.trace("Trying to determine objectClass for kind: {}, intent: {}", getKind(), getIntent());
                    ResourceObjectDefinition objectClassDef = null;
                    try {
                        objectClassDef = getDefinitionByKind();
                    } catch (SchemaException e) {
                        LOGGER.error("Failed to search for objectClass definition. Reason: {}", e.getMessage(), e);
                    }
                    if (objectClassDef == null) {
                        LOGGER.warn("Cannot find any definition for kind: {}, intent: {}", getKind(), getIntent());
                        continue;
                    }
                    objectClass = objectClassDef.getTypeName();
                }
                if (QNameUtil.match(objectClass, taskObjectClass)) {
                    tasksForKind.add(task.asObjectable());
                }
            } else {
                String taskIntentValue = resourceSet.getIntent();
                if (StringUtils.isNotEmpty(getIntent())) {
                    if (getKind() == taskKindValue && getIntent().equals(taskIntentValue)) {
                        tasksForKind.add(task.asObjectable());
                    }
                } else if (getKind() == taskKindValue) {
                    tasksForKind.add(task.asObjectable());
                }
            }
        }
    }
    return tasksForKind;
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) QName(javax.xml.namespace.QName) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)64 QName (javax.xml.namespace.QName)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 ArrayList (java.util.ArrayList)14 Task (com.evolveum.midpoint.task.api.Task)12 Test (org.testng.annotations.Test)12 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)8 NotNull (org.jetbrains.annotations.NotNull)8 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)6 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)5 Collection (java.util.Collection)5 Nullable (org.jetbrains.annotations.Nullable)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 AutoCompleteQNamePanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel)3 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2