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