Search in sources :

Example 21 with NetSuiteException

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);
    }
}
Also used : MetaDataSource(org.talend.components.netsuite.client.MetaDataSource) SchemaCustomMetaDataSource(org.talend.components.netsuite.SchemaCustomMetaDataSource) SchemaCustomMetaDataSource(org.talend.components.netsuite.SchemaCustomMetaDataSource) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) IOException(java.io.IOException)

Example 22 with NetSuiteException

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);
    }
}
Also used : NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) IOException(java.io.IOException)

Example 23 with NetSuiteException

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;
}
Also used : Schema(org.apache.avro.Schema) SchemaCustomMetaDataSource(org.talend.components.netsuite.SchemaCustomMetaDataSource) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) MetaDataSource(org.talend.components.netsuite.client.MetaDataSource) SchemaCustomMetaDataSource(org.talend.components.netsuite.SchemaCustomMetaDataSource)

Example 24 with NetSuiteException

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;
}
Also used : NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime)

Example 25 with NetSuiteException

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();
    }
}
Also used : ArrayList(java.util.ArrayList) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NsReadResponse(org.talend.components.netsuite.client.NsReadResponse) NsRef(org.talend.components.netsuite.client.NsRef) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) StopWatch(org.apache.commons.lang3.time.StopWatch) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) CustomizationRef(com.netsuite.webservices.v2016_2.platform.core.CustomizationRef) ArrayList(java.util.ArrayList) NetSuiteClientServiceImpl.toNsReadResponseList(org.talend.components.netsuite.v2016_2.client.NetSuiteClientServiceImpl.toNsReadResponseList) List(java.util.List) Record(com.netsuite.webservices.v2016_2.platform.core.Record) GetListRequest(com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)

Aggregations

NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)29 ArrayList (java.util.ArrayList)10 MalformedURLException (java.net.MalformedURLException)9 NetSuiteErrorCode (org.talend.components.netsuite.NetSuiteErrorCode)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 SocketException (java.net.SocketException)6 RemoteException (java.rmi.RemoteException)6 WebServiceException (javax.xml.ws.WebServiceException)6 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)6 Schema (org.apache.avro.Schema)6 ComponentException (org.talend.components.api.exception.ComponentException)6 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)5 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)5 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)5 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)5 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)5 IOException (java.io.IOException)4 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)4 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)4 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)4