use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteSearchInputReader method start.
@Override
public boolean start() throws IOException {
try {
schema = properties.module.main.schema.getValue();
clientService = ((NetSuiteSource) getCurrentSource()).getClientService();
// Set up MetaDataSource which retrieves customization meta data from schema.
// We use MetaDataSource from NetSuite client as base source.
MetaDataSource originalMetaDataSource = clientService.getMetaDataSource();
metaDataSource = clientService.createDefaultMetaDataSource();
metaDataSource.setCustomizationEnabled(originalMetaDataSource.isCustomizationEnabled());
SchemaCustomMetaDataSource schemaCustomMetaDataSource = new SchemaCustomMetaDataSource(clientService.getBasicMetaData(), originalMetaDataSource.getCustomMetaDataSource(), schema);
metaDataSource.setCustomMetaDataSource(schemaCustomMetaDataSource);
// Execute search and get search result set.
resultSet = search();
return advance();
} catch (NetSuiteException e) {
throw new IOException(e);
}
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteOutputWriter method open.
@Override
public void open(String uId) throws IOException {
try {
clientService = writeOperation.getSink().getClientService();
// Get descriptor of target NetSuite data model object type.
String typeName = writeOperation.getProperties().module.moduleName.getValue();
typeDesc = metaDataSource.getTypeInfo(typeName);
schema = writeOperation.getProperties().module.main.schema.getValue();
flowSchema = writeOperation.getProperties().module.flowSchema.schema.getValue();
rejectSchema = writeOperation.getProperties().module.rejectSchema.schema.getValue();
initTransducer();
} catch (NetSuiteException e) {
throw new IOException(e);
}
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class NetSuiteWriteOperation method createWriter.
@Override
public Writer<Result> createWriter(RuntimeContainer adaptor) {
NetSuiteClientService clientService = sink.getClientService();
OutputAction action = properties.module.action.getValue();
Schema schema = properties.module.main.schema.getValue();
MetaDataSource originalMetaDataSource = clientService.getMetaDataSource();
MetaDataSource metaDataSource = clientService.createDefaultMetaDataSource();
metaDataSource.setCustomizationEnabled(originalMetaDataSource.isCustomizationEnabled());
SchemaCustomMetaDataSource schemaCustomMetaDataSource = new SchemaCustomMetaDataSource(clientService.getBasicMetaData(), originalMetaDataSource.getCustomMetaDataSource(), schema);
metaDataSource.setCustomMetaDataSource(schemaCustomMetaDataSource);
NetSuiteOutputWriter<?, ?> writer;
switch(action) {
case ADD:
writer = new NetSuiteAddWriter<>(this, adaptor, metaDataSource);
break;
case UPDATE:
writer = new NetSuiteUpsertWriter<>(this, adaptor, metaDataSource);
break;
case UPSERT:
writer = new NetSuiteUpsertWriter<>(this, adaptor, metaDataSource);
Boolean useNativeUpsert = properties.module.useNativeUpsert.getValue();
if (useNativeUpsert != null) {
((NetSuiteUpsertWriter) writer).setUseNativeUpsert(useNativeUpsert);
}
break;
case DELETE:
writer = new NetSuiteDeleteWriter<>(this, adaptor, metaDataSource);
break;
default:
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.outputOperationNotImplemented", action));
}
Integer batchSize = properties.batchSize.getValue();
if (batchSize != null) {
writer.setBatchSize(batchSize);
}
Boolean dieOnError = properties.dieOnError.getValue();
if (dieOnError != null) {
writer.setExceptionForErrors(dieOnError);
}
return writer;
}
use of org.talend.components.netsuite.client.NetSuiteException in project components by Talend.
the class SearchDateFieldAdapter method convertDateTime.
protected XMLGregorianCalendar convertDateTime(String input) {
String valueToParse = input;
String dateTimeFormatPattern = dateFormatPattern + " " + timeFormatPattern;
if (input.length() == dateFormatPattern.length()) {
dateTimeFormatPattern = dateFormatPattern;
} else if (input.length() == timeFormatPattern.length()) {
DateTime dateTime = new DateTime();
DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(dateFormatPattern);
valueToParse = dateFormatter.print(dateTime) + " " + input;
}
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatPattern);
DateTime dateTime;
try {
dateTime = dateTimeFormatter.parseDateTime(valueToParse);
} catch (IllegalArgumentException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.searchDateField.invalidDateTimeFormat", valueToParse));
}
XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar();
xts.setYear(dateTime.getYear());
xts.setMonth(dateTime.getMonthOfYear());
xts.setDay(dateTime.getDayOfMonth());
xts.setHour(dateTime.getHourOfDay());
xts.setMinute(dateTime.getMinuteOfHour());
xts.setSecond(dateTime.getSecondOfMinute());
xts.setMillisecond(dateTime.getMillisOfSecond());
xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000);
return xts;
}
use of org.talend.components.netsuite.client.NetSuiteException 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();
}
}
Aggregations