use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class Component method initializeParametersForSchema.
/**
* Sometimes the property parameters of schema are base on other parameters,but they might be initialized after the
* schema. So there need to initialize the schema's again.
*
*/
private void initializeParametersForSchema(List<ElementParameter> listParam, final INode node) {
ComponentProperties rootProperty = node.getComponentProperties();
Map<String, SchemaProperty> listSchemaProperties = new HashMap<>();
findSchemaProperties(rootProperty, listParam, listSchemaProperties, null);
for (String paramName : listSchemaProperties.keySet()) {
boolean found = setupConnector(node, listParam, paramName, listSchemaProperties.get(paramName), true);
if (!found) {
// check in the input schema
// for now we only handle input schema named MAIN. But we will name them "FLOW" to keep
// compatibility.
setupConnector(node, listParam, paramName, listSchemaProperties.get(paramName), false);
}
}
ElementParameter autoSwitchParam = null;
for (ElementParameter param : listParam) {
// TUP-4161
if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
ElementParameter newParam = new ElementParameter(node);
newParam.setCategory(EComponentCategory.BASIC);
newParam.setName(EParameterName.SCHEMA_TYPE.getName());
newParam.setDisplayName(EParameterName.SCHEMA_TYPE.getDisplayName());
newParam.setListItemsDisplayName(new String[] { TEXT_BUILTIN, TEXT_REPOSITORY });
newParam.setListItemsDisplayCodeName(new String[] { BUILTIN, REPOSITORY });
newParam.setListItemsValue(new String[] { BUILTIN, REPOSITORY });
newParam.setValue(BUILTIN);
newParam.setNumRow(param.getNumRow());
newParam.setFieldType(EParameterFieldType.TECHNICAL);
newParam.setShow(false);
//$NON-NLS-1$ //$NON-NLS-2$
newParam.setShowIf(param.getName() + " =='" + REPOSITORY + "'");
newParam.setReadOnly(param.isReadOnly());
newParam.setNotShowIf(param.getNotShowIf());
newParam.setContext(IGenericConstants.CONTEXT);
newParam.setSerialized(true);
newParam.setParentParameter(param);
newParam = new ElementParameter(node);
newParam.setCategory(EComponentCategory.BASIC);
newParam.setName(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
newParam.setDisplayName(EParameterName.REPOSITORY_SCHEMA_TYPE.getDisplayName());
newParam.setListItemsDisplayName(new String[] {});
newParam.setListItemsValue(new String[] {});
newParam.setNumRow(param.getNumRow());
newParam.setFieldType(EParameterFieldType.TECHNICAL);
//$NON-NLS-1$
newParam.setValue("");
newParam.setShow(false);
newParam.setRequired(true);
newParam.setReadOnly(param.isReadOnly());
//$NON-NLS-1$//$NON-NLS-2$
newParam.setShowIf(param.getName() + " =='" + REPOSITORY + "'");
newParam.setNotShowIf(param.getNotShowIf());
newParam.setContext(IGenericConstants.CONTEXT);
newParam.setSerialized(true);
newParam.setParentParameter(param);
if (autoSwitchParam == null) {
autoSwitchParam = new ElementParameter(node);
autoSwitchParam.setCategory(EComponentCategory.TECHNICAL);
autoSwitchParam.setName(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
autoSwitchParam.setDisplayName(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getDisplayName());
autoSwitchParam.setNumRow(param.getNumRow());
autoSwitchParam.setFieldType(EParameterFieldType.CHECK);
autoSwitchParam.setValue(Boolean.FALSE);
autoSwitchParam.setShow(false);
autoSwitchParam.setRequired(true);
autoSwitchParam.setReadOnly(true);
}
}
}
if (autoSwitchParam != null) {
listParam.add(autoSwitchParam);
}
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class Component method setupConnector.
/**
* DOC nrousseau Comment method "setupConnector".
*
* @param node
* @param rootProperty
* @param paramName
* @param schemaProperty
* @param found
* @return
*/
private boolean setupConnector(final INode node, List<ElementParameter> listParam, String paramName, SchemaProperty schemaProperty, boolean isOutput) {
ComponentProperties rootProperty = node.getComponentProperties();
boolean found = false;
for (Connector connector : rootProperty.getPossibleConnectors(isOutput)) {
if (!(schemaProperty.getValue() instanceof Schema)) {
continue;
}
Schema schema = schemaProperty.getValue();
if (connector instanceof PropertyPathConnector) {
//$NON-NLS-1$
String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
if (paramName.equals(linkedSchema)) {
found = true;
ElementParameter param = new ElementParameter(node);
param.setName(paramName);
param.setFieldType(EParameterFieldType.SCHEMA_REFERENCE);
param.setShow(false);
if (!isOutput) {
param.setContext(EConnectionType.FLOW_MAIN.getName());
} else {
param.setContext(connector.getName());
}
param.setCategory(EComponentCategory.TECHNICAL);
IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
param.getDefaultValues().add(defaultValue);
listParam.add(param);
}
}
}
return found;
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class NewNetsuiteMigrationTask method processSearchConditionsTable.
private void processSearchConditionsTable(GenericElementParameter param, ElementParameterType paramType, NamedThing target) {
ComponentProperties searchQueryProps = (ComponentProperties) target;
List<ElementValueType> columns = paramType.getElementValue();
if (!(columns != null && columns.size() > 0)) {
return;
}
Map<String, String> columnMapping = new HashMap<String, String>();
columnMapping.put("INPUT_COLUMN", "field");
columnMapping.put("OPERATOR", "operator");
columnMapping.put("RVALUE", "value1");
columnMapping.put("RVALUE2", "value2");
List<String> fieldPropPossibleValues = new ArrayList<String>();
List<Map<String, Object>> tableEntries = new ArrayList<Map<String, Object>>();
Map<String, Object> tableEntry = null;
for (ElementValueType column : columns) {
String sourceName = column.getElementRef();
if ("INPUT_COLUMN".equals(sourceName)) {
if (tableEntry != null) {
tableEntries.add(tableEntry);
}
tableEntry = new HashMap<String, Object>();
}
String targetName = columnMapping.get(sourceName);
Object targetValue = column.getValue();
if ("field".equals(targetName)) {
String mappedFieldName = toInitialLower(targetValue.toString());
targetValue = mappedFieldName;
fieldPropPossibleValues.add(mappedFieldName);
} else if ("operator".equals(targetName)) {
String mappedOperatorName = searchOperatorMapping.get(targetValue.toString());
if (mappedOperatorName != null) {
targetValue = mappedOperatorName;
}
}
tableEntry.put(targetName, targetValue);
}
tableEntries.add(tableEntry);
GenericTableUtils.setTableValues(searchQueryProps, tableEntries, param);
Property<String> fieldProp = (Property<String>) searchQueryProps.getProperty("field");
fieldProp.setPossibleValues(Arrays.asList("type"));
Property<String> operatorProp = (Property<String>) searchQueryProps.getProperty("operator");
List<String> operatorPropPossibleValues = new ArrayList<String>(searchOperatorMapping.values());
Collections.sort(operatorPropPossibleValues);
operatorProp.setPossibleValues(operatorPropPossibleValues);
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class Component method getRepositoryType.
@Override
public String getRepositoryType(Connection connection) {
String propertiesStr = null;
IGenericWizardService wizardService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
}
if (wizardService != null) {
propertiesStr = wizardService.getConnectionProperties(connection);
}
ComponentProperties properties = ComponentsUtils.getComponentPropertiesFromSerialized(propertiesStr, connection, false);
if (properties != null) {
ComponentWizardDefinition wizardDefinition = getWizardDefinition(properties);
if (wizardDefinition != null) {
return wizardDefinition.getName();
}
}
return null;
}
use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.
the class Component method getWizardDefinition.
private ComponentWizardDefinition getWizardDefinition(ComponentProperties componentProperties) {
ComponentWizardDefinition definition = null;
if (componentProperties == null) {
return null;
}
ComponentService service = ComponentsUtils.getComponentService();
List<ComponentWizard> componentWizards = service.getComponentWizardsForProperties(componentProperties, null);
for (ComponentWizard componentWizard : componentWizards) {
definition = componentWizard.getDefinition();
// Can we ensure it is the same wizard with metadata connection wizard by this way?
if (definition.isTopLevel()) {
return definition;
}
}
List<NamedThing> namedThings = componentProperties.getProperties();
for (NamedThing namedThing : namedThings) {
if (namedThing instanceof ComponentProperties) {
definition = getWizardDefinition((ComponentProperties) namedThing);
if (definition != null && definition.isTopLevel()) {
return definition;
}
}
}
return null;
}
Aggregations