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