Search in sources :

Example 61 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class ChangeReturnTypeOfServerAliveResult method convertItem.

private boolean convertItem(Item item, ProcessType processType) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    ECodeLanguage language = getProject().getLanguage();
    EList node = processType.getNode();
    EList connections = processType.getConnection();
    for (Object n : node) {
        NodeType type = (NodeType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (language.equals(ECodeLanguage.JAVA)) {
                if (elemType.getValue() != null && elemType.getValue().contains("tServerAlive")) {
                    //$NON-NLS-1$
                    Matcher match = PATTERN_GET.matcher(elemType.getValue());
                    String replace = getReplaceValue(match);
                    if (replace != null && replace.length() > 0) {
                        elemType.setValue(replace);
                        modified = true;
                    }
                }
            }
            // for table
            EList elemValue = elemType.getElementValue();
            for (Object elemV : elemValue) {
                ElementValueType elemVal = (ElementValueType) elemV;
                if (language.equals(ECodeLanguage.JAVA)) {
                    if (elemVal.getValue() != null && elemVal.getValue().contains("tServerAlive")) {
                        //$NON-NLS-1$
                        Matcher match = PATTERN_GET.matcher(elemVal.getValue());
                        String replace = getReplaceValue(match);
                        if (replace != null && replace.length() > 0) {
                            elemVal.setValue(replace);
                            modified = true;
                        }
                    }
                }
            }
        }
    }
    // the links
    for (Object n : connections) {
        ConnectionType type = (ConnectionType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (language.equals(ECodeLanguage.JAVA)) {
                if (elemType.getValue() != null && elemType.getValue().contains("tServerAlive")) {
                    //$NON-NLS-1$
                    Matcher match = PATTERN_GET.matcher(elemType.getValue());
                    String replace = getReplaceValue(match);
                    if (replace != null && replace.length() > 0) {
                        elemType.setValue(replace);
                        modified = true;
                    }
                }
            }
        }
    }
    if (modified) {
        factory.save(item, true);
    }
    return modified;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EList(org.eclipse.emf.common.util.EList) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) Matcher(java.util.regex.Matcher) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 62 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class ChangeUniqRowLinksMigrationTask method replaceConnections.

public boolean replaceConnections(Item item) throws PersistenceException {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return false;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean replaceDone = false;
    boolean modified = false;
    for (Object o : processType.getConnection()) {
        ConnectionType currentConnection = (ConnectionType) o;
        // output of the tUniqRow, set the connector name to UNIQUE.
        if (((currentConnection.getConnectorName() == null) || STANDARD_CONNECTOR_NAME.equals(currentConnection.getConnectorName())) && sourceComeFromtUniqRow(processType, currentConnection.getSource())) {
            currentConnection.setConnectorName(NEW_CONNECTOR_NAME);
            modified = true;
        }
    }
    if (modified) {
        factory.save(item, true);
        replaceDone = true;
    }
    return replaceDone;
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)

