Search in sources :

Example 1 with LeadSelector

use of org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector 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 2 with LeadSelector

use of org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector 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)

Aggregations

TMarketoInputProperties (org.talend.components.marketo.tmarketoinput.TMarketoInputProperties)2 LeadSelector (org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector)2 ValidationResultMutable (org.talend.daikon.properties.ValidationResultMutable)2 Path (java.nio.file.Path)1 TMarketoBulkExecProperties (org.talend.components.marketo.tmarketobulkexec.TMarketoBulkExecProperties)1 TMarketoListOperationProperties (org.talend.components.marketo.tmarketolistoperation.TMarketoListOperationProperties)1 TMarketoOutputProperties (org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties)1