Search in sources :

Example 21 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class AbstractManagedConnectorInstance method applyConfigurationToConfigurationClass.

private void applyConfigurationToConfigurationClass(PrismContainerValue<?> configurationContainer) throws ConfigurationException {
    BeanWrapper connectorBean = new BeanWrapperImpl(this);
    PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorBean, ManagedConnectorConfiguration.class);
    if (connectorConfigurationProp == null) {
        return;
    }
    Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
    Object configurationObject;
    try {
        configurationObject = configurationClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new ConfigurationException("Cannot instantiate configuration " + configurationClass);
    }
    BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationObject);
    for (Item<?, ?> configurationItem : configurationContainer.getItems()) {
        if (!(configurationItem instanceof PrismProperty<?>)) {
            throw new ConfigurationException("Only properties are supported for now");
        }
        PrismProperty<?> configurationProperty = (PrismProperty<?>) configurationItem;
        Object realValue = configurationProperty.getRealValue();
        configurationClassBean.setPropertyValue(configurationProperty.getElementName().getLocalPart(), realValue);
    }
    connectorBean.setPropertyValue(connectorConfigurationProp.getName(), configurationObject);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) PropertyDescriptor(java.beans.PropertyDescriptor) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException)

Example 22 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class PageTaskController method deleteSyncTokenPerformed.

public void deleteSyncTokenPerformed(AjaxRequestTarget target) {
    LOGGER.debug("Deleting sync token.");
    OperationResult result = new OperationResult(PageTaskEdit.OPERATION_DELETE_SYNC_TOKEN);
    Task operationTask = parentPage.createSimpleTask(PageTaskEdit.OPERATION_DELETE_SYNC_TOKEN);
    try {
        final TaskDto taskDto = parentPage.getTaskDto();
        final PrismProperty property = taskDto.getExtensionProperty(SchemaConstants.SYNC_TOKEN);
        if (property == null) {
            // should be treated by isVisible
            result.recordWarning("Token is not present in this task.");
        } else {
            final ObjectDelta<? extends ObjectType> delta = (ObjectDelta<? extends ObjectType>) DeltaBuilder.deltaFor(TaskType.class, parentPage.getPrismContext()).item(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.SYNC_TOKEN), property.getDefinition()).replace().asObjectDelta(parentPage.getTaskDto().getOid());
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Deleting sync token:\n{}", delta.debugDump());
            }
            parentPage.getModelService().executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singleton(delta), null, operationTask, result);
            result.recomputeStatus();
        }
    } catch (Exception ex) {
        result.recomputeStatus();
        result.recordFatalError("Couldn't delete sync token from the task.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete sync token from the task.", ex);
    }
    afterStateChangingOperation(target, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) TaskDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskDto) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class PageForgotPassword method createDynamicFormQuery.

private ObjectQuery createDynamicFormQuery(Form form) {
    DynamicFormPanel<UserType> userDynamicPanel = (DynamicFormPanel<UserType>) form.get(createComponentPath(ID_DYNAMIC_LAYOUT, ID_DYNAMIC_FORM));
    List<ItemPath> filledItems = userDynamicPanel.getChangedItems();
    PrismObject<UserType> user;
    try {
        user = userDynamicPanel.getObject();
    } catch (SchemaException e1) {
        getSession().error(getString("pageForgetPassword.message.usernotfound"));
        throw new RestartResponseException(PageForgotPassword.class);
    }
    List<EqualFilter> filters = new ArrayList<>();
    for (ItemPath path : filledItems) {
        PrismProperty property = user.findProperty(path);
        EqualFilter filter = EqualFilter.createEqual(path, property.getDefinition(), null);
        filter.setValue(property.getAnyValue().clone());
        filters.add(filter);
    }
    return ObjectQuery.createObjectQuery(AndFilter.createAnd((List) filters));
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ArrayList(java.util.ArrayList) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) DynamicFormPanel(com.evolveum.midpoint.web.component.prism.DynamicFormPanel) RestartResponseException(org.apache.wicket.RestartResponseException) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) List(java.util.List) ArrayList(java.util.ArrayList) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 24 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class WebComponentUtil method getEffectiveName.

