/** * @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); } }
/** * @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; } }