/**
   * Handles listing of shallow metric representations. Method still has to be overridden (and
   * annotated) in subclasses because of the way {@link PagedResourcesAssemblerArgumentResolver}
   * works.
   */
  protected PagedResources<MetricResource> list(
      Pageable pageable, PagedResourcesAssembler<M> pagedAssembler) {
    /* Page */ Iterable<M> metrics = repository.findAll(/* pageable */ );

    // Ok for now until we use PagingAndSortingRepo as we know we have lists
    Page<M> page = new PageImpl<M>((List<M>) metrics);
    return pagedAssembler.toResource(page, shallowResourceAssembler);
  }
  public WebsiteResource toResource() {
    UserAccount currentUser = this.userAccountService.getCurrentUser();
    WebsiteResource resource = new WebsiteResource();
    resource.setAuthenticated(currentUser != null);

    try {
      resource.add(
          linkTo(methodOn(WebsiteRestController.class).getPublicWebsiteResource()).withSelfRel());

      String baseUri = BasicLinkBuilder.linkToCurrentMapping().toString();

      Link blogsLink =
          new Link(
              new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_SITE_BLOGS),
              WebsiteResource.LINK_NAME_BLOGS);
      resource.add(assembler.appendPaginationParameterTemplates(blogsLink));

      Link blogLink =
          new Link(
              new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_SITE_BLOGS_BLOG),
              WebsiteResource.LINK_NAME_BLOG);
      resource.add(blogLink);

      resource.add(
          linkTo(methodOn(WebsiteRestController.class).getCurrentUserAccount())
              .withRel(WebsiteResource.LINK_NAME_CURRENT_USER));
      resource.add(
          linkTo(methodOn(WebsiteRestController.class).getLatestBlogPost())
              .withRel(WebsiteResource.LINK_NAME_LATEST_BLOG));
      resource.add(
          linkTo(methodOn(WebsiteRestController.class).getRecentPublicBlogPosts())
              .withRel(WebsiteResource.LINK_NAME_RECENT_BLOGS));
      resource.add(
          linkTo(methodOn(WebsiteRestController.class).getRecentPublicCommentPosts())
              .withRel(WebsiteResource.LINK_NAME_RECENT_COMMENTS));
      resource.add(
          linkTo(methodOn(WebsiteRestController.class).getTagCloud())
              .withRel(WebsiteResource.LINK_NAME_TAG_CLOUD));

      Link profileLink =
          new Link(
              new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_SITE_PROFILES_USER),
              WebsiteResource.LINK_NAME_PROFILE);
      resource.add(profileLink);

      Link postCommentLink =
          new Link(
              new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_USER_BLOGS_BLOG_COMMENTS),
              WebsiteResource.LINK_NAME_POST_COMMENT);
      resource.add(postCommentLink);

    } catch (ResourceNotFoundException ex) {
    }

    return resource;
  }
    @RequestMapping("/persons")
    PagedResources<Resource<Person>> sample(Pageable pageable) {

      Page<Person> page =
          new PageImpl<Person>(
              Arrays.asList(new Person()),
              pageable,
              pageable.getOffset() + pageable.getPageSize() + 1);

      return assembler.toResource(page);
    }
