Search in sources :

Example 1 with RAnyConverter

use of com.evolveum.midpoint.repo.sql.data.common.any.RAnyConverter in project midpoint by Evolveum.

the class RObject method copyFromJAXB.

public static void copyFromJAXB(PrismContainerValue containerValue, RObject repo, RepositoryContext repositoryContext, RObjectExtensionType ownerType) throws DtoTranslationException {
    RAnyConverter converter = new RAnyConverter(repositoryContext.prismContext);
    Set<RAnyValue> values = new HashSet<RAnyValue>();
    try {
        List<Item<?, ?>> items = containerValue.getItems();
        //TODO: is this ehought??should we try items without definitions??
        if (items != null) {
            for (Item item : items) {
                values.addAll(converter.convertToRValue(item, false));
            }
        }
    } catch (Exception ex) {
        throw new DtoTranslationException(ex.getMessage(), ex);
    }
    for (RAnyValue value : values) {
        ROExtValue ex = (ROExtValue) value;
        ex.setOwner(repo);
        ex.setOwnerType(ownerType);
        if (value instanceof ROExtDate) {
            repo.getDates().add(value);
        } else if (value instanceof ROExtLong) {
            repo.getLongs().add(value);
        } else if (value instanceof ROExtReference) {
            repo.getReferences().add(value);
        } else if (value instanceof ROExtString) {
            repo.getStrings().add(value);
        } else if (value instanceof ROExtPolyString) {
            repo.getPolys().add(value);
        } else if (value instanceof ROExtBoolean) {
            repo.getBooleans().add(value);
        }
    }
    repo.setStringsCount((short) repo.getStrings().size());
    repo.setDatesCount((short) repo.getDates().size());
    repo.setPolysCount((short) repo.getPolys().size());
    repo.setReferencesCount((short) repo.getReferences().size());
    repo.setLongsCount((short) repo.getLongs().size());
    repo.setBooleansCount((short) repo.getBooleans().size());
}
Also used : ROExtLong(com.evolveum.midpoint.repo.sql.data.common.any.ROExtLong) ROExtString(com.evolveum.midpoint.repo.sql.data.common.any.ROExtString) ROExtReference(com.evolveum.midpoint.repo.sql.data.common.any.ROExtReference) ROExtDate(com.evolveum.midpoint.repo.sql.data.common.any.ROExtDate) RAnyConverter(com.evolveum.midpoint.repo.sql.data.common.any.RAnyConverter) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) ROExtValue(com.evolveum.midpoint.repo.sql.data.common.any.ROExtValue) Item(com.evolveum.midpoint.prism.Item) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) ROExtBoolean(com.evolveum.midpoint.repo.sql.data.common.any.ROExtBoolean) ROExtPolyString(com.evolveum.midpoint.repo.sql.data.common.any.ROExtPolyString) RAnyValue(com.evolveum.midpoint.repo.sql.data.common.any.RAnyValue) HashSet(java.util.HashSet)

Example 2 with RAnyConverter

use of com.evolveum.midpoint.repo.sql.data.common.any.RAnyConverter in project midpoint by Evolveum.

the class RAnyConverterStaticTest method testExtensionEnum.

@Test
public void testExtensionEnum() throws Exception {
    Session session = getFactory().openSession();
    QName valueName = new QName(NS_P, "enumType");
    ItemDefinition def = getDefinition(GenericObjectType.class, ItemPath.create(ObjectType.F_EXTENSION, valueName));
    AssertJUnit.assertNotNull(def);
    PrismProperty item = (PrismProperty) def.instantiate();
    item.setRealValue(BeforeAfterType.AFTER);
    RAnyConverter converter = new RAnyConverter(prismContext, extItemDictionary);
    Set<RAnyValue<?>> values;
    try {
        values = converter.convertToRValue(item, false, RObjectExtensionType.EXTENSION);
        AssertJUnit.fail("Should have throw serialization related exception after creating ext item");
    } catch (RestartOperationRequestedException ex) {
        // this is a new way
        System.out.println("Got expected exception: " + ex);
    } catch (DtoTranslationException ex) {
        // this was an old way
        AssertJUnit.assertEquals("Wrong exception class", RestartOperationRequestedException.class, ex.getCause().getClass());
    }
    values = converter.convertToRValue(item, false, RObjectExtensionType.EXTENSION);
    AssertJUnit.assertEquals("Expected only one enum value, but was " + values.size(), 1, values.size());
    RAnyValue value = values.iterator().next();
    AssertJUnit.assertEquals("after", value.getValue());
    session.close();
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) QName(javax.xml.namespace.QName) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) RAnyConverter(com.evolveum.midpoint.repo.sql.data.common.any.RAnyConverter) RAnyValue(com.evolveum.midpoint.repo.sql.data.common.any.RAnyValue) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

RAnyConverter (com.evolveum.midpoint.repo.sql.data.common.any.RAnyConverter)2 RAnyValue (com.evolveum.midpoint.repo.sql.data.common.any.RAnyValue)2 DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)2 Item (com.evolveum.midpoint.prism.Item)1 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1 ROExtBoolean (com.evolveum.midpoint.repo.sql.data.common.any.ROExtBoolean)1 ROExtDate (com.evolveum.midpoint.repo.sql.data.common.any.ROExtDate)1 ROExtLong (com.evolveum.midpoint.repo.sql.data.common.any.ROExtLong)1 ROExtPolyString (com.evolveum.midpoint.repo.sql.data.common.any.ROExtPolyString)1 ROExtReference (com.evolveum.midpoint.repo.sql.data.common.any.ROExtReference)1 ROExtString (com.evolveum.midpoint.repo.sql.data.common.any.ROExtString)1 ROExtValue (com.evolveum.midpoint.repo.sql.data.common.any.ROExtValue)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 Session (org.hibernate.Session)1 Test (org.testng.annotations.Test)1