use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.
the class AnalysisColumnTreeViewer method addColumnUdi.
/**
* DOC xqliu Comment method "addColumnUdi". ADD xqliu 2010-02-23 feature 11617
*
* @param treeItem
* @param meIndicator
* @param columnIndex
* @return
*/
private TreeEditor addColumnUdi(final TreeItem treeItem, final ModelElementIndicator meIndicator, int columnIndex) {
TreeEditor addUdiEditor = new TreeEditor(tree);
// $NON-NLS-1$
Label addUdiLabl = createTreeItemLabel(tree, ImageLib.ADD_IND_DEFINITION, "AnalysisColumnTreeViewer.addUdi");
addUdiLabl.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
DataManager dm = getAnalysis().getContext().getConnection();
if (dm == null) {
masterPage.doSave(null);
}
CheckedTreeSelectionDialog dialog = UDIUtils.createUdiCheckedTreeSelectionDialog(meIndicator);
if (dialog.open() == Window.OK) {
// MOD qiongli 2012-10-24 TDQ-6308,just remove some deselected indicatorUnit then set dirty to
// true,just create new indicatorUnit for some new added UDI then set dirty to true.
List<IndicatorDefinition> allSelectedIndicatorDefinitions = new ArrayList<IndicatorDefinition>();
Set<String> allSelectedIndNames = new HashSet<String>();
for (Object obj : dialog.getResult()) {
if (obj instanceof SysIndicatorDefinitionRepNode) {
IndicatorDefinition udid = ((SysIndicatorDefinitionRepNode) obj).getIndicatorDefinition();
allSelectedIndicatorDefinitions.add(udid);
if (udid != null) {
allSelectedIndNames.add(udid.getName());
}
}
}
Set<String> oldSelectedIndNames = new HashSet<String>();
for (IndicatorUnit indicatorUnit : meIndicator.getIndicatorUnits()) {
Indicator indicator = indicatorUnit.getIndicator();
if (indicator instanceof UserDefIndicator) {
if (allSelectedIndNames.contains(indicator.getName())) {
oldSelectedIndNames.add(indicator.getName());
} else {
// remove the UDI from UI need to insert this UDI into removeList
deleteIndicatorItems(meIndicator, indicatorUnit);
if (!isDirty()) {
setDirty(true);
}
}
}
}
treeItem.removeAll();
for (IndicatorDefinition udid : allSelectedIndicatorDefinitions) {
if (udid != null && oldSelectedIndNames.contains(udid.getName())) {
continue;
}
IndicatorUnit[] addIndicatorUnits = null;
try {
addIndicatorUnits = UDIUtils.createIndicatorUnit(udid, meIndicator, getAnalysis());
} catch (Throwable e1) {
log.warn(e1, e1);
}
if (addIndicatorUnits != null && addIndicatorUnits.length > 0) {
for (IndicatorUnit unit : addIndicatorUnits) {
createOneUnit(treeItem, unit);
}
if (!isDirty()) {
setDirty(true);
}
}
}
treeItem.setExpanded(true);
masterPage.refreshTheTree(masterPage.getCurrentModelElementIndicators());
}
}
});
addUdiEditor.minimumWidth = addUdiLabl.getImage().getBounds().width;
addUdiEditor.setEditor(addUdiLabl, treeItem, columnIndex);
return addUdiEditor;
}
use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.
the class RunAnalysisAction method isConnectedAvailable.
/**
* check whether the connection of analysis is available.
*
* @return true when the connection is well connected
*/
private boolean isConnectedAvailable(TDQAnalysisItem runItem) {
DataManager datamanager = runItem.getAnalysis().getContext().getConnection();
if (datamanager == null) {
// $NON-NLS-1$
log.error(DefaultMessagesImpl.getString("ColumnMasterDetailsPage.NoColumnAssigned", runItem.getAnalysis().getName()));
// $NON-NLS-1$
MessageDialogWithToggle.openError(// $NON-NLS-1$
null, // $NON-NLS-1$
DefaultMessagesImpl.getString("RunAnalysisAction.runAnalysis"), // $NON-NLS-1$
DefaultMessagesImpl.getString("ColumnMasterDetailsPage.NoColumnAssigned", runItem.getAnalysis().getName()));
return false;
}
return ConnectionUtils.checkConnection(datamanager, runItem.getAnalysis().getName());
}
use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.
the class RunAnalysisAction method addTaggedVaLueIntoConnection.
private void addTaggedVaLueIntoConnection(TDQAnalysisItem runItem) {
DataManager datamanager = runItem.getAnalysis().getContext().getConnection();
if (datamanager instanceof DatabaseConnection) {
TaggedValue productName = TaggedValueHelper.getTaggedValue(TaggedValueHelper.DB_PRODUCT_NAME, datamanager.getTaggedValue());
TaggedValue productVersion = TaggedValueHelper.getTaggedValue(TaggedValueHelper.DB_PRODUCT_VERSION, datamanager.getTaggedValue());
// $NON-NLS-1$
log.info("DB Product Name: " + productName.getValue());
// $NON-NLS-1$
log.info("DB Product Version: " + productVersion.getValue());
} else if (datamanager instanceof DelimitedFileConnection) {
// $NON-NLS-1$
log.info("File Connection path: " + ((DelimitedFileConnection) datamanager).getFilePath());
}
}
use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.
the class PatternLabelProvider method createIndicatorUnit.
/**
* DOC xqliu Comment method "createIndicatorUnit".
*
* @param pfile
* @param modelElementIndicator
* @param analysis
* @param indicatorDefinition
* @return
*/
public static TypedReturnCode<IndicatorUnit> createIndicatorUnit(Pattern pattern, ModelElementIndicator modelElementIndicator, Analysis analysis, IndicatorDefinition indicatorDefinition) {
TypedReturnCode<IndicatorUnit> result = new TypedReturnCode<IndicatorUnit>();
for (Indicator indicator : modelElementIndicator.getIndicators()) {
// MOD xwang 2011-08-01 bug TDQ-2730
if (UDIHelper.getMatchingIndicatorName(indicatorDefinition, pattern).equals(indicator.getName()) && indicator instanceof PatternMatchingIndicator) {
result.setOk(false);
// $NON-NLS-1$
result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.Selected"));
return result;
}
// ~
}
// MOD scorreia 2009-01-06: when expression type is not set (version
// TOP-1.1.x), then it's supposed to be a
// regexp pattern. This could be false because expression type was not
// set into SQL pattern neither in TOP-1.1.
// This means that there could exist the need for a migration task to
// set the expression type depending on the
// folder where the pattern is stored. The method
// DomainHelper.getExpressionType(pattern) tries to find the type
// of pattern.
Indicator patternMatchingIndicator = null;
String expressionType = DomainHelper.getExpressionType(pattern);
boolean isSQLPattern = (ExpressionType.SQL_LIKE.getLiteral().equals(expressionType));
if (indicatorDefinition != null) {
patternMatchingIndicator = UDIFactory.createUserDefIndicator(indicatorDefinition, pattern);
} else {
patternMatchingIndicator = isSQLPattern ? PatternIndicatorFactory.createSqlPatternMatchingIndicator(pattern) : PatternIndicatorFactory.createRegexpMatchingIndicator(pattern);
}
IEditorPart theEdit = CorePlugin.getDefault().getCurrentActiveEditor();
if (theEdit != null && theEdit instanceof AnalysisEditor && analysis.getContext().getConnection() == null) {
theEdit.doSave(null);
}
ExecutionLanguage executionLanguage = analysis.getParameters().getExecutionLanguage();
DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(analysis);
if (dbmsLanguage.isSql()) {
// $NON-NLS-1$
MessageUI.openWarning(DefaultMessagesImpl.getString("PatternUtilities.ConnectionError"));
result.setOk(false);
return result;
}
boolean isJavaEngin = ExecutionLanguage.JAVA.equals(executionLanguage);
Expression returnExpression = dbmsLanguage.getRegexp(pattern);
// MOD gdbu 2011-8-26 bug : TDQ-2169
if ((ExpressionType.REGEXP.getLiteral().equals(expressionType) || ExpressionType.SQL_LIKE.getLiteral().equals(expressionType)) && returnExpression == null) {
// ~TDQ-2169
String executeType = isJavaEngin ? executionLanguage.getName() : dbmsLanguage.getDbmsName();
boolean openPattern = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("PatternUtilities.Warning"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("PatternUtilities.NoExpression", executeType, pattern.getName()));
if (openPattern) {
RepositoryNode node = RepositoryNodeHelper.recursiveFind(pattern);
if (RepositoryNodeHelper.canOpenEditor(node)) {
new OpenItemEditorAction(new IRepositoryNode[] { node }).run();
}
}
result.setOk(false);
return result;
}
// a regular expression for the analyzed
// database, but we probably test also whether the analyzed database
// support the regular expressions (=> check
// DB type, DB number version, existence of UDF)
DataManager dm = analysis.getContext().getConnection();
if (dm != null) {
TypedReturnCode<java.sql.Connection> trc = JavaSqlFactory.createConnection((Connection) dm);
// MOD qiongli 2011-1-10 feature 16796
boolean isDelimitedFileConnection = ConnectionUtils.isDelimitedFileConnection((DataProvider) dm);
if (trc != null) {
// SoftwareSystem softwareSystem = DatabaseContentRetriever.getSoftwareSystem(conn);
// MOD sizhaoliu TDQ-6316
dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(dm);
}
// MOD xqliu 2010-08-12 bug 14601
if (!(isSQLPattern || DefinitionHandler.getInstance().canRunRegularExpressionMatchingIndicator(dbmsLanguage, isJavaEngin, pattern) || isDelimitedFileConnection)) {
// MessageDialogWithToggle.openInformation(null,
// DefaultMessagesImpl.getString("PatternUtilities.Pattern"), DefaultMessagesImpl //$NON-NLS-1$
// .getString("PatternUtilities.couldnotSetIndicator")); //$NON-NLS-1$
result.setOk(false);
// $NON-NLS-1$
result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.couldnotSetIndicator"));
return result;
}
// ~ 14601
}
// when the indicator is created.
if (indicatorDefinition == null) {
if (!DefinitionHandler.getInstance().setDefaultIndicatorDefinition(patternMatchingIndicator)) {
// $NON-NLS-1$
log.error(DefaultMessagesImpl.getString("PatternUtilities.SetFailed", patternMatchingIndicator.getName()));
}
} else {
patternMatchingIndicator.setIndicatorDefinition(indicatorDefinition);
}
IndicatorEnum type = IndicatorEnum.findIndicatorEnum(patternMatchingIndicator.eClass());
IndicatorUnit addIndicatorUnit = modelElementIndicator.addSpecialIndicator(type, patternMatchingIndicator);
DependenciesHandler.getInstance().setUsageDependencyOn(analysis, pattern);
result.setOk(true);
// $NON-NLS-1$
result.setMessage(DefaultMessagesImpl.getString("PatternUtilities.OK"));
result.setObject(addIndicatorUnit);
return result;
}
use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.
the class CheckAndUpdateAnalysisDependencyTask method checkAndRemoveWrongDependencies.
/**
* check each analysis if it has only one client dependency, if more than one, remove the useless one.
*
* @param list
* @throws CoreException
*/
private void checkAndRemoveWrongDependencies(List<Analysis> analyses) throws CoreException {
for (Analysis analysis : analyses) {
if (analysis != null) {
boolean isAnalysisModified = false;
if (analysis.getContext().getAnalysedElements() == null || analysis.getContext().getAnalysedElements().size() < 1) {
continue;
}
TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analysis.getContext().getAnalysedElements().get(0));
if (tdColumn == null) {
continue;
}
// find the correct db connection from analyzed element
DataManager correctDB = ConnectionHelper.getConnection(tdColumn);
// check if the connection is correct or not
DataManager connection = analysis.getContext().getConnection();
if (connection == null || !correctDB.getName().equals(connection.getName())) {
analysis.getContext().setConnection(correctDB);
isAnalysisModified = true;
}
List<DataProvider> clientDependencyDB = null;
for (Dependency dependency : analysis.getClientDependency()) {
ModelElement supplier = dependency.getSupplier().get(0);
if (supplier instanceof DataProvider) {
if (supplier != null && correctDB.getName().equals(supplier.getName())) {
continue;
} else {
if (clientDependencyDB == null) {
clientDependencyDB = new ArrayList<DataProvider>();
}
clientDependencyDB.add((DataProvider) supplier);
}
}
}
if (clientDependencyDB != null) {
for (DataProvider uselessDB : clientDependencyDB) {
// if the db in client dependency do not equal to the correct db, remove it from both the
// analysis and db connection
removeDependenciesBetweenAnaCon(uselessDB, analysis);
isAnalysisModified = true;
}
}
if (isAnalysisModified) {
EMFSharedResources.getInstance().saveResource(analysis.eResource());
}
}
}
}
Aggregations