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;
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations