Search in sources :

Example 21 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method performQuery.

public void performQuery(IProgressMonitor monitor, Set<String> nodeIds) throws CoreException {
    Set<INode> nodes = new HashSet<INode>();
    for (String nodeId : nodeIds) {
        Node node = new Node();
        node.setId(nodeId);
        nodes.add(node);
    }
    performNodeQuery(monitor, nodes);
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) HashSet(java.util.HashSet)

Example 22 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class DefaultMarketplaceService method resolveFavoriteNodes.

private ISearchResult resolveFavoriteNodes(final List<INode> nodes, IProgressMonitor monitor, boolean filterIncompatible) throws CoreException {
    IMarketplaceService resolveService = this;
    IMarketplaceService registeredService = ServiceHelper.getMarketplaceServiceLocator().getMarketplaceService(this.getBaseUrl().toString());
    if (registeredService instanceof CachingMarketplaceService) {
        CachingMarketplaceService cachingService = (CachingMarketplaceService) registeredService;
        if (cachingService.getDelegate() == this) {
            resolveService = cachingService;
        }
    }
    final List<INode> resolvedNodes = resolveService.getNodes(nodes, monitor);
    for (ListIterator<INode> i = resolvedNodes.listIterator(); i.hasNext(); ) {
        INode resolved = i.next();
        ((Node) resolved).setUserFavorite(true);
        if (filterIncompatible && !isInstallable(resolved)) {
            i.remove();
        }
    }
    if (!filterIncompatible) {
        // sort the node list so uninstallable nodes come last
        Collections.sort(resolvedNodes, new Comparator<INode>() {

            public int compare(INode n1, INode n2) {
                if (n1 == n2) {
                    return 0;
                }
                boolean n1Installable = isInstallable(n1);
                boolean n2Installable = isInstallable(n2);
                if (n1Installable == n2Installable) {
                    return 0;
                }
                if (n1Installable) {
                    // && !n2Installable
                    return -1;
                }
                // !n1Installable && n2Installable
                return 1;
            }
        });
    }
    return new ISearchResult() {

        public List<? extends INode> getNodes() {
            return resolvedNodes;
        }

        public Integer getMatchCount() {
            return resolvedNodes.size();
        }
    };
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService)

Example 23 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class DefaultMarketplaceService method reportInstallError.

public void reportInstallError(IStatus result, Set<? extends INode> nodes, Set<String> iuIdsAndVersions, String resolutionDetails, IProgressMonitor monitor) throws CoreException {
    HttpClient client;
    URL location;
    HttpPost method;
    try {
        // $NON-NLS-1$
        location = new URL(baseUrl, "install/error/report");
        String target = location.toURI().toString();
        client = HttpUtil.createHttpClient(target);
        method = new HttpPost(target);
    } catch (URISyntaxException e) {
        throw new IllegalStateException(e);
    } catch (MalformedURLException e) {
        throw new IllegalStateException(e);
    }
    try {
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        Map<String, String> requestMetaParameters = getRequestMetaParameters();
        for (Map.Entry<String, String> metaParam : requestMetaParameters.entrySet()) {
            if (metaParam.getKey() != null) {
                parameters.add(new BasicNameValuePair(metaParam.getKey(), metaParam.getValue()));
            }
        }
        // $NON-NLS-1$
        parameters.add(new BasicNameValuePair("status", Integer.toString(result.getSeverity())));
        // $NON-NLS-1$
        parameters.add(new BasicNameValuePair("statusMessage", result.getMessage()));
        for (INode node : nodes) {
            // $NON-NLS-1$
            parameters.add(new BasicNameValuePair("node", node.getId()));
        }
        if (iuIdsAndVersions != null && !iuIdsAndVersions.isEmpty()) {
            for (String iuAndVersion : iuIdsAndVersions) {
                // $NON-NLS-1$
                parameters.add(new BasicNameValuePair("iu", iuAndVersion));
            }
        }
        // $NON-NLS-1$
        parameters.add(new BasicNameValuePair("detailedMessage", resolutionDetails));
        if (!parameters.isEmpty()) {
            // $NON-NLS-1$
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters, "UTF-8");
            method.setEntity(entity);
            client.execute(method);
        }
    } catch (IOException e) {
        String message = NLS.bind(Messages.DefaultMarketplaceService_cannotCompleteRequest_reason, location.toString(), e.getMessage());
        throw new CoreException(createErrorStatus(message, e));
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) MalformedURLException(java.net.MalformedURLException) INode(org.eclipse.epp.mpc.core.model.INode) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class DefaultMarketplaceService method related.

public SearchResult related(List<? extends INode> basedOn, IProgressMonitor monitor) throws CoreException {
    // $NON-NLS-1$
    String basedOnQuery = "";
    if (basedOn != null && !basedOn.isEmpty()) {
        StringBuilder sb = new StringBuilder().append('?').append(PARAM_BASED_ON_NODES).append('=');
        boolean first = true;
        for (INode node : basedOn) {
            if (!first) {
                sb.append('+');
            }
            sb.append(node.getId());
            first = false;
        }
        basedOnQuery = sb.toString();
    }
    Marketplace marketplace = processRequest(API_RELATED_URI + '/' + API_URI_SUFFIX + basedOnQuery, monitor);
    return createSearchResult(marketplace.getRelated());
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace)

Example 25 with INode

use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.

the class DefaultMarketplaceService method getNode.

public Node getNode(INode node, IProgressMonitor monitor) throws CoreException {
    Marketplace marketplace;
    String query;
    if (node.getId() != null) {
        // bug 304928: prefer the id method rather than the URL, since the id provides a stable URL and the
        // URL is based on the name, which could change.
        query = node.getId();
        String encodedId = urlEncode(node.getId());
        marketplace = processRequest(API_NODE_URI + '/' + encodedId + '/' + API_URI_SUFFIX, monitor);
    } else {
        query = node.getUrl();
        marketplace = processRequest(node.getUrl(), API_URI_SUFFIX, monitor);
    }
    if (marketplace.getNode().isEmpty()) {
        throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_nodeNotFound, query));
    } else if (marketplace.getNode().size() > 1) {
        throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, query));
    }
    Node resolvedNode = marketplace.getNode().get(0);
    return resolvedNode;
}
Also used : Marketplace(org.eclipse.epp.internal.mpc.core.model.Marketplace) CoreException(org.eclipse.core.runtime.CoreException) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode)

Aggregations

INode (org.eclipse.epp.mpc.core.model.INode)63 Node (org.eclipse.epp.internal.mpc.core.model.Node)13 ArrayList (java.util.ArrayList)12 CoreException (org.eclipse.core.runtime.CoreException)12 SubMonitor (org.eclipse.core.runtime.SubMonitor)12 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 ICategory (org.eclipse.epp.mpc.core.model.ICategory)8 URISyntaxException (java.net.URISyntaxException)7 NotAuthorizedException (org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException)7 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)7 IOException (java.io.IOException)6 MalformedURLException (java.net.MalformedURLException)6 List (java.util.List)6 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)6 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)6