use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSchemaForDeleteFlow.
@Override
public Schema getSchemaForDeleteFlow(String typeName, Schema schema) {
RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
// We should check and add key fields:
// internalId, externalId and scriptId (for custom record type)
List<FieldDesc> fieldDescList = new ArrayList<>();
Schema.Field internalIdField = getNsFieldByName(schema, "internalId");
if (internalIdField == null) {
FieldDesc fieldDesc = typeDesc.getField("internalId");
fieldDescList.add(fieldDesc);
}
Schema.Field externalIdField = getNsFieldByName(schema, "externalId");
if (externalIdField == null) {
FieldDesc fieldDesc = typeDesc.getField("externalId");
fieldDescList.add(fieldDesc);
}
if (recordTypeInfo instanceof CustomRecordTypeInfo) {
Schema.Field scriptIdField = getNsFieldByName(schema, "scriptId");
if (scriptIdField == null) {
FieldDesc fieldDesc = typeDesc.getField("scriptId");
if (fieldDesc != null) {
fieldDescList.add(fieldDesc);
}
}
}
// Create schema fields for mandatory fields.
List<Schema.Field> fields = new ArrayList<>();
Schema.Field f;
if (!fieldDescList.isEmpty()) {
Schema schemaToAdd = inferSchemaForType(typeName, fieldDescList);
for (Schema.Field sourceField : schemaToAdd.getFields()) {
f = copyField(sourceField);
f.addProp(SchemaConstants.TALEND_FIELD_GENERATED, "true");
f.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
fields.add(f);
}
}
return extendSchema(schema, typeName + "_FLOW", fields);
}
use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getRecordTypes.
@Override
public List<NamedThing> getRecordTypes() {
try {
Collection<RecordTypeInfo> recordTypeList = metaDataSource.getRecordTypes();
List<NamedThing> recordTypes = new ArrayList<>(recordTypeList.size());
for (RecordTypeInfo recordTypeInfo : recordTypeList) {
recordTypes.add(new SimpleNamedThing(recordTypeInfo.getName(), recordTypeInfo.getDisplayName()));
}
// Sort by display name in alphabetical order
Collections.sort(recordTypes, new Comparator<NamedThing>() {
@Override
public int compare(NamedThing o1, NamedThing o2) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
});
return recordTypes;
} catch (NetSuiteException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.netsuite.client.model.RecordTypeInfo 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.RecordTypeInfo in project components by Talend.
the class MetaDataSourceTest method testGetSearchableTypes.
@Test
public void testGetSearchableTypes() {
Collection<NamedThing> searchableTypeNamedThings = metaDataSource.getSearchableTypes();
assertNotNull(searchableTypeNamedThings);
assertFalse(searchableTypeNamedThings.isEmpty());
Set<String> searchableTypeNames = new HashSet<>();
for (NamedThing namedThing : searchableTypeNamedThings) {
assertNotNull(namedThing);
searchableTypeNames.add(namedThing.getName());
}
for (RecordTypeDesc recordTypeDesc : TestRecordTypeEnum.values()) {
if (recordTypeDesc.getSearchRecordType() != null) {
assertTrue(recordTypeDesc.getTypeName(), searchableTypeNames.contains(recordTypeDesc.getTypeName()));
}
}
for (RecordTypeInfo recordTypeInfo : customMetaDataSource.getCustomRecordTypes()) {
assertTrue(recordTypeInfo.getName(), searchableTypeNames.contains(recordTypeInfo.getName()));
}
}
use of org.talend.components.netsuite.client.model.RecordTypeInfo in project components by Talend.
the class SearchResultSetTest method testRecordFiltering.
@Test
public void testRecordFiltering() throws Exception {
NetSuiteClientService<?> conn = mock(NetSuiteClientService.class);
List<Record> page1 = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
page1.add(new InventoryItem());
}
List<Record> page2 = new ArrayList<>();
for (int i = 0; i < 750; i++) {
page2.add(new ServiceSaleItem());
}
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);
ItemSearch nsSearchRecord1 = new ItemSearch();
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("InventoryItem");
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(), recordList.size());
}
Aggregations