Search in sources :

Example 1 with AvailableExtensionViewDetail

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

the class ComponentSearcher method getAvailableExtensionViewDetail.

public static ComponentExtension getAvailableExtensionViewDetail(String idExtension, String typeExtension) {
    ComponentExtension extension = null;
    try {
        JSONObject extensionJSONObject = ExchangeWebService.searchExtensionViewDetail(idExtension, typeExtension);
        Map<String, ComponentExtension> extensionsMap = new HashMap<String, ComponentExtension>();
        extension = extensionsMap.get(extensionJSONObject.getString("label"));
        if (extension == null) {
            extension = ExchangeFactory.eINSTANCE.createComponentExtension();
            extension.setIdExtension(extensionJSONObject.getString("idExtension"));
            extension.setLabel(extensionJSONObject.getString("label"));
            extension.setLastVersionAvailable(extensionJSONObject.getString("lastVersionAvailable"));
            extension.setPublicationDate(formatter.parse(extensionJSONObject.getString("publicationDate")));
            extension.setDescription(extensionJSONObject.getString("description"));
            extension.setRate(extensionJSONObject.getString("rate"));
            extension.setAuthor(extensionJSONObject.getString("author"));
            //
            List<AvailableExtensionViewDetail> reviews = new ArrayList<AvailableExtensionViewDetail>();
            JSONArray o = extensionJSONObject.getJSONArray("Reviews");
            int size = o.length();
            for (int i = 0; i < size; i++) {
                JSONObject review = o.getJSONObject(i);
                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);
            }
            extensionsMap.put(extension.getIdExtension(), extension);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return extension;
}
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 2 with AvailableExtensionViewDetail

use of org.talend.designer.components.exchange.model.AvailableExtensionViewDetail 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 3 with AvailableExtensionViewDetail

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

the class ExchangeContentProvider method createContent.

public void createContent(String id, Element parent) {
    if (componentExtension != null) {
        Document dom = parent.getOwnerDocument();
        if (ContentConstants.LEFT_NAME_PART.equals(id)) {
            Element span = dom.createElement("span");
            span.setAttribute("class", "style_1 style_2 style_3");
            span.appendChild(dom.createTextNode(componentExtension.getLabel()));
            parent.appendChild(span);
            parent.appendChild(dom.createElement("br"));
            span = dom.createElement("span");
            span.appendChild(dom.createTextNode("Version " + componentExtension.getVersionExtension()));
            parent.appendChild(span);
            parent.appendChild(dom.createElement("br"));
            span = dom.createElement("span");
            span.appendChild(dom.createTextNode(formatter.format(componentExtension.getPublicationDate())));
            parent.appendChild(span);
        } else if (ContentConstants.COMPONENT_DESCRIPTION.equals(id)) {
            String description = componentExtension.getDescription();
            if (description != null) {
                String[] split = description.split("/n/r|\\n\\r");
                for (int i = 0; i < split.length; i++) {
                    String text = split[i];
                    if (!text.trim().equals("")) {
                        parent.appendChild(dom.createTextNode(text));
                    }
                    if (i < split.length - 1) {
                        String text1 = split[i + 1];
                        if (!text1.trim().equals("")) {
                            parent.appendChild(dom.createElement("br"));
                        }
                    }
                }
            }
        } else if (ContentConstants.RATE_IMANGE.equals(id)) {
            String rateImage = getRateImage(componentExtension.getRate());
            Element imgElem = dom.createElement("img");
            imgElem.setAttribute("src", rateImage);
            parent.appendChild(imgElem);
        } else if (ContentConstants.INSTALL_COMPONENT.equals(id)) {
            Element hyperlink = dom.createElement("a");
            String url = "http://org.eclipse.ui.intro/runAction?pluginId=org.talend.designer.components.exchange&" + "class=org.talend.designer.components.exchange.ui.actions.DownloadComponenentsAction&" + "id=org.talend.designer.components.exchange.ui.actions.DownloadComponenentsAction";
            hyperlink.setAttribute("href", url);
            Element imgElem = dom.createElement("img");
            imgElem.setAttribute("src", "imgs/install.png");
            hyperlink.appendChild(imgElem);
            parent.appendChild(hyperlink);
        } else if (ContentConstants.EXTENSION_REVIEWS.equals(id)) {
            EList<AvailableExtensionViewDetail> reviews = componentExtension.getReviews();
            for (AvailableExtensionViewDetail detail : reviews) {
                String desc = " " + detail.getTitle() + "\n\t" + detail.getComment();
                String image = getRateImage(detail.getReviewrate());
                Element imgElem = dom.createElement("img");
                imgElem.setAttribute("src", image);
                parent.appendChild(imgElem);
                Element b = dom.createElement("b");
                b.setTextContent(detail.getTitle());
                parent.appendChild(b);
                parent.appendChild(dom.createTextNode(" : " + detail.getComment() + " (" + detail.getAuthor() + ")"));
                parent.appendChild(dom.createElement("br"));
            }
        } else if (ContentConstants.WRITE_REVIEWS.equals(id)) {
            Element hyperlink = dom.createElement("a");
            String url = "http://org.eclipse.ui.intro/runAction?pluginId=org.talend.designer.components.exchange&" + "class=org.talend.designer.components.exchange.ui.htmlcontent.ExchangeUrlAction&" + "id=org.talend.designer.components.exchange.ui.htmlcontent.ExchangeUrlAction&" + "type=EDIT_REVIEWS";
            hyperlink.setAttribute("href", url);
            hyperlink.appendChild(dom.createTextNode("write a review"));
            parent.appendChild(hyperlink);
        } else if (ContentConstants.GET_EXTENSION_IMAGE.equals(id)) {
            String idExtension = componentExtension.getIdExtension();
            String typeExtension = ExchangeUtils.TYPEEXTENSION != null ? ExchangeUtils.TYPEEXTENSION : "tos";
            String imageUrl = "http://www.talendforge.org/exchange/" + typeExtension + "/upload_" + typeExtension + "/extension-" + idExtension + "/thumbnail.jpg";
            boolean touchFile = false;
            try {
                // Get the image
                URL url = new URL(imageUrl);
                InputStream is = url.openStream();
                is.close();
                touchFile = true;
            } catch (Exception e) {
                touchFile = false;
            }
            if (touchFile) {
                Element imgElem = dom.createElement("img");
                imgElem.setAttribute("src", imageUrl);
                imgElem.setAttribute("align", "middle");
                parent.appendChild(imgElem);
            }
        }
    }
}
Also used : AvailableExtensionViewDetail(org.talend.designer.components.exchange.model.AvailableExtensionViewDetail) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) URL(java.net.URL)

Aggregations

AvailableExtensionViewDetail (org.talend.designer.components.exchange.model.AvailableExtensionViewDetail)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ComponentExtension (org.talend.designer.components.exchange.model.ComponentExtension)2 JSONArray (us.monoid.json.JSONArray)2 JSONObject (us.monoid.json.JSONObject)2 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1