use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class AElementPersistance method createItem.
/**
* DOC bZhou Comment method "createItem".
*
* @param element
* @return
*/
public Item createItem(ModelElement element) {
Item item = null;
// MOD mzhao feature 13114, 2010-05-19 distinguish tdq items.
if (ModelElementIdentifier.isAnalysis(element)) {
item = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
((TDQAnalysisItem) item).setAnalysis((Analysis) element);
} else if (ModelElementIdentifier.isDQRule(element)) {
item = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
((TDQBusinessRuleItem) item).setDqrule((DQRule) element);
} else if (ModelElementIdentifier.isDataProvider(element)) {
if (element instanceof DatabaseConnection) {
item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
((ConnectionItem) item).setConnection((DatabaseConnection) element);
}
((ConnectionItem) item).setConnection((Connection) element);
} else if (ModelElementIdentifier.isMatchRule(element)) {
// this Condition must before the IndicatorDefinition one because MatchRule instance of it.
item = PropertiesFactory.eINSTANCE.createTDQMatchRuleItem();
((TDQMatchRuleItem) item).setMatchRule((MatchRuleDefinition) element);
} else if (ModelElementIdentifier.isID(element)) {
item = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
((TDQIndicatorDefinitionItem) item).setIndicatorDefinition((IndicatorDefinition) element);
} else if (ModelElementIdentifier.isPattern(element)) {
item = PropertiesFactory.eINSTANCE.createTDQPatternItem();
((TDQPatternItem) item).setPattern((Pattern) element);
} else if (ModelElementIdentifier.isReport(element)) {
item = PropertiesFactory.eINSTANCE.createTDQReportItem();
((TDQReportItem) item).setReport((Report) element);
} else {
item = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createTDQItem();
}
ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
itemState.setDeleted(false);
item.setState(itemState);
if (item instanceof TDQItem) {
setTDQItemFileName(element, item);
}
Resource eResource = element.eResource();
if (eResource != null) {
URI uri = eResource.getURI();
if (uri.isPlatform()) {
IPath elementPath = new Path(uri.toPlatformString(true)).removeLastSegments(1);
IPath typedPath = ResourceManager.getRootProject().getFullPath().append(PropertyHelper.getItemTypedPath(item));
IPath statePath = elementPath.makeRelativeTo(typedPath);
itemState.setPath(statePath.toString());
}
}
return item;
}
use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class PatternWriter method save.
@Override
public ReturnCode save(final Item item, final boolean careDependency) {
ReturnCode rc = new ReturnCode();
RepositoryWorkUnit<Object> repositoryWorkUnit = new // $NON-NLS-1$
RepositoryWorkUnit<Object>(// $NON-NLS-1$
"save Analysis item") {
@Override
protected void run() throws LoginException, PersistenceException {
TDQPatternItem patternItem = (TDQPatternItem) item;
Pattern pattern = patternItem.getPattern();
updateDisplayName(patternItem);
// MOD yyi 2012-02-07 TDQ-4621:Update dependencies(connection) when careDependency is true.
if (careDependency) {
saveWithDependencies(patternItem, pattern);
} else {
saveWithoutDependencies(patternItem, pattern);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
try {
repositoryWorkUnit.throwPersistenceExceptionIfAny();
} catch (PersistenceException e) {
log.error(e, e);
rc.setOk(Boolean.FALSE);
rc.setMessage(e.getMessage());
}
return rc;
}
use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class AnalysisWriter method addDependencies.
/*
* (non-Javadoc)
*
* @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
*/
@Override
public void addDependencies(ModelElement element) {
Analysis analysis = (Analysis) element;
List<IndicatorDefinition> udis = AnalysisHelper.getUserDefinedIndicators(analysis);
try {
for (IndicatorDefinition udi : udis) {
if (udi == null) {
continue;
}
InternalEObject iudi = (InternalEObject) udi;
if (!iudi.eIsProxy()) {
DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(udi);
// only do save when the dependency is not reference project node
if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, udi);
if (dependencyReturn.isOk()) {
Property property = PropertyHelper.getProperty(udi);
if (property != null) {
TDQItem udiItem = (TDQItem) property.getItem();
if (udiItem instanceof TDQIndicatorDefinitionItem) {
((TDQIndicatorDefinitionItem) udiItem).setIndicatorDefinition(udi);
} else if (udiItem instanceof TDQBusinessRuleItem) {
((TDQBusinessRuleItem) udiItem).setDqrule((DQRule) udi);
}
}
ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(udi.eResource());
}
}
}
}
List<Pattern> patterns = AnalysisHelper.getPatterns(analysis);
for (Pattern pattern : patterns) {
InternalEObject iptn = (InternalEObject) pattern;
if (!iptn.eIsProxy()) {
DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(pattern);
// only do save when the dependency is not reference project node
if (recursiveFind != null && recursiveFind.getProject().isMainProject()) {
TypedReturnCode<Dependency> dependencyReturn = DependenciesHandler.getInstance().setDependencyOn(analysis, pattern);
if (dependencyReturn.isOk()) {
Property property = PropertyHelper.getProperty(pattern);
if (property != null && property.getItem() instanceof TDQPatternItem) {
TDQPatternItem patternItem = (TDQPatternItem) property.getItem();
patternItem.setPattern(pattern);
}
ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(pattern.eResource());
// EMFUtil.saveSingleResource(pattern.eResource());
}
}
}
}
} catch (PersistenceException e) {
log.error(e, e);
}
}
use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class RespositoryDetailView method createFileDetail.
private boolean createFileDetail(boolean is, IRepositoryViewObject reposViewObj) {
// MOD klliu 2001-02-28 bug 19154
if (reposViewObj.getProperty() != null) {
Item item = reposViewObj.getProperty().getItem();
if (item instanceof ConnectionItem) {
Connection conn = ((ConnectionItem) item).getConnection();
createDataProviderDetail(conn);
is = false;
}
if (item instanceof TDQAnalysisItem) {
Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
createAnaysisDetail(analysis);
is = false;
}
if (item instanceof TDQPatternItem) {
Pattern pattern = ((TDQPatternItem) item).getPattern();
createPatternDetail(pattern);
is = false;
}
if (item instanceof TDQReportItem) {
Report report = ((TDQReportItem) item).getReport();
createReportDetail(report);
is = false;
}
}
return is;
}
use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class FileSystemImportWriter method write.
/*
* After check the conflicts of the imported object, calling this method (from ImportWizard) replace the conflicts
* object in the records if the record is valid; then call the finish to do migrate. OR: merge the conflict system
* indicators if valid.(overwrite)
*
* @see
* org.talend.dataprofiler.core.ui.imex.model.IImexWriter#write(org.talend.dataprofiler.core.ui.imex.model.ItemRecord
* [], org.eclipse.core.runtime.IProgressMonitor)
*/
public void write(ItemRecord[] records, IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
final ItemRecord[] fRecords = records;
final IProgressMonitor fMonitor = monitor;
need2MergeModelElementMap.clear();
allImportItems.clear();
RepositoryWorkUnit<Object> workUnit = new // $NON-NLS-1$
RepositoryWorkUnit<Object>(// $NON-NLS-1$
"Import TDQ Element") {
@Override
protected void run() {
try {
for (ItemRecord record : fRecords) {
if (fMonitor.isCanceled()) {
break;
}
Map<IPath, IPath> toImportMap = mapping(record);
// $NON-NLS-1$
fMonitor.subTask("Importing " + record.getName());
if (record.isValid()) {
boolean isDeleted = false;
// $NON-NLS-1$
log.info("Importing " + record.getFile().getAbsolutePath());
// Delete the conflict node before import.
IRepositoryViewObject object = record.getConflictObject();
boolean isDelete = true;
ModelElement modEle = record.getElement();
if (object != null) {
// is a system indicator definition, (using its UUid to find this SI not label)
if (isIndicatorDefinition(modEle)) {
if (isDQRule(modEle)) {
if (isParserRule(modEle)) {
mergeParserRule(record, (TDQBusinessRuleItem) object.getProperty().getItem());
isDelete = false;
} else if (isWhereRule(modEle)) {
// do nothing here now
}
} else if (isMatchRuleDefinition(modEle)) {
// do nothing here now
} else {
// System Indicator and UDI need merge
TDQIndicatorDefinitionItem indItem = (TDQIndicatorDefinitionItem) object.getProperty().getItem();
mergeSystemIndicator(record, indItem);
// only add it when it is UDIndicatorDefinition
if (record.getElement() instanceof UDIndicatorDefinition) {
need2MergeModelElementMap.put(indItem, record.getElement());
}
isDelete = false;
}
} else if (isPattern(modEle)) {
TDQPatternItem patternItem = (TDQPatternItem) object.getProperty().getItem();
mergePattern(record, patternItem);
need2MergeModelElementMap.put(patternItem, record.getElement());
isDelete = false;
} else {
// remove the dependency of the object
EObjectHelper.removeDependencys(PropertyHelper.getModelElement(object.getProperty()));
isDeleted = true;
// delete the object
ProxyRepositoryFactory.getInstance().deleteObjectPhysical(object);
}
}
if (isDelete) {
updateFiles.clear();
updateFilesCoverd.clear();
for (IPath resPath : toImportMap.keySet()) {
IPath desPath = toImportMap.get(resPath);
ResourceSet resourceSet = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().resourceSet;
synchronized (resourceSet) {
write(resPath, desPath);
allCopiedFiles.add(desPath.toFile());
}
allImportItems.add(desPath);
// TDQ-12180
if (isDeleted) {
AbstractSvnRepositoryService svnReposService = GlobalServiceRegister.getDefault().getSvnRepositoryService(AbstractSvnRepositoryService.class);
if (svnReposService != null) {
svnReposService.addIfImportOverride(desPath);
}
}
}
for (File file : updateFiles) {
update(file, false);
}
for (File file : updateFilesCoverd) {
update(file, true);
}
}
} else {
for (String error : record.getErrors()) {
log.error(error);
}
}
fMonitor.worked(1);
}
finish(fRecords, fMonitor);
} catch (Exception e) {
log.error(e, e);
}
}
};
workUnit.setAvoidUnloadResources(Boolean.TRUE);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnit);
// after above workUnit executed, the imported items will worked, than can do merge/update about UDI and Pattern
RepositoryWorkUnit<Object> workUnitFinish = new // $NON-NLS-1$
RepositoryWorkUnit<Object>(// $NON-NLS-1$
"Finish Import TDQ Element") {
@Override
protected void run() throws LoginException, PersistenceException {
try {
postFinish();
} catch (IOException e) {
log.error(e, e);
}
}
};
workUnitFinish.setAvoidUnloadResources(Boolean.TRUE);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnitFinish);
}
Aggregations