Search in sources :

Example 16 with CustomFieldDesc

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);
            }
        }
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Mapper(org.talend.components.netsuite.util.Mapper) Schema(org.apache.avro.Schema) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 17 with CustomFieldDesc

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;
}
Also used : HashMap(java.util.HashMap) BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) List(java.util.List) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) SimpleFieldDesc(org.talend.components.netsuite.client.model.SimpleFieldDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 18 with CustomFieldDesc

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);
}
Also used : CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 19 with CustomFieldDesc

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;
}
Also used : RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo)

Example 20 with CustomFieldDesc

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;
}
Also used : ArrayList(java.util.ArrayList) BooleanCustomFieldRef(com.netsuite.webservices.v2016_2.platform.core.BooleanCustomFieldRef) CustomFieldList(com.netsuite.webservices.v2016_2.platform.core.CustomFieldList) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) Contact(com.netsuite.webservices.v2016_2.lists.relationships.Contact)

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