Search in sources :

Example 16 with NetSuiteException

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

the class NetSuiteDatasetRuntimeImpl method getRecordTypes.

@Override
public List<NamedThing> getRecordTypes() {
    try {
        Collection<RecordTypeInfo> recordTypeList = metaDataSource.getRecordTypes();
        List<NamedThing> recordTypes = new ArrayList<>(recordTypeList.size());
        for (RecordTypeInfo recordTypeInfo : recordTypeList) {
            recordTypes.add(new SimpleNamedThing(recordTypeInfo.getName(), recordTypeInfo.getDisplayName()));
        }
        // Sort by display name in alphabetical order
        Collections.sort(recordTypes, new Comparator<NamedThing>() {

            @Override
            public int compare(NamedThing o1, NamedThing o2) {
                return o1.getDisplayName().compareTo(o2.getDisplayName());
            }
        });
        return recordTypes;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomRecordTypeInfo(org.talend.components.netsuite.client.model.CustomRecordTypeInfo) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing)

Example 17 with NetSuiteException

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

the class NetSuiteDatasetRuntimeImpl method getSearchInfo.

@Override
public SearchInfo getSearchInfo(String typeName) {
    try {
        final SearchRecordTypeDesc searchInfo = metaDataSource.getSearchRecordType(typeName);
        final TypeDesc searchRecordInfo = metaDataSource.getBasicMetaData().getTypeInfo(searchInfo.getSearchBasicClass());
        List<FieldDesc> fieldDescList = searchRecordInfo.getFields();
        List<SearchFieldInfo> fields = new ArrayList<>(fieldDescList.size());
        for (FieldDesc fieldDesc : fieldDescList) {
            SearchFieldInfo field = new SearchFieldInfo(fieldDesc.getName(), fieldDesc.getValueType());
            fields.add(field);
        }
        // Sort by display name in alphabetical order
        Collections.sort(fields, new Comparator<SearchFieldInfo>() {

            @Override
            public int compare(SearchFieldInfo o1, SearchFieldInfo o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        return new SearchInfo(searchRecordInfo.getTypeName(), fields);
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : SearchRecordTypeDesc(org.talend.components.netsuite.client.model.SearchRecordTypeDesc) SearchFieldInfo(org.talend.components.netsuite.schema.SearchFieldInfo) SearchInfo(org.talend.components.netsuite.schema.SearchInfo) 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) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 18 with NetSuiteException

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

the class NetSuiteDatasetRuntimeImpl method getSchemaForUpdate.

@Override
public Schema getSchemaForUpdate(String typeName) {
    try {
        final RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
        final TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
        List<FieldDesc> fieldDescList = new ArrayList<>(typeDesc.getFields());
        // Sort in alphabetical order
        Collections.sort(fieldDescList, FieldDescComparator.INSTANCE);
        Schema schema = inferSchemaForType(typeDesc.getTypeName(), fieldDescList);
        augmentSchemaWithCustomMetaData(metaDataSource, schema, recordTypeInfo, typeDesc.getFields());
        return schema;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
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) ComponentException(org.talend.components.api.exception.ComponentException) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc)

Example 19 with NetSuiteException

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

the class SearchQuery method processCondition.

/**
 * Process search condition and update search record.
 *
 * @param fieldType type of search field
 * @param condition condition
 * @return search field built for this condition
 * @throws NetSuiteException if an error occurs during processing of condition
 */
private Object processCondition(SearchFieldType fieldType, SearchCondition condition) throws NetSuiteException {
    try {
        String searchFieldName = toInitialLower(condition.getFieldName());
        String searchOperator = condition.getOperatorName();
        List<String> searchValue = condition.getValues();
        SearchFieldAdapter<?> fieldAdapter = metaDataSource.getBasicMetaData().getSearchFieldAdapter(fieldType);
        Object searchField = fieldAdapter.populate(searchFieldName, searchOperator, searchValue);
        return searchField;
    } catch (IllegalArgumentException e) {
        throw new NetSuiteException(e.getMessage(), e);
    }
}
Also used : NetSuiteException(org.talend.components.netsuite.client.NetSuiteException)

Example 20 with NetSuiteException

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

the class SearchQuery method initSearch.

/**
 * Performs lazy initialization of search query.
 *
 * @throws NetSuiteException if an error occurs during obtaining of meta data
 */
private void initSearch() throws NetSuiteException {
    if (searchBasic != null) {
        return;
    }
    try {
        // get a search class instance
        if (searchRecordTypeDesc.getSearchClass() != null) {
            search = (SearchT) searchRecordTypeDesc.getSearchClass().newInstance();
        }
        // get a advanced search class instance and set 'savedSearchId' into it
        searchAdvanced = null;
        if (savedSearchId != null && savedSearchId.length() > 0) {
            if (searchRecordTypeDesc.getSearchAdvancedClass() != null) {
                searchAdvanced = (SearchT) searchRecordTypeDesc.getSearchAdvancedClass().newInstance();
                setProperty(searchAdvanced, "savedSearchId", savedSearchId);
            } else {
                throw new NetSuiteException("Advanced search not available: " + recordTypeName);
            }
        }
        // basic search class not found or supported
        if (searchRecordTypeDesc.getSearchBasicClass() == null) {
            throw new IllegalArgumentException("Search basic class not found: " + recordTypeName);
        }
        // get a basic search class instance
        searchBasic = (SearchT) searchRecordTypeDesc.getSearchBasicClass().newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new NetSuiteException(e.getMessage(), e);
    }
}
Also used : NetSuiteException(org.talend.components.netsuite.client.NetSuiteException)

Aggregations

NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)29 ArrayList (java.util.ArrayList)10 MalformedURLException (java.net.MalformedURLException)9 NetSuiteErrorCode (org.talend.components.netsuite.NetSuiteErrorCode)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 SocketException (java.net.SocketException)6 RemoteException (java.rmi.RemoteException)6 WebServiceException (javax.xml.ws.WebServiceException)6 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)6 Schema (org.apache.avro.Schema)6 ComponentException (org.talend.components.api.exception.ComponentException)6 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)5 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)5 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)5 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)5 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)5 IOException (java.io.IOException)4 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)4 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)4 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)4