Exemple #1
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 #2
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 #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
 /**
  * @param aInstance
  * @param aNameSpace
  * @param aInstanceType
  * @param aActions
  * @param aAmount
  * @return
  */
 @Override
 public long increaseQuota(
     String aInstance, String aNameSpace, String aInstanceType, String aActions, long aAmount) {
   IQuotaSingleInstance lQSingle = getQuota(aInstance, aNameSpace, aInstanceType, aActions);
   long lResult = -1;
   if (lQSingle != null) {
     long lReduce = lQSingle.getvalue() + aAmount;
     lResult =
         setQuota(
             lQSingle.getInstance(), aNameSpace, lQSingle.getInstanceType(), aActions, lReduce);
   }
   return lResult;
 }
Exemple #5
0
  /**
   * @param aInstance
   * @param aUuid
   * @throws ExceptionQuotaNotFound
   */
  @Override
  public void unregister(String aInstance, String aUuid) throws ExceptionQuotaNotFound {

    if (!mQuotaStorage.quotaExist(aUuid)) {
      throw new ExceptionQuotaNotFound(aUuid);
    }
    IQuotaSingleInstance lQSingle = getQuota(aUuid);
    if (lQSingle.getInstance().equals(aInstance)) {
      mQuotaStorage.remove(aUuid, aInstance);
    } else {
      QuotaChildSI lChild = lQSingle.getChildQuota(aInstance);
      if (lChild != null) {
        mQuotaStorage.remove(lChild);
      }
    }
  }