|
| 1 | +//Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +//or more contributor license agreements. See the NOTICE file |
| 3 | +//distributed with this work for additional information |
| 4 | +//regarding copyright ownership. The ASF licenses this file |
| 5 | +//to you under the Apache License, Version 2.0 (the |
| 6 | +//"License"); you may not use this file except in compliance |
| 7 | +//with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +//http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +//Unless required by applicable law or agreed to in writing, |
| 12 | +//software distributed under the License is distributed on an |
| 13 | +//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +//KIND, either express or implied. See the License for the |
| 15 | +//specific language governing permissions and limitations |
| 16 | +//under the License. |
| 17 | +package org.apache.cloudstack.api.command; |
| 18 | + |
| 19 | +import com.cloud.utils.Pair; |
| 20 | + |
| 21 | +import org.apache.cloudstack.api.ACL; |
| 22 | +import org.apache.cloudstack.api.APICommand; |
| 23 | +import org.apache.cloudstack.api.ApiConstants; |
| 24 | +import org.apache.cloudstack.api.BaseCmd; |
| 25 | +import org.apache.cloudstack.api.Parameter; |
| 26 | +import org.apache.cloudstack.api.response.AccountResponse; |
| 27 | +import org.apache.cloudstack.api.response.DomainResponse; |
| 28 | +import org.apache.cloudstack.api.response.ListResponse; |
| 29 | +import org.apache.cloudstack.api.response.QuotaCreditsResponse; |
| 30 | +import org.apache.cloudstack.api.response.QuotaResponseBuilder; |
| 31 | +import org.apache.commons.lang3.ObjectUtils; |
| 32 | +import org.apache.commons.lang3.time.DateUtils; |
| 33 | + |
| 34 | +import java.util.Calendar; |
| 35 | +import java.util.Date; |
| 36 | +import java.util.List; |
| 37 | + |
| 38 | +import javax.inject.Inject; |
| 39 | + |
| 40 | +@APICommand(name = "quotaCreditsList", responseObject = QuotaCreditsResponse.class, description = "Lists quota credits of an account.", since = "4.21.0", |
| 41 | + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) |
| 42 | +public class QuotaCreditsListCmd extends BaseCmd { |
| 43 | + |
| 44 | + @Inject |
| 45 | + QuotaResponseBuilder quotaResponseBuilder; |
| 46 | + |
| 47 | + @ACL |
| 48 | + @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "ID of the account for which the credit statement will be generated.") |
| 49 | + private Long accountId; |
| 50 | + |
| 51 | + @ACL |
| 52 | + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "ID of the domain for which credit statement will be generated. " + |
| 53 | + "Available only for administrators.") |
| 54 | + private Long domainId; |
| 55 | + |
| 56 | + @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "End date of the credit statement. If not provided, the current date will be " + |
| 57 | + "considered as the end date. " + ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS) |
| 58 | + private Date endDate; |
| 59 | + |
| 60 | + @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "Start date of the credit statement. If not provided, the first day of the current month " + |
| 61 | + "will be considered as the start date. " + ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS) |
| 62 | + private Date startDate; |
| 63 | + |
| 64 | + @Parameter(name = ApiConstants.IS_RECURSIVE, type = CommandType.BOOLEAN, description = "Whether to generate the credit statement for the provided domain and its children. " + |
| 65 | + "Defaults to false.") |
| 66 | + private Boolean recursive = false; |
| 67 | + |
| 68 | + public Long getAccountId() { |
| 69 | + return accountId; |
| 70 | + } |
| 71 | + |
| 72 | + public void setAccountId(Long accountId) { |
| 73 | + this.accountId = accountId; |
| 74 | + } |
| 75 | + |
| 76 | + public Long getDomainId() { |
| 77 | + return domainId; |
| 78 | + } |
| 79 | + |
| 80 | + public void setDomainId(Long domainId) { |
| 81 | + this.domainId = domainId; |
| 82 | + } |
| 83 | + |
| 84 | + public Date getEndDate() { |
| 85 | + return ObjectUtils.defaultIfNull(endDate, new Date()); |
| 86 | + } |
| 87 | + |
| 88 | + public void setEndDate(Date endDate) { |
| 89 | + this.endDate = endDate; |
| 90 | + } |
| 91 | + |
| 92 | + public Date getStartDate() { |
| 93 | + return ObjectUtils.defaultIfNull(startDate, DateUtils.truncate(new Date(), Calendar.MONTH)); |
| 94 | + } |
| 95 | + |
| 96 | + public void setStartDate(Date startDate) { |
| 97 | + this.startDate = startDate; |
| 98 | + } |
| 99 | + |
| 100 | + public Boolean getRecursive() { |
| 101 | + return recursive; |
| 102 | + } |
| 103 | + |
| 104 | + public void setRecursive(Boolean recursive) { |
| 105 | + this.recursive = recursive; |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public void execute() { |
| 110 | + Pair<List<QuotaCreditsResponse>, Integer> responses = quotaResponseBuilder.createQuotaCreditsListResponse(this); |
| 111 | + ListResponse<QuotaCreditsResponse> response = new ListResponse<>(); |
| 112 | + response.setResponses(responses.first(), responses.second()); |
| 113 | + response.setResponseName(getCommandName()); |
| 114 | + setResponseObject(response); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public long getEntityOwnerId() { |
| 119 | + return -1; |
| 120 | + } |
| 121 | + |
| 122 | +} |
0 commit comments