Search in sources :

Example 76 with ProxyRepositoryFactory

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

the class JSONConnectionContextHelper method getRepositoryContext.

private static ISelection getRepositoryContext(final String contextNameOrId, boolean isId) {
    if (contextNameOrId == null || "".equals(contextNameOrId.trim())) {
        //$NON-NLS-1$
        return null;
    }
    if (isId && RepositoryNode.NO_ID.equals(contextNameOrId.trim())) {
        return null;
    }
    IRepositoryViewObject contextObject = null;
    try {
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        List<IRepositoryViewObject> contextObjectList = factory.getAll(ERepositoryObjectType.CONTEXT, true);
        if (contextObjectList != null) {
            for (IRepositoryViewObject object : contextObjectList) {
                Item item = object.getProperty().getItem();
                if (item != null && item instanceof ContextItem) {
                    String itemNameOrId = null;
                    if (isId) {
                        itemNameOrId = item.getProperty().getId();
                    } else {
                        itemNameOrId = item.getProperty().getLabel();
                    }
                    if (contextNameOrId.equals(itemNameOrId)) {
                        contextObject = object;
                        break;
                    }
                }
            }
        }
    } catch (PersistenceException e) {
    //
    }
    StructuredSelection selection = new StructuredSelection();
    if (contextObject != null) {
        RepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(contextObject);
        if (repositoryNode != null) {
            selection = new StructuredSelection(repositoryNode);
        }
    }
    return selection;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ContextItem(org.talend.core.model.properties.ContextItem) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 77 with ProxyRepositoryFactory

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

the class RenametForCurrentIterationMigrationTask 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();
    for (Object n : node) {
        NodeType type = (NodeType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (!elemType.getField().equals("CHECK")) {
                //$NON-NLS-1$
                if (language.equals(ECodeLanguage.JAVA)) {
                    if (elemType.getValue() != null && elemType.getValue().contains(TFOR) && elemType.getValue().contains(CURRENT_ITER)) {
                        elemType.setValue(elemType.getValue().replaceAll(CURRENT_ITER, CURRENT_VALUE));
                    }
                }
                if (elemType.getValue() != null && elemType.getValue().contains(TFOR)) {
                    elemType.setValue(elemType.getValue().replaceAll(TFOR, TLOOP));
                    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(TFOR) && elemVal.getValue().contains(CURRENT_ITER)) {
                            elemVal.setValue(elemVal.getValue().replaceAll(CURRENT_ITER, CURRENT_VALUE));
                        }
                    }
                    if (elemVal.getValue() != null && elemVal.getValue().contains(TFOR)) {
                        elemVal.setValue(elemVal.getValue().replaceAll(TFOR, TLOOP));
                        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) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 78 with ProxyRepositoryFactory

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

the class RenametStandardizePhoneNumberColumnName method changeCustomerColumn.

private void changeCustomerColumn(Item item) throws PersistenceException {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    for (Object o : processType.getNode()) {
        NodeType node = (NodeType) o;
        if ("tStandardizePhoneNumber".equalsIgnoreCase(node.getComponentName())) {
            for (Object o2 : node.getMetadata()) {
                MetadataType metadata = (MetadataType) o2;
                for (Object o3 : metadata.getColumn()) {
                    ColumnType column = (ColumnType) o3;
                    if ("IsPossiblePhoneNumber ".equals(column.getName())) {
                        column.setName("IsPossiblePhoneNumber");
                        modified = true;
                        break;
                    }
                }
            }
        }
    }
    if (modified) {
        factory.save(item, true);
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType)

Example 79 with ProxyRepositoryFactory

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

the class SalesforceMultiSchemaMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org .talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof SalesforceSchemaConnectionItem) {
        boolean modify = false;
        SalesforceSchemaConnectionItem salesforceItem = (SalesforceSchemaConnectionItem) item;
        if (salesforceItem.getConnection() instanceof SalesforceSchemaConnection) {
            SalesforceSchemaConnection sfConnection = (SalesforceSchemaConnection) salesforceItem.getConnection();
            SalesforceModuleUnit module = ConnectionFactory.eINSTANCE.createSalesforceModuleUnit();
            module.setId(ProxyRepositoryFactory.getInstance().getNextId());
            String moduleName = sfConnection.getModuleName();
            if (moduleName == null || "".equals(moduleName)) {
                moduleName = "Default";
            }
            module.setLabel(moduleName);
            module.setModuleName(moduleName);
            EList<orgomg.cwm.objectmodel.core.Package> originalPackages = sfConnection.getDataPackage();
            for (int i = 0; i < originalPackages.size(); i++) {
                MetadataTable table = (MetadataTable) originalPackages.get(i).getOwnedElement().get(0);
                if (originalPackages.get(i) instanceof RecordFile) {
                    table.setLabel(moduleName);
                }
                module.getTables().add(table);
            }
            sfConnection.getModules().add(module);
            modify = true;
        }
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) RecordFile(orgomg.cwm.resource.record.RecordFile) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SalesforceModuleUnit(org.talend.core.model.metadata.builder.connection.SalesforceModuleUnit)

Example 80 with ProxyRepositoryFactory

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

the class LoginDialog method logIn.

/**
     * DOC smallet Comment method "logIn".
     * 
     * @param project
     * @throws Exception
     */
protected boolean logIn(final Project project) {
    final ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    ConnectionBean connBean = loginComposite.getConnection();
    final boolean needRestartForLocal = loginComposite.needRestartForLocal();
    if (connBean == null || project == null || project.getLabel() == null) {
        return false;
    }
    try {
        if (!project.getEmfProject().isLocal() && factory.isLocalConnectionProvider()) {
            List<IRepositoryFactory> rfList = RepositoryFactoryProvider.getAvailableRepositories();
            IRepositoryFactory remoteFactory = null;
            for (IRepositoryFactory rf : rfList) {
                if (!rf.isLocalConnectionProvider()) {
                    remoteFactory = rf;
                    break;
                }
            }
            if (remoteFactory != null) {
                factory.setRepositoryFactoryFromProvider(remoteFactory);
                factory.getRepositoryContext().setOffline(true);
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    // Save last used parameters
    PreferenceManipulator prefManipulator = new PreferenceManipulator(CorePlugin.getDefault().getPreferenceStore());
    prefManipulator.setLastProject(project.getTechnicalLabel());
    saveLastConnBean(connBean);
    // check for Talendforge
    if (PluginChecker.isExchangeSystemLoaded() && !TalendPropertiesUtil.isHideExchange()) {
        IPreferenceStore prefStore = PlatformUI.getPreferenceStore();
        boolean checkTisVersion = prefStore.getBoolean(ITalendCorePrefConstants.EXCHANGE_CHECK_TIS_VERSION);
        IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
        if (!checkTisVersion && brandingService.isPoweredbyTalend()) {
            int count = prefStore.getInt(TalendForgeDialog.LOGINCOUNT);
            if (count < 0) {
                count = 1;
            }
            ExchangeUser exchangeUser = project.getExchangeUser();
            boolean isExchangeLogon = exchangeUser.getLogin() != null && !exchangeUser.getLogin().equals("");
            boolean isUserPassRight = true;
            if (isExchangeLogon) {
                IExchangeService service = (IExchangeService) GlobalServiceRegister.getDefault().getService(IExchangeService.class);
                if (service.checkUserAndPass(exchangeUser.getUsername(), exchangeUser.getPassword()) != null) {
                    isUserPassRight = false;
                }
            }
            if (!isExchangeLogon || !isUserPassRight) {
                if ((count + 1) % 4 == 0) {
                    // if (Platform.getOS().equals(Platform.OS_LINUX)) {
                    // TalendForgeDialog tfDialog = new TalendForgeDialog(this.getShell(), project);
                    // tfDialog.open();
                    // } else {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            String userEmail = null;
                            if (project.getAuthor() != null) {
                                userEmail = project.getAuthor().getLogin();
                            }
                            TalendForgeDialog tfDialog = new TalendForgeDialog(getShell(), userEmail);
                            tfDialog.setBlockOnOpen(true);
                            tfDialog.open();
                        }
                    });
                }
                prefStore.setValue(TalendForgeDialog.LOGINCOUNT, count + 1);
            }
        }
    }
    try {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreTisService.class)) {
            final ICoreTisService service = (ICoreTisService) GlobalServiceRegister.getDefault().getService(ICoreTisService.class);
            if (service != null) {
                // if in TIS then update the bundle status according to the project type
                if (!service.validProject(project, needRestartForLocal)) {
                    LoginComposite.isRestart = true;
                    return true;
                }
            }
        // else not in TIS so ignor caus we may not have a licence so we do not know which bundles belong to
        // DI, DQ or MDM
        }
    } catch (PersistenceException e) {
        e.printStackTrace();
        loginComposite.populateProjectList();
        MessageDialog.openError(getShell(), getShell().getText(), e.getMessage());
        return false;
    }
    final Shell shell = this.getShell();
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            // monitorWrap = new EventLoopProgressMonitor(monitor);
            try {
                factory.logOnProject(project, monitor);
            } catch (LoginException e) {
                throw new InvocationTargetException(e);
            } catch (PersistenceException e) {
                throw new InvocationTargetException(e);
            } catch (OperationCanceledException e) {
                throw new InterruptedException(e.getLocalizedMessage());
            }
            monitor.done();
        }
    };
    try {
        dialog.run(true, true, runnable);
    } catch (final InvocationTargetException e) {
        if (PluginChecker.isSVNProviderPluginLoaded()) {
            loginComposite.populateProjectList();
            if (e.getTargetException() instanceof OperationCancelException) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("LoginDialog.logonCanceled"), e.getTargetException().getLocalizedMessage());
                    }
                });
            } else {
                MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
            }
        } else {
            loginComposite.populateTOSProjectList();
            MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
        }
        return false;
    } catch (InterruptedException e) {
        if (PluginChecker.isSVNProviderPluginLoaded()) {
            loginComposite.populateProjectList();
        } else {
            loginComposite.populateTOSProjectList();
        }
        return false;
    }
    return true;
}
Also used : PreferenceManipulator(org.talend.core.prefs.PreferenceManipulator) OperationCancelException(org.talend.commons.exception.OperationCancelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ICoreTisService(org.talend.core.services.ICoreTisService) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IExchangeService(org.talend.core.service.IExchangeService) Shell(org.eclipse.swt.widgets.Shell) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IBrandingService(org.talend.core.ui.branding.IBrandingService) ExchangeUser(org.talend.core.model.properties.ExchangeUser) Point(org.eclipse.swt.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) ConnectionBean(org.talend.core.model.general.ConnectionBean) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) TalendForgeDialog(org.talend.registration.wizards.register.TalendForgeDialog)

Aggregations

ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)92 PersistenceException (org.talend.commons.exception.PersistenceException)40 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)25 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)22 Project (org.talend.core.model.general.Project)20 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)17 EList (org.eclipse.emf.common.util.EList)15 IProject (org.eclipse.core.resources.IProject)14 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)14 IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)12 User (org.talend.core.model.properties.User)11 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)11 Path (org.eclipse.core.runtime.Path)10 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)9 ArrayList (java.util.ArrayList)8 BusinessException (org.talend.commons.exception.BusinessException)8 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 EMFUtil (org.talend.commons.emf.EMFUtil)6