Search in sources :

Example 16 with ExportFileResource

use of org.talend.repository.documentation.ExportFileResource in project tdi-studio-se by Talend.

the class JavaScriptForESBWithMavenManager method getExportResources.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.repository.ui.wizards.exportjob.scriptsmanager.esb.JobJavaScriptOSGIForESBManager#getExportResources
     * (org.talend.repository.documentation.ExportFileResource[], java.lang.String[])
     */
@Override
public List<ExportFileResource> getExportResources(ExportFileResource[] processes, String... codeOptions) throws ProcessorException {
    List<ExportFileResource> list = super.getExportResources(processes, codeOptions);
    Map<String, String> mavenPropertiesMap = getMainMavenProperties(processes[0].getItem());
    Iterator<ExportFileResource> it = list.iterator();
    while (it.hasNext()) {
        ExportFileResource resource = it.next();
        if ("".equals(resource.getDirectoryName())) {
            //$NON-NLS-1$
            Map<String, Set<URL>> newResourcesMap = new HashMap<String, Set<URL>>();
            for (String path : resource.getRelativePathList()) {
                if (path.startsWith("OSGI") || path.startsWith(FileConstants.META_INF_FOLDER_NAME)) {
                    //$NON-NLS-1$
                    Set<URL> urls = resource.getResourcesByRelativePath(path);
                    // put OSGI_INF to /src/main/resources/
                    newResourcesMap.put(IMavenProperties.MAIN_RESOURCES_PATH + path, urls);
                }
            }
            resource.removeAllMap();
            for (String path : newResourcesMap.keySet()) {
                resource.addResources(path, new ArrayList<URL>(newResourcesMap.get(path)));
            }
        } else if (LIBRARY_FOLDER_NAME.equals(resource.getDirectoryName())) {
            resource.setDirectoryName(IMavenProperties.MAIN_RESOURCES_LIB_PATH);
        } else if (PROVIDED_LIB_FOLDER.equals(resource.getDirectoryName())) {
            resource.setDirectoryName(IMavenProperties.MAIN_RESOURCES_PROVIDED_LIB_PATH);
        } else if (FileConstants.META_INF_FOLDER_NAME.equals(resource.getDirectoryName())) {
            it.remove();
            if (!resource.getAllResources().isEmpty()) {
                Set<URL> urls = resource.getAllResources().iterator().next();
                if (!urls.isEmpty()) {
                    URL manifestURL = urls.iterator().next();
                    getMenifestMavenProperties(manifestURL, mavenPropertiesMap);
                }
            }
        }
    }
    addSourceCodeToExport(list, processes, codeOptions);
    addMavenScriptToExport(list, processes, mavenPropertiesMap);
    return list;
}
Also used : Set(java.util.Set) ExportFileResource(org.talend.repository.documentation.ExportFileResource) HashMap(java.util.HashMap) URL(java.net.URL)

Example 17 with ExportFileResource

use of org.talend.repository.documentation.ExportFileResource in project tdi-studio-se by Talend.

the class JavaScriptForESBWithMavenManager method getProvidedLibExportFileResource.

@Override
protected ExportFileResource getProvidedLibExportFileResource(ExportFileResource[] processes) {
    Set<String> providedModuleNames = getExcludedModuleNames();
    if (providedModuleNames.isEmpty()) {
        // if empty, won't add the privided lib folder
        return null;
    }
    ExportFileResource libResource = new ExportFileResource(null, PROVIDED_LIB_FOLDER);
    List<URL> providedUrls = getNeededModuleURLs(providedModuleNames);
    if (providedUrls.isEmpty()) {
        // if empty, won't add the privided lib folder
        return null;
    }
    libResource.addResources(providedUrls);
    return libResource;
}
Also used : ExportFileResource(org.talend.repository.documentation.ExportFileResource) URL(java.net.URL)

Example 18 with ExportFileResource

use of org.talend.repository.documentation.ExportFileResource 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 19 with ExportFileResource

use of org.talend.repository.documentation.ExportFileResource in project tdi-studio-se by Talend.

the class SpagicDeployWizardPage method setTopFolder.

