Search in sources :

Example 61 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AElementPersistance method save.

/**
 * DOC bZhou Comment method "save".
 *
 * Save a model element and update the related property.
 *
 * @param element
 * @param withProperty
 * @return
 */
public ReturnCode save(ModelElement element, boolean withProperty) {
    ReturnCode rc = new ReturnCode();
    addDependencies(element);
    addResourceContent(element);
    rc.setOk(util.saveResource(element.eResource()));
    if (withProperty) {
        updateProperty(element);
    }
    if (rc.isOk()) {
        // $NON-NLS-1$ //$NON-NLS-2$
        rc.setMessage("save " + element.getName() + " is OK!");
        if (withProperty) {
            notifyResourceChanges();
        }
    } else {
        rc.setMessage(util.getLastErrorMessage());
    }
    return rc;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode)

Example 62 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class AnalysisWriter method removeDependencies.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.writer.AElementPersistance#removeDependencies(org.talend.core.model.properties.Item)
     */
@Override
protected ReturnCode removeDependencies(Item item) {
    ReturnCode rc = new ReturnCode();
    TDQAnalysisItem anaItem = (TDQAnalysisItem) item;
    Analysis analysis = anaItem.getAnalysis();
    List<Property> clintDependency = DependenciesHandler.getInstance().getClintDependency(anaItem.getProperty());
    List<ModelElement> clientDepListByResultList = DependenciesHandler.getInstance().getClientDepListByResult(analysis);
    for (Property currentClient : clintDependency) {
        ModelElement modelElement = PropertyHelper.getModelElement(currentClient);
        if (!clientDepListByResultList.contains(modelElement)) {
            boolean isSuccess = DependenciesHandler.getInstance().removeDependenciesBetweenModel(analysis, modelElement);
            if (isSuccess) {
                try {
                    ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(modelElement.eResource());
                } catch (PersistenceException e) {
                    log.error(e, e);
                    rc.setOk(false);
                    rc.setMessage(e.getMessage());
                }
            } else {
                rc.setOk(false);
                rc.setMessage(// $NON-NLS-1$
                Messages.getString(// $NON-NLS-1$
                "AnalysisWriter.CanNotFindDependencyElement", // $NON-NLS-1$
                analysis.getName(), modelElement.getName()));
            }
        }
    }
    return rc;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) PersistenceException(org.talend.commons.exception.PersistenceException) Property(org.talend.core.model.properties.Property) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 63 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class DataProviderWriter method create.

@Override
public ReturnCode create(ModelElement element, IFile file) {
    ReturnCode rc = new ReturnCode();
    IPath itemPath = file.getFullPath();
    Property property = initProperty(element);
    Item item = property.getItem();
    try {
        ProxyRepositoryFactory.getInstance().create(item, itemPath.removeFirstSegments(3).removeLastSegments(1));
    } catch (PersistenceException e) {
        log.error(e, e);
    }
    return rc;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) ReturnCode(org.talend.utils.sugars.ReturnCode) IPath(org.eclipse.core.runtime.IPath) PersistenceException(org.talend.commons.exception.PersistenceException) Property(org.talend.core.model.properties.Property)

Example 64 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class IndicatorDefinitionWriter 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 Indicator Definition item") {

        @Override
        protected void run() throws LoginException, PersistenceException {
            TDQIndicatorDefinitionItem indicatorItem = (TDQIndicatorDefinitionItem) item;
            IndicatorDefinition indiDefinition = indicatorItem.getIndicatorDefinition();
            String oldName = indiDefinition.getLabel();
            indiDefinition.setLabel(indiDefinition.getName());
            // MOD yyi 2012-02-07 TDQ-4621:Update dependencies when careDependency is true.
            if (careDependency) {
                saveWithDependencies(indicatorItem, indiDefinition);
            } else {
                saveWithoutDependencies(indicatorItem, indiDefinition);
            }
            updateDependencies(indiDefinition);
            checkNameUpdate(oldName, item);
        }
    };
    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;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 65 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class WorkspaceResourceHelper method checkSourceFileSubFolderNodeOpening.

/**
 * DOC xqliu Comment method "checkSourceFileSubFolderNodeOpening".
 *
 * @param node
 * @return
 */
public static ReturnCode checkSourceFileSubFolderNodeOpening(RepositoryNode node) {
    boolean opened = false;
    // $NON-NLS-1$
    String msg = "";
    List<IRepositoryNode> children = node.getChildren();
    for (IRepositoryNode iNode : children) {
        if (iNode instanceof SourceFileRepNode || iNode instanceof JrxmlTempleteRepNode) {
            ReturnCode rc = checkSourceFileNodeOpening((RepositoryNode) iNode);
            if (rc.isOk()) {
                opened = rc.isOk();
                msg += rc.getMessage();
            }
        } else if (iNode instanceof SourceFileSubFolderNode || iNode instanceof JrxmlTempSubFolderNode) {
            ReturnCode rc = checkSourceFileSubFolderNodeOpening((RepositoryNode) iNode);
            if (rc.isOk()) {
                opened = rc.isOk();
                msg += rc.getMessage();
            }
        }
    }
    return new ReturnCode(msg, opened);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) SourceFileSubFolderNode(org.talend.dq.nodes.SourceFileSubFolderNode) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) JrxmlTempleteRepNode(org.talend.dq.nodes.JrxmlTempleteRepNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) JrxmlTempSubFolderNode(org.talend.dq.nodes.JrxmlTempSubFolderNode)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10