use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class RecordTypeInfoTest method testCustomRecordTypeInfo.
@Test
public void testCustomRecordTypeInfo() {
NsRef customizationRef = new NsRef(RefType.CUSTOMIZATION_REF);
customizationRef.setName("Custom Record Type 1");
customizationRef.setScriptId("custom_record_type_1");
customizationRef.setInternalId("12345");
CustomRecordTypeInfo info = new CustomRecordTypeInfo("custom_record_type_1", TestRecordTypeEnum.CUSTOM_RECORD, customizationRef);
assertEquals(TestRecordTypeEnum.CUSTOM_RECORD, info.getRecordType());
assertEquals("custom_record_type_1", info.getName());
assertEquals("Custom Record Type 1", info.getDisplayName());
assertEquals(RefType.CUSTOM_RECORD_REF, info.getRefType());
assertEquals(customizationRef, info.getCustomizationRef());
assertNotNull(info.toString());
}
use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class TypeDescTest method testTypeDesc.
@Test
public void testTypeDesc() {
SimpleFieldDesc field1 = new SimpleFieldDesc("InternalId", String.class, true, true);
field1.setPropertyName("internalId");
SimpleFieldDesc field2 = new SimpleFieldDesc("Inventory", Boolean.class, false, true);
field2.setPropertyName("inventory");
CustomFieldDesc field3 = new CustomFieldDesc();
NsRef customizationRef1 = new NsRef(RefType.CUSTOMIZATION_REF);
customizationRef1.setScriptId("custentity101");
customizationRef1.setInternalId("10001");
customizationRef1.setName("Custom Field 1");
field3.setCustomizationRef(customizationRef1);
field3.setName("Custentity101");
CustomFieldDesc field4 = new CustomFieldDesc();
NsRef customizationRef2 = new NsRef(RefType.CUSTOMIZATION_REF);
customizationRef2.setScriptId("custentity102");
customizationRef2.setInternalId("10002");
customizationRef2.setName("Custom Field 2");
field4.setCustomizationRef(customizationRef2);
field4.setName("Custentity102");
TypeDesc typeDesc = new TypeDesc("Account", Account.class, Arrays.asList(field1, field2, field3, field4));
assertEquals("Account", typeDesc.getTypeName());
assertEquals(Account.class, typeDesc.getTypeClass());
assertEquals(4, typeDesc.getFields().size());
assertEquals(4, typeDesc.getFieldMap().size());
List<String> fieldNames = Arrays.asList("InternalId", "Inventory", "Custentity101", "Custentity102");
for (String fieldName : fieldNames) {
FieldDesc fieldDesc = typeDesc.getField(fieldName);
assertNotNull(fieldDesc);
if (fieldDesc instanceof SimpleFieldDesc) {
fieldDesc.asSimple();
} else if (fieldDesc instanceof CustomFieldDesc) {
fieldDesc.asCustom();
}
}
assertNotNull(typeDesc.toString());
}
use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class TypeDescTest method testCustomFieldDesc.
@Test
public void testCustomFieldDesc() {
CustomFieldDesc fieldDesc1 = new CustomFieldDesc();
NsRef customizationRef1 = new NsRef(RefType.CUSTOMIZATION_REF);
customizationRef1.setScriptId("custentity101");
customizationRef1.setInternalId("10001");
customizationRef1.setName("Custom Field 1");
fieldDesc1.setCustomizationRef(customizationRef1);
fieldDesc1.setName("Custentity101");
fieldDesc1.setCustomFieldType(CustomFieldRefType.STRING);
assertEquals("Custentity101", fieldDesc1.getName());
assertEquals(customizationRef1, fieldDesc1.getCustomizationRef());
assertEquals(CustomFieldRefType.STRING, fieldDesc1.getCustomFieldType());
assertNotNull(fieldDesc1.toString());
}
use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class SearchQuery method toNativeQuery.
/**
* Finalize building of search query and get built NetSuite's search record object.
*
* @return
* @throws NetSuiteException if an error occurs during updating of search record
*/
public SearchT toNativeQuery() throws NetSuiteException {
initSearch();
BasicRecordType basicRecordType = BasicRecordType.getByType(searchRecordTypeDesc.getType());
if (BasicRecordType.TRANSACTION == basicRecordType) {
SearchFieldAdapter<?> fieldAdapter = metaDataSource.getBasicMetaData().getSearchFieldAdapter(SearchFieldType.SELECT);
Object searchTypeField = fieldAdapter.populate("List.anyOf", Arrays.asList(recordTypeInfo.getRecordType().getType()));
setProperty(searchBasic, "type", searchTypeField);
} else if (BasicRecordType.CUSTOM_RECORD == basicRecordType) {
CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
NsRef customizationRef = customRecordTypeInfo.getCustomizationRef();
Object recType = metaDataSource.getBasicMetaData().createInstance(RefType.CUSTOMIZATION_REF.getTypeName());
setProperty(recType, "scriptId", customizationRef.getScriptId());
setProperty(recType, "internalId", customizationRef.getInternalId());
setProperty(searchBasic, "recType", recType);
}
// Set custom fields
if (!customFieldList.isEmpty()) {
Object customFieldListWrapper = metaDataSource.getBasicMetaData().createInstance("SearchCustomFieldList");
List<Object> customFields = (List<Object>) getProperty(customFieldListWrapper, "customField");
for (Object customField : customFieldList) {
customFields.add(customField);
}
setProperty(searchBasic, "customFieldList", customFieldListWrapper);
}
SearchT searchRecord;
if (searchRecordTypeDesc.getSearchClass() != null) {
setProperty(search, "basic", searchBasic);
searchRecord = search;
if (searchAdvanced != null) {
setProperty(searchAdvanced, "condition", search);
searchRecord = searchAdvanced;
}
} else {
searchRecord = searchBasic;
}
return searchRecord;
}
use of org.talend.components.netsuite.client.NsRef in project components by Talend.
the class NsObjectTransducer method writeCustomField.
/**
* Write a custom field which is not defined by NetSuite standard data model.
*
* @param nsObject target NetSuite data model object which to write field value to
* @param fieldDesc field descriptor
* @param customFieldMap map of native custom field objects by names
* @param replace specifies whether to forcibly replace a field's value
* @param nullFieldNames collection to register null'ed fields
* @param value value to be written, can be <code>null</code>
*/
protected void writeCustomField(Object nsObject, CustomFieldDesc fieldDesc, Map<String, Object> customFieldMap, boolean replace, Collection<String> nullFieldNames, Object value) {
NsRef ref = fieldDesc.getCustomizationRef();
CustomFieldRefType customFieldRefType = fieldDesc.getCustomFieldType();
// Create custom field list wrapper if required
Object customFieldListWrapper = getSimpleProperty(nsObject, "customFieldList");
if (customFieldListWrapper == null) {
customFieldListWrapper = clientService.getBasicMetaData().createInstance("CustomFieldList");
setSimpleProperty(nsObject, "customFieldList", customFieldListWrapper);
}
List<Object> customFieldList = (List<Object>) getSimpleProperty(customFieldListWrapper, "customField");
Object customField = customFieldMap.get(ref.getScriptId());
AvroConverter valueConverter = getValueConverter(fieldDesc);
Object targetValue = valueConverter.convertToDatum(value);
if (targetValue == null) {
if (replace && customField != null && customFieldList != null) {
customFieldList.remove(customField);
nullFieldNames.add(fieldDesc.getName());
}
} else {
if (customField == null) {
// Custom field instance doesn't exist,
// create new instance and set identifiers
customField = clientService.getBasicMetaData().createInstance(customFieldRefType.getTypeName());
setSimpleProperty(customField, "scriptId", ref.getScriptId());
setSimpleProperty(customField, "internalId", ref.getInternalId());
customFieldList.add(customField);
customFieldMap.put(ref.getScriptId(), customField);
}
setSimpleProperty(customField, "value", targetValue);
}
}
Aggregations