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);
}
}
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);
}
}
}
}
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);
}
}
}
}
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());
}
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());
}
Aggregations