use of org.talend.components.netsuite.client.model.FieldDesc in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSchema.
@Override
public Schema getSchema(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, fieldDescList);
return schema;
} catch (NetSuiteException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.netsuite.client.model.FieldDesc 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.FieldDesc 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.FieldDesc in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method inferSchemaForType.
/**
* Infers an Avro schema for the given type. This can be an expensive operation so the schema
* should be cached where possible. This is always an {@link Schema.Type#RECORD}.
*
* @param name name of a record.
* @return the schema for data given from the object.
*/
public static Schema inferSchemaForType(String name, List<FieldDesc> fieldDescList) {
List<Schema.Field> fields = new ArrayList<>();
for (FieldDesc fieldDesc : fieldDescList) {
final String fieldName = fieldDesc.getName();
final String avroFieldName = toInitialUpper(fieldName);
Schema.Field avroField = new Schema.Field(avroFieldName, inferSchemaForField(fieldDesc), null, (Object) null);
// Add some Talend6 custom properties to the schema.
Schema avroFieldSchema = AvroUtils.unwrapIfNullable(avroField.schema());
avroField.addProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, fieldDesc.getName());
if (AvroUtils.isSameType(avroFieldSchema, AvroUtils._string())) {
if (fieldDesc.getLength() != 0) {
avroField.addProp(SchemaConstants.TALEND_COLUMN_DB_LENGTH, String.valueOf(fieldDesc.getLength()));
}
}
if (fieldDesc instanceof CustomFieldDesc) {
CustomFieldDesc customFieldInfo = (CustomFieldDesc) fieldDesc;
CustomFieldRefType customFieldRefType = customFieldInfo.getCustomFieldType();
avroField.addProp(SchemaConstants.TALEND_COLUMN_DB_TYPE, customFieldRefType.getTypeName());
if (customFieldRefType == CustomFieldRefType.DATE) {
avroField.addProp(SchemaConstants.TALEND_COLUMN_PATTERN, "yyyy-MM-dd'T'HH:mm:ss'.000Z'");
}
NsRef ref = customFieldInfo.getCustomizationRef();
if (StringUtils.isNotEmpty(ref.getName())) {
avroField.addProp(NetSuiteSchemaConstants.TALEND6_COMMENT, ref.getName());
}
} else {
Class<?> fieldType = fieldDesc.getValueType();
avroField.addProp(SchemaConstants.TALEND_COLUMN_DB_TYPE, fieldType.getSimpleName());
if (fieldType == XMLGregorianCalendar.class) {
avroField.addProp(SchemaConstants.TALEND_COLUMN_PATTERN, "yyyy-MM-dd'T'HH:mm:ss'.000Z'");
}
}
if (avroField.defaultVal() != null) {
avroField.addProp(SchemaConstants.TALEND_COLUMN_DEFAULT, String.valueOf(avroField.defaultVal()));
}
if (fieldDesc.isKey()) {
avroField.addProp(SchemaConstants.TALEND_COLUMN_IS_KEY, Boolean.TRUE.toString());
}
fields.add(avroField);
}
return Schema.createRecord(name, null, null, false, fields);
}
use of org.talend.components.netsuite.client.model.FieldDesc 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);
}
}
Aggregations