Search in sources :

Example 1 with Account

use of com.netsuite.webservices.v2014_2.lists.accounting.Account in project components by Talend.

the class NetSuiteSearchInputReaderTest method testBasic.

@Test
public void testBasic() throws Exception {
    properties.module.moduleName.setValue("Account");
    properties.module.searchQuery.field.setValue(Lists.newArrayList("type", "generalRateType"));
    properties.module.searchQuery.operator.setValue(Lists.newArrayList("List.anyOf", "List.anyOf"));
    properties.module.searchQuery.value1.setValue(Lists.newArrayList((Object) Arrays.asList("bank", "otherAsset"), (Object) Arrays.asList("current", "historical")));
    properties.module.searchQuery.value2.setValue(Lists.newArrayList(null, null));
    NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(mockTestFixture.getRuntimeContainer(), properties);
    List<Account> recordList = makeNsObjects(new SimpleObjectComposer<>(Account.class), 150);
    mockSearchRequestResults(recordList, 100);
    NetSuiteClientService<?> clientService = source.getClientService();
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(Account.class);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(mockTestFixture.getRuntimeContainer());
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    while (reader.advance()) {
        record = reader.getCurrent();
        assertIndexedRecord(typeDesc, record);
    }
    Map<String, Object> readerResult = reader.getReturnValues();
    assertNotNull(readerResult);
    assertEquals(150, readerResult.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
}
Also used : Account(com.netsuite.webservices.v2016_2.lists.accounting.Account) NetSuiteSourceImpl(org.talend.components.netsuite.v2016_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) Test(org.junit.Test)

Example 2 with Account

use of com.netsuite.webservices.v2014_2.lists.accounting.Account in project components by Talend.

the class NetSuiteOutputWriterIT method testUpdate.

@Test
public void testUpdate() throws Exception {
    final NetSuiteClientService<NetSuitePortType> clientService = webServiceTestFixture.getClientService();
    clientService.getMetaDataSource().setCustomizationEnabled(false);
    RuntimeContainer container = mock(RuntimeContainer.class);
    NetSuiteOutputProperties properties = new NetSuiteOutputProperties("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(RecordTypeEnum.ACCOUNT.getTypeName());
    properties.module.action.setValue(OutputAction.UPDATE);
    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);
    SubsidiarySearch subsidiarySearch = new SubsidiarySearch();
    SubsidiarySearchBasic subsidiarySearchBasic = new SubsidiarySearchBasic();
    subsidiarySearch.setBasic(subsidiarySearchBasic);
    NsSearchResult<Subsidiary> searchResult = clientService.search(subsidiarySearch);
    assertTrue(searchResult.isSuccess());
    assertNotNull(searchResult.getRecordList());
    assertTrue(searchResult.getRecordList().size() > 0);
    Subsidiary subsidiary = searchResult.getRecordList().get(0);
    RecordRef subsidiaryRef = new RecordRef();
    subsidiaryRef.setType(RecordType.SUBSIDIARY);
    subsidiaryRef.setInternalId(subsidiary.getInternalId());
    List<Account> recordsToAdd = makeAccountRecords(5, subsidiaryRef);
    final List<RecordRef> refList = new ArrayList<>(recordsToAdd.size());
    // Add records
    List<NsWriteResponse<RecordRef>> writeResponseList = clientService.addList(recordsToAdd);
    for (NsWriteResponse<RecordRef> writeResponse : writeResponseList) {
        assertTrue(writeResponse.getStatus().isSuccess());
        assertNotNull(writeResponse.getRef());
        refList.add(writeResponse.getRef());
    }
    // Read added records
    List<Account> recordList = new ArrayList<>(refList.size());
    List<NsReadResponse<Account>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Account>>, NetSuitePortType>() {

        @Override
        public List<NsReadResponse<Account>> execute(NetSuitePortType port) throws Exception {
            GetListRequest request = new GetListRequest();
            request.getBaseRef().addAll(refList);
            return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
        }
    });
    for (NsReadResponse<Account> readResponse : readResponseList) {
        assertTrue(readResponse.getStatus().isSuccess());
        recordList.add(readResponse.getRecord());
    }
    List<IndexedRecord> indexedRecordList = new ArrayList<>(refList.size());
    for (Account record : recordList) {
        GenericRecord indexedRecord = new GenericData.Record(schema);
        indexedRecord.put("InternalId", record.getInternalId());
        indexedRecord.put("AcctNumber", record.getAcctNumber());
        indexedRecord.put("AcctType", record.getAcctType().value());
        // Updated fields
        indexedRecord.put("AcctName", record.getAcctName() + " (edited)");
        indexedRecord.put("Description", "qwerty");
        indexedRecordList.add(indexedRecord);
    }
    // Update records
    NetSuiteSink sink = new NetSuiteSinkImpl();
    sink.setClientFactory(clientFactory);
    sink.initialize(container, properties);
    NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
    NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(container);
    writer.open(UUID.randomUUID().toString());
    for (IndexedRecord indexedRecord : indexedRecordList) {
        writer.write(indexedRecord);
    }
    Result writerResult = writer.close();
    assertNotNull(writerResult);
    assertEquals(indexedRecordList.size(), writerResult.totalCount);
    assertEquals(indexedRecordList.size(), writerResult.successCount);
    // Re-read updated records
    readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Account>>, NetSuitePortType>() {

        @Override
        public List<NsReadResponse<Account>> execute(NetSuitePortType port) throws Exception {
            GetListRequest request = new GetListRequest();
            request.getBaseRef().addAll(refList);
            return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
        }
    });
    for (NsReadResponse<Account> readResponse : readResponseList) {
        assertTrue(readResponse.getStatus().isSuccess());
        Account record = readResponse.getRecord();
        assertEquals("qwerty", record.getDescription());
        assertTrue(record.getAcctName().endsWith("(edited)"));
    }
    clientService.deleteList(refList);
}
Also used : Account(com.netsuite.webservices.v2016_2.lists.accounting.Account) NetSuiteSinkImpl(org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) RecordRef(com.netsuite.webservices.v2016_2.platform.core.RecordRef) CustomRecordRef(com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef) ArrayList(java.util.ArrayList) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteWriteOperation(org.talend.components.netsuite.output.NetSuiteWriteOperation) NsReadResponse(org.talend.components.netsuite.client.NsReadResponse) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) Result(org.talend.components.api.component.runtime.Result) NsSearchResult(org.talend.components.netsuite.client.NsSearchResult) SubsidiarySearch(com.netsuite.webservices.v2016_2.lists.accounting.SubsidiarySearch) Subsidiary(com.netsuite.webservices.v2016_2.lists.accounting.Subsidiary) CustomFieldList(com.netsuite.webservices.v2016_2.platform.core.CustomFieldList) List(java.util.List) ArrayList(java.util.ArrayList) RecordRefList(com.netsuite.webservices.v2016_2.platform.core.RecordRefList) CustomRecord(com.netsuite.webservices.v2016_2.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord) NsWriteResponse(org.talend.components.netsuite.client.NsWriteResponse) NetSuiteOutputWriter(org.talend.components.netsuite.output.NetSuiteOutputWriter) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) SubsidiarySearchBasic(com.netsuite.webservices.v2016_2.platform.common.SubsidiarySearchBasic) NetSuiteOutputProperties(org.talend.components.netsuite.output.NetSuiteOutputProperties) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteSink(org.talend.components.netsuite.NetSuiteSink) GetListRequest(com.netsuite.webservices.v2016_2.platform.messages.GetListRequest) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 3 with Account

