Search in sources :

Example 11 with ILookupCall

use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall 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 12 with ILookupCall

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

the class BatchNormalizerTest method testInternal.

private void testInternal(BatchLookupCall batchCall, int expectedNormalizedSize, int expectedServerInvocations, int expectedNullArrayCount, int expectedTotalResultRowCount) throws Exception {
    // 
    BatchLookupNormalizer normalizer = new BatchLookupNormalizer();
    List<ILookupCall<?>> callArray = batchCall.getCallBatch();
    List<ILookupCall<?>> normCallArray = normalizer.normalizeCalls(callArray);
    List<List<ILookupRow<?>>> normResultArray = new BatchLookupService().getBatchDataByKey(new BatchLookupCall(normCallArray));
    List<List<ILookupRow<?>>> resultArray = normalizer.denormalizeResults(normResultArray);
    // 
    assertEquals(resultArray.size(), callArray.size());
    assertEquals(normResultArray.size(), normCallArray.size());
    assertEquals(expectedNormalizedSize, normResultArray.size());
    Mockito.verify(m_lookupService, Mockito.times(expectedServerInvocations)).getDataByKey(Mockito.<ILookupCall<Object>>any());
    int rowCount = 0;
    int nullArrayCount = 0;
    for (int i = 0; i < resultArray.size(); i++) {
        if (resultArray.get(i) == null) {
            nullArrayCount++;
        } else if (resultArray.get(i).size() == 1) {
            rowCount++;
            assertEquals(callArray.get(i).getKey(), resultArray.get(i).get(0).getKey());
            assertEquals(dumpCall(callArray.get(i)), resultArray.get(i).get(0).getText());
        } else if (resultArray.get(i).size() > 1) {
            fail("result length is expected to be 0 or 1");
        }
    }
    assertEquals(expectedNullArrayCount, nullArrayCount);
    assertEquals(expectedTotalResultRowCount, rowCount);
}
Also used : IBatchLookupService(org.eclipse.scout.rt.shared.services.lookup.IBatchLookupService) BatchLookupService(org.eclipse.scout.rt.server.services.lookup.BatchLookupService) BatchLookupNormalizer(org.eclipse.scout.rt.shared.services.lookup.BatchLookupNormalizer) ArrayList(java.util.ArrayList) List(java.util.List) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) BatchLookupCall(org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall)

Example 13 with ILookupCall

use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall 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)

Example 14 with ILookupCall

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

the class BatchLookupService method getBatchDataByKey.

@Override
public List<List<ILookupRow<?>>> getBatchDataByKey(BatchLookupCall batch) {
    List<ILookupCall<?>> calls = batch.getCallBatch();
    List<List<ILookupRow<?>>> result = new ArrayList<List<ILookupRow<?>>>();
    BatchLookupResultCache cache = new BatchLookupResultCache();
    for (ILookupCall<?> call : calls) {
        result.add(new ArrayList<ILookupRow<?>>(cache.getDataByKey(call)));
    }
    return result;
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BatchLookupResultCache(org.eclipse.scout.rt.shared.services.lookup.BatchLookupResultCache) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall)

Example 15 with ILookupCall

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

the class BatchLookupService method getBatchDataByRec.

@Override
public List<List<ILookupRow<?>>> getBatchDataByRec(BatchLookupCall batch) {
    List<ILookupCall<?>> calls = batch.getCallBatch();
    List<List<ILookupRow<?>>> result = new ArrayList<List<ILookupRow<?>>>();
    BatchLookupResultCache cache = new BatchLookupResultCache();
    for (ILookupCall<?> call : calls) {
        result.add(new ArrayList<ILookupRow<?>>(cache.getDataByRec(call)));
    }
    return result;
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BatchLookupResultCache(org.eclipse.scout.rt.shared.services.lookup.BatchLookupResultCache) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall)

Aggregations

ILookupCall (org.eclipse.scout.rt.shared.services.lookup.ILookupCall)25 ArrayList (java.util.ArrayList)19 List (java.util.List)19 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)18 ClientRunContext (org.eclipse.scout.rt.client.context.ClientRunContext)8 ToStringBuilder (org.eclipse.scout.rt.platform.util.ToStringBuilder)8 BatchLookupResultCache (org.eclipse.scout.rt.shared.services.lookup.BatchLookupResultCache)8 ILookupRowFetchedCallback (org.eclipse.scout.rt.shared.services.lookup.ILookupRowFetchedCallback)8 BatchLookupCall (org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall)6 Test (org.junit.Test)5 ILookupRowProvider (org.eclipse.scout.rt.client.ui.form.fields.smartfield.ILookupRowProvider)4 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)4 TestLookupCall (org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall)3 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)2 BatchLookupNormalizer (org.eclipse.scout.rt.shared.services.lookup.BatchLookupNormalizer)2 IBatchLookupService (org.eclipse.scout.rt.shared.services.lookup.IBatchLookupService)2 Before (org.junit.Before)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 IMixedSmartField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IMixedSmartField)1