Search in sources :

Example 26 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class RemoveDuplicatedContextGroupMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    List<?> contexts = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
    }
    Set<String> nameSet = new HashSet<String>();
    Iterator<?> iterator = contexts.listIterator();
    int count = 0;
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof ContextType) {
            ContextType context = (ContextType) obj;
            if (nameSet.contains(context.getName())) {
                iterator.remove();
                count++;
            } else {
                nameSet.add(context.getName());
            }
        }
    }
    if (count > 0) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) HashSet(java.util.HashSet)

Example 27 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class RemoveProjectLibsFolder method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.migration.IProjectMigrationTask#execute(org.talend.core.model.general.Project)
     */
@Override
public ExecutionResult execute(Project project) {
    String libsFolderName = "libs";
    IFolder libsF = null;
    try {
        IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
        libsF = fsProject.getFolder(libsFolderName);
        if (!libsF.exists()) {
            return ExecutionResult.NOTHING_TO_DO;
        }
        final IPath location = libsF.getLocation();
        libsFolder = new File(location.toPortableString());
        ShareProjectLibsMigration migration = new ShareProjectLibsMigration();
        migration.shareLibs(null, new NullProgressMonitor());
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    try {
        libsF.delete(true, new NullProgressMonitor());
    } catch (CoreException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) File(java.io.File) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 28 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class RemoveUnuseQuoteOnTLoop method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    //$NON-NLS-1$
    String[] componentsName = new String[] { "tLoop" };
    IComponentConversion removeQuote = new IComponentConversion() {

        private void removeQuote(ElementParameterType element) {
            if (element != null && element.getValue() != null) {
                String dValue = element.getValue();
                if (dValue.startsWith("\"") && dValue.endsWith("\"")) {
                    //$NON-NLS-1$ //$NON-NLS-2$
                    dValue = dValue.substring(1, dValue.length() - 1);
                    element.setValue(dValue);
                }
            }
        }

        @Override
        public void transform(NodeType node) {
            //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
            List<String> parameters = Arrays.asList(new String[] { "DECLARATION", "CONDITION", "ITERATION" });
            for (String parameter : parameters) {
                removeQuote(ComponentUtilities.getNodeProperty(node, parameter));
            }
        }
    };
    for (String name : componentsName) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(removeQuote));
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 29 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class RenamePasswordParaForLdapMigrationTask method renamePasswordName.

private void renamePasswordName(Item item) {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    ProcessType processType = getProcessType(item);
    for (Object object : processType.getNode()) {
        if (object instanceof NodeType) {
            NodeType currentNode = (NodeType) object;
            if (currentNode.getComponentName().startsWith("tLDAP")) {
                //$NON-NLS-1$
                for (Object o : currentNode.getElementParameter()) {
                    ElementParameterType para = (ElementParameterType) o;
                    if ("PASSWD".equals(para.getName())) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        para.setName("PASS");
                        modified = true;
                        break;
                    }
                }
            }
        }
    }
    if (modified) {
        try {
            factory.save(item, true);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 30 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class RenameSchemaParameterForMSSqlConnectionMigrationTask method renamePasswordName.

private void renamePasswordName(Item item) {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    ProcessType processType = getProcessType(item);
    for (Object object : processType.getNode()) {
        if (object instanceof NodeType) {
            NodeType currentNode = (NodeType) object;
            if (currentNode.getComponentName().startsWith("tMSSqlConnection")) {
                //$NON-NLS-1$
                for (Object o : currentNode.getElementParameter()) {
                    ElementParameterType para = (ElementParameterType) o;
                    if ("DB_SCHEMA".equals(para.getName())) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        para.setName("SCHEMA_DB");
                        modified = true;
                        break;
                    }
                }
            }
        }
    }
    if (modified) {
        try {
            factory.save(item, true);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

PersistenceException (org.talend.commons.exception.PersistenceException)571 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)202 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)151 Property (org.talend.core.model.properties.Property)106 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)106 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)91 Item (org.talend.core.model.properties.Item)90 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)85 ArrayList (java.util.ArrayList)80 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)78 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)78 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)77 Project (org.talend.core.model.general.Project)68 ConnectionItem (org.talend.core.model.properties.ConnectionItem)61 ProcessItem (org.talend.core.model.properties.ProcessItem)60 IPath (org.eclipse.core.runtime.IPath)58 IProject (org.eclipse.core.resources.IProject)54 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)52 CoreException (org.eclipse.core.runtime.CoreException)50 Path (org.eclipse.core.runtime.Path)50