use of org.talend.components.netsuite.client.model.beans.BeanInfo in project components by Talend.
the class SearchFieldAdapter method createField.
/**
* Create instance of NetSuite's search field.
*
* @param internalId internal identifier to be applied to a search field
* @return search field object
* @throws NetSuiteException if an error occurs during creation of a search field
*/
protected T createField(String internalId) throws NetSuiteException {
try {
BeanInfo fieldTypeMetaData = Beans.getBeanInfo(fieldClass);
T searchField = fieldClass.newInstance();
if (fieldTypeMetaData.getProperty("internalId") != null && internalId != null) {
setProperty(searchField, "internalId", internalId);
}
return searchField;
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException e) {
throw new NetSuiteException(e.getMessage(), e);
}
}
use of org.talend.components.netsuite.client.model.beans.BeanInfo in project components by Talend.
the class NsRef method fromNativeRef.
/**
* Create ref object from NetSuite's native ref data object.
*
* @param ref native ref data object
* @return ref object
*/
public static NsRef fromNativeRef(Object ref) {
String typeName = ref.getClass().getSimpleName();
RefType refType = RefType.getByTypeName(typeName);
NsRef nsRef = new NsRef();
nsRef.setRefType(refType);
BeanInfo beanInfo = Beans.getBeanInfo(ref.getClass());
nsRef.setInternalId((String) getSimpleProperty(ref, "internalId"));
nsRef.setExternalId((String) getSimpleProperty(ref, "externalId"));
if (refType == RefType.RECORD_REF) {
nsRef.setType(Beans.getEnumAccessor((Class<Enum>) beanInfo.getProperty("type").getReadType()).getStringValue((Enum) getSimpleProperty(ref, "type")));
} else if (refType == RefType.CUSTOM_RECORD_REF) {
nsRef.setTypeId((String) getSimpleProperty(ref, "typeId"));
} else if (refType == RefType.CUSTOMIZATION_REF) {
nsRef.setScriptId((String) getSimpleProperty(ref, "scriptId"));
}
return nsRef;
}
use of org.talend.components.netsuite.client.model.beans.BeanInfo 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.beans.BeanInfo in project components by Talend.
the class AbstractNetSuiteTestBase method composeObject.
protected static <T> T composeObject(Class<T> clazz) throws Exception {
BeanInfo beanInfo = Beans.getBeanInfo(clazz);
List<PropertyInfo> propertyInfoList = beanInfo.getProperties();
T obj = clazz.newInstance();
for (PropertyInfo propertyInfo : propertyInfoList) {
if (propertyInfo.getWriteType() != null) {
Object value;
if (propertyInfo.getName().equals("internalId")) {
value = composeValue(Integer.class).toString();
} else {
value = composeValue(propertyInfo.getWriteType());
}
setProperty(obj, propertyInfo.getName(), value);
}
}
return obj;
}
use of org.talend.components.netsuite.client.model.beans.BeanInfo in project components by Talend.
the class NsRef method toNativeRef.
/**
* Create NetSuite's native ref data object from this ref object.
*
* @param basicMetaData basic meta data to be used
* @return ref data object
*/
public Object toNativeRef(BasicMetaData basicMetaData) {
Object ref = basicMetaData.createInstance(refType.getTypeName());
BeanInfo beanInfo = Beans.getBeanInfo(ref.getClass());
setSimpleProperty(ref, "internalId", internalId);
setSimpleProperty(ref, "externalId", externalId);
if (refType == RefType.CUSTOMIZATION_REF || refType == RefType.CUSTOM_RECORD_REF) {
setSimpleProperty(ref, "scriptId", scriptId);
}
if (refType == RefType.CUSTOM_RECORD_REF) {
setSimpleProperty(ref, "typeId", typeId);
} else {
setSimpleProperty(ref, "type", Beans.getEnumAccessor((Class<Enum>) beanInfo.getProperty("type").getWriteType()).getEnumValue(type));
}
return ref;
}
Aggregations