use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.
the class GenericTableUtils method getTableValues.
public static List<Map<String, Object>> getTableValues(Properties tableProperties, IElementParameter param) {
List<Map<String, Object>> table = new ArrayList<Map<String, Object>>();
if (param.getListItemsDisplayCodeName().length == 0) {
return table;
}
Property property = tableProperties.getValuedProperty(param.getListItemsDisplayCodeName()[0]);
Object value = property.getValue();
if (value instanceof List) {
for (int i = 0; i < ((List) value).size(); i++) {
Map<String, Object> line = new HashMap<String, Object>();
for (String columnName : param.getListItemsDisplayCodeName()) {
Property columnProperty = tableProperties.getValuedProperty(columnName);
EParameterFieldType type = getTypeFromColumnName(param, columnName);
Object columnValue = columnProperty.getValue();
if (columnValue instanceof List) {
List values = (List) columnValue;
if (type.equals(EParameterFieldType.CHECK)) {
if (values.size() > i) {
Object o = values.get(i);
if (o == null) {
line.put(columnName, Boolean.FALSE);
} else {
line.put(columnName, new Boolean(o.toString()));
}
} else {
line.put(columnName, Boolean.FALSE);
}
} else {
line.put(columnName, values.get(i));
}
} else {
if (type.equals(EParameterFieldType.CHECK)) {
for (int j = 0; j < ((List) value).size(); j++) {
line.put(columnName, Boolean.FALSE);
}
}
}
}
table.add(line);
}
}
return table;
}
use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.
the class WidgetFieldTypeMapper method getFieldType.
public static EParameterFieldType getFieldType(Widget widget, NamedThing widgetProperty) {
// init
mappingReader.init();
Property property = null;
if (widgetProperty instanceof Property) {
property = (Property) widgetProperty;
}
String fieldType = mappingReader.getFieldType(widget.getWidgetType(), widgetProperty, property != null ? property.getType() : null);
if (widgetProperty instanceof EnumProperty) {
return EParameterFieldType.CLOSED_LIST;
}
return fieldType != null ? EParameterFieldType.valueOf(fieldType.toUpperCase()) : null;
}
use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.
the class WidgetFieldTypeMappingReader method getFieldType.
public String getFieldType(String widgetType, NamedThing widgetProperty, String schemaType) {
init();
String fieldType = null;
if (Widget.DEFAULT_WIDGET_TYPE.equals(widgetType)) {
if (schemaType == null) {
return EParameterFieldType.LABEL.getName();
}
if (widgetProperty != null && widgetProperty instanceof Property) {
Property prop = (Property) widgetProperty;
if (prop.isFlag(Property.Flags.ENCRYPT)) {
return EParameterFieldType.HIDDEN_TEXT.getName();
}
}
//$NON-NLS-1$
fieldType = this.allDynamicWidgetFieldType.get(widgetType + "+" + schemaType);
if (fieldType != null) {
return fieldType;
} else {
return EParameterFieldType.TEXT.getName();
}
} else {
return this.allDynamicWidgetFieldType.get(widgetType);
}
}
use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.
the class NewComponentFrameworkMigrationTask method execute.
@Override
public ExecutionResult execute(final Item item) {
final ProcessType processType = getProcessType(item);
ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
Properties props = getPropertiesFromFile();
IComponentConversion conversion = new IComponentConversion() {
@Override
public void transform(NodeType nodeType) {
if (nodeType == null || props == null) {
return;
}
boolean modified = false;
Map<String, String> schemaParamMap = new HashMap<>();
String currComponentName = nodeType.getComponentName();
String newComponentName = props.getProperty(currComponentName);
nodeType.setComponentName(newComponentName);
IComponent component = ComponentsFactoryProvider.getInstance().get(newComponentName, category.getName());
ComponentProperties compProperties = ComponentsUtils.getComponentProperties(newComponentName);
FakeNode fNode = new FakeNode(component);
for (IElementParameter param : fNode.getElementParameters()) {
if (param instanceof GenericElementParameter) {
String paramName = param.getName();
NamedThing currNamedThing = ComponentsUtils.getGenericSchemaElement(compProperties, paramName);
String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
if (oldParamName != null && !(oldParamName = oldParamName.trim()).isEmpty()) {
if (currNamedThing instanceof Property && (GenericTypeUtils.isSchemaType((Property<?>) currNamedThing))) {
schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
}
ElementParameterType paramType = getParameterType(nodeType, oldParamName);
if (paramType != null) {
if (currNamedThing instanceof ComponentReferenceProperties) {
ComponentReferenceProperties refProps = (ComponentReferenceProperties) currNamedThing;
refProps.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
refProps.componentInstanceId.setStoredValue(ParameterUtilTool.convertParameterValue(paramType));
refProps.componentInstanceId.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
} else {
processMappedElementParameter(props, nodeType, (GenericElementParameter) param, paramType, currNamedThing);
}
ParameterUtilTool.removeParameterType(nodeType, paramType);
modified = true;
}
if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
//$NON-NLS-1$
String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
//$NON-NLS-1$
String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + schemaTypeName);
}
paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + repSchemaTypeName);
}
}
} else {
processUnmappedElementParameter(props, nodeType, (GenericElementParameter) param, currNamedThing);
}
} else {
if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
String paramName = param.getName();
schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
//$NON-NLS-1$
String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
//$NON-NLS-1$
String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
ElementParameterType paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + schemaTypeName);
}
paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
if (paramType != null) {
paramType.setName(param.getName() + repSchemaTypeName);
}
}
}
}
// Migrate schemas
Map<String, MetadataType> metadatasMap = new HashMap<>();
EList<MetadataType> metadatas = nodeType.getMetadata();
for (MetadataType metadataType : metadatas) {
metadatasMap.put(metadataType.getConnector(), metadataType);
}
Iterator<Entry<String, String>> schemaParamIter = schemaParamMap.entrySet().iterator();
//$NON-NLS-1$
String uniqueName = ParameterUtilTool.getParameterValue(nodeType, "UNIQUE_NAME");
while (schemaParamIter.hasNext()) {
Entry<String, String> schemaParamEntry = schemaParamIter.next();
String newParamName = schemaParamEntry.getKey();
String connectorMapping = schemaParamEntry.getValue();
//$NON-NLS-1$
String oldConnector = connectorMapping.split("->")[0];
//$NON-NLS-1$
String newConnector = connectorMapping.split("->")[1];
MetadataType metadataType = metadatasMap.get(oldConnector);
if (metadataType != null) {
metadataType.setConnector(newConnector);
MetadataEmfFactory factory = new MetadataEmfFactory();
factory.setMetadataType(metadataType);
IMetadataTable metadataTable = factory.getMetadataTable();
Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(ConvertionHelper.convert(metadataTable));
compProperties.setValue(newParamName, schema);
}
if (!oldConnector.equals(newConnector)) {
// if connector was changed, we should update the connections
for (Object connectionObj : processType.getConnection()) {
if (connectionObj instanceof ConnectionType) {
ConnectionType connectionType = (ConnectionType) connectionObj;
if (connectionType.getSource().equals(uniqueName) && connectionType.getConnectorName().equals(oldConnector)) {
connectionType.setConnectorName(newConnector);
}
}
}
}
}
for (Object connectionObj : processType.getConnection()) {
ConnectionType connection = (ConnectionType) connectionObj;
if (connection.getSource() != null && connection.getSource().equals(uniqueName)) {
if (EConnectionType.FLOW_MAIN.getName().equals(connection.getConnectorName())) {
connection.setConnectorName(Connector.MAIN_NAME);
}
}
}
if (modified) {
String serializedProperties = compProperties.toSerialized();
if (serializedProperties != null) {
ElementParameterType pType = //$NON-NLS-1$
ParameterUtilTool.createParameterType(//$NON-NLS-1$
null, //$NON-NLS-1$
"PROPERTIES", serializedProperties);
nodeType.getElementParameter().add(pType);
}
}
}
};
if (processType != null) {
boolean modified = false;
for (Object obj : processType.getNode()) {
if (obj != null && obj instanceof NodeType) {
String componentName = ((NodeType) obj).getComponentName();
String newComponentName = props.getProperty(componentName);
if (newComponentName == null) {
continue;
}
IComponentFilter filter = new NameComponentFilter(componentName);
modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(conversion)) || modified;
}
}
if (modified) {
try {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.daikon.properties.property.Property 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);
}
Aggregations