use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class FileSystemImportWriter method mergeSystemIndicator.
/**
* Added: (20120808 yyin, TDQ-4189) The system indicators are not read-only because the user may want to write his
* own SQL template. so this task deals with the modified SI from imported one, and merge them with the current
* studio. 1)only when the user select the"Overwrite existing items" on the import wizard(and the modifydate is
* newer than the current studio's SI), the conflict modification in imported SI will overwrite the ones in current
* studio, otherwise, the SI in current studio will keep. 2)If a language does not exist in the system indicator but
* exists in the user modified indicator, then we add it 3)if a language exists in the system indicator but has been
* removed in the user modified indicator, then we keep the system indicator definition. [for Indicator
* matadata(Purpose, Description, Author, Status): 1) will replace old value with new value if new value is not
* blank; 2) will keep old value if new value is blank][for IndicatorDefinitionParameter: 1) will replace the same
* name old parameter with new parameter; 2) will keep the old parameter if new one don't include the same name
* parameter ]
*
* @param record imported modified system indicator
* @param siDef the system indicator in the current studio
*/
protected void mergeSystemIndicator(ItemRecord record, TDQIndicatorDefinitionItem siDefItem) {
// only when the Si is modified, do the save
boolean isModified = false;
// old object
IndicatorDefinition siDef = siDefItem.getIndicatorDefinition();
Property siProp = siDefItem.getProperty();
// new object
IndicatorDefinition indDef = (IndicatorDefinition) record.getElement();
Property indDefProp = record.getProperty();
// get expression list from record
EList<TdExpression> importedExs = indDef.getSqlGenericExpression();
// for each expression:
for (TdExpression importedEx : importedExs) {
// if the modify date ==null, means it is not modified, do nothing
if (importedEx.getModificationDate() == null) {
continue;
}
// find the related template in system indicator(with same language)
TdExpression systemExpression = null;
for (TdExpression ex : siDef.getSqlGenericExpression()) {
if (ex.getLanguage().equals(importedEx.getLanguage())) {
systemExpression = ex;
break;
}
}
// if new, add to SI
if (systemExpression == null) {
IndicatorDefinitionFileHelper.addSqlExpression(siDef, importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
isModified = true;
} else {
// if the expression are different: compare the modify date, make the SI keep the new one
if (replaceExpression(systemExpression, importedEx)) {
IndicatorDefinitionFileHelper.removeSqlExpression(siDef, importedEx.getLanguage());
IndicatorDefinitionFileHelper.addSqlExpression(siDef, importedEx.getLanguage(), importedEx.getBody(), importedEx.getModificationDate());
isModified = true;
}
}
}
// handle the category
IndicatorCategory siDefCategory = IndicatorCategoryHelper.getCategory(siDef);
IndicatorCategory indDefCategory = IndicatorCategoryHelper.getCategory(indDef);
siDefCategory = (IndicatorCategory) EObjectHelper.resolveObject(siDefCategory);
indDefCategory = (IndicatorCategory) EObjectHelper.resolveObject(indDefCategory);
if (!ModelElementHelper.compareUUID(siDefCategory, indDefCategory)) {
// use the imported one
IndicatorCategoryHelper.setCategory(siDef, indDefCategory);
isModified = true;
} else {
// if the uuid is the same, but the label is different
if (siDefCategory != null && indDefCategory != null && !siDefCategory.eIsProxy()) {
if (!indDefCategory.equals(siDefCategory)) {
// especially: "Pattern Finder" is changed by us
if (!indDefCategory.getLabel().equals(RenamePatternFinderFolderTask.PATTERN_FINDER)) {
IndicatorCategoryHelper.setCategory(siDef, indDefCategory);
isModified = true;
}
}
}
}
// for Indicator Metadata
if (siProp != null && indDefProp != null) {
if (!StringUtils.isBlank(indDefProp.getPurpose())) {
siProp.setPurpose(indDefProp.getPurpose());
}
if (!StringUtils.isBlank(indDefProp.getDescription())) {
siProp.setDescription(indDefProp.getDescription());
}
siProp.setAuthor(indDefProp.getAuthor());
siProp.setStatusCode(indDefProp.getStatusCode());
isModified = true;
}
// for judi's jar file information
String jarFilePath = TaggedValueHelper.getJarFilePath(indDef);
if (!StringUtils.isBlank(jarFilePath)) {
TaggedValueHelper.setJarFilePath(jarFilePath, siDef);
isModified = true;
}
String classNameText = TaggedValueHelper.getClassNameText(indDef);
if (!StringUtils.isBlank(classNameText)) {
TaggedValueHelper.setClassNameText(classNameText, siDef);
isModified = true;
}
// for IndicatorDefinintionParameter
EList<IndicatorDefinitionParameter> siParameter = siDef.getIndicatorDefinitionParameter();
EList<IndicatorDefinitionParameter> indDefParameter = indDef.getIndicatorDefinitionParameter();
List<IndicatorDefinitionParameter> tempParameter = new ArrayList<IndicatorDefinitionParameter>();
for (IndicatorDefinitionParameter indDefPara : indDefParameter) {
boolean include = false;
String key = indDefPara.getKey();
for (IndicatorDefinitionParameter siPara : siParameter) {
if (key.equals(siPara.getKey())) {
include = true;
siPara.setValue(indDefPara.getValue());
isModified = true;
}
}
if (!include) {
tempParameter.add(indDefPara);
isModified = true;
}
}
if (isModified && !tempParameter.isEmpty()) {
siParameter.addAll(tempParameter);
}
if (isModified) {
try {
ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().save(siDefItem, false);
} catch (Exception e) {
log.error(e);
}
}
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class DefinitionHandler method updateRegex.
public boolean updateRegex(String dbmsName, String regexpFunction) {
boolean ok = true;
boolean replaced = false;
IndicatorDefinition regexIndDef = this.getIndicatorDefinition(REGULAR_EXPRESSION_MATCHING);
EList<TdExpression> sqlGenericExpression = regexIndDef.getSqlGenericExpression();
for (Expression expression : sqlGenericExpression) {
// MOD qiongli 2011-4-18,bug 16723.data cleansing.
if (DbmsLanguageFactory.compareDbmsLanguage(dbmsName, expression.getLanguage())) {
replaced = replaceBodyWith(expression, regexpFunction);
}
}
if (!replaced) {
// add new expression
String genericSQL = getGenericSQL(dbmsName, regexpFunction);
TdExpression createdExpression = BooleanExpressionHelper.createTdExpression(dbmsName, genericSQL);
sqlGenericExpression.add(createdExpression);
}
return ok;
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class RegularExpressionImpl method basicSetExpression.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetExpression(TdExpression newExpression, NotificationChain msgs) {
TdExpression oldExpression = expression;
expression = newExpression;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, PatternPackage.REGULAR_EXPRESSION__EXPRESSION, oldExpression, newExpression);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class TOPRepositoryService method getPaserRulesFromRules.
public List<Map<String, String>> getPaserRulesFromRules(Object parser) {
if (parser != null && parser instanceof ParserRule) {
List<Map<String, String>> ruleValues = new ArrayList<Map<String, String>>();
for (TdExpression exp : ((ParserRule) parser).getExpression()) {
Map<String, String> pr = new HashMap<String, String>();
// MOD yyi 2011-08-12 TDQ-1698:avoid importing null value
pr.put(RULE_NAME, null == exp.getName() ? StringUtils.EMPTY : exp.getName());
pr.put(RULE_VALUE, null == exp.getBody() ? StringUtils.EMPTY : exp.getBody());
pr.put(RULE_TYPE, null == exp.getLanguage() ? StringUtils.EMPTY : exp.getLanguage().toUpperCase());
ruleValues.add(pr);
}
return ruleValues;
}
return null;
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class ExportFactory method export.
public static void export(File exportFile, IFolder folder, ParserRule... parserRules) {
if (exportFile.isDirectory()) {
for (ParserRule pr : parserRules) {
// $NON-NLS-1$
File file = new File(exportFile, pr.getName() + ".csv");
export(file, folder, pr);
}
}
String fileExtName = getFileExtName(exportFile);
if (FileUtils.isCSV(fileExtName)) {
try {
CSVWriter out = FileUtils.createCSVWriter(exportFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
List<TdExpression> expressions = parserRules[0].getExpression();
ParserRuleToExcelEnum[] values = getParserRuleEnumValues();
String[] temp = new String[values.length];
for (int i = 0; i < expressions.toArray().length + 1; i++) {
for (int j = 0; j < values.length; j++) {
if (i == 0) {
temp[j] = values[j].getLiteral();
} else {
Map<ParserRuleToExcelEnum, String> relatedValueFromParserRule = getRelatedValueFromParserRule(parserRules[0], folder, expressions.get(i - 1));
temp[j] = relatedValueFromParserRule.get(values[j]);
}
}
out.writeNext(temp);
}
out.flush();
out.close();
} catch (FileNotFoundException fe) {
MessageDialogWithToggle.openError(null, DefaultMessagesImpl.getString("ExportFactory.errorOne"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("ExportFactory.notFoundFile"));
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
Aggregations