Search in sources :

Example 6 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc 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 7 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class MetaDataSourceTest method testGetSearchableTypes.

@Test
public void testGetSearchableTypes() {
    Collection<NamedThing> searchableTypeNamedThings = metaDataSource.getSearchableTypes();
    assertNotNull(searchableTypeNamedThings);
    assertFalse(searchableTypeNamedThings.isEmpty());
    Set<String> searchableTypeNames = new HashSet<>();
    for (NamedThing namedThing : searchableTypeNamedThings) {
        assertNotNull(namedThing);
        searchableTypeNames.add(namedThing.getName());
    }
    for (RecordTypeDesc recordTypeDesc : TestRecordTypeEnum.values()) {
        if (recordTypeDesc.getSearchRecordType() != null) {
            assertTrue(recordTypeDesc.getTypeName(), searchableTypeNames.contains(recordTypeDesc.getTypeName()));
        }
    }
    for (RecordTypeInfo recordTypeInfo : customMetaDataSource.getCustomRecordTypes()) {
        assertTrue(recordTypeInfo.getName(), searchableTypeNames.contains(recordTypeInfo.getName()));
    }
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) NamedThing(org.talend.daikon.NamedThing) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class DefaultMetaDataSource method getRecordTypes.

/**
 * {@inheritDoc}
 */
@Override
public Collection<RecordTypeInfo> getRecordTypes() {
    List<RecordTypeInfo> recordTypes = new ArrayList<>();
    Collection<RecordTypeDesc> standardRecordTypes = clientService.getBasicMetaData().getRecordTypes();
    for (RecordTypeDesc recordType : standardRecordTypes) {
        recordTypes.add(new RecordTypeInfo(recordType));
    }
    if (customizationEnabled) {
        recordTypes.addAll(customMetaDataSource.getCustomRecordTypes());
    }
    return recordTypes;
}
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) ArrayList(java.util.ArrayList)

Example 9 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class DefaultCustomMetaDataSource method retrieveCustomRecordTypes.

/**
 * Retrieve custom record types from NetSuite web service.
 *
 * @see #customRecordTypeMap
 *
 * @throws NetSuiteException if an error occurs during retrieving of customization data
 */
protected void retrieveCustomRecordTypes() throws NetSuiteException {
    if (customRecordTypesLoaded) {
        return;
    }
    List<NsRef> customTypes = new ArrayList<>();
    List<NsRef> customRecordTypes = customMetaDataRetriever.retrieveCustomizationIds(BasicRecordType.CUSTOM_RECORD_TYPE);
    customTypes.addAll(customRecordTypes);
    List<NsRef> customTransactionTypes = customMetaDataRetriever.retrieveCustomizationIds(BasicRecordType.CUSTOM_TRANSACTION_TYPE);
    customTypes.addAll(customTransactionTypes);
    for (NsRef customizationRef : customTypes) {
        String recordType = customizationRef.getType();
        RecordTypeDesc recordTypeDesc = null;
        BasicRecordType basicRecordType = BasicRecordType.getByType(recordType);
        if (basicRecordType != null) {
            recordTypeDesc = clientService.getBasicMetaData().getRecordType(toInitialUpper(basicRecordType.getSearchType()));
        }
        CustomRecordTypeInfo customRecordTypeInfo = new CustomRecordTypeInfo(customizationRef.getScriptId(), recordTypeDesc, customizationRef);
        customRecordTypeMap.put(customRecordTypeInfo.getName(), customRecordTypeInfo);
    }
    customRecordTypesLoaded = true;
}
Also used : RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) ArrayList(java.util.ArrayList) BasicRecordType(org.talend.components.netsuite.client.model.BasicRecordType) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo)

Example 10 with RecordTypeDesc

use of org.talend.components.netsuite.client.model.RecordTypeDesc in project components by Talend.

the class DefaultCustomMetaDataSource method getCustomFieldsImpl.

/**
 * Get custom field descriptors for a given record type.
 *
 * @param recordTypeInfo record type info
 * @return custom field descriptors as map
 * @throws NetSuiteException if an error occurs during obtaining of customization data
 */
protected Map<String, CustomFieldDesc> getCustomFieldsImpl(RecordTypeInfo recordTypeInfo) throws NetSuiteException {
    RecordTypeDesc recordType = recordTypeInfo.getRecordType();
    Map<String, CustomFieldDesc> fieldDescMap;
    if (recordTypeInfo instanceof CustomRecordTypeInfo) {
        fieldDescMap = customRecordCustomFieldMap.get(recordTypeInfo.getName());
        if (fieldDescMap == null) {
            retrieveCustomRecordCustomFields((CustomRecordTypeInfo) recordTypeInfo);
            fieldDescMap = customRecordCustomFieldMap.get(recordTypeInfo.getName());
        }
    } else {
        fieldDescMap = recordCustomFieldMap.get(recordType.getType());
        if (fieldDescMap == null) {
            retrieveCustomFields(recordType);
            fieldDescMap = recordCustomFieldMap.get(recordType.getType());
        }
    }
    return fieldDescMap;
}
Also used : RecordTypeDesc(org.talend.components.netsuite.client.model.RecordTypeDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo)

Aggregations

RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)11 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)7 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)7 NsRef (org.talend.components.netsuite.client.NsRef)4 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 NamedThing (org.talend.daikon.NamedThing)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 List (java.util.List)1 Schema (org.apache.avro.Schema)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 BasicRecordType (org.talend.components.netsuite.client.model.BasicRecordType)1 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)1 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)1 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)1 BeanInfo (org.talend.components.netsuite.client.model.beans.BeanInfo)1 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)1