Search in sources :

Example 1 with CustomRecordTypeInfo

use of org.talend.components.netsuite.client.model.CustomRecordTypeInfo 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 CustomRecordTypeInfo

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

the class CustomMetaDataSourceTest method testGetCustomRecordTypes.

@Test
public void testGetCustomRecordTypes() throws Exception {
    Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customRecordFieldSpecs = createCustomRecordFieldSpecs();
    CustomRecordType customRecordType = createCustomRecordType(customRecordFieldSpecs);
    customMetaDataRetriever.setCustomRecordType(customRecordType);
    customMetaDataRetriever.setCustomRecordFieldSpecs(customRecordFieldSpecs);
    Collection<CustomRecordTypeInfo> recordTypeInfos = customMetaDataSource.getCustomRecordTypes();
    assertNotNull(recordTypeInfos);
    assertEquals(1, recordTypeInfos.size());
    CustomRecordTypeInfo recordTypeInfo1 = recordTypeInfos.iterator().next();
    assertNotNull(recordTypeInfo1.getName());
    assertNotNull(recordTypeInfo1.getCustomizationRef());
    assertEquals(customRecordType.getScriptId(), recordTypeInfo1.getName());
    assertEquals(customRecordType.getScriptId(), recordTypeInfo1.getCustomizationRef().getScriptId());
    assertEquals(customRecordType.getInternalId(), recordTypeInfo1.getCustomizationRef().getInternalId());
}
Also used : CustomRecordType(com.netsuite.webservices.test.setup.customization.CustomRecordType) CustomFieldSpec(org.talend.components.netsuite.CustomFieldSpec) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Test(org.junit.Test)

Example 3 with CustomRecordTypeInfo

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

the class CustomMetaDataSourceTest method testGetCustomRecordType.

@Test
public void testGetCustomRecordType() throws Exception {
    Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customRecordFieldSpecs = createCustomRecordFieldSpecs();
    CustomRecordType customRecordType = createCustomRecordType(customRecordFieldSpecs);
    customMetaDataRetriever.setCustomRecordType(customRecordType);
    customMetaDataRetriever.setCustomRecordFieldSpecs(customRecordFieldSpecs);
    CustomRecordTypeInfo recordTypeInfo = customMetaDataSource.getCustomRecordType(customRecordType.getScriptId());
    assertNotNull(recordTypeInfo);
    Map<String, CustomFieldDesc> customFieldDescMap = customMetaDataSource.getCustomFields(recordTypeInfo);
    assertNotNull(customFieldDescMap);
    for (CustomFieldSpec customFieldSpec : customRecordFieldSpecs.values()) {
        CustomFieldDesc customFieldDesc = customFieldDescMap.get(customFieldSpec.getScriptId());
        assertNotNull(customFieldDesc);
        assertNotNull(customFieldDesc.getCustomizationRef());
        assertEquals(customFieldSpec.getScriptId(), customFieldDesc.getName());
        assertEquals(customFieldSpec.getInternalId(), customFieldDesc.getCustomizationRef().getInternalId());
    }
}
Also used : CustomRecordType(com.netsuite.webservices.test.setup.customization.CustomRecordType) CustomFieldSpec(org.talend.components.netsuite.CustomFieldSpec) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Test(org.junit.Test)

Example 4 with CustomRecordTypeInfo

use of org.talend.components.netsuite.client.model.CustomRecordTypeInfo 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 5 with CustomRecordTypeInfo

use of org.talend.components.netsuite.client.model.CustomRecordTypeInfo 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);
}
Also used : 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) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Aggregations

CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)12 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)8 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)6 ArrayList (java.util.ArrayList)5 Schema (org.apache.avro.Schema)4 NsRef (org.talend.components.netsuite.client.NsRef)4 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)4 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)4 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)3 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)3 CustomRecordType (com.netsuite.webservices.test.setup.customization.CustomRecordType)2 List (java.util.List)2 Test (org.junit.Test)2 CustomFieldSpec (org.talend.components.netsuite.CustomFieldSpec)2 BasicRecordType (org.talend.components.netsuite.client.model.BasicRecordType)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashSet (java.util.HashSet)1 BeanInfo (org.talend.components.netsuite.client.model.beans.BeanInfo)1