Search in sources :

Example 11 with LookupTableType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType in project midpoint by Evolveum.

the class TestEditSchema method test102LookupLanguagesGetExclude.

@Test
public void test102LookupLanguagesGetExclude() throws Exception {
    final String TEST_NAME = "test102LookupLanguagesGetExclude";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(LookupTableType.F_ROW, GetOperationOptions.createRetrieve(RetrieveOption.EXCLUDE));
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    PrismObject<LookupTableType> lookup = modelService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, options, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    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);
    assertNull("Table container sneaked in", tableContainer);
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) 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 12 with LookupTableType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType in project midpoint by Evolveum.

the class TestEditSchema method test182LookupLanguagesReimport.

@Test
public void test182LookupLanguagesReimport() throws Exception {
    final String TEST_NAME = "test182LookupLanguagesReimport";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ImportOptionsType options = new ImportOptionsType();
    options.setOverwrite(true);
    options.setKeepOid(true);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.importObjectsFromFile(LOOKUP_LANGUAGES_FILE, options, 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", "Languages", lookup.asObjectable().getName().getOrig());
    checkLookupResult(lookup, new String[] { "en_US", "en", "English (US)" }, new String[] { "en_PR", "en", "English (pirate)" }, new String[] { "sk_SK", "sk", "Slovak" }, new String[] { "tr_TR", "tr", "Turkish" });
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ImportOptionsType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test)

Example 13 with LookupTableType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType in project midpoint by Evolveum.

the class TestEditSchema method test154LookupLanguagesAddRowKeyValue.

@Test
public void test154LookupLanguagesAddRowKeyValue() throws Exception {
    final String TEST_NAME = "test154LookupLanguagesAddRowKeyValue";
    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");
    ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationAddContainer(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", 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", null);
    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 14 with LookupTableType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType in project midpoint by Evolveum.

the class LookupTableHelper method updateLoadedLookupTable.

public <T extends ObjectType> void updateLoadedLookupTable(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
    if (!SelectorOptions.hasToLoadPath(LookupTableType.F_ROW, options)) {
        return;
    }
    LOGGER.debug("Loading lookup table data.");
    GetOperationOptions getOption = findLookupTableGetOption(options);
    RelationalValueSearchQuery queryDef = getOption == null ? null : getOption.getRelationalValueSearchQuery();
    Criteria criteria = setupLookupTableRowsQuery(session, queryDef, object.getOid());
    if (queryDef != null && queryDef.getPaging() != null) {
        ObjectPaging paging = queryDef.getPaging();
        if (paging.getOffset() != null) {
            criteria.setFirstResult(paging.getOffset());
        }
        if (paging.getMaxSize() != null) {
            criteria.setMaxResults(paging.getMaxSize());
        }
        ItemPath orderByPath = paging.getOrderBy();
        if (paging.getDirection() != null && orderByPath != null && !orderByPath.isEmpty()) {
            if (orderByPath.size() > 1 || !(orderByPath.first() instanceof NameItemPathSegment) && !(orderByPath.first() instanceof IdentifierPathSegment)) {
                throw new SchemaException("OrderBy has to consist of just one naming or identifier segment");
            }
            ItemPathSegment first = orderByPath.first();
            String orderBy = first instanceof NameItemPathSegment ? ((NameItemPathSegment) first).getName().getLocalPart() : RLookupTableRow.ID_COLUMN_NAME;
            switch(paging.getDirection()) {
                case ASCENDING:
                    criteria.addOrder(Order.asc(orderBy));
                    break;
                case DESCENDING:
                    criteria.addOrder(Order.desc(orderBy));
                    break;
            }
        }
    }
    List<RLookupTableRow> rows = criteria.list();
    if (rows == null || rows.isEmpty()) {
        return;
    }
    LookupTableType lookup = (LookupTableType) object.asObjectable();
    List<LookupTableRowType> jaxbRows = lookup.getRow();
    for (RLookupTableRow row : rows) {
        LookupTableRowType jaxbRow = row.toJAXB();
        jaxbRows.add(jaxbRow);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RelationalValueSearchQuery(com.evolveum.midpoint.schema.RelationalValueSearchQuery) Criteria(org.hibernate.Criteria) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)

Example 15 with LookupTableType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType in project midpoint by Evolveum.

the class LookupTableTest method test105AddTableNonOverwriteExisting.

@Test(expectedExceptions = ObjectAlreadyExistsException.class)
public void test105AddTableNonOverwriteExisting() throws Exception {
    PrismObject<LookupTableType> table = prismContext.parseObject(new File(TEST_DIR, "table-0.xml"));
    OperationResult result = new OperationResult("test105AddTableNonOverwriteExisting");
    repositoryService.addObject(table, null, result);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test)

Aggregations

LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)33 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)27 Test (org.testng.annotations.Test)27 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)26 Task (com.evolveum.midpoint.task.api.Task)23 LookupTableRowType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)17 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)10 RelationalValueSearchQuery (com.evolveum.midpoint.schema.RelationalValueSearchQuery)9 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)3 File (java.io.File)3 RLookupTableRow (com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow)2 PropertyModel (org.apache.wicket.model.PropertyModel)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)1 RepoModifyOptions (com.evolveum.midpoint.repo.api.RepoModifyOptions)1 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)1