Search in sources :

Example 21 with RecordTypeInfo

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

the class DefaultMetaDataSource method getTypeInfo.

/**
 * {@inheritDoc}
 */
@Override
public TypeDesc getTypeInfo(final String typeName) {
    TypeDesc baseTypeDesc;
    String targetTypeName = null;
    Class<?> targetTypeClass;
    List<FieldDesc> baseFieldDescList;
    RecordTypeInfo recordTypeInfo = getRecordType(typeName);
    if (recordTypeInfo != null) {
        if (recordTypeInfo instanceof CustomRecordTypeInfo) {
            CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
            baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(customRecordTypeInfo.getRecordType().getTypeName());
            targetTypeName = customRecordTypeInfo.getName();
        } else {
            baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(typeName);
        }
    } else {
        baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(typeName);
    }
    if (targetTypeName == null) {
        targetTypeName = baseTypeDesc.getTypeName();
    }
    targetTypeClass = baseTypeDesc.getTypeClass();
    baseFieldDescList = baseTypeDesc.getFields();
    List<FieldDesc> resultFieldDescList = new ArrayList<>(baseFieldDescList.size() + 10);
    // Add basic fields except field list containers (custom field list, null field list)
    for (FieldDesc fieldDesc : baseFieldDescList) {
        String fieldName = fieldDesc.getName();
        if (fieldName.equals("customFieldList") || fieldName.equals("nullFieldList")) {
            continue;
        }
        resultFieldDescList.add(fieldDesc);
    }
    if (recordTypeInfo != null) {
        if (customizationEnabled) {
            // Add custom fields
            Map<String, CustomFieldDesc> customFieldMap = customMetaDataSource.getCustomFields(recordTypeInfo);
            for (CustomFieldDesc fieldInfo : customFieldMap.values()) {
                resultFieldDescList.add(fieldInfo);
            }
        }
    }
    return new TypeDesc(targetTypeName, targetTypeClass, resultFieldDescList);
}
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) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) 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 22 with RecordTypeInfo

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

the class NetSuiteClientServiceTest method testBasicMetaData.

@Test
public void testBasicMetaData() throws Exception {
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    Set<SearchRecordType> searchRecordTypeSet = new HashSet<>(Arrays.asList(SearchRecordType.values()));
    Set<String> searchRecordTypeNameSet = new HashSet<>();
    for (SearchRecordType searchRecordType : searchRecordTypeSet) {
        searchRecordTypeNameSet.add(toInitialUpper(searchRecordType.value()));
    }
    searchRecordTypeNameSet.add("Address");
    searchRecordTypeNameSet.add("InventoryDetail");
    searchRecordTypeNameSet.add("TimeEntry");
    for (String searchRecordType : searchRecordTypeNameSet) {
        try {
            SearchRecordTypeDesc searchRecordInfo = clientService.getMetaDataSource().getSearchRecordType(searchRecordType);
            assertNotNull("Search record def found: " + searchRecordType, searchRecordInfo);
        } catch (Exception e) {
            throw new AssertionError("Search record type: " + searchRecordType, e);
        }
    }
    Set<RecordType> recordTypeSet = new HashSet<>(Arrays.asList(RecordType.values()));
    recordTypeSet.remove(RecordType.CUSTOM_TRANSACTION_TYPE);
    Set<String> recordTypeNameSet = new HashSet<>();
    for (RecordType recordType : recordTypeSet) {
        recordTypeNameSet.add(toInitialUpper(recordType.value()));
    }
    recordTypeNameSet.add("Address");
    recordTypeNameSet.add("InventoryDetail");
    recordTypeNameSet.add("TimeEntry");
    for (String recordType : recordTypeNameSet) {
        RecordTypeInfo recordTypeInfo = clientService.getMetaDataSource().getRecordType(recordType);
        assertNotNull("Record type def found: " + recordType, recordTypeInfo);
    }
    Collection<SearchFieldOperatorName> searchOperatorNames = clientService.getBasicMetaData().getSearchOperatorNames();
    List<SearchFieldOperatorName> searchFieldOperatorNameList = new ArrayList<>(searchOperatorNames);
    Collections.sort(searchFieldOperatorNameList, new Comparator<SearchFieldOperatorName>() {

        @Override
        public int compare(SearchFieldOperatorName o1, SearchFieldOperatorName o2) {
            return o1.getQualifiedName().compareTo(o2.getQualifiedName());
        }
    });
    for (SearchFieldOperatorName operatorName : searchFieldOperatorNameList) {
        assertNotNull(operatorName.getDataType());
        if (!SearchFieldOperatorType.BOOLEAN.dataTypeEquals(operatorName.getDataType())) {
            assertNotNull(operatorName.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SearchRecordType(com.netsuite.webservices.v2016_2.platform.core.types.SearchRecordType) SearchFieldOperatorName(org.talend.components.netsuite.client.model.search.SearchFieldOperatorName) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) SearchRecordType(com.netsuite.webservices.v2016_2.platform.core.types.SearchRecordType) RecordType(com.netsuite.webservices.v2016_2.platform.core.types.RecordType) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with RecordTypeInfo

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

the class NetSuiteClientServiceIT method testSearchCustomRecord.

@Test
public void testSearchCustomRecord() throws Exception {
    NetSuiteClientService<?> connection = webServiceTestFixture.getClientService();
    connection.login();
    Collection<RecordTypeInfo> recordTypes = connection.getMetaDataSource().getRecordTypes();
    RecordTypeInfo recordType = getCustomRecordType(recordTypes, "customrecord_campaign_revenue");
    SearchQuery searchQuery = connection.newSearch();
    searchQuery.target(recordType.getName());
    SearchResultSet<Record> rs = searchQuery.search();
    int count = 10;
    while (rs.next() && count-- > 0) {
        Record record = rs.get();
        assertNotNull(record);
    }
}
Also used : SearchQuery(org.talend.components.netsuite.client.search.SearchQuery) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) Record(com.netsuite.webservices.v2016_2.platform.core.Record) Test(org.junit.Test)

Example 24 with RecordTypeInfo

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

the class NetSuiteClientServiceIT method testRetrieveCustomRecordCustomFields.

@Test
public void testRetrieveCustomRecordCustomFields() throws Exception {
    NetSuiteClientService<?> connection = webServiceTestFixture.getClientService();
    connection.login();
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    RecordTypeInfo recordType = connection.getMetaDataSource().getRecordType("customrecord_campaign_revenue");
    TypeDesc typeDesc = connection.getMetaDataSource().getTypeInfo(recordType.getName());
    logger.debug("Record type desc: {}", typeDesc.getTypeName());
    stopWatch.stop();
}
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) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) StopWatch(org.apache.commons.lang3.time.StopWatch) 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