use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSchemaForUpdateFlow.
@Override
public Schema getSchemaForUpdateFlow(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.TypeDesc 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.TypeDesc in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSearchInfo.
@Override
public SearchInfo getSearchInfo(String typeName) {
try {
final SearchRecordTypeDesc searchInfo = metaDataSource.getSearchRecordType(typeName);
final TypeDesc searchRecordInfo = metaDataSource.getBasicMetaData().getTypeInfo(searchInfo.getSearchBasicClass());
List<FieldDesc> fieldDescList = searchRecordInfo.getFields();
List<SearchFieldInfo> fields = new ArrayList<>(fieldDescList.size());
for (FieldDesc fieldDesc : fieldDescList) {
SearchFieldInfo field = new SearchFieldInfo(fieldDesc.getName(), fieldDesc.getValueType());
fields.add(field);
}
// Sort by display name in alphabetical order
Collections.sort(fields, new Comparator<SearchFieldInfo>() {
@Override
public int compare(SearchFieldInfo o1, SearchFieldInfo o2) {
return o1.getName().compareTo(o2.getName());
}
});
return new SearchInfo(searchRecordInfo.getTypeName(), fields);
} catch (NetSuiteException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.netsuite.client.model.TypeDesc 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.TypeDesc in project components by Talend.
the class NetSuiteClientServiceTest method testDeleteList.
@Test
public void testDeleteList() throws Exception {
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
List<RecordRef> recordRefList = makeNsObjects(new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc), 10);
DeleteListResponse response = new DeleteListResponse();
response.setWriteResponseList(createSuccessWriteResponseList(recordRefList.size()));
when(port.deleteList(notNull(DeleteListRequest.class))).thenReturn(response);
clientService.deleteList(recordRefList);
verify(port, times(1)).login(notNull(LoginRequest.class));
verify(port, times(1)).deleteList(notNull(DeleteListRequest.class));
List<NsWriteResponse<RecordRef>> writeResponses = clientService.deleteList(null);
assertTrue(writeResponses.isEmpty());
}
Aggregations