Search in sources :

Example 31 with TMarketoInputProperties

use of org.talend.components.marketo.tmarketoinput.TMarketoInputProperties in project components by Talend.

the class MarketoSink method validate.

@Override
public ValidationResult validate(RuntimeContainer container) {
    ValidationResultMutable vr = new ValidationResultMutable(super.validate(container));
    if (vr.getStatus().equals(Result.ERROR)) {
        return vr;
    }
    // output
    if (properties instanceof TMarketoOutputProperties) {
        switch(((TMarketoOutputProperties) properties).outputOperation.getValue()) {
            case syncLead:
                break;
            case syncMultipleLeads:
                break;
            case deleteLeads:
                break;
            case syncCustomObjects:
                if (StringUtils.isEmpty(((TMarketoOutputProperties) properties).customObjectName.getValue())) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.customobject.customobjectname"));
                    return vr;
                }
                if (StringUtils.isEmpty(((TMarketoOutputProperties) properties).customObjectDedupeBy.getValue())) {
                // TODO check API if required. Not sure...
                }
                break;
            case deleteCustomObjects:
                if (StringUtils.isEmpty(((TMarketoOutputProperties) properties).customObjectName.getValue())) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.customobject.customobjectname"));
                    return vr;
                }
                break;
        }
    }
    // check list operations
    if (properties instanceof TMarketoListOperationProperties) {
    // nothing to check for now.
    }
    // check getMultipleLeads with an input
    if (properties instanceof TMarketoInputProperties) {
        // operation must be getMultipleLeads
        if (!((TMarketoInputProperties) properties).inputOperation.getValue().equals(InputOperation.getMultipleLeads)) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.sink.getmultipleleads.only"));
            return vr;
        }
        // lead selector must be LeadKeySelector
        LeadSelector selector;
        if (APIMode.SOAP.equals(properties.getConnectionProperties().apiMode.getValue())) {
            selector = ((TMarketoInputProperties) properties).leadSelectorSOAP.getValue();
        } else {
            selector = ((TMarketoInputProperties) properties).leadSelectorREST.getValue();
        }
        if (!selector.equals(LeadSelector.LeadKeySelector)) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.sink.leadkeyselector.only"));
            return vr;
        }
        // lead key values must be defined
        if (StringUtils.isEmpty(((TMarketoInputProperties) properties).leadKeyValues.getValue())) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.leadkeyvalues"));
            return vr;
        }
    }
    return ValidationResult.OK;
}
Also used : TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) TMarketoListOperationProperties(org.talend.components.marketo.tmarketolistoperation.TMarketoListOperationProperties) TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) LeadSelector(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector)

Example 32 with TMarketoInputProperties

use of org.talend.components.marketo.tmarketoinput.TMarketoInputProperties in project components by Talend.

the class MarketoSource method validate.

