Search in sources :

Example 1 with SchemaCustomMetaDataSource

use of org.talend.components.netsuite.SchemaCustomMetaDataSource in project components by Talend.

the class NsObjectInputTransducer method prepare.

/**
 * Prepare processing of data object.
 */
private void prepare() {
    if (runtimeSchema != null) {
        return;
    }
    if (AvroUtils.isIncludeAllFields(schema)) {
        // It's dynamic schema, we should use dynamic schema as runtime schema.
        typeDesc = metaDataSource.getTypeInfo(typeName);
        runtimeSchema = getDynamicSchema(typeDesc, schema, typeDesc.getTypeName());
        // Replace custom meta data source with SchemaCustomMetaDataSource
        // which will be using new runtime schema
        SchemaCustomMetaDataSource schemaCustomMetaDataSource = new SchemaCustomMetaDataSource(clientService.getBasicMetaData(), clientService.getMetaDataSource().getCustomMetaDataSource(), runtimeSchema);
        metaDataSource.setCustomMetaDataSource(schemaCustomMetaDataSource);
    } else {
        typeDesc = metaDataSource.getTypeInfo(typeName);
        // Use design schema as runtime schema
        runtimeSchema = schema;
    }
}
Also used : SchemaCustomMetaDataSource(org.talend.components.netsuite.SchemaCustomMetaDataSource)

Example 2 with SchemaCustomMetaDataSource

use of org.talend.components.netsuite.SchemaCustomMetaDataSource 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 3 with SchemaCustomMetaDataSource

use of org.talend.components.netsuite.SchemaCustomMetaDataSource 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)

Aggregations

SchemaCustomMetaDataSource (org.talend.components.netsuite.SchemaCustomMetaDataSource)3 MetaDataSource (org.talend.components.netsuite.client.MetaDataSource)2 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)2 IOException (java.io.IOException)1 Schema (org.apache.avro.Schema)1 NetSuiteErrorCode (org.talend.components.netsuite.NetSuiteErrorCode)1 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)1