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));
}
}
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());
}
}
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);
}
}
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;
}
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);
}
}
Aggregations