Search in sources :

Example 96 with PersistenceException

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

the class OpenExistVersionProcessWizard method refreshNewJob.

protected boolean refreshNewJob() {
    if (alreadyEditedByUser) {
        return false;
    }
    boolean lastVersion = true;
    StructuredSelection selection = (StructuredSelection) mainPage.getSelection();
    if (selection != null && !selection.isEmpty()) {
        RepositoryNode node = (RepositoryNode) selection.getFirstElement();
        lastVersion = node.getObject().getVersion().equals(originalVersion);
        if (!lastVersion) {
            originalVersion = node.getObject().getVersion();
            String newVersion = mainPage.getNewVersion();
            processObject = node.getObject();
            processObject.getProperty().setVersion(newVersion);
        }
    }
    if (lastVersion) {
        getProperty().setVersion(mainPage.getNewVersion());
    }
    IProxyRepositoryFactory repositoryFactory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    try {
        repositoryFactory.save(getProperty(), this.originaleObjectLabel, this.originalVersion);
        ExpressionPersistance.getInstance().jobNameChanged(originaleObjectLabel, processObject.getLabel());
        ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
        return true;
    } catch (PersistenceException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryNode(org.talend.repository.model.RepositoryNode) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 97 with PersistenceException

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

the class DowngradeParameterHelper method getOldLabelFromId.

/**
     * DOC nrousseau Comment method "getOldLabelFromId".
     * 
     * @param id
     * @param type
     * @return
     */
private static String getOldLabelFromId(String id, ERepositoryObjectType type) {
    final IProxyRepositoryFactory proxyRepositoryFactory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    try {
        ERepositoryObjectType repositoryConnectionsNeeded;
        if (type == ERepositoryObjectType.METADATA_CON_QUERY) {
            repositoryConnectionsNeeded = ERepositoryObjectType.METADATA_CONNECTIONS;
        } else {
            repositoryConnectionsNeeded = ERepositoryObjectType.METADATA;
        }
        List<IRepositoryViewObject> objects = proxyRepositoryFactory.getAll(repositoryConnectionsNeeded);
        ConnectionItem connectionItem = null;
        for (IRepositoryViewObject object : objects) {
            connectionItem = (ConnectionItem) object.getProperty().getItem();
            if (type == ERepositoryObjectType.METADATA_CON_QUERY) {
                QueriesConnection queries = connectionItem.getConnection().getQueries();
                if (queries == null) {
                    continue;
                }
                for (Query query : (List<Query>) queries.getQuery()) {
                    if (query.getId().equals(id)) {
                        return connectionItem.getProperty().getId() + SEPARATOR + query.getLabel();
                    }
                }
            } else if (type == ERepositoryObjectType.METADATA_CON_TABLE) {
                for (MetadataTable table : (Set<MetadataTable>) ConnectionHelper.getTables(connectionItem.getConnection())) {
                    if (table.getId().equals(id)) {
                        return connectionItem.getProperty().getId() + SEPARATOR + table.getLabel();
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        return null;
    }
    return null;
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) ConnectionItem(org.talend.core.model.properties.ConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 98 with PersistenceException

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

the class JavaProcessorUtilities method getNeededModulesForProcess.

public static Set<ModuleNeeded> getNeededModulesForProcess(IProcess process) {
    Set<ModuleNeeded> neededLibraries = new TreeSet<ModuleNeeded>(new Comparator<ModuleNeeded>() {

        @Override
        public int compare(ModuleNeeded m1, ModuleNeeded m2) {
            return m1.toString().compareTo(m2.toString());
        }
    });
    Set<ModuleNeeded> neededModules = LastGenerationInfo.getInstance().getModulesNeededWithSubjobPerJob(process.getId(), process.getVersion());
    neededLibraries.addAll(neededModules);
    if (process == null || !(process instanceof IProcess2)) {
        if (neededLibraries.isEmpty() && process != null) {
            neededLibraries = process.getNeededModules(true);
            if (neededLibraries == null) {
                neededLibraries = new HashSet<ModuleNeeded>();
            // for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeeded()) {
            // neededLibraries.add(moduleNeeded.getModuleName());
            // }
            }
        } else {
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getRunningModules()) {
                neededLibraries.add(moduleNeeded);
            }
        }
        return neededLibraries;
    }
    Property property = ((IProcess2) process).getProperty();
    if (neededLibraries.isEmpty()) {
        neededLibraries = process.getNeededModules(true);
        if (neededLibraries == null) {
            neededLibraries = new HashSet<ModuleNeeded>();
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeeded()) {
                neededLibraries.add(moduleNeeded);
            }
        }
    } else {
        if (property != null && property.getItem() instanceof ProcessItem) {
            neededLibraries.addAll(ModulesNeededProvider.getModulesNeededForProcess((ProcessItem) property.getItem(), process));
        } else {
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getRunningModules()) {
                neededLibraries.add(moduleNeeded);
            }
        }
    }
    if (property != null && GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
        if (camelService.isInstanceofCamel(property.getItem())) {
            // http://jira.talendforge.org/browse/TESB-5887 LiXiaopeng 2012-6-19
            // Synchronize Route resources
            camelService.synchronizeRouteResource((ProcessItem) property.getItem());
            try {
                for (IRepositoryViewObject object : CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().getAll(camelService.getBeansType())) {
                    Item item = object.getProperty().getItem();
                    if (item instanceof RoutineItem) {
                        RoutineItem routine = (RoutineItem) item;
                        for (Object o : routine.getImports()) {
                            IMPORTType type = (IMPORTType) o;
                            ModuleNeeded neededModule = new ModuleNeeded("camel bean dependencies", type.getMODULE(), "camel bean dependencies", true);
                            neededLibraries.add(neededModule);
                        }
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    return neededLibraries;
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) RoutineItem(org.talend.core.model.properties.RoutineItem) Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) TreeSet(java.util.TreeSet) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) Property(org.talend.core.model.properties.Property)

Example 99 with PersistenceException

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

the class JSONWizard method performFinish.

/**
     * This method determine if the 'Finish' button is enable This method is called when 'Finish' button is pressed in
     * the wizard. We will create an operation and run it using wizard as execution context.
     */
@Override
public boolean performFinish() {
    boolean formIsPerformed = false;
    IWizardPage finalPage = getCurrentPage();
    if (finalPage == null) {
        finalPage = propertiesWizardPage;
    }
    // deleteTemFile();
    if (connection.isInputModel()) {
        if (finalPage instanceof JSONFileWizardPage) {
            int step = ((JSONFileWizardPage) finalPage).step;
            if (step == 2) {
                formIsPerformed = finalPage.isPageComplete();
                if (formIsPerformed) {
                    List schemas = connection.getSchema();
                    Set tables = ConnectionHelper.getTables(connection);
                    if (!schemas.isEmpty() && !tables.isEmpty()) {
                        JSONXPathLoopDescriptor currentSchema = (JSONXPathLoopDescriptor) schemas.get(0);
                        MetadataTable currentTable = (MetadataTable) tables.toArray(new MetadataTable[0])[0];
                        if (!currentSchema.getAbsoluteXPathQuery().equals(oldAbstractQueryPath)) {
                            resetMetadata(currentSchema.getSchemaTargets(), true);
                        } else {
                            resetMetadata(currentSchema.getSchemaTargets(), false);
                        }
                    }
                }
            } else {
                formIsPerformed = finalPage.isPageComplete();
            }
        } else {
            formIsPerformed = finalPage.isPageComplete();
        }
    } else {
        formIsPerformed = finalPage.isPageComplete();
    }
    if (formIsPerformed) {
        final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        final IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (creation) {
                            String nextId = factory.getNextId();
                            connectionProperty.setId(nextId);
                            // changed by hqzhang for TDI-19527, label=displayName
                            connectionProperty.setLabel(connectionProperty.getDisplayName());
                            final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                                @Override
                                protected void run() throws LoginException, PersistenceException {
                                    factory.create(connectionItem, propertiesWizardPage.getDestinationPath());
                                }
                            };
                            workUnit.setAvoidUnloadResources(true);
                            factory.executeRepositoryWorkUnit(workUnit);
                        } else {
                            // changed by hqzhang for TDI-19527, label=displayName
                            connectionProperty.setLabel(connectionProperty.getDisplayName());
                            // update schemas
                            Map<String, SchemaTarget> schemaTargetMap = new HashMap<String, SchemaTarget>();
                            EList<JSONXPathLoopDescriptor> schema = connection.getSchema();
                            if (schema != null && schema.size() > 0) {
                                JSONXPathLoopDescriptor jsonXPathLoopDescriptor = schema.get(0);
                                if (jsonXPathLoopDescriptor != null) {
                                    EList<SchemaTarget> schemaTargets = jsonXPathLoopDescriptor.getSchemaTargets();
                                    if (schemaTargets != null && schemaTargets.size() > 0) {
                                        for (SchemaTarget schemaTarget : schemaTargets) {
                                            schemaTargetMap.put(schemaTarget.getTagName(), schemaTarget);
                                        }
                                    }
                                }
                            }
                            Map<String, MetadataColumn> columnsMap = new HashMap<String, MetadataColumn>();
                            MetadataTable[] tables = ConnectionHelper.getTables(connectionItem.getConnection()).toArray(new MetadataTable[0]);
                            for (MetadataTable table : tables) {
                                EList<MetadataColumn> columns = table.getColumns();
                                Iterator<MetadataColumn> columnsIter = columns.iterator();
                                while (columnsIter.hasNext()) {
                                    MetadataColumn column = columnsIter.next();
                                    if (connection.isInputModel()) {
                                        if (schemaTargetMap.get(column.getLabel()) == null) {
                                            columnsIter.remove();
                                        } else {
                                            columnsMap.put(column.getLabel(), column);
                                        }
                                    } else {
                                        columnsMap.put(column.getLabel(), column);
                                    }
                                }
                            }
                            boolean hasAddedColumns = false;
                            Iterator<Entry<String, SchemaTarget>> schemaTargetIter = schemaTargetMap.entrySet().iterator();
                            while (schemaTargetIter.hasNext()) {
                                Map.Entry<String, SchemaTarget> entry = schemaTargetIter.next();
                                String key = entry.getKey();
                                if (columnsMap.get(key) == null) {
                                    hasAddedColumns = true;
                                    break;
                                }
                            }
                            if (hasAddedColumns) {
                                MessageDialog.openInformation(getShell(), "Detect new columns", "There are some new fields to extract, guess your schema manually if you want to apply the update.");
                            }
                            // update
                            RepositoryUpdateManager.updateFileConnection(connectionItem);
                            refreshInFinish(propertiesWizardPage.isNameModifiedByUser());
                            final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                                @Override
                                protected void run() throws LoginException, PersistenceException {
                                    factory.save(connectionItem);
                                }
                            };
                            workUnit.setAvoidUnloadResources(true);
                            factory.executeRepositoryWorkUnit(workUnit);
                            closeLockStrategy();
                        }
                        final RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>("", this) {

                            @Override
                            protected void run() throws LoginException, PersistenceException {
                                ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                            }
                        };
                        workUnit.setAvoidUnloadResources(true);
                        factory.executeRepositoryWorkUnit(workUnit);
                    }
                });
            }
        };
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    // the update the project files need to be done in the workspace runnable to avoid all
                    // notification
                    // of changes before the end of the modifications.
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorDialog(null).run(true, true, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        //
        }
        return true;
    } else {
        return false;
    }
}
Also used : Set(java.util.Set) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) Entry(java.util.Map.Entry) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) SchemaTarget(org.talend.repository.model.json.SchemaTarget) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EList(org.eclipse.emf.common.util.EList) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IWizardPage(org.eclipse.jface.wizard.IWizardPage) Map(java.util.Map) HashMap(java.util.HashMap)