@Override
public ValidationResult validate(RuntimeContainer container) {
    ValidationResultMutable vr = new ValidationResultMutable(super.validate(container));
    if (vr.getStatus().equals(Result.ERROR)) {
        return vr;
    }
    if (properties instanceof TMarketoInputProperties) {
        TMarketoInputProperties p = (TMarketoInputProperties) properties;
        boolean useSOAP = APIMode.SOAP.equals(properties.getConnectionProperties().apiMode.getValue());
        // Validate dynamic schema if needed
        Boolean isDynamic = AvroUtils.isIncludeAllFields(p.schemaInput.schema.getValue());
        if (useSOAP) {
            // no dynamic schema for SOAP !
            if (isDynamic) {
                vr.setStatus(Result.ERROR);
                vr.setMessage(messages.getMessage("error.validation.soap.dynamicschema"));
                return vr;
            }
        }
        // getLead
        if (p.inputOperation.getValue().equals(InputOperation.getLead)) {
            if (p.leadKeyValue.getValue().isEmpty()) {
                vr.setStatus(Result.ERROR);
                vr.setMessage(messages.getMessage("error.validation.leadkeyvalue"));
                return vr;
            }
        }
        // getMultipleLeads
        if (p.inputOperation.getValue().equals(InputOperation.getMultipleLeads)) {
            LeadSelector sel;
            if (useSOAP) {
                sel = p.leadSelectorSOAP.getValue();
            } else {
                sel = p.leadSelectorREST.getValue();
            }
            switch(sel) {
                case LeadKeySelector:
                    if (p.leadKeyValues.getValue().isEmpty()) {
                        vr.setStatus(Result.ERROR);
                        vr.setMessage(messages.getMessage("error.validation.leadkeyvalues"));
                        return vr;
                    }
                    break;
                case StaticListSelector:
                    if (ListParam.STATIC_LIST_NAME.equals(p.listParam.getValue())) {
                        if (p.listParamListName.getValue().isEmpty()) {
                            vr.setStatus(Result.ERROR);
                            vr.setMessage(messages.getMessage("error.validation.listparamvalue"));
                            return vr;
                        }
                    } else {
                        if (p.listParamListId.getValue() == null) {
                            vr.setStatus(Result.ERROR);
                            vr.setMessage(messages.getMessage("error.validation.listparamvalue"));
                            return vr;
                        }
                    }
                    break;
                case LastUpdateAtSelector:
                    if (p.oldestUpdateDate.getValue().isEmpty() || p.latestUpdateDate.getValue().isEmpty() || isInvalidDate(p.oldestUpdateDate.getValue()) || isInvalidDate(p.latestUpdateDate.getValue())) {
                        vr.setStatus(Result.ERROR);
                        vr.setMessage(messages.getMessage("error.validation.updatedates"));
                        return vr;
                    }
                    break;
            }
        }
        // getLeadActivity
        if (p.inputOperation.getValue().equals(InputOperation.getLeadActivity)) {
            if (isDynamic) {
                vr.setStatus(Result.ERROR);
                vr.setMessage(messages.getMessage("error.validation.operation.dynamicschema"));
                return vr;
            }
            if (useSOAP) {
                if (p.leadKeyValue.getValue().isEmpty()) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.leadkeyvalue"));
                    return vr;
                }
            } else {
                if (p.sinceDateTime.getValue().isEmpty() || isInvalidDate(p.sinceDateTime.getValue())) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.sincedatetime"));
                    return vr;
                }
            }
        }
        // getLeadChanges
        if (p.inputOperation.getValue().equals(InputOperation.getLeadChanges)) {
            if (isDynamic) {
                vr.setStatus(Result.ERROR);
                vr.setMessage(messages.getMessage("error.validation.operation.dynamicschema"));
                return vr;
            }
            if (useSOAP) {
                if (p.oldestCreateDate.getValue().isEmpty() || p.latestCreateDate.getValue().isEmpty() || isInvalidDate(p.oldestCreateDate.getValue()) || isInvalidDate(p.latestCreateDate.getValue())) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.createdates"));
                    return vr;
                }
            } else {
                if (p.sinceDateTime.getValue().isEmpty() || isInvalidDate(p.sinceDateTime.getValue())) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.sincedatetime"));
                    return vr;
                }
                if (StringUtils.isEmpty(p.fieldList.getValue())) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.fieldlist"));
                    return vr;
                }
            }
        }
        // ///////////////////
        if (p.inputOperation.getValue().equals(InputOperation.CustomObject)) {
            // get Action
            if (p.customObjectAction.getValue().equals(CustomObjectAction.get)) {
                if (p.customObjectName.getValue().isEmpty()) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.customobject.customobjectname"));
                    return vr;
                }
                if (p.useCompoundKey.getValue()) {
                    if (p.compoundKey.size() == 0) {
                        vr.setStatus(Result.ERROR);
                        vr.setMessage(messages.getMessage("error.validation.customobject.compoundkey"));
                        return vr;
                    }
                } else {
                    // filterType & filterValue
                    if (p.customObjectFilterType.getValue().isEmpty()) {
                        vr.setStatus(Result.ERROR);
                        vr.setMessage(messages.getMessage("error.validation.customobject.filtertype"));
                        return vr;
                    }
                    if (p.customObjectFilterValues.getValue().isEmpty()) {
                        vr.setStatus(Result.ERROR);
                        vr.setMessage(messages.getMessage("error.validation.customobject.filtervalues"));
                        return vr;
                    }
                }
            }
            // list no checking...
            if (p.customObjectAction.getValue().equals(CustomObjectAction.list)) {
                if (isDynamic) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.operation.dynamicschema"));
                    return vr;
                }
            }
            // describe
            if (p.customObjectAction.getValue().equals(CustomObjectAction.describe)) {
                if (isDynamic) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.operation.dynamicschema"));
                    return vr;
                }
                if (p.customObjectName.getValue().isEmpty()) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.customobject.customobjectname"));
                    return vr;
                }
            }
        }
    }
    // BulkExec
    if (properties instanceof TMarketoBulkExecProperties) {
        TMarketoBulkExecProperties p = (TMarketoBulkExecProperties) properties;
        if (StringUtils.isEmpty(p.bulkFilePath.getValue())) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.sink.bulk.bulkfilepath"));
            return vr;
        }
        Path tmpPath = Paths.get(p.bulkFilePath.getValue());
        if (!Files.exists(tmpPath)) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.sink.bulk.bulkfilepath.notexists"));
            return vr;
        }
        if (StringUtils.isEmpty(p.logDownloadPath.getValue())) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.sink.bulk.logdownloadpath"));
            return vr;
        }
        tmpPath = Paths.get(p.logDownloadPath.getValue());
        if (!Files.isDirectory(tmpPath)) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.sink.bulk.logdownloadpath"));
            return vr;
        }
        if (p.bulkImportTo.getValue().equals(BulkImportTo.Leads)) {
            if (StringUtils.isEmpty(p.lookupField.getValue().name())) {
                vr.setStatus(Result.ERROR);
                vr.setMessage(messages.getMessage("error.validation.bulk.lookupfield"));
                return vr;
            }
        } else {
            if (StringUtils.isEmpty(p.customObjectName.getValue())) {
                vr.setStatus(Result.ERROR);
                vr.setMessage(messages.getMessage("error.validation.customobject.customobjectname"));
                return vr;
            }
        }
    }
    return vr;
}
Also used : Path(java.nio.file.Path) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) TMarketoBulkExecProperties(org.talend.components.marketo.tmarketobulkexec.TMarketoBulkExecProperties) LeadSelector(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector)

