/**
   * Static method that converts the persistence {@link VirtualMachine} object to transfer {@link
   * VirtualMachineDto} object. It also adds REST self-discover {@link RESTLink}s
   *
   * @param vm Input persistence object.
   * @param restBuilder Context-injected {@link RESTLink} builder to create the links.
   * @return the corresponding transfer object.
   * @throws Exception Serialization unhandled exception.
   */
  public static VirtualMachineDto createTransferObject(
      final Integer datacenterId,
      final Integer rackId,
      final Integer machineId,
      final VirtualMachine vm,
      final VirtualAppliance vapp,
      final IRESTBuilder restBuilder)
      throws Exception {
    // TODO: Try with enterprise and user != null
    VirtualMachineDto vmDto =
        ModelTransformer.transportFromPersistence(VirtualMachineDto.class, vm);
    if (vm.getIdType() == 0) {
      vmDto.setIdType(com.abiquo.server.core.cloud.VirtualMachine.NOT_MANAGED);
    } else {
      vmDto.setIdType(com.abiquo.server.core.cloud.VirtualMachine.MANAGED);
    }
    Integer enterpriseId = null;
    Integer userId = null;

    if (vm.getEnterprise() != null) {
      enterpriseId = vm.getEnterprise().getId();
    }
    if (vm.getUser() != null) {
      userId = vm.getUser().getId();
    }
    vmDto.setLinks(
        restBuilder.buildVirtualMachineAdminLinks(
            datacenterId,
            rackId,
            machineId,
            enterpriseId,
            userId,
            vm.getHypervisor().getType(),
            vapp,
            vm.getId()));

    final VirtualMachineTemplate vmtemplate = vm.getVirtualMachineTemplate();
    if (vmtemplate != null) {
      if (vmtemplate.getRepository() != null) {
        vmDto.addLink(
            restBuilder.buildVirtualMachineTemplateLink(
                vmtemplate.getEnterprise().getId(),
                vmtemplate.getRepository().getDatacenter().getId(),
                vmtemplate.getId()));
      } else {
        // imported virtual machines
        vmDto.addLink(
            restBuilder.buildVirtualMachineTemplateLink(
                vmtemplate.getEnterprise().getId(),
                vm.getHypervisor().getMachine().getRack().getDatacenter().getId(),
                vmtemplate.getId()));
      }
    }
    return vmDto;
  }
  public static IpPoolManagementDto createTransferObject(
      final IpPoolManagement ip, final IRESTBuilder restBuilder) throws Exception {
    IpPoolManagementDto dto =
        ModelTransformer.transportFromPersistence(IpPoolManagementDto.class, ip);

    // Create the links to the resources where the IP object is assigned to
    dto.addLinks(restBuilder.buildIpRasdLinks(ip));
    dto.addLinks(restBuilder.buildRasdLinks(ip));

    return dto;
  }