/**
  * Retrieve the attribute of an entity
  *
  * @param entityId the entity ID
  * @param type optional entity type to avoid ambiguity when multiple entities have the same ID,
  *     null or zero-length for empty
  * @param attributeName the attribute name
  * @return
  */
 public ListenableFuture<Object> getAttributeValue(
     String entityId, String type, String attributeName) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/entities/{entityId}/attrs/{attributeName}/value");
   addParam(builder, "type", type);
   return adapt(
       request(
           HttpMethod.GET,
           builder.buildAndExpand(entityId, attributeName).toUriString(),
           null,
           Object.class));
 }
  private UriComponents applyContributers(
      UriComponentsBuilder builder,
      Method method,
      Object[] argumentValues,
      Map<String, Object> uriVars) {

    if (this.contributors.isEmpty()) {
      return builder.buildAndExpand(uriVars);
    }

    int paramCount = method.getParameters().length;
    int argCount = argumentValues.length;

    Assert.isTrue(
        paramCount == argCount,
        "Number of method parameters "
            + paramCount
            + " does not match number of argument values "
            + argCount);

    for (int i = 0; i < paramCount; i++) {
      MethodParameter param = new MethodParameter(method, i);
      param.initParameterNameDiscovery(parameterNameDiscoverer);
      for (UriComponentsContributor c : this.contributors) {
        if (c.supportsParameter(param)) {
          c.contributeMethodArgument(
              param, argumentValues[i], builder, uriVars, this.conversionService);
          break;
        }
      }
    }

    return builder.buildAndExpand(uriVars);
  }
Esempio n. 3
0
  private String path(UriComponentsBuilder builder, Page page, boolean encode) {
    Map<String, Object> params = new HashMap<>();

    PageTree pageTree =
        (PageTree) processingContext.getContext().getVariables().get("PAGE_TREE_ALL");
    //		PageTree pageTree =
    // defaultModelAttributeService.readPageTree(LocaleContextHolder.getLocale().getLanguage());
    List<String> codes = new LinkedList<>();
    Page parent = page.getParent();
    while (parent != null) {
      codes.add(parent.getCode());
      parent =
          (parent.getParent() != null)
              ? pageTree.getPageByCode(parent.getParent().getCode())
              : null;
    }

    Collections.reverse(codes);
    codes.add(page.getCode());

    for (int i = 0; i < codes.size(); i++) {
      String key = "code" + i;
      builder.path("/{" + key + "}");
      params.put(key, codes.get(i));
    }

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
      components = components.encode();
    }
    return components.toUriString();
  }
 /**
  * Delete an entity
  *
  * @param entityId the entity ID
  * @param type optional entity type to avoid ambiguity when multiple entities have the same ID,
  *     null or zero-length for empty
  * @return the listener to notify of completion
  */
 public ListenableFuture<Void> deleteEntity(String entityId, String type) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/entities/{entityId}");
   addParam(builder, "type", type);
   return adapt(
       request(
           HttpMethod.DELETE, builder.buildAndExpand(entityId).toUriString(), null, Void.class));
 }
 /**
  * Retrieve an entity type
  *
  * @param entityType the entityType to retrieve
  * @return an entity type
  */
 public ListenableFuture<EntityType> getEntityType(String entityType) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/types/{entityType}");
   return adapt(
       request(
           HttpMethod.GET,
           builder.buildAndExpand(entityType).toUriString(),
           null,
           EntityType.class));
 }
 /**
  * Retrieve the registration by registration ID
  *
  * @param registrationId the registration ID
  * @return registration
  */
 public ListenableFuture<Registration> getRegistration(String registrationId) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/registrations/{registrationId}");
   return adapt(
       request(
           HttpMethod.GET,
           builder.buildAndExpand(registrationId).toUriString(),
           null,
           Registration.class));
 }
 /**
  * Delete the subscription by subscription ID
  *
  * @param subscriptionId the subscription ID
  * @return
  */
 public ListenableFuture<Void> deleteSubscription(String subscriptionId) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/subscriptions/{subscriptionId}");
   return adapt(
       request(
           HttpMethod.DELETE,
           builder.buildAndExpand(subscriptionId).toUriString(),
           null,
           Void.class));
 }
 /**
  * Get an entity
  *
  * @param entityId the entity ID
  * @param type optional entity type to avoid ambiguity when multiple entities have the same ID,
  *     null or zero-length for empty
  * @param attrs the list of attributes to retreive for this entity, null or empty means all
  *     attributes
  * @return the entity
  */
 public ListenableFuture<Entity> getEntity(
     String entityId, String type, Collection<String> attrs) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/entities/{entityId}");
   addParam(builder, "type", type);
   addParam(builder, "attrs", attrs);
   return adapt(
       request(
           HttpMethod.GET, builder.buildAndExpand(entityId).toUriString(), null, Entity.class));
 }
 /**
  * Update the registration by registration ID
  *
  * @param registrationId the registration ID
  * @return
  */
 public ListenableFuture<Void> updateRegistration(
     String registrationId, Registration registration) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/registrations/{registrationId}");
   return adapt(
       request(
           HttpMethod.PATCH,
           builder.buildAndExpand(registrationId).toUriString(),
           registration,
           Void.class));
 }
 /**
  * Replace all the existing attributes of an entity with a new set of attributes
  *
  * @param entityId the entity ID
  * @param type optional entity type to avoid ambiguity when multiple entities have the same ID,
  *     null or zero-length for empty
  * @param attributes the new set of attributes
  * @return the listener to notify of completion
  */
 public ListenableFuture<Void> replaceEntity(
     String entityId, String type, Map<String, Attribute> attributes) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/entities/{entityId}");
   addParam(builder, "type", type);
   return adapt(
       request(
           HttpMethod.PUT,
           builder.buildAndExpand(entityId).toUriString(),
           attributes,
           Void.class));
 }
 /**
  * Delete the attribute of an entity
  *
  * @param entityId the entity ID
  * @param type optional entity type to avoid ambiguity when multiple entities have the same ID,
  *     null or zero-length for empty
  * @param attributeName the attribute name
  * @return
  */
 public ListenableFuture<Attribute> deleteAttribute(
     String entityId, String type, String attributeName) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/entities/{entityId}/attrs/{attributeName}");
   addParam(builder, "type", type);
   return adapt(
       request(
           HttpMethod.DELETE,
           builder.buildAndExpand(entityId, attributeName).toUriString(),
           null,
           Attribute.class));
 }
