Package com.abiquo.model.rest

Examples of com.abiquo.model.rest.RESTLink


    * Returns the URI that identifies the transport object
    *
    * @return The URI identifying the transport object
    */
   public URI getURI() {
      RESTLink link = LinkUtils.getSelfLink(target);
      return link == null ? null : URI.create(link.getHref());
   }
View Full Code Here


   /**
    * Refresh the state of the current object.
    */
   @SuppressWarnings("unchecked")
   public void refresh() {
      RESTLink link = checkNotNull(LinkUtils.getSelfLink(target), ValidationErrors.MISSING_REQUIRED_LINK + " edit/self");

      HttpResponse response = context.getApi().get(link);

      ParseXMLWithJAXB<T> parser = new ParseXMLWithJAXB<T>(context.utils().xml(), TypeLiteral.get((Class<T>) target
            .getClass()));
View Full Code Here

   /**
    * Update or creates a link of "target" with the uri of a link from "source".
    */
   protected <T1 extends SingleResourceTransportDto, T2 extends SingleResourceTransportDto> void updateLink(
         final T1 target, final String targetLinkRel, final T2 source, final String sourceLinkRel) {
      RESTLink parent = null;

      checkNotNull(source.searchLink(sourceLinkRel), ValidationErrors.MISSING_REQUIRED_LINK);

      // Insert
      if ((parent = target.searchLink(targetLinkRel)) == null) {
         target.addLink(new RESTLink(targetLinkRel, source.searchLink(sourceLinkRel).getHref()));
      }
      // Replace
      else {
         parent.setHref(source.searchLink(sourceLinkRel).getHref());
      }
   }
View Full Code Here

      VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
      dto.setId(5);
      dto.setName("Template");
      dto.setDescription("Template description");
      dto.addLink(new RESTLink("diskfile", "http://foo/bar"));
      dto.addLink(new RESTLink("datacenter", "http://foo/bar/4"));

      Image image = function.apply(wrap(context, VirtualMachineTemplate.class, dto));

      verify(regionMap);
      verify(dcToLocation);
View Full Code Here

      VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
      dto.setId(5);
      dto.setName("Template");
      dto.setDescription("Template description");
      dto.addLink(new RESTLink("datacenter", "http://foo/bar/4"));

      Image image = function.apply(wrap(context, VirtualMachineTemplate.class, dto));

      verify(regionMap);
      verify(dcToLocation);
View Full Code Here

    * @param acceptedRequest
    *           The accepted request dto.
    * @return The async task.
    */
   protected AsyncTask<?, ?> getTask(final AcceptedRequestDto<String> acceptedRequest) {
      RESTLink taskLink = acceptedRequest.getStatusLink();
      checkNotNull(taskLink, ValidationErrors.MISSING_REQUIRED_LINK + AsyncTask.class);

      // This will return null on untrackable tasks
      TaskDto dto = context.getApi().getTaskApi().getTask(taskLink);
      return newTask(context, dto);
View Full Code Here

      protected Function<Object, IterableWithMarker<T>> nextPage(final PaginatedCollection<T, W> input) {
         return new Function<Object, IterableWithMarker<T>>() {
            @Override
            public IterableWithMarker<T> apply(Object marker) {
               checkArgument(marker instanceof RESTLink, "Marker must be a RESTLink");
               RESTLink next = RESTLink.class.cast(marker);

               // The Abiquo API does not provide the media types in the
               // pagination links, but it will be the same type than the
               // current page, so just set it.
               next.setType(input.delegate.getMediaType());

               W nextPage = parser.apply(api.get(next));
               return new PaginatedCollection<T, W>(api, nextPage, parser);
            }
         };
View Full Code Here

      protected Function<Object, IterableWithMarker<UserDto>> nextPage(PaginatedCollection<UserDto, UsersDto> input) {
         return new Function<Object, IterableWithMarker<UserDto>>() {
            @Override
            public IterableWithMarker<UserDto> apply(Object marker) {
               checkArgument(marker instanceof RESTLink, "Marker must be a RESTLink");
               RESTLink next = RESTLink.class.cast(marker);

               // The Abiquo API does not provide the media types in the
               // pagination links, but it will be the same type than the
               // current page, so just set it.
               next.setType(UsersDto.BASE_MEDIA_TYPE);

               UsersDto nextPage = parser.apply(api.get(next));
               return new UserPaginatedCollection(api, nextPage, parser);
            }
         };
View Full Code Here

         // default behavior to handle this, and to adapt the query
         // parameters returned in the pagination links to what the api
         // expects in the GET requests
         if (next.isPresent()) {
            checkArgument(next.get() instanceof RESTLink, "Marker must be a RESTLink");
            RESTLink link = RESTLink.class.cast(next.get());

            // Get the conflicting query parameters and remove them from the
            // query parameter map
            Multimap<String, String> params = queryParser().apply(URI.create(link.getHref()).getRawQuery());
            String limit = getFirst(params.removeAll("limit"), null);
            String startwith = getFirst(params.removeAll("startwith"), null);

            // Next page links always have both query parameters. Otherwise
            // assume there is no next page
            if (limit != null && startwith != null) {
               int resultsPerPage = Integer.parseInt(limit);
               int totalResults = delegate.getTotalSize();
               int pageNumber = Integer.parseInt(startwith) - resultsPerPage;

               // Check if there is really a next page, and then return the
               // marker with the appropriate values
               if (totalResults / (double) resultsPerPage > pageNumber + 1) {
                  params.put("numResults", limit);
                  params.put("page", String.valueOf(pageNumber + 1));

                  // Build the new URI stripping the existing query
                  // parameters and using the new ones
                  String uri = link.getHref().substring(0, link.getHref().indexOf('?') + 1);
                  uri += encodeQueryLine(params);

                  return Optional.<Object> of(new RESTLink(link.getRel(), uri));
               }
            }
         }

         return Optional.absent();
View Full Code Here

   }

   public static VirtualDatacenterDto virtualDatacenterPut() {
      VirtualDatacenterDto virtualDatacenter = virtualDatacenterPost();
      virtualDatacenter.setId(1);
      virtualDatacenter.addLink(new RESTLink("datacenter", "http://localhost/api/admin/datacenters/1"));
      virtualDatacenter.addLink(new RESTLink("disks", "http://localhost/api/cloud/virtualdatacenters/1/disks"));
      virtualDatacenter.addLink(new RESTLink("enterprise", "http://localhost/api/admin/enterprises/1"));
      virtualDatacenter.addLink(new RESTLink("edit", "http://localhost/api/cloud/virtualdatacenters/1"));
      virtualDatacenter.addLink(new RESTLink("tiers", "http://localhost/api/cloud/virtualdatacenters/1/tiers"));
      virtualDatacenter.addLink(new RESTLink("virtualappliances",
            "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances"));
      virtualDatacenter.addLink(new RESTLink("volumes", "http://localhost/api/cloud/virtualdatacenters/1/volumes"));
      virtualDatacenter.addLink(new RESTLink("privatenetworks",
            "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks"));
      virtualDatacenter.addLink(new RESTLink("defaultnetwork",
            "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1"));
      virtualDatacenter.addLink(new RESTLink("defaultvlan",
            "http://localhost/api/cloud/virtualdatacenters/1/action/defaultvlan"));
      virtualDatacenter.addLink(new RESTLink("topurchase",
            "http://localhost/api/cloud/virtualdatacenters/1/publicips/topurchase"));
      virtualDatacenter.addLink(new RESTLink("purchased",
            "http://localhost/api/cloud/virtualdatacenters/1/publicips/purchased"));
      virtualDatacenter.addLink(new RESTLink("templates",
            "http://localhost/api/cloud/virtualdatacenters/1/action/templates"));
      return virtualDatacenter;

   }
View Full Code Here

TOP

Related Classes of com.abiquo.model.rest.RESTLink

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.