Search in sources :

Example 6 with CustomFieldDesc

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

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

the class NsObjectTransducer method readField.

/**
 * Read a value from a field.
 *
 * @param valueMap map containing raw values by names
 * @param fieldDesc field descriptor
 * @return value of a field or <code>null</code>
 */
protected Object readField(Map<String, Object> valueMap, FieldDesc fieldDesc) {
    String fieldName = fieldDesc.getName();
    AvroConverter valueConverter = getValueConverter(fieldDesc);
    if (fieldDesc instanceof CustomFieldDesc) {
        Object customField = valueMap.get(fieldName);
        if (customField != null) {
            Object value = getSimpleProperty(customField, "value");
            return valueConverter.convertToAvro(value);
        }
        return null;
    } else {
        Object value = valueMap.get(fieldName);
        return valueConverter.convertToAvro(value);
    }
}
Also used : CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) AvroConverter(org.talend.daikon.avro.converter.AvroConverter)

Example 8 with CustomFieldDesc

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

the class DefaultCustomMetaDataSource method retrieveCustomFields.

/**
 * Retrieve custom fields for a given record type.
 *
 * @param recordType record type
 * @throws NetSuiteException if an error occurs during retrieving of customization data
 */
protected void retrieveCustomFields(RecordTypeDesc recordType) throws NetSuiteException {
    retrieveCustomFields();
    Map<String, CustomFieldDesc> fieldDescMap = new HashMap<>();
    for (BasicRecordType customizationType : fieldCustomizationTypes) {
        List<?> customFieldList = customFieldMap.get(customizationType);
        Map<String, CustomFieldDesc> customFieldDescMap = createCustomFieldDescMap(clientService, recordType, customizationType, customFieldList);
        fieldDescMap.putAll(customFieldDescMap);
    }
    recordCustomFieldMap.put(recordType.getType(), fieldDescMap);
}
Also used : HashMap(java.util.HashMap) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) BasicRecordType(org.talend.components.netsuite.client.model.BasicRecordType)

Example 9 with CustomFieldDesc

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

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

the class NetSuiteDatasetRuntimeImpl method getCustomFieldDescMap.

/**
 * Build and return map of custom field descriptors.
 *
 * @param fieldDescList list of custom field descriptors
 * @return map of custom field descriptors by names
 */
public static Map<String, CustomFieldDesc> getCustomFieldDescMap(Collection<FieldDesc> fieldDescList) {
    Map<String, CustomFieldDesc> customFieldDescMap = new HashMap<>();
    for (FieldDesc fieldDesc : fieldDescList) {
        if (fieldDesc instanceof CustomFieldDesc) {
            CustomFieldDesc customFieldDesc = fieldDesc.asCustom();
            customFieldDescMap.put(customFieldDesc.getName(), customFieldDesc);
        }
    }
    return customFieldDescMap;
}
Also used : HashMap(java.util.HashMap) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

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