use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class UpdateMainParameterCommand method execute.
@Override
public void execute() {
if (result == null) {
return;
}
Object job = result.getJob();
if (job == null) {
return;
}
if (job instanceof IProcess2) {
Process process = (Process) job;
EComponentCategory category = null;
IUpdateItemType updateType = result.getUpdateType();
if (updateType instanceof EUpdateItemType) {
switch((EUpdateItemType) updateType) {
case JOB_PROPERTY_EXTRA:
category = EComponentCategory.EXTRA;
break;
case JOB_PROPERTY_STATS_LOGS:
category = EComponentCategory.STATSANDLOGS;
break;
case JOB_PROPERTY_HEADERFOOTER:
category = EComponentCategory.HEADERFOOTER;
break;
case JOB_PROPERTY_STORM:
if (ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
category = EComponentCategory.SPARK_JOB_CONFIG;
}
break;
case JOB_PROPERTY_MAPREDUCE:
if (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType())) {
category = EComponentCategory.MAPREDUCE_JOB_CONFIG_FOR_HADOOP;
} else if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType())) {
category = EComponentCategory.SPARK_JOB_CONFIG;
}
break;
default:
}
if (category == EComponentCategory.HEADERFOOTER) {
if (result.getResultType() == EUpdateResult.UPDATE) {
if (result.isChecked()) {
for (IElementParameter param : process.getElementParameters()) {
if (param.getCategory() == EComponentCategory.HEADERFOOTER) {
IElementParameter headerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_HEADERID.getName());
if (headerIDParameter != null) {
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) headerIDParameter.getValue());
HeaderFooterConnection repositoryConnection = null;
if (lastVersion != null) {
final Item item = lastVersion.getProperty().getItem();
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
if (repositoryConnection != null) {
Boolean isHeader = repositoryConnection.isIsHeader();
String libraries = repositoryConnection.getLibraries();
String mainCode = repositoryConnection.getMainCode();
String imports = repositoryConnection.getImports();
process.getElementParameter(EParameterName.HEADER_ENABLED.getName()).setValue(isHeader);
process.getElementParameter(EParameterName.HEADER_LIBRARY.getName()).setValue(libraries);
process.getElementParameter(EParameterName.HEADER_CODE.getName()).setValue(mainCode);
process.getElementParameter(EParameterName.HEADER_IMPORT.getName()).setValue(imports);
}
}
}
}
IElementParameter footerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_FOOTERID.getName());
if (footerIDParameter != null) {
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) footerIDParameter.getValue());
HeaderFooterConnection repositoryConnection = null;
if (lastVersion != null) {
final Item item = lastVersion.getProperty().getItem();
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
if (repositoryConnection != null) {
Boolean isHeader = repositoryConnection.isIsHeader();
String libraries = repositoryConnection.getLibraries();
String mainCode = repositoryConnection.getMainCode();
String imports = repositoryConnection.getImports();
process.getElementParameter(EParameterName.FOOTER_ENABLED.getName()).setValue(!isHeader);
process.getElementParameter(EParameterName.FOOTER_LIBRARY.getName()).setValue(libraries);
process.getElementParameter(EParameterName.FOOTER_CODE.getName()).setValue(mainCode);
process.getElementParameter(EParameterName.FOOTER_IMPORT.getName()).setValue(imports);
}
}
}
}
}
}
}
}
} else if (category != null) {
boolean repository = false;
if (result.getResultType() == EUpdateResult.UPDATE) {
// upgrade from repository
if (result.isChecked()) {
IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
if (property != null) {
Map<String, IElementParameter> childParameters = property.getChildParameters();
if (childParameters != null) {
IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
// is repository
if (elementParameter != null && EmfComponent.REPOSITORY.equals(elementParameter.getValue())) {
for (IElementParameter param : process.getElementParameters()) {
if (param.getCategory() != category) {
continue;
}
String repositoryValue = param.getRepositoryValue();
if (param.isShow(process.getElementParameters()) && (repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName()))) {
Object objectValue = RepositoryToComponentProperty.getValue((org.talend.core.model.metadata.builder.connection.Connection) result.getParameter(), repositoryValue, null);
if (objectValue != null) {
if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) {
boolean found = false;
String[] items = param.getListRepositoryItems();
for (int i = 0; (i < items.length) && (!found); i++) {
if (objectValue.equals(items[i])) {
found = true;
process.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
}
}
} else if (EParameterName.HADOOP_ADVANCED_PROPERTIES.getName().equals(param.getName()) || EParameterName.SPARK_ADVANCED_PROPERTIES.getName().equals(param.getName())) {
List<Map> list = (ArrayList) param.getValue();
for (Map map : list) {
if (map.get("BUILDIN") != null && map.get("BUILDIN").equals("TRUE")) {
if (objectValue instanceof List) {
((List) objectValue).add(map);
}
}
}
process.setPropertyValue(param.getName(), objectValue);
} else {
process.setPropertyValue(param.getName(), objectValue);
}
param.setRepositoryValueUsed(true);
param.setReadOnly(true);
repository = true;
}
}
}
}
}
}
}
}
IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
Map<String, IElementParameter> childParameters = null;
if (property != null) {
childParameters = property.getChildParameters();
}
if (!repository) {
if (childParameters != null) {
IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
elementParameter.setValue(EmfComponent.BUILTIN);
}
// built-in
IElementParameter dbTypeParam = null;
IElementParameter impliciteDbType = null;
for (IElementParameter param : process.getElementParameters()) {
if (param.getCategory() != category) {
continue;
}
String repositoryValue = param.getRepositoryValue();
if (param.isShow(process.getElementParameters()) && (repositoryValue != null)) {
// for mysql db verion
if (EParameterName.DB_TYPE.getName().equals(param.getName()) && "TYPE".equals(repositoryValue)) {
dbTypeParam = param;
}
if ("DB_TYPE_IMPLICIT_CONTEXT".equals(param.getName()) && "TYPE".equals(repositoryValue)) {
impliciteDbType = param;
}
if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && dbTypeParam != null && dbTypeParam.getValue() != null) {
final int indexOfItem = dbTypeParam.getIndexOfItemFromList(dbTypeParam.getValue().toString());
String dbType = dbTypeParam.getListItemsDisplayCodeName()[indexOfItem];
setDBVersionForMysql(param, dbType);
} else if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && impliciteDbType != null && impliciteDbType.getValue() != null) {
final int indexOfItem = impliciteDbType.getIndexOfItemFromList(impliciteDbType.getValue().toString());
String dbType = impliciteDbType.getListItemsDisplayCodeName()[indexOfItem];
setDBVersionForMysql(param, dbType);
}
param.setRepositoryValueUsed(false);
param.setReadOnly(false);
}
}
} else {
if (childParameters != null) {
IElementParameter elementParameter = childParameters.get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
ConnectionItem connItem = UpdateRepositoryUtils.getConnectionItemByItemId((String) elementParameter.getValue());
ConnectionContextHelper.addContextForProcessParameter(process, connItem, category, false);
}
}
}
}
// else { // for extension
}
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class UpdateJobletNodeCommand method updateGraphicalNodesSchema.
/**
* qzhang Comment method "updateGraphicalNodesSchema".
*
* this method is moved from class AbstractTalendEditor.
*
* @param evt
*/
@SuppressWarnings("unchecked")
private void updateGraphicalNodesSchema(Process process, PropertyChangeEvent evt) {
if (!(evt.getSource() instanceof INode)) {
return;
}
INode sourceNode = (INode) evt.getSource();
String componentName = sourceNode.getComponent().getName();
IComponent newComponent = ComponentsFactoryProvider.getInstance().get(componentName, process.getComponentsType());
if (newComponent == null) {
return;
}
Object[] newMetadataTables = (Object[]) evt.getNewValue();
List<IMetadataTable> newInputTableList = (List<IMetadataTable>) newMetadataTables[0];
List<IMetadataTable> newOutputTableList = (List<IMetadataTable>) newMetadataTables[1];
for (Node node : (List<Node>) process.getGraphicalNodes()) {
if (node.getComponent().getName().equals(componentName)) {
List<IElementParameter> outputElemParams = new ArrayList<IElementParameter>();
IElementParameter outputElemParam = null;
List<? extends IElementParameter> elementParameters = node.getElementParameters();
for (IElementParameter elementParameter : elementParameters) {
if (EParameterFieldType.SCHEMA_TYPE.equals(elementParameter.getFieldType())) {
outputElemParams.add(elementParameter);
}
}
ChangeMetadataCommand command;
List<? extends IConnection> incomingConnections = node.getIncomingConnections();
if (incomingConnections.size() <= 1) {
for (int i = 0; i < incomingConnections.size(); i++) {
IConnection connection = incomingConnections.get(i);
Node source = (Node) connection.getSource();
IMetadataTable metadataTable = connection.getMetadataTable();
IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
if (newInputMetadataTable != null && !metadataTable.sameMetadataAs(newInputMetadataTable)) {
IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(source, elementParam, metadataTable, newInputMetadataTable);
command.execute(Boolean.FALSE);
}
}
} else {
for (IElementParameter param : node.getElementParameters()) {
if (param.isShow(node.getElementParameters()) && param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) {
IMetadataTable table = node.getMetadataFromConnector(param.getContext());
IElementParameter connParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
if (table != null && connParam != null && !StringUtils.isEmpty((String) connParam.getValue())) {
for (IConnection connection : incomingConnections) {
if (connection.isActivate() && connection.getName().equals(connParam.getValue())) {
if (!table.sameMetadataAs(connection.getMetadataTable(), IMetadataColumn.OPTIONS_IGNORE_KEY | IMetadataColumn.OPTIONS_IGNORE_NULLABLE | IMetadataColumn.OPTIONS_IGNORE_COMMENT | IMetadataColumn.OPTIONS_IGNORE_PATTERN | IMetadataColumn.OPTIONS_IGNORE_DBCOLUMNNAME | IMetadataColumn.OPTIONS_IGNORE_DBTYPE | IMetadataColumn.OPTIONS_IGNORE_DEFAULT | IMetadataColumn.OPTIONS_IGNORE_BIGGER_SIZE)) {
Node source = (Node) connection.getSource();
IMetadataTable metadataTable = connection.getMetadataTable();
IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(source, elementParam, metadataTable, table);
command.execute(Boolean.FALSE);
}
}
}
}
}
}
}
List<? extends IConnection> outgoingConnections = node.getOutgoingConnections();
for (int i = 0; i < outgoingConnections.size(); i++) {
IConnection connection = outgoingConnections.get(i);
Node target = (Node) connection.getTarget();
IMetadataTable metadataTable = connection.getMetadataTable();
if (metadataTable != null) {
IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
if (newOutputMetadataTable != null && !metadataTable.sameMetadataAs(newOutputMetadataTable)) {
IElementParameter elementParam = target.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
command = new ChangeMetadataCommand(target, elementParam, target.getMetadataFromConnector(metadataTable.getAttachedConnector()), newOutputMetadataTable);
command.execute(Boolean.FALSE);
}
}
}
List<IMetadataTable> metadataList = node.getMetadataList();
for (IMetadataTable metadataTable : metadataList) {
IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
outputElemParam = UpdateManagerUtils.getElemParam(outputElemParams, metadataTable.getAttachedConnector());
if (outputElemParam != null && newInputMetadataTable != null) {
command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newInputMetadataTable);
command.execute(Boolean.FALSE);
IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
MetadataToolHelper.copyTable(newInputMetadataTable, metadataFromConnector);
} else if (outputElemParam != null && newOutputMetadataTable != null) {
command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newOutputMetadataTable);
command.execute(Boolean.FALSE);
IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
MetadataToolHelper.copyTable(newOutputMetadataTable, metadataFromConnector);
}
}
}
}
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class ValidationRulesUtil method getCurrentValidationRuleObjs.
public static IRepositoryViewObject getCurrentValidationRuleObjs(IElement element) {
IElementParameter param = element.getElementParameter(EParameterName.VALIDATION_RULES.getName());
if (param == null || param.getValue() == null || (Boolean) param.getValue() == false) {
return null;
}
param = element.getElementParameter(EParameterFieldType.VALIDATION_RULE_TYPE.getName());
if (param == null) {
return null;
}
param = param.getChildParameters().get(EParameterName.REPOSITORY_VALIDATION_RULE_TYPE.getName());
if (param != null && param.getValue() != null) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
String linkedRepository = (String) param.getValue();
try {
IRepositoryViewObject object = factory.getLastVersion(linkedRepository);
if (object == null) {
return null;
}
return object;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
return null;
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class MapperComponentDocumentation method generateParameters.
private void generateParameters(Element parametersElement, List elementParameterList) {
List<IElementParameter> copyElementParameterList = new ArrayList(elementParameterList);
if (elementParameterList != null && elementParameterList.size() != 0) {
for (int j = 0; j < elementParameterList.size(); j++) {
IElementParameter elemparameter = (IElementParameter) elementParameterList.get(j);
if ((!elemparameter.isShow(copyElementParameterList) && (!elemparameter.getName().equals(EParameterFieldType.SCHEMA_TYPE.getName()))) || elemparameter.getCategory().equals(EComponentCategory.VIEW) || //$NON-NLS-1$
"ACTIVATE".equals(elemparameter.getName()) || //$NON-NLS-1$
"MAP".equals(elemparameter.getName()) || "PREVIEW".equals(elemparameter.getName())) {
//$NON-NLS-1$
continue;
}
//$NON-NLS-1$
Element columnElement = parametersElement.addElement("column");
//$NON-NLS-1$
columnElement.addAttribute("name", HTMLDocUtils.checkString(elemparameter.getDisplayName()));
Object eleObj = elemparameter.getValue();
//$NON-NLS-1$
String value = "";
if (eleObj != null) {
value = eleObj.toString();
if (elemparameter.getName().equals("COMMENT")) {
//$NON-NLS-1$
columnElement.addCDATA(value);
} else {
columnElement.setText(value);
}
}
}
}
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class RunProcessContext method loadLog4jContextFromProcess.
public void loadLog4jContextFromProcess() {
IElementParameter param = process.getElementParameter(EParameterName.LOG4J_RUN_ACTIVATE.getName());
if (param != null && param.getValue() instanceof Boolean && (Boolean) param.getValue()) {
// checked
RunProcessPlugin.getDefault().getPreferenceStore().setValue(RunProcessPrefsConstants.CUSTOMLOG4J, true);
} else {
RunProcessPlugin.getDefault().getPreferenceStore().setValue(RunProcessPrefsConstants.CUSTOMLOG4J, false);
}
setUseCustomLevel(RunProcessPlugin.getDefault().getPreferenceStore().getBoolean(RunProcessPrefsConstants.CUSTOMLOG4J));
if (useCustomLevel) {
IElementParameter log4jLevelParam = process.getElementParameter(EParameterName.LOG4J_RUN_LEVEL.getName());
if (log4jLevelParam != null && log4jLevelParam.getValue() != null) {
RunProcessPlugin.getDefault().getPreferenceStore().setValue(RunProcessPrefsConstants.LOG4JLEVEL, (String) log4jLevelParam.getValue());
} else {
RunProcessPlugin.getDefault().getPreferenceStore().setValue(RunProcessPrefsConstants.LOG4JLEVEL, "");
}
}
setLog4jLevel(RunProcessPlugin.getDefault().getPreferenceStore().getString(RunProcessPrefsConstants.LOG4JLEVEL));
}
Aggregations