use of org.talend.components.netsuite.input.NsObjectInputTransducer in project components by Talend.
the class NetSuiteMockTestBase method makeIndexedRecords.
public static <T> List<IndexedRecord> makeIndexedRecords(NetSuiteClientService<?> clientService, Schema schema, AbstractNetSuiteTestBase.ObjectComposer<T> objectComposer, int count) throws Exception {
NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, schema.getName());
List<IndexedRecord> recordList = new ArrayList<>();
while (count > 0) {
T nsRecord = objectComposer.composeObject();
IndexedRecord convertedRecord = transducer.read(nsRecord);
Schema recordSchema = convertedRecord.getSchema();
GenericRecord record = new GenericData.Record(recordSchema);
for (Schema.Field field : schema.getFields()) {
Object value = convertedRecord.get(field.pos());
record.put(field.pos(), value);
}
recordList.add(record);
count--;
}
return recordList;
}
use of org.talend.components.netsuite.input.NsObjectInputTransducer 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");
}
}
use of org.talend.components.netsuite.input.NsObjectInputTransducer in project components by Talend.
the class NsObjectInputTransducerIT method testBasic.
@Test
public void testBasic() throws Exception {
NetSuiteClientService<?> connection = webServiceTestFixture.getClientService();
connection.login();
TypeDesc typeDesc = connection.getMetaDataSource().getTypeInfo("Opportunity");
Schema schema = NetSuiteDatasetRuntimeImpl.inferSchemaForType(typeDesc.getTypeName(), typeDesc.getFields());
NsObjectInputTransducer transducer = new NsObjectInputTransducer(connection, schema, typeDesc.getTypeName());
SearchResultSet<Record> rs = connection.newSearch().target(typeDesc.getTypeName()).search();
if (!rs.next()) {
throw new IllegalStateException("No records");
}
Record record = rs.get();
IndexedRecord indexedRecord = transducer.read(record);
logger.debug("Indexed record: {}", indexedRecord);
}
use of org.talend.components.netsuite.input.NsObjectInputTransducer in project components by Talend.
the class NetSuiteMockTestBase method makeIndexedRecords.
public static <T> List<IndexedRecord> makeIndexedRecords(NetSuiteClientService<?> clientService, Schema schema, ObjectComposer<T> objectComposer, int count) throws Exception {
NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, schema.getName());
List<IndexedRecord> recordList = new ArrayList<>();
while (count > 0) {
T nsRecord = objectComposer.composeObject();
IndexedRecord convertedRecord = transducer.read(nsRecord);
Schema recordSchema = convertedRecord.getSchema();
GenericRecord record = new GenericData.Record(recordSchema);
for (Schema.Field field : schema.getFields()) {
Object value = convertedRecord.get(field.pos());
record.put(field.pos(), value);
}
recordList.add(record);
count--;
}
return recordList;
}
Aggregations