use of com.netsuite.webservices.v2014_2.lists.accounting.Account in project components by Talend.

the class NetSuiteClientServiceImpl method getNetSuitePort.

protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
    try {
        URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2014.2/netsuite.wsdl");
        NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);
        List<WebServiceFeature> features = new ArrayList<>(2);
        if (isMessageLoggingEnabled()) {
            features.add(new LoggingFeature());
        }
        NetSuitePortType port = service.getNetSuitePort(features.toArray(new WebServiceFeature[features.size()]));
        BindingProvider provider = (BindingProvider) port;
        Map<String, Object> requestContext = provider.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);
        GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
        dataCenterRequest.setAccount(account);
        DataCenterUrls urls = null;
        GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
        if (response != null && response.getGetDataCenterUrlsResult() != null) {
            urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
        }
        if (urls == null) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain", defaultEndpointUrl));
        }
        String wsDomain = urls.getWebservicesDomain();
        String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());
        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
        return port;
    } catch (WebServiceException | MalformedURLException | UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) GetDataCenterUrlsResponse(com.netsuite.webservices.v2014_2.platform.messages.GetDataCenterUrlsResponse) ArrayList(java.util.ArrayList) DataCenterUrls(com.netsuite.webservices.v2014_2.platform.core.DataCenterUrls) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.v2014_2.platform.UnexpectedErrorFault) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) NetSuiteService(com.netsuite.webservices.v2014_2.platform.NetSuiteService) LoggingFeature(org.apache.cxf.feature.LoggingFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) GetDataCenterUrlsRequest(com.netsuite.webservices.v2014_2.platform.messages.GetDataCenterUrlsRequest) ExceededRequestSizeFault(com.netsuite.webservices.v2014_2.platform.ExceededRequestSizeFault)

