Search in sources :

Example 1 with MetaDataSource

use of org.talend.components.netsuite.client.MetaDataSource 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()));
}
Also used : EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) IOException(java.io.IOException) EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) MetaDataSource(org.talend.components.netsuite.client.MetaDataSource) EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) Test(org.junit.Test)

Example 2 with MetaDataSource

use of org.talend.components.netsuite.client.MetaDataSource in project components by Talend.

the class NetSuiteEndpoint method connect.

/**
 * Creates new NetSuite client and connects to NetSuite remote endpoint.
 *
 * @param connectionConfig connection configuration
 * @return client
 * @throws NetSuiteException if an error occurs during connecting
 */
private NetSuiteClientService<?> connect(ConnectionConfig connectionConfig) throws NetSuiteException {
    NetSuiteClientService<?> clientService = clientFactory.createClient();
    clientService.setEndpointUrl(connectionConfig.getEndpointUrl().toString());
    clientService.setCredentials(connectionConfig.getCredentials());
    clientService.setBodyFieldsOnly(connectionConfig.isBodyFieldsOnly());
    MetaDataSource metaDataSource = clientService.getMetaDataSource();
    metaDataSource.setCustomizationEnabled(connectionConfig.isCustomizationEnabled());
    clientService.login();
    return clientService;
}
Also used : MetaDataSource(org.talend.components.netsuite.client.MetaDataSource)

Example 3 with MetaDataSource

use of org.talend.components.netsuite.client.MetaDataSource 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 4 with MetaDataSource

use of org.talend.components.netsuite.client.MetaDataSource 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

MetaDataSource (org.talend.components.netsuite.client.MetaDataSource)4 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)3 IOException (java.io.IOException)2 Schema (org.apache.avro.Schema)2 SchemaCustomMetaDataSource (org.talend.components.netsuite.SchemaCustomMetaDataSource)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Test (org.junit.Test)1 NetSuiteErrorCode (org.talend.components.netsuite.NetSuiteErrorCode)1 CustomMetaDataSource (org.talend.components.netsuite.client.CustomMetaDataSource)1 EmptyCustomMetaDataSource (org.talend.components.netsuite.client.EmptyCustomMetaDataSource)1 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)1 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)1 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)1 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)1