Search in sources :

Example 11 with NetSuiteException

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

the class SearchFieldAdapter method createField.

/**
 * Create instance of NetSuite's search field.
 *
 * @param internalId internal identifier to be applied to a search field
 * @return search field object
 * @throws NetSuiteException if an error occurs during creation of a search field
 */
protected T createField(String internalId) throws NetSuiteException {
    try {
        BeanInfo fieldTypeMetaData = Beans.getBeanInfo(fieldClass);
        T searchField = fieldClass.newInstance();
        if (fieldTypeMetaData.getProperty("internalId") != null && internalId != null) {
            setProperty(searchField, "internalId", internalId);
        }
        return searchField;
    } catch (IllegalAccessException | IllegalArgumentException | InstantiationException e) {
        throw new NetSuiteException(e.getMessage(), e);
    }
}
Also used : BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException)

Example 12 with NetSuiteException

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

the class NetSuiteEndpoint method createConnectionConfig.

/**
 * Create connection configuration for given connection properties.
 *
 * @param properties connection properties
 * @return connection configuration
 * @throws NetSuiteException if connection configuration not valid
 */
public static ConnectionConfig createConnectionConfig(NetSuiteProvideConnectionProperties properties) throws NetSuiteException {
    NetSuiteConnectionProperties connProps = properties.getConnectionProperties();
    if (StringUtils.isEmpty(connProps.endpoint.getStringValue())) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.endpointUrlRequired"));
    }
    if (StringUtils.isEmpty(connProps.apiVersion.getStringValue())) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.apiVersionRequired"));
    }
    if (StringUtils.isEmpty(connProps.email.getStringValue())) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.emailRequired"));
    }
    if (StringUtils.isEmpty(connProps.password.getStringValue())) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.passwordRequired"));
    }
    if (StringUtils.isEmpty(connProps.account.getStringValue())) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.accountRequired"));
    }
    if (connProps.role.getValue() == null) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.roleRequired"));
    }
    String endpointUrl = connProps.endpoint.getStringValue();
    NetSuiteVersion endpointApiVersion;
    try {
        endpointApiVersion = NetSuiteVersion.detectVersion(endpointUrl);
    } catch (IllegalArgumentException e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotDetectApiVersionFromEndpointUrl", endpointUrl));
    }
    String apiVersionString = connProps.apiVersion.getStringValue();
    NetSuiteVersion apiVersion;
    try {
        apiVersion = NetSuiteVersion.parseVersion(apiVersionString);
    } catch (IllegalArgumentException e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.invalidApiVersion", apiVersionString));
    }
    if (!endpointApiVersion.isSameMajor(apiVersion)) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.endpointUrlApiVersionMismatch", endpointUrl, apiVersionString));
    }
    if (apiVersion.getMajorYear() >= 2015 && StringUtils.isEmpty(connProps.applicationId.getStringValue())) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.applicationIdRequired"));
    }
    String email = connProps.email.getStringValue();
    String password = connProps.password.getStringValue();
    Integer roleId = connProps.role.getValue();
    String account = connProps.account.getStringValue();
    String applicationId = connProps.applicationId.getStringValue();
    Boolean customizationEnabled = connProps.customizationEnabled.getValue();
    NetSuiteCredentials credentials = new NetSuiteCredentials();
    credentials.setEmail(email);
    credentials.setPassword(password);
    credentials.setRoleId(roleId.toString());
    credentials.setAccount(account);
    credentials.setApplicationId(applicationId);
    try {
        ConnectionConfig connectionConfig = new ConnectionConfig(new URL(endpointUrl), apiVersion.getMajor(), credentials);
        if (properties instanceof NetSuiteInputProperties) {
            connectionConfig.setBodyFieldsOnly(((NetSuiteInputProperties) properties).bodyFieldsOnly.getValue());
        }
        connectionConfig.setCustomizationEnabled(customizationEnabled);
        return connectionConfig;
    } catch (MalformedURLException e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.invalidEndpointUrl", endpointUrl));
    }
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) MalformedURLException(java.net.MalformedURLException) NetSuiteConnectionProperties(org.talend.components.netsuite.connection.NetSuiteConnectionProperties) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) URL(java.net.URL) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials)

Example 13 with NetSuiteException

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

the class NetSuiteDatasetRuntimeImpl method getSchemaForRecordRef.

public Schema getSchemaForRecordRef(String typeName) {
    try {
        // Get info for target record type
        final RecordTypeInfo referencedRecordTypeInfo = metaDataSource.getRecordType(typeName);
        final RefType refType = referencedRecordTypeInfo.getRefType();
        // Get type info for record ref
        final TypeDesc typeDesc = metaDataSource.getTypeInfo(refType.getTypeName());
        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, referencedRecordTypeInfo, null);
        return schema;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : CustomFieldRefType(org.talend.components.netsuite.client.model.customfield.CustomFieldRefType) RefType(org.talend.components.netsuite.client.model.RefType) 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 14 with NetSuiteException

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

the class NetSuiteDatasetRuntimeImpl method getSchema.

@Override
public Schema getSchema(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, fieldDescList);
        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 15 with NetSuiteException

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

the class NetSuiteDatasetRuntimeImpl method getSearchableTypes.

@Override
public List<NamedThing> getSearchableTypes() {
    try {
        List<NamedThing> searchableTypes = new ArrayList<>(metaDataSource.getSearchableTypes());
        // Sort by display name in alphabetical order
        Collections.sort(searchableTypes, new Comparator<NamedThing>() {

            @Override
            public int compare(NamedThing o1, NamedThing o2) {
                return o1.getDisplayName().compareTo(o2.getDisplayName());
            }
        });
        return searchableTypes;
    } catch (NetSuiteException e) {
        throw new ComponentException(e);
    }
}
Also used : 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)

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