Search in sources :

Example 16 with ILookupRow

use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.

the class IncrementalTreeBuilderTest method testCreatePaths_NonEmpty.

@Test
public void testCreatePaths_NonEmpty() {
    @SuppressWarnings("unchecked") IKeyLookupProvider<Long> mockProvider = Mockito.mock(IKeyLookupProvider.class);
    ITree tree = createTestTree();
    IncrementalTreeBuilder<Long> builder = new IncrementalTreeBuilder<Long>(mockProvider);
    ArrayList<ILookupRow<Long>> rows = new ArrayList<>();
    rows.add(new LookupRow<Long>(1L, ""));
    rows.add(new LookupRow<Long>(2L, "").withParentKey(1L));
    List<List<ILookupRow<Long>>> paths = builder.createPaths(rows, tree);
    assertTrue(paths.size() == 2);
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ArrayList(java.util.ArrayList) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 17 with ILookupRow

use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.

the class IncrementalTreeBuilderTest method testCreatePaths_NullKeyLookupRow.

@Test
public void testCreatePaths_NullKeyLookupRow() {
    final Map<Long, ILookupRow<Long>> lookupRowsMap = new HashMap<>();
    lookupRowsMap.put(1L, new LookupRow<Long>(1L, "A"));
    lookupRowsMap.put(2L, new LookupRow<Long>(2L, "A-B").withParentKey(1L));
    lookupRowsMap.put(null, new LookupRow<Long>(null, "(none)"));
    Collection<ILookupRow<Long>> rows = lookupRowsMap.values();
    IKeyLookupProvider<Long> provider = new IKeyLookupProvider<Long>() {

        @Override
        public ILookupRow<Long> getLookupRow(Long key) {
            return lookupRowsMap.get(key);
        }
    };
    ITree tree = createTestTree();
    IncrementalTreeBuilder<Long> builder = new IncrementalTreeBuilder<Long>(provider);
    List<List<ILookupRow<Long>>> paths = builder.createPaths(rows, tree);
    assertEquals(3, paths.size());
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) HashMap(java.util.HashMap) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 18 with ILookupRow

use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.

the class SmartFieldLookupTest method testTextLookupExceptions_InBackground.

@SuppressWarnings("unchecked")
@Test
public void testTextLookupExceptions_InBackground() throws InterruptedException {
    m_field.setLookupCall(new TestLookupCall());
    final String errorText = "lookup error";
    when(m_mock_service.getDataByText(any(ILookupCall.class))).thenThrow(new PlatformException(errorText));
    final IBlockingCondition bc = Jobs.newBlockingCondition(true);
    ILookupRowFetchedCallback callback = new ILookupRowFetchedCallback<Long>() {

        @Override
        public void onSuccess(List<? extends ILookupRow<Long>> rows) {
            Assert.fail("no exception thrown");
            bc.setBlocking(false);
        }

        @Override
        public void onFailure(RuntimeException exception) {
            assertTrue(exception instanceof PlatformException);
            assertEquals(errorText, exception.getMessage());
            bc.setBlocking(false);
        }
    };
    m_field.callTextLookupInBackground("", 10, callback);
    bc.waitFor();
}
Also used : TestLookupCall(org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ILookupRowFetchedCallback(org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback) ArrayList(java.util.ArrayList) List(java.util.List) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) IBlockingCondition(org.eclipse.scout.rt.platform.job.IBlockingCondition) Test(org.junit.Test)

Example 19 with ILookupRow

use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.

the class BatchLookupTest method setUp.

@Before
public void setUp() throws Exception {
    Answer answer = new Answer<List<ILookupRow<Object>>>() {

        @Override
        public List<ILookupRow<Object>> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            ILookupCall<?> call = (ILookupCall<?>) args[0];
            return createCallResult(call);
        }
    };
    Mockito.doAnswer(answer).when(m_lookupService).getDataByKey(Mockito.<ILookupCall<Object>>any());
    Mockito.doAnswer(answer).when(m_lookupService).getDataByAll(Mockito.<ILookupCall<Object>>any());
    Mockito.doAnswer(answer).when(m_lookupService).getDataByText(Mockito.<ILookupCall<Object>>any());
    Mockito.doAnswer(answer).when(m_lookupService).getDataByRec(Mockito.<ILookupCall<Object>>any());
}
Also used : Answer(org.mockito.stubbing.Answer) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) Before(org.junit.Before)

