/** {@inheritDoc} */
  @Override
  public Collection<CacheEntity> getCaches(final UriInfo info) {
    LOG.debug(
        String.format("Invoking CachesResourceServiceImpl.getCaches: %s", info.getRequestUri()));

    validator.validateSafe(info);

    String cacheManagerNames =
        info.getPathSegments().get(1).getMatrixParameters().getFirst("names");
    Set<String> cmNames =
        cacheManagerNames == null
            ? null
            : new HashSet<String>(Arrays.asList(cacheManagerNames.split(",")));

    String cacheNames = info.getPathSegments().get(2).getMatrixParameters().getFirst("names");
    Set<String> cNames =
        cacheNames == null ? null : new HashSet<String>(Arrays.asList(cacheNames.split(",")));

    MultivaluedMap<String, String> qParams = info.getQueryParameters();
    List<String> attrs = qParams.get(ATTR_QUERY_KEY);
    Set<String> cAttrs = attrs == null || attrs.isEmpty() ? null : new HashSet<String>(attrs);

    try {
      return entityResourceFactory.createCacheEntities(cmNames, cNames, cAttrs);
    } catch (ServiceExecutionException e) {
      throw new ResourceRuntimeException(
          "Failed to get caches", e, Response.Status.BAD_REQUEST.getStatusCode());
    }
  }
  /** {@inheritDoc} */
  @Override
  public void updateCacheManager(UriInfo info, CacheManagerEntity resource) {
    LOG.info(String.format("Invoking updateCacheManager: %s", info.getRequestUri()));

    validator.validate(info);

    String cacheManagerName = info.getPathSegments().get(1).getMatrixParameters().getFirst("names");

    try {
      cacheMgrSvc.updateCacheManager(cacheManagerName, resource);
    } catch (ServiceExecutionException e) {
      LOG.error("Failed to update cache manager.", e.getCause());
      throw new WebApplicationException(
          Response.status(Response.Status.BAD_REQUEST).entity(e.getCause().getMessage()).build());
    }
  }
  /** {@inheritDoc} */
  @Override
  public void createOrUpdateCache(final UriInfo info, CacheEntity resource) {
    LOG.debug(
        String.format(
            "Invoking CachesResourceServiceImpl.createOrUpdateCache: %s", info.getRequestUri()));

    validator.validate(info);

    String cacheManagerName = info.getPathSegments().get(1).getMatrixParameters().getFirst("names");

    String cacheName = info.getPathSegments().get(2).getMatrixParameters().getFirst("names");

    try {
      cacheSvc.createOrUpdateCache(cacheManagerName, cacheName, resource);
    } catch (ServiceExecutionException e) {
      throw new ResourceRuntimeException(
          "Failed to create or update cache", e, Response.Status.BAD_REQUEST.getStatusCode());
    }
  }
  /** {@inheritDoc} */
  public Collection<CacheManagerEntity> getCacheManagers(UriInfo info) {
    LOG.info(String.format("Invoking getCacheManagers: %s", info.getRequestUri()));

    validator.validateSafe(info);

    String names = info.getPathSegments().get(1).getMatrixParameters().getFirst("names");
    Set<String> cmNames =
        names == null ? null : new HashSet<String>(Arrays.asList(names.split(",")));

    MultivaluedMap<String, String> qParams = info.getQueryParameters();
    List<String> attrs = qParams.get(ATTR_QUERY_KEY);
    Set<String> cmAttrs = attrs == null || attrs.isEmpty() ? null : new HashSet<String>(attrs);

    try {
      return entityResourceFactory.createCacheManagerEntities(cmNames, cmAttrs);
    } catch (ServiceExecutionException e) {
      LOG.error("Failed to get cache managers.", e.getCause());
      throw new WebApplicationException(
          Response.status(Response.Status.BAD_REQUEST).entity(e.getCause().getMessage()).build());
    }
  }
Exemplo n.º 5
0
  @Override
  public Collection<CacheManagerConfigEntity> getCacheManagerConfigs(UriInfo info) {
    LOG.debug(
        String.format(
            "Invoking CacheManagerConfigsResourceServiceImpl.getXMLCacheManagerConfigs: %s",
            info.getRequestUri()));

    validator.validateSafe(info);

    String names = info.getPathSegments().get(1).getMatrixParameters().getFirst("names");
    Set<String> cmNames =
        names == null ? null : new HashSet<String>(Arrays.asList(names.split(",")));

    try {
      return entityResourceFactory.createCacheManagerConfigEntities(cmNames);
    } catch (ServiceExecutionException e) {
      throw new ResourceRuntimeException(
          "Failed to get xml cache manager configs",
          e,
          Response.Status.BAD_REQUEST.getStatusCode());
    }
  }