use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.
the class SearchResultSetTest method testPagination.
@Test
public void testPagination() throws Exception {
NetSuiteClientService<?> conn = mock(NetSuiteClientService.class);
List<Record> page1 = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
page1.add(new Account());
}
List<Record> page2 = new ArrayList<>();
for (int i = 0; i < 750; i++) {
page2.add(new Account());
}
SearchResult result1 = new SearchResult();
Status status = new Status();
status.setIsSuccess(true);
result1.setStatus(status);
result1.setSearchId("abc123");
result1.setPageIndex(1);
result1.setTotalRecords(page1.size() + page2.size());
result1.setTotalPages(2);
result1.setRecordList(new RecordList());
result1.getRecordList().getRecord().addAll(page1);
SearchResult result2 = new SearchResult();
result2.setStatus(status);
result2.setSearchId(result1.getSearchId());
result2.setPageIndex(2);
result2.setTotalRecords(result1.getTotalRecords());
result2.setTotalPages(result1.getTotalPages());
result2.setRecordList(new RecordList());
result2.getRecordList().getRecord().addAll(page2);
SearchResponse response1 = new SearchResponse();
response1.setSearchResult(result1);
SearchMoreWithIdResponse response2 = new SearchMoreWithIdResponse();
response2.setSearchResult(result2);
AccountSearch nsSearchRecord1 = new AccountSearch();
NsSearchResult nsSearchResult1 = TestNetSuiteClientService.toNsSearchResult(result1);
NsSearchResult nsSearchResult2 = TestNetSuiteClientService.toNsSearchResult(result2);
when(conn.search(eq(nsSearchRecord1))).thenReturn(nsSearchResult1);
when(conn.searchMoreWithId(eq("abc123"), eq(2))).thenReturn(nsSearchResult2);
NetSuiteClientService<?> clientService = new TestNetSuiteClientService();
RecordTypeInfo recordTypeInfo = clientService.getMetaDataSource().getRecordType("Account");
SearchRecordTypeDesc searchRecordTypeDesc = clientService.getMetaDataSource().getSearchRecordType(recordTypeInfo.getRecordType().getSearchRecordType());
SearchResultSet<Record> resultSet = new SearchResultSet<>(conn, recordTypeInfo.getRecordType(), searchRecordTypeDesc, nsSearchResult1);
List<Object> recordList = new ArrayList<>();
while (resultSet.next()) {
Object record = resultSet.get();
assertNotNull(record);
recordList.add(record);
}
assertEquals(page1.size() + page2.size(), recordList.size());
}
use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.
the class NetSuiteSearchInputReader method search.
/**
* Build and execute NetSuite search query.
*
* @return
* @throws NetSuiteException if an error occurs during execution of search
*/
private ResultSet<?> search() throws NetSuiteException {
SearchQuery search = buildSearchQuery();
RecordTypeInfo recordTypeInfo = search.getRecordTypeInfo();
// Set up object translator
transducer = new NsObjectInputTransducer(clientService, schema, recordTypeInfo.getName());
transducer.setMetaDataSource(metaDataSource);
transducer.setApiVersion(properties.connection.apiVersion.getValue());
ResultSet<?> resultSet = search.search();
return resultSet;
}
use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.
the class NsObjectTransducer method getDynamicSchema.
/**
* Get dynamic schema using given type descriptor and design schema.
*
* @param typeDesc NetSuite data model object type descriptor
* @param designSchema design schema
* @param targetSchemaName name of target schema
* @return schema with all fields
*/
protected Schema getDynamicSchema(TypeDesc typeDesc, Schema designSchema, String targetSchemaName) {
RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeDesc.getTypeName());
Map<String, FieldDesc> fieldMap = typeDesc.getFieldMap();
String dynamicPosProp = designSchema.getProp(NetSuiteSchemaConstants.TALEND6_DYNAMIC_COLUMN_POSITION);
List<Schema.Field> fields = new ArrayList<>();
if (dynamicPosProp != null) {
Set<String> designFieldNames = new HashSet<>(designSchema.getFields().size());
for (Schema.Field field : designSchema.getFields()) {
String fieldName = NetSuiteDatasetRuntimeImpl.getNsFieldName(field);
designFieldNames.add(fieldName);
}
int dynPos = Integer.parseInt(dynamicPosProp);
int dynamicColumnSize = fieldMap.size() - designSchema.getFields().size();
List<FieldDesc> dynaFieldDescList = new ArrayList<>(dynamicColumnSize);
for (FieldDesc fieldDesc : fieldMap.values()) {
String fieldName = fieldDesc.getName();
if (!designFieldNames.contains(fieldName)) {
dynaFieldDescList.add(fieldDesc);
}
}
if (designSchema.getFields().size() > 0) {
for (Schema.Field field : designSchema.getFields()) {
// Dynamic column is first or middle column in design schema
if (dynPos == field.pos()) {
for (int i = 0; i < dynamicColumnSize; i++) {
// Add dynamic schema fields
FieldDesc fieldDesc = dynaFieldDescList.get(i);
fields.add(createSchemaField(fieldDesc));
}
}
// Add fields of design schema
Schema.Field avroField = new Schema.Field(field.name(), field.schema(), null, field.defaultVal());
Map<String, Object> fieldProps = field.getObjectProps();
for (String propName : fieldProps.keySet()) {
Object propValue = fieldProps.get(propName);
if (propValue != null) {
avroField.addProp(propName, propValue);
}
}
fields.add(avroField);
// Dynamic column is last column in design schema
if (field.pos() == (designSchema.getFields().size() - 1) && dynPos == (field.pos() + 1)) {
for (int i = 0; i < dynamicColumnSize; i++) {
// Add dynamic schema fields
FieldDesc fieldDesc = dynaFieldDescList.get(i);
fields.add(createSchemaField(fieldDesc));
}
}
}
} else {
// All fields are included in dynamic schema
for (String fieldName : fieldMap.keySet()) {
FieldDesc fieldDesc = fieldMap.get(fieldName);
fields.add(createSchemaField(fieldDesc));
}
}
} else {
// All fields are included in dynamic schema
for (String fieldName : fieldMap.keySet()) {
FieldDesc fieldDesc = fieldMap.get(fieldName);
fields.add(createSchemaField(fieldDesc));
}
}
Schema schema = Schema.createRecord(targetSchemaName, null, null, false, fields);
NetSuiteDatasetRuntimeImpl.augmentSchemaWithCustomMetaData(metaDataSource, schema, recordTypeInfo, typeDesc.getFields());
return schema;
}
use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.
the class DefaultMetaDataSource method getRecordTypes.
/**
* {@inheritDoc}
*/
@Override
public Collection<RecordTypeInfo> getRecordTypes() {
List<RecordTypeInfo> recordTypes = new ArrayList<>();
Collection<RecordTypeDesc> standardRecordTypes = clientService.getBasicMetaData().getRecordTypes();
for (RecordTypeDesc recordType : standardRecordTypes) {
recordTypes.add(new RecordTypeInfo(recordType));
}
if (customizationEnabled) {
recordTypes.addAll(customMetaDataSource.getCustomRecordTypes());
}
return recordTypes;
}
use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.
the class DefaultMetaDataSource method getSearchRecordType.
/**
* {@inheritDoc}
*/
@Override
public SearchRecordTypeDesc getSearchRecordType(String recordTypeName) {
SearchRecordTypeDesc searchRecordType = clientService.getBasicMetaData().getSearchRecordType(recordTypeName);
if (searchRecordType != null) {
return searchRecordType;
}
RecordTypeInfo recordTypeInfo = getRecordType(recordTypeName);
if (recordTypeInfo != null) {
return getSearchRecordType(recordTypeInfo.getRecordType());
}
return null;
}
Aggregations