use of com.netsuite.webservices.v2014_2.platform.NetSuitePortType in project components by Talend.
the class NetSuiteMockTestBase method mockCustomizationRequestResults.
protected void mockCustomizationRequestResults(final Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs) throws Exception {
final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
when(port.getCustomizationId(any(GetCustomizationIdRequest.class))).then(new Answer<GetCustomizationIdResponse>() {
@Override
public GetCustomizationIdResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
GetCustomizationIdRequest request = (GetCustomizationIdRequest) invocationOnMock.getArguments()[0];
CustomizationType customizationType = request.getCustomizationType();
GetCustomizationIdResult result = new GetCustomizationIdResult();
result.setCustomizationRefList(new CustomizationRefList());
result.setStatus(createSuccessStatus());
Map<String, CustomizationRef> customizationRefMap = createCustomFieldCustomizationRefs(customFieldSpecs);
for (String scriptId : customFieldSpecs.keySet()) {
RecordType recordType = RecordType.fromValue(customizationType.getGetCustomizationType().value());
CustomizationRef customizationRef = customizationRefMap.get(scriptId);
if (recordType == customizationRef.getType()) {
result.getCustomizationRefList().getCustomizationRef().add(customizationRef);
}
}
result.setTotalRecords(result.getCustomizationRefList().getCustomizationRef().size());
GetCustomizationIdResponse response = new GetCustomizationIdResponse();
response.setGetCustomizationIdResult(result);
return response;
}
});
when(port.getList(any(GetListRequest.class))).then(new Answer<GetListResponse>() {
@Override
public GetListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
GetListRequest request = (GetListRequest) invocationOnMock.getArguments()[0];
ReadResponseList readResponseList = new ReadResponseList();
readResponseList.setStatus(createSuccessStatus());
Map<String, CustomFieldType> customFieldTypeMap = createCustomFieldTypes(customFieldSpecs);
for (BaseRef ref : request.getBaseRef()) {
if (ref instanceof CustomizationRef) {
CustomizationRef customizationRef = (CustomizationRef) ref;
if (customFieldTypeMap.containsKey(customizationRef.getScriptId())) {
CustomFieldType fieldType = customFieldTypeMap.get(customizationRef.getScriptId());
ReadResponse readResponse = new ReadResponse();
readResponse.setRecord(fieldType);
readResponse.setStatus(createSuccessStatus());
readResponseList.getReadResponse().add(readResponse);
}
}
}
GetListResponse response = new GetListResponse();
response.setReadResponseList(readResponseList);
return response;
}
});
}
use of com.netsuite.webservices.v2014_2.platform.NetSuitePortType in project components by Talend.
the class CustomMetaDataRetrieverImpl method retrieveCustomizations.
public List<?> retrieveCustomizations(final List<NsRef> nsCustomizationRefs) throws NetSuiteException {
if (nsCustomizationRefs.isEmpty()) {
return Collections.emptyList();
}
final List<CustomizationRef> customizationRefs = new ArrayList<>(nsCustomizationRefs.size());
for (NsRef nsCustomizationRef : nsCustomizationRefs) {
CustomizationRef customizationRef = new CustomizationRef();
customizationRef.setType(RecordType.fromValue(nsCustomizationRef.getType()));
customizationRef.setScriptId(nsCustomizationRef.getScriptId());
customizationRef.setInternalId(nsCustomizationRef.getInternalId());
customizationRefs.add(customizationRef);
}
List<NsReadResponse<Record>> result = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Record>>, NetSuitePortType>() {
@Override
public List<NsReadResponse<Record>> execute(NetSuitePortType port) throws Exception {
logger.debug("Retrieving customizations: {}", nsCustomizationRefs.size());
StopWatch stopWatch = new StopWatch();
try {
stopWatch.start();
final GetListRequest request = new GetListRequest();
request.getBaseRef().addAll(customizationRefs);
return toNsReadResponseList(port.getList(request).getReadResponseList());
} finally {
stopWatch.stop();
logger.debug("Retrieved customizations: {}, {}", nsCustomizationRefs.size(), stopWatch);
}
}
});
if (!result.isEmpty()) {
List<Record> customizations = new ArrayList<>(result.size());
for (NsReadResponse<Record> response : result) {
if (response.getStatus().isSuccess()) {
customizations.add(response.getRecord());
} else {
throw new NetSuiteException("Retrieving of customization was not successful: " + response.getStatus());
}
}
return customizations;
} else {
return Collections.emptyList();
}
}
use of com.netsuite.webservices.v2014_2.platform.NetSuitePortType 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/2016.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 | InsufficientPermissionFault | InvalidCredentialsFault | InvalidSessionFault | UnexpectedErrorFault | ExceededRequestSizeFault e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e);
}
}
use of com.netsuite.webservices.v2014_2.platform.NetSuitePortType in project components by Talend.
the class NetSuiteComponentMockTestFixture method mockLoginResponse.
@Override
protected void mockLoginResponse(NetSuitePortType port) throws Exception {
SessionResponse sessionResponse = new SessionResponse();
Status status = new Status();
status.setIsSuccess(true);
sessionResponse.setStatus(status);
LoginResponse response = new LoginResponse();
response.setSessionResponse(sessionResponse);
when(port.login(any(LoginRequest.class))).thenReturn(response);
}
use of com.netsuite.webservices.v2014_2.platform.NetSuitePortType in project components by Talend.
the class NetSuiteClientServiceImpl method doLogin.
protected void doLogin() throws NetSuiteException {
port = getNetSuitePort(endpointUrl, credentials.getAccount());
setHttpClientPolicy(port);
setLoginHeaders(port);
PortOperation<SessionResponse, NetSuitePortType> loginOp;
if (!credentials.isUseSsoLogin()) {
final Passport passport = createNativePassport(credentials);
loginOp = new PortOperation<SessionResponse, NetSuitePortType>() {
@Override
public SessionResponse execute(NetSuitePortType port) throws Exception {
LoginRequest request = new LoginRequest();
request.setPassport(passport);
LoginResponse response = port.login(request);
return response.getSessionResponse();
}
};
} else {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.ssoLoginNotSupported"));
}
Status status = null;
SessionResponse sessionResponse;
String exceptionMessage = null;
for (int i = 0; i < getRetryCount(); i++) {
try {
sessionResponse = loginOp.execute(port);
status = sessionResponse.getStatus();
} catch (InvalidCredentialsFault f) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), f.getFaultInfo().getMessage());
} catch (UnexpectedErrorFault f) {
exceptionMessage = f.getFaultInfo().getMessage();
} catch (Exception e) {
exceptionMessage = e.getMessage();
}
if (status != null) {
break;
}
if (i != getRetryCount() - 1) {
waitForRetryInterval();
}
}
checkLoginError(toNsStatus(status), exceptionMessage);
removeLoginHeaders(port);
}
Aggregations