Search in sources :

Example 16 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class SearchResultSetTest method testPagination.

@Test
public void testPagination() throws Exception {
    NetSuiteClientService<?> conn = mock(NetSuiteClientService.class);
    List<Record> page1 = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        page1.add(new Account());
    }
    List<Record> page2 = new ArrayList<>();
    for (int i = 0; i < 750; i++) {
        page2.add(new Account());
    }
    SearchResult result1 = new SearchResult();
    Status status = new Status();
    status.setIsSuccess(true);
    result1.setStatus(status);
    result1.setSearchId("abc123");
    result1.setPageIndex(1);
    result1.setTotalRecords(page1.size() + page2.size());
    result1.setTotalPages(2);
    result1.setRecordList(new RecordList());
    result1.getRecordList().getRecord().addAll(page1);
    SearchResult result2 = new SearchResult();
    result2.setStatus(status);
    result2.setSearchId(result1.getSearchId());
    result2.setPageIndex(2);
    result2.setTotalRecords(result1.getTotalRecords());
    result2.setTotalPages(result1.getTotalPages());
    result2.setRecordList(new RecordList());
    result2.getRecordList().getRecord().addAll(page2);
    SearchResponse response1 = new SearchResponse();
    response1.setSearchResult(result1);
    SearchMoreWithIdResponse response2 = new SearchMoreWithIdResponse();
    response2.setSearchResult(result2);
    AccountSearch nsSearchRecord1 = new AccountSearch();
    NsSearchResult nsSearchResult1 = TestNetSuiteClientService.toNsSearchResult(result1);
    NsSearchResult nsSearchResult2 = TestNetSuiteClientService.toNsSearchResult(result2);
    when(conn.search(eq(nsSearchRecord1))).thenReturn(nsSearchResult1);
    when(conn.searchMoreWithId(eq("abc123"), eq(2))).thenReturn(nsSearchResult2);
    NetSuiteClientService<?> clientService = new TestNetSuiteClientService();
    RecordTypeInfo recordTypeInfo = clientService.getMetaDataSource().getRecordType("Account");
    SearchRecordTypeDesc searchRecordTypeDesc = clientService.getMetaDataSource().getSearchRecordType(recordTypeInfo.getRecordType().getSearchRecordType());
    SearchResultSet<Record> resultSet = new SearchResultSet<>(conn, recordTypeInfo.getRecordType(), searchRecordTypeDesc, nsSearchResult1);
    List<Object> recordList = new ArrayList<>();
    while (resultSet.next()) {
        Object record = resultSet.get();
        assertNotNull(record);
        recordList.add(record);
    }
    assertEquals(page1.size() + page2.size(), recordList.size());
}
Also used : Status(com.netsuite.webservices.test.platform.core.Status) Account(com.netsuite.webservices.test.lists.accounting.Account) TestNetSuiteClientService(org.talend.components.netsuite.test.client.TestNetSuiteClientService) SearchMoreWithIdResponse(com.netsuite.webservices.test.platform.messages.SearchMoreWithIdResponse) ArrayList(java.util.ArrayList) SearchResult(com.netsuite.webservices.test.platform.core.SearchResult) SearchResponse(com.netsuite.webservices.test.platform.messages.SearchResponse) AccountSearch(com.netsuite.webservices.test.lists.accounting.AccountSearch) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordList(com.netsuite.webservices.test.platform.core.RecordList) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchResultSet(org.talend.components.netsuite.client.search.SearchResultSet) Record(com.netsuite.webservices.test.platform.core.Record) Test(org.junit.Test)

Example 17 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class NetSuiteSearchInputReader method search.

/**
 * Build and execute NetSuite search query.
 *
 * @return
 * @throws NetSuiteException if an error occurs during execution of search
 */
private ResultSet<?> search() throws NetSuiteException {
    SearchQuery search = buildSearchQuery();
    RecordTypeInfo recordTypeInfo = search.getRecordTypeInfo();
    // Set up object translator
    transducer = new NsObjectInputTransducer(clientService, schema, recordTypeInfo.getName());
    transducer.setMetaDataSource(metaDataSource);
    transducer.setApiVersion(properties.connection.apiVersion.getValue());
    ResultSet<?> resultSet = search.search();
    return resultSet;
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo)

Example 18 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class NsObjectTransducer method getDynamicSchema.

/**
 * Get dynamic schema using given type descriptor and design schema.
 *
 * @param typeDesc NetSuite data model object type descriptor
 * @param designSchema design schema
 * @param targetSchemaName name of target schema
 * @return schema with all fields
 */