public static <O extends ObjectType> String getEffectiveName(PrismObject<O> object, QName propertyName) {
    if (object == null) {
        return null;
    }
    PrismProperty prop = object.findProperty(propertyName);
    if (prop != null) {
        Object realValue = prop.getRealValue();
        if (prop.getDefinition().getTypeName().equals(DOMUtil.XSD_STRING)) {
            return (String) realValue;
        } else if (realValue instanceof PolyString) {
            return WebComponentUtil.getOrigStringFromPoly((PolyString) realValue);
        }
    }
    PolyString name = getValue(object, ObjectType.F_NAME, PolyString.class);
    return name != null ? name.getOrig() : null;
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 25 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class RunReportPopupPanel method createLookupTableRows.

private <O extends ObjectType> List<LookupTableRowType> createLookupTableRows(JasperReportParameterDto param, String input) {
    ItemPath label = null;
    ItemPath key = null;
    List<LookupTableRowType> rows = new ArrayList<>();
    JasperReportParameterPropertiesDto properties = param.getProperties();
    if (properties == null) {
        return null;
    }
    String pLabel = properties.getLabel();
    if (pLabel != null) {
        label = new ItemPath(pLabel);
    }
    String pKey = properties.getKey();
    if (pKey != null) {
        key = new ItemPath(pKey);
    }
    String pTargetType = properties.getTargetType();
    Class<O> targetType = null;
    if (pTargetType != null) {
        try {
            targetType = (Class<O>) Class.forName(pTargetType);
        } catch (ClassNotFoundException e) {
            error("Error while creating lookup table for input parameter: " + param.getName() + ", " + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
        //e.printStackTrace();
        }
    }
    if (label != null && targetType != null && input != null) {
        OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
        Task task = createSimpleTask(OPERATION_LOAD_RESOURCES);
        Collection<PrismObject<O>> objects;
        ObjectQuery query = QueryBuilder.queryFor(targetType, getPrismContext()).item(new QName(SchemaConstants.NS_C, pLabel)).startsWith(input).matching(new QName(SchemaConstants.NS_MATCHING_RULE, "origIgnoreCase")).maxSize(AUTO_COMPLETE_BOX_SIZE).build();
        try {
            objects = getPageBase().getModelService().searchObjects(targetType, query, SelectorOptions.createCollection(GetOperationOptions.createNoFetch()), task, result);
            for (PrismObject<O> o : objects) {
                Object realKeyValue = null;
                PrismProperty labelItem = o.findProperty(label);
                //TODO: e.g. support not only for property, but also ref, container..
                if (labelItem == null || labelItem.isEmpty()) {
                    continue;
                }
                PrismProperty keyItem = o.findProperty(key);
                if ("oid".equals(pKey)) {
                    realKeyValue = o.getOid();
                }
                if (realKeyValue == null && (keyItem == null || keyItem.isEmpty())) {
                    continue;
                }
                //TODO: support for single/multivalue value 
                if (!labelItem.isSingleValue()) {
                    continue;
                }
                Object realLabelValue = labelItem.getRealValue();
                realKeyValue = (realKeyValue == null) ? keyItem.getRealValue() : realKeyValue;
                // TODO: take definition into account
                QName typeName = labelItem.getDefinition().getTypeName();
                LookupTableRowType row = new LookupTableRowType();
                if (realKeyValue != null) {
                    row.setKey(convertObjectToPolyStringType(realKeyValue).getOrig());
                } else {
                    throw new SchemaException("Cannot create lookup table with null key for label: " + realLabelValue);
                }
                row.setLabel(convertObjectToPolyStringType(realLabelValue));
                rows.add(row);
            }
            return rows;
        } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
            error("Error while creating lookup table for input parameter: " + param.getName() + ", " + e.getClass().getSimpleName() + " (" + e.getMessage() + ")");
        //e.printStackTrace();
        }
    }
    return rows;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) JasperReportParameterPropertiesDto(com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportParameterPropertiesDto) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PrismProperty (com.evolveum.midpoint.prism.PrismProperty)41 PrismObject (com.evolveum.midpoint.prism.PrismObject)14 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 QName (javax.xml.namespace.QName)13 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 ArrayList (java.util.ArrayList)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)7 SystemException (com.evolveum.midpoint.util.exception.SystemException)7 Containerable (com.evolveum.midpoint.prism.Containerable)6 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)6 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 Test (org.testng.annotations.Test)6 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)5 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)5 Item (com.evolveum.midpoint.prism.Item)4 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)4 Task (com.evolveum.midpoint.task.api.Task)4