Example 4 with Account

use of com.netsuite.webservices.v2014_2.lists.accounting.Account in project components by Talend.

the class NetSuiteSearchInputReaderTest method testBasic.

@Test
public void testBasic() throws Exception {
    properties.module.moduleName.setValue("Account");
    NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(mockTestFixture.getRuntimeContainer(), properties);
    List<Account> recordList = makeNsObjects(new SimpleObjectComposer<>(Account.class), 150);
    mockSearchRequestResults(recordList, 100);
    NetSuiteClientService<?> clientService = source.getClientService();
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(Account.class);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(mockTestFixture.getRuntimeContainer());
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    while (reader.advance()) {
        record = reader.getCurrent();
        assertIndexedRecord(typeDesc, record);
    }
    Map<String, Object> readerResult = reader.getReturnValues();
    assertNotNull(readerResult);
    assertEquals(150, readerResult.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
}
Also used : Account(com.netsuite.webservices.v2014_2.lists.accounting.Account) NetSuiteSourceImpl(org.talend.components.netsuite.v2014_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2014_2.NetSuiteRuntimeImpl) Test(org.junit.Test)

Example 5 with Account

use of com.netsuite.webservices.v2014_2.lists.accounting.Account in project components by Talend.

the class NetSuiteOutputWriterIT method makeAccountRecords.

private static List<Account> makeAccountRecords(int count, RecordRef subsidiary) {
    List<Account> recordList = new ArrayList<>(count);
    for (int i = 1; i <= count; i++) {
        Account record = new Account();
        String id = Long.toString(System.currentTimeMillis());
        record.setAcctNumber(id);
        record.setAcctName("Test account " + id);
        record.setAcctType(AccountType.OTHER_ASSET);
        record.setDescription("Test description " + i);
        RecordRefList subsidiaries = new RecordRefList();
        subsidiaries.getRecordRef().add(subsidiary);
        record.setSubsidiaryList(subsidiaries);
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }
        recordList.add(record);
    }
    return recordList;
}
Also used : RecordRefList(com.netsuite.webservices.v2016_2.platform.core.RecordRefList) Account(com.netsuite.webservices.v2016_2.lists.accounting.Account) ArrayList(java.util.ArrayList)

Aggregations

Test (org.junit.Test)4 Account (com.netsuite.webservices.v2016_2.lists.accounting.Account)3 ArrayList (java.util.ArrayList)3 Schema (org.apache.avro.Schema)3 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)3 RecordRefList (com.netsuite.webservices.v2016_2.platform.core.RecordRefList)2 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)2 NetSuiteSource (org.talend.components.netsuite.NetSuiteSource)2 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)2 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)2 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl)2 Account (com.netsuite.webservices.v2014_2.lists.accounting.Account)1 ExceededRequestSizeFault (com.netsuite.webservices.v2014_2.platform.ExceededRequestSizeFault)1 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)1 NetSuiteService (com.netsuite.webservices.v2014_2.platform.NetSuiteService)1 UnexpectedErrorFault (com.netsuite.webservices.v2014_2.platform.UnexpectedErrorFault)1 DataCenterUrls (com.netsuite.webservices.v2014_2.platform.core.DataCenterUrls)1 Record (com.netsuite.webservices.v2014_2.platform.core.Record)1 GetDataCenterUrlsRequest (com.netsuite.webservices.v2014_2.platform.messages.GetDataCenterUrlsRequest)1