Search in sources :

Example 1 with FieldDesc

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

the class NsObjectInputTransducerIT method testIncludeAllFields.

@Test
public void testIncludeAllFields() throws Exception {
    NetSuiteClientService<?> connection = webServiceTestFixture.getClientService();
    connection.login();
    TypeDesc basicTypeDesc = connection.getBasicMetaData().getTypeInfo("Opportunity");
    Schema schema = getDynamicSchema();
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(connection, schema, basicTypeDesc.getTypeName());
    SearchResultSet<Record> rs = connection.newSearch().target(basicTypeDesc.getTypeName()).search();
    TypeDesc typeDesc = connection.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());
    int count = 0;
    while (count++ < connection.getSearchPageSize() && rs.next()) {
        Record record = rs.get();
        IndexedRecord indexedRecord = transducer.read(record);
        logger.debug("Indexed record: {}", indexedRecord);
        Schema recordSchema = indexedRecord.getSchema();
        assertEquals(typeDesc.getFields().size(), recordSchema.getFields().size());
        for (FieldDesc fieldDesc : typeDesc.getFields()) {
            String fieldName = fieldDesc.getName();
            Schema.Field field = recordSchema.getField(fieldName);
            assertNotNull(field);
            Object value = indexedRecord.get(field.pos());
        }
    }
    if (count == 0) {
        throw new IllegalStateException("No records");
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) Record(com.netsuite.webservices.v2014_2.platform.core.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 2 with FieldDesc

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

the class NetSuiteDatasetRuntimeTest method testGetSchemaForRecordBasic.

@Test
public void testGetSchemaForRecordBasic() throws Exception {
    TypeDesc typeDesc = clientService.getBasicMetaData().getTypeInfo("Account");
    Schema s = NetSuiteDatasetRuntimeImpl.inferSchemaForType(typeDesc.getTypeName(), typeDesc.getFields());
    assertThat(s.getType(), is(Schema.Type.RECORD));
    assertThat(s.getName(), is("Account"));
    assertThat(s.getFields(), hasSize(typeDesc.getFields().size()));
    assertThat(s.getObjectProps().keySet(), empty());
    FieldDesc fieldDesc = typeDesc.getField("acctType");
    Schema.Field f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.STRING, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    assertThat(f.schema().getObjectProps().keySet(), empty());
    fieldDesc = typeDesc.getField("acctName");
    f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.STRING, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    assertThat(f.schema().getObjectProps().keySet(), empty());
    fieldDesc = typeDesc.getField("inventory");
    f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.BOOLEAN, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    assertThat(f.schema().getObjectProps().keySet(), empty());
    fieldDesc = typeDesc.getField("tranDate");
    f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.LONG, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_PATTERN, SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_PATTERN), is("yyyy-MM-dd'T'HH:mm:ss'.000Z'"));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
}
Also used : Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 3 with FieldDesc

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

the class ValueConverterTest method testIdentityConverters.

@Test
public void testIdentityConverters() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    FieldDesc fieldDesc = typeDesc.getField("isInactive");
    AvroConverter<Boolean, Boolean> converter1 = (AvroConverter<Boolean, Boolean>) transducer.getValueConverter(fieldDesc);
    assertEquals(Boolean.TRUE, converter1.convertToAvro(Boolean.TRUE));
    assertEquals(Boolean.FALSE, converter1.convertToDatum(Boolean.FALSE));
    fieldDesc = typeDesc.getField("openingBalance");
    AvroConverter<Double, Double> converter2 = (AvroConverter<Double, Double>) transducer.getValueConverter(fieldDesc);
    assertEquals(Double.valueOf(12345.6789), converter2.convertToAvro(Double.valueOf(12345.6789)));
    assertEquals(Double.valueOf(98765.4321), converter2.convertToDatum(Double.valueOf(98765.4321)));
}
Also used : NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 4 with FieldDesc

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

the class ValueConverterTest method testEnumConverter.

