Search in sources :

Example 16 with Properties

use of org.talend.daikon.properties.Properties in project tdi-studio-se by Talend.

the class Component method processCodegenPropInfos.

protected void processCodegenPropInfos(List<CodegenPropInfo> propList, Properties props, String fieldString) {
    for (NamedThing prop : props.getProperties()) {
        if (prop instanceof Properties) {
            if (prop instanceof ComponentReferenceProperties) {
                ComponentReferenceProperties crp = (ComponentReferenceProperties) prop;
                crp.componentInstanceId.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
                crp.referenceDefinitionName.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
            }
            CodegenPropInfo childPropInfo = new CodegenPropInfo();
            if (fieldString.equals("")) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                childPropInfo.fieldName = "." + prop.getName();
            } else {
                //$NON-NLS-1$
                childPropInfo.fieldName = fieldString + "." + prop.getName();
            }
            childPropInfo.className = prop.getClass().getName();
            childPropInfo.props = (Properties) prop;
            propList.add(childPropInfo);
            processCodegenPropInfos(propList, childPropInfo.props, childPropInfo.fieldName);
        }
    }
}
Also used : NamedThing(org.talend.daikon.NamedThing) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Properties(org.talend.daikon.properties.Properties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties)

Example 17 with Properties

use of org.talend.daikon.properties.Properties in project tdi-studio-se by Talend.

the class DynamicComposite method resetParameters.

public List<ElementParameter> resetParameters() {
    final List<ElementParameter> newParameters = new ArrayList<>();
    List<ElementParameter> currentParameters = (List<ElementParameter>) element.getElementParameters();
    List<ElementParameter> parameters = new ArrayList<>();
    ComponentService componentService = internalService.getComponentService();
    Connection theConnection = null;
    if (connectionItem != null) {
        theConnection = connectionItem.getConnection();
    }
    Properties properties = null;
    PropertyValueEvaluator evaluator = null;
    if (element instanceof FakeElement) {
        properties = form.getProperties();
        evaluator = new MetadataContextPropertyValueEvaluator(theConnection);
        currentParameters.clear();
    } else {
        properties = ((INode) element).getComponentProperties();
        evaluator = new ComponentContextPropertyValueEvaluator((INode) element);
    }
    if (properties instanceof ComponentProperties) {
        if (form != null) {
            properties.setValueEvaluator(evaluator);
            properties.refreshLayout(form);
        }
        // For context display.
        properties.setValueEvaluator(null);
        boolean isInitializing = false;
        if (element instanceof INode) {
            INode node = (INode) element;
            IComponent component = node.getComponent();
            if (component instanceof AbstractBasicComponent) {
                isInitializing = ((AbstractBasicComponent) component).isInitializing();
            }
        }
        parameters = ComponentsUtils.getParametersFromForm(element, isInitializing, section, (ComponentProperties) properties, form);
        addUpdateParameterIfNotExist(parameters);
        properties.setValueEvaluator(evaluator);
    }
    for (ElementParameter parameter : parameters) {
        if (parameter instanceof GenericElementParameter) {
            GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
            genericElementParameter.setComponentService(componentService);
            genericElementParameter.setDrivedByForm(drivedByForm);
            genericElementParameter.callBeforePresent();
            genericElementParameter.removePropertyChangeListener(this);
            genericElementParameter.addPropertyChangeListener(this);
            if (wizardPropertyChangeListener != null && IGenericConstants.NAME_PROPERTY.equals(parameter.getName())) {
                genericElementParameter.addPropertyChangeListener(wizardPropertyChangeListener);
            }
            if (EParameterFieldType.SCHEMA_REFERENCE.equals(genericElementParameter.getFieldType())) {
                if (genericElementParameter.getChildParameters().size() == 0) {
                    IElementParameter schemaParameter = element.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE, section);
                    genericElementParameter.getChildParameters().putAll(schemaParameter.getChildParameters());
                }
            } else if (EParameterFieldType.NAME_SELECTION_AREA.equals(genericElementParameter.getFieldType()) && theConnection != null) {
                List<NamedThing> values = new ArrayList<>();
                List<MetadataTable> metadataTables = SchemaUtils.getMetadataTables(theConnection, SubContainer.class);
                List<String> tableLabels = new ArrayList<>();
                for (MetadataTable metaTable : metadataTables) {
                    tableLabels.add(metaTable.getLabel());
                }
                List<NamedThing> possibleValues = ComponentsUtils.getFormalPossibleValues(genericElementParameter);
                for (NamedThing possibleValue : possibleValues) {
                    if (tableLabels.contains(possibleValue.getName())) {
                        values.add(possibleValue);
                    }
                }
                genericElementParameter.setValue(values);
            }
            if (properties != null && isRepository(element)) {
                String repositoryValue = genericElementParameter.getRepositoryValue();
                if (genericElementParameter.isShow(currentParameters) && (repositoryValue != null) && (!genericElementParameter.getName().equals(EParameterName.PROPERTY_TYPE.getName())) && genericElementParameter.getCategory() == section) {
                    org.talend.daikon.properties.property.Property property = properties.getValuedProperty(genericElementParameter.getName());
                    if (property != null && property.getTaggedValue(IGenericConstants.REPOSITORY_VALUE) != null) {
                        genericElementParameter.setRepositoryValueUsed(true);
                        genericElementParameter.setReadOnly(true);
                    }
                }
            }
        }
    }
    boolean added = false;
    for (ElementParameter currentParameter : currentParameters) {
        if (EParameterName.UPDATE_COMPONENTS.getName().equals(currentParameter.getName())) {
            currentParameter.setValue(true);
        }
        if (currentParameter.isSerialized() && currentParameter.getCategory().equals(section)) {
            if (!added) {
                newParameters.addAll(parameters);
                added = true;
            }
            continue;
        }
        newParameters.add(currentParameter);
    }
    if (element instanceof FakeElement) {
        newParameters.addAll(reverseParameters(parameters));
    }
    element.setElementParameters(newParameters);
    return newParameters;
}
Also used : INode(org.talend.core.model.process.INode) ComponentProperties(org.talend.components.api.properties.ComponentProperties) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) PropertyValueEvaluator(org.talend.daikon.properties.property.PropertyValueEvaluator) ComponentContextPropertyValueEvaluator(org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator) MetadataContextPropertyValueEvaluator(org.talend.metadata.managment.ui.wizard.context.MetadataContextPropertyValueEvaluator) IElementParameterEventProperties(org.talend.designer.core.generic.constants.IElementParameterEventProperties) IContextEventProperties(org.talend.designer.core.generic.constants.IContextEventProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Properties(org.talend.daikon.properties.Properties) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) ComponentService(org.talend.components.api.service.ComponentService) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataContextPropertyValueEvaluator(org.talend.metadata.managment.ui.wizard.context.MetadataContextPropertyValueEvaluator) NamedThing(org.talend.daikon.NamedThing) FakeElement(org.talend.designer.core.model.FakeElement) SubContainer(org.talend.repository.generic.model.genericMetadata.SubContainer) AbstractBasicComponent(org.talend.designer.core.model.components.AbstractBasicComponent) ComponentContextPropertyValueEvaluator(org.talend.designer.core.generic.context.ComponentContextPropertyValueEvaluator)

