Search in sources :

Example 6 with ComponentExtension

use of org.talend.designer.components.exchange.model.ComponentExtension in project tdi-studio-se by Talend.

the class ComponentSearcher method getAvailableComponentExtensions.

/**
     * Find available components.
     * 
     * @param version The tos version.
     * @param language The project language.
     * @return
     */
public static List<ComponentExtension> getAvailableComponentExtensions(String typeExtensionTemp, String versionStudioTemp, ECodeLanguage language, String category) {
    List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
    try {
        JSONArray extensionsJSONArray = ExchangeWebService.searchExtensionJSONArray(typeExtensionTemp, versionStudioTemp, category);
        if (extensionsJSONArray != null) {
            int size = extensionsJSONArray.length();
            for (int i = 0; i < size; i++) {
                JSONObject extensionObj = extensionsJSONArray.getJSONObject(i);
                Map<String, ComponentExtension> extensionsMap = new HashMap<String, ComponentExtension>();
                ComponentExtension extension = extensionsMap.get(extensionObj.getString("label"));
                if (extension == null) {
                    extension = ExchangeFactory.eINSTANCE.createComponentExtension();
                    //
                    JSONObject extensionsViewDetailObj = ExchangeWebService.searchExtensionViewDetail(extensionObj.getString("idExtension"), "tos");
                    extension.setIdExtension(extensionObj.getString("idExtension"));
                    extension.setLabel(extensionObj.getString("label"));
                    extension.setAuthor(extensionObj.getString("author"));
                    extension.setRate(extensionObj.getString("rate"));
                    extension.setTypeExtension(extensionObj.getString("typeExtension"));
                    extension.setVersionExtension(extensionObj.getString("versionExtension"));
                    if (extensionsViewDetailObj.length() > 0) {
                        extension.setLastVersionAvailable(extensionsViewDetailObj.getString("lastVersionAvailable"));
                        extension.setPublicationDate(formatter.parse(extensionsViewDetailObj.getString("publicationDate")));
                        extension.setDescription(extensionsViewDetailObj.getString("description"));
                        //
                        List<AvailableExtensionViewDetail> reviews = new ArrayList<AvailableExtensionViewDetail>();
                        if ((extensionsViewDetailObj.get("reviews")) != null && (extensionsViewDetailObj.get("reviews") instanceof JSONArray)) {
                            JSONArray o = extensionsViewDetailObj.getJSONArray("reviews");
                            int sumRate = 0;
                            int sizeDetail = o.length();
                            for (int j = 0; j < sizeDetail; j++) {
                                JSONObject review = o.getJSONObject(j);
                                AvailableExtensionViewDetail extensionViewDetail = ExchangeFactory.eINSTANCE.createAvailableExtensionViewDetail();
                                extensionViewDetail.setAuthor(review.getString("author"));
                                extensionViewDetail.setTitle(review.getString("title"));
                                extensionViewDetail.setComment(review.getString("comment"));
                                extensionViewDetail.setReviewrate(review.getString("rate"));
                                reviews.add(extensionViewDetail);
                                sumRate = sumRate + Integer.parseInt(review.getString("rate"));
                            }
                            //
                            if (sizeDetail > 0 && sumRate > 0) {
                                int im = sumRate / sizeDetail;
                                extension.setRate(im + "");
                            }
                        }
                        extension.getReviews().addAll((Collection<? extends AvailableExtensionViewDetail>) reviews);
                    }
                    extensionsMap.put(extension.getIdExtension(), extension);
                    extensions.add(extension);
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return extensions;
}
Also used : AvailableExtensionViewDetail(org.talend.designer.components.exchange.model.AvailableExtensionViewDetail) JSONObject(us.monoid.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension)

Example 7 with ComponentExtension

use of org.talend.designer.components.exchange.model.ComponentExtension in project tdi-studio-se by Talend.

the class ComponentSearcher method getInstalledExtensions.

/**
     * Find Installed components.
     * 
     * @param version The tos version.
     * @param language The project language.
     * @return
     */
public static List<ComponentExtension> getInstalledExtensions(String version, ECodeLanguage language, String username, String passwordHash) {
    List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
    try {
        JSONArray extensionsJSONArray = ExchangeWebService.searchInstalledExtensionJSONArray(username, passwordHash);
        if (extensionsJSONArray != null) {
            int size = extensionsJSONArray.length();
            for (int i = 0; i < size; i++) {
                JSONObject extensionObj = extensionsJSONArray.getJSONObject(i);
                Map<String, ComponentExtension> extensionsMap = new HashMap<String, ComponentExtension>();
                ComponentExtension extension = extensionsMap.get(extensionObj.getString("name"));
                if (extension == null) {
                    extension = ExchangeFactory.eINSTANCE.createComponentExtension();
                    //
                    extension.setIdExtension(extensionObj.getString("idExtension"));
                    extension.setTypeExtension(extensionObj.getString("typeExtension"));
                    extension.setLabel(extensionObj.getString("name"));
                    extension.setDateDownload(formatter.parse(extensionObj.getString("dateDownload")));
                    extension.setDownloadedVersion(extensionObj.getString("downloadedVersion"));
                    extension.setVersionExtension(extensionObj.getString("lastVersion"));
                    extensionsMap.put(extension.getIdExtension(), extension);
                    extensions.add(extension);
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return extensions;
}
Also used : JSONObject(us.monoid.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension)

Example 8 with ComponentExtension

use of org.talend.designer.components.exchange.model.ComponentExtension in project tdi-studio-se by Talend.

the class RefreshJob method run.

@Override
public IStatus run(IProgressMonitor monitor) {
    monitor.beginTask(Messages.getString("RefreshJob.FindExtensions.Message"), IProgressMonitor.UNKNOWN);
    // run in another thread, make it possible to stop the remote procedure call when user press cancel
    // button
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<List<ComponentExtension>> task = executor.submit(new Callable<List<ComponentExtension>>() {

        @Override
        public List<ComponentExtension> call() throws Exception {
            List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
            extensions = ComponentSearcher.getAvailableComponentExtensions(ExchangeUtils.TYPEEXTENSION, ExchangePlugin.getStudioVersion(), ExchangeUtils.getCurrentLanguage(), //$NON-NLS-1$
            "");
            if (extensions == null || extensions.isEmpty() || extensions.size() == 0) {
                extensions = //$NON-NLS-1$
                ComponentSearcher.getAvailableComponentExtensions(//$NON-NLS-1$
                ExchangeUtils.TYPEEXTENSION, //$NON-NLS-1$
                "5.6.1", ExchangeUtils.getCurrentLanguage(), //$NON-NLS-1$
                "");
            }
            return extensions;
        }
    });
    while (true) {
        try {
            if (monitor.isCanceled()) {
                // stop the web service call
                task.cancel(true);
                return Status.CANCEL_STATUS;
            } else if (task.isDone()) {
                // web service call complete
                fAvailableExtensions = task.get();
                break;
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
            return Status.CANCEL_STATUS;
        } finally {
            executor.shutdown();
        }
    }
    monitor.done();
    return Status.OK_STATUS;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) List(java.util.List) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension)

Example 9 with ComponentExtension

use of org.talend.designer.components.exchange.model.ComponentExtension in project tdi-studio-se by Talend.

the class ComponentSearcher method getContributedExtensions.

/**
     * Find Contributed components.
     * 
     * @param version The tos version.
     * @param language The project language.
     * @return
     */
public static List<ComponentExtension> getContributedExtensions(String version, ECodeLanguage language, String username, String passwordHash) {
    List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
    try {
        JSONArray extensionsJSONArray = ExchangeWebService.searchContributedExtensionJSONArray(username, passwordHash);
        if (extensionsJSONArray != null) {
            int size = extensionsJSONArray.length();
            for (int i = 0; i < size; i++) {
                JSONObject extensionObj = extensionsJSONArray.getJSONObject(i);
                Map<String, ComponentExtension> extensionsMap = new HashMap<String, ComponentExtension>();
                ComponentExtension extension = extensionsMap.get(extensionObj.getString("name"));
                if (extension == null) {
                    extension = ExchangeFactory.eINSTANCE.createComponentExtension();
                    //
                    extension.setIdExtension(extensionObj.getString("idExtension"));
                    extension.setTypeExtension(extensionObj.getString("typeExtension"));
                    extension.setLabel(extensionObj.getString("name"));
                    if (extensionObj.getString("dateExtension") != null && !"".equals(extensionObj.getString("dateExtension"))) {
                        extension.setPublicationDate(formatter.parse(extensionObj.getString("dateExtension")));
                    } else {
                        extension.setPublicationDate(formatter.parse(formatter.format(new Date())));
                    }
                    extension.setLastVersionAvailable(extensionObj.getString("lastVersion"));
                    extensionsMap.put(extension.getIdExtension(), extension);
                    extensions.add(extension);
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return extensions;
}
Also used : JSONObject(us.monoid.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension) Date(java.util.Date)

Example 10 with ComponentExtension

use of org.talend.designer.components.exchange.model.ComponentExtension in project tdi-studio-se by Talend.

the class ComponentSearcher method getImportComponentExtensions.

public static List<ComponentExtension> getImportComponentExtensions(String version, ECodeLanguage language, String type) {
    List<ComponentExtension> extensions = new ArrayList<ComponentExtension>();
    try {
        List<RevisionInfo> revisions = ExchangeUtils.getRevisionList(version, getLanguageId(language), type);
        Map<String, ComponentExtension> extensionsMap = new HashMap<String, ComponentExtension>();
        for (RevisionInfo revision : revisions) {
            ComponentExtension extension = extensionsMap.get(revision.getExtension_id());
            if (extension == null) {
                extension = ExchangeFactory.eINSTANCE.createComponentExtension();
                extension.setIdExtension(revision.getExtension_id() + "");
                extension.setLabel(revision.getExtension_name());
                extension.setAuthor(revision.getAuthor_name());
                extension.setLanguage(Language.get(getLanguageId(language)));
                extension.setDescription(revision.getExtension_description());
                extension.setLinkDownload(revision.getDownload_url());
                extension.setFilename(revision.getFilename());
                extension.setVersionExtension(revision.getRevision_name());
                extensionsMap.put(revision.getExtension_id() + "", extension);
                extensions.add(extension);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return extensions;
}
Also used : RevisionInfo(org.talend.designer.components.exchange.model.RevisionInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension)

Aggregations

ComponentExtension (org.talend.designer.components.exchange.model.ComponentExtension)16 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)5 Element (org.w3c.dom.Element)4 JSONArray (us.monoid.json.JSONArray)4 JSONObject (us.monoid.json.JSONObject)4 List (java.util.List)3 Document (org.w3c.dom.Document)3 Date (java.util.Date)2 AvailableExtensionViewDetail (org.talend.designer.components.exchange.model.AvailableExtensionViewDetail)2 Text (org.w3c.dom.Text)2 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 TableItem (org.eclipse.swt.widgets.TableItem)1 IntroContentProvider (org.eclipse.ui.internal.intro.impl.model.IntroContentProvider)1