Search in sources :

Example 6 with NetSuiteException

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

the class ValueConverterTest method testJsonConverterError.

@Test
public void testJsonConverterError() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    FieldDesc fieldDesc = typeDesc.getField("department");
    AvroConverter<RecordRef, String> converter1 = (AvroConverter<RecordRef, String>) transducer.getValueConverter(fieldDesc);
    try {
        converter1.convertToDatum("{name:'R&D',internalId:'12345',externalId:null,type:null}");
        fail("NetSuiteException expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(NetSuiteException.class));
        NetSuiteException nsException = (NetSuiteException) e;
        assertNotNull(nsException.getCode());
        assertNotNull(nsException.getContext());
        assertNotNull(nsException.getContext().get(ExceptionContext.KEY_MESSAGE));
    }
}
Also used : RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 7 with NetSuiteException

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

the class NetSuiteOutputWriterIT method testDelete.

@Test
public void testDelete() throws Exception {
    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.MESSAGE.getTypeName());
    properties.module.action.setValue(OutputAction.DELETE);
    NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
    runtime.setClientFactory(clientFactory);
    NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(RefType.RECORD_REF.getTypeName());
    properties.module.main.schema.setValue(schema);
    List<Message> recordsToAdd = makeMessageRecords(5);
    final List<RecordRef> refList = new ArrayList<>(recordsToAdd.size());
    List<NsWriteResponse<RecordRef>> writeResponseList = clientService.addList(recordsToAdd);
    for (NsWriteResponse<RecordRef> writeResponse : writeResponseList) {
        assertTrue(writeResponse.getStatus().isSuccess());
        assertNotNull(writeResponse.getRef());
        refList.add(writeResponse.getRef());
    }
    List<IndexedRecord> indexedRecordList = makeRecordRefIndexedRecords(schema, refList);
    NetSuiteSink sink = new NetSuiteSinkImpl();
    sink.setClientFactory(new NetSuiteClientFactoryImpl() {

        @Override
        public NetSuiteClientService<NetSuitePortType> createClient() throws NetSuiteException {
            NetSuiteClientService<NetSuitePortType> service = super.createClient();
            service.getMetaDataSource().setCustomizationEnabled(webServiceTestFixture.getClientService().getMetaDataSource().isCustomizationEnabled());
            return service;
        }
    });
    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);
    List<NsReadResponse<Message>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Message>>, NetSuitePortType>() {

        @Override
        public List<NsReadResponse<Message>> execute(NetSuitePortType port) throws Exception {
            GetListRequest request = new GetListRequest();
            request.getBaseRef().addAll(refList);
            return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
        }
    });
    for (NsReadResponse<Message> readResponse : readResponseList) {
        // success=false means that NetSuite Record was not found because it was deleted
        assertFalse(readResponse.getStatus().isSuccess());
    }
}
Also used : NetSuiteSinkImpl(org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl) Message(com.netsuite.webservices.v2016_2.general.communication.Message) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) NetSuiteClientFactoryImpl(org.talend.components.netsuite.v2016_2.client.NetSuiteClientFactoryImpl) 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) 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) NsWriteResponse(org.talend.components.netsuite.client.NsWriteResponse) NetSuiteOutputWriter(org.talend.components.netsuite.output.NetSuiteOutputWriter) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) 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 8 with NetSuiteException

use of org.talend.components.netsuite.client.NetSuiteException 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 9 with NetSuiteException

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

the class SearchQuery method condition.

/**
 * Add condition for search query.
 *
 * @param condition condition to be added
 * @return
 * @throws NetSuiteException if an error occurs during adding of condition
 */
public SearchQuery condition(SearchCondition condition) throws NetSuiteException {
    initSearch();
    BeanInfo searchMetaData = Beans.getBeanInfo(searchRecordTypeDesc.getSearchBasicClass());
    String fieldName = toInitialLower(condition.getFieldName());
    PropertyInfo propertyInfo = searchMetaData.getProperty(fieldName);
    SearchFieldOperatorName operatorQName = new SearchFieldOperatorName(condition.getOperatorName());
    if (propertyInfo != null) {
        Object searchField = processConditionForSearchRecord(searchBasic, condition);
        setProperty(searchBasic, fieldName, searchField);
    } else {
        String dataType = operatorQName.getDataType();
        SearchFieldType searchFieldType = null;
        if (SearchFieldOperatorType.STRING.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_STRING;
        } else if (SearchFieldOperatorType.BOOLEAN.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_BOOLEAN;
        } else if (SearchFieldOperatorType.LONG.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_LONG;
        } else if (SearchFieldOperatorType.DOUBLE.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_DOUBLE;
        } else if (SearchFieldOperatorType.DATE.dataTypeEquals(dataType) || SearchFieldOperatorType.PREDEFINED_DATE.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_DATE;
        } else if (SearchFieldOperatorType.MULTI_SELECT.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_MULTI_SELECT;
        } else if (SearchFieldOperatorType.ENUM_MULTI_SELECT.dataTypeEquals(dataType)) {
            searchFieldType = SearchFieldType.CUSTOM_SELECT;
        } else {
            throw new NetSuiteException("Invalid data type: " + searchFieldType);
        }
        Object searchField = processCondition(searchFieldType, condition);
        customFieldList.add(searchField);
    }
    return this;
}
Also used : BeanInfo(org.talend.components.netsuite.client.model.beans.BeanInfo) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) SearchFieldOperatorName(org.talend.components.netsuite.client.model.search.SearchFieldOperatorName) SearchFieldType(org.talend.components.netsuite.client.model.search.SearchFieldType) PropertyInfo(org.talend.components.netsuite.client.model.beans.PropertyInfo)

Example 10 with NetSuiteException

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

the class NetSuiteSearchInputReader method advance.

@Override
public boolean advance() throws IOException {
    try {
        if (resultSet.next()) {
            currentRecord = resultSet.get();
            currentIndexedRecord = transducer.read(currentRecord);
            dataCount++;
            return true;
        }
        return false;
    } catch (NetSuiteException e) {
        throw new IOException(e);
    }
}
Also used : NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) IOException(java.io.IOException)

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