Example 18 with Properties

use of org.talend.daikon.properties.Properties in project tdi-studio-se by Talend.

the class ComponentTest method testGetCodegenPropInfosWithoutReferenceObject.

@Test
public void testGetCodegenPropInfosWithoutReferenceObject() {
    //$NON-NLS-1$
    ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
    List<CodegenPropInfo> propInfos = component.getCodegenPropInfos(props);
    for (CodegenPropInfo propInfo : propInfos) {
        Properties properties = propInfo.props;
        if (properties instanceof ComponentReferenceProperties) {
            ComponentReferenceProperties crp = (ComponentReferenceProperties) properties;
            assertEquals(Boolean.TRUE, crp.componentInstanceId.getTaggedValue(IGenericConstants.ADD_QUOTES));
            assertEquals(Boolean.TRUE, crp.referenceDefinitionName.getTaggedValue(IGenericConstants.ADD_QUOTES));
            //please see ComponentRefController class, the reference will be set when some ui action happen, so expect the value is null as no any ui action here
            assertNull(crp.getReference());
        }
    }
}
Also used : TestProperties(org.talend.designer.core.generic.utils.TestProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) CodegenPropInfo(org.talend.designer.core.generic.model.Component.CodegenPropInfo) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) TestProperties(org.talend.designer.core.generic.utils.TestProperties) Properties(org.talend.daikon.properties.Properties) TestReferencedProperties(org.talend.designer.core.generic.utils.TestReferencedProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Test(org.junit.Test)

Example 19 with Properties

use of org.talend.daikon.properties.Properties in project tdi-studio-se by Talend.

the class ComponentTest method testGetCodegenPropInfosWithReferencePropertiesObject.

@Test
public void testGetCodegenPropInfosWithReferencePropertiesObject() {
    //$NON-NLS-1$
    TestProperties props = (TestProperties) new TestProperties("test").init();
    props.referencePros.setReference(new TestReferencedProperties("reference").init());
    List<CodegenPropInfo> propInfos = component.getCodegenPropInfos(props);
    for (CodegenPropInfo propInfo : propInfos) {
        Properties properties = propInfo.props;
        if (properties instanceof ComponentReferenceProperties) {
            ComponentReferenceProperties crp = (ComponentReferenceProperties) properties;
            assertEquals(Boolean.TRUE, crp.componentInstanceId.getTaggedValue(IGenericConstants.ADD_QUOTES));
            assertEquals(Boolean.TRUE, crp.referenceDefinitionName.getTaggedValue(IGenericConstants.ADD_QUOTES));
            assertNotNull(crp.getReference());
        }
    }
}
Also used : TestProperties(org.talend.designer.core.generic.utils.TestProperties) CodegenPropInfo(org.talend.designer.core.generic.model.Component.CodegenPropInfo) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) TestProperties(org.talend.designer.core.generic.utils.TestProperties) Properties(org.talend.daikon.properties.Properties) TestReferencedProperties(org.talend.designer.core.generic.utils.TestReferencedProperties) TestReferencedProperties(org.talend.designer.core.generic.utils.TestReferencedProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Test(org.junit.Test)

Example 20 with Properties

use of org.talend.daikon.properties.Properties in project components by Talend.

the class PropertiesControllerImpl method triggerOnProperty.

@Override
public // 
ResponseEntity<String> triggerOnProperty(// 
PropertyTrigger trigger, // 
String property, // 
String formName, UiSpecsPropertiesDto propertiesContainer) {
    Properties properties = propertiesHelpers.propertiesFromDto(propertiesContainer);
    String response;
    try {
        Properties updatedProperties;
        switch(trigger) {
            case VALIDATE:
                updatedProperties = componentService.validateProperty(property, properties);
                break;
            case BEFORE_ACTIVE:
                updatedProperties = componentService.beforePropertyActivate(property, properties);
                break;
            case BEFORE_PRESENT:
                updatedProperties = componentService.beforePropertyPresent(property, properties);
                break;
            case AFTER:
                updatedProperties = componentService.afterProperty(property, properties);
                break;
            default:
                throw new IllegalArgumentException("This enum does not contain this value: " + trigger);
        }
        response = jsonSerializationHelper.toJson(updatedProperties, formName, propertiesContainer.getDefinitionName());
    } catch (IllegalStateException e) {
        log.info("Tried to execute an undefined trigger. It show either a bug in the calling client or the definition" + " properties advertised a non-existent trigger", e);
        throw new UndefinedTriggerException(propertiesContainer.getDefinitionName(), property, trigger);
    } catch (Throwable throwable) {
        Exception exception = handleErrors(throwable);
        log.warn("Error validating property.", exception);
        // Letting common handler return a 500 error and correct message structure
        throw new TalendRuntimeException(CommonErrorCodes.UNEXPECTED_EXCEPTION, exception);
    }
    return new ResponseEntity<>(response, OK);
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) ResponseEntity(org.springframework.http.ResponseEntity) DatasetProperties(org.talend.components.common.dataset.DatasetProperties) DatastoreProperties(org.talend.components.common.datastore.DatastoreProperties) Properties(org.talend.daikon.properties.Properties) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Aggregations

Properties (org.talend.daikon.properties.Properties)24 ComponentProperties (org.talend.components.api.properties.ComponentProperties)15 Test (org.junit.Test)7 NamedThing (org.talend.daikon.NamedThing)7 ComponentReferenceProperties (org.talend.components.api.properties.ComponentReferenceProperties)6 Property (org.talend.daikon.properties.property.Property)6 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)5 SchemaProperty (org.talend.daikon.properties.property.SchemaProperty)4 ArrayList (java.util.ArrayList)3 DatasetProperties (org.talend.components.common.dataset.DatasetProperties)3 DatastoreProperties (org.talend.components.common.datastore.DatastoreProperties)3 INode (org.talend.core.model.process.INode)3 List (java.util.List)2 Schema (org.apache.avro.Schema)2 AbstractComponentTest (org.talend.components.api.test.AbstractComponentTest)2 SalesforceConnectionModuleProperties (org.talend.components.salesforce.SalesforceConnectionModuleProperties)2 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)2 SalesforceModuleProperties (org.talend.components.salesforce.SalesforceModuleProperties)2 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)2 TSalesforceOutputProperties (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)2