Example 33 with TMarketoInputProperties

use of org.talend.components.marketo.tmarketoinput.TMarketoInputProperties in project components by Talend.

the class MarketoInputWriterTestIT method setUp.

@Before
public void setUp() throws Exception {
    propsSOAP = new TMarketoInputProperties("test");
    propsSOAP.connection.setupProperties();
    propsSOAP.connection.endpoint.setValue(ENDPOINT_SOAP);
    propsSOAP.connection.clientAccessId.setValue(USERID_SOAP);
    propsSOAP.connection.secretKey.setValue(SECRETKEY_SOAP);
    propsSOAP.connection.apiMode.setValue(SOAP);
    propsSOAP.connection.setupLayout();
    propsSOAP.mappingInput.setupProperties();
    propsSOAP.setupProperties();
    propsSOAP.schemaInput.setupProperties();
    propsSOAP.schemaInput.setupLayout();
    propsSOAP.includeTypes.setupProperties();
    propsSOAP.includeTypes.type.setValue(new ArrayList<String>());
    propsSOAP.excludeTypes.setupProperties();
    propsSOAP.excludeTypes.type.setValue(new ArrayList<String>());
    propsSOAP.setupLayout();
    propsSOAP.inputOperation.setValue(getMultipleLeads);
    propsSOAP.leadSelectorSOAP.setValue(LeadSelector.LeadKeySelector);
    propsSOAP.leadKeyTypeSOAP.setValue(EMAIL);
    propsSOAP.afterInputOperation();
    propsSOAP.batchSize.setValue(1);
    propsSOAP.leadKeyValues.setValue("email");
    // REST
    propsREST = new TMarketoInputProperties("test");
    propsREST.connection.setupProperties();
    propsREST.connection.endpoint.setValue(ENDPOINT_REST);
    propsREST.connection.clientAccessId.setValue(USERID_REST);
    propsREST.connection.secretKey.setValue(SECRETKEY_REST);
    propsREST.connection.apiMode.setValue(REST);
    propsREST.connection.setupLayout();
    propsREST.mappingInput.setupProperties();
    propsREST.setupProperties();
    propsREST.schemaInput.setupProperties();
    propsREST.schemaInput.setupLayout();
    propsREST.includeTypes.setupProperties();
    propsREST.includeTypes.type.setValue(new ArrayList<String>());
    propsREST.excludeTypes.setupProperties();
    propsREST.excludeTypes.type.setValue(new ArrayList<String>());
    propsREST.setupLayout();
    propsREST.inputOperation.setValue(getMultipleLeads);
    propsREST.leadSelectorREST.setValue(LeadSelector.LeadKeySelector);
    propsREST.leadKeyTypeREST.setValue(LeadKeyTypeREST.email);
    propsREST.afterInputOperation();
    propsREST.batchSize.setValue(1);
    propsREST.leadKeyValues.setValue("email");
    // 
    sink = new MarketoSink();
}
Also used : TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) Before(org.junit.Before)

