Search in sources :

Example 16 with FieldDesc

use of org.talend.components.netsuite.client.model.FieldDesc 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 17 with FieldDesc

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

the class NetSuiteWebServiceMockTestFixture method assertNsObject.

public static void assertNsObject(TypeDesc typeDesc, Object nsObject) throws Exception {
    assertNotNull(nsObject);
    assertEquals(typeDesc.getTypeClass(), nsObject.getClass());
    for (FieldDesc fieldDesc : typeDesc.getFields()) {
        String fieldName = fieldDesc.getName();
        Object value = getProperty(nsObject, fieldName);
        if (fieldDesc instanceof CustomFieldDesc) {
            CustomFieldDesc customFieldDesc = fieldDesc.asCustom();
            switch(customFieldDesc.getCustomFieldType()) {
                case BOOLEAN:
                case LONG:
                case DOUBLE:
                case STRING:
                case DATE:
                    assertNotNull(value);
                    break;
            }
        } else {
            Class<?> datumClass = fieldDesc.getValueType();
            if (datumClass == Boolean.class || datumClass == Long.class || datumClass == Double.class || datumClass == String.class || datumClass == XMLGregorianCalendar.class) {
                assertNotNull(value);
            } else if (datumClass.isEnum()) {
                assertNotNull(value);
            }
        }
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 18 with FieldDesc

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

the class NetSuiteWebServiceMockTestFixture method assertIndexedRecord.

public static void assertIndexedRecord(TypeDesc typeDesc, IndexedRecord indexedRecord) throws Exception {
    assertNotNull(indexedRecord);
    Schema recordSchema = indexedRecord.getSchema();
    assertEquals(typeDesc.getFields().size(), recordSchema.getFields().size());
    for (Schema.Field field : recordSchema.getFields()) {
        String nsFieldName = getNsFieldName(field);
        FieldDesc fieldDesc = typeDesc.getField(nsFieldName);
        assertNotNull(field);
        Object value = indexedRecord.get(field.pos());
        if (fieldDesc instanceof CustomFieldDesc) {
            CustomFieldDesc customFieldDesc = fieldDesc.asCustom();
            switch(customFieldDesc.getCustomFieldType()) {
                case BOOLEAN:
                case LONG:
                case DOUBLE:
                case STRING:
                case DATE:
                    assertNotNull(value);
                    break;
            }
        } else {
            Class<?> datumClass = fieldDesc.getValueType();
            if (datumClass == Boolean.class || datumClass == Long.class || datumClass == Double.class || datumClass == String.class || datumClass == XMLGregorianCalendar.class) {
                assertNotNull(value);
            } else if (datumClass.isEnum()) {
                assertNotNull(value);
                Mapper<String, Enum> enumAccessor = Beans.getEnumFromStringMapper((Class<Enum>) datumClass);
                Enum modelValue = enumAccessor.map((String) value);
                assertNotNull(modelValue);
            }
        }
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Mapper(org.talend.components.netsuite.util.Mapper) Schema(org.apache.avro.Schema) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 19 with FieldDesc

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

the class ValueConverterTest method testJsonConverterNestedObjectConcreteType.

@Test
public void testJsonConverterNestedObjectConcreteType() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    ObjectMapper objectMapper = new ObjectMapper();
    RecordRef recordRef1 = new RecordRef();
    recordRef1.setInternalId("12345");
    recordRef1.setName("R&D");
    ObjectNode recordRefNode1 = JsonNodeFactory.instance.objectNode();
    recordRefNode1.set("name", JsonNodeFactory.instance.textNode("R&D"));
    recordRefNode1.set("internalId", JsonNodeFactory.instance.textNode("12345"));
    recordRefNode1.set("externalId", JsonNodeFactory.instance.nullNode());
    recordRefNode1.set("type", JsonNodeFactory.instance.nullNode());
    String recordRefJson1 = objectMapper.writer().writeValueAsString(recordRef1);
    FieldDesc fieldDesc = typeDesc.getField("department");
    AvroConverter<RecordRef, String> converter1 = (AvroConverter<RecordRef, String>) transducer.getValueConverter(fieldDesc);
    String testRecordRefJson1 = converter1.convertToAvro(recordRef1);
    assertNotNull(testRecordRefJson1);
    JsonNode testRecordRefNode1 = objectMapper.reader().readTree(testRecordRefJson1);
    assertTrue(testRecordRefNode1.has("name"));
    assertTrue(testRecordRefNode1.has("internalId"));
    assertTrue(testRecordRefNode1.has("externalId"));
    assertTrue(testRecordRefNode1.has("type"));
    assertEquals(recordRef1.getName(), testRecordRefNode1.get("name").asText());
    assertEquals(recordRef1.getInternalId(), testRecordRefNode1.get("internalId").asText());
    assertEquals(recordRef1.getExternalId(), testRecordRefNode1.get("externalId").asText(null));
    assertNull(testRecordRefNode1.get("type").asText(null));
    RecordRef testRecordRef1 = converter1.convertToDatum(recordRefJson1);
    assertNotNull(testRecordRef1);
    assertEquals(recordRef1.getName(), testRecordRef1.getName());
    assertEquals(recordRef1.getInternalId(), testRecordRef1.getInternalId());
    assertEquals(recordRef1.getExternalId(), testRecordRef1.getExternalId());
    assertEquals(recordRef1.getType(), testRecordRef1.getType());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 20 with FieldDesc

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

the class ValueConverterTest method testJsonConverterNestedObjectPolymorphicType.

@Test
public void testJsonConverterNestedObjectPolymorphicType() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    BooleanCustomFieldRef customFieldRef1 = new BooleanCustomFieldRef();
    customFieldRef1.setInternalId("100001");
    customFieldRef1.setScriptId("custentity_field1");
    customFieldRef1.setValue(true);
    StringCustomFieldRef customFieldRef2 = new StringCustomFieldRef();
    customFieldRef2.setInternalId("100002");
    customFieldRef2.setScriptId("custentity_field2");
    customFieldRef2.setValue("test123");
    CustomFieldList customFieldList = new CustomFieldList();
    customFieldList.getCustomField().add(customFieldRef1);
    customFieldList.getCustomField().add(customFieldRef2);
    FieldDesc fieldDesc = typeDesc.getField("customFieldList");
    AvroConverter<CustomFieldList, String> converter1 = (AvroConverter<CustomFieldList, String>) transducer.getValueConverter(fieldDesc);
    String testJson1 = converter1.convertToAvro(customFieldList);
    assertNotNull(testJson1);
    ObjectNode node1 = JsonNodeFactory.instance.objectNode();
    ArrayNode list1 = JsonNodeFactory.instance.arrayNode();
    node1.set("customField", list1);
    ObjectNode customFieldNode1 = JsonNodeFactory.instance.objectNode();
    customFieldNode1.set(NsTypeResolverBuilder.TYPE_PROPERTY_NAME, JsonNodeFactory.instance.textNode("BooleanCustomFieldRef"));
    customFieldNode1.set("internalId", JsonNodeFactory.instance.textNode("100001"));
    customFieldNode1.set("scriptId", JsonNodeFactory.instance.textNode("custentity_field1"));
    customFieldNode1.set("value", JsonNodeFactory.instance.booleanNode(true));
    list1.add(customFieldNode1);
    ObjectNode customFieldNode2 = JsonNodeFactory.instance.objectNode();
    customFieldNode2.set(NsTypeResolverBuilder.TYPE_PROPERTY_NAME, JsonNodeFactory.instance.textNode("StringCustomFieldRef"));
    customFieldNode2.set("internalId", JsonNodeFactory.instance.textNode("100002"));
    customFieldNode2.set("scriptId", JsonNodeFactory.instance.textNode("custentity_field2"));
    customFieldNode2.set("value", JsonNodeFactory.instance.textNode("test123"));
    list1.add(customFieldNode2);
    CustomFieldList testCustomFieldList = converter1.convertToDatum(node1.toString());
    assertNotNull(testCustomFieldList);
    assertEquals(2, testCustomFieldList.getCustomField().size());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BooleanCustomFieldRef(com.netsuite.webservices.test.platform.core.BooleanCustomFieldRef) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CustomFieldList(com.netsuite.webservices.test.platform.core.CustomFieldList) StringCustomFieldRef(com.netsuite.webservices.test.platform.core.StringCustomFieldRef) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) 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