protected Schema getDynamicSchema(TypeDesc typeDesc, Schema designSchema, String targetSchemaName) {
    RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeDesc.getTypeName());
    Map<String, FieldDesc> fieldMap = typeDesc.getFieldMap();
    String dynamicPosProp = designSchema.getProp(NetSuiteSchemaConstants.TALEND6_DYNAMIC_COLUMN_POSITION);
    List<Schema.Field> fields = new ArrayList<>();
    if (dynamicPosProp != null) {
        Set<String> designFieldNames = new HashSet<>(designSchema.getFields().size());
        for (Schema.Field field : designSchema.getFields()) {
            String fieldName = NetSuiteDatasetRuntimeImpl.getNsFieldName(field);
            designFieldNames.add(fieldName);
        }
        int dynPos = Integer.parseInt(dynamicPosProp);
        int dynamicColumnSize = fieldMap.size() - designSchema.getFields().size();
        List<FieldDesc> dynaFieldDescList = new ArrayList<>(dynamicColumnSize);
        for (FieldDesc fieldDesc : fieldMap.values()) {
            String fieldName = fieldDesc.getName();
            if (!designFieldNames.contains(fieldName)) {
                dynaFieldDescList.add(fieldDesc);
            }
        }
        if (designSchema.getFields().size() > 0) {
            for (Schema.Field field : designSchema.getFields()) {
                // Dynamic column is first or middle column in design schema
                if (dynPos == field.pos()) {
                    for (int i = 0; i < dynamicColumnSize; i++) {
                        // Add dynamic schema fields
                        FieldDesc fieldDesc = dynaFieldDescList.get(i);
                        fields.add(createSchemaField(fieldDesc));
                    }
                }
                // Add fields of design schema
                Schema.Field avroField = new Schema.Field(field.name(), field.schema(), null, field.defaultVal());
                Map<String, Object> fieldProps = field.getObjectProps();
                for (String propName : fieldProps.keySet()) {
                    Object propValue = fieldProps.get(propName);
                    if (propValue != null) {
                        avroField.addProp(propName, propValue);
                    }
                }
                fields.add(avroField);
                // Dynamic column is last column in design schema
                if (field.pos() == (designSchema.getFields().size() - 1) && dynPos == (field.pos() + 1)) {
                    for (int i = 0; i < dynamicColumnSize; i++) {
                        // Add dynamic schema fields
                        FieldDesc fieldDesc = dynaFieldDescList.get(i);
                        fields.add(createSchemaField(fieldDesc));
                    }
                }
            }
        } else {
            // All fields are included in dynamic schema
            for (String fieldName : fieldMap.keySet()) {
                FieldDesc fieldDesc = fieldMap.get(fieldName);
                fields.add(createSchemaField(fieldDesc));
            }
        }
    } else {
        // All fields are included in dynamic schema
        for (String fieldName : fieldMap.keySet()) {
            FieldDesc fieldDesc = fieldMap.get(fieldName);
            fields.add(createSchemaField(fieldDesc));
        }
    }
    Schema schema = Schema.createRecord(targetSchemaName, null, null, false, fields);
    NetSuiteDatasetRuntimeImpl.augmentSchemaWithCustomMetaData(metaDataSource, schema, recordTypeInfo, typeDesc.getFields());
    return schema;
}
Also used : Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SimpleFieldDesc(org.talend.components.netsuite.client.model.SimpleFieldDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) HashSet(java.util.HashSet)

Example 19 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class DefaultMetaDataSource method getRecordTypes.

/**
 * {@inheritDoc}
 */
@Override
public Collection<RecordTypeInfo> getRecordTypes() {
    List<RecordTypeInfo> recordTypes = new ArrayList<>();
    Collection<RecordTypeDesc> standardRecordTypes = clientService.getBasicMetaData().getRecordTypes();
    for (RecordTypeDesc recordType : standardRecordTypes) {
        recordTypes.add(new RecordTypeInfo(recordType));
    }
    if (customizationEnabled) {
        recordTypes.addAll(customMetaDataSource.getCustomRecordTypes());
    }
    return recordTypes;
}
Also used : CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) ArrayList(java.util.ArrayList)

Example 20 with RecordTypeInfo

use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.

the class DefaultMetaDataSource method getSearchRecordType.

/**
 * {@inheritDoc}
 */
@Override
public SearchRecordTypeDesc getSearchRecordType(String recordTypeName) {
    SearchRecordTypeDesc searchRecordType = clientService.getBasicMetaData().getSearchRecordType(recordTypeName);
    if (searchRecordType != null) {
        return searchRecordType;
    }
    RecordTypeInfo recordTypeInfo = getRecordType(recordTypeName);
    if (recordTypeInfo != null) {
        return getSearchRecordType(recordTypeInfo.getRecordType());
    }
    return null;
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo)

Aggregations

RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)24 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)17 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)11 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)11 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)9 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)8 Schema (org.apache.avro.Schema)7 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)7 HashSet (java.util.HashSet)5 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)5 ComponentException (org.talend.components.api.exception.ComponentException)4 Record (com.netsuite.webservices.test.platform.core.Record)3 SearchResult (com.netsuite.webservices.test.platform.core.SearchResult)3 Status (com.netsuite.webservices.test.platform.core.Status)3 SearchResponse (com.netsuite.webservices.test.platform.messages.SearchResponse)3 SearchResultSet (org.talend.components.netsuite.client.search.SearchResultSet)3 TestNetSuiteClientService (org.talend.components.netsuite.test.client.TestNetSuiteClientService)3 NamedThing (org.talend.daikon.NamedThing)3