Example 34 with TMarketoInputProperties

use of org.talend.components.marketo.tmarketoinput.TMarketoInputProperties in project components by Talend.

the class MarketoInputReaderTestIT method testCustomObjectDynamicSchema.

@Test
public void testCustomObjectDynamicSchema() throws Exception {
    TMarketoInputProperties props = getRESTProperties();
    String coName = "smartphone_c";
    String brand = "Apple";
    String models = "iPhone 7";
    props.inputOperation.setValue(CustomObject);
    props.customObjectAction.setValue(CustomObjectAction.get);
    props.batchSize.setValue(1);
    props.afterCustomObjectAction();
    props.customObjectName.setValue(coName);
    props.customObjectFilterType.setValue("model");
    props.customObjectFilterValues.setValue(models);
    Schema design = SchemaBuilder.builder().record("test").prop(SchemaConstants.INCLUDE_ALL_FIELDS, "true").fields().endRecord();
    design.addProp(SchemaConstants.INCLUDE_ALL_FIELDS, "true");
    props.schemaInput.schema.setValue(design);
    reader = getReader(props);
    assertTrue(reader.start());
    IndexedRecord r = reader.getCurrent();
    assertNotNull(r);
    assertTrue(r.getSchema().getFields().size() > 6);
    assertFalse(reader.advance());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) Test(org.junit.Test)

Example 35 with TMarketoInputProperties

use of org.talend.components.marketo.tmarketoinput.TMarketoInputProperties in project components by Talend.

the class MarketoSourceOrSinkTestIT method testGetSchemaNames.

@Test
public void testGetSchemaNames() throws Exception {
    TMarketoInputProperties props = new TMarketoInputProperties("test");
    props.connection.setupProperties();
    props.setupProperties();
    props.connection.endpoint.setValue(MarketoBaseTestIT.ENDPOINT_REST);
    props.connection.clientAccessId.setValue(MarketoBaseTestIT.USERID_REST);
    props.connection.secretKey.setValue(MarketoBaseTestIT.SECRETKEY_REST);
    MarketoSourceOrSink sos = new MarketoSourceOrSink();
    sos.initialize(null, props);
    List<NamedThing> cos = sos.getSchemaNames(null);
    assertFalse(cos.isEmpty());
}
Also used : TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) NamedThing(org.talend.daikon.NamedThing) Test(org.junit.Test)

Aggregations

TMarketoInputProperties (org.talend.components.marketo.tmarketoinput.TMarketoInputProperties)45 Test (org.junit.Test)25 Before (org.junit.Before)11 IndexedRecord (org.apache.avro.generic.IndexedRecord)10 TMarketoOutputProperties (org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties)9 TMarketoListOperationProperties (org.talend.components.marketo.tmarketolistoperation.TMarketoListOperationProperties)6 Date (java.util.Date)5 Schema (org.apache.avro.Schema)5 SimpleDateFormat (java.text.SimpleDateFormat)4 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)4 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)2 MarketoRESTClient (org.talend.components.marketo.runtime.client.MarketoRESTClient)2 TMarketoBulkExecProperties (org.talend.components.marketo.tmarketobulkexec.TMarketoBulkExecProperties)2 LeadSelector (org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector)2 NamedThing (org.talend.daikon.NamedThing)2 ValidationResult (org.talend.daikon.properties.ValidationResult)2 ValidationResultMutable (org.talend.daikon.properties.ValidationResultMutable)2 Gson (com.google.gson.Gson)1 AuthenticationHeader (com.marketo.mktows.AuthenticationHeader)1 MktowsPort (com.marketo.mktows.MktowsPort)1