Search in sources :

Example 1 with CustomFieldRefType

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

the class BasicMetaDataTest method testGetCustomFieldRefType.

@Test
public void testGetCustomFieldRefType() {
    EntityCustomField entityCustomField1 = new EntityCustomField();
    entityCustomField1.setFieldType(CustomizationFieldType.FREE_FORM_TEXT);
    entityCustomField1.setAppliesToContact(true);
    entityCustomField1.setAppliesToVendor(true);
    CustomFieldRefType customFieldRefType = basicMetaData.getCustomFieldRefType(TestRecordTypeEnum.CONTACT.getType(), BasicRecordType.ENTITY_CUSTOM_FIELD, entityCustomField1);
    assertEquals(CustomFieldRefType.STRING, customFieldRefType);
    customFieldRefType = basicMetaData.getCustomFieldRefType(TestRecordTypeEnum.VENDOR.getType(), BasicRecordType.ENTITY_CUSTOM_FIELD, entityCustomField1);
    assertEquals(CustomFieldRefType.STRING, customFieldRefType);
    customFieldRefType = basicMetaData.getCustomFieldRefType(TestRecordTypeEnum.PARTNER.getType(), BasicRecordType.ENTITY_CUSTOM_FIELD, entityCustomField1);
    assertNull(customFieldRefType);
}
Also used : EntityCustomField(com.netsuite.webservices.test.setup.customization.EntityCustomField) CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) Test(org.junit.Test)

Example 2 with CustomFieldRefType

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

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

the class NsObjectTransducer method getValueConverter.

/**
 * Get value converter for given field descriptor.
 *
 * @param fieldDesc field descriptor
 * @return value converter
 */
public AvroConverter<?, ?> getValueConverter(FieldDesc fieldDesc) {
    Class<?> valueClass;
    if (fieldDesc instanceof CustomFieldDesc) {
        CustomFieldDesc customFieldDesc = (CustomFieldDesc) fieldDesc;
        CustomFieldRefType customFieldRefType = customFieldDesc.getCustomFieldType();
        valueClass = getCustomFieldValueConverterTargetClass(customFieldRefType);
    } else {
        valueClass = fieldDesc.getValueType();
    }
    AvroConverter<?, ?> converter = null;
    if (valueClass != null) {
        converter = getValueConverter(valueClass);
    }
    if (converter == null) {
        converter = new NullConverter(valueClass, null);
    }
    return converter;
}
Also used : NullConverter(org.talend.components.netsuite.avro.converter.NullConverter) CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc)

Example 4 with CustomFieldRefType

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

the class DefaultCustomMetaDataSource method createCustomFieldDescMap.

/**
 * Create custom field descriptors.
 *
 * @param recordType record type
 * @param customizationType customization type
 * @param customFieldList list of native NetSuite objects describing custom fields
 * @param <T> type of custom field data objects
 * @return custom field descriptors as map
 * @throws NetSuiteException if an error occurs during obtaining of customization data
 */
public static <T> Map<String, CustomFieldDesc> createCustomFieldDescMap(NetSuiteClientService<?> clientService, RecordTypeDesc recordType, BasicRecordType customizationType, List<T> customFieldList) throws NetSuiteException {
    Map<String, CustomFieldDesc> customFieldDescMap = new HashMap<>();
    for (T customField : customFieldList) {
        CustomFieldRefType customFieldRefType = clientService.getBasicMetaData().getCustomFieldRefType(recordType.getType(), customizationType, customField);
        if (customFieldRefType != null) {
            CustomFieldDesc customFieldDesc = new CustomFieldDesc();
            String internalId = (String) getSimpleProperty(customField, "internalId");
            String scriptId = (String) getSimpleProperty(customField, "scriptId");
            String label = (String) getSimpleProperty(customField, "label");
            NsRef customizationRef = new NsRef();
            customizationRef.setRefType(RefType.CUSTOMIZATION_REF);
            customizationRef.setType(customizationType.getType());
            customizationRef.setName(label);
            customizationRef.setInternalId(internalId);
            customizationRef.setScriptId(scriptId);
            customFieldDesc.setCustomizationRef(customizationRef);
            customFieldDesc.setName(customizationRef.getScriptId());
            customFieldDesc.setCustomFieldType(customFieldRefType);
            customFieldDesc.setValueType(getCustomFieldValueClass(customFieldRefType));
            customFieldDesc.setNullable(true);
            customFieldDescMap.put(customFieldDesc.getName(), customFieldDesc);
        }
    }
    return customFieldDescMap;
}
Also used : HashMap(java.util.HashMap) CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc)

Example 5 with CustomFieldRefType

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

the class NetSuiteDatasetRuntimeImpl method writeCustomField.

/**
 * Write custom field meta data to a given <code>JsonProperties</code>.
 *
 * @see NetSuiteSchemaConstants
 *
 * @param properties properties object which to write meta data to
 * @param fieldDesc information about custom field to be used
 */
public static void writeCustomField(JsonProperties properties, CustomFieldDesc fieldDesc) {
    NsRef ref = fieldDesc.getCustomizationRef();
    CustomFieldRefType customFieldRefType = fieldDesc.getCustomFieldType();
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_FIELD, "true");
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_FIELD_SCRIPT_ID, ref.getScriptId());
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_FIELD_INTERNAL_ID, ref.getInternalId());
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_FIELD_CUSTOMIZATION_TYPE, ref.getType());
    properties.addProp(NetSuiteSchemaConstants.NS_CUSTOM_FIELD_TYPE, customFieldRefType.name());
}
Also used : CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) NsRef(org.talend.components.netsuite.client.NsRef)

Aggregations

CustomFieldRefType (org.talend.components.netsuite.client.model.customfield.CustomFieldRefType)9 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)6 NsRef (org.talend.components.netsuite.client.NsRef)5 ArrayList (java.util.ArrayList)2 Schema (org.apache.avro.Schema)2 EntityCustomField (com.netsuite.webservices.test.setup.customization.EntityCustomField)1 HashMap (java.util.HashMap)1 List (java.util.List)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Test (org.junit.Test)1 NullConverter (org.talend.components.netsuite.avro.converter.NullConverter)1 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)1 AvroConverter (org.talend.daikon.avro.converter.AvroConverter)1