use of org.talend.components.netsuite.client.model.RefType in project components by Talend.
the class NsRef method fromNativeRef.
/**
* Create ref object from NetSuite's native ref data object.
*
* @param ref native ref data object
* @return ref object
*/
public static NsRef fromNativeRef(Object ref) {
String typeName = ref.getClass().getSimpleName();
RefType refType = RefType.getByTypeName(typeName);
NsRef nsRef = new NsRef();
nsRef.setRefType(refType);
BeanInfo beanInfo = Beans.getBeanInfo(ref.getClass());
nsRef.setInternalId((String) getSimpleProperty(ref, "internalId"));
nsRef.setExternalId((String) getSimpleProperty(ref, "externalId"));
if (refType == RefType.RECORD_REF) {
nsRef.setType(Beans.getEnumAccessor((Class<Enum>) beanInfo.getProperty("type").getReadType()).getStringValue((Enum) getSimpleProperty(ref, "type")));
} else if (refType == RefType.CUSTOM_RECORD_REF) {
nsRef.setTypeId((String) getSimpleProperty(ref, "typeId"));
} else if (refType == RefType.CUSTOMIZATION_REF) {
nsRef.setScriptId((String) getSimpleProperty(ref, "scriptId"));
}
return nsRef;
}
use of org.talend.components.netsuite.client.model.RefType in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSchemaForRecordRef.
public Schema getSchemaForRecordRef(String typeName) {
try {
// Get info for target record type
final RecordTypeInfo referencedRecordTypeInfo = metaDataSource.getRecordType(typeName);
final RefType refType = referencedRecordTypeInfo.getRefType();
// Get type info for record ref
final TypeDesc typeDesc = metaDataSource.getTypeInfo(refType.getTypeName());
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, referencedRecordTypeInfo, null);
return schema;
} catch (NetSuiteException e) {
throw new ComponentException(e);
}
}
Aggregations