Search in sources :

Example 11 with RecordTypeInfo

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

the class NetSuiteDatasetRuntimeImpl method getSchemaForDeleteFlow.

@Override
public Schema getSchemaForDeleteFlow(String typeName, Schema schema) {
    RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
    TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
    // We should check and add key fields:
    // internalId, externalId and scriptId (for custom record type)
    List<FieldDesc> fieldDescList = new ArrayList<>();
    Schema.Field internalIdField = getNsFieldByName(schema, "internalId");
    if (internalIdField == null) {
        FieldDesc fieldDesc = typeDesc.getField("internalId");
        fieldDescList.add(fieldDesc);
    }
    Schema.Field externalIdField = getNsFieldByName(schema, "externalId");
    if (externalIdField == null) {
        FieldDesc fieldDesc = typeDesc.getField("externalId");
        fieldDescList.add(fieldDesc);
    }
    if (recordTypeInfo instanceof CustomRecordTypeInfo) {
        Schema.Field scriptIdField = getNsFieldByName(schema, "scriptId");
        if (scriptIdField == null) {
            FieldDesc fieldDesc = typeDesc.getField("scriptId");
            if (fieldDesc != null) {
                fieldDescList.add(fieldDesc);
            }
        }
    }
    // Create schema fields for mandatory fields.
    List<Schema.Field> fields = new ArrayList<>();
    Schema.Field f;
    if (!fieldDescList.isEmpty()) {
        Schema schemaToAdd = inferSchemaForType(typeName, fieldDescList);
        for (Schema.Field sourceField : schemaToAdd.getFields()) {
            f = copyField(sourceField);
            f.addProp(SchemaConstants.TALEND_FIELD_GENERATED, "true");
            f.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
            fields.add(f);
        }
    }
    return extendSchema(schema, typeName + "_FLOW", fields);
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 12 with RecordTypeInfo

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

the class NetSuiteDatasetRuntimeImpl method getRecordTypes.

@Override
public List<NamedThing> getRecordTypes() {
    try {
        Collection<RecordTypeInfo> recordTypeList = metaDataSource.getRecordTypes();
        List<NamedThing> recordTypes = new ArrayList<>(recordTypeList.size());
        for (RecordTypeInfo recordTypeInfo : recordTypeList) {
            recordTypes.add(new SimpleNamedThing(recordTypeInfo.getName(), recordTypeInfo.getDisplayName()));
        }
        // Sort by display name in alphabetical order
        Collections.sort(recordTypes, new Comparator<NamedThing>() {

            @Override
            public int compare(NamedThing o1, NamedThing o2) {
                return o1.getDisplayName().compareTo(o2.getDisplayName());
            }
        });
        return recordTypes;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing)

Example 13 with RecordTypeInfo

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

the class NetSuiteDatasetRuntimeImpl method getSchemaForUpdate.

@Override
public Schema getSchemaForUpdate(String typeName) {
    try {
        final RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
        final TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
        List<FieldDesc> fieldDescList = new ArrayList<>(typeDesc.getFields());
        // Sort in alphabetical order
        Collections.sort(fieldDescList, FieldDescComparator.INSTANCE);
        Schema schema = inferSchemaForType(typeDesc.getTypeName(), fieldDescList);
        augmentSchemaWithCustomMetaData(metaDataSource, schema, recordTypeInfo, typeDesc.getFields());
        return schema;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 14 with RecordTypeInfo

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

the class MetaDataSourceTest method testGetSearchableTypes.

@Test
public void testGetSearchableTypes() {
    Collection<NamedThing> searchableTypeNamedThings = metaDataSource.getSearchableTypes();
    assertNotNull(searchableTypeNamedThings);
    assertFalse(searchableTypeNamedThings.isEmpty());
    Set<String> searchableTypeNames = new HashSet<>();
    for (NamedThing namedThing : searchableTypeNamedThings) {
        assertNotNull(namedThing);
        searchableTypeNames.add(namedThing.getName());
    }
    for (RecordTypeDesc recordTypeDesc : TestRecordTypeEnum.values()) {
        if (recordTypeDesc.getSearchRecordType() != null) {
            assertTrue(recordTypeDesc.getTypeName(), searchableTypeNames.contains(recordTypeDesc.getTypeName()));
        }
    }
    for (RecordTypeInfo recordTypeInfo : customMetaDataSource.getCustomRecordTypes()) {
        assertTrue(recordTypeInfo.getName(), searchableTypeNames.contains(recordTypeInfo.getName()));
    }
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) NamedThing(org.talend.daikon.NamedThing) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with RecordTypeInfo

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

the class SearchResultSetTest method testRecordFiltering.

@Test
public void testRecordFiltering() throws Exception {
    NetSuiteClientService<?> conn = mock(NetSuiteClientService.class);
    List<Record> page1 = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        page1.add(new InventoryItem());
    }
    List<Record> page2 = new ArrayList<>();
    for (int i = 0; i < 750; i++) {
        page2.add(new ServiceSaleItem());
    }
    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);
    ItemSearch nsSearchRecord1 = new ItemSearch();
    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("InventoryItem");
    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(), recordList.size());
}
Also used : Status(com.netsuite.webservices.test.platform.core.Status) InventoryItem(com.netsuite.webservices.test.lists.accounting.InventoryItem) ServiceSaleItem(com.netsuite.webservices.test.lists.accounting.ServiceSaleItem) 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) ItemSearch(com.netsuite.webservices.test.lists.accounting.ItemSearch) SearchResponse(com.netsuite.webservices.test.platform.messages.SearchResponse) 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)

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