use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class FunctionalDependencyAnalysisDetailsPage method saveAnalysis.
/*
* (non-Javadoc)
*
* @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#saveAnalysis()
*/
@Override
protected void saveAnalysis() throws DataprofilerCoreException {
analysisHandler.changeDefaultRowLoaded(rowLoadedText.getText());
analysisHandler.changeSampleDataShowWay(sampleDataShowWayCombo.getText());
for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
domain.setName(getCurrentModelElement().getName());
}
IRepositoryViewObject reposObject = null;
getAnalysisHandler().clearAnalysis();
List<RepositoryNode> columnListAANode = anaColumnCompareViewer.getColumnListA();
List<RepositoryNode> columnListBBNode = anaColumnCompareViewer.getColumnListB();
AnalysisBuilder anaBuilder = new AnalysisBuilder();
anaBuilder.setAnalysis(getCurrentModelElement());
Connection tdDataProvider = null;
for (int i = 0; i < columnListAANode.size(); i++) {
if (columnListBBNode.size() > i) {
ColumnDependencyIndicator indicator = ColumnsetFactory.eINSTANCE.createColumnDependencyIndicator();
TdColumn columnA = (TdColumn) ((MetadataColumnRepositoryObject) columnListAANode.get(i).getObject()).getTdColumn();
TdColumn columnB = (TdColumn) ((MetadataColumnRepositoryObject) columnListBBNode.get(i).getObject()).getTdColumn();
indicator.setColumnA(columnA);
indicator.setColumnB(columnB);
indicator.setIndicatorDefinition(DefinitionHandler.getInstance().getFDRuleDefaultIndicatorDefinition());
getCurrentModelElement().getResults().getIndicators().add(indicator);
anaBuilder.addElementToAnalyze(columnA, indicator);
// ADD this line qiongli 2010-6-8
anaBuilder.addElementToAnalyze(columnB, indicator);
}
}
if (columnListAANode.size() > 0) {
reposObject = columnListAANode.get(0).getObject();
tdDataProvider = ((ConnectionItem) reposObject.getProperty().getItem()).getConnection();
// MOD qiongli bug 14437:Add dependency
getCurrentModelElement().getContext().setConnection(tdDataProvider);
TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(getCurrentModelElement(), tdDataProvider);
if (!rc.isOk()) {
// $NON-NLS-1$
log.info("fail to save dependency analysis:" + getCurrentModelElement().getFileName());
}
} else {
getCurrentModelElement().getContext().setConnection(null);
}
// save the number of connections per analysis
this.saveNumberOfConnectionsPerAnalysis();
// 2011.1.12 MOD by zhsne to unify anlysis and connection id when saving.
this.nameText.setText(getCurrentModelElement().getName());
// MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(getCurrentRepNode().getObject().getProperty().getItem(), true);
// MOD yyi 2012-02-03 TDQ-3602:Avoid to rewriting all analyzes after saving, no reason to update all analyzes
// which is depended in the referred connection.
// Extract saving log function.
// @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#logSaved(ReturnCode)
logSaved(saved);
anaColumnCompareViewer.setDirty(false);
dataFilterComp.setDirty(false);
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class SoftwareSystemManagerTest method testUpdateSoftwareSystem.
/**
* Test method for
* {@link org.talend.cwm.management.api.SoftwareSystemManager#updateSoftwareSystem(java.sql.Connection, orgomg.cwm.foundation.softwaredeployment.SoftwareSystem)}
* .
*/
@Test
public void testUpdateSoftwareSystem() {
SoftwareSystemManager softwareSystemManger = SoftwareSystemManager.getInstance();
PowerMockito.mockStatic(EMFSharedResources.class);
EMFSharedResources emfSharedResourceMock = mock(EMFSharedResources.class);
when(EMFSharedResources.getInstance()).thenReturn(emfSharedResourceMock).thenReturn(emfSharedResourceMock);
Resource softwareSysResource = mock(Resource.class);
when(emfSharedResourceMock.getSoftwareDeploymentResource()).thenReturn(softwareSysResource);
EList<EObject> existedSystems = new BasicEList<EObject>();
when(softwareSysResource.getContents()).thenReturn(existedSystems);
when(emfSharedResourceMock.saveResource(softwareSysResource)).thenReturn(Boolean.TRUE);
try {
softwareSystemManger.updateSoftwareSystem(null);
Connection mockConnection = mock(Connection.class);
DatabaseMetaData mockDBMetaData = mock(DatabaseMetaData.class);
// Mocking Static Class
PowerMockito.mockStatic(DriverManager.class);
// $NON-NLS-1$
String sql = "jdbc:mysql://localhost:3306/tbi";
when(DriverManager.getConnection(sql)).thenReturn(mockConnection);
when(mockConnection.getMetaData()).thenReturn(mockDBMetaData);
// Mock database product name.
// $NON-NLS-1$
String mysqlDB = "MYSQL";
when(mockDBMetaData.getDatabaseProductName()).thenReturn(mysqlDB);
// Mock database product version
// $NON-NLS-1$
String version = "5.5";
when(mockDBMetaData.getDatabaseProductVersion()).thenReturn(version);
when(mockDBMetaData.getDatabaseMinorVersion()).thenReturn(5);
when(mockDBMetaData.getDatabaseMajorVersion()).thenReturn(5);
DatabaseConnection dbConn = ConnectionPackage.eINSTANCE.getConnectionFactory().createDatabaseConnection();
TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_NAME, mysqlDB);
TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_VERSION, version);
PowerMockito.mockStatic(ConvertionHelper.class);
// $NON-NLS-1$
when(ConvertionHelper.convert(dbConn, false, "")).thenReturn(null);
PowerMockito.mockStatic(MetadataFillFactory.class);
MetadataFillFactory metadataFillFactory = mock(MetadataFillFactory.class);
when(MetadataFillFactory.getDBInstance()).thenReturn(metadataFillFactory);
TypedReturnCode<java.sql.Connection> returnCode = new TypedReturnCode<Connection>(Boolean.TRUE);
returnCode.setObject(mockConnection);
when(metadataFillFactory.createConnection(null)).thenReturn(returnCode);
softwareSystemManger.updateSoftwareSystem(dbConn);
Assert.assertTrue(existedSystems.size() > 0);
SoftwareSystem newSoftwareSys = (SoftwareSystem) existedSystems.get(0);
Assert.assertEquals(mysqlDB, newSoftwareSys.getSubtype());
Assert.assertEquals(version, newSoftwareSys.getVersion());
} catch (SQLException e) {
Assert.fail(e.getMessage());
}
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class FileSystemImportWriterTest method testMergePattern.
/**
* Test method for
* {@link org.talend.dataprofiler.core.ui.imex.model.FileSystemImportWriter#mergePattern(org.talend.dataprofiler.core.ui.imex.model.ItemRecord, org.talend.dataquality.domain.pattern.Pattern)}
* .
*
* @throws MalformedURLException
*/
@Test
public void testMergePattern() throws MalformedURLException {
// import object
ItemRecord importItem = mock(ItemRecord.class);
Pattern importPattern = mock(Pattern.class);
when(importItem.getElement()).thenReturn(importPattern);
// old object
TDQPatternItem oldPatternItem = mock(TDQPatternItem.class);
Pattern oldPattern = mock(Pattern.class);
when(oldPatternItem.getPattern()).thenReturn(oldPattern);
// for imported pattern's expression
InternalEObject eo = mock(InternalEObject.class);
EList<PatternComponent> importComponents = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
RegularExpression re = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td.setBody("sql body");
// $NON-NLS-1$
td.setLanguage("SQL");
// $NON-NLS-1$
td.setModificationDate("20130101");
re.setExpression(td);
importComponents.add(re);
RegularExpression re3 = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td3 = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td3.setBody("imported body");
// $NON-NLS-1$
td3.setLanguage("MYSQL");
// $NON-NLS-1$
td3.setModificationDate("20130101");
re3.setExpression(td3);
importComponents.add(re3);
RegularExpression re4 = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td4 = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td4.setBody("imported 4 body");
// $NON-NLS-1$
td4.setLanguage("Default");
td4.setModificationDate(null);
re4.setExpression(td4);
importComponents.add(re4);
when(importPattern.getComponents()).thenReturn(importComponents);
// for imported pattern's supplierDependencies
Analysis analysis = mock(Analysis.class);
Dependency dependency = mock(Dependency.class);
when(dependency.getKind()).thenReturn(DependenciesHandler.USAGE);
EList<ModelElement> analysisList = new BasicEList<ModelElement>();
analysisList.add(analysis);
when(dependency.getClient()).thenReturn(analysisList);
when(analysis.eIsProxy()).thenReturn(false);
// $NON-NLS-1$
File file = new File("C://Users//msjian//Desktop//myusetest//AA//TDQ_Data Profiling//Analyses//k_0.1.ana");
org.eclipse.emf.common.util.URI uri = URI.createFileURI(file.toURL().getPath().substring(1));
Resource resource = mock(Resource.class);
when(analysis.eResource()).thenReturn(resource);
when(resource.getURI()).thenReturn(uri);
PowerMockito.mockStatic(ResourceManager.class);
IProject pro = mock(IProject.class);
when(ResourceManager.getRootProject()).thenReturn(pro);
// $NON-NLS-1$
when(pro.getLocation()).thenReturn(new Path("D:\\worspace\\workspace_TDQEE_5.3\\A"));
EList<ModelElement> patternlist = mock(EObjectContainmentEList.class);
patternlist.add(importPattern);
when(dependency.getSupplier()).thenReturn(patternlist);
EList<Dependency> supplierDependencies_old = new BasicEList<Dependency>();
when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_old);
Assert.assertEquals(0, oldPattern.getSupplierDependency().size());
EList<Dependency> supplierDependencies_import = new BasicEList<Dependency>();
supplierDependencies_import.add(dependency);
when(importPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
Assert.assertEquals(1, importPattern.getSupplierDependency().size());
PowerMockito.mockStatic(DependenciesHandler.class);
DependenciesHandler instance = mock(DependenciesHandler.class);
when(DependenciesHandler.getInstance()).thenReturn(instance);
TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
rc.setObject(dependency);
when(instance.setUsageDependencyOn(analysis, oldPattern)).thenReturn(rc);
when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
// for system pattern's expression
EList<PatternComponent> components = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
RegularExpression re2 = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td2 = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td2.setBody("system 2 body");
// $NON-NLS-1$
td2.setLanguage("MYSQL");
// $NON-NLS-1$
td2.setModificationDate("20120101");
re2.setExpression(td2);
components.add(re2);
// for re5: should be replace by re4
RegularExpression re5 = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td5 = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td5.setBody("system 5 body");
// $NON-NLS-1$
td5.setLanguage("Default");
td5.setModificationDate(null);
re5.setExpression(td5);
components.add(re5);
when(oldPattern.getComponents()).thenReturn(components);
ElementWriterFactory ewFactory = mock(ElementWriterFactory.class);
PatternWriter pw = mock(PatternWriter.class);
when(pw.save(oldPatternItem, true)).thenReturn(null);
// $NON-NLS-1$
stub(method(ElementWriterFactory.class, "getInstance")).toReturn(ewFactory);
when(ewFactory.createPatternWriter()).thenReturn(pw);
writer.mergePattern(importItem, oldPatternItem);
for (PatternComponent component : components) {
TdExpression ex = ((RegularExpression) component).getExpression();
if (ex.getLanguage().equals("SQL")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("sql body", ex.getBody());
} else if (ex.getLanguage().equals("MYSQL")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("imported body", ex.getBody());
} else if (ex.getLanguage().equals("Default")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("imported 4 body", ex.getBody());
}
}
Assert.assertNotNull(oldPattern.getSupplierDependency());
Assert.assertEquals(1, oldPattern.getSupplierDependency().size());
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class AnalysisColumnTreeViewer method sortIndicatorUnits.
/**
* DOC yyi Sort indicators.
*
* @param units
* @param targetUnit
* @param step
* @return
*/
private TypedReturnCode<IndicatorUnit[]> sortIndicatorUnits(IndicatorUnit[] units, IndicatorUnit targetUnit, int step, List<IndicatorUnit> indicatorUnitList) {
TypedReturnCode<IndicatorUnit[]> code = new TypedReturnCode<IndicatorUnit[]>();
int index = -1;
for (int i = 0; i < units.length; i++) {
if (targetUnit.getIndicator() == units[i].getIndicator()) {
index = i;
break;
} else if (null != units[i].getChildren()) {
TypedReturnCode<IndicatorUnit[]> code2 = sortIndicatorUnits(units[i].getChildren(), targetUnit, step, indicatorUnitList);
if (null != code2.getObject()) {
units[i].setChildren(code2.getObject());
code.setOk(true);
break;
}
}
}
int changeIndex = index + step;
if (-1 != index && changeIndex > -1 && changeIndex < units.length) {
IndicatorUnit tmpUnit = units[changeIndex];
// when the changed one is the selected one too, get next one
while (indicatorUnitList.contains(tmpUnit)) {
tmpUnit = units[++changeIndex];
}
units[changeIndex] = units[index];
units[index] = tmpUnit;
// after the data changed successfully remove it from the selected list
indicatorUnitList.remove(targetUnit);
// $NON-NLS-1$
code.setReturnCode("", true, units);
}
return code;
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class ExecuteMatchRuleHandler method execute.
public TypedReturnCode<MatchGroupResultConsumer> execute(Map<MetadataColumn, String> columnMap, RecordMatchingIndicator recordMatchingIndicator, List<Object[]> matchRows, BlockKeyIndicator blockKeyIndicator, MatchGroupResultConsumer matchResultConsumer) {
TypedReturnCode<MatchGroupResultConsumer> returnCode = new TypedReturnCode<MatchGroupResultConsumer>(false);
returnCode.setObject(matchResultConsumer);
// By default for analysis, the applied blocking key will be the key
// from key generation definition. This
// will be refined when there is a need to define the applied blocking
// key manually by user later.
AnalysisRecordGroupingUtils.createAppliedBlockKeyByGenKey(recordMatchingIndicator);
ReturnCode computeMatchGroupReturnCode = null;
// Blocking key specified.
computeMatchGroupReturnCode = computeMatchGroupWithBlockKey(recordMatchingIndicator, blockKeyIndicator, columnMap, matchResultConsumer, matchRows);
returnCode.setOk(computeMatchGroupReturnCode.isOk());
returnCode.setMessage(computeMatchGroupReturnCode.getMessage());
return returnCode;
}
Aggregations