Search in sources :

Example 1 with CustomFieldDesc

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

the class TestUtils method readCustomFields.

public static Map<String, CustomFieldDesc> readCustomFields(JsonNode node) {
    Map<String, CustomFieldDesc> customFieldDescMap = new HashMap<>();
    for (int i = 0; i < node.size(); i++) {
        JsonNode fieldNode = node.get(i);
        CustomFieldDesc customFieldDesc = readCustomField(fieldNode);
        customFieldDescMap.put(customFieldDesc.getName(), customFieldDesc);
    }
    return customFieldDescMap;
}
Also used : HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc)

Example 2 with CustomFieldDesc

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

the class TestUtils method readCustomField.

public static CustomFieldDesc readCustomField(JsonNode node) {
    String scriptId = node.get("scriptId").asText();
    String internalId = node.get("internalId").asText();
    String customizationType = node.get("customizationType").asText();
    String type = node.get("valueType").asText();
    NsRef ref = new NsRef();
    ref.setRefType(RefType.CUSTOMIZATION_REF);
    ref.setScriptId(scriptId);
    ref.setInternalId(internalId);
    ref.setType(customizationType);
    CustomFieldRefType customFieldRefType = CustomFieldRefType.valueOf(type);
    CustomFieldDesc fieldDesc = new CustomFieldDesc();
    fieldDesc.setCustomFieldType(customFieldRefType);
    fieldDesc.setCustomizationRef(ref);
    fieldDesc.setName(scriptId);
    fieldDesc.setValueType(NetSuiteDatasetRuntimeImpl.getCustomFieldValueClass(customFieldRefType));
    fieldDesc.setNullable(true);
    return fieldDesc;
}
Also used : CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) NsRef(org.talend.components.netsuite.client.NsRef)

Example 3 with CustomFieldDesc

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

the class NetSuiteDatasetRuntimeTest method testGetSchemaForRecordWithCustomFields.

@Test
public void testGetSchemaForRecordWithCustomFields() throws Exception {
    final CustomMetaDataSource customMetaDataSource = new EmptyCustomMetaDataSource() {

        @Override
        public Map<String, CustomFieldDesc> getCustomFields(RecordTypeInfo recordTypeInfo) {
            try {
                if (recordTypeInfo.getName().equals("Account")) {
                    JsonNode fieldListNode = objectMapper.readTree(NetSuiteDatasetRuntimeTest.class.getResource("/test-data/customFields-1.json"));
                    Map<String, CustomFieldDesc> customFieldDescMap = TestUtils.readCustomFields(fieldListNode);
                    return customFieldDescMap;
                }
                return null;
            } catch (IOException e) {
                throw new NetSuiteException(e.getMessage(), e);
            }
        }
    };
    MetaDataSource metaDataSource = clientService.createDefaultMetaDataSource();
    metaDataSource.setCustomMetaDataSource(customMetaDataSource);
    NetSuiteDatasetRuntimeImpl datasetRuntime = new NetSuiteDatasetRuntimeImpl(metaDataSource);
    TypeDesc typeDesc = metaDataSource.getTypeInfo("Account");
    Schema s = datasetRuntime.getSchema(typeDesc.getTypeName());
    assertThat(s.getType(), is(Schema.Type.RECORD));
    assertThat(s.getName(), is("Account"));
    assertThat(s.getFields(), hasSize(typeDesc.getFields().size()));
    assertThat(s.getObjectProps().keySet(), Matchers.<String>empty());
    CustomFieldDesc fieldDesc = (CustomFieldDesc) typeDesc.getField("custom_field_1");
    Schema.Field f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.STRING, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE, NetSuiteSchemaConstants.NS_CUSTOM_FIELD, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_SCRIPT_ID, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_INTERNAL_ID, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_CUSTOMIZATION_TYPE, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    CustomFieldDesc customFieldDesc = NetSuiteDatasetRuntimeImpl.readCustomField(f);
    assertThat(customFieldDesc.getName(), is(fieldDesc.getName()));
}
Also used : EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) IOException(java.io.IOException) EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) MetaDataSource(org.talend.components.netsuite.client.MetaDataSource) EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) Test(org.junit.Test)

Example 4 with CustomFieldDesc

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

the class CustomMetaDataSourceTest method testGetCustomFields.

@Test
public void testGetCustomFields() {
    Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs = createCustomFieldSpecs();
    customMetaDataRetriever.setCustomFieldSpecs(customFieldSpecs);
    RecordTypeInfo recordTypeInfo = clientService.getMetaDataSource().getRecordType(TestRecordTypeEnum.OPPORTUNITY.getTypeName());
    Map<String, CustomFieldDesc> customFieldDescMap = customMetaDataSource.getCustomFields(recordTypeInfo);
    assertNotNull(customFieldDescMap);
    for (CustomFieldSpec customFieldSpec : customFieldSpecs.values()) {
        CustomFieldDesc customFieldDesc = customFieldDescMap.get(customFieldSpec.getScriptId());
        assertNotNull(customFieldDesc);
        assertNotNull(customFieldDesc.getCustomizationRef());
        assertEquals(customFieldSpec.getScriptId(), customFieldDesc.getName());
        assertEquals(customFieldSpec.getInternalId(), customFieldDesc.getCustomizationRef().getInternalId());
    }
    CustomFieldDesc customFieldDesc = customFieldDescMap.get("custbody_field1");
    assertNotNull(customFieldDesc);
    assertEquals(CustomFieldRefType.BOOLEAN, customFieldDesc.getCustomFieldType());
    assertEquals(TestRecordTypeEnum.TRANSACTION_BODY_CUSTOM_FIELD.getType(), customFieldDesc.getCustomizationRef().getType());
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldSpec(org.talend.components.netsuite.CustomFieldSpec) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) Test(org.junit.Test)

Example 5 with CustomFieldDesc

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

Aggregations

CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)21 Schema (org.apache.avro.Schema)6 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)6 CustomFieldRefType (org.talend.components.netsuite.client.model.customfield.CustomFieldRefType)6 HashMap (java.util.HashMap)5 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)5 ArrayList (java.util.ArrayList)4 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 Test (org.junit.Test)3 NsRef (org.talend.components.netsuite.client.NsRef)3 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 CustomFieldSpec (org.talend.components.netsuite.CustomFieldSpec)2 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)2 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)2 CustomRecordType (com.netsuite.webservices.test.setup.customization.CustomRecordType)1 Contact (com.netsuite.webservices.v2016_2.lists.relationships.Contact)1 BooleanCustomFieldRef (com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef)1 CustomFieldList (com.netsuite.webservices.v2016_2.platform.core.CustomFieldList)1 CustomRecordType (com.netsuite.webservices.v2016_2.setup.customization.CustomRecordType)1