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());
}
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();
}
Aggregations