Exemple #1
0
  /**
   * @param aUuid
   * @param aInstance
   * @param aInstanceType
   * @throws Exception
   */
  @Override
  public void register(String aUuid, String aInstance, String aInstanceType) throws Exception {

    if (!mQuotaStorage.quotaExist(aUuid)) {
      throw new ExceptionQuotaNotFound(aUuid);
    }
    // Creating the child Quota
    IQuotaSingleInstance lSingleInstance = mQuotaStorage.getQuotaByUuid(aUuid);

    if (lSingleInstance.getInstance().equals(aInstance)) {
      throw new ExceptionQuotaAlreadyExist(aInstance);
    }

    QuotaChildSI lChildQuota = new QuotaChildSI(aInstance, aUuid, aInstanceType);

    // if a register quota occur over a quota with InstanceType user
    // The quota is shared between the users of this quota, by this reason
    // The quota is register to the parent quota with 0 as their own value.
    if (lSingleInstance.getInstanceType().equals("User")) {
      lChildQuota.setValue(0);
    } else {
      lChildQuota.setValue(lSingleInstance.getvalue());
    }
    boolean lResult;

    lResult = lSingleInstance.addChildQuota(lChildQuota);

    if (lResult == true) {
      lResult = mQuotaStorage.save(lChildQuota);

    } else {
      throw new ExceptionQuotaAlreadyExist(aInstance);
    }
  }
Exemple #2
0
  /**
   * @param aInstance
   * @param aNameSpace
   * @param aInstanceType
   * @param aActions
   * @param aAmount
   * @return
   */
  @Override
  public long setQuota(
      String aInstance, String aNameSpace, String aInstanceType, String aActions, long aAmount) {

    IQuotaSingleInstance lQSingle = getQuota(aInstance, aNameSpace, aInstanceType, aActions);
    // if the instanceType request is Group then update the father quota.
    if (lQSingle.getInstanceType().equals("Group") && aInstanceType.equals("Group")) {
      return setQuota(lQSingle.getUuid(), aAmount);
    }

    /**
     * if the quota type of the getQuota method is User, it is possible that this quota be part of a
     * father quota.
     */
    if (lQSingle.getInstanceType().equals("User")) {
      if (mQuotaStorage.quotaExist(
          aNameSpace, mQuotaIdentifier, lQSingle.getInstance(), lQSingle.getActions())) {
        return setQuota(lQSingle.getUuid(), aAmount);
      } else {
        IQuotaSingleInstance lSingleInstance = mQuotaStorage.getQuotaByUuid(lQSingle.getUuid());
        QuotaChildSI lQChild = lSingleInstance.getChildQuota(lQSingle.getInstance());
        lQChild.setValue(aAmount);

        if (lSingleInstance.getInstanceType().equals("User")) {
          return mQuotaStorage.update(lSingleInstance.getUuid(), lQChild.getValue());
        }
        return mQuotaStorage.update(lQChild);
      }
    } else {
      return -1;
    }
  }
Exemple #3
0
  /**
   * @param aUuid
   * @param aInstance
   * @return
   */
  @Override
  public IQuotaSingleInstance getQuota(String aUuid, String aInstance) {

    IQuotaSingleInstance lQuotaInstance =
        (IQuotaSingleInstance) mQuotaStorage.getQuotaByUuid(aUuid);

    if (lQuotaInstance.getInstance().equals(aInstance)) {
      return lQuotaInstance;
    } else {

      QuotaChildSI lQuotaChild = lQuotaInstance.getChildQuota(aInstance);
      if (null != lQuotaChild) {

        IQuotaSingleInstance lSingle =
            new QuotaBaseInstance(
                lQuotaChild.getValue(),
                aInstance,
                aUuid,
                lQuotaInstance.getNamespace(),
                lQuotaInstance.getQuotaType(),
                lQuotaInstance.getQuotaIdentifier(),
                lQuotaChild.getInstanceType(),
                lQuotaInstance.getActions());

        return lSingle;
      }
    }
    return null;
  }
Exemple #4
0
  /**
   * get a IQuotaSingleInstance list and an string with the instance and return all quotas about
   * belong to this instance.
   *
   * @return
   */
  private List<IQuotaSingleInstance> findQuotasByInstance(
      List<IQuotaSingleInstance> aQuotas, String aInstance) {

    List<IQuotaSingleInstance> lQResult = new FastList<IQuotaSingleInstance>();

    if (aQuotas.size() > 0) {
      IQuotaSingleInstance lQtmp = null;
      for (Iterator<IQuotaSingleInstance> it = aQuotas.iterator(); it.hasNext(); ) {
        IQuotaSingleInstance lQuotaSingle = it.next();
        QuotaChildSI lChild;
        lChild = lQuotaSingle.getChildQuota(aInstance);
        if (null != lChild) {
          if (lQuotaSingle.getInstanceType().equals("Group")) {

            lQtmp =
                QuotaHelper.factorySingleInstance(
                    lChild.getValue(),
                    lChild.getInstance(),
                    lChild.getUuid(),
                    lQuotaSingle.getNamespace(),
                    lQuotaSingle.getQuotaType(),
                    lQuotaSingle.getQuotaIdentifier(),
                    lChild.getInstanceType(),
                    lQuotaSingle.getActions());
          }

          if (lQuotaSingle.getInstanceType().equals("User")) {

            lQtmp =
                QuotaHelper.factorySingleInstance(
                    lQuotaSingle.getvalue(),
                    lChild.getInstance(),
                    lChild.getUuid(),
                    lQuotaSingle.getNamespace(),
                    lQuotaSingle.getQuotaType(),
                    lQuotaSingle.getQuotaIdentifier(),
                    lChild.getInstanceType(),
                    lQuotaSingle.getActions());
          }

          if (lQtmp != null) {
            lQResult.add(lQtmp);
          }
        }
      }
    }
    return lQResult;
  }
Exemple #5
0
  /**
   * get a IQuotaSingleInstance list and an string with the instanceType and return the
   * IQuotaSingleInstance.
   *
   * @return
   */
  private IQuotaSingleInstance findQuotaByInstance(
      List<IQuotaSingleInstance> aQuotas, String aInstance, String aActions) {

    IQuotaSingleInstance lQResult = null;

    for (Iterator<IQuotaSingleInstance> it = aQuotas.iterator(); it.hasNext(); ) {
      IQuotaSingleInstance lQuotaSingle = it.next();
      QuotaChildSI lChild;
      lChild = lQuotaSingle.getChildQuota(aInstance);
      if (null != lChild) {
        if (!lQuotaSingle.getActions().equals(aActions)) {
          continue;
        }
        if (lQuotaSingle.getInstanceType().equals("Group")) {

          lQResult =
              QuotaHelper.factorySingleInstance(
                  lChild.getValue(),
                  lChild.getInstance(),
                  lChild.getUuid(),
                  lQuotaSingle.getNamespace(),
                  lQuotaSingle.getQuotaType(),
                  lQuotaSingle.getQuotaIdentifier(),
                  lChild.getInstanceType(),
                  lQuotaSingle.getActions());
        }

        if (lQuotaSingle.getInstanceType().equals("User")) {

          lQResult =
              QuotaHelper.factorySingleInstance(
                  lQuotaSingle.getvalue(),
                  lChild.getInstance(),
                  lChild.getUuid(),
                  lQuotaSingle.getNamespace(),
                  lQuotaSingle.getQuotaType(),
                  lQuotaSingle.getQuotaIdentifier(),
                  lChild.getInstanceType(),
                  lQuotaSingle.getActions());
        }

        return lQResult;
      }
    }
    return null;
  }