use of org.talend.components.netsuite.client.model.CustomRecordTypeInfo in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSchemaForDeleteFlow.
@Override
public Schema getSchemaForDeleteFlow(String typeName, Schema schema) {
RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
// We should check and add key fields:
// internalId, externalId and scriptId (for custom record type)
List<FieldDesc> fieldDescList = new ArrayList<>();
Schema.Field internalIdField = getNsFieldByName(schema, "internalId");
if (internalIdField == null) {
FieldDesc fieldDesc = typeDesc.getField("internalId");
fieldDescList.add(fieldDesc);
}
Schema.Field externalIdField = getNsFieldByName(schema, "externalId");
if (externalIdField == null) {
FieldDesc fieldDesc = typeDesc.getField("externalId");
fieldDescList.add(fieldDesc);
}
if (recordTypeInfo instanceof CustomRecordTypeInfo) {
Schema.Field scriptIdField = getNsFieldByName(schema, "scriptId");
if (scriptIdField == null) {
FieldDesc fieldDesc = typeDesc.getField("scriptId");
if (fieldDesc != null) {
fieldDescList.add(fieldDesc);
}
}
}
// Create schema fields for mandatory fields.
List<Schema.Field> fields = new ArrayList<>();
Schema.Field f;
if (!fieldDescList.isEmpty()) {
Schema schemaToAdd = inferSchemaForType(typeName, fieldDescList);
for (Schema.Field sourceField : schemaToAdd.getFields()) {
f = copyField(sourceField);
f.addProp(SchemaConstants.TALEND_FIELD_GENERATED, "true");
f.addProp(SchemaConstants.TALEND_IS_LOCKED, "true");
fields.add(f);
}
}
return extendSchema(schema, typeName + "_FLOW", fields);
}
use of org.talend.components.netsuite.client.model.CustomRecordTypeInfo in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method readCustomRecord.
/**
* Read custom record meta data from a given <code>JsonProperties</code>.
*
* @see NetSuiteSchemaConstants
*
* @param basicMetaData basic meta data
* @param properties properties object which to read meta data from
* @return custom record type info or <code>null</code> if meta data was not found
*/
public static CustomRecordTypeInfo readCustomRecord(BasicMetaData basicMetaData, JsonProperties properties) {
String scriptId = properties.getProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD_SCRIPT_ID);
if (StringUtils.isEmpty(scriptId)) {
return null;
}
String internalId = properties.getProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD_INTERNAL_ID);
String customizationType = properties.getProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD_CUSTOMIZATION_TYPE);
String recordType = properties.getProp(NetSuiteSchemaConstants.NS_CUSTOM_RECORD_TYPE);
NsRef ref = new NsRef();
ref.setRefType(RefType.CUSTOMIZATION_REF);
ref.setScriptId(scriptId);
ref.setInternalId(internalId);
ref.setType(customizationType);
RecordTypeDesc recordTypeDesc = basicMetaData.getRecordType(recordType);
CustomRecordTypeInfo recordTypeInfo = new CustomRecordTypeInfo(scriptId, recordTypeDesc, ref);
return recordTypeInfo;
}
use of org.talend.components.netsuite.client.model.CustomRecordTypeInfo in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method augmentSchemaWithCustomMetaData.
/**
* Augment a given <code>Schema</code> with customization related meta data.
*
* @param metaDataSource source of meta data
* @param schema schema to be augmented
* @param recordTypeInfo information about record type to be used for augmentation
* @param fieldDescList list of field descriptors to be used for augmentation
*/
public static void augmentSchemaWithCustomMetaData(final MetaDataSource metaDataSource, final Schema schema, final RecordTypeInfo recordTypeInfo, final Collection<FieldDesc> fieldDescList) {
if (recordTypeInfo == null) {
// Not a record, do nothing
return;
}
// Add custom record type meta data to a key field
if (recordTypeInfo instanceof CustomRecordTypeInfo) {
CustomRecordTypeInfo customRecordTypeInfo = (CustomRecordTypeInfo) recordTypeInfo;
for (Schema.Field field : schema.getFields()) {
writeCustomRecord(metaDataSource.getBasicMetaData(), field, customRecordTypeInfo);
}
}
// Add custom field meta data to fields
if (fieldDescList != null && !fieldDescList.isEmpty()) {
Map<String, CustomFieldDesc> customFieldDescMap = getCustomFieldDescMap(fieldDescList);
if (!customFieldDescMap.isEmpty()) {
for (Schema.Field field : schema.getFields()) {
String nsFieldName = getNsFieldName(field);
CustomFieldDesc customFieldDesc = customFieldDescMap.get(nsFieldName);
if (customFieldDesc != null) {
writeCustomField(field, customFieldDesc);
}
}
}
}
}
use of org.talend.components.netsuite.client.model.CustomRecordTypeInfo 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.model.CustomRecordTypeInfo 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);
}
Aggregations