mirror of https://github.com/apache/cloudstack.git
quota: for BigDecimal use String in API cmd and responses
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
c4d82f0a60
commit
c8cfb383da
|
|
@ -37,8 +37,7 @@ public class QuotaCreditsCmd extends BaseCmd {
|
|||
@Inject
|
||||
QuotaDBUtilsImpl _quotaDBUtils;
|
||||
|
||||
public static final Logger s_logger = Logger
|
||||
.getLogger(QuotaStatementCmd.class.getName());
|
||||
public static final Logger s_logger = Logger.getLogger(QuotaStatementCmd.class.getName());
|
||||
|
||||
private static final String s_name = "quotacreditsresponse";
|
||||
|
||||
|
|
@ -98,11 +97,11 @@ public class QuotaCreditsCmd extends BaseCmd {
|
|||
"The account does not exists or has been removed/disabled");
|
||||
}
|
||||
|
||||
final QuotaCreditsResponse credit_response = _quotaDBUtils
|
||||
.addQuotaCredits(accountId, domainId, value, CallContext
|
||||
.current().getCallingAccount().getId());
|
||||
|
||||
setResponseObject(credit_response);
|
||||
final QuotaCreditsResponse response = _quotaDBUtils.addQuotaCredits(accountId, domainId, value,
|
||||
CallContext.current().getCallingUserId());
|
||||
response.setResponseName(getCommandName());
|
||||
response.setObjectName("quotacredits");
|
||||
setResponseObject(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,22 +16,20 @@
|
|||
//under the License.
|
||||
package org.apache.cloudstack.api.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.QuotaConfigurationResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.quota.QuotaMappingVO;
|
||||
import org.apache.cloudstack.api.response.QuotaConfigurationResponse;
|
||||
import org.apache.cloudstack.quota.QuotaDBUtilsImpl;
|
||||
import org.apache.cloudstack.quota.QuotaMappingVO;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@APICommand(name = "quotaMapping", responseObject = QuotaConfigurationResponse.class, description = "Lists all Quota and Usage configurations", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class QuotaMappingCmd extends BaseListCmd {
|
||||
|
|
|
|||
|
|
@ -16,27 +16,26 @@
|
|||
//under the License.
|
||||
package org.apache.cloudstack.api.response;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.quota.QuotaCreditsVO;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class QuotaCreditsResponse extends BaseResponse {
|
||||
|
||||
@SerializedName("credits")
|
||||
@Param(description = "the credit deposited")
|
||||
private Integer credits;
|
||||
private String credits;
|
||||
|
||||
@SerializedName("balance")
|
||||
@Param(description = "the balance credit in account")
|
||||
private Integer balance;
|
||||
private String balance;
|
||||
|
||||
@SerializedName("updated_by")
|
||||
@Param(description = "the account name of the admin who updated the credits")
|
||||
@Param(description = "the user name of the admin who updated the credits")
|
||||
private String updatedBy;
|
||||
|
||||
@SerializedName("updated_on")
|
||||
|
|
@ -47,29 +46,29 @@ public class QuotaCreditsResponse extends BaseResponse {
|
|||
super();
|
||||
}
|
||||
|
||||
public QuotaCreditsResponse(QuotaCreditsVO result) {
|
||||
public QuotaCreditsResponse(QuotaCreditsVO result, String updatedBy) {
|
||||
super();
|
||||
if (result != null) {
|
||||
this.credits = 100;
|
||||
this.balance = 200;
|
||||
this.updatedBy = "1";
|
||||
this.credits = result.getCredit().setScale(2, BigDecimal.ROUND_HALF_EVEN).toString();
|
||||
this.balance = (new BigDecimal("200")).toString();
|
||||
this.updatedBy = updatedBy;
|
||||
this.updatedOn = new Timestamp(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getCredits() {
|
||||
public String getCredits() {
|
||||
return credits;
|
||||
}
|
||||
|
||||
public void setCredits(Integer credits) {
|
||||
public void setCredits(String credits) {
|
||||
this.credits = credits;
|
||||
}
|
||||
|
||||
public Integer getBalance() {
|
||||
public String getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void setBalance(Integer balance) {
|
||||
public void setBalance(String balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ public class QuotaCreditsVO implements InternalIdentity {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
// User ID of the creditor
|
||||
@Column(name = "updated_by")
|
||||
private Long updatedBy = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,23 @@
|
|||
//under the License.
|
||||
package org.apache.cloudstack.quota;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import org.apache.cloudstack.api.command.QuotaEditMappingCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaMappingCmd;
|
||||
import org.apache.cloudstack.api.response.QuotaConfigurationResponse;
|
||||
import org.apache.cloudstack.api.response.QuotaCreditsResponse;
|
||||
import org.apache.cloudstack.api.response.QuotaStatementResponse;
|
||||
import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaMappingDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -24,23 +41,6 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.api.command.QuotaEditMappingCmd;
|
||||
import org.apache.cloudstack.api.command.QuotaMappingCmd;
|
||||
import org.apache.cloudstack.api.response.QuotaConfigurationResponse;
|
||||
import org.apache.cloudstack.api.response.QuotaCreditsResponse;
|
||||
import org.apache.cloudstack.api.response.QuotaStatementResponse;
|
||||
import org.apache.cloudstack.quota.dao.QuotaMappingDao;
|
||||
import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
|
||||
@Component
|
||||
@Local(value = QuotaDBUtilsImpl.class)
|
||||
public class QuotaDBUtilsImpl implements QuotaDBUtils {
|
||||
|
|
@ -52,6 +52,9 @@ public class QuotaDBUtilsImpl implements QuotaDBUtils {
|
|||
@Inject
|
||||
private QuotaCreditsDao _quotaCreditsDao;
|
||||
|
||||
@Inject
|
||||
private UserDao _userDao;
|
||||
|
||||
@Override
|
||||
public QuotaConfigurationResponse createQuotaConfigurationResponse(QuotaMappingVO configuration) {
|
||||
final QuotaConfigurationResponse response = new QuotaConfigurationResponse();
|
||||
|
|
@ -145,7 +148,12 @@ public class QuotaDBUtilsImpl implements QuotaDBUtils {
|
|||
txn.close();
|
||||
}
|
||||
TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
|
||||
return new QuotaCreditsResponse(result);
|
||||
String creditor = "1";
|
||||
User creditorUser = _userDao.getUser(updatedBy);
|
||||
if (creditorUser != null) {
|
||||
creditor = creditorUser.getUsername();
|
||||
}
|
||||
return new QuotaCreditsResponse(result, creditor);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue