Exemple #1
0
  public Collection<Role> find(
      final Enterprise enterprise,
      final String filter,
      final String orderBy,
      final boolean desc,
      final Integer offset,
      final Integer numResults,
      final boolean discardNullEnterprises) {
    Criteria criteria = createCriteria(enterprise, filter, orderBy, desc, discardNullEnterprises);

    Long total = count(criteria);

    criteria = createCriteria(enterprise, filter, orderBy, desc, discardNullEnterprises);

    criteria.setFirstResult(offset * numResults);
    criteria.setMaxResults(numResults);

    List<Role> result = getResultList(criteria);

    PagedList<Role> page = new PagedList<Role>();
    page.addAll(result);
    page.setCurrentElement(offset);
    page.setPageSize(numResults);
    page.setTotalResults(total.intValue());

    return page;
  }
  public List<IpPoolManagement> findpublicIpsToPurchaseByVirtualDatacenter(
      final Integer vdcId,
      Integer startwith,
      final Integer limit,
      final String filter,
      final OrderByEnum orderByEnum,
      final Boolean descOrAsc) {
    Query finalQuery =
        getSession().createQuery(BY_VDC_TO_PURCHASE + " " + defineOrderBy(orderByEnum, descOrAsc));
    finalQuery.setParameter("vdc_id", vdcId);
    finalQuery.setParameter(
        "filterLike", filter == null || filter.isEmpty() ? "%" : "%" + filter + "%");

    // Check if the page requested is bigger than the last one
    Integer totalResults = finalQuery.list().size();

    if (limit != null) {
      finalQuery.setMaxResults(limit);
    }

    if (startwith >= totalResults) {
      startwith = totalResults - limit;
    }
    finalQuery.setFirstResult(startwith);
    finalQuery.setMaxResults(limit);

    PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list());
    ipList.setTotalResults(totalResults);
    ipList.setPageSize(limit);
    ipList.setCurrentElement(startwith);

    return ipList;
  }
  public List<IpPoolManagement> findIpsByVdc(
      final Integer vdcId,
      Integer firstElem,
      final Integer numElem,
      final String has,
      final IpPoolManagement.OrderByEnum orderby,
      final Boolean asc) {
    // Get the query that counts the total results.
    Query finalQuery = getSession().createQuery(BY_VDC + " " + defineOrderBy(orderby, asc));
    finalQuery.setParameter("vdc_id", vdcId);
    finalQuery.setParameter("filterLike", has.isEmpty() ? "%" : "%" + has + "%");

    // Check if the page requested is bigger than the last one
    Integer totalResults = finalQuery.list().size();

    if (firstElem == null) {
      firstElem = 0;
    }

    if (firstElem >= totalResults) {
      firstElem = totalResults - numElem;
    }
    finalQuery.setFirstResult(firstElem);
    finalQuery.setMaxResults(numElem);

    PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list());
    ipList.setTotalResults(totalResults);
    ipList.setPageSize(numElem);
    ipList.setCurrentElement(firstElem);

    return ipList;
  }
  /**
   * Return all the IPs from a VLAN filtered by a string and saying how many elements do you want
   * and the first element to retrieve
   *
   * @param network {@link Network} network entity that stores all the VLANs
   * @param vlanId identifier of the VLAN to search into.
   * @param has to filter the search
   * @param firstElem firstelement to retrieve.
   * @param numeElem to retrieve.
   * @return all the {@link IpPoolManagement} ips.
   */
  public List<IpPoolManagement> findIpsByNetwork(
      final Network network,
      final Integer vlanId,
      final String has,
      Integer firstElem,
      final Integer numElem) {
    Query finalQuery = getSession().createQuery(BY_NETWORK);
    finalQuery.setParameter("net_id", network.getId());
    finalQuery.setParameter("vlan_id", vlanId);
    finalQuery.setParameter("filterLike", has == null || has.isEmpty() ? "%" : "%" + has + "%");

    // Check if the page requested is bigger than the last one
    Integer totalResults = finalQuery.list().size();

    if (numElem != null) {
      finalQuery.setMaxResults(numElem);
    }

    if (firstElem >= totalResults) {
      firstElem = totalResults - 1;
      finalQuery.setMaxResults(1);
    }
    finalQuery.setFirstResult(firstElem);

    PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list());
    ipList.setTotalResults(totalResults);
    ipList.setPageSize(numElem);
    ipList.setCurrentElement(firstElem);

    return ipList;
  }
  public List<IpPoolManagement> findUsedIpsByPrivateVLAN(final Integer vlanId) {
    Query finalQuery = getSession().createQuery(BY_VLAN_USED_BY_ANY_VM + " " + defineFilterUsed());
    finalQuery.setParameter("vlan_id", vlanId);
    finalQuery.setParameter("filterLike", "%");

    Integer totalResults = finalQuery.list().size();

    PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list());
    ipList.setTotalResults(totalResults);

    return ipList;
  }
  public List<IpPoolManagement> findExternalIpsByVlan(
      final Integer entId,
      final Integer datacenterLimitId,
      final Integer vlanId,
      Integer startwith,
      final Integer limit,
      final String filter,
      final OrderByEnum orderByEnum,
      final Boolean descOrAsc,
      final Boolean onlyAvailable) {
    // TODO Auto-generated method stub
    Query finalQuery =
        getSession()
            .createQuery(
                BY_EXTERNAL_VLAN
                    + " "
                    + defineOnlyAvailableFilter(onlyAvailable)
                    + defineOrderBy(orderByEnum, descOrAsc));
    finalQuery.setParameter("ent_id", entId);
    finalQuery.setParameter("dc_limit_id", datacenterLimitId);
    finalQuery.setParameter("vlan_id", vlanId);
    finalQuery.setParameter(
        "filterLike", filter == null || filter.isEmpty() ? "%" : "%" + filter + "%");

    // Check if the page requested is bigger than the last one
    Integer totalResults = finalQuery.list().size();

    if (limit != null) {
      finalQuery.setMaxResults(limit);
    }

    if (startwith >= totalResults) {
      startwith = totalResults - limit;
    }
    finalQuery.setFirstResult(startwith);
    finalQuery.setMaxResults(limit);

    PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list());
    ipList.setTotalResults(totalResults);
    ipList.setPageSize(limit);
    ipList.setCurrentElement(startwith);

    return ipList;
  }
  public List<IpPoolManagement> findPublicIpsByVlan(
      final Integer datacenterId,
      final Integer vlanId,
      Integer startwith,
      final Integer limit,
      final String filter,
      final OrderByEnum orderByEnum,
      final Boolean descOrAsc,
      final Boolean all) {
    Query finalQuery =
        getSession()
            .createQuery(
                BY_PUBLIC_VLAN
                    + " "
                    + defineAllFilter(all)
                    + " "
                    + defineOrderBy(orderByEnum, descOrAsc));
    finalQuery.setParameter("datacenter_id", datacenterId);
    finalQuery.setParameter("vlan_id", vlanId);
    finalQuery.setParameter(
        "filterLike", filter == null || filter.isEmpty() ? "%" : "%" + filter + "%");

    // Check if the page requested is bigger than the last one
    Integer totalResults = finalQuery.list().size();

    if (limit != null) {
      finalQuery.setMaxResults(limit);
    }

    if (startwith >= totalResults) {
      startwith = totalResults - limit;
    }
    finalQuery.setFirstResult(startwith);
    finalQuery.setMaxResults(limit);

    PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list());
    ipList.setTotalResults(totalResults);
    ipList.setPageSize(limit);
    ipList.setCurrentElement(startwith);

    return ipList;
  }
  /**
   * Find all the IpPoolManagement created by a vLAN with filter options
   *
   * @param vdcId identifier of the virtual datacenter.
   * @param vlanId identifier of the vlan.
   * @param firstElem first element to retrieve.
   * @param numElem number of elements to retrieve.
   * @param has filter %like%
   * @param orderby ordering filter. {@see IpPoolManagement.OrderByEnum}
   * @param asc ordering filter, ascending = true, descending = false.
   * @return List of IP addresses that pass the filter.
   */
  public List<IpPoolManagement> findIpsByPrivateVLANFiltered(
      final Integer vdcId,
      final Integer vlanId,
      Integer firstElem,
      final Integer numElem,
      final String has,
      final IpPoolManagement.OrderByEnum orderby,
      final Boolean asc,
      final Boolean freeIps) {
    // Get the query that counts the total results.
    Query finalQuery;
    if (!freeIps) {
      finalQuery = getSession().createQuery(BY_VLAN + " " + defineOrderBy(orderby, asc));
    } else {
      finalQuery =
          getSession()
              .createQuery(
                  BY_VLAN_WITHOUT_USED_IPS
                      + " "
                      + defineFilterAvailable()
                      + defineOrderBy(orderby, asc));
    }
    finalQuery.setParameter("vdc_id", vdcId);
    finalQuery.setParameter("vlan_id", vlanId);
    finalQuery.setParameter("filterLike", has.isEmpty() ? "%" : "%" + has + "%");

    // Check if the page requested is bigger than the last one
    Integer totalResults = finalQuery.list().size();

    if (firstElem >= totalResults) {
      firstElem = totalResults - numElem;
    }
    finalQuery.setFirstResult(firstElem);
    finalQuery.setMaxResults(numElem);

    PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list());
    ipList.setTotalResults(totalResults);
    ipList.setPageSize(numElem);
    ipList.setCurrentElement(firstElem);

    return ipList;
  }