use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class CustomMetaDataRetrieverImpl method retrieveCustomizationIds.
public List<NsRef> retrieveCustomizationIds(final BasicRecordType type) throws NetSuiteException {
GetCustomizationIdResult result = clientService.execute(new NetSuiteClientService.PortOperation<GetCustomizationIdResult, NetSuitePortType>() {
@Override
public GetCustomizationIdResult execute(NetSuitePortType port) throws Exception {
logger.debug("Retrieving customization IDs: {}", type.getType());
StopWatch stopWatch = new StopWatch();
try {
stopWatch.start();
final GetCustomizationIdRequest request = new GetCustomizationIdRequest();
CustomizationType customizationType = new CustomizationType();
customizationType.setGetCustomizationType(GetCustomizationType.fromValue(type.getType()));
request.setCustomizationType(customizationType);
return port.getCustomizationId(request).getGetCustomizationIdResult();
} finally {
stopWatch.stop();
logger.debug("Retrieved customization IDs: {}, {}", type.getType(), stopWatch);
}
}
});
if (result.getStatus().getIsSuccess()) {
List<NsRef> nsRefs;
if (result.getTotalRecords() > 0) {
final List<CustomizationRef> refs = result.getCustomizationRefList().getCustomizationRef();
nsRefs = new ArrayList<>(refs.size());
for (final CustomizationRef ref : refs) {
NsRef nsRef = new NsRef();
nsRef.setRefType(RefType.CUSTOMIZATION_REF);
nsRef.setScriptId(ref.getScriptId());
nsRef.setInternalId(ref.getInternalId());
nsRef.setType(ref.getType().value());
nsRef.setName(ref.getName());
nsRefs.add(nsRef);
}
} else {
nsRefs = Collections.emptyList();
}
return nsRefs;
} else {
throw new NetSuiteException("Retrieving of customizations was not successful: " + type);
}
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteClientServiceImpl method doLogin.
@Override
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);
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class TestNetSuiteClientService method doLogout.
@Override
protected void doLogout() throws NetSuiteException {
try {
LogoutRequest request = new LogoutRequest();
port.logout(request);
} catch (Exception e) {
throw new NetSuiteException(e.getMessage(), e);
}
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class TestNetSuiteClientService method doLogin.
@Override
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);
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteDatasetRuntimeTest method testGetSchemaForRecordWithCustomFields.
@Test
public void testGetSchemaForRecordWithCustomFields() throws Exception {
final CustomMetaDataSource customMetaDataSource = new EmptyCustomMetaDataSource() {
@Override
public Map<String, CustomFieldDesc> getCustomFields(RecordTypeInfo recordTypeInfo) {
try {
if (recordTypeInfo.getName().equals("Account")) {
JsonNode fieldListNode = objectMapper.readTree(NetSuiteDatasetRuntimeTest.class.getResource("/test-data/customFields-1.json"));
Map<String, CustomFieldDesc> customFieldDescMap = TestUtils.readCustomFields(fieldListNode);
return customFieldDescMap;
}
return null;
} catch (IOException e) {
throw new NetSuiteException(e.getMessage(), e);
}
}
};
MetaDataSource metaDataSource = clientService.createDefaultMetaDataSource();
metaDataSource.setCustomMetaDataSource(customMetaDataSource);
NetSuiteDatasetRuntimeImpl datasetRuntime = new NetSuiteDatasetRuntimeImpl(metaDataSource);
TypeDesc typeDesc = metaDataSource.getTypeInfo("Account");
Schema s = datasetRuntime.getSchema(typeDesc.getTypeName());
assertThat(s.getType(), is(Schema.Type.RECORD));
assertThat(s.getName(), is("Account"));
assertThat(s.getFields(), hasSize(typeDesc.getFields().size()));
assertThat(s.getObjectProps().keySet(), Matchers.<String>empty());
CustomFieldDesc fieldDesc = (CustomFieldDesc) typeDesc.getField("custom_field_1");
Schema.Field f = getNsFieldByName(s, fieldDesc.getName());
assertUnionType(f.schema(), Arrays.asList(Schema.Type.STRING, Schema.Type.NULL));
assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE, NetSuiteSchemaConstants.NS_CUSTOM_FIELD, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_SCRIPT_ID, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_INTERNAL_ID, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_CUSTOMIZATION_TYPE, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_TYPE));
assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
CustomFieldDesc customFieldDesc = NetSuiteDatasetRuntimeImpl.readCustomField(f);
assertThat(customFieldDesc.getName(), is(fieldDesc.getName()));
}
Aggregations