Search in sources :

Example 6 with MarketoSourceOrSinkRuntime

use of org.talend.components.marketo.runtime.MarketoSourceOrSinkRuntime in project components by Talend.

the class MarketoCustomObjectsSchemasProperties method afterFormFinishCustomObjects.

public ValidationResult afterFormFinishCustomObjects(Repository<Properties> repo) throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(RUNTIME_SOURCEORSINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        MarketoSourceOrSinkRuntime sos = (MarketoSourceOrSinkRuntime) sandboxedInstance.getInstance();
        sos.initialize(null, this);
        try {
            String repoLoc = repo.storeProperties(connection, connection.name.getValue(), repositoryLocation, null);
            String storeId;
            for (NamedThing nl : selectedCustomObjectsNames.getValue()) {
                String customObjectId = nl.getName();
                storeId = nl.getName().replaceAll("-", "_").replaceAll(" ", "_");
                MarketoComponentWizardBaseProperties customObjectProps = new MarketoComponentWizardBaseProperties(customObjectId);
                customObjectProps.init();
                customObjectProps.connection = connection;
                customObjectProps.inputOperation.setValue(InputOperation.CustomObject);
                customObjectProps.outputOperation.setValue(OutputOperation.syncCustomObjects);
                customObjectProps.customObjectAction.setValue(CustomObjectAction.get);
                customObjectProps.customObjectSyncAction.setValue(CustomObjectSyncAction.createOrUpdate);
                customObjectProps.schemaInput.schema.setValue(sos.getEndpointSchema(null, customObjectId));
                customObjectProps.customObjectName.setValue(nl.getName());
                repo.storeProperties(customObjectProps, storeId, repoLoc, "schemaInput.schema");
            }
        } catch (Exception e) {
            ValidationResultMutable vr = new ValidationResultMutable();
            vr.setStatus(Result.ERROR);
            vr.setMessage(e.getMessage());
            return vr;
        }
    }
    return ValidationResult.OK;
}
Also used : MarketoComponentDefinition.getSandboxedInstance(org.talend.components.marketo.MarketoComponentDefinition.getSandboxedInstance) SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) MarketoSourceOrSinkRuntime(org.talend.components.marketo.runtime.MarketoSourceOrSinkRuntime) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) NamedThing(org.talend.daikon.NamedThing) IOException(java.io.IOException)

Aggregations

MarketoComponentDefinition.getSandboxedInstance (org.talend.components.marketo.MarketoComponentDefinition.getSandboxedInstance)6 MarketoSourceOrSinkRuntime (org.talend.components.marketo.runtime.MarketoSourceOrSinkRuntime)6 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)6 ValidationResult (org.talend.daikon.properties.ValidationResult)4 IOException (java.io.IOException)3 ValidationResultMutable (org.talend.daikon.properties.ValidationResultMutable)3 MarketoSourceOrSinkSchemaProvider (org.talend.components.marketo.runtime.MarketoSourceOrSinkSchemaProvider)2 NamedThing (org.talend.daikon.NamedThing)2 Schema (org.apache.avro.Schema)1 PropertyFactory.newString (org.talend.daikon.properties.property.PropertyFactory.newString)1