Search in sources :

Example 26 with LookupTableRowType

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));
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) Test(org.testng.annotations.Test)

Example 27 with LookupTableRowType

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);
        }
    }
}
Also used : RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) QName(javax.xml.namespace.QName) Collection(java.util.Collection) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ArrayList(java.util.ArrayList) List(java.util.List) RContainerId(com.evolveum.midpoint.repo.sql.data.common.id.RContainerId) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)

Example 28 with LookupTableRowType

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);
        }
    }
}
Also used : RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)

Example 29 with LookupTableRowType

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test)

Example 30 with LookupTableRowType

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test)

Aggregations

LookupTableRowType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)34 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)23 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)23 Test (org.testng.annotations.Test)22 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 Task (com.evolveum.midpoint.task.api.Task)14 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 RLookupTableRow (com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow)4 ArrayList (java.util.ArrayList)3 RelationalValueSearchQuery (com.evolveum.midpoint.schema.RelationalValueSearchQuery)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 QName (javax.xml.namespace.QName)2 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)1