Search in sources :

Example 1 with NetSuiteInputProperties

use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.

the class NetSuiteSearchInputReaderIT method testInput.

@Test
public void testInput() throws Exception {
    RuntimeContainer container = mock(RuntimeContainer.class);
    NetSuiteInputProperties properties = new NetSuiteInputProperties("test");
    properties.init();
    properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
    properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
    properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
    properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
    properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
    properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
    properties.module.moduleName.setValue("Account");
    NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    properties.module.afterModuleName();
    properties.module.searchQuery.field.setValue(Arrays.asList("Type"));
    properties.module.searchQuery.operator.setValue(Arrays.asList("List.anyOf"));
    properties.module.searchQuery.value1.setValue(Arrays.<Object>asList("Bank"));
    properties.module.searchQuery.value2.setValue(Arrays.<Object>asList((String) null));
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(container, properties);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(container);
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    List<Schema.Field> fields = record.getSchema().getFields();
    for (int i = 0; i < fields.size(); i++) {
        Schema.Field typeField = getFieldByName(fields, "AcctType");
        Object value = record.get(typeField.pos());
        assertNotNull(value);
        assertEquals(AccountType.BANK.value(), value);
    }
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) NetSuiteSourceImpl(org.talend.components.netsuite.v2014_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) Schema(org.apache.avro.Schema) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2014_2.NetSuiteRuntimeImpl) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 2 with NetSuiteInputProperties

use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.

the class NetSuiteSearchInputReaderTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    installMockTestFixture();
    super.setUp();
    properties = new NetSuiteInputProperties("test");
    properties.init();
    properties.connection.copyValuesFrom(mockTestFixture.getConnectionProperties());
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) Before(org.junit.Before)

Example 3 with NetSuiteInputProperties

use of org.talend.components.netsuite.input.NetSuiteInputProperties 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 4 with NetSuiteInputProperties

use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.

the class NetSuiteSearchInputReaderTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    installMockTestFixture();
    super.setUp();
    properties = new NetSuiteInputProperties("test");
    properties.init();
    properties.connection.copyValuesFrom(mockTestFixture.getConnectionProperties());
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) Before(org.junit.Before)

Example 5 with NetSuiteInputProperties

use of org.talend.components.netsuite.input.NetSuiteInputProperties in project components by Talend.

the class NetSuiteSearchInputReaderIT method testSearch.

@Test
public void testSearch() throws Exception {
    RuntimeContainer container = mock(RuntimeContainer.class);
    NetSuiteInputProperties properties = new NetSuiteInputProperties("test");
    properties.init();
    properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
    properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
    properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
    properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
    properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
    properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
    properties.module.moduleName.setValue("Account");
    NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
    runtime.setClientFactory(clientFactory);
    NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    properties.module.afterModuleName();
    properties.module.searchQuery.field.setValue(Arrays.asList("Type"));
    properties.module.searchQuery.operator.setValue(Arrays.asList("List.anyOf"));
    properties.module.searchQuery.value1.setValue(Arrays.<Object>asList("Bank"));
    properties.module.searchQuery.value2.setValue(Arrays.<Object>asList((String) null));
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(container, properties);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(container);
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    List<Schema.Field> fields = record.getSchema().getFields();
    for (int i = 0; i < fields.size(); i++) {
        Schema.Field typeField = getFieldByName(fields, "AcctType");
        Object value = record.get(typeField.pos());
        assertNotNull(value);
        assertEquals(AccountType.BANK.value(), value);
    }
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) NetSuiteSourceImpl(org.talend.components.netsuite.v2016_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) Schema(org.apache.avro.Schema) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

NetSuiteInputProperties (org.talend.components.netsuite.input.NetSuiteInputProperties)5 Schema (org.apache.avro.Schema)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 Before (org.junit.Before)2 Test (org.junit.Test)2 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)2 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)2 NetSuiteSource (org.talend.components.netsuite.NetSuiteSource)2 NetSuiteSearchInputReader (org.talend.components.netsuite.input.NetSuiteSearchInputReader)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NetSuiteCredentials (org.talend.components.netsuite.client.NetSuiteCredentials)1 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)1 NetSuiteConnectionProperties (org.talend.components.netsuite.connection.NetSuiteConnectionProperties)1 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2014_2.NetSuiteRuntimeImpl)1 NetSuiteSourceImpl (org.talend.components.netsuite.v2014_2.NetSuiteSourceImpl)1 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl)1 NetSuiteSourceImpl (org.talend.components.netsuite.v2016_2.NetSuiteSourceImpl)1