From 97bb7ee87cb3bccd37ad119945b2d1eac3f0f49d Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Mon, 15 Feb 2021 22:06:32 +0530 Subject: [PATCH] Add SMS management common classes --- .../sms-mgt/io.entgra.sms.mgt.common/pom.xml | 98 +++++++++++++++++++ .../sms/mgt/common/SMSMgtConstants.java | 10 ++ .../sms/mgt/common/bean/SMSMessage.java | 71 ++++++++++++++ .../sms/mgt/common/config/Property.java | 48 +++++++++ .../mgt/common/config/SMSConfiguration.java | 67 +++++++++++++ .../sms/mgt/common/config/SMSGateway.java | 85 ++++++++++++++++ .../common/exception/SMSSenderException.java | 47 +++++++++ .../entgra/sms/mgt/common/spi/SMSSender.java | 38 +++++++ components/sms-mgt/pom.xml | 44 +++++++++ 9 files changed, 508 insertions(+) create mode 100644 components/sms-mgt/io.entgra.sms.mgt.common/pom.xml create mode 100644 components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/SMSMgtConstants.java create mode 100644 components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/bean/SMSMessage.java create mode 100644 components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/Property.java create mode 100644 components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/SMSConfiguration.java create mode 100644 components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/SMSGateway.java create mode 100644 components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/exception/SMSSenderException.java create mode 100644 components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/spi/SMSSender.java create mode 100644 components/sms-mgt/pom.xml diff --git a/components/sms-mgt/io.entgra.sms.mgt.common/pom.xml b/components/sms-mgt/io.entgra.sms.mgt.common/pom.xml new file mode 100644 index 0000000000..6595066646 --- /dev/null +++ b/components/sms-mgt/io.entgra.sms.mgt.common/pom.xml @@ -0,0 +1,98 @@ + + + + + + + org.wso2.carbon.devicemgt + sms-mgt + 4.1.12-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.sms.mgt.common + bundle + Entgra IoT - SMS Management Common + Entgra IoT - SMS Management Common + http://entgra.io + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + SMS Management Common Bundle + + io.entgra.sms.mgt.common.* + + + io.swagger.annotations; version="${swagger.annotations.version}"; resolution:=optional, + + + + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + + + + + + io.swagger + swagger-annotations + provided + + + + + diff --git a/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/SMSMgtConstants.java b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/SMSMgtConstants.java new file mode 100644 index 0000000000..cbe46d742e --- /dev/null +++ b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/SMSMgtConstants.java @@ -0,0 +1,10 @@ +package io.entgra.sms.mgt.common; + +/** + * This class holds SMS Management Constants + */ +public final class SMSMgtConstants { + + public static final String SCOPE = "scope"; + public static final String SMS_CONFIG_XML_NAME = "sms-config.xml"; +} diff --git a/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/bean/SMSMessage.java b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/bean/SMSMessage.java new file mode 100644 index 0000000000..23cde039b9 --- /dev/null +++ b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/bean/SMSMessage.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.sms.mgt.common.bean; + +import io.swagger.annotations.ApiModelProperty; + +/** + * This class hold the SMS Message + */ +public class SMSMessage { + + @ApiModelProperty( + name = "from", + value = "Sender's number.", + required = true + ) + private String from; + + @ApiModelProperty( + name = "to", + value = "Recipient's number." + ) + private String to; + + @ApiModelProperty( + name = "body", + value = "SMS message content.", + required = true + ) + private String body; + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } +} diff --git a/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/Property.java b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/Property.java new file mode 100644 index 0000000000..de667cfd11 --- /dev/null +++ b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/Property.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.sms.mgt.common.config; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlValue; + +@XmlRootElement(name = "Property") +public class Property { + + private String name; + private String value; + + @XmlAttribute(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlValue + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/SMSConfiguration.java b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/SMSConfiguration.java new file mode 100644 index 0000000000..7992533c76 --- /dev/null +++ b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/SMSConfiguration.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.sms.mgt.common.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement(name = "SMSConfiguration") +public class SMSConfiguration { + + private List smsGateways; + + @XmlElementWrapper(name = "Gateways") + @XmlElement(name = "Gateway") + public List getSMSGateways() { + return smsGateways; + } + + public void setSMSGateways(List smsGateways) { + this.smsGateways = smsGateways; + } + + /** + * Retrieve the default SMS Gateway as defined in the SMS configuration. + * @return default {@link SMSGateway} + */ + public SMSGateway getDefaultSMSGateway() { + for (SMSGateway smsGateway : smsGateways) { + if (smsGateway.isDefault()) { + return smsGateway; + } + } + return null; + } + + /** + * Retrieve SMS Gateway by the provided Gateway Name + * @param gatewayName has the name of the Gateway to be retrieved + * @return retrieved {@link SMSGateway} + */ + public SMSGateway getSMSGateway(String gatewayName) { + for (SMSGateway smsGateway : smsGateways) { + if (gatewayName.equals(smsGateway.getName())) { + return smsGateway; + } + } + return null; + } +} diff --git a/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/SMSGateway.java b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/SMSGateway.java new file mode 100644 index 0000000000..988faca8e5 --- /dev/null +++ b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/config/SMSGateway.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.sms.mgt.common.config; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement(name = "Gateway") +public class SMSGateway { + + private String name; + private String extensionClass; + private boolean isDefault; + private List properties; + + @XmlAttribute(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlAttribute(name = "extensionClass") + public String getExtensionClass() { + return extensionClass; + } + + public void setExtensionClass(String extensionClass) { + this.extensionClass = extensionClass; + } + + @XmlAttribute(name = "isDefault") + public boolean isDefault() { + return isDefault; + } + + public void setDefault(boolean aDefault) { + isDefault = aDefault; + } + + @XmlElementWrapper(name = "Properties") + @XmlElement(name = "Property") + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + + /** + * Retrives the Property based on the provided property name + * @param propertyName has the name of the Property to be retrieved + * @return retrieved {@link Property} + */ + public Property getPropertyByName(String propertyName) { + for (Property property : properties) { + if (propertyName.equals(property.getName())) { + return property; + } + } + return null; + } +} diff --git a/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/exception/SMSSenderException.java b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/exception/SMSSenderException.java new file mode 100644 index 0000000000..8a86a0c406 --- /dev/null +++ b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/exception/SMSSenderException.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.sms.mgt.common.exception; + +/** + * Exception that will be thrown during SMS Sender Management + */ +public class SMSSenderException extends Exception { + + private static final long serialVersionUID = 3570365211845277909L; + + public SMSSenderException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public SMSSenderException(String message, Throwable cause) { + super(message, cause); + } + + public SMSSenderException(String msg) { + super(msg); + } + + public SMSSenderException() { + super(); + } + + public SMSSenderException(Throwable cause) { + super(cause); + } +} diff --git a/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/spi/SMSSender.java b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/spi/SMSSender.java new file mode 100644 index 0000000000..34b283384f --- /dev/null +++ b/components/sms-mgt/io.entgra.sms.mgt.common/src/main/java/io/entgra/sms/mgt/common/spi/SMSSender.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.sms.mgt.common.spi; + +import io.entgra.sms.mgt.common.bean.SMSMessage; +import io.entgra.sms.mgt.common.exception.SMSSenderException; + +/** + * Manages the sending of SMS. + * This interface can be implemented by SMS Senders and specific implementation can be done + * depending on the SMS Sender. + */ +public interface SMSSender { + + /** + * Responsible for sending SMS. + * This method can be implemented by the relevant SMS Senders for specific sender related implementation. + * @param smsMessage which has data on the SMS to be send + * @throws SMSSenderException catches all other exception and {@link SMSSenderException} is thrown + */ + void sendSMS(SMSMessage smsMessage) throws SMSSenderException; +} diff --git a/components/sms-mgt/pom.xml b/components/sms-mgt/pom.xml new file mode 100644 index 0000000000..4a0d9a4e8f --- /dev/null +++ b/components/sms-mgt/pom.xml @@ -0,0 +1,44 @@ + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 4.1.12-SNAPSHOT + ../../pom.xml + + + 4.0.0 + sms-mgt + pom + Entgra IoT - SMS Management Component + http://entgra.io + + + + io.entgra.sms.mgt.core + io.entgra.sms.mgt.common + io.entgra.sms.mgt.api + + +