use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.
the class NsObjectInputTransducerTest method testDynamicSchemaWithCustomFields.
@Test
public void testDynamicSchemaWithCustomFields() throws Exception {
TestCustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService, "Opportunity");
clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
TypeDesc basicTypeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
final List<Opportunity> recordList = makeNsObjects(new NsObjectComposer<Opportunity>(clientService.getMetaDataSource(), basicTypeDesc), 10);
mockSearchRequestResults(recordList, 100);
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());
Schema schema = getDynamicSchema();
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);
}
}
use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.
the class DefaultMetaDataSource method getTypeInfo.
/**
* {@inheritDoc}
*/
@Override
public TypeDesc getTypeInfo(final String typeName) {
TypeDesc baseTypeDesc;
String targetTypeName = null;
Class<?> targetTypeClass;
List<FieldDesc> baseFieldDescList;
RecordTypeInfo recordTypeInfo = getRecordType(typeName);
if (recordTypeInfo != null) {
if (recordTypeInfo instanceof CustomRecordTypeInfo) {
CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(customRecordTypeInfo.getRecordType().getTypeName());
targetTypeName = customRecordTypeInfo.getName();
} else {
baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(typeName);
}
} else {
baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(typeName);
}
if (targetTypeName == null) {
targetTypeName = baseTypeDesc.getTypeName();
}
targetTypeClass = baseTypeDesc.getTypeClass();
baseFieldDescList = baseTypeDesc.getFields();
List<FieldDesc> resultFieldDescList = new ArrayList<>(baseFieldDescList.size() + 10);
// Add basic fields except field list containers (custom field list, null field list)
for (FieldDesc fieldDesc : baseFieldDescList) {
String fieldName = fieldDesc.getName();
if (fieldName.equals("customFieldList") || fieldName.equals("nullFieldList")) {
continue;
}
resultFieldDescList.add(fieldDesc);
}
if (recordTypeInfo != null) {
if (customizationEnabled) {
// Add custom fields
Map<String, CustomFieldDesc> customFieldMap = customMetaDataSource.getCustomFields(recordTypeInfo);
for (CustomFieldDesc fieldInfo : customFieldMap.values()) {
resultFieldDescList.add(fieldInfo);
}
}
}
return new TypeDesc(targetTypeName, targetTypeClass, resultFieldDescList);
}
use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.
the class NetSuiteOutputTransducerTest method testNonRecordObjects.
@Test
public void testNonRecordObjects() throws Exception {
NetSuiteRuntime netSuiteRuntime = new TestNetSuiteRuntimeImpl(webServiceMockTestFixture.getClientFactory());
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(mockTestFixture.getConnectionProperties());
Collection<String> typeNames = Arrays.asList(RefType.RECORD_REF.getTypeName(), RefType.CUSTOM_RECORD_REF.getTypeName());
for (String typeName : typeNames) {
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(typeName);
Schema schema = dataSetRuntime.getSchema(typeDesc.getTypeName());
NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), typeDesc.getTypeName());
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new AbstractNetSuiteTestBase.SimpleObjectComposer<>(typeDesc.getTypeClass()), 10);
for (IndexedRecord indexedRecord : indexedRecordList) {
Object nsObject = transducer.write(indexedRecord);
assertNsObject(typeDesc, nsObject);
}
}
}
use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.
the class NetSuiteOutputTransducerTest method testCustomRecordRef.
@Test
public void testCustomRecordRef() throws Exception {
CustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService);
clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
NetSuiteDatasetRuntime dataSetRuntime = new NetSuiteDatasetRuntimeImpl(clientService.getMetaDataSource());
mockGetRequestResults(null);
TypeDesc customTypeDesc = clientService.getMetaDataSource().getTypeInfo("custom_record_type_1");
Schema schema = dataSetRuntime.getSchemaForDelete(customTypeDesc.getTypeName());
NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), customTypeDesc.getTypeName());
transducer.setReference(true);
GenericRecord indexedRecordToAdd = new GenericData.Record(schema);
indexedRecordToAdd.put("InternalId", "123456789");
List<IndexedRecord> indexedRecordList = new ArrayList<>();
indexedRecordList.add(indexedRecordToAdd);
for (IndexedRecord indexedRecord : indexedRecordList) {
CustomRecordRef recordRef = (CustomRecordRef) transducer.write(indexedRecord);
assertNotNull(recordRef.getInternalId());
assertNotNull(recordRef.getTypeId());
}
}
use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.
the class NetSuiteSearchInputReaderTest method testBasic.
@Test
public void testBasic() throws Exception {
properties.module.moduleName.setValue("Account");
NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
properties.module.main.schema.setValue(schema);
NetSuiteSource source = new NetSuiteSourceImpl();
source.initialize(mockTestFixture.getRuntimeContainer(), properties);
List<Account> recordList = makeNsObjects(new SimpleObjectComposer<>(Account.class), 150);
mockSearchRequestResults(recordList, 100);
NetSuiteClientService<?> clientService = source.getClientService();
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(Account.class);
NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(mockTestFixture.getRuntimeContainer());
boolean started = reader.start();
assertTrue(started);
IndexedRecord record = reader.getCurrent();
assertNotNull(record);
while (reader.advance()) {
record = reader.getCurrent();
assertIndexedRecord(typeDesc, record);
}
Map<String, Object> readerResult = reader.getReturnValues();
assertNotNull(readerResult);
assertEquals(150, readerResult.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
}
Aggregations