Search in sources :

Example 1 with NetSuiteConnectionProperties

use of org.talend.components.netsuite.connection.NetSuiteConnectionProperties 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 2 with NetSuiteConnectionProperties

use of org.talend.components.netsuite.connection.NetSuiteConnectionProperties in project components by Talend.

the class NetSuiteRuntimeInfoTest method testRuntimeVersion.

public void testRuntimeVersion(String apiVersion) throws Exception {
    NetSuiteConnectionProperties connProps = new NetSuiteConnectionProperties("test");
    connProps.setupProperties();
    connProps.endpoint.setValue("https://webservices.netsuite.com/services/NetSuitePort_" + apiVersion);
    connProps.apiVersion.setValue(NetSuiteVersion.detectVersion(connProps.endpoint.getStringValue()).getMajorAsString("."));
    RuntimeInfo runtimeInfo = NetSuiteComponentDefinition.getRuntimeInfo(connProps, NetSuiteComponentDefinition.RUNTIME_CLASS);
    assertNotNull(runtimeInfo);
    assertThat(runtimeInfo, instanceOf(JarRuntimeInfo.class));
    JarRuntimeInfo jarRuntimeInfo = (JarRuntimeInfo) runtimeInfo;
    assertNotNull(jarRuntimeInfo.getJarUrl());
    assertNotNull(jarRuntimeInfo.getDepTxtPath());
    assertEquals(jarRuntimeInfo.getRuntimeClassName(), "org.talend.components.netsuite.v" + apiVersion + ".NetSuiteRuntimeImpl");
}
Also used : RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) JarRuntimeInfo(org.talend.components.api.component.runtime.JarRuntimeInfo) NetSuiteConnectionProperties(org.talend.components.netsuite.connection.NetSuiteConnectionProperties) JarRuntimeInfo(org.talend.components.api.component.runtime.JarRuntimeInfo)

Example 3 with NetSuiteConnectionProperties

use of org.talend.components.netsuite.connection.NetSuiteConnectionProperties in project components by Talend.

the class AbstractNetSuiteComponentMockTestFixture method setUp.

@Override
public void setUp() throws Exception {
    if (reinstall) {
        webServiceMockTestFixture.reinstall();
    }
    final PortT port = webServiceMockTestFixture.getPortMock();
    mockLoginResponse(port);
    runtimeContainer = spy(new DefaultComponentRuntimeContainerImpl());
    connectionProperties = new NetSuiteConnectionProperties("test");
    connectionProperties.init();
    connectionProperties.endpoint.setValue(webServiceMockTestFixture.getEndpointAddress().toString());
    connectionProperties.apiVersion.setValue(webServiceMockTestFixture.getClientFactory().getApiVersion().getMajorAsString("."));
    connectionProperties.email.setValue("test@test.com");
    connectionProperties.password.setValue("123");
    connectionProperties.role.setValue(3);
    connectionProperties.account.setValue("test");
    connectionProperties.applicationId.setValue("00000000-0000-0000-0000-000000000000");
    connectionProperties.customizationEnabled.setValue(true);
}
Also used : DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) NetSuiteConnectionProperties(org.talend.components.netsuite.connection.NetSuiteConnectionProperties)

Aggregations

NetSuiteConnectionProperties (org.talend.components.netsuite.connection.NetSuiteConnectionProperties)3 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 JarRuntimeInfo (org.talend.components.api.component.runtime.JarRuntimeInfo)1 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)1 NetSuiteCredentials (org.talend.components.netsuite.client.NetSuiteCredentials)1 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)1 NetSuiteInputProperties (org.talend.components.netsuite.input.NetSuiteInputProperties)1 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)1