Search in sources :

Example 1 with RefType

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;
}
Also used : RefType(org.talend.components.netsuite.client.model.RefType) BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo)

Example 2 with RefType

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);
    }
}
Also used : CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) RefType(org.talend.components.netsuite.client.model.RefType) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Aggregations

RefType (org.talend.components.netsuite.client.model.RefType)2 ArrayList (java.util.ArrayList)1 Schema (org.apache.avro.Schema)1 ComponentException (org.talend.components.api.exception.ComponentException)1 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)1 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)1 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)1 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)1 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)1 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)1 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)1 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)1 BeanInfo (org.talend.components.netsuite.client.model.beans.BeanInfo)1 CustomFieldRefType (org.talend.components.netsuite.client.model.customfield.CustomFieldRefType)1