Search in sources :

Example 11 with RepositoryContext

use of org.talend.core.context.RepositoryContext in project tdi-studio-se by Talend.

the class PublishOnSpagoExportWizardPage method finish.

/**
     * The Finish button was pressed. Try to do the required work now and answer a boolean indicating success. If false
     * is returned then the wizard will not close.
     * 
     * @returns boolean
     */
public boolean finish() {
    Map<ExportChoice, Object> exportChoiceMap = getExportChoiceMap();
    boolean canExport = false;
    for (ExportChoice choice : ExportChoice.values()) {
        if (exportChoiceMap.get(choice) != null && exportChoiceMap.get(choice) instanceof Boolean && (Boolean) exportChoiceMap.get(choice)) {
            canExport = true;
            break;
        }
    }
    if (!canExport) {
        MessageDialog.openInformation(getContainer().getShell(), //$NON-NLS-1$
        Messages.getString("PublishOnSpagoExportWizardPage.publishResourceError"), //$NON-NLS-1$
        Messages.getString("PublishOnSpagoExportWizardPage.chooseResource"));
        return false;
    }
    if (!ensureTargetIsValid()) {
        return false;
    }
    String topFolder = getRootFolderName();
    manager = new //$NON-NLS-1$
    JobJavaScriptsManager(//$NON-NLS-1$
    exportChoiceMap, //$NON-NLS-1$
    contextCombo.getText(), //$NON-NLS-1$
    "all", //$NON-NLS-1$
    IProcessor.NO_STATISTICS, IProcessor.NO_TRACES);
    List<ExportFileResource> resourcesToExport = null;
    try {
        resourcesToExport = getExportResources();
    } catch (ProcessorException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
    setTopFolder(resourcesToExport, topFolder);
    // Save dirty editors if possible but do not stop if not all are saved
    saveDirtyEditors();
    // about to invoke the operation so save our state
    saveWidgetValues();
    // boolean ok = executeExportOperation(new ArchiveFileExportOperationFullPath(process));
    ArchiveFileExportOperationFullPath exporterOperation = getExporterOperation(resourcesToExport);
    boolean ok = executeExportOperation(exporterOperation);
    // path can like name/name
    manager.deleteTempFiles();
    ProcessorUtilities.resetExportConfig();
    for (int i = 0; i < process.length; i++) {
        ProcessItem processItem = (ProcessItem) process[i].getItem();
        try {
            ProcessorUtilities.generateCode(processItem, processItem.getProcess().getDefaultContext(), false, false);
        } catch (ProcessorException e) {
            ExceptionHandler.process(e);
        }
    }
    // cantoine : connection to SpagoBiEngineClient to publish Job.
    try {
        Project project = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject();
        // retrieve user, password, host, port from selected SpagoBiServer
        String selectedSpagoBiEngineName = serverSpagoBi.getItem(serverSpagoBi.getSelectionIndex());
        SpagoBiServer spagoBiServer = null;
        List<SpagoBiServer> listServerSapgo = null;
        // ProxyRepositoryFactory proxyRepositoryFactory = ProxyRepositoryFactory.getInstance();
        // try {
        listServerSapgo = SpagoBiServerHelper.parse(new SpagoBiPreferencePage().getPreferenceStore().getString(SpagoBiServer.SPAGOBI_SERVER));
        if (listServerSapgo != null && !listServerSapgo.isEmpty()) {
            Iterator<SpagoBiServer> iterator = listServerSapgo.iterator();
            while (iterator.hasNext()) {
                spagoBiServer = iterator.next();
                if (spagoBiServer.getEngineName().equals(selectedSpagoBiEngineName)) {
                    break;
                }
            }
        }
        // } catch (PersistenceException e) {
        // displayErrorDialog(e.getMessage());
        // }
        // "biadmin";
        String user = spagoBiServer.getLogin();
        // "biadmin";
        String password = spagoBiServer.getPassword();
        String host = spagoBiServer.getHost();
        String port = spagoBiServer.getPort();
        // create the client
        //$NON-NLS-1$
        ISpagoBITalendEngineClient client = new SpagoBITalendEngineClient(user, password, host, port, "SpagoBITalendEngine");
        // get some informations about the engine instance referenced by the client
        //$NON-NLS-1$
        System.out.println("Engine version: " + client.getEngineVersion());
        //$NON-NLS-1$
        System.out.println("Engine fullname: " + client.getEngineName());
        // prepare parameters used during deployment
        JobDeploymentDescriptor jobDeploymentDescriptor = new JobDeploymentDescriptor(project.getLabel(), project.getLanguage().getName());
        File zipFile = new File(getDestinationValue());
        // deploy job on engine runtime
        boolean result = client.deployJob(jobDeploymentDescriptor, zipFile);
        if (result)
            //$NON-NLS-1$
            System.out.println("Jobs deployed succesfully");
        else
            //$NON-NLS-1$
            System.out.println("Jobs not deployed");
    } catch (EngineUnavailableException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: " + e.getMessage());
    } catch (AuthenticationFailedException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: " + e.getMessage());
    } catch (UnsupportedEngineVersionException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: Unsupported engine version");
        System.err.println(//$NON-NLS-1$
        "You are using TalendEngineClientAPI version " + SpagoBITalendEngineClient.CLIENTAPI_VERSION_NUMBER + //$NON-NLS-1$
        ". " + //$NON-NLS-1$
        "The TalendEngine instance you are trying to connect to require TalendEngineClientAPI version " + e.getComplianceVersion() + //$NON-NLS-1$
        " or grater.");
    } catch (ServiceInvocationFailedException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: " + e.getMessage());
        //$NON-NLS-1$ //$NON-NLS-2$
        System.err.println("StatusLine: " + e.getStatusLine() + "responseBody: " + e.getResponseBody());
    }
    return ok;
// return true;
}
Also used : SpagoBiServer(org.talend.core.model.properties.SpagoBiServer) ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) RepositoryContext(org.talend.core.context.RepositoryContext) JobDeploymentDescriptor(it.eng.spagobi.engines.talend.client.JobDeploymentDescriptor) AuthenticationFailedException(it.eng.spagobi.engines.talend.client.exception.AuthenticationFailedException) ISpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient) SpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.SpagoBITalendEngineClient) SpagoBiPreferencePage(org.talend.sbi.engines.client.ui.preferences.SpagoBiPreferencePage) ProcessorException(org.talend.designer.runprocess.ProcessorException) UnsupportedEngineVersionException(it.eng.spagobi.engines.talend.client.exception.UnsupportedEngineVersionException) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) Project(org.talend.core.model.general.Project) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ISpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient) File(java.io.File) ArchiveFileExportOperationFullPath(org.talend.core.ui.export.ArchiveFileExportOperationFullPath)

