Search in sources :

Example 1 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class TestUtils method readCustomRecord.

public static CustomRecordTypeInfo readCustomRecord(BasicMetaData basicMetaData, JsonNode node) {
    String scriptId = node.get("scriptId").asText();
    String internalId = node.get("internalId").asText();
    String customizationType = node.get("customizationType").asText();
    String recordType = node.get("recordType").asText();
    NsRef ref = new NsRef();
    ref.setRefType(RefType.CUSTOMIZATION_REF);
    ref.setScriptId(scriptId);
    ref.setInternalId(internalId);
    ref.setType(customizationType);
    RecordTypeDesc recordTypeDesc = basicMetaData.getRecordType(recordType);
    CustomRecordTypeInfo recordTypeInfo = new CustomRecordTypeInfo(scriptId, recordTypeDesc, ref);
    return recordTypeInfo;
}
Also used : RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) NsRef(org.talend.components.netsuite.client.NsRef) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo)

Example 2 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class MetaDataSourceTest method testGetRecordTypes.

@Test
public void testGetRecordTypes() {
    Collection<RecordTypeInfo> recordTypeInfos = metaDataSource.getRecordTypes();
    assertNotNull(recordTypeInfos);
    assertFalse(recordTypeInfos.isEmpty());
    Set<String> recordTypeNames = new HashSet<>();
    for (RecordTypeInfo recordTypeInfo : recordTypeInfos) {
        assertNotNull(recordTypeInfo);
        recordTypeNames.add(recordTypeInfo.getName());
    }
    for (RecordTypeDesc recordTypeDesc : TestRecordTypeEnum.values()) {
        assertTrue(recordTypeNames.contains(recordTypeDesc.getTypeName()));
    }
    for (RecordTypeInfo recordTypeInfo : customMetaDataSource.getCustomRecordTypes()) {
        assertTrue(recordTypeNames.contains(recordTypeInfo.getName()));
    }
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class NsObjectOutputTransducer method write.

/**
 * Translate input {@code IndexedRecord} to output NetSuite data object.
 *
 * @param indexedRecord indexed record to be processed
 * @return NetSuite data object
 */
public Object write(IndexedRecord indexedRecord) {
    prepare();
    Map<String, FieldDesc> fieldMap = typeDesc.getFieldMap();
    BeanInfo beanInfo = Beans.getBeanInfo(typeDesc.getTypeClass());
    Schema schema = indexedRecord.getSchema();
    String targetTypeName;
    if (recordTypeInfo != null && !reference) {
        RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
        targetTypeName = recordTypeDesc.getTypeName();
    } else {
        targetTypeName = typeDesc.getTypeName();
    }
    Object nsObject = clientService.getBasicMetaData().createInstance(targetTypeName);
    // Names of fields to be null'ed.
    Set<String> nullFieldNames = new HashSet<>();
    // Custom fields by names.
    Map<String, Object> customFieldMap = Collections.emptyMap();
    if (!reference && beanInfo.getProperty("customFieldList") != null) {
        customFieldMap = new HashMap<>();
        Object customFieldListWrapper = getSimpleProperty(nsObject, "customFieldList");
        if (customFieldListWrapper != null) {
            List<Object> customFieldList = (List<Object>) getSimpleProperty(customFieldListWrapper, "customField");
            for (Object customField : customFieldList) {
                String scriptId = (String) getSimpleProperty(customField, "scriptId");
                customFieldMap.put(scriptId, customField);
            }
        }
    }
    for (Schema.Field field : schema.getFields()) {
        String nsFieldName = NetSuiteDatasetRuntimeImpl.getNsFieldName(field);
        FieldDesc fieldDesc = fieldMap.get(nsFieldName);
        if (fieldDesc == null) {
            continue;
        }
        Object value = indexedRecord.get(field.pos());
        writeField(nsObject, fieldDesc, customFieldMap, nullFieldNames, value);
    }
    if (reference) {
        if (recordTypeInfo.getRefType() == RefType.RECORD_REF) {
            FieldDesc recTypeFieldDesc = typeDesc.getField("type");
            RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
            nullFieldNames.remove("type");
            writeSimpleField(nsObject, recTypeFieldDesc.asSimple(), false, nullFieldNames, recordTypeDesc.getType());
        } else if (recordTypeInfo.getRefType() == RefType.CUSTOM_RECORD_REF) {
            CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
            NsRef customizationRef = customRecordTypeInfo.getCustomizationRef();
            FieldDesc typeIdFieldDesc = typeDesc.getField("typeId");
            nullFieldNames.remove("typeId");
            writeSimpleField(nsObject, typeIdFieldDesc.asSimple(), false, nullFieldNames, customizationRef.getInternalId());
        }
    } else if (recordTypeInfo != null) {
        RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
        if (recordTypeDesc.getType().equals(BasicRecordType.CUSTOM_RECORD.getType())) {
            CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
            FieldDesc recTypeFieldDesc = typeDesc.getField("recType");
            NsRef recordTypeRef = customRecordTypeInfo.getCustomizationRef();
            // Create custom record type ref as JSON to create native RecordRef
            ObjectNode recordRefNode = JsonNodeFactory.instance.objectNode();
            recordRefNode.set("internalId", JsonNodeFactory.instance.textNode(recordTypeRef.getInternalId()));
            recordRefNode.set("type", JsonNodeFactory.instance.textNode(recordTypeDesc.getType()));
            nullFieldNames.remove("recType");
            writeSimpleField(nsObject, recTypeFieldDesc.asSimple(), false, nullFieldNames, recordRefNode.toString());
        }
    }
    if (!nullFieldNames.isEmpty() && beanInfo.getProperty("nullFieldList") != null) {
        Object nullFieldListWrapper = clientService.getBasicMetaData().createInstance("NullField");
        setSimpleProperty(nsObject, "nullFieldList", nullFieldListWrapper);
        List<String> nullFields = (List<String>) getSimpleProperty(nullFieldListWrapper, "name");
        nullFields.addAll(nullFieldNames);
    }
    return nsObject;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) Schema(org.apache.avro.Schema) NsRef(org.talend.components.netsuite.client.NsRef) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) List(java.util.List) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) HashSet(java.util.HashSet)

