Skip to content

Commit

Permalink
push global notification class and updated SMS. SMPP and VOICE to use…
Browse files Browse the repository at this point in the history
… global notification
  • Loading branch information
croufay committed Nov 10, 2016
1 parent 35f2ad9 commit 33f1bd7
Show file tree
Hide file tree
Showing 15 changed files with 836 additions and 574 deletions.
1 change: 1 addition & 0 deletions restcomm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<module>restcomm.identity</module>
<module>restcomm.mrb</module>
<module>restcomm.mrb.api</module>
<module>restcomm.notification</module>
<module>restcomm.monitoring.service</module>
</modules>

Expand Down
105 changes: 105 additions & 0 deletions restcomm/restcomm.notification/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.restcomm</groupId>
<artifactId>restcomm-connect</artifactId>
<version>8.0.0-SNAPSHOT</version>
</parent>

<artifactId>restcomm-connect.notification</artifactId>
<name>restcomm-connect.notification</name>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</dependency>

<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
</dependency>

<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-slf4j_2.10</artifactId>
</dependency>


<dependency>
<groupId>org.restcomm</groupId>
<artifactId>restcomm-connect.dao</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>



<dependency>
<groupId>org.restcomm</groupId>
<artifactId>restcomm-connect.interpreter</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.mobicents.servlet.sip</groupId>
<artifactId>sip-servlets-spec</artifactId>
<version>${sipservletapi.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.1</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.10</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.restcomm.connect.notification;

import java.net.URI;
import org.apache.commons.configuration.Configuration;
import org.joda.time.DateTime;
import org.restcomm.connect.dao.DaoManager;
import org.restcomm.connect.dao.NotificationsDao;
import org.restcomm.connect.dao.entities.Notification;
import org.restcomm.connect.commons.dao.Sid;



/**
*
* @author charles.roufay
*/
public class GlobalNotification {


public static int getERROR_NOTIFICATION() {
return ERROR_NOTIFICATION;
}

public static int getWARNING_NOTIFICATION() {
return WARNING_NOTIFICATION;
}
private static final int WARNING_NOTIFICATION = 1;
private static final int ERROR_NOTIFICATION = 0;
private final Sid accountId = new Sid("ACae6e420f425248d6a26948c17a9e2acf");

public GlobalNotification(Configuration configuration, DaoManager storage) {
this.runtime = configuration.subset("runtime-settings");
this.apiVersion = runtime.getString("api-version");
this.storage = storage;
}
private final String apiVersion;
private final Configuration runtime;
private final DaoManager storage;
private Notification notification = null;
private NotificationsDao notifications = null;
// application data.
//private HttpRequestDescriptor request;
//private HttpResponseDescriptor response;
//notifications.addNotification(notification);
private URI uri = URI.create("http://documentation.telestax.com/connect/api/");
public void sendNotification(final int errorWarningCode, final int apiErrorCode, final String errorMessage) {
notification = notification(errorWarningCode, apiErrorCode, errorMessage, uri,"","","");
notifications = storage.getNotificationsDao();
notifications.addNotification(notification);
}
protected Notification notification(final int errorWarningCode, final int apiErrorCode,
final String errorMessage,
final URI requestUrl,
final String requestMethod,
final String requestVariables,
final String responseHeaders) {

final Notification.Builder builder = Notification.builder();
final Sid sid = Sid.generate(Sid.Type.NOTIFICATION);
builder.setSid(sid);
builder.setAccountSid(accountId);
builder.setApiVersion(apiVersion);
builder.setLog(errorWarningCode);
builder.setErrorCode(apiErrorCode);
final String base = runtime.getString("error-dictionary-uri");
StringBuilder buffer = new StringBuilder();
buffer.append(base);
if (!base.endsWith("/")) {
buffer.append("/");
}
buffer.append(apiErrorCode).append(".html");
final URI info = URI.create(buffer.toString());
builder.setMoreInfo(info);
builder.setMessageText(errorMessage);
final DateTime now = DateTime.now();
builder.setMessageDate(now);
builder.setRequestUrl(requestUrl);
builder.setRequestMethod(requestMethod);
builder.setRequestVariables(requestVariables);
builder.setResponseHeaders(responseHeaders);
buffer = new StringBuilder();
buffer.append("/").append(apiVersion).append("/Accounts/");
buffer.append(accountId.toString()).append("/Notifications/");
buffer.append(sid.toString());
final URI uri = URI.create(buffer.toString());
builder.setUri(uri);
return builder.build();
}

}
6 changes: 6 additions & 0 deletions restcomm/restcomm.sms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
<artifactId>ch-commons-util</artifactId>
<version>${ch-commons-util.version}</version>
</dependency>
<dependency>
<groupId>org.restcomm</groupId>
<artifactId>restcomm-connect.notification</artifactId>
<version>8.0.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>

<build>
Expand Down

0 comments on commit 33f1bd7

Please sign in to comment.