Search in sources :

Example 16 with TypeDesc

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

the class NsObjectInputTransducerTest method testBasic.

@Test
public void testBasic() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
    final List<Opportunity> recordList = makeNsObjects(new NsObjectComposer<Opportunity>(clientService.getMetaDataSource(), typeDesc), 10);
    mockSearchRequestResults(recordList, 100);
    Schema schema = NetSuiteDatasetRuntimeImpl.inferSchemaForType(typeDesc.getTypeName(), typeDesc.getFields());
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    for (Record record : recordList) {
        IndexedRecord indexedRecord = transducer.read(record);
        assertIndexedRecord(typeDesc, indexedRecord);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Opportunity(com.netsuite.webservices.test.transactions.sales.Opportunity) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Record(com.netsuite.webservices.test.platform.core.Record) Test(org.junit.Test)

Example 17 with TypeDesc

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

the class NsObjectInputTransducerTest method testDynamicSchemaWithDynamicColumnLast.

@Test
public void testDynamicSchemaWithDynamicColumnLast() throws Exception {
    TypeDesc basicTypeDesc = clientService.getMetaDataSource().getTypeInfo("Check");
    final List<Check> recordList = makeNsObjects(new NsObjectComposer<Check>(clientService.getMetaDataSource(), basicTypeDesc), 10);
    mockSearchRequestResults(recordList, 100);
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());
    Schema designSchema = SchemaBuilder.record(typeDesc.getTypeName()).fields().name("InternalId").type(NetSuiteDatasetRuntimeImpl.inferSchemaForField(typeDesc.getField("internalId"))).noDefault().name("TranId").type(NetSuiteDatasetRuntimeImpl.inferSchemaForField(typeDesc.getField("tranId"))).noDefault().name("LastModifiedDate").type(NetSuiteDatasetRuntimeImpl.inferSchemaForField(typeDesc.getField("lastModifiedDate"))).noDefault().endRecord();
    designSchema.addProp(NetSuiteSchemaConstants.TALEND6_DYNAMIC_COLUMN_POSITION, "3");
    designSchema.addProp(NetSuiteSchemaConstants.TALEND6_DYNAMIC_COLUMN_ID, "dynamic");
    Schema schema = AvroUtils.setIncludeAllFields(designSchema, true);
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    SearchResultSet<Record> rs = clientService.newSearch().target(basicTypeDesc.getTypeName()).search();
    while (rs.next()) {
        Record record = rs.get();
        IndexedRecord indexedRecord = transducer.read(record);
        assertIndexedRecord(typeDesc, indexedRecord);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) Check(com.netsuite.webservices.test.transactions.bank.Check) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Record(com.netsuite.webservices.test.platform.core.Record) Test(org.junit.Test)

Example 18 with TypeDesc

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

the class NsObjectInputTransducerTest method testDynamicSchemaWithDynamicColumnMiddle.

@Test
public void testDynamicSchemaWithDynamicColumnMiddle() throws Exception {
    TypeDesc basicTypeDesc = clientService.getMetaDataSource().getTypeInfo("Check");
    final List<Check> recordList = makeNsObjects(new NsObjectComposer<Check>(clientService.getMetaDataSource(), basicTypeDesc), 10);
    mockSearchRequestResults(recordList, 100);
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());
    Schema designSchema = SchemaBuilder.record(typeDesc.getTypeName()).fields().name("InternalId").type(NetSuiteDatasetRuntimeImpl.inferSchemaForField(typeDesc.getField("internalId"))).noDefault().name("TranId").type(NetSuiteDatasetRuntimeImpl.inferSchemaForField(typeDesc.getField("tranId"))).noDefault().name("LastModifiedDate").type(NetSuiteDatasetRuntimeImpl.inferSchemaForField(typeDesc.getField("lastModifiedDate"))).noDefault().endRecord();
    designSchema.addProp(NetSuiteSchemaConstants.TALEND6_DYNAMIC_COLUMN_POSITION, "1");
    designSchema.addProp(NetSuiteSchemaConstants.TALEND6_DYNAMIC_COLUMN_ID, "dynamic");
    Schema schema = AvroUtils.setIncludeAllFields(designSchema, true);
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    SearchResultSet<Record> rs = clientService.newSearch().target(basicTypeDesc.getTypeName()).search();
    while (rs.next()) {
        Record record = rs.get();
        IndexedRecord indexedRecord = transducer.read(record);
        assertIndexedRecord(typeDesc, indexedRecord);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) Check(com.netsuite.webservices.test.transactions.bank.Check) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Record(com.netsuite.webservices.test.platform.core.Record) Test(org.junit.Test)

Example 19 with TypeDesc

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

the class NetSuiteDatasetRuntimeImpl method getSchemaForRecordRef.

public Schema getSchemaForRecordRef(String typeName) {
    try {
        // Get info for target record type
        final RecordTypeInfo referencedRecordTypeInfo = metaDataSource.getRecordType(typeName);
        final RefType refType = referencedRecordTypeInfo.getRefType();
        // Get type info for record ref
        final TypeDesc typeDesc = metaDataSource.getTypeInfo(refType.getTypeName());
        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, referencedRecordTypeInfo, null);
        return schema;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) RefType(org.talend.components.netsuite.client.model.RefType) 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 20 with TypeDesc

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

the class NetSuiteDatasetRuntimeImpl method getSchema.

@Override
public Schema getSchema(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, fieldDescList);
        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)

Aggregations

TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)48 Test (org.junit.Test)41 Schema (org.apache.avro.Schema)31 IndexedRecord (org.apache.avro.generic.IndexedRecord)23 ArrayList (java.util.ArrayList)14 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)13 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)12 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)10 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)10 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)10 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)10 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)9 PurchaseOrder (com.netsuite.webservices.test.transactions.purchases.PurchaseOrder)8 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)8 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)8 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)7 CustomRecord (com.netsuite.webservices.test.setup.customization.CustomRecord)7 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4