CLOUDSTACK-8592: Adding email management APIs

This commit is contained in:
Abhinandan Prateek 2015-07-06 13:52:01 +05:30 committed by Rohit Yadav
parent 1f75299016
commit 1345b9fbfb
3 changed files with 367 additions and 0 deletions

View File

@ -0,0 +1,116 @@
//Licensed to the Apache Software Foundation (ASF) under one
//or more contributor license agreements. See the NOTICE file
//distributed with this work for additional information
//regarding copyright ownership. The ASF licenses this file
//to you under the Apache License, Version 2.0 (the
//"License"); you may not use this file except in compliance
//with the License. You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing,
//software distributed under the License is distributed on an
//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
//KIND, either express or implied. See the License for the
//specific language governing permissions and limitations
//under the License.
package org.apache.cloudstack.api.command;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.QuotaCreditsResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.quota.QuotaManager;
import org.apache.cloudstack.api.response.QuotaEmailTemplateResponse;
@APICommand(name = "quotaEmailTemplateAdd", responseObject = QuotaEmailTemplateResponse.class, description = "Add a new email template", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class QuotaEmailTemplateAddCmd extends BaseListCmd {
public static final Logger s_logger = Logger
.getLogger(QuotaEmailTemplateAddCmd.class.getName());
private static final String s_name = "quotaemailtemplateresponse";
@Inject
private QuotaManager _quotaManager;
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Account Id for which quota credits need to be added")
private String accountName;
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "Domain for which quota credits need to be added")
private Long domainId;
@Parameter(name = ApiConstants.VALUE, type = CommandType.INTEGER, entityType = DomainResponse.class, description = "Value of the credits to be added+, subtracted-")
private Integer value;
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public Long getDomainId() {
return domainId;
}
public void setDomainId(Long domainId) {
this.domainId = domainId;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public QuotaEmailTemplateAddCmd() {
super();
}
public QuotaEmailTemplateAddCmd(final QuotaManager quotaManager) {
super();
_quotaManager = quotaManager;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute() {
Long accountId = _accountService.finalyzeAccountId(accountName, domainId, null, true);
if (accountId==null){
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "The account does not exists or has been removed/disabled");
}
final QuotaCreditsResponse credit_response = _quotaManager.addQuotaCredits(accountId, domainId, value, CallContext.current().getCallingAccount().getId());
setResponseObject(credit_response);
}
}

View File

@ -0,0 +1,136 @@
//Licensed to the Apache Software Foundation (ASF) under one
//or more contributor license agreements. See the NOTICE file
//distributed with this work for additional information
//regarding copyright ownership. The ASF licenses this file
//to you under the Apache License, Version 2.0 (the
//"License"); you may not use this file except in compliance
//with the License. You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing,
//software distributed under the License is distributed on an
//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
//KIND, either express or implied. See the License for the
//specific language governing permissions and limitations
//under the License.
package org.apache.cloudstack.api.response;
import java.sql.Timestamp;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
public class QuotaEmailTemplateResponse extends BaseResponse {
@SerializedName(ApiConstants.ID)
@Param(description = "the ID of the credit")
private String id;
@SerializedName(ApiConstants.ACCOUNT)
@Param(description = "the account name of the api remaining count")
private String accountName;
@SerializedName(ApiConstants.DOMAIN_ID)
@Param(description = "the domain ID of the iam policy")
private String domainId;
@SerializedName("credits")
@Param(description = "the credit deposited")
private String credits;
@SerializedName("balance")
@Param(description = "the balance credit in account")
private String balance;
@SerializedName("updated_by")
@Param(description = "the account name of the admin who updated the credits")
private String updatedBy;
@SerializedName("updated_on")
@Param(description = "the account name of the admin who updated the credits")
private Timestamp updatedOn;
public QuotaEmailTemplateResponse() {
super();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public String getDomainId() {
return domainId;
}
public void setDomainId(String domainId) {
this.domainId = domainId;
}
public String getCredits() {
return credits;
}
public void setCredits(String credits) {
this.credits = credits;
}
public String getBalance() {
return balance;
}
public void setBalance(String balance) {
this.balance = balance;
}
public String getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
public Timestamp getUpdatedOn() {
return updatedOn;
}
public void setUpdatedOn(Timestamp updatedOn) {
this.updatedOn = updatedOn;
}
}

View File

@ -0,0 +1,115 @@
//Licensed to the Apache Software Foundation (ASF) under one
//or more contributor license agreements. See the NOTICE file
//distributed with this work for additional information
//regarding copyright ownership. The ASF licenses this file
//to you under the Apache License, Version 2.0 (the
//"License"); you may not use this file except in compliance
//with the License. You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing,
//software distributed under the License is distributed on an
//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
//KIND, either express or implied. See the License for the
//specific language governing permissions and limitations
//under the License.
package org.apache.cloudstack.quota;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name = "quota_sent_emails")
public class QuotaSentEmailsVO implements InternalIdentity {
/*
*
CREATE TABLE `cloud_usage.quota_sent_emails` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`from_address` varchar(1024) NOT NULL,
`to_address` varchar(1024) NOT NULL,
`cc_address` varchar(1024) DEFAULT NULL,
`bcc_address` varchar(1024) DEFAULT NULL,
`send_date` datetime NOT NULL,
`subject` varchar(1024) NOT NULL,
`mail_text` longtext NOT NULL,
`version` int(11) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*/
private static final long serialVersionUID = -7117933845287653210L;
@Id
@Column(name = "id")
private Long id;
@Column(name = "from_address")
private String fromAddress = null;
@Column(name = "to_address")
private String toAddress = null;
@Column(name = "cc_address")
private String ccAddress = null;
@Column(name = "bcc_address")
private String bccAddress = null;
@Column(name = "credit")
private BigDecimal credit;
@Column(name = "updated_on")
@Temporal(value = TemporalType.TIMESTAMP)
private Date updatedOn = null;
public QuotaSentEmailsVO() {
super();
}
public BigDecimal getCredit() {
return credit;
}
public void setCredit(BigDecimal credit) {
this.credit = credit;
}
public Date getUpdatedOn() {
return updatedOn;
}
public void setUpdatedOn(Date updatedOn) {
this.updatedOn = updatedOn;
}
public Long getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(Long updatedBy) {
this.updatedBy = updatedBy;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "updated_by")
private Long updatedBy = null;
@Override
public long getId() {
// TODO Auto-generated method stub
return this.id;
}
}