Search in sources :

Example 21 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class ClassDefinitionParser method parseMethod.

private JpaLinkDefinition parseMethod(Method method) {
    // non-null if return type is Set<X>, null if it's X
    CollectionSpecification collectionSpecification;
    // X in return type, which is either X or Set<X>
    Type returnedContentType;
    if (Set.class.isAssignableFrom(method.getReturnType())) {
        // e.g. Set<RObject> or Set<String> or Set<REmbeddedReference<RFocus>>
        Type returnType = method.getGenericReturnType();
        if (!(returnType instanceof ParameterizedType)) {
            throw new IllegalStateException("Method " + method + " returns a non-parameterized collection");
        }
        returnedContentType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
        collectionSpecification = new CollectionSpecification();
    } else {
        returnedContentType = method.getReturnType();
        collectionSpecification = null;
    }
    ItemPath itemPath = getJaxbName(method);
    String jpaName = getJpaName(method);
    Class<? extends RObject> jpaClass = getClass(returnedContentType);
    // sanity check
    if (Set.class.isAssignableFrom(jpaClass)) {
        throw new IllegalStateException("Collection within collection is not supported: method=" + method);
    }
    JpaLinkDefinition<? extends JpaDataNodeDefinition> linkDefinition;
    Any any = method.getAnnotation(Any.class);
    if (any != null) {
        JpaAnyContainerDefinition targetDefinition = new JpaAnyContainerDefinition(jpaClass);
        ItemName jaxbNameForAny = new ItemName(any.jaxbNameNamespace(), any.jaxbNameLocalPart());
        linkDefinition = new JpaLinkDefinition<>(jaxbNameForAny, jpaName, collectionSpecification, false, targetDefinition);
    } else if (ObjectReference.class.isAssignableFrom(jpaClass)) {
        boolean embedded = method.isAnnotationPresent(Embedded.class);
        // computing referenced entity type from returned content type like RObjectReference<RFocus> or REmbeddedReference<RRole>
        Class referencedJpaClass;
        if (returnedContentType instanceof ParameterizedType) {
            referencedJpaClass = getClass(((ParameterizedType) returnedContentType).getActualTypeArguments()[0]);
        } else {
            referencedJpaClass = RObject.class;
        }
        JpaReferenceDefinition targetDefinition = new JpaReferenceDefinition(jpaClass, referencedJpaClass);
        linkDefinition = new JpaLinkDefinition<>(itemPath, jpaName, collectionSpecification, embedded, targetDefinition);
    } else if (isEntity(jpaClass)) {
        JpaEntityDefinition content = parseClass(jpaClass);
        boolean embedded = method.isAnnotationPresent(Embedded.class) || jpaClass.isAnnotationPresent(Embeddable.class);
        linkDefinition = new JpaLinkDefinition<>(itemPath, jpaName, collectionSpecification, embedded, content);
    } else {
        boolean lob = method.isAnnotationPresent(Lob.class);
        boolean enumerated = method.isAnnotationPresent(Enumerated.class);
        // todo implement also lookup for @Table indexes
        boolean indexed = method.isAnnotationPresent(Index.class);
        boolean count = method.isAnnotationPresent(Count.class);
        Class jaxbClass = getJaxbClass(method, jpaClass);
        if (method.isAnnotationPresent(IdQueryProperty.class)) {
            if (collectionSpecification != null) {
                throw new IllegalStateException("ID property is not allowed to be multivalued; for method " + method);
            }
            itemPath = ItemPath.create(IdentifierPathSegment.QNAME);
        } else if (method.isAnnotationPresent(OwnerIdGetter.class)) {
            if (collectionSpecification != null) {
                throw new IllegalStateException("Owner ID property is not allowed to be multivalued; for method " + method);
            }
            itemPath = ItemPath.create(ParentPathSegment.QNAME, IdentifierPathSegment.QNAME);
        }
        boolean neverNull = method.isAnnotationPresent(NeverNull.class);
        JpaPropertyDefinition<?> propertyDefinition = new JpaPropertyDefinition<>(jpaClass, jaxbClass, lob, enumerated, indexed, count, neverNull);
        // Note that properties are considered to be embedded
        linkDefinition = new JpaLinkDefinition<>(itemPath, jpaName, collectionSpecification, true, propertyDefinition);
    }
    return linkDefinition;
}
Also used : RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ObjectReference(com.evolveum.midpoint.repo.sql.data.common.ObjectReference) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) ItemName(com.evolveum.midpoint.prism.path.ItemName) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 22 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class TestOperationPerf method populateUserExtension.

private void populateUserExtension(PrismObject<UserType> user, int numberOfProperties) throws SchemaException {
    PrismContainer<?> extension = user.getExtension();
    if (extension == null) {
        extension = user.createExtension();
    }
    for (int i = 0; i < numberOfProperties; i++) {
        String propName = String.format(USER_EXTENSION_PROPERTY_NAME_FORMAT, i);
        PrismProperty<String> prop = extension.findOrCreateProperty(new ItemName(USER_EXTENSION_NS, propName));
        prop.setRealValue("val " + i);
    }
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 23 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class TestParseLookupTable method assertPropertyValue.

public static void assertPropertyValue(PrismContainer<?> container, String propName, Object propValue) {
    ItemName propQName = new ItemName(SchemaConstantsGenerated.NS_COMMON, propName);
    PrismAsserts.assertPropertyValue(container, propQName, propValue);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 24 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class TestParseObjectTemplate method assertPropertyDefinition.

private void assertPropertyDefinition(PrismContainer<?> container, String propName, QName xsdType, int minOccurs, int maxOccurs) {
    ItemName propQName = new ItemName(SchemaConstantsGenerated.NS_COMMON, propName);
    PrismAsserts.assertPropertyDefinition(container, propQName, xsdType, minOccurs, maxOccurs);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 25 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class TestParseTask method assertPropertyDefinition.

private void assertPropertyDefinition(PrismContainer<?> container, String propName, QName xsdType, int minOccurs, int maxOccurs) {
    ItemName propQName = new ItemName(SchemaConstantsGenerated.NS_COMMON, propName);
    PrismAsserts.assertPropertyDefinition(container, propQName, xsdType, minOccurs, maxOccurs);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Aggregations

ItemName (com.evolveum.midpoint.prism.path.ItemName)89 Test (org.testng.annotations.Test)24 QName (javax.xml.namespace.QName)19 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 NotNull (org.jetbrains.annotations.NotNull)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 Task (com.evolveum.midpoint.task.api.Task)6 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)5 MUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser)5 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)5 Element (org.w3c.dom.Element)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)4 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)4 ArrayList (java.util.ArrayList)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3