Search in sources :

Example 21 with PersistenceException

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

the class RepositoryPreferenceStore method save.

public void save() throws IOException {
    try {
        factory.setDocumentationStatus(StatusHelper.parse(docStatusList));
        factory.setTechnicalStatus(StatusHelper.parse(techStatusList));
    } catch (PersistenceException e) {
        // TODO Auto-generated catch block
        throw new IOException(e.getMessage());
    }
}
Also used : PersistenceException(org.talend.commons.exception.PersistenceException) IOException(java.io.IOException)

Example 22 with PersistenceException

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

the class ActivateQueryLogging method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    List<String> filterList = Arrays.asList("tELTTeradataMap", "tTeradataConnection", "tTeradataInput", "tTeradataOutput", "tTeradataRow");
    IComponentConversion correctBatchModeForDBComponents = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType queryBand = ComponentUtilities.getNodeProperty(node, "QUERY_BAND");
            ElementParameterType activateQueryLogging = ComponentUtilities.getNodeProperty(node, "ACTIVATE_QUERY_LOGGING");
            if (activateQueryLogging == null) {
                ComponentUtilities.addNodeProperty(node, "ACTIVATE_QUERY_LOGGING", "CHECK");
                if (queryBand != null) {
                    boolean queryBandActived = "true".equalsIgnoreCase(queryBand.getValue());
                    if (queryBandActived) {
                        ComponentUtilities.getNodeProperty(node, "ACTIVATE_QUERY_LOGGING").setValue("true");
                    }
                }
            }
        }
    };
    for (String componentName : filterList) {
        IComponentFilter filter = new NameComponentFilter(componentName);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(correctBatchModeForDBComponents));
        } 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 23 with PersistenceException

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

the class AddHashKeyFromInputConnector4tHashOutput method execute.

@Override
public ExecutionResult execute(Item item) {
    final ProcessType processType = getProcessType(item);
    //$NON-NLS-1$
    String[] compNames = { "tHashOutput" };
    IComponentConversion action = new IComponentConversion() {

        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            //$NON-NLS-1$
            ElementParameterType property = ComponentUtilities.getNodeProperty(node, "HASH_KEY_FROM_INPUT_CONNECTOR");
            if (property == null) {
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "HASH_KEY_FROM_INPUT_CONNECTOR", "CHECK");
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.setNodeValue(node, "HASH_KEY_FROM_INPUT_CONNECTOR", "true");
            }
        }
    };
    for (String name : compNames) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(action));
        } 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 24 with PersistenceException

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

the class AddConnectionVersionForJobsettingMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType.getParameters() != null) {
        EList elementParameter = processType.getParameters().getElementParameter();
        String dbTypeImplicit = "";
        String dbTypeStatsLog = "";
        String dbImplicitVersionRepository = "";
        String dbStasLogVersionRepository = "";
        for (int i = 0; i < elementParameter.size(); i++) {
            final Object object = elementParameter.get(i);
            if (object instanceof ElementParameterTypeImpl) {
                ElementParameterTypeImpl parameterType = (ElementParameterTypeImpl) object;
                String name = parameterType.getName();
                if ("DB_TYPE_IMPLICIT_CONTEXT".equals(name)) {
                    //$NON-NLS-N$
                    dbTypeImplicit = parameterType.getValue();
                }
                if ("DB_TYPE".equals(name)) {
                    //$NON-NLS-N$
                    dbTypeStatsLog = parameterType.getValue();
                }
                if ("DB_VERSION_IMPLICIT_CONTEXT".equals(name)) {
                    //$NON-NLS-N$
                    dbImplicitVersionRepository = parameterType.getValue();
                }
                if ("DB_VERSION".equals(name)) {
                    //$NON-NLS-N$
                    dbStasLogVersionRepository = parameterType.getValue();
                }
            }
        }
        boolean implicitSame = sameDB(dbTypeImplicit, dbImplicitVersionRepository);
        boolean stasLogSame = sameDB(dbTypeStatsLog, dbStasLogVersionRepository);
        if (!implicitSame) {
            if (dbTypeImplicit.toUpperCase().contains("MYSQL")) {
                //$NON-NLS-N$
                //$NON-NLS-N$//$NON-NLS-N$
                setParameterValue(elementParameter, "DB_VERSION_IMPLICIT_CONTEXT", "mysql-connector-java-5.1.0-bin.jar");
            } else if (dbTypeImplicit.toUpperCase().contains("ORACLE")) {
                //$NON-NLS-N$
                //$NON-NLS-N$//$NON-NLS-N$
                setParameterValue(elementParameter, "DB_VERSION_IMPLICIT_CONTEXT", "ojdbc14-10g.jar");
            } else if (dbTypeImplicit.toUpperCase().contains("ACCESS")) {
                //$NON-NLS-N$
                //$NON-NLS-N$//$NON-NLS-N$
                setParameterValue(elementParameter, "DB_VERSION_IMPLICIT_CONTEXT", "ACCESS_2003");
            }
        }
        if (!stasLogSame) {
            if (dbTypeStatsLog.toUpperCase().contains("MYSQL")) {
                //$NON-NLS-N$
                //$NON-NLS-N$//$NON-NLS-N$
                setParameterValue(elementParameter, "DB_VERSION", "mysql-connector-java-5.1.0-bin.jar");
            } else if (dbTypeStatsLog.toUpperCase().contains("ORACLE")) {
                //$NON-NLS-N$
                //$NON-NLS-N$//$NON-NLS-N$
                setParameterValue(elementParameter, "DB_VERSION", "ojdbc14-10g.jar");
            } else if (dbTypeStatsLog.toUpperCase().contains("ACCESS")) {
                //$NON-NLS-N$
                //$NON-NLS-N$//$NON-NLS-N$
                setParameterValue(elementParameter, "DB_VERSION", "ACCESS_2007");
            }
        }
        if (!implicitSame || !stasLogSame) {
            try {
                FACTORY.save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) PersistenceException(org.talend.commons.exception.PersistenceException) ElementParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)

Example 25 with PersistenceException

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

the class RemoveBinFolderMigrationTask method execute.

@Override
public ExecutionResult execute(Project project) {
    XmiResourceManager xmiResourceManager = new XmiResourceManager();
    IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
    IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
    for (ERepositoryObjectType type : getTypes()) {
        IFolder folder = null;
        if (type != null && type.hasFolder()) {
            try {
                IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
                if (!fsProject.getFolder(ERepositoryObjectType.getFolderName(type)).exists()) {
                    continue;
                }
                folder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
                for (IResource current : ResourceUtils.getMembers(folder)) {
                    if ((current instanceof IFolder) && ((IFolder) current).getName().equals("bin")) {
                        for (IResource fileCurrent : ResourceUtils.getMembers((IFolder) current)) {
                            if (fileCurrent instanceof IFile) {
                                if (xmiResourceManager.isPropertyFile((IFile) fileCurrent)) {
                                    Property property = null;
                                    try {
                                        property = xmiResourceManager.loadProperty(fileCurrent);
                                    } catch (RuntimeException e) {
                                        // property will be null
                                        ExceptionHandler.process(e);
                                    }
                                    if (property != null) {
                                        // restore folder if doesn't exist anymore.
                                        Item propertyItem = property.getItem();
                                        propertyItem.getState().setDeleted(true);
                                        EmfHelper.saveResource(propertyItem.eResource());
                                        String oldPath = propertyItem.getState().getPath();
                                        IPath path = new Path(oldPath);
                                        factory.createParentFoldersRecursively(project, type, path, true);
                                        FolderItem folderItem = factory.getFolderItem(project, type, path);
                                        propertyItem.setParent(folderItem);
                                        String name = fileCurrent.getName().replace(".properties", "");
                                        // take all the files starting by the same name
                                        IFolder typeRootFolder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
                                        for (IResource filesToMove : ResourceUtils.getMembers((IFolder) current)) {
                                            if (filesToMove.getName().startsWith(name)) {
                                                IPath originalPath = filesToMove.getFullPath();
                                                IPath finalPath = typeRootFolder.getFullPath().append(path).append(originalPath.lastSegment());
                                                if (fsProject.getWorkspace().getRoot().getFile(finalPath).exists()) {
                                                    // if the file exists in both bin and target directory, delete
                                                    // the one from bin.
                                                    filesToMove.delete(true, new NullProgressMonitor());
                                                } else {
                                                    ResourceUtils.moveResource(filesToMove, finalPath);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        IResource[] binFolder = ResourceUtils.getMembers((IFolder) current);
                        if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
                            try {
                                ((IFolder) current).delete(true, null);
                            } catch (CoreException e) {
                            // not catched, not important if can delete or not
                            }
                        }
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            } catch (CoreException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    // }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject) IRepositoryService(org.talend.repository.model.IRepositoryService) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) FolderItem(org.talend.core.model.properties.FolderItem) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

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