protected void setTopFolder(List<ExportFileResource> resourcesToExport, String topFolder) {
    for (ExportFileResource fileResource : resourcesToExport) {
        String directory = fileResource.getDirectoryName();
        //$NON-NLS-1$
        fileResource.setDirectoryName(topFolder + "/" + directory);
    }
}
Also used : ExportFileResource(org.talend.repository.documentation.ExportFileResource)

Example 20 with ExportFileResource

use of org.talend.repository.documentation.ExportFileResource in project tdi-studio-se by Talend.

the class SpagicDeployWizardPage 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
     */
@Override
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("SpagicDeployWizardPage.exportResourceError"), //$NON-NLS-1$
        Messages.getString("SpagicDeployWizardPage.chooseResource"));
        return false;
    }
    if (!ensureTargetIsValid()) {
        return false;
    }
    manager = new //$NON-NLS-1$
    SpagicJavaDeployManager(//$NON-NLS-1$
    exportChoiceMap, //$NON-NLS-1$
    contextCombo.getText(), //$NON-NLS-1$
    "all", //$NON-NLS-1$
    IProcessor.NO_STATISTICS, IProcessor.NO_TRACES);
    String topFolder = getRootFolderName();
    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));
    // File file = createSapgicProperty();
    ArchiveFileExportOperationFullPath exporterOperation = getExporterOperation(resourcesToExport);
    // exportResource(topFolder, "", "", 1);
    boolean ok = executeExportOperation(exporterOperation);
    // path can like name/name
    manager.deleteTempFiles();
    ProcessorUtilities.resetExportConfig();
    String projectName = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLabel();
    List<JobResource> jobResources = new ArrayList<JobResource>();
    for (ExportFileResource proces : process) {
        try {
            proces.setProcess((ProcessItem) ProxyRepositoryFactory.getInstance().getUptodateProperty(proces.getItem().getProperty()).getItem());
        } catch (PersistenceException e) {
            e.printStackTrace();
        }
        ProcessItem processItem = (ProcessItem) proces.getItem();
        JobInfo jobInfo = new JobInfo(processItem, processItem.getProcess().getDefaultContext());
        jobResources.add(new JobResource(projectName, jobInfo));
        Set<JobInfo> jobInfos = ProcessorUtilities.getChildrenJobInfo(processItem);
        for (JobInfo subjobInfo : jobInfos) {
            jobResources.add(new JobResource(projectName, subjobInfo));
        }
    }
    JobResourceManager reManager = JobResourceManager.getInstance();
    for (JobResource r : jobResources) {
        if (reManager.isProtected(r)) {
            try {
                ProcessorUtilities.generateCode(r.getJobInfo().getJobId(), r.getJobInfo().getContextName(), r.getJobInfo().getJobVersion(), false, false);
            } catch (ProcessorException e) {
                ExceptionHandler.process(e);
            }
        } else {
            reManager.deleteResource(r);
        }
    }
    return ok;
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) JobResource(org.talend.core.model.repository.job.JobResource) ArrayList(java.util.ArrayList) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) JobInfo(org.talend.core.model.process.JobInfo) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) JobResourceManager(org.talend.core.model.repository.job.JobResourceManager) ArchiveFileExportOperationFullPath(org.talend.core.ui.export.ArchiveFileExportOperationFullPath)

Aggregations

ExportFileResource (org.talend.repository.documentation.ExportFileResource)48 URL (java.net.URL)24 ProcessItem (org.talend.core.model.properties.ProcessItem)23 File (java.io.File)20 ArrayList (java.util.ArrayList)19 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 ProcessorException (org.talend.designer.runprocess.ProcessorException)11 MalformedURLException (java.net.MalformedURLException)10 IOException (java.io.IOException)8 PersistenceException (org.talend.commons.exception.PersistenceException)8 IFile (org.eclipse.core.resources.IFile)6 Item (org.talend.core.model.properties.Item)6 EList (org.eclipse.emf.common.util.EList)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Set (java.util.Set)4 Path (org.eclipse.core.runtime.Path)4 IProcess (org.talend.core.model.process.IProcess)4 ArchiveFileExportOperationFullPath (org.talend.core.ui.export.ArchiveFileExportOperationFullPath)4 ExportChoice (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice)4