use of org.talend.core.model.process.Element in project tdi-studio-se by Talend.
the class StatLogsAndImplicitcontextTreeViewPage method saveProcess.
private void saveProcess(RepositoryNode node, String paramName, Boolean isUseProjectSettings, boolean addContextModel, Map<String, Set<String>> contextVars, IProgressMonitor monitor) {
Property property = node.getObject().getProperty();
ProcessItem pItem = (ProcessItem) property.getItem();
ParametersType pType = pItem.getProcess().getParameters();
if (isOpenProcess(node)) {
Process process = getProcess(opendProcess, node);
LoadProjectSettingsCommand command = new LoadProjectSettingsCommand(process, paramName, isUseProjectSettings);
exeCommand(process, command);
Element elem = null;
String propertyName = "";
String propertyTypeName = "";
if (EParameterName.IMPLICITCONTEXT_USE_PROJECT_SETTINGS.getName().equals(paramName)) {
elem = (Element) pro.getInitialContextLoad();
propertyName = JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName()) + ':' + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
propertyTypeName = JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName()) + ':' + EParameterName.PROPERTY_TYPE.getName();
} else if (EParameterName.STATANDLOG_USE_PROJECT_SETTINGS.getName().equals(paramName)) {
elem = (Element) pro.getStatsAndLog();
propertyName = EParameterName.PROPERTY_TYPE.getName() + ':' + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
propertyTypeName = EParameterName.PROPERTY_TYPE.getName() + ':' + EParameterName.PROPERTY_TYPE.getName();
}
IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
if (ptParam != null) {
IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
Object proValue = propertyElem.getValue();
if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
String value = (String) repositoryElem.getValue();
ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
if (connectionItem != null) {
Connection connection = connectionItem.getConnection();
ChangeValuesFromRepository cmd = new ChangeValuesFromRepository(process, connection, addContextModel ? propertyName : propertyTypeName, value);
cmd.ignoreContextMode(true);
exeCommand(process, cmd);
}
}
}
monitor.worked(100);
} else {
ElementParameter2ParameterType.setParameterValue(pType, paramName, isUseProjectSettings);
if (isUseProjectSettings) {
if (EParameterName.IMPLICITCONTEXT_USE_PROJECT_SETTINGS.getName().equals(paramName)) {
ProjectSettingManager.reloadImplicitValuesFromProjectSettings(pType, ProjectManager.getInstance().getCurrentProject());
} else if (EParameterName.STATANDLOG_USE_PROJECT_SETTINGS.getName().equals(paramName)) {
ProjectSettingManager.reloadStatsAndLogFromProjectSettings(pType, ProjectManager.getInstance().getCurrentProject());
}
}
if (addContextModel && contextVars != null && !contextVars.isEmpty() && ContextUtils.getAllContextItem() != null) {
ContextUtils.addInContextModelForProcessItem(pItem, contextVars, ContextUtils.getAllContextItem());
}
try {
factory.save(pItem);
monitor.worked(100);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
use of org.talend.core.model.process.Element in project tdi-studio-se by Talend.
the class StatLogsAndImplicitcontextTreeViewPage method save.
private void save() {
if (viewer == null) {
return;
}
final IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.getString("StatLogsAndImplicitcontextTreeViewPage.SaveProjectSettings"), //$NON-NLS-1$
(addedObjects.size() + statAddedObjects.size()) * 100);
addContext = false;
statsLogAddContextModel = false;
implicitAddContextModel = false;
Map<String, Set<String>> implicitContextVars = null;
Map<String, Set<String>> statsLogContextVars = null;
// if add some object to use project setting ,check context model
if (!addedObjects.isEmpty()) {
if (pro != null) {
Element implicitContextLoad = (Element) pro.getInitialContextLoad();
implicitContextVars = DetectContextVarsUtils.detectByPropertyType(implicitContextLoad, true);
}
}
if (!statAddedObjects.isEmpty()) {
if (pro != null) {
Element statsAndLog = (Element) pro.getStatsAndLog();
statsLogContextVars = DetectContextVarsUtils.detectByPropertyType(statsAndLog, true);
}
}
// if statslog and implicit use the same connection only show add context dialog one time
if (implicitContextVars != null && statsLogContextVars != null && !implicitContextVars.isEmpty() && !statsLogContextVars.isEmpty() && implicitContextVars.keySet().toArray()[0].equals(statsLogContextVars.keySet().toArray()[0])) {
showAddContextDialog(implicitContextVars);
if (addContext) {
statsLogAddContextModel = true;
implicitAddContextModel = true;
}
} else {
if (implicitContextVars != null && !implicitContextVars.isEmpty()) {
showAddContextDialog(implicitContextVars);
if (addContext) {
implicitAddContextModel = true;
}
}
if (statsLogContextVars != null && !statsLogContextVars.isEmpty()) {
showAddContextDialog(statsLogContextVars);
if (addContext) {
statsLogAddContextModel = true;
}
}
}
saveChangedNode(EParameterName.IMPLICITCONTEXT_USE_PROJECT_SETTINGS.getName(), implicitAddContextModel, implicitContextVars, monitor);
saveChangedNode(EParameterName.STATANDLOG_USE_PROJECT_SETTINGS.getName(), statsLogAddContextModel, statsLogContextVars, monitor);
monitor.done();
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(true, true, runnable);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.process.Element in project tdi-studio-se by Talend.
the class ProjectSettingMultipleThreadDynamicComposite method updateConnectionFromRepository.
private void updateConnectionFromRepository() {
if (repositoryPropertyName == null || repositoryPropertyName.split(":").length != 2 || connectionUpdated) {
return;
}
String[] split = repositoryPropertyName.split(":");
String parentParamName = split[0];
Element elementParams = elem;
IElementParameter elementParameter = elementParams.getElementParameter(parentParamName);
if (elementParameter != null && elementParameter.isShow(elem.getElementParameters()) && elementParameter.getChildParameters() != null) {
if (elementParameter.getChildParameters().get("PROPERTY_TYPE") != null && !EmfComponent.BUILTIN.equals(elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue())) {
DatabaseConnection connection = null;
String id = (String) elementParameter.getChildParameters().get("REPOSITORY_PROPERTY_TYPE").getValue();
// bug 0018192
String propertyType = (String) elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue();
ProxyRepositoryFactory proxyRepositoryFactory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject lastVersion = null;
if (null != id && !"".equals(id)) {
try {
lastVersion = proxyRepositoryFactory.getLastVersion(id);
if (null == lastVersion && propertyType.equals(EmfComponent.REPOSITORY)) {
List<ConnectionItem> connectionItems = proxyRepositoryFactory.getMetadataConnectionsItem();
if (connectionItems.isEmpty()) {
elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", "");
ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, null, parentParamName + ":" + "PROPERTY_TYPE", EmfComponent.REPOSITORY);
changeValuesFromRepository1.execute();
}
for (ConnectionItem cItem : connectionItems) {
if (cItem instanceof DatabaseConnectionItem) {
id = cItem.getProperty().getId();
lastVersion = proxyRepositoryFactory.getLastVersion(id);
elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", id);
break;
}
}
}
} catch (PersistenceException e) {
e.printStackTrace();
}
} else {
try {
List<ConnectionItem> connectionItems = proxyRepositoryFactory.getMetadataConnectionsItem();
for (ConnectionItem cItem : connectionItems) {
if (cItem instanceof DatabaseConnectionItem) {
lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(cItem.getProperty().getId());
id = cItem.getProperty().getId();
lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(id);
elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", id);
break;
}
}
} catch (PersistenceException e) {
e.printStackTrace();
}
}
if (lastVersion != null && lastVersion.getProperty() != null) {
Item item = lastVersion.getProperty().getItem();
if (item instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
connection = (DatabaseConnection) dbItem.getConnection();
}
}
if (connection != null) {
boolean sameValues = true;
for (IElementParameter param : elementParams.getElementParameters()) {
String repositoryValue = param.getRepositoryValue();
if (param.isShow(elementParams.getElementParameters()) && repositoryValue != null && !param.getName().equals("PROPERTY_TYPE")) {
Object repValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, null);
if (repValue == null) {
continue;
}
if (repositoryValue.equals(UpdatesConstants.TYPE)) {
// datebase type
boolean found = false;
String[] list = param.getListRepositoryItems();
for (int i = 0; (i < list.length) && (!found); i++) {
if (repValue.equals(list[i])) {
found = true;
}
}
if (!found) {
sameValues = false;
break;
}
} else {
// check the value
if (!param.getValue().equals(repValue)) {
sameValues = false;
break;
}
}
}
}
if (!sameValues) {
ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, connection, repositoryPropertyName, id);
changeValuesFromRepository.execute();
connectionUpdated = true;
}
}
// bug 0018192
// else {
// change to build in
// ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem,
// null,
// parentParamName + ":" + "PROPERTY_TYPE", EmfComponent.BUILTIN);
// changeValuesFromRepository1.execute();
// }
}
}
}
use of org.talend.core.model.process.Element in project tdi-studio-se by Talend.
the class ProjectSettingManager method reloadStatsAndLogFromProjectSettings.
public static void reloadStatsAndLogFromProjectSettings(Element process, Project pro, StatsAndLogsComposite statsComposite) {
Element elem = createStatsAndLogsElement(pro);
ParametersType stats = pro.getEmfProject().getStatAndLogsSettings().getParameters();
ElementParameterType eleType = ElementParameter2ParameterType.findElementParameterType(stats, //$NON-NLS-1$
EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (eleType != null) {
String value = eleType.getValue();
if (value != null && !"".equals(value) && !RepositoryNode.NO_ID.equals(value)) {
//$NON-NLS-1$
ElementParameterType propertyType = ElementParameter2ParameterType.findElementParameterType(stats, //$NON-NLS-1$
EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.PROPERTY_TYPE.getName());
if (propertyType != null) {
String propertyTypeValue = propertyType.getValue();
if (//$NON-NLS-1$
propertyTypeValue != null && !"".equals(propertyTypeValue) && !EmfComponent.BUILTIN.equals(propertyTypeValue)) {
IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(value);
if (lastVersion == null || lastVersion.getProperty() == null || lastVersion.getProperty().getItem() == null) {
ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, null, //$NON-NLS-1$
EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.PROPERTY_TYPE.getName(), EmfComponent.BUILTIN);
changeValuesFromRepository.execute();
saveStatsAndLogToProjectSettings(elem, pro);
}
}
}
}
// load the project settings to process
ElementParameter2ParameterType.loadElementParameters(process, stats, //$NON-NLS-1$
EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.PROPERTY_TYPE.getName());
// change repository item
// TODO
// StatsAndLogsHelper.changeRepositoryConnection(process, statsComposite);
}
}
use of org.talend.core.model.process.Element in project tdi-studio-se by Talend.
the class ProjectSettingManager method createStatsAndLogsElement.
/**
*
* create StatsAndLogsElement for project
*
* @param pro
* @return
*/
public static Element createStatsAndLogsElement(Project pro) {
StatAndLogsSettings stats = pro.getEmfProject().getStatAndLogsSettings();
// load Project's StatsAndLogsSetting to StatsAndLogsElement
if (stats == null) {
StatsAndLogsHelper.loadPreferenceToProject(pro);
} else {
// 10927
if (stats.getParameters() == null) {
stats.setParameters(TalendFileFactory.eINSTANCE.createParametersType());
}
}
Element elem = (Element) pro.getStatsAndLog();
if (elem == null) {
elem = new StatsAndLogsElement();
StatsAndLogsHelper.createStatsAndLogsParameters(elem);
pro.setStatsAndLog(elem);
}
return elem;
}
Aggregations