Example 63 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class ChangeJobscriptContentValueMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (item instanceof JobScriptItem) {
        byte[] bytes = ((JobScriptItem) item).getContent().getInnerContent();
        String message = new String(bytes);
        message = message.replaceAll("PATTREN", "PATTERN");
        try {
            ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
            byteArray.setInnerContent(message.getBytes());
            ((JobScriptItem) item).setContent(byteArray);
            factory.save(item, true);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) JobScriptItem(org.talend.core.model.properties.JobScriptItem) ByteArray(org.talend.core.model.properties.ByteArray)

Example 64 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class AbstractRoutineAction method openRoutineEditor.

/**
     * DOC smallet Comment method "openRoutineEditor".
     * 
     * @param routineItem
     * @throws SystemException
     * @throws PartInitException
     */
protected IEditorPart openRoutineEditor(RoutineItem routineItem, boolean readOnly) throws SystemException, PartInitException {
    if (routineItem == null) {
        return null;
    }
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    ITalendSynchronizer routineSynchronizer;
    switch(lang) {
        case JAVA:
            routineSynchronizer = service.createJavaRoutineSynchronizer();
            break;
        case PERL:
            routineSynchronizer = service.createPerlRoutineSynchronizer();
            break;
        default:
            //$NON-NLS-1$
            throw new UnsupportedOperationException(Messages.getString("AbstractRoutineAction.unknowLanguage") + lang);
    }
    // check if the related editor is open.
    IWorkbenchPage page = getActivePage();
    IEditorReference[] editorParts = page.getEditorReferences();
    //$NON-NLS-1$ //$NON-NLS-2$
    String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
    boolean found = false;
    IEditorPart talendEditor = null;
    for (IEditorReference reference : editorParts) {
        IEditorPart editor = reference.getEditor(false);
        if (talendEditorID.equals(editor.getSite().getId())) {
            // TextEditor talendEditor = (TextEditor) editor;
            RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
            if (editorInput.getItem().equals(routineItem)) {
                page.bringToTop(editor);
                found = true;
                talendEditor = editor;
                break;
            }
        }
    }
    if (!found) {
        IFile file = null;
        ProjectManager projectManager = ProjectManager.getInstance();
        boolean flag = projectManager.isInCurrentMainProject(routineItem);
        if (!flag) {
            // is ref project
            file = routineSynchronizer.getRoutinesFile(routineItem);
        } else {
            // need open from item file with multiple version
            boolean needForceRefresh = false;
            if (!ProxyRepositoryFactory.getInstance().isLocalConnectionProvider()) {
                // in case only routine.item file modified, better refresh every time, especially for git mode
                needForceRefresh = true;
            }
            routineSynchronizer.syncRoutine(routineItem, true, needForceRefresh);
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            String lastVersion = factory.getLastVersion(routineItem.getProperty().getId()).getVersion();
            String curVersion = routineItem.getProperty().getVersion();
            if (curVersion != null && curVersion.equals(lastVersion)) {
                file = routineSynchronizer.getFile(routineItem);
            } else {
                file = routineSynchronizer.getRoutinesFile(routineItem);
            }
        }
        if (file == null) {
            return null;
        }
        RepositoryEditorInput input = new RoutineEditorInput(file, routineItem);
        input.setReadOnly(readOnly);
        talendEditor = page.openEditor(input, talendEditorID);
    }
    return talendEditor;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ProjectManager(org.talend.repository.ProjectManager) IEditorReference(org.eclipse.ui.IEditorReference) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 65 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class SelectDeleteProjectDialog method getProjectItem.

private List<Project> getProjectItem() {
    if (login) {
        List<Project> projectList = new ArrayList<Project>();
        if (projectItemList != null && !projectItemList.isEmpty()) {
            Iterator<Object> iter = projectItemList.iterator();
            while (iter.hasNext()) {
                Object project = iter.next();
                if (project instanceof Project) {
                    projectList.add((Project) project);
                }
            }
        }
        return projectList;
    }
    if (!projects.isEmpty()) {
        return projects;
    }
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    Project[] projects = null;
    try {
        projects = repositoryFactory.readProject();
    } catch (PersistenceException e) {
        CommonExceptionHandler.process(e);
    } catch (BusinessException e) {
        CommonExceptionHandler.process(e);
    }
    for (Project p : projects) {
        this.projects.add(p);
    }
    if (projects != null) {
        return this.projects;
    }
    return Collections.emptyList();
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) BusinessException(org.talend.commons.exception.BusinessException) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ArrayList(java.util.ArrayList) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)74 PersistenceException (org.talend.commons.exception.PersistenceException)32 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)25 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)22 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)18 EList (org.eclipse.emf.common.util.EList)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)11 Project (org.talend.core.model.general.Project)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 BusinessException (org.talend.commons.exception.BusinessException)8 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)8 ArrayList (java.util.ArrayList)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Path (org.eclipse.core.runtime.Path)6 EConnectionType (org.talend.core.model.process.EConnectionType)6 ConnectionItem (org.talend.core.model.properties.ConnectionItem)6 List (java.util.List)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)5