Search in sources :

Example 1 with MarketplaceUnreachableException

use of org.craftercms.studio.api.v2.exception.marketplace.MarketplaceUnreachableException in project studio by craftercms.

the class MarketplaceServiceInternalImpl method searchPlugins.

@Override
public Map<String, Object> searchPlugins(final String type, final String keywords, final boolean showIncompatible, final long offset, final long limit) throws MarketplaceException {
    validate();
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url).path(Paths.PLUGIN_SEARCH).queryParam(Constants.PARAM_VERSION, version).queryParam(Constants.PARAM_EDITION, edition).queryParam(Constants.PARAM_SHOW_PENDING, showPending).queryParam(Constants.PARAM_SHOW_INCOMPATIBLE, showIncompatible).queryParam(Constants.PARAM_OFFSET, offset).queryParam(Constants.PARAM_LIMIT, limit);
    if (StringUtils.isNotEmpty(type)) {
        builder.queryParam(Constants.PARAM_TYPE, type);
    }
    if (StringUtils.isNotEmpty(keywords)) {
        builder.queryParam(Constants.PARAM_KEYWORDS, keywords);
    }
    HttpEntity<Void> request = new HttpEntity<>(null, httpHeaders);
    try {
        ResponseEntity<Map<String, Object>> response = restTemplate.exchange(builder.build().toString(), HttpMethod.GET, request, new ParameterizedTypeReference<Map<String, Object>>() {
        });
        return response.getBody();
    } catch (ResourceAccessException e) {
        throw new MarketplaceUnreachableException(url, e);
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MarketplaceUnreachableException(org.craftercms.studio.api.v2.exception.marketplace.MarketplaceUnreachableException) Map(java.util.Map) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 2 with MarketplaceUnreachableException

use of org.craftercms.studio.api.v2.exception.marketplace.MarketplaceUnreachableException in project studio by craftercms.

the class MarketplaceServiceInternalImpl method getDescriptor.

protected Map<String, Object> getDescriptor(String id, Version version) throws MarketplaceException, BlueprintNotFoundException {
    validate();
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url).path(Paths.GET_PLUGIN).pathSegment(id, String.format("%s.%s.%s", version.getMajor(), version.getMinor(), version.getPatch())).queryParam(Constants.PARAM_SHOW_PENDING, showPending);
    HttpEntity<Void> request = new HttpEntity<>(null, httpHeaders);
    try {
        ResponseEntity<Map<String, Object>> response = restTemplate.exchange(builder.build().toString(), HttpMethod.GET, request, new ParameterizedTypeReference<Map<String, Object>>() {
        });
        return response.getBody();
    } catch (ResourceAccessException e) {
        throw new MarketplaceUnreachableException(url, e);
    } catch (IllegalArgumentException e) {
        throw new BlueprintNotFoundException(String.format("Blueprint not found in the Marketplace: %s %s.%s.%s", id, version.getMajor(), version.getMinor(), version.getPatch()));
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) BlueprintNotFoundException(org.craftercms.studio.api.v1.exception.BlueprintNotFoundException) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MarketplaceUnreachableException(org.craftercms.studio.api.v2.exception.marketplace.MarketplaceUnreachableException) Map(java.util.Map) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Aggregations

Map (java.util.Map)2 MarketplaceUnreachableException (org.craftercms.studio.api.v2.exception.marketplace.MarketplaceUnreachableException)2 HttpEntity (org.springframework.http.HttpEntity)2 ResourceAccessException (org.springframework.web.client.ResourceAccessException)2 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)2 BlueprintNotFoundException (org.craftercms.studio.api.v1.exception.BlueprintNotFoundException)1