use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class ImportFactory method createAndStoreUDI.
/**
* DOC xqliu Comment method "createAndStoreUDI".
*
* @param parameters
* @param selectionFolder
*/
private static TypedReturnCode<Object> createAndStoreUDI(UDIParameters parameters, IFolder selectionFolder) {
UDIndicatorDefinition indDef = UDIHelper.createUDI(parameters.name, parameters.auther, parameters.description, parameters.purpose, parameters.status, parameters.category, parameters.javaClassName, parameters.javaJarPath);
for (String key : parameters.regex.keySet()) {
TdExpression expression = BooleanExpressionHelper.createTdExpression(key, parameters.regex.get(key));
indDef.getSqlGenericExpression().add(expression);
}
boolean validStatus = UDIHelper.isUDIValid(indDef);
TaggedValueHelper.setValidStatus(validStatus, indDef);
Map<String, String> paraMap = parameters.getParaMap();
if (!paraMap.isEmpty()) {
for (String key : paraMap.keySet()) {
String value = paraMap.get(key);
IndicatorDefinitionParameter idPara = DefinitionFactory.eINSTANCE.createIndicatorDefinitionParameter();
idPara.setKey(key);
idPara.setValue(value);
indDef.getIndicatorDefinitionParameter().add(idPara);
}
}
try {
// $NON-NLS-1$
String[] folderNames = parameters.relativePath.split("/");
for (String folderName : folderNames) {
IFolder folder = selectionFolder.getFolder(folderName);
if (!folder.exists()) {
folder.create(false, true, null);
}
selectionFolder = folder;
}
} catch (CoreException e) {
log.error(e, e);
}
indDef = UDIUtils.createDefaultDrillDownList(indDef);
return ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().create(indDef, selectionFolder);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UpdateModeIndicatorDefinitionForAS400Task method doExecute.
@Override
protected boolean doExecute() throws Exception {
boolean result = true;
try {
IndicatorDefinition indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(MODE_INDICATOR_LABEL);
URI uriItem = indicatorDefinition.eResource().getURI();
File fileItem = null;
if (uriItem.isPlatform()) {
fileItem = WorkspaceUtils.ifileToFile(getIFile(indicatorDefinition));
} else {
fileItem = new File(uriItem.toFileString());
}
File fileProp = WorkspaceUtils.ifileToFile(PropertyHelper.getPropertyFile(indicatorDefinition));
Property property = PropertyHelper.getProperty(indicatorDefinition);
Item item = property.getItem();
if (indicatorDefinition != null) {
EList<TdExpression> sqlGenericExpression = indicatorDefinition.getSqlGenericExpression();
boolean addAS400Expression = true;
for (TdExpression expression : sqlGenericExpression) {
if (SupportDBUrlType.AS400DEFAULTURL.getLanguage().equals(expression.getLanguage())) {
addAS400Expression = false;
break;
}
}
if (addAS400Expression) {
TDQIndicatorDefinitionItem indDefItem = (TDQIndicatorDefinitionItem) item;
Resource itemResource = getResource(fileItem);
IndicatorDefinition indDef = null;
for (EObject object : itemResource.getContents()) {
if (object instanceof IndicatorDefinition) {
indDef = (IndicatorDefinition) object;
IndicatorDefinitionFileHelper.addSqlExpression(indDef, SupportDBUrlType.AS400DEFAULTURL.getLanguage(), BODY_MODE_AS400);
String relationPropPath = ReponsitoryContextBridge.getRootProject().getFullPath().append(new Path(fileProp.getPath()).makeRelativeTo(this.getWorkspacePath())).toOSString();
MetadataHelper.setPropertyPath(relationPropPath, indDef);
indDefItem.setIndicatorDefinition(indDef);
}
}
EMFUtil.saveResource(itemResource);
Resource propResource = getResource(fileProp);
Property newProperty = (Property) EcoreUtil.getObjectByType(propResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
newProperty.setAuthor(property.getAuthor());
newProperty.setLabel(indDefItem.getIndicatorDefinition().getName());
newProperty.setItem(item);
item.setProperty(newProperty);
propResource.getContents().clear();
propResource.getContents().add(newProperty);
propResource.getContents().add(item);
propResource.getContents().add(item.getState());
EMFUtil.saveResource(propResource);
}
}
} catch (Exception e) {
result = false;
e.printStackTrace();
}
return result;
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UpdateOracleAverageLengthTask method setNewExpression.
private void setNewExpression(IndicatorDefinition indDefinition, String newExpOracle) {
if (indDefinition == null) {
return;
}
EList<TdExpression> sqlExpressions = indDefinition.getSqlGenericExpression();
String languge = null;
for (TdExpression tdExp : sqlExpressions) {
languge = tdExp.getLanguage();
if (DbmsLanguageFactory.isOracle(languge)) {
tdExp.setBody(newExpOracle);
}
}
IndicatorDefinitionFileHelper.save(indDefinition);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UpdateRegularExpressionMatchingMysqlExpressionTask method doExecute.
/*
* (non-Javadoc)
*
* @see org.talend.dataprofiler.core.migration.AMigrationTask#doExecute()
*/
@Override
protected boolean doExecute() throws Exception {
IndicatorDefinition indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(REGULAR_EXPRESSION_MATCHING_LABEL);
if (indicatorDefinition != null) {
EList<TdExpression> sqlGenericExpression = indicatorDefinition.getSqlGenericExpression();
if (sqlGenericExpression != null && sqlGenericExpression.size() > 0) {
boolean notFoundMysqlExpression = true;
for (TdExpression expression : sqlGenericExpression) {
if (expression != null && SupportDBUrlType.MYSQLDEFAULTURL.getLanguage().equals(expression.getLanguage())) {
notFoundMysqlExpression = false;
expression.setBody(MYSQL_EXPRESSION);
break;
}
}
if (notFoundMysqlExpression) {
TdExpression newExpression = BooleanExpressionHelper.createTdExpression(SupportDBUrlType.MYSQLDEFAULTURL.getLanguage(), MYSQL_EXPRESSION);
sqlGenericExpression.add(newExpression);
} else {
// mysql expression have exist, so needn't to create a new mysql expression
}
}
}
return true;
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UpdateLowerUpperQuartileForDB2Task method updateSqlForDB2.
private boolean updateSqlForDB2(String indicatorName, String sqlExpression) {
IndicatorDefinition indiDefinition = IndicatorDefinitionFileHelper.getSystemIndicatorByName(indicatorName);
if (indiDefinition != null && IndicatorDefinitionFileHelper.removeSqlExpression(indiDefinition, DB2)) {
List<TdExpression> remainExpLs = new ArrayList<TdExpression>();
remainExpLs.addAll(indiDefinition.getSqlGenericExpression());
indiDefinition.getSqlGenericExpression().clear();
IndicatorDefinitionFileHelper.addSqlExpression(indiDefinition, DB2, sqlExpression);
indiDefinition.getSqlGenericExpression().addAll(remainExpLs);
return IndicatorDefinitionFileHelper.save(indiDefinition);
}
return true;
}
Aggregations