Example 4 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class DefaultMetaDataSource method getSearchableTypes.

/**
 * {@inheritDoc}
 */
@Override
public Collection<NamedThing> getSearchableTypes() {
    List<NamedThing> searchableTypes = new ArrayList<>(256);
    Collection<RecordTypeInfo> recordTypes = getRecordTypes();
    for (RecordTypeInfo recordTypeInfo : recordTypes) {
        RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
        if (recordTypeDesc.getSearchRecordType() != null) {
            SearchRecordTypeDesc searchRecordType = clientService.getBasicMetaData().getSearchRecordType(recordTypeDesc);
            if (searchRecordType != null) {
                searchableTypes.add(new SimpleNamedThing(recordTypeInfo.getName(), recordTypeInfo.getDisplayName()));
            }
        }
    }
    return searchableTypes;
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing)

Example 5 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class NetSuiteDatasetRuntimeImpl method writeCustomRecord.

/**
 * Write custom record meta data to a given <code>JsonProperties</code>.
 *
 * @see NetSuiteSchemaConstants
 *
 * @param basicMetaData basic meta data
 * @param properties properties object which to write meta data to
 * @param recordTypeInfo information about record type to be used
 */
public static void writeCustomRecord(BasicMetaData basicMetaData, JsonProperties properties, CustomRecordTypeInfo recordTypeInfo) {
    NsRef ref = recordTypeInfo.getCustomizationRef();
    RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD, "true");
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD_SCRIPT_ID, ref.getScriptId());
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD_INTERNAL_ID, ref.getInternalId());
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD_CUSTOMIZATION_TYPE, ref.getType());
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD_TYPE, recordTypeDesc.getType());
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) NsRef(org.talend.components.netsuite.client.NsRef)

Aggregations

RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)11 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)7 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)7 NsRef (org.talend.components.netsuite.client.NsRef)4 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 NamedThing (org.talend.daikon.NamedThing)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 List (java.util.List)1 Schema (org.apache.avro.Schema)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 BasicRecordType (org.talend.components.netsuite.client.model.BasicRecordType)1 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)1 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)1 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)1 BeanInfo (org.talend.components.netsuite.client.model.beans.BeanInfo)1 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)1