Search in sources :

Example 96 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class BeanUnmarshaller method unmarshalEnumFromPrimitive.

private <T> T unmarshalEnumFromPrimitive(PrimitiveXNode prim, Class<T> beanClass, ParsingContext pc) throws SchemaException {
    String primValue = (String) prim.getParsedValue(DOMUtil.XSD_STRING, String.class);
    primValue = StringUtils.trim(primValue);
    if (StringUtils.isEmpty(primValue)) {
        return null;
    }
    String javaEnumString = inspector.findEnumFieldName(beanClass, primValue);
    if (javaEnumString == null) {
        for (Field field : beanClass.getDeclaredFields()) {
            if (field.getName().equals(primValue)) {
                javaEnumString = field.getName();
                break;
            }
        }
    }
    if (javaEnumString == null) {
        throw new SchemaException("Cannot find enum value for string '" + primValue + "' in " + beanClass);
    }
    @SuppressWarnings("unchecked") T bean = (T) Enum.valueOf((Class<Enum>) beanClass, javaEnumString);
    return bean;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 97 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class ItemInfo method augmentWithClass.

private static <ID extends ItemDefinition> ID augmentWithClass(ID definition, Class<ID> definitionClass, SchemaRegistry schemaRegistry, Class<?> clazz) throws SchemaException {
    if (clazz == null) {
        return definition;
    }
    if (definition instanceof PrismContainerDefinition && clazz.equals(((PrismContainerDefinition) definition).getCompileTimeClass())) {
        return definition;
    }
    QName typeNameFromClass = schemaRegistry.determineTypeForClass(clazz);
    if (typeNameFromClass == null) {
        throw new SchemaException("Unknown class " + clazz.getName());
    }
    if (definition != null && definition.getTypeName().equals(typeNameFromClass)) {
        return definition;
    }
    @SuppressWarnings("unchecked") List<ID> defFromClass = schemaRegistry.findItemDefinitionsByCompileTimeClass((Class) clazz, (Class) definitionClass);
    if (defFromClass.size() != 1) {
        return definition;
    } else {
        return schemaRegistry.selectMoreSpecific(definition, defFromClass.get(0));
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName)

Example 98 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class JaxbDomHack method parseRawElement.

/**
	 * This is used in a form of "fromAny" to parse elements from a JAXB getAny method to prism. 
	 */
public <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> Item<IV, ID> parseRawElement(Object element, PrismContainerDefinition<C> definition) throws SchemaException {
    Validate.notNull(definition, "Attempt to parse raw element in a container without definition");
    QName elementName = JAXBUtil.getElementQName(element);
    ItemDefinition itemDefinition = definition.findItemDefinition(elementName);
    if (itemDefinition == null) {
        itemDefinition = locateItemDefinition(definition, elementName, element);
        if (itemDefinition == null) {
            throw new SchemaException("No definition for item " + elementName);
        }
    }
    PrismContext prismContext = definition.getPrismContext();
    Item<IV, ID> subItem;
    if (element instanceof Element) {
        // DOM Element
        subItem = prismContext.parserFor((Element) element).name(elementName).definition(itemDefinition).parseItem();
    } else if (element instanceof JAXBElement<?>) {
        // JAXB Element
        JAXBElement<?> jaxbElement = (JAXBElement<?>) element;
        Object jaxbBean = jaxbElement.getValue();
        if (itemDefinition == null) {
            throw new SchemaException("No definition for item " + elementName + " in container " + definition + " (parsed from raw element)", elementName);
        }
        if (itemDefinition instanceof PrismPropertyDefinition<?>) {
            // property
            PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
            property.setRealValue(jaxbBean);
            subItem = (Item<IV, ID>) property;
        } else if (itemDefinition instanceof PrismContainerDefinition<?>) {
            if (jaxbBean instanceof Containerable) {
                PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
                PrismContainerValue subValue = ((Containerable) jaxbBean).asPrismContainerValue();
                container.add(subValue);
                subItem = (Item<IV, ID>) container;
            } else {
                throw new IllegalArgumentException("Unsupported JAXB bean " + jaxbBean.getClass());
            }
        } else if (itemDefinition instanceof PrismReferenceDefinition) {
            // TODO
            if (jaxbBean instanceof Referencable) {
                PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
                PrismReferenceValue refValue = ((Referencable) jaxbBean).asReferenceValue();
                reference.merge(refValue);
                subItem = (Item<IV, ID>) reference;
            } else {
                throw new IllegalArgumentException("Unsupported JAXB bean" + jaxbBean);
            }
        } else {
            throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
        }
    } else {
        throw new IllegalArgumentException("Unsupported element type " + element.getClass());
    }
    return subItem;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBElement(javax.xml.bind.JAXBElement)

Example 99 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class PrismUnmarshaller method setReferenceObject.

private void setReferenceObject(PrismReferenceValue refVal, PrismObject<Objectable> object) throws SchemaException {
    refVal.setObject(object);
    if (object.getOid() != null) {
        if (refVal.getOid() == null) {
            refVal.setOid(object.getOid());
        } else {
            if (!refVal.getOid().equals(object.getOid())) {
                throw new SchemaException("OID in reference (" + refVal.getOid() + ") does not match OID in composite object (" + object.getOid() + ")");
            }
        }
    }
    QName objectTypeName = object.getDefinition().getTypeName();
    if (refVal.getTargetType() == null) {
        refVal.setTargetType(objectTypeName);
    } else {
        if (!refVal.getTargetType().equals(objectTypeName)) {
            throw new SchemaException("Target type in reference (" + refVal.getTargetType() + ") does not match type in composite object (" + objectTypeName + ")");
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName)

Example 100 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class PrismUnmarshaller method parseReferenceValueAsReference.

private PrismReferenceValue parseReferenceValueAsReference(@NotNull XNode xnode, @NotNull PrismReferenceDefinition definition, @NotNull ParsingContext pc, boolean allowMissingRefTypesOverride) throws SchemaException {
    if (!(xnode instanceof MapXNode)) {
        throw new IllegalArgumentException("Cannot parse reference from " + xnode);
    }
    MapXNode map = (MapXNode) xnode;
    String oid = map.getParsedPrimitiveValue(XNode.KEY_REFERENCE_OID, DOMUtil.XSD_STRING);
    PrismReferenceValue refVal = new PrismReferenceValue(oid);
    QName type = map.getParsedPrimitiveValue(XNode.KEY_REFERENCE_TYPE, DOMUtil.XSD_QNAME);
    if (type == null) {
        if (!pc.isAllowMissingRefTypes() && !allowMissingRefTypesOverride) {
            type = definition.getTargetTypeName();
            if (type == null) {
                throw new SchemaException("Target type in reference " + definition.getName() + " not specified in reference nor in the schema");
            }
        }
    } else {
        if (QNameUtil.noNamespace(type)) {
            type = getSchemaRegistry().resolveUnqualifiedTypeName(type);
        }
        QName defTargetType = definition.getTargetTypeName();
        if (defTargetType != null) {
            if (!(prismContext.getSchemaRegistry().isAssignableFrom(defTargetType, type))) {
                throw new SchemaException("Target type specified in reference " + definition.getName() + " (" + type + ") does not match target type in schema (" + defTargetType + ")");
            }
        }
    }
    PrismObjectDefinition<Objectable> objectDefinition = null;
    if (type != null) {
        objectDefinition = getSchemaRegistry().findObjectDefinitionByType(type);
        if (objectDefinition == null) {
            throw new SchemaException("No definition for type " + type + " in reference");
        }
        refVal.setTargetType(type);
    }
    QName relationAttribute = map.getParsedPrimitiveValue(XNode.KEY_REFERENCE_RELATION, DOMUtil.XSD_QNAME);
    refVal.setRelation(relationAttribute);
    refVal.setDescription(map.getParsedPrimitiveValue(XNode.KEY_REFERENCE_DESCRIPTION, DOMUtil.XSD_STRING));
    refVal.setFilter(parseFilter(map.get(XNode.KEY_REFERENCE_FILTER)));
    String resolutionTimeString = map.getParsedPrimitiveValue(XNode.KEY_REFERENCE_RESOLUTION_TIME, DOMUtil.XSD_STRING);
    if (resolutionTimeString != null) {
        EvaluationTimeType resolutionTime = EvaluationTimeType.fromValue(resolutionTimeString);
        refVal.setResolutionTime(resolutionTime);
    }
    XNode xnodeForTargetName = map.get(XNode.KEY_REFERENCE_TARGET_NAME);
    if (xnodeForTargetName != null) {
        PolyStringType targetName = getBeanUnmarshaller().unmarshal(xnodeForTargetName, PolyStringType.class, pc);
        refVal.setTargetName(targetName);
    }
    XNode xrefObject = map.get(XNode.KEY_REFERENCE_OBJECT);
    if (xrefObject != null) {
        if (!(xrefObject instanceof MapXNode)) {
            throw new SchemaException("Cannot parse object from " + xrefObject);
        }
        if (type == null) {
            throw new SchemaException("Cannot parse object from " + xrefObject + " without knowing its type");
        }
        PrismObject<Objectable> object = parseObject((MapXNode) xrefObject, objectDefinition, pc);
        setReferenceObject(refVal, object);
    }
    return refVal;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) EvaluationTimeType(com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType)

Aggregations

SchemaException (com.evolveum.midpoint.util.exception.SchemaException)576 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)235 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)214 QName (javax.xml.namespace.QName)132 SystemException (com.evolveum.midpoint.util.exception.SystemException)113 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)100 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)100 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)92 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)89 Task (com.evolveum.midpoint.task.api.Task)87 PrismObject (com.evolveum.midpoint.prism.PrismObject)86 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)69 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)68 ArrayList (java.util.ArrayList)67 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)59 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)49 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)47 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)46 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)34 Test (org.testng.annotations.Test)34