Search in sources :

Example 6 with ResourceType

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

the class SchemaStep method createXmlEditorModel.

private IModel<String> createXmlEditorModel() {
    return new IModel<String>() {

        @Override
        public void detach() {
        }

        @Override
        public String getObject() {
            PrismObject<ResourceType> resource = model.getObject();
            PrismContainer xmlSchema = resource.findContainer(ResourceType.F_SCHEMA);
            if (xmlSchema == null) {
                return null;
            }
            PageBase page = (PageBase) SchemaStep.this.getPage();
            try {
                return page.getPrismContext().xmlSerializer().serialize(xmlSchema.getValue(), SchemaConstantsGenerated.C_SCHEMA);
            } catch (SchemaException | RuntimeException ex) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't serialize resource schema", ex);
                return WebComponentUtil.exceptionToString("Couldn't serialize resource schema", ex);
            }
        }

        @Override
        public void setObject(String object) {
        // ignore (it's interesting that this is called sometimes, even when the ACE is set to be read only)
        }
    };
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IModel(org.apache.wicket.model.IModel) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PageBase(com.evolveum.midpoint.gui.api.page.PageBase)

Example 7 with ResourceType

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

the class ConfigurationStep method createConfigContainerWrappers.

@NotNull
private List<ContainerWrapper> createConfigContainerWrappers() throws SchemaException {
    PrismObject<ResourceType> resource = resourceModelNoFetch.getObject();
    PrismContainer<ConnectorConfigurationType> configuration = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    List<ContainerWrapper> containerWrappers = new ArrayList<>();
    if (configuration == null) {
        PrismObject<ConnectorType> connector = ResourceTypeUtil.getConnectorIfPresent(resource);
        if (connector == null) {
            throw new IllegalStateException("No resolved connector object in resource object");
        }
        ConnectorType connectorType = connector.asObjectable();
        PrismSchema schema;
        try {
            schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, parentPage.getPrismContext());
        } catch (SchemaException e) {
            throw new SystemException("Couldn't parse connector schema: " + e.getMessage(), e);
        }
        PrismContainerDefinition<ConnectorConfigurationType> definition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, schema);
        // Fixing (errorneously) set maxOccurs = unbounded. See MID-2317 and related issues.
        PrismContainerDefinition<ConnectorConfigurationType> definitionFixed = definition.clone();
        ((PrismContainerDefinitionImpl) definitionFixed).setMaxOccurs(1);
        configuration = definitionFixed.instantiate();
    }
    List<PrismContainerDefinition> containerDefinitions = getSortedConfigContainerDefinitions(configuration);
    for (PrismContainerDefinition<?> containerDef : containerDefinitions) {
        ItemPath containerPath = new ItemPath(ResourceType.F_CONNECTOR_CONFIGURATION, containerDef.getName());
        PrismContainer container = configuration.findContainer(containerDef.getName());
        ContainerWrapperFactory cwf = new ContainerWrapperFactory(parentPage);
        ContainerWrapper containerWrapper;
        if (container != null) {
            containerWrapper = cwf.createContainerWrapper(container, ContainerStatus.MODIFYING, containerPath, parentPage.isReadOnly());
        } else {
            container = containerDef.instantiate();
            containerWrapper = cwf.createContainerWrapper(container, ContainerStatus.ADDING, containerPath, parentPage.isReadOnly());
        }
        containerWrappers.add(containerWrapper);
    }
    return containerWrappers;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ArrayList(java.util.ArrayList) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ContainerWrapper(com.evolveum.midpoint.web.component.prism.ContainerWrapper) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ContainerWrapperFactory(com.evolveum.midpoint.web.component.prism.ContainerWrapperFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ResourceType

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

the class PageTaskAdd method createResourceList.

private List<TaskAddResourcesDto> createResourceList() {
    OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
    Task task = createSimpleTask(OPERATION_LOAD_RESOURCES);
    List<PrismObject<ResourceType>> resources = null;
    List<TaskAddResourcesDto> resourceList = new ArrayList<TaskAddResourcesDto>();
    try {
        resources = getModelService().searchObjects(ResourceType.class, new ObjectQuery(), null, task, result);
        result.recomputeStatus();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get resource list.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get resource list", ex);
    }
    // }
    if (resources != null) {
        ResourceType item = null;
        for (PrismObject<ResourceType> resource : resources) {
            item = resource.asObjectable();
            resourceList.add(new TaskAddResourcesDto(item.getOid(), WebComponentUtil.getOrigStringFromPoly(item.getName())));
        }
    }
    return resourceList;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) TaskAddResourcesDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskAddResourcesDto) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 9 with ResourceType

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