Example 20 with ILookupRow

use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.

the class BatchLookupServiceClientProxy method getBatchDataByKey.

@Override
public List<List<ILookupRow<?>>> getBatchDataByKey(BatchLookupCall batch) {
    List<ILookupCall<?>> allCalls = batch.getCallBatch();
    List<ILookupCall<?>> cleanCalls = new ArrayList<ILookupCall<?>>(allCalls.size());
    // set calls with key==null to null
    for (ILookupCall<?> call : allCalls) {
        if (call != null && call.getKey() == null) {
            cleanCalls.add(null);
        } else {
            cleanCalls.add(call);
        }
    }
    BatchSplit split = new BatchSplit(cleanCalls);
    if (split.getLocalCallCount() > 0) {
        BatchLookupResultCache cache = new BatchLookupResultCache();
        List<ILookupCall<?>> calls = split.getLocalCalls();
        List<List<ILookupRow<?>>> result = new ArrayList<List<ILookupRow<?>>>();
        for (ILookupCall<?> call : calls) {
            result.add(cache.getDataByKey(call));
        }
        split.setLocalResults(result);
    }
    if (split.getRemoteCallCount() > 0) {
        BatchLookupNormalizer normalizer = new BatchLookupNormalizer();
        List<ILookupCall<?>> normCallArray = normalizer.normalizeCalls(split.getRemoteCalls());
        List<List<ILookupRow<?>>> normResultArray = getTargetService().getBatchDataByKey(new BatchLookupCall(normCallArray));
        List<List<ILookupRow<?>>> resultArray = normalizer.denormalizeResults(normResultArray);
        split.setRemoteResults(resultArray);
    }
    List<List<ILookupRow<?>>> results = split.getCombinedResults();
    // set null results to empty list
    for (int i = 0; i < results.size(); i++) {
        if (results.get(i) == null) {
            List<ILookupRow<?>> emptyList = CollectionUtility.emptyArrayList();
            results.set(i, emptyList);
        }
    }
    return results;
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ArrayList(java.util.ArrayList) BatchLookupResultCache(org.eclipse.scout.rt.shared.services.lookup.BatchLookupResultCache) BatchLookupCall(org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall) List(java.util.List) ArrayList(java.util.ArrayList) BatchLookupNormalizer(org.eclipse.scout.rt.shared.services.lookup.BatchLookupNormalizer) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall)

Aggregations

ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)36 ArrayList (java.util.ArrayList)29 List (java.util.List)24 ILookupCall (org.eclipse.scout.rt.shared.services.lookup.ILookupCall)19 BatchLookupResultCache (org.eclipse.scout.rt.shared.services.lookup.BatchLookupResultCache)10 ILookupRowFetchedCallback (org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback)10 ClientRunContext (org.eclipse.scout.rt.client.context.ClientRunContext)9 ToStringBuilder (org.eclipse.scout.rt.platform.util.ToStringBuilder)8 Test (org.junit.Test)7 BatchLookupCall (org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall)6 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)5 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)4 ILookupRowProvider (org.eclipse.scout.rt.client.ui.form.fields.smartfield.ILookupRowProvider)4 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)4 LookupRow (org.eclipse.scout.rt.shared.services.lookup.LookupRow)4 HashMap (java.util.HashMap)3 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)3 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)3 Pattern (java.util.regex.Pattern)2 IBatchLookupService (org.eclipse.scout.rt.shared.services.lookup.IBatchLookupService)2