use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class ChangeValuesFromRepositoryTest method testChangeValuesMultipleProperty.
@Test
public void testChangeValuesMultipleProperty() {
Property property = PropertiesFactory.eINSTANCE.createProperty();
IProcess2 process = new Process(property);
IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
Node node = new Node(sourceCom, process);
node.setLabel("tMysqlInput_1");
IMetadataTable table = createSimpleMetadata();
table.setAttachedConnector("FLOW");
List<IMetadataTable> metadataList = new ArrayList<IMetadataTable>();
metadataList.add(table);
node.setMetadataList(metadataList);
ElementParameter parentParam = new ElementParameter(node);
parentParam.setCategory(EComponentCategory.BASIC);
parentParam.setName("PROPERTY2");
parentParam.setFieldType(EParameterFieldType.PROPERTY_TYPE);
ElementParameter newParam = new ElementParameter(node);
newParam.setCategory(EComponentCategory.BASIC);
newParam.setName(EParameterName.PROPERTY_TYPE.getName());
newParam.setDisplayName(EParameterName.PROPERTY_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(1);
newParam.setFieldType(EParameterFieldType.TECHNICAL);
newParam.setRepositoryValue("TEST");
newParam.setShow(true);
newParam.setParentParameter(parentParam);
// listParam.add(newParam);
newParam = new ElementParameter(node);
newParam.setCategory(EComponentCategory.BASIC);
newParam.setName(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
newParam.setDisplayName(EParameterName.REPOSITORY_PROPERTY_TYPE.getDisplayName());
newParam.setListItemsDisplayName(new String[] {});
newParam.setListItemsValue(new String[] {});
newParam.setNumRow(1);
newParam.setFieldType(EParameterFieldType.TECHNICAL);
//$NON-NLS-1$
newParam.setValue("");
newParam.setShow(false);
newParam.setRequired(true);
newParam.setParentParameter(parentParam);
((List<IElementParameter>) node.getElementParameters()).add(parentParam);
IElementParameter param = node.getElementParameter("USER");
param.setRepositoryProperty("PROPERTY");
param = node.getElementParameter("PASS");
param.setRepositoryProperty("PROPERTY");
param = node.getElementParameter("HOST");
param.setRepositoryProperty("PROPERTY");
param = node.getElementParameter("PORT");
param.setRepositoryProperty("PROPERTY2");
param = node.getElementParameter("DBNAME");
param.setRepositoryProperty("PROPERTY2");
ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(node, connection, "PROPERTY:REPOSITORY_PROPERTY_TYPE", databaseConnItem.getProperty().getId());
changeValuesFromRepository.execute();
DatabaseConnection dbConn = (DatabaseConnection) connection;
assertEquals(databaseConnItem.getProperty().getId(), node.getPropertyValue("PROPERTY:REPOSITORY_PROPERTY_TYPE"));
assertEquals(TalendTextUtils.addQuotes(dbConn.getUsername()), node.getPropertyValue("USER"));
assertEquals(TalendTextUtils.addQuotes(dbConn.getRawPassword()), node.getPropertyValue("PASS"));
assertEquals(TalendTextUtils.addQuotes(dbConn.getServerName()), node.getPropertyValue("HOST"));
assertNotSame(TalendTextUtils.addQuotes(dbConn.getPort()), node.getPropertyValue("PORT"));
assertNotSame(TalendTextUtils.addQuotes(dbConn.getDatasourceName()), node.getPropertyValue("DBNAME"));
dbConn.setUsername("user2");
dbConn.setPort("5002");
dbConn.setDatasourceName("Test2");
changeValuesFromRepository = new ChangeValuesFromRepository(node, connection, "PROPERTY2:REPOSITORY_PROPERTY_TYPE", databaseConnItem.getProperty().getId());
changeValuesFromRepository.execute();
assertNotSame(TalendTextUtils.addQuotes(dbConn.getUsername()), node.getPropertyValue("USER"));
assertEquals(TalendTextUtils.addQuotes(dbConn.getPort()), node.getPropertyValue("PORT"));
assertEquals(TalendTextUtils.addQuotes(dbConn.getDatasourceName()), node.getPropertyValue("DBNAME"));
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class QueryGuessCommandTest method generateNewTeradataQuery2.
@Test
public void generateNewTeradataQuery2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, PersistenceException {
ProxyRepositoryFactory repFactory = ProxyRepositoryFactory.getInstance();
String propertyId = repFactory.getNextId();
try {
DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
connection.setSID("myschema");
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
connectionProperty.setStatusCode("");
connectionProperty.setId(propertyId);
connectionProperty.setLabel("test_connection");
ConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
connectionItem.setProperty(connectionProperty);
connectionItem.setConnection(connection);
repFactory.create(connectionItem, new Path(""));
node = Mockito.mock(INode.class);
connection.setContextMode(true);
TdTable table = RelationalFactory.eINSTANCE.createTdTable();
table.setName("tableName");
table.setLabel("tableLabel");
TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
column1.setName("id");
TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
column2.setName("name");
table.getColumns().add(column1);
table.getColumns().add(column2);
metadataTable = ConvertionHelper.convert(table);
ElementParameter parameter = new ElementParameter(node);
parameter.setName("DBTABLE");
parameter.setValue(table.getName());
Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
ElementParameter connectionId = new ElementParameter(node);
connectionId.setValue(connectionProperty.getId());
Mockito.when(node.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())).thenReturn(connectionId);
// test case 1
String schema = "";
String dbType = EDatabaseTypeName.TERADATA.getDisplayName();
String expectedQuery = "\"SELECT myschema.tableName.\\\"id\\\", myschema.tableName.name FROM myschema.tableName\"";
QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
Method method = command.getClass().getDeclaredMethod("generateNewQuery");
method.setAccessible(true);
String queryString = (String) method.invoke(command);
Assert.assertEquals(expectedQuery, queryString);
} catch (Exception e) {
throw e;
} finally {
IRepositoryViewObject lastVersion = repFactory.getLastVersion(propertyId);
if (lastVersion != null) {
repFactory.deleteObjectPhysical(lastVersion);
}
}
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class ParallelExecutionUtils method setHashKeysForCon.
public static void setHashKeysForCon(IConnection con) {
List<String> conKeyColumnList = getKeyColumnList(con.getMetadataTable());
IElementParameter parTableCon = con.getElementParameter(HASH_KEYS);
boolean isExistHashValue = false;
if (parTableCon != null) {
if (conKeyColumnList.size() > 0) {
((List) parTableCon.getValue()).clear();
con.getElementParameter(HASH_PARTION).setValue(true);
Object[] itemCon = parTableCon.getListItemsValue();
String clumnKeyListName = "";
for (Object itemList : itemCon) {
if (((ElementParameter) itemList).getFieldType().equals(EParameterFieldType.PREV_COLUMN_LIST) || ((ElementParameter) itemList).getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
clumnKeyListName = ((ElementParameter) itemList).getName();
break;
}
}
for (String partionValue : conKeyColumnList) {
for (Object keyParMap : ((List) parTableCon.getValue())) {
Map existKeyMap = (Map) keyParMap;
if (existKeyMap.get(clumnKeyListName).equals(partionValue)) {
isExistHashValue = true;
break;
}
}
if (!isExistHashValue) {
Map partionKeyMap = new HashMap<String, String>();
partionKeyMap.put(clumnKeyListName, partionValue);
((List) parTableCon.getValue()).add(partionKeyMap);
}
}
} else {
con.getElementParameter(HASH_PARTION).setValue(false);
}
}
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class ParallelExecutionUtils method compareKeyPartions.
public static boolean compareKeyPartions(IConnection parConnection, Node needToPar) {
String partitioning = needToPar.getComponent().getPartitioning();
boolean isSame = false;
String[] partitionKey = partitioning.split("\\.");
boolean canCompare = partitionKey.length > 1 ? true : false;
if (canCompare) {
// before compare,in case there is a Integer value exist in the column list
if (isPartitionKeysExist(parConnection)) {
reSetParKeyValuesForCon(parConnection);
}
IElementParameter parTableCon = parConnection.getElementParameter(HASH_KEYS);
IElementParameter parTableNode = needToPar.getElementParameter(partitionKey[0]);
if (parTableNode != null) {
// for the partition key
String clumnKeyListName = "KEY_COLUMN";
String clumnNodeListName = partitionKey[1];
List<String> parKeyValues = new ArrayList<String>();
List<String> columnKeyValues = new ArrayList<String>();
ElementParameter nodeElemForList = null;
for (Map conColumnListMap : (List<Map>) parTableCon.getValue()) {
if (conColumnListMap.get(clumnKeyListName) instanceof String) {
parKeyValues.add((String) conColumnListMap.get(clumnKeyListName));
}
}
for (Object nodeItemList : parTableNode.getListItemsValue()) {
if (((ElementParameter) nodeItemList).getFieldType().equals(EParameterFieldType.PREV_COLUMN_LIST) || ((ElementParameter) nodeItemList).getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
nodeElemForList = (ElementParameter) nodeItemList;
break;
}
}
if (nodeElemForList != null) {
for (Map nodeColumnListMap : (List<Map>) parTableNode.getValue()) {
Object value = nodeColumnListMap.get(clumnNodeListName);
if (nodeColumnListMap.get(clumnNodeListName) instanceof String) {
columnKeyValues.add((String) value);
} else if (value instanceof Integer) {
Integer index = (Integer) value;
if (nodeElemForList.getListItemsDisplayName().length > index) {
columnKeyValues.add(nodeElemForList.getListItemsDisplayName()[index]);
}
}
}
}
if (columnKeyValues.size() > 0) {
if (columnKeyValues.equals(parKeyValues)) {
isSame = true;
} else {
isSame = false;
}
}
}
}
return isSame;
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class StatsAndLogsManager method statsAndLogsParametersTitlePart.
private static List<IElementParameter> statsAndLogsParametersTitlePart(IProcess process) {
ElementParameter param;
IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
List<IElementParameter> paramList = new ArrayList<IElementParameter>();
//$NON-NLS-1$
String languagePrefix = LanguageManager.getCurrentLanguage().toString() + "_";
param = new ElementParameter(process);
param.setName(EParameterName.UPDATE_COMPONENTS.getName());
param.setValue(Boolean.FALSE);
param.setDisplayName(EParameterName.UPDATE_COMPONENTS.getDisplayName());
param.setFieldType(EParameterFieldType.CHECK);
param.setCategory(EComponentCategory.STATSANDLOGS);
param.setNumRow(1);
param.setReadOnly(true);
param.setRequired(false);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.ON_STATCATCHER_FLAG.getName());
param.setValue(preferenceStore.getBoolean(languagePrefix + EParameterName.ON_STATCATCHER_FLAG.getName()));
param.setDisplayName(EParameterName.ON_STATCATCHER_FLAG.getDisplayName());
param.setFieldType(EParameterFieldType.CHECK);
param.setCategory(EComponentCategory.STATSANDLOGS);
param.setNumRow(1);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.ON_LOGCATCHER_FLAG.getName());
param.setValue(preferenceStore.getBoolean(languagePrefix + EParameterName.ON_LOGCATCHER_FLAG.getName()));
param.setDisplayName(EParameterName.ON_LOGCATCHER_FLAG.getDisplayName());
param.setFieldType(EParameterFieldType.CHECK);
param.setCategory(EComponentCategory.STATSANDLOGS);
param.setNumRow(1);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.ON_METERCATCHER_FLAG.getName());
param.setValue(preferenceStore.getBoolean(languagePrefix + EParameterName.ON_METERCATCHER_FLAG.getName()));
param.setDisplayName(EParameterName.ON_METERCATCHER_FLAG.getDisplayName());
param.setFieldType(EParameterFieldType.CHECK);
param.setCategory(EComponentCategory.STATSANDLOGS);
param.setNumRow(1);
paramList.add(param);
// on console
param = new ElementParameter(process);
param.setName(EParameterName.ON_CONSOLE_FLAG.getName());
param.setValue(Boolean.FALSE);
param.setDisplayName(EParameterName.ON_CONSOLE_FLAG.getDisplayName());
param.setFieldType(EParameterFieldType.CHECK);
param.setCategory(EComponentCategory.STATSANDLOGS);
param.setNumRow(2);
//$NON-NLS-1$
param.setShowIf("((ON_CONSOLE_FLAG == 'true' or ON_CONSOLE_FLAG == 'false') and (ON_STATCATCHER_FLAG == 'true' or ON_LOGCATCHER_FLAG == 'true' or ON_METERCATCHER_FLAG == 'true'))");
paramList.add(param);
return paramList;
}
Aggregations