Search in sources :

Example 1 with BeanInfo

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

the class NetSuiteMockTestBase method createCustomFieldRefs.

protected Map<String, CustomFieldRef> createCustomFieldRefs(Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs) throws Exception {
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    Map<String, CustomFieldRef> map = new HashMap<>();
    for (CustomFieldSpec<RecordType, CustomizationFieldType> spec : customFieldSpecs.values()) {
        CustomFieldRef fieldRef = clientService.getBasicMetaData().createInstance(spec.getFieldRefType().getTypeName());
        fieldRef.setScriptId(spec.getScriptId());
        fieldRef.setInternalId(spec.getInternalId());
        BeanInfo beanInfo = Beans.getBeanInfo(fieldRef.getClass());
        PropertyInfo valuePropInfo = beanInfo.getProperty("value");
        Object value = composeValue(valuePropInfo.getWriteType());
        if (value != null) {
            Beans.setProperty(fieldRef, "value", value);
        }
        map.put(fieldRef.getScriptId(), fieldRef);
    }
    return map;
}
Also used : CustomizationFieldType(com.netsuite.webservices.v2014_2.setup.customization.types.CustomizationFieldType) RecordType(com.netsuite.webservices.v2014_2.platform.core.types.RecordType) HashMap(java.util.HashMap) BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) CustomFieldRef(com.netsuite.webservices.v2014_2.platform.core.CustomFieldRef) PropertyInfo(org.talend.components.netsuite.client.model.beans.PropertyInfo)

Example 2 with BeanInfo

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

the class SearchQuery method condition.

/**
 * Add condition for search query.
 *
 * @param condition condition to be added
 * @return
 * @throws NetSuiteException if an error occurs during adding of condition
 */
public SearchQuery condition(SearchCondition condition) throws NetSuiteException {
    initSearch();
    BeanInfo searchMetaData = Beans.getBeanInfo(searchRecordTypeDesc.getSearchBasicClass());
    String fieldName = toInitialLower(condition.getFieldName());
    PropertyInfo propertyInfo = searchMetaData.getProperty(fieldName);
    SearchFieldOperatorName operatorQName = new SearchFieldOperatorName(condition.getOperatorName());
    if (propertyInfo != null) {
        Object searchField = processConditionForSearchRecord(searchBasic, condition);
        setProperty(searchBasic, fieldName, searchField);
    } else {
        String dataType = operatorQName.getDataType();
        SearchFieldType searchFieldType = null;
        if (SearchFieldOperatorType.STRING.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_STRING;
        } else if (SearchFieldOperatorType.BOOLEAN.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_BOOLEAN;
        } else if (SearchFieldOperatorType.LONG.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_LONG;
        } else if (SearchFieldOperatorType.DOUBLE.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_DOUBLE;
        } else if (SearchFieldOperatorType.DATE.dataTypeEquals(dataType) || SearchFieldOperatorType.PREDEFINED_DATE.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_DATE;
        } else if (SearchFieldOperatorType.MULTI_SELECT.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_MULTI_SELECT;
        } else if (SearchFieldOperatorType.ENUM_MULTI_SELECT.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_SELECT;
        } else {
            throw new NetSuiteException("Invalid data type: " + searchFieldType);
        }
        Object searchField = processCondition(searchFieldType, condition);
        customFieldList.add(searchField);
    }
    return this;
}
Also used : BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) SearchFieldOperatorName(org.talend.components.netsuite.client.model.search.SearchFieldOperatorName) SearchFieldType(org.talend.components.netsuite.client.model.search.SearchFieldType) PropertyInfo(org.talend.components.netsuite.client.model.beans.PropertyInfo)

Example 3 with BeanInfo

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

the class SearchQuery method processConditionForSearchRecord.

/**
 * Process search condition and update search record.
 *
 * @param searchRecord search record
 * @param condition condition
 * @return search field built for this condition
 * @throws NetSuiteException if an error occurs during processing of condition
 */
private Object processConditionForSearchRecord(Object searchRecord, SearchCondition condition) throws NetSuiteException {
    String fieldName = toInitialLower(condition.getFieldName());
    BeanInfo beanInfo = Beans.getBeanInfo(searchRecord.getClass());
    Class<?> searchFieldClass = beanInfo.getProperty(fieldName).getWriteType();
    SearchFieldType fieldType = SearchFieldType.getByFieldTypeName(searchFieldClass.getSimpleName());
    Object searchField = processCondition(fieldType, condition);
    return searchField;
}
Also used : BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) SearchFieldType(org.talend.components.netsuite.client.model.search.SearchFieldType)

Example 4 with BeanInfo

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

the class NsObjectOutputTransducer method write.

/**
 * Translate input {@code IndexedRecord} to output NetSuite data object.
 *
 * @param indexedRecord indexed record to be processed
 * @return NetSuite data object
 */