Example 100 with PersistenceException

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

the class ChangeValue4BonitaComponents method execute.

@Override
public ExecutionResult execute(Item item) {
    final ProcessType processType = getProcessType(item);
    String[] compNames = { "tBonitaDeploy", "tBonitaInstantiateProcess" };
    IComponentConversion conversion = new IComponentConversion() {

        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            ElementParameterType parameter = ComponentUtilities.getNodeProperty(node, "DB_VERSION");
            if (parameter != null) {
                String value = parameter.getValue();
                if (value == null) {
                    return;
                }
                String oldValue523Prefix = "bonita-client-5.2.3.jar";
                String oldValue531Prefix = "bonita-client-5.3.jar";
                if (value.startsWith(oldValue523Prefix)) {
                    String newValue = "antlr-2.7.6.jar;asm-1.5.3.jar;asm-3.1.jar;asm-attrs-1.5.3.jar;cglib-nodep-2.1_3.jar;commons-collections-2.1.1.jar;commons-logging-1.0.4.jar;dom4j-1.6.1.jar;ehcache-1.2.3.jar;groovy-all-1.7.0.jar;h2-1.2.132.jar;hibernate-3.2.6.ga.jar;jline-0.9.94.jar;jta-1.1.jar;novaBpmIdentity-1.0.jar;novaBpmPerf-1.0.jar;novaBpmUtil-1.0.jar";
                    ComponentUtilities.setNodeValue(node, "DB_VERSION", newValue);
                } else if (value.startsWith(oldValue531Prefix)) {
                    String newValue = "novaBpmIdentity-1.0.jar;novaBpmPerf-1.0.jar;novaBpmUtil-1.0.jar;hibernate-core-3.5.6-Final.jar;commons-collections-3.1.jar;ehcache-core-2.2.0.jar;hibernate-commons-annotations-3.2.0.Final.jar;hibernate-search-3.2.1.Final.jar;javassist-3.8.0.GA.jar;lucene-core-2.9.3.jar;slf4j-api-1.6.1.jar;dom4j-1.6.1.jar;h2-1.2.132.jar;jta-1.1.jar;antlr-2.7.6.jar;commons-logging-1.1.1.jar";
                    ComponentUtilities.setNodeValue(node, "DB_VERSION", newValue);
                }
            }
        }
    };
    for (String name : compNames) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(conversion));
        } catch (PersistenceException e) {
            // TODO Auto-generated catch block
            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)

Aggregations

PersistenceException (org.talend.commons.exception.PersistenceException)367 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)113 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)112 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)104 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)89 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)84 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)77 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)76 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)75 Item (org.talend.core.model.properties.Item)59 ArrayList (java.util.ArrayList)58 ProcessItem (org.talend.core.model.properties.ProcessItem)54 Property (org.talend.core.model.properties.Property)51 ConnectionItem (org.talend.core.model.properties.ConnectionItem)47 Project (org.talend.core.model.general.Project)40 CoreException (org.eclipse.core.runtime.CoreException)37 List (java.util.List)36 IElementParameter (org.talend.core.model.process.IElementParameter)35 IProject (org.eclipse.core.resources.IProject)32 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)32