예제 #4
0
  @RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=utf-8")
  public PagedResources<UserResource> collectionList(
      Pageable pageable,
      PagedResourcesAssembler<User> assembler,
      @RequestParam(value = "firstName", required = false) String firstName,
      @RequestParam(value = "lastName", required = false) String lastName,
      @RequestParam(value = "mail", required = false) String mail,
      HttpServletRequest httpServletRequest) {

    Page<User> users = null;

    try {
      if (firstName != null || lastName != null || mail != null) {

        if (firstName == null) firstName = "";
        if (lastName == null) lastName = "";
        if (mail == null) mail = "";

        users =
            userRepo.findByLastNameLikeIgnoreCaseAndFirstNameLikeIgnoreCaseAndMailLikeIgnoreCase(
                "%" + lastName + "%", "%" + firstName + "%", "%" + mail + "%", pageable);
      } else {
        users = userRepo.findAllPaged(pageable);
      }

    } catch (DataAccessException e) {
      String msg = "Can't retrieve asked users from DB";
      logger.error(msg, e);
      throw new DefaultSportManagerException(
          new ErrorResource("db error", msg, HttpStatus.INTERNAL_SERVER_ERROR));
    }

    PagedResources<UserResource> resources = assembler.toResource(users, userResourceAssembler);
    resources.add(linkTo(UserController.class).withSelfRel());
    if (httpServletRequest.isUserInRole("AK_ADMIN")) {
      resources.add(linkTo(UserController.class).withRel(ActionsConstants.CREATE_VIA_POST));
      // On rajoute les liens sur les users
      for (UserResource resource : resources) {
        resource.add(
            linkTo(methodOn(UserController.class).userGet(resource.getTech_id(), null))
                .withRel(ActionsConstants.UPDATE_VIA_PUT));
        resource.add(
            linkTo(methodOn(UserController.class).userGet(resource.getTech_id(), null))
                .withRel(ActionsConstants.DELETE_VIA_DELETE));
      }
    }
    return resources;
  }
 /**
  * List all the available containers along with the message rates for each deployed modules.
  *
  * @throws ModuleMessageRateNotFoundException
  * @throws JSONException
  */
 @RequestMapping(value = "", method = RequestMethod.GET)
 @ResponseStatus(HttpStatus.OK)
 @ResponseBody
 public PagedResources<DetailedContainerResource> list(
     Pageable pageable, PagedResourcesAssembler<DetailedContainer> assembler)
     throws ModuleMessageRateNotFoundException, JSONException {
   Page<DetailedContainer> containers = containerRepository.findAllRuntimeContainers(pageable);
   for (DetailedContainer container : containers) {
     String containerHost = container.getAttributes().getIp();
     String containerManagementPort = container.getAttributes().getManagementPort();
     if (StringUtils.hasText(containerManagementPort)
         && enableMessageRates.equalsIgnoreCase("true")) {
       Map<String, HashMap<String, Double>> messageRates =
           new HashMap<String, HashMap<String, Double>>();
       for (ModuleMetadata moduleMetadata : container.getDeployedModules()) {
         String moduleName = moduleMetadata.getName();
         String moduleLabel = moduleName.substring(0, moduleName.indexOf('.'));
         String request =
             CONTAINER_HOST_URI_PROTOCOL
                 + containerHost
                 + ":"
                 + containerManagementPort
                 + "/management/jolokia/read/xd."
                 + moduleMetadata.getUnitName()
                 + ":module="
                 + moduleLabel
                 + ".*,component=*,name=%s/MeanSendRate";
         try {
           HashMap<String, Double> rate = new HashMap<String, Double>();
           if (moduleMetadata.getModuleType().equals(ModuleType.source)) {
             rate.put("output", getMessageRate(String.format(request, "output")));
           } else if (moduleMetadata.getModuleType().equals(ModuleType.sink)) {
             rate.put("input", getMessageRate(String.format(request, "input")));
           } else if (moduleMetadata.getModuleType().equals(ModuleType.processor)) {
             rate.put("output", getMessageRate(String.format(request, "output")));
             rate.put("input", getMessageRate(String.format(request, "input")));
           }
           messageRates.put(moduleMetadata.getQualifiedId(), rate);
         } catch (RestClientException e) {
           throw new ModuleMessageRateNotFoundException(e.getMessage());
         }
       }
       container.setMessageRates(messageRates);
     }
   }
   return assembler.toResource(containers, resourceAssembler);
 }
  /** List module registrations. */
  @RequestMapping(method = RequestMethod.GET)
  @ResponseStatus(HttpStatus.OK)
  public PagedResources<? extends ModuleRegistrationResource> list(
      PagedResourcesAssembler<ArtifactRegistration> assembler,
      @RequestParam(value = "type", required = false) ArtifactType type,
      @RequestParam(value = "detailed", defaultValue = "false") boolean detailed) {

    List<ArtifactRegistration> list = new ArrayList<>(registry.findAll());
    for (Iterator<ArtifactRegistration> iterator = list.iterator(); iterator.hasNext(); ) {
      ArtifactType artifactType = iterator.next().getType();
      if ((type != null && artifactType != type) || artifactType == ArtifactType.library) {
        iterator.remove();
      }
    }
    Collections.sort(list);
    return assembler.toResource(new PageImpl<>(list), moduleAssembler);
  }