the class ValidateExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    PipelineData output = PipelineData.createEmpty();
    for (PipelineItem item : input.getData()) {
        PrismValue value = item.getValue();
        OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
        context.checkTaskStop();
        if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof ResourceType) {
            PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue) value).asPrismObject();
            ResourceType resourceType = resourceTypePrismObject.asObjectable();
            long started = operationsHelper.recordStart(context, resourceType);
            try {
                ValidationResult validationResult = resourceValidator.validate(resourceTypePrismObject, Scope.THOROUGH, null, context.getTask(), result);
                PrismContainer pc = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(SchemaConstantsGenerated.C_VALIDATION_RESULT).instantiate();
                pc.add(validationResult.toValidationResultType().asPrismContainerValue());
                context.println("Validated " + resourceTypePrismObject + ": " + validationResult.getIssues().size() + " issue(s)");
                operationsHelper.recordEnd(context, resourceType, started, null);
                output.add(new PipelineItem(pc.getValue(), item.getResult()));
            } catch (SchemaException | RuntimeException e) {
                operationsHelper.recordEnd(context, resourceType, started, e);
                context.println("Error validation " + resourceTypePrismObject + ": " + e.getMessage());
                //noinspection ThrowableNotThrown
                processActionException(e, NAME, value, context);
                output.add(item);
            }
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    return output;
}
Also used : ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem)

Example 10 with ResourceType

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

the class CorrelationConfirmationEvaluator method findFocusesByCorrelationRule.

public <F extends FocusType> List<PrismObject<F>> findFocusesByCorrelationRule(Class<F> focusType, ShadowType currentShadow, List<ConditionalSearchFilterType> conditionalFilters, ResourceType resourceType, SystemConfigurationType configurationType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    if (conditionalFilters == null || conditionalFilters.isEmpty()) {
        LOGGER.warn("Correlation rule for resource '{}' doesn't contain query, " + "returning empty list of users.", resourceType);
        return null;
    }
    List<PrismObject<F>> users = null;
    if (conditionalFilters.size() == 1) {
        if (satisfyCondition(currentShadow, conditionalFilters.get(0), resourceType, configurationType, "Condition expression", task, result)) {
            LOGGER.trace("Condition {} in correlation expression evaluated to true", conditionalFilters.get(0).getCondition());
            users = findUsersByCorrelationRule(focusType, currentShadow, conditionalFilters.get(0), resourceType, configurationType, task, result);
        }
    } else {
        for (ConditionalSearchFilterType conditionalFilter : conditionalFilters) {
            //TODO: better description
            if (satisfyCondition(currentShadow, conditionalFilter, resourceType, configurationType, "Condition expression", task, result)) {
                LOGGER.trace("Condition {} in correlation expression evaluated to true", conditionalFilter.getCondition());
                List<PrismObject<F>> foundUsers = findUsersByCorrelationRule(focusType, currentShadow, conditionalFilter, resourceType, configurationType, task, result);
                if (foundUsers == null && users == null) {
                    continue;
                }
                if (foundUsers != null && foundUsers.isEmpty() && users == null) {
                    users = new ArrayList<PrismObject<F>>();
                }
                if (users == null && foundUsers != null) {
                    users = foundUsers;
                }
                if (users != null && !users.isEmpty() && foundUsers != null && !foundUsers.isEmpty()) {
                    for (PrismObject<F> foundUser : foundUsers) {
                        if (!contains(users, foundUser)) {
                            users.add(foundUser);
                        }
                    }
                }
            }
        }
    }
    if (users != null) {
        LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} returned {} users: {}", new Object[] { currentShadow, users.size(), PrettyPrinter.prettyPrint(users, 3) });
        if (users.size() > 1) {
            // remove duplicates
            Set<PrismObject<F>> usersWithoutDups = new HashSet<>();
            usersWithoutDups.addAll(users);
            users.clear();
            users.addAll(usersWithoutDups);
            LOGGER.debug("SYNCHRONIZATION: CORRELATION: found {} users without duplicates", users.size());
        }
    }
    return users;
}
Also used : ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType) HashSet(java.util.HashSet)

Aggregations

ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)252 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)199 Test (org.testng.annotations.Test)165 Task (com.evolveum.midpoint.task.api.Task)115 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)58 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)54 PrismObject (com.evolveum.midpoint.prism.PrismObject)50 QName (javax.xml.namespace.QName)45 ArrayList (java.util.ArrayList)37 Element (org.w3c.dom.Element)34 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)33 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)30 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)28 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)27 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)26 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)26 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)25 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)24 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)23 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)23