public Object write(IndexedRecord indexedRecord) {
    prepare();
    Map<String, FieldDesc> fieldMap = typeDesc.getFieldMap();
    BeanInfo beanInfo = Beans.getBeanInfo(typeDesc.getTypeClass());
    Schema schema = indexedRecord.getSchema();
    String targetTypeName;
    if (recordTypeInfo != null && !reference) {
        RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
        targetTypeName = recordTypeDesc.getTypeName();
    } else {
        targetTypeName = typeDesc.getTypeName();
    }
    Object nsObject = clientService.getBasicMetaData().createInstance(targetTypeName);
    // Names of fields to be null'ed.
    Set<String> nullFieldNames = new HashSet<>();
    // Custom fields by names.
    Map<String, Object> customFieldMap = Collections.emptyMap();
    if (!reference && beanInfo.getProperty("customFieldList") != null) {
        customFieldMap = new HashMap<>();
        Object customFieldListWrapper = getSimpleProperty(nsObject, "customFieldList");
        if (customFieldListWrapper != null) {
            List<Object> customFieldList = (List<Object>) getSimpleProperty(customFieldListWrapper, "customField");
            for (Object customField : customFieldList) {
                String scriptId = (String) getSimpleProperty(customField, "scriptId");
                customFieldMap.put(scriptId, customField);
            }
        }
    }
    for (Schema.Field field : schema.getFields()) {
        String nsFieldName = NetSuiteDatasetRuntimeImpl.getNsFieldName(field);
        FieldDesc fieldDesc = fieldMap.get(nsFieldName);
        if (fieldDesc == null) {
            continue;
        }
        Object value = indexedRecord.get(field.pos());
        writeField(nsObject, fieldDesc, customFieldMap, nullFieldNames, value);
    }
    if (reference) {
        if (recordTypeInfo.getRefType() == RefType.RECORD_REF) {
            FieldDesc recTypeFieldDesc = typeDesc.getField("type");
            RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
            nullFieldNames.remove("type");
            writeSimpleField(nsObject, recTypeFieldDesc.asSimple(), false, nullFieldNames, recordTypeDesc.getType());
        } else if (recordTypeInfo.getRefType() == RefType.CUSTOM_RECORD_REF) {
            CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
            NsRef customizationRef = customRecordTypeInfo.getCustomizationRef();
            FieldDesc typeIdFieldDesc = typeDesc.getField("typeId");
            nullFieldNames.remove("typeId");
            writeSimpleField(nsObject, typeIdFieldDesc.asSimple(), false, nullFieldNames, customizationRef.getInternalId());
        }
    } else if (recordTypeInfo != null) {
        RecordTypeDesc recordTypeDesc = recordTypeInfo.getRecordType();
        if (recordTypeDesc.getType().equals(BasicRecordType.CUSTOM_RECORD.getType())) {
            CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
            FieldDesc recTypeFieldDesc = typeDesc.getField("recType");
            NsRef recordTypeRef = customRecordTypeInfo.getCustomizationRef();
            // Create custom record type ref as JSON to create native RecordRef
            ObjectNode recordRefNode = JsonNodeFactory.instance.objectNode();
            recordRefNode.set("internalId", JsonNodeFactory.instance.textNode(recordTypeRef.getInternalId()));
            recordRefNode.set("type", JsonNodeFactory.instance.textNode(recordTypeDesc.getType()));
            nullFieldNames.remove("recType");
            writeSimpleField(nsObject, recTypeFieldDesc.asSimple(), false, nullFieldNames, recordRefNode.toString());
        }
    }
    if (!nullFieldNames.isEmpty() && beanInfo.getProperty("nullFieldList") != null) {
        Object nullFieldListWrapper = clientService.getBasicMetaData().createInstance("NullField");
        setSimpleProperty(nsObject, "nullFieldList", nullFieldListWrapper);
        List<String> nullFields = (List<String>) getSimpleProperty(nullFieldListWrapper, "name");
        nullFields.addAll(nullFieldNames);
    }
    return nsObject;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) Schema(org.apache.avro.Schema) NsRef(org.talend.components.netsuite.client.NsRef) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) List(java.util.List) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) HashSet(java.util.HashSet)

Example 5 with BeanInfo

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

the class NetSuiteMockTestBase method createCustomFieldRefs.

protected Map<String, CustomFieldRef> createCustomFieldRefs(Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs) throws Exception {
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    Map<String, CustomFieldRef> map = new HashMap<>();
    for (CustomFieldSpec spec : customFieldSpecs.values()) {
        CustomFieldRef fieldRef = clientService.getBasicMetaData().createInstance(spec.getFieldRefType().getTypeName());
        fieldRef.setScriptId(spec.getScriptId());
        fieldRef.setInternalId(spec.getInternalId());
        BeanInfo beanInfo = Beans.getBeanInfo(fieldRef.getClass());
        PropertyInfo valuePropInfo = beanInfo.getProperty("value");
        Object value = composeValue(valuePropInfo.getWriteType());
        if (value != null) {
            Beans.setProperty(fieldRef, "value", value);
        }
        map.put(fieldRef.getScriptId(), fieldRef);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) CustomFieldRef(com.netsuite.webservices.test.platform.core.CustomFieldRef) PropertyInfo(org.talend.components.netsuite.client.model.beans.PropertyInfo)

Aggregations

BeanInfo (org.talend.components.netsuite.client.model.beans.BeanInfo)12 PropertyInfo (org.talend.components.netsuite.client.model.beans.PropertyInfo)6 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Schema (org.apache.avro.Schema)2 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)2 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)2 SearchFieldType (org.talend.components.netsuite.client.model.search.SearchFieldType)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 CustomFieldRef (com.netsuite.webservices.test.platform.core.CustomFieldRef)1 CustomFieldRef (com.netsuite.webservices.v2014_2.platform.core.CustomFieldRef)1 RecordType (com.netsuite.webservices.v2014_2.platform.core.types.RecordType)1 CustomizationFieldType (com.netsuite.webservices.v2014_2.setup.customization.types.CustomizationFieldType)1 CustomFieldRef (com.netsuite.webservices.v2016_2.platform.core.CustomFieldRef)1 HashSet (java.util.HashSet)1 CustomFieldSpec (org.talend.components.netsuite.CustomFieldSpec)1 NsRef (org.talend.components.netsuite.client.NsRef)1 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)1 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)1