Search in sources :

Example 1 with RecordList

use of com.netsuite.webservices.v2016_2.platform.core.RecordList in project components by Talend.

the class NetSuiteClientServiceImpl method toRecordList.

public static <RecT> List<Record> toRecordList(List<RecT> nsRecordList) {
    List<Record> recordList = new ArrayList<>(nsRecordList.size());
    for (RecT nsRecord : nsRecordList) {
        Record r = (Record) nsRecord;
        recordList.add(r);
    }
    return recordList;
}
Also used : ArrayList(java.util.ArrayList) Record(com.netsuite.webservices.v2016_2.platform.core.Record) SearchRecord(com.netsuite.webservices.v2016_2.platform.core.SearchRecord)

Example 2 with RecordList

use of com.netsuite.webservices.v2016_2.platform.core.RecordList in project components by Talend.

the class NetSuiteSearchInputReaderTest method testBasic.

@Test
public void testBasic() throws Exception {
    properties.module.moduleName.setValue("Account");
    properties.module.searchQuery.field.setValue(Lists.newArrayList("type", "generalRateType"));
    properties.module.searchQuery.operator.setValue(Lists.newArrayList("List.anyOf", "List.anyOf"));
    properties.module.searchQuery.value1.setValue(Lists.newArrayList((Object) Arrays.asList("bank", "otherAsset"), (Object) Arrays.asList("current", "historical")));
    properties.module.searchQuery.value2.setValue(Lists.newArrayList(null, null));
    NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(mockTestFixture.getRuntimeContainer(), properties);
    List<Account> recordList = makeNsObjects(new SimpleObjectComposer<>(Account.class), 150);
    mockSearchRequestResults(recordList, 100);
    NetSuiteClientService<?> clientService = source.getClientService();
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(Account.class);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(mockTestFixture.getRuntimeContainer());
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    while (reader.advance()) {
        record = reader.getCurrent();
        assertIndexedRecord(typeDesc, record);
    }
    Map<String, Object> readerResult = reader.getReturnValues();
    assertNotNull(readerResult);
    assertEquals(150, readerResult.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
}
Also used : Account(com.netsuite.webservices.v2016_2.lists.accounting.Account) NetSuiteSourceImpl(org.talend.components.netsuite.v2016_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) Test(org.junit.Test)

Example 3 with RecordList

use of com.netsuite.webservices.v2016_2.platform.core.RecordList in project components by Talend.

the class NetSuiteMockTestBase method makeRecordPages.

public static <T extends Record> List<SearchResult> makeRecordPages(List<T> recordList, int pageSize) throws Exception {
    int count = recordList.size();
    int totalPages = count / pageSize;
    if (count % pageSize != 0) {
        totalPages += 1;
    }
    String searchId = UUID.randomUUID().toString();
    List<SearchResult> pageResults = new ArrayList<>();
    SearchResult result = null;
    Iterator<T> recordIterator = recordList.iterator();
    while (recordIterator.hasNext() && count > 0) {
        T record = recordIterator.next();
        if (result == null) {
            result = new SearchResult();
            result.setSearchId(searchId);
            result.setTotalPages(totalPages);
            result.setTotalRecords(count);
            result.setPageIndex(pageResults.size() + 1);
            result.setPageSize(pageSize);
            result.setStatus(createSuccessStatus());
        }
        if (result.getRecordList() == null) {
            result.setRecordList(new RecordList());
        }
        result.getRecordList().getRecord().add(record);
        if (result.getRecordList().getRecord().size() == pageSize) {
            pageResults.add(result);
            result = null;
        }
        count--;
    }
    if (result != null) {
        pageResults.add(result);
    }
    return pageResults;
}
Also used : RecordList(com.netsuite.webservices.v2016_2.platform.core.RecordList) ArrayList(java.util.ArrayList) SearchResult(com.netsuite.webservices.v2016_2.platform.core.SearchResult)

Example 4 with RecordList

use of com.netsuite.webservices.v2016_2.platform.core.RecordList in project components by Talend.

the class NetSuiteMockTestBase method makeIndexedRecords.

public static <T> List<IndexedRecord> makeIndexedRecords(NetSuiteClientService<?> clientService, Schema schema, ObjectComposer<T> objectComposer, int count) throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, schema.getName());
    List<IndexedRecord> recordList = new ArrayList<>();
    while (count > 0) {
        T nsRecord = objectComposer.composeObject();
        IndexedRecord convertedRecord = transducer.read(nsRecord);
        Schema recordSchema = convertedRecord.getSchema();
        GenericRecord record = new GenericData.Record(recordSchema);
        for (Schema.Field field : schema.getFields()) {
            Object value = convertedRecord.get(field.pos());
            record.put(field.pos(), value);
        }
        recordList.add(record);
        count--;
    }
    return recordList;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) Record(com.netsuite.webservices.v2016_2.platform.core.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 5 with RecordList

use of com.netsuite.webservices.v2016_2.platform.core.RecordList in project components by Talend.

the class NetSuiteMockTestBase method mockSearchRequestResults.

protected <T extends Record> void mockSearchRequestResults(List<T> recordList, int pageSize) throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    final List<SearchResult> pageResults = makeRecordPages(recordList, pageSize);
    when(port.search(any(SearchRequest.class))).then(new Answer<SearchResponse>() {

        @Override
        public SearchResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            SearchResponse response = new SearchResponse();
            response.setSearchResult(pageResults.get(0));
            return response;
        }
    });
    when(port.searchMoreWithId(any(SearchMoreWithIdRequest.class))).then(new Answer<SearchMoreWithIdResponse>() {

        @Override
        public SearchMoreWithIdResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            SearchMoreWithIdRequest request = (SearchMoreWithIdRequest) invocationOnMock.getArguments()[0];
            SearchMoreWithIdResponse response = new SearchMoreWithIdResponse();
            response.setSearchResult(pageResults.get(request.getPageIndex() - 1));
            return response;
        }
    });
}
Also used : NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) SearchRequest(com.netsuite.webservices.v2016_2.platform.messages.SearchRequest) SearchMoreWithIdResponse(com.netsuite.webservices.v2016_2.platform.messages.SearchMoreWithIdResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SearchResult(com.netsuite.webservices.v2016_2.platform.core.SearchResult) SearchResponse(com.netsuite.webservices.v2016_2.platform.messages.SearchResponse) SearchMoreWithIdRequest(com.netsuite.webservices.v2016_2.platform.messages.SearchMoreWithIdRequest)

Aggregations

ArrayList (java.util.ArrayList)8 Schema (org.apache.avro.Schema)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)4 Account (com.netsuite.webservices.v2016_2.lists.accounting.Account)3 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)3 CustomFieldList (com.netsuite.webservices.v2016_2.platform.core.CustomFieldList)3 RecordRefList (com.netsuite.webservices.v2016_2.platform.core.RecordRefList)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 Test (org.junit.Test)3 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)3 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl)3 Subsidiary (com.netsuite.webservices.v2016_2.lists.accounting.Subsidiary)2 SubsidiarySearch (com.netsuite.webservices.v2016_2.lists.accounting.SubsidiarySearch)2 Contact (com.netsuite.webservices.v2016_2.lists.relationships.Contact)2 SubsidiarySearchBasic (com.netsuite.webservices.v2016_2.platform.common.SubsidiarySearchBasic)2 BooleanCustomFieldRef (com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef)2 CustomRecordRef (com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef)2 Record (com.netsuite.webservices.v2016_2.platform.core.Record)2 RecordRef (com.netsuite.webservices.v2016_2.platform.core.RecordRef)2 SearchResult (com.netsuite.webservices.v2016_2.platform.core.SearchResult)2