Search in sources :

Example 6 with CustomRecordTypeInfo

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);
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) Schema(org.apache.avro.Schema) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 7 with CustomRecordTypeInfo

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;
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) NsRef(org.talend.components.netsuite.client.NsRef) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo)

Example 8 with CustomRecordTypeInfo

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);
                }
            }
        }
    }
}
Also used : Schema(org.apache.avro.Schema) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo)

Example 9 with CustomRecordTypeInfo

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BasicRecordType(org.talend.components.netsuite.client.model.BasicRecordType) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) NsRef(org.talend.components.netsuite.client.NsRef)

Example 10 with CustomRecordTypeInfo

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);
}
Also used : CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Aggregations

CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)12 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)8 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)6 ArrayList (java.util.ArrayList)5 Schema (org.apache.avro.Schema)4 NsRef (org.talend.components.netsuite.client.NsRef)4 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)4 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)4 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)3 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)3 CustomRecordType (com.netsuite.webservices.test.setup.customization.CustomRecordType)2 List (java.util.List)2 Test (org.junit.Test)2 CustomFieldSpec (org.talend.components.netsuite.CustomFieldSpec)2 BasicRecordType (org.talend.components.netsuite.client.model.BasicRecordType)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashSet (java.util.HashSet)1 BeanInfo (org.talend.components.netsuite.client.model.beans.BeanInfo)1