use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class SearchFieldAdapter method createField.
/**
* Create instance of NetSuite's search field.
*
* @param internalId internal identifier to be applied to a search field
* @return search field object
* @throws NetSuiteException if an error occurs during creation of a search field
*/
protected T createField(String internalId) throws NetSuiteException {
try {
BeanInfo fieldTypeMetaData = Beans.getBeanInfo(fieldClass);
T searchField = fieldClass.newInstance();
if (fieldTypeMetaData.getProperty("internalId") != null && internalId != null) {
setProperty(searchField, "internalId", internalId);
}
return searchField;
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException e) {
throw new NetSuiteException(e.getMessage(), e);
}
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteEndpoint method createConnectionConfig.
/**
* Create connection configuration for given connection properties.
*
* @param properties connection properties
* @return connection configuration
* @throws NetSuiteException if connection configuration not valid
*/
public static ConnectionConfig createConnectionConfig(NetSuiteProvideConnectionProperties properties) throws NetSuiteException {
NetSuiteConnectionProperties connProps = properties.getConnectionProperties();
if (StringUtils.isEmpty(connProps.endpoint.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.endpointUrlRequired"));
}
if (StringUtils.isEmpty(connProps.apiVersion.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.apiVersionRequired"));
}
if (StringUtils.isEmpty(connProps.email.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.emailRequired"));
}
if (StringUtils.isEmpty(connProps.password.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.passwordRequired"));
}
if (StringUtils.isEmpty(connProps.account.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.accountRequired"));
}
if (connProps.role.getValue() == null) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.roleRequired"));
}
String endpointUrl = connProps.endpoint.getStringValue();
NetSuiteVersion endpointApiVersion;
try {
endpointApiVersion = NetSuiteVersion.detectVersion(endpointUrl);
} catch (IllegalArgumentException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotDetectApiVersionFromEndpointUrl", endpointUrl));
}
String apiVersionString = connProps.apiVersion.getStringValue();
NetSuiteVersion apiVersion;
try {
apiVersion = NetSuiteVersion.parseVersion(apiVersionString);
} catch (IllegalArgumentException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.invalidApiVersion", apiVersionString));
}
if (!endpointApiVersion.isSameMajor(apiVersion)) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.endpointUrlApiVersionMismatch", endpointUrl, apiVersionString));
}
if (apiVersion.getMajorYear() >= 2015 && StringUtils.isEmpty(connProps.applicationId.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.applicationIdRequired"));
}
String email = connProps.email.getStringValue();
String password = connProps.password.getStringValue();
Integer roleId = connProps.role.getValue();
String account = connProps.account.getStringValue();
String applicationId = connProps.applicationId.getStringValue();
Boolean customizationEnabled = connProps.customizationEnabled.getValue();
NetSuiteCredentials credentials = new NetSuiteCredentials();
credentials.setEmail(email);
credentials.setPassword(password);
credentials.setRoleId(roleId.toString());
credentials.setAccount(account);
credentials.setApplicationId(applicationId);
try {
ConnectionConfig connectionConfig = new ConnectionConfig(new URL(endpointUrl), apiVersion.getMajor(), credentials);
if (properties instanceof NetSuiteInputProperties) {
connectionConfig.setBodyFieldsOnly(((NetSuiteInputProperties) properties).bodyFieldsOnly.getValue());
}
connectionConfig.setCustomizationEnabled(customizationEnabled);
return connectionConfig;
} catch (MalformedURLException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.invalidEndpointUrl", endpointUrl));
}
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSchemaForRecordRef.
public Schema getSchemaForRecordRef(String typeName) {
try {
// Get info for target record type
final RecordTypeInfo referencedRecordTypeInfo = metaDataSource.getRecordType(typeName);
final RefType refType = referencedRecordTypeInfo.getRefType();
// Get type info for record ref
final TypeDesc typeDesc = metaDataSource.getTypeInfo(refType.getTypeName());
List<FieldDesc> fieldDescList = new ArrayList<>(typeDesc.getFields());
// Sort in alphabetical order
Collections.sort(fieldDescList, FieldDescComparator.INSTANCE);
Schema schema = inferSchemaForType(typeDesc.getTypeName(), fieldDescList);
augmentSchemaWithCustomMetaData(metaDataSource, schema, referencedRecordTypeInfo, null);
return schema;
} catch (NetSuiteException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSchema.
@Override
public Schema getSchema(String typeName) {
try {
final RecordTypeInfo recordTypeInfo = metaDataSource.getRecordType(typeName);
final TypeDesc typeDesc = metaDataSource.getTypeInfo(typeName);
List<FieldDesc> fieldDescList = new ArrayList<>(typeDesc.getFields());
// Sort in alphabetical order
Collections.sort(fieldDescList, FieldDescComparator.INSTANCE);
Schema schema = inferSchemaForType(typeDesc.getTypeName(), fieldDescList);
augmentSchemaWithCustomMetaData(metaDataSource, schema, recordTypeInfo, fieldDescList);
return schema;
} catch (NetSuiteException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteDatasetRuntimeImpl method getSearchableTypes.
@Override
public List<NamedThing> getSearchableTypes() {
try {
List<NamedThing> searchableTypes = new ArrayList<>(metaDataSource.getSearchableTypes());
// Sort by display name in alphabetical order
Collections.sort(searchableTypes, new Comparator<NamedThing>() {
@Override
public int compare(NamedThing o1, NamedThing o2) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
}
});
return searchableTypes;
} catch (NetSuiteException e) {
throw new ComponentException(e);
}
}
Aggregations