use of org.talend.components.netsuite.client.model.CustomFieldDesc in project components by Talend.
the class NetSuiteWebServiceMockTestFixture method assertIndexedRecord.
public static void assertIndexedRecord(TypeDesc typeDesc, IndexedRecord indexedRecord) throws Exception {
assertNotNull(indexedRecord);
Schema recordSchema = indexedRecord.getSchema();
assertEquals(typeDesc.getFields().size(), recordSchema.getFields().size());
for (Schema.Field field : recordSchema.getFields()) {
String nsFieldName = getNsFieldName(field);
FieldDesc fieldDesc = typeDesc.getField(nsFieldName);
assertNotNull(field);
Object value = indexedRecord.get(field.pos());
if (fieldDesc instanceof CustomFieldDesc) {
CustomFieldDesc customFieldDesc = fieldDesc.asCustom();
switch(customFieldDesc.getCustomFieldType()) {
case BOOLEAN:
case LONG:
case DOUBLE:
case STRING:
case DATE:
assertNotNull(value);
break;
}
} else {
Class<?> datumClass = fieldDesc.getValueType();
if (datumClass == Boolean.class || datumClass == Long.class || datumClass == Double.class || datumClass == String.class || datumClass == XMLGregorianCalendar.class) {
assertNotNull(value);
} else if (datumClass.isEnum()) {
assertNotNull(value);
Mapper<String, Enum> enumAccessor = Beans.getEnumFromStringMapper((Class<Enum>) datumClass);
Enum modelValue = enumAccessor.map((String) value);
assertNotNull(modelValue);
}
}
}
}
use of org.talend.components.netsuite.client.model.CustomFieldDesc in project components by Talend.
the class NsObjectTransducer method getMapView.
/**
* Build and get map of field values by names, including custom fields.
*
* <p>Custom fields in data model object are stored in separate {@code customFieldList} field
* as list of {@code CustomFieldRef} objects.
*
* @param nsObject NetSuite data model object which to extract field values from
* @param schema target schema
* @param typeDesc type descriptor
* @return table of fields' values by field names
*/
protected Map<String, Object> getMapView(Object nsObject, Schema schema, TypeDesc typeDesc) {
Map<String, Object> valueMap = new HashMap<>();
BeanInfo beanInfo = Beans.getBeanInfo(typeDesc.getTypeClass());
Map<String, FieldDesc> fieldMap = typeDesc.getFieldMap();
Map<String, CustomFieldDesc> customFieldMap = new HashMap<>();
for (Schema.Field field : schema.getFields()) {
// Get actual name of the field
String nsFieldName = NetSuiteDatasetRuntimeImpl.getNsFieldName(field);
FieldDesc fieldDesc = fieldMap.get(nsFieldName);
if (fieldDesc == null) {
continue;
}
if (fieldDesc instanceof CustomFieldDesc) {
// It's custom field, we will extract it in next stage.
customFieldMap.put(nsFieldName, (CustomFieldDesc) fieldDesc);
} else {
Object value = getSimpleProperty(nsObject, fieldDesc.getName());
valueMap.put(nsFieldName, value);
}
}
if (!customFieldMap.isEmpty() && beanInfo.getProperty("customFieldList") != null) {
List<?> customFieldList = (List<?>) getProperty(nsObject, "customFieldList.customField");
if (customFieldList != null && !customFieldList.isEmpty()) {
// Traverse all received custom fields and extract fields specified in schema
for (Object customField : customFieldList) {
String scriptId = (String) getSimpleProperty(customField, "scriptId");
CustomFieldDesc customFieldInfo = customFieldMap.get(scriptId);
if (customFieldInfo != null) {
String fieldName = customFieldInfo.getName();
valueMap.put(fieldName, customField);
}
}
}
}
return valueMap;
}
use of org.talend.components.netsuite.client.model.CustomFieldDesc in project components by Talend.
the class DefaultMetaDataSource method getTypeInfo.
/**
* {@inheritDoc}
*/
@Override
public TypeDesc getTypeInfo(final String typeName) {
TypeDesc baseTypeDesc;
String targetTypeName = null;
Class<?> targetTypeClass;
List<FieldDesc> baseFieldDescList;
RecordTypeInfo recordTypeInfo = getRecordType(typeName);
if (recordTypeInfo != null) {
if (recordTypeInfo instanceof CustomRecordTypeInfo) {
CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(customRecordTypeInfo.getRecordType().getTypeName());
targetTypeName = customRecordTypeInfo.getName();
} else {
baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(typeName);
}
} else {
baseTypeDesc = clientService.getBasicMetaData().getTypeInfo(typeName);
}
if (targetTypeName == null) {
targetTypeName = baseTypeDesc.getTypeName();
}
targetTypeClass = baseTypeDesc.getTypeClass();
baseFieldDescList = baseTypeDesc.getFields();
List<FieldDesc> resultFieldDescList = new ArrayList<>(baseFieldDescList.size() + 10);
// Add basic fields except field list containers (custom field list, null field list)
for (FieldDesc fieldDesc : baseFieldDescList) {
String fieldName = fieldDesc.getName();
if (fieldName.equals("customFieldList") || fieldName.equals("nullFieldList")) {
continue;
}
resultFieldDescList.add(fieldDesc);
}
if (recordTypeInfo != null) {
if (customizationEnabled) {
// Add custom fields
Map<String, CustomFieldDesc> customFieldMap = customMetaDataSource.getCustomFields(recordTypeInfo);
for (CustomFieldDesc fieldInfo : customFieldMap.values()) {
resultFieldDescList.add(fieldInfo);
}
}
}
return new TypeDesc(targetTypeName, targetTypeClass, resultFieldDescList);
}
use of org.talend.components.netsuite.client.model.CustomFieldDesc in project components by Talend.
the class DefaultCustomMetaDataSource method getCustomFieldsImpl.
/**
* Get custom field descriptors for a given record type.
*
* @param recordTypeInfo record type info
* @return custom field descriptors as map
* @throws NetSuiteException if an error occurs during obtaining of customization data
*/
protected Map<String, CustomFieldDesc> getCustomFieldsImpl(RecordTypeInfo recordTypeInfo) throws NetSuiteException {
RecordTypeDesc recordType = recordTypeInfo.getRecordType();
Map<String, CustomFieldDesc> fieldDescMap;
if (recordTypeInfo instanceof CustomRecordTypeInfo) {
fieldDescMap = customRecordCustomFieldMap.get(recordTypeInfo.getName());
if (fieldDescMap == null) {
retrieveCustomRecordCustomFields((CustomRecordTypeInfo) recordTypeInfo);
fieldDescMap = customRecordCustomFieldMap.get(recordTypeInfo.getName());
}
} else {
fieldDescMap = recordCustomFieldMap.get(recordType.getType());
if (fieldDescMap == null) {
retrieveCustomFields(recordType);
fieldDescMap = recordCustomFieldMap.get(recordType.getType());
}
}
return fieldDescMap;
}
use of org.talend.components.netsuite.client.model.CustomFieldDesc in project components by Talend.
the class NetSuiteOutputWriterIT method makeContactRecords.
private static List<Contact> makeContactRecords(int count, RecordRef subsidiary, Map<String, FieldDesc> fieldDescMap) {
CustomFieldDesc customFieldDesc1 = fieldDescMap.get("custentity_interest_bpm").asCustom();
List<Contact> recordList = new ArrayList<>(count);
for (int i = 1; i <= count; i++) {
Contact record = new Contact();
String id = Long.toString(System.currentTimeMillis());
record.setFirstName("AAA " + id);
record.setLastName("BBB " + id);
record.setPhone(id);
record.setEntityId(id);
record.setSubsidiary(subsidiary);
record.setCustomFieldList(new CustomFieldList());
BooleanCustomFieldRef customFieldRef1 = new BooleanCustomFieldRef();
customFieldRef1.setScriptId(customFieldDesc1.getCustomizationRef().getScriptId());
customFieldRef1.setInternalId(customFieldDesc1.getCustomizationRef().getInternalId());
customFieldRef1.setValue(true);
record.getCustomFieldList().getCustomField().add(customFieldRef1);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
recordList.add(record);
}
return recordList;
}
Aggregations