use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class LookupTableTest method test255AddDeleteRows.
@Test
public void test255AddDeleteRows() throws Exception {
OperationResult result = new OperationResult("test255AddDeleteRows");
LookupTableRowType rowNoId = new LookupTableRowType(prismContext);
rowNoId.setKey("key new new");
rowNoId.setValue("value new new");
rowNoId.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(new Date(99, 3, 4)));
LookupTableRowType row5 = new LookupTableRowType(prismContext);
row5.setKey("key 5");
row5.setValue("value 5");
LookupTableRowType row4 = new LookupTableRowType(prismContext);
row4.setId(4L);
List<ItemDelta<?, ?>> modifications = DeltaBuilder.deltaFor(LookupTableType.class, prismContext).item(F_ROW).add(rowNoId, row5).delete(row4).asItemDeltas();
executeAndCheckModification(modifications, result, 0, keysOf(row5));
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class LookupTableHelper method updateLookupTableData.
public void updateLookupTableData(Session session, String tableOid, Collection<? extends ItemDelta> modifications) throws SchemaException {
if (modifications.isEmpty()) {
return;
}
for (ItemDelta delta : modifications) {
if (delta.getPath().size() == 1) {
// whole row add/delete/replace
if (!(delta instanceof ContainerDelta)) {
throw new IllegalStateException("Wrong table delta sneaked into updateLookupTableData: class=" + delta.getClass() + ", path=" + delta.getPath());
}
// one "table" container modification
ContainerDelta containerDelta = (ContainerDelta) delta;
if (containerDelta.getValuesToDelete() != null) {
// todo do 'bulk' delete like delete from ... where oid=? and id in (...)
for (PrismContainerValue<LookupTableRowType> value : (Collection<PrismContainerValue>) containerDelta.getValuesToDelete()) {
if (value.getId() != null) {
deleteRowById(session, tableOid, value.getId());
} else if (value.asContainerable().getKey() != null) {
deleteRowByKey(session, tableOid, value.asContainerable().getKey());
} else {
// ignore (or throw an exception?)
}
}
}
if (containerDelta.getValuesToAdd() != null) {
int currentId = generalHelper.findLastIdInRepo(session, tableOid, "get.lookupTableLastId") + 1;
addLookupTableRows(session, tableOid, containerDelta.getValuesToAdd(), currentId, true);
}
if (containerDelta.getValuesToReplace() != null) {
deleteLookupTableRows(session, tableOid);
addLookupTableRows(session, tableOid, containerDelta.getValuesToReplace(), 1, false);
}
} else if (delta.getPath().size() == 3) {
// row segment modification (structure is already checked)
List<ItemPathSegment> segments = delta.getPath().getSegments();
Long rowId = ((IdItemPathSegment) segments.get(1)).getId();
QName name = ((NameItemPathSegment) segments.get(2)).getName();
RLookupTableRow row = (RLookupTableRow) session.get(RLookupTableRow.class, new RContainerId(RUtil.toInteger(rowId), tableOid));
LookupTableRowType rowType = row.toJAXB();
delta.setParentPath(ItemPath.EMPTY_PATH);
delta.applyTo(rowType.asPrismContainerValue());
if (!QNameUtil.match(name, LookupTableRowType.F_LAST_CHANGE_TIMESTAMP)) {
// in order to get filled in via toRepo call below
rowType.setLastChangeTimestamp(null);
}
RLookupTableRow rowUpdated = RLookupTableRow.toRepo(tableOid, rowType);
session.merge(rowUpdated);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class RLookupTable method copyFromJAXB.
public static void copyFromJAXB(LookupTableType jaxb, RLookupTable repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException, SchemaException {
RObject.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
List<LookupTableRowType> rows = jaxb.getRow();
if (!rows.isEmpty()) {
repo.setRows(new HashSet<>());
for (LookupTableRowType row : rows) {
RLookupTableRow rRow = RLookupTableRow.toRepo(repo, row);
rRow.setTransient(generatorResult.isTransient(row.asPrismContainerValue()));
repo.getRows().add(rRow);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class TestEditSchema method test164LookupLanguagesDeleteRowFullId.
@Test
public void test164LookupLanguagesDeleteRowFullId() throws Exception {
final String TEST_NAME = "test164LookupLanguagesDeleteRowFullId";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
LookupTableRowType row = new LookupTableRowType();
row.setKey("en_US");
row.setValue("en");
row.setLabel(PrismTestUtil.createPolyStringType("English (US)"));
row.setId(1L);
ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationDeleteContainer(LookupTableType.class, LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
IntegrationTestTools.display("Languages", lookup);
assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());
PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
assertNotNull("Table container missing", tableContainer);
assertEquals("Unexpected table container size", 5, tableContainer.size());
assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");
assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");
assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");
assertLookupRow(tableContainer, "gi_HU", "gi", "Humbug");
assertSteadyResources();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType in project midpoint by Evolveum.
the class TestEditSchema method test156LookupLanguagesAddRowExistingKey.
@Test
public void test156LookupLanguagesAddRowExistingKey() throws Exception {
final String TEST_NAME = "test156LookupLanguagesAddRowExistingKey";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
LookupTableRowType row = new LookupTableRowType();
row.setKey("gi_HU");
row.setValue("gi");
row.setLabel(PrismTestUtil.createPolyStringType("Humbug"));
ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationAddContainer(LookupTableType.class, LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);
// WHEN
TestUtil.displayWhen(TEST_NAME);
boolean exception = false;
try {
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
} catch (ObjectAlreadyExistsException ex) {
exception = true;
}
// as per description in https://wiki.evolveum.com/display/midPoint/Development+with+LookupTable
AssertJUnit.assertFalse(exception);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
result = task.getResult();
PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
IntegrationTestTools.display("Languages", lookup);
assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());
PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
assertNotNull("Table container missing", tableContainer);
assertEquals("Unexpected table container size", 7, tableContainer.size());
assertLookupRow(tableContainer, "en_US", "en", "English (US)");
assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
assertLookupRow(tableContainer, "sk_SK", "sk", "Slovak");
assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");
assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");
assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");
assertLookupRow(tableContainer, "gi_HU", "gi", "Humbug");
assertSteadyResources();
}
Aggregations