Example 12 with RepositoryContext

use of org.talend.core.context.RepositoryContext in project tdi-studio-se by Talend.

the class GenerateSpagoBIXML method createSpagoBIXML.

private void createSpagoBIXML() {
    if (file != null) {
        try {
            Project project = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject();
            final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
            fabrique.setValidating(true);
            final DocumentBuilder analyseur = fabrique.newDocumentBuilder();
            analyseur.setErrorHandler(new ErrorHandler() {

                public void error(final SAXParseException exception) throws SAXException {
                    throw exception;
                }

                public void fatalError(final SAXParseException exception) throws SAXException {
                    throw exception;
                }

                public void warning(final SAXParseException exception) throws SAXException {
                    throw exception;
                }
            });
            Document document = analyseur.newDocument();
            //$NON-NLS-1$
            Element spagobi = document.createElement("etl");
            document.appendChild(spagobi);
            // ///////////////////add job element.
            //$NON-NLS-1$
            Element projectElement = document.createElement("job");
            spagobi.appendChild(projectElement);
            //$NON-NLS-1$
            Attr attr = document.createAttribute("project");
            attr.setNodeValue(project.getEmfProject().getLabel());
            projectElement.setAttributeNode(attr);
            //$NON-NLS-1$
            attr = document.createAttribute("jobName");
            attr.setNodeValue(item.getProperty().getLabel());
            projectElement.setAttributeNode(attr);
            //$NON-NLS-1$
            attr = document.createAttribute("context");
            attr.setNodeValue(contextName);
            projectElement.setAttributeNode(attr);
            //$NON-NLS-1$
            attr = document.createAttribute("language");
            attr.setNodeValue(project.getLanguage().getName());
            projectElement.setAttributeNode(attr);
            XMLSerializer serializer = new XMLSerializer();
            OutputFormat outputFormat = new OutputFormat();
            outputFormat.setIndenting(true);
            serializer.setOutputFormat(outputFormat);
            serializer.setOutputCharStream(new java.io.FileWriter(file));
            serializer.serialize(document);
        } catch (Exception e) {
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
    }
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) RepositoryContext(org.talend.core.context.RepositoryContext) XMLSerializer(com.sun.org.apache.xml.internal.serialize.XMLSerializer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) OutputFormat(com.sun.org.apache.xml.internal.serialize.OutputFormat) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) Project(org.talend.core.model.general.Project) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException)