@Test
public void testEnumConverter() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    FieldDesc fieldDesc = typeDesc.getField("acctType");
    AvroConverter<Enum<AccountType>, String> converter1 = (AvroConverter<Enum<AccountType>, String>) transducer.getValueConverter(fieldDesc);
    assertEquals(AvroUtils._string(), converter1.getSchema());
    assertEquals(AccountType.class, converter1.getDatumClass());
    assertEquals(AccountType.ACCOUNTS_PAYABLE.value(), converter1.convertToAvro(AccountType.ACCOUNTS_PAYABLE));
    assertEquals(AccountType.ACCOUNTS_PAYABLE, converter1.convertToDatum(AccountType.ACCOUNTS_PAYABLE.value()));
    assertEquals(AccountType.ACCOUNTS_PAYABLE, converter1.convertToDatum(AccountType.ACCOUNTS_PAYABLE.name()));
    fieldDesc = typeDesc.getField("generalRate");
    assertNotNull(fieldDesc);
    AvroConverter<Enum<ConsolidatedRate>, String> converter2 = (AvroConverter<Enum<ConsolidatedRate>, String>) transducer.getValueConverter(fieldDesc);
    assertEquals(ConsolidatedRate.HISTORICAL.value(), converter2.convertToAvro(ConsolidatedRate.HISTORICAL));
    assertEquals(ConsolidatedRate.HISTORICAL, converter2.convertToDatum(ConsolidatedRate.HISTORICAL.value()));
}
Also used : ConsolidatedRate(com.netsuite.webservices.test.lists.accounting.types.ConsolidatedRate) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) AccountType(com.netsuite.webservices.test.lists.accounting.types.AccountType) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 5 with FieldDesc

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

the class ValueConverterTest method testXMLGregorianCalendarConverter.

@Test
public void testXMLGregorianCalendarConverter() throws Exception {
    DateTimeZone tz1 = DateTimeZone.getDefault();
    MutableDateTime dateTime1 = new MutableDateTime(tz1);
    dateTime1.setDate(System.currentTimeMillis());
    Long controlValue1 = dateTime1.getMillis();
    XMLGregorianCalendar xmlCalendar1 = datatypeFactory.newXMLGregorianCalendar();
    xmlCalendar1.setYear(dateTime1.getYear());
    xmlCalendar1.setMonth(dateTime1.getMonthOfYear());
    xmlCalendar1.setDay(dateTime1.getDayOfMonth());
    xmlCalendar1.setHour(dateTime1.getHourOfDay());
    xmlCalendar1.setMinute(dateTime1.getMinuteOfHour());
    xmlCalendar1.setSecond(dateTime1.getSecondOfMinute());
    xmlCalendar1.setMillisecond(dateTime1.getMillisOfSecond());
    xmlCalendar1.setTimezone(tz1.toTimeZone().getOffset(dateTime1.getMillis()) / 60000);
    FieldDesc fieldInfo = typeDesc.getField("tranDate");
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    AvroConverter<XMLGregorianCalendar, Long> converter1 = (AvroConverter<XMLGregorianCalendar, Long>) transducer.getValueConverter(fieldInfo);
    assertEquals(AvroUtils._logicalTimestamp(), converter1.getSchema());
    assertEquals(XMLGregorianCalendar.class, converter1.getDatumClass());
    assertEquals(controlValue1, converter1.convertToAvro(xmlCalendar1));
    assertEquals(xmlCalendar1, converter1.convertToDatum(controlValue1));
    AvroConverter<XMLGregorianCalendar, Object> converter2 = (AvroConverter<XMLGregorianCalendar, Object>) transducer.getValueConverter(fieldInfo);
    assertEquals(xmlCalendar1, converter2.convertToDatum(new Date(controlValue1.longValue())));
    assertNull(converter1.convertToAvro(null));
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) MutableDateTime(org.joda.time.MutableDateTime) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) DateTimeZone(org.joda.time.DateTimeZone) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) Date(java.util.Date) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Aggregations

FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)24 Schema (org.apache.avro.Schema)14 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)14 ArrayList (java.util.ArrayList)10 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)10 Test (org.junit.Test)9 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)8 NsObjectInputTransducer (org.talend.components.netsuite.input.NsObjectInputTransducer)8 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)7 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)7 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)7 AvroConverter (org.talend.daikon.avro.converter.AvroConverter)6 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)5 ComponentException (org.talend.components.api.exception.ComponentException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2