Esempio n. 12
0
  private String path(UriComponentsBuilder builder, Article article, boolean encode) {
    Map<String, Object> params = new HashMap<>();
    builder.path("/{year}/{month}/{day}/{code}");
    params.put("year", String.format("%04d", article.getDate().getYear()));
    params.put("month", String.format("%02d", article.getDate().getMonthOfYear()));
    params.put("day", String.format("%02d", article.getDate().getDayOfMonth()));
    params.put("code", article.getCode());

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
      components = components.encode();
    }
    return components.toUriString();
  }
 /**
  * Update existing or append some attributes to an entity
  *
  * @param entityId the entity ID
  * @param type optional entity type to avoid ambiguity when multiple entities have the same ID,
  *     null or zero-length for empty
  * @param attributes the attributes to update or to append
  * @param append if true, will only allow to append new attributes
  * @return the listener to notify of completion
  */
 public ListenableFuture<Void> updateEntity(
     String entityId, String type, Map<String, Attribute> attributes, boolean append) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/entities/{entityId}");
   addParam(builder, "type", type);
   if (append) {
     addParam(builder, "options", "append");
   }
   return adapt(
       request(
           HttpMethod.POST,
           builder.buildAndExpand(entityId).toUriString(),
           attributes,
           Void.class));
 }
 /**
  * Retrieve the attribute of an entity
  *
  * @param entityId the entity ID
  * @param type optional entity type to avoid ambiguity when multiple entities have the same ID,
  *     null or zero-length for empty
  * @param attributeName the attribute name
  * @return
  */
 public ListenableFuture<String> getAttributeValueAsString(
     String entityId, String type, String attributeName) {
   UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
   builder.path("v2/entities/{entityId}/attrs/{attributeName}/value");
   addParam(builder, "type", type);
   HttpHeaders httpHeaders = cloneHttpHeaders();
   httpHeaders.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN));
   return adapt(
       request(
           HttpMethod.GET,
           builder.buildAndExpand(entityId, attributeName).toUriString(),
           httpHeaders,
           null,
           String.class));
 }
Esempio n. 15
0
  private String link(Article article) {
    UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath();
    Map<String, Object> params = new HashMap<>();

    Blog blog = blogService.readBlogById(Blog.DEFAULT_ID);
    if (blog.getLanguages().size() > 1) {
      builder.path("/{language}");
      params.put("language", LocaleContextHolder.getLocale().getLanguage());
    }
    builder.path("/{year}/{month}/{day}/{code}");
    params.put("year", String.format("%04d", article.getDate().getYear()));
    params.put("month", String.format("%02d", article.getDate().getMonthOfYear()));
    params.put("day", String.format("%02d", article.getDate().getDayOfMonth()));
    params.put("code", article.getCode());
    return builder.buildAndExpand(params).encode().toUriString();
  }
Esempio n. 16
0
  protected void buildFeedMetadata(
      Map<String, Object> model, Feed feed, HttpServletRequest request) {
    Blog blog = blogService.readBlogById(Blog.DEFAULT_ID);
    String language = LocaleContextHolder.getLocale().getLanguage();

    feed.setTitle(blog.getTitle(language));
    Content info = new Content();
    info.setValue(blog.getTitle(language));
    feed.setInfo(info);

    ArrayList<Link> links = new ArrayList<>();
    Link link = new Link();
    UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath();
    link.setHref(builder.buildAndExpand().toUriString());
    links.add(link);
    feed.setOtherLinks(links);
    //		feed.setIcon("http://" + settings.getAsString(Setting.Key.SITE_URL) +
    // "resources/default/img/favicon.ico");
  }
  @RequestMapping(method = RequestMethod.GET)
  public String search(
      @PathVariable String language,
      @Validated ArticleSearchForm form,
      BindingResult result,
      @PageableDefault(50) Pageable pageable,
      Model model,
      HttpSession session) {
    Page<Article> articles = articleService.readArticles(form.toArticleSearchRequest(), pageable);

    new DomainObjectSearchCondition<>(session, form, pageable);

    model.addAttribute("form", form);
    model.addAttribute("articles", articles);
    model.addAttribute("pageable", pageable);

    UriComponentsBuilder builder = UriComponentsBuilder.fromPath(Application.ADMIN_SERVLET_PATH);
    builder.path("/{language}/articles/index");
    builder.queryParams(form.toQueryParams());
    String url = builder.buildAndExpand(language).toString();
    model.addAttribute("pagination", new Pagination<>(articles, url));
    return "article/index";
  }