Example 13 with RepositoryContext

use of org.talend.core.context.RepositoryContext in project tdi-studio-se by Talend.

the class ShadowProcessTest method setUp.

/*
     * (non-Javadoc)
     * 
     * @see junit.framework.TestCase#setUp()
     */
@Override
protected void setUp() throws Exception {
    //$NON-NLS-1$
    Project project = new Project("ShadowProcessTest");
    project.setLanguage(ECodeLanguage.PERL);
    RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
    repositoryContext.setProject(project);
    super.setUp();
}
Also used : Project(org.talend.core.model.general.Project) RepositoryContext(org.talend.core.context.RepositoryContext)

Example 14 with RepositoryContext

use of org.talend.core.context.RepositoryContext in project tdi-studio-se by Talend.

the class DemosImportTest method recordOriginalProject.

@BeforeClass
public static void recordOriginalProject() throws PersistenceException, CoreException, LoginException {
    Context ctx = CoreRuntimePlugin.getInstance().getContext();
    RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
    originalProject = repositoryContext.getProject();
}
Also used : Context(org.talend.core.context.Context) RepositoryContext(org.talend.core.context.RepositoryContext) RepositoryContext(org.talend.core.context.RepositoryContext) BeforeClass(org.junit.BeforeClass)

Example 15 with RepositoryContext

use of org.talend.core.context.RepositoryContext in project tdi-studio-se by Talend.

the class AddContextCommentValueMigrationTaskTest method afterAllTests.

@AfterClass
public static void afterAllTests() throws PersistenceException, CoreException {
    removeTempProject();
    Context ctx = CoreRuntimePlugin.getInstance().getContext();
    RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
    repositoryContext.setProject(originalProject);
    originalProject = null;
    sampleProject = null;
}
Also used : Context(org.talend.core.context.Context) RepositoryContext(org.talend.core.context.RepositoryContext) RepositoryContext(org.talend.core.context.RepositoryContext) AfterClass(org.junit.AfterClass)

Aggregations

RepositoryContext (org.talend.core.context.RepositoryContext)31 Context (org.talend.core.context.Context)17 Project (org.talend.core.model.general.Project)12 PersistenceException (org.talend.commons.exception.PersistenceException)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 IProject (org.eclipse.core.resources.IProject)5 ECodeLanguage (org.talend.core.language.ECodeLanguage)5 File (java.io.File)3 CoreException (org.eclipse.core.runtime.CoreException)3 BeforeClass (org.junit.BeforeClass)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2