diff --git a/.classpath b/.classpath index 9892aaf..6e195df 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c50ed88 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +.svn + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +.DS_Store diff --git a/.project b/.project index 9b9a686..02865b5 100644 --- a/.project +++ b/.project @@ -1,17 +1,17 @@ - - - google-voice-java - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - + + + google-voice-java + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md index 2d70af3..c3cc73c 100644 --- a/README.md +++ b/README.md @@ -1 +1,95 @@ -The original API for Google Voice. This could possibly be revived if the login and token can be renegotiated. The client login API it is based on no longer works. +# Google Voice Java Library (Unofficial) + +An unofficial Java API for interacting with Google Voice. This library is currently being modernized. + +## Notice +This project has recently been migrated to Gradle and uses OAuth 2.0 for authentication. +The previous ClientLogin authentication method is no longer supported as it has been deprecated by Google. + +## Prerequisites +- Java Development Kit (JDK) 17 or higher. +- Git (for cloning the repository). +- A Google Account with Google Voice. +- OAuth 2.0 Client Credentials (`client_secret.json`) from Google Cloud Console. + +## Building the Project +This project uses Gradle with Kotlin DSL. + +1. **Clone the repository:** + ```bash + git clone [YOUR_REPOSITORY_URL_HERE] + cd google_voice_java + ``` + (Replace `google_voice_java` with the actual directory name if different) +2. **Build the project:** + Use the Gradle wrapper (recommended): + ```bash + ./gradlew build + ``` + Or, if you have Gradle installed: + ```bash + gradle build + ``` + This will compile the code, run tests, and create a JAR file in `build/libs/`. + +Common Gradle tasks: +- `clean`: Cleans the build directory. +- `jar`: Creates the library JAR. +- `sourcesJar`: Creates a JAR with source files. +- `javadocJar`: Creates a JAR with Javadoc. +- `dokkaHtml`: Generates Dokka HTML documentation for Kotlin/Java (output in `build/docs/dokka/`). +- `test`: Runs unit tests. + +## Authentication (OAuth 2.0 Setup - One Time) +This library uses OAuth 2.0 for authentication with Google. You need to set this up once. + +1. **Obtain OAuth 2.0 Credentials:** + * Go to the [Google Cloud Console](https://console.cloud.google.com/). + * Create a new project or select an existing one. + * Enable the Google People API (or any other relevant APIs if specific Voice API scopes are identified and used later). + * Go to "Credentials", click "Create Credentials", and choose "OAuth client ID". + * Select "Desktop app" as the application type. + * Name your client (e.g., "GoogleVoiceJavaDesktopApp"). + * After creation, download the JSON credentials file. Rename it to `client_secret.json`. +2. **Place `client_secret.json`:** + * Put the downloaded and renamed `client_secret.json` file into the root directory of this project. +3. **Configure Redirect URI:** + * In the Google Cloud Console, under your newly created OAuth Client ID, ensure you add a "Authorized redirect URI". + * This URI **must be** `http://localhost:8888/Callback` (the port `8888` is what the current authentication helper uses). +4. **Run the Authentication Task:** + Open your terminal in the project root and run: + ```bash + ./gradlew initiateGoogleAuth + ``` + * This task will print further instructions and should automatically open a URL in your web browser. + * Log in with your Google account and grant the requested permissions. + * Upon successful authorization, an access token and refresh token will be stored securely in your user's home directory (typically `~/.credentials/google-voice-java/`). + * A file named `google-auth.properties` containing the necessary `AUTH_TOKEN` will also be created in that directory. The application (specifically `GVCookieManager`) will load this file for subsequent API calls. + +## Using the Library +After successful authentication, you can use the library. +(Details on how `GVCookieManager` now uses the OAuth token and how `Voice.java` makes authenticated calls can be added here or kept in more detailed class/method documentation). + +Example (conceptual, assuming Voice class usage remains similar): +```java +// GVCookieManager automatically loads the token from google-auth.properties +// when getInstance() is called. +// The Voice class constructor no longer requires username/password for authentication. +// It will rely on the token loaded by GVCookieManager. +Voice voice = new Voice(); + +try { + String inboxHtml = voice.getInbox(); // This call should now use the OAuth token + System.out.println(inboxHtml); +} catch (IOException e) { + e.printStackTrace(); +} +``` +**Note:** The `Voice` class constructors and methods that previously relied on username/password or the old `authToken` field will now automatically attempt to use the OAuth token loaded by `GVCookieManager`. The old constructors taking username/password are still present but their authentication mechanism (ClientLogin) is deprecated and will likely fail or not be used if an OAuth token is present. + +## Contributing +(Add contribution guidelines if any) + +## License +This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details. +(Verify the actual LICENSE file if it's different). diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..cc5558b --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,160 @@ +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale // Added Locale for SimpleDateFormat +import java.util.Properties // Added Properties for buildProps + +plugins { + kotlin("jvm") version "1.8.20" + `java-library` + id("org.jetbrains.dokka") version "1.8.20" // Added Dokka plugin +} + +group = "com.techventus.server.voice" +version = "1.0-SNAPSHOT" // Default version, actual app version comes from properties + +repositories { + mavenCentral() +} + +// Load properties from build.properties +val buildProps = Properties() +val propertiesFile = file("build.properties") +if (propertiesFile.exists()) { + try { + propertiesFile.inputStream().use { buildProps.load(it) } + } catch (e: Exception) { + println("Warning: Could not load build.properties: ${e.message}") + } +} + +val appVersion = buildProps.getProperty("gvjava.version-number", "1.0-SNAPSHOT") +val builtBy = buildProps.getProperty("builder", "Gradle") +val builtDate = SimpleDateFormat("d-MMMM-yyyy", Locale.ENGLISH).format(Date()) +val builtTime = SimpleDateFormat("hh:mm:ss a z", Locale.ENGLISH).format(Date()) + +dependencies { + implementation(kotlin("stdlib-jdk8")) + implementation("org.json:json:20231013") + + // Google API Client Libraries for OAuth + implementation("com.google.api-client:google-api-client:2.2.0") + implementation("com.google.oauth-client:google-oauth-client-jetty:1.34.1") + implementation("com.google.http-client:google-http-client-gson:1.42.3") // For JSON parsing with Google HTTP client + + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") + testImplementation("junit:junit:4.13.2") + testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.9.1") +} + +kotlin { + jvmToolchain(17) +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +tasks.withType().configureEach { + kotlinOptions { + jvmTarget = "17" + } +} + +// Configure the test task to use JUnit Platform and add logging +tasks.test { + useJUnitPlatform() + testLogging { + events("passed", "skipped", "failed") + } +} + +// Configure Jar manifest +tasks.jar { + manifest { + attributes( + "Implementation-Title" to project.name, + "Implementation-Version" to appVersion, + "Built-By" to builtBy, + "Built-On" to builtDate, + "Built-At" to builtTime + ) + } +} + +// Register sourcesJar task +tasks.register("sourcesJar") { + archiveClassifier.set("sources") + from(sourceSets.main.get().allSource) +} + +// Configure Javadoc task +tasks.javadoc { + destinationDir = layout.buildDirectory.dir("docs/javadoc").get().asFile + // Add any specific Javadoc options if needed, e.g., for encoding + options.encoding = "UTF-8" +} + +// Register javadocJar task +tasks.register("javadocJar") { + archiveClassifier.set("javadoc") + from(tasks.javadoc) +} + +// Configure Dokka task (dokkaHtml is the default HTML format task) +tasks.dokkaHtml { + outputDirectory.set(layout.buildDirectory.dir("docs/dokka")) +} + +sourceSets { + main { + java.srcDirs("src/main/java") + kotlin.srcDirs("src/main/kotlin") + resources.srcDirs("src/main/resources") + } + test { + java.srcDirs("src/test/java") + kotlin.srcDirs("src/test/kotlin") + resources.srcDirs("src/test/resources") + } +} + +tasks.register("initiateGoogleAuth") { + group = "authentication" + description = "Initiates the Google OAuth 2.0 flow to retrieve and store an access token." + + mainClass.set("com.techventus.server.voice.auth.GoogleAuthHelper") + classpath = sourceSets.main.get().runtimeClasspath + standardInput = System.`in` // Allow the application to read from console if needed + + doFirst { + println("") + println("****************************************************************************") + println("* Preparing to initiate Google OAuth 2.0 authorization flow... *") + println("* *") + println("* IMPORTANT PREQUISITES: *") + println("* 1. Ensure you have downloaded your 'client_secret.json' file from the *") + println("* Google Cloud Console for your OAuth 2.0 Client ID. *") + println("* 2. Place the 'client_secret.json' file in the project root directory: *") + println("* ${project.projectDir.absolutePath} *") + println("* 3. In your Google Cloud Console, ensure the OAuth Client ID has a *") + println("* redirect URI set to: http://localhost:8888/Callback *") + println("* (The port must match the one used by GoogleAuthHelper, currently 8888).*") + println("****************************************************************************") + println("") + println("The helper will now run. Follow the instructions it provides, which will likely involve opening a URL in your browser.") + println("----------------------------------------------------------------------------") + } +} + +tasks.register("cleanAntOutput") { + doLast { + delete("bin", "dist", "doc") // Added "doc" from old javadoc.home + println("Cleaned old Ant output directories: bin, dist, doc") + } +} + +tasks.named("clean") { + dependsOn("cleanAntOutput") +} diff --git a/build.xml b/build.xml index ab2e6d1..5c50756 100644 --- a/build.xml +++ b/build.xml @@ -1,85 +1,93 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/com/techventus/server/voice/Voice.html b/doc/com/techventus/server/voice/Voice.html index 6a521ef..97eb98c 100644 --- a/doc/com/techventus/server/voice/Voice.html +++ b/doc/com/techventus/server/voice/Voice.html @@ -609,7 +609,7 @@


          Disables multiple phones in one post - + TODO Test this with multiple phones in an account Make faster - spawn threads Best would be to be able to construct a url which can switch multiple phones at a time. @@ -621,7 +621,7 @@


          Enables multiple phones in one post - + TODO Test this with multiple phones in an account Best would be to be able to construct a url which can switch multiple phones at a time. @@ -860,8 +860,8 @@

Parameters:
user - the username in the format of user@gmail.com or user@googlemail.com
pass - the password
source - the arbitrary source identifier. Can be anything.
printDebugIntoToSystemOut - the print debug into to system out
accountType - Type of account to request authorization for. Possible values are: - Voice.GOOGLE (get authorization for a Google account only) - Voice.HOSTED (get authorization for a hosted account only) + Voice.GOOGLE (get authorization for a Google account only) + Voice.HOSTED (get authorization for a hosted account only) Voice.HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account) Use Voice.HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized.
Throws: @@ -886,8 +886,8 @@

Parameters:
user - the username in the format of user@gmail.com or user@googlemail.com
pass - the password
source - the arbitrary source identifier. Can be anything.
printDebugIntoToSystemOut - the print debug into to system out
accountType - Type of account to request authorization for. Possible values are: - Voice.GOOGLE (get authorization for a Google account only) - Voice.HOSTED (get authorization for a hosted account only) + Voice.GOOGLE (get authorization for a Google account only) + Voice.HOSTED (get authorization for a hosted account only) Voice.HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account) Use Voice.HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized.
captchaResponse - response to a captcha challenge, set to null if normal login
captchaToken - (optional) token which matches the response/url from the captcha challenge
Throws: @@ -1032,7 +1032,7 @@

public java.lang.String getGeneralPage(int page) throws java.io.IOException
-
The main Google Voice section is paginated. Access the raw HTML for +
The main Google Voice section is paginated. Access the raw HTML for specific page of the main section.

@@ -1560,7 +1560,7 @@

throws java.io.IOException
Enables multiple phones in one post - + TODO Test this with multiple phones in an account Best would be to be able to construct a url which can switch multiple phones at a time.

@@ -1598,7 +1598,7 @@

throws java.io.IOException
Disables multiple phones in one post - + TODO Test this with multiple phones in an account Make faster - spawn threads Best would be to be able to construct a url which can switch multiple phones at a time. @@ -1849,7 +1849,7 @@

authentication or if an exception is thrown, a false is returned, otherwise if arbitrary text is contained for a logged in account, a true is returned. - + TODO Examine methodology.

diff --git a/doc/com/techventus/server/voice/datatypes/AllSettings.html b/doc/com/techventus/server/voice/datatypes/AllSettings.html index ea43dde..6542d45 100644 --- a/doc/com/techventus/server/voice/datatypes/AllSettings.html +++ b/doc/com/techventus/server/voice/datatypes/AllSettings.html @@ -284,7 +284,7 @@

Query disabled status - if id not found, then it returned false, which normally means enabled.

-
Parameters:
phoneId - +
Parameters:
phoneId -
Returns:
true if the Phone is Disabled. Otherwise it return false.

diff --git a/doc/com/techventus/server/voice/datatypes/Group.html b/doc/com/techventus/server/voice/datatypes/Group.html index 900f3ae..aa61e7c 100644 --- a/doc/com/techventus/server/voice/datatypes/Group.html +++ b/doc/com/techventus/server/voice/datatypes/Group.html @@ -428,7 +428,7 @@

throws gvjava.org.json.JSONException
-
Parameters:
jsonObject - +
Parameters:
jsonObject -
Throws:
gvjava.org.json.JSONException
diff --git a/doc/com/techventus/server/voice/datatypes/Phone.html b/doc/com/techventus/server/voice/datatypes/Phone.html index 8422826..22df085 100644 --- a/doc/com/techventus/server/voice/datatypes/Phone.html +++ b/doc/com/techventus/server/voice/datatypes/Phone.html @@ -629,7 +629,7 @@

saveMode is off

-
Parameters:
phonesJSON - +
Parameters:
phonesJSON -
Throws:
gvjava.org.json.JSONException

@@ -725,7 +725,7 @@

-
Parameters:
phones - +
Parameters:
phones -
Returns:
Json Object
Throws:
gvjava.org.json.JSONException
diff --git a/doc/com/techventus/server/voice/datatypes/PhoneOld.html b/doc/com/techventus/server/voice/datatypes/PhoneOld.html index b6fe41a..9084faf 100644 --- a/doc/com/techventus/server/voice/datatypes/PhoneOld.html +++ b/doc/com/techventus/server/voice/datatypes/PhoneOld.html @@ -1,785 +1,785 @@ - - - - - - -PhoneOld - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

- -com.techventus.server.voice.datatypes -
-Class PhoneOld

-
-java.lang.Object
-  extended by com.techventus.server.voice.datatypes.PhoneOld
-
-
-Deprecated. please move everything over to Phone.java -

-

-
@Deprecated
-public class PhoneOld
extends java.lang.Object
- - -

-


- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Field Summary
- java.lang.Stringcarrier - -
-          Deprecated. 
- booleanenabled - -
-          Deprecated. 
- java.lang.StringformattedNumber - -
-          Deprecated. 
- intid - -
-          Deprecated. 
- java.lang.Stringname - -
-          Deprecated. 
- java.lang.Stringnumber - -
-          Deprecated. 
- java.lang.Stringtype - -
-          Deprecated. 
- booleanverified - -
-          Deprecated. 
-  - - - - - - - - - - - - - -
-Constructor Summary
PhoneOld() - -
-          Deprecated. 
PhoneOld(int id, - java.lang.String number, - java.lang.String formattedNumber, - java.lang.String type, - java.lang.String name, - java.lang.String carrier, - boolean verified, - boolean enabled) - -
-          Deprecated.  
-  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Method Summary
- java.lang.StringgetCarrier() - -
-          Deprecated.  
- booleangetEnabled() - -
-          Deprecated.  
- java.lang.StringgetFormattedNumber() - -
-          Deprecated.  
- intgetId() - -
-          Deprecated.  
- java.lang.StringgetName() - -
-          Deprecated.  
- java.lang.StringgetNumber() - -
-          Deprecated.  
- java.lang.StringgetType() - -
-          Deprecated.  
- booleangetVerified() - -
-          Deprecated.  
-static PhoneOld[]jsonObjectToPhone(gvjava.org.json.JSONObject jsonObject) - -
-          Deprecated.  
- voidsetCarrier(java.lang.String carrier) - -
-          Deprecated.  
- voidsetEnabled(boolean enabled) - -
-          Deprecated.  
- voidsetFormattedNumber(java.lang.String formattedNumber) - -
-          Deprecated.  
- voidsetId(int id) - -
-          Deprecated.  
- voidsetName(java.lang.String name) - -
-          Deprecated.  
- voidsetNumber(java.lang.String number) - -
-          Deprecated.  
- voidsetType(java.lang.String type) - -
-          Deprecated.  
- voidsetVerified(boolean verified) - -
-          Deprecated.  
- java.lang.StringtoString() - -
-          Deprecated.  
- - - - - - - -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-  -

- - - - - - - - -
-Field Detail
- -

-id

-
-@Deprecated
-public int id
-
-
Deprecated. 
-
-
-
- -

-number

-
-@Deprecated
-public java.lang.String number
-
-
Deprecated. 
-
-
-
- -

-formattedNumber

-
-@Deprecated
-public java.lang.String formattedNumber
-
-
Deprecated. 
-
-
-
- -

-type

-
-@Deprecated
-public java.lang.String type
-
-
Deprecated. 
-
-
-
- -

-name

-
-@Deprecated
-public java.lang.String name
-
-
Deprecated. 
-
-
-
- -

-carrier

-
-@Deprecated
-public java.lang.String carrier
-
-
Deprecated. 
-
-
-
- -

-verified

-
-@Deprecated
-public boolean verified
-
-
Deprecated. 
-
-
-
- -

-enabled

-
-@Deprecated
-public boolean enabled
-
-
Deprecated. 
-
-
- - - - - - - - -
-Constructor Detail
- -

-PhoneOld

-
-@Deprecated
-public PhoneOld()
-
-
Deprecated.  -

+ + + + + + +PhoneOld + + + + + + + + + + + + +


+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +com.techventus.server.voice.datatypes +
+Class PhoneOld

+
+java.lang.Object
+  extended by com.techventus.server.voice.datatypes.PhoneOld
+
+
+Deprecated. please move everything over to Phone.java +

+

+
@Deprecated
+public class PhoneOld
extends java.lang.Object
+ + +

+


+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Field Summary
+ java.lang.Stringcarrier + +
+          Deprecated. 
+ booleanenabled + +
+          Deprecated. 
+ java.lang.StringformattedNumber + +
+          Deprecated. 
+ intid + +
+          Deprecated. 
+ java.lang.Stringname + +
+          Deprecated. 
+ java.lang.Stringnumber + +
+          Deprecated. 
+ java.lang.Stringtype + +
+          Deprecated. 
+ booleanverified + +
+          Deprecated. 
+  + + + + + + + + + + + + + +
+Constructor Summary
PhoneOld() + +
+          Deprecated. 
PhoneOld(int id, + java.lang.String number, + java.lang.String formattedNumber, + java.lang.String type, + java.lang.String name, + java.lang.String carrier, + boolean verified, + boolean enabled) + +
+          Deprecated.  
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ java.lang.StringgetCarrier() + +
+          Deprecated.  
+ booleangetEnabled() + +
+          Deprecated.  
+ java.lang.StringgetFormattedNumber() + +
+          Deprecated.  
+ intgetId() + +
+          Deprecated.  
+ java.lang.StringgetName() + +
+          Deprecated.  
+ java.lang.StringgetNumber() + +
+          Deprecated.  
+ java.lang.StringgetType() + +
+          Deprecated.  
+ booleangetVerified() + +
+          Deprecated.  
+static PhoneOld[]jsonObjectToPhone(gvjava.org.json.JSONObject jsonObject) + +
+          Deprecated.  
+ voidsetCarrier(java.lang.String carrier) + +
+          Deprecated.  
+ voidsetEnabled(boolean enabled) + +
+          Deprecated.  
+ voidsetFormattedNumber(java.lang.String formattedNumber) + +
+          Deprecated.  
+ voidsetId(int id) + +
+          Deprecated.  
+ voidsetName(java.lang.String name) + +
+          Deprecated.  
+ voidsetNumber(java.lang.String number) + +
+          Deprecated.  
+ voidsetType(java.lang.String type) + +
+          Deprecated.  
+ voidsetVerified(boolean verified) + +
+          Deprecated.  
+ java.lang.StringtoString() + +
+          Deprecated.  
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+id

+
+@Deprecated
+public int id
+
+
Deprecated. 
+
+
+
+ +

+number

+
+@Deprecated
+public java.lang.String number
+
+
Deprecated. 
+
+
+
+ +

+formattedNumber

+
+@Deprecated
+public java.lang.String formattedNumber
+
+
Deprecated. 
+
+
+
+ +

+type

+
+@Deprecated
+public java.lang.String type
+
+
Deprecated. 
+
+
+
+ +

+name

+
+@Deprecated
+public java.lang.String name
+
+
Deprecated. 
+
+
+
+ +

+carrier

+
+@Deprecated
+public java.lang.String carrier
+
+
Deprecated. 
+
+
+
+ +

+verified

+
+@Deprecated
+public boolean verified
+
+
Deprecated. 
+
+
+
+ +

+enabled

+
+@Deprecated
+public boolean enabled
+
+
Deprecated. 
+
+
+ + + + + + + + +
+Constructor Detail
+ +

+PhoneOld

+
+@Deprecated
+public PhoneOld()
+
+
Deprecated.  +

Instantiates a new empty PhoneOld object. This method is deprecated. - Consider using PhoneOld(int id,String number,String formattedNumber,String type,String name,String carrier, Boolean verified) -

-

-
- -

-PhoneOld

-
-public PhoneOld(int id,
-                java.lang.String number,
-                java.lang.String formattedNumber,
-                java.lang.String type,
-                java.lang.String name,
-                java.lang.String carrier,
-                boolean verified,
-                boolean enabled)
-
-
Deprecated. 
- - - - - - - - -
-Method Detail
- -

-getId

-
-public int getId()
-
-
Deprecated. 
-
-
-
-
- -

-setId

-
-public void setId(int id)
-
-
Deprecated. 
-
-
-
-
- -

-getNumber

-
-public java.lang.String getNumber()
-
-
Deprecated. 
-
-
-
-
- -

-setNumber

-
-public void setNumber(java.lang.String number)
-
-
Deprecated. 
-
-
-
-
- -

-getFormattedNumber

-
-public java.lang.String getFormattedNumber()
-
-
Deprecated. 
-
-
-
-
- -

-setFormattedNumber

-
-public void setFormattedNumber(java.lang.String formattedNumber)
-
-
Deprecated. 
-
-
-
-
- -

-getType

-
-public java.lang.String getType()
-
-
Deprecated. 
-
-
-
-
- -

-setType

-
-public void setType(java.lang.String type)
-
-
Deprecated. 
-
-
-
-
- -

-getName

-
-public java.lang.String getName()
-
-
Deprecated. 
-
-
-
-
- -

-setName

-
-public void setName(java.lang.String name)
-
-
Deprecated. 
-
-
-
-
- -

-getCarrier

-
-public java.lang.String getCarrier()
-
-
Deprecated. 
-
-
-
-
- -

-setCarrier

-
-public void setCarrier(java.lang.String carrier)
-
-
Deprecated. 
-
-
-
-
- -

-getVerified

-
-public boolean getVerified()
-
-
Deprecated. 
-
-
-
-
- -

-setVerified

-
-public void setVerified(boolean verified)
-
-
Deprecated. 
-
-
-
-
- -

-getEnabled

-
-public boolean getEnabled()
-
-
Deprecated. 
-
-
-
-
- -

-setEnabled

-
-public void setEnabled(boolean enabled)
-
-
Deprecated. 
-
-
-
-
- -

-toString

-
-public java.lang.String toString()
-
-
Deprecated. 
-
Overrides:
toString in class java.lang.Object
-
-
-
-
-
-
- -

-jsonObjectToPhone

-
-public static PhoneOld[] jsonObjectToPhone(gvjava.org.json.JSONObject jsonObject)
-
-
Deprecated. 
-
-
-
- -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - + Consider using PhoneOld(int id,String number,String formattedNumber,String type,String name,String carrier, Boolean verified) +

+

+
+ +

+PhoneOld

+
+public PhoneOld(int id,
+                java.lang.String number,
+                java.lang.String formattedNumber,
+                java.lang.String type,
+                java.lang.String name,
+                java.lang.String carrier,
+                boolean verified,
+                boolean enabled)
+
+
Deprecated. 
+ + + + + + + + +
+Method Detail
+ +

+getId

+
+public int getId()
+
+
Deprecated. 
+
+
+
+
+ +

+setId

+
+public void setId(int id)
+
+
Deprecated. 
+
+
+
+
+ +

+getNumber

+
+public java.lang.String getNumber()
+
+
Deprecated. 
+
+
+
+
+ +

+setNumber

+
+public void setNumber(java.lang.String number)
+
+
Deprecated. 
+
+
+
+
+ +

+getFormattedNumber

+
+public java.lang.String getFormattedNumber()
+
+
Deprecated. 
+
+
+
+
+ +

+setFormattedNumber

+
+public void setFormattedNumber(java.lang.String formattedNumber)
+
+
Deprecated. 
+
+
+
+
+ +

+getType

+
+public java.lang.String getType()
+
+
Deprecated. 
+
+
+
+
+ +

+setType

+
+public void setType(java.lang.String type)
+
+
Deprecated. 
+
+
+
+
+ +

+getName

+
+public java.lang.String getName()
+
+
Deprecated. 
+
+
+
+
+ +

+setName

+
+public void setName(java.lang.String name)
+
+
Deprecated. 
+
+
+
+
+ +

+getCarrier

+
+public java.lang.String getCarrier()
+
+
Deprecated. 
+
+
+
+
+ +

+setCarrier

+
+public void setCarrier(java.lang.String carrier)
+
+
Deprecated. 
+
+
+
+
+ +

+getVerified

+
+public boolean getVerified()
+
+
Deprecated. 
+
+
+
+
+ +

+setVerified

+
+public void setVerified(boolean verified)
+
+
Deprecated. 
+
+
+
+
+ +

+getEnabled

+
+public boolean getEnabled()
+
+
Deprecated. 
+
+
+
+
+ +

+setEnabled

+
+public void setEnabled(boolean enabled)
+
+
Deprecated. 
+
+
+
+
+ +

+toString

+
+public java.lang.String toString()
+
+
Deprecated. 
+
Overrides:
toString in class java.lang.Object
+
+
+
+
+
+
+ +

+jsonObjectToPhone

+
+public static PhoneOld[] jsonObjectToPhone(gvjava.org.json.JSONObject jsonObject)
+
+
Deprecated. 
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/doc/com/techventus/server/voice/datatypes/Settings.html b/doc/com/techventus/server/voice/datatypes/Settings.html index 2556abd..af706fa 100644 --- a/doc/com/techventus/server/voice/datatypes/Settings.html +++ b/doc/com/techventus/server/voice/datatypes/Settings.html @@ -1,549 +1,549 @@ - - - - - - -Settings - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

- -com.techventus.server.voice.datatypes -
-Class Settings

-
-java.lang.Object
-  extended by com.techventus.server.voice.datatypes.Settings
-
-
-Deprecated. please use the class AllSettings which holds phoneList, phones and settings and for the settings, the class Setting -

-

-
@Deprecated
-public class Settings
extends java.lang.Object
- - -

+ + + + + + +Settings + + + + + + + + + + + + +


+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +com.techventus.server.voice.datatypes +
+Class Settings

+
+java.lang.Object
+  extended by com.techventus.server.voice.datatypes.Settings
+
+
+Deprecated. please use the class AllSettings which holds phoneList, phones and settings and for the settings, the class Setting +

+

+
@Deprecated
+public class Settings
extends java.lang.Object
+ + +

Holds all settings of the gVoice account and can return it as String, as lists or as json-string - Most Lists also have a .toJson() method -

- -

-


- -

- - - - - - - - - - - -
-Constructor Summary
Settings(java.lang.String json, - boolean useJSONParser, - boolean saveMode) - -
-          Deprecated.  
-  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Method Summary
- java.util.List<java.lang.Integer>getActiveForwardingList() - -
-          Deprecated.  
- java.lang.StringgetBaseUrl() - -
-          Deprecated.  
- intgetDefaultGreetingId() - -
-          Deprecated.  
- java.util.List<DisabledId>getDisabledIdList() - -
-          Deprecated.  
- java.util.List<EmailAddress>getEmailAddressList() - -
-          Deprecated.  
- java.util.List<java.lang.String>getGroupListSimple() - -
-          Deprecated.  
- java.util.List<Group>getGroupSettingsList() - -
-          Deprecated.  
- java.util.List<PhoneOld>getPhoneList() - -
-          Deprecated.  
- int[]getPhoneListSimple() - -
-          Deprecated.  
- java.util.List<Greeting>getVoicemailGreetingsList() - -
-          Deprecated.  
- java.util.List<WebCallButton>getWebCallButtonList() - -
-          Deprecated.  
- java.lang.StringtoJson() - -
-          Deprecated. Make a JSON text of the Settings.
- java.lang.StringtoJson(int indentFactor) - -
-          Deprecated. Make a prettyprinted JSON text of this JSONObject.
- java.lang.StringtoString() - -
-          Deprecated.  
- - - - - - - -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-  -

- - - - - - - - -
-Constructor Detail
- -

-Settings

-
-public Settings(java.lang.String json,
-                boolean useJSONParser,
-                boolean saveMode)
-
-
Deprecated. 
-
Parameters:
json -
useJSONParser - - uses the json.org json parser
saveMode - - check if each key exists before trying to parse it(in JSON Parser mode)
-
- - - - - - - - -
-Method Detail
- -

-toJson

-
-public java.lang.String toJson(int indentFactor)
-                        throws gvjava.org.json.JSONException
-
+ Most Lists also have a .toJson() method +

+ +

+


+ +

+ + + + + + + + + + + +
+Constructor Summary
Settings(java.lang.String json, + boolean useJSONParser, + boolean saveMode) + +
+          Deprecated.  
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ java.util.List<java.lang.Integer>getActiveForwardingList() + +
+          Deprecated.  
+ java.lang.StringgetBaseUrl() + +
+          Deprecated.  
+ intgetDefaultGreetingId() + +
+          Deprecated.  
+ java.util.List<DisabledId>getDisabledIdList() + +
+          Deprecated.  
+ java.util.List<EmailAddress>getEmailAddressList() + +
+          Deprecated.  
+ java.util.List<java.lang.String>getGroupListSimple() + +
+          Deprecated.  
+ java.util.List<Group>getGroupSettingsList() + +
+          Deprecated.  
+ java.util.List<PhoneOld>getPhoneList() + +
+          Deprecated.  
+ int[]getPhoneListSimple() + +
+          Deprecated.  
+ java.util.List<Greeting>getVoicemailGreetingsList() + +
+          Deprecated.  
+ java.util.List<WebCallButton>getWebCallButtonList() + +
+          Deprecated.  
+ java.lang.StringtoJson() + +
+          Deprecated. Make a JSON text of the Settings.
+ java.lang.StringtoJson(int indentFactor) + +
+          Deprecated. Make a prettyprinted JSON text of this JSONObject.
+ java.lang.StringtoString() + +
+          Deprecated.  
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+Settings

+
+public Settings(java.lang.String json,
+                boolean useJSONParser,
+                boolean saveMode)
+
+
Deprecated. 
+
Parameters:
json -
useJSONParser - - uses the json.org json parser
saveMode - - check if each key exists before trying to parse it(in JSON Parser mode)
+
+ + + + + + + + +
+Method Detail
+ +

+toJson

+
+public java.lang.String toJson(int indentFactor)
+                        throws gvjava.org.json.JSONException
+
Deprecated. 
Make a prettyprinted JSON text of this JSONObject.

- Warning: This method assumes that the data structure is acyclical. -

-

+ Warning: This method assumes that the data structure is acyclical. +

+

Parameters:
indentFactor - The number of spaces to add to each level of - indentation. + indentation.
Returns:
a printable, displayable, portable, transmittable representation of the object, beginning with { (left brace) and ending - with } (right brace). -
Throws: -
gvjava.org.json.JSONException - if using identFactor > 0 and If the object contains an invalid number.
-
-
-
- -

-toJson

-
-public java.lang.String toJson()
-
+ with } (right brace). +
Throws: +
gvjava.org.json.JSONException - if using identFactor > 0 and If the object contains an invalid number.
+
+
+
+ +

+toJson

+
+public java.lang.String toJson()
+
Deprecated. 
Make a JSON text of the Settings. For compactness, no whitespace is added. If this would not result in a syntactically correct JSON text, then null will be returned instead.

- Warning: This method assumes that the data structure is acyclical. -

-

- + Warning: This method assumes that the data structure is acyclical. +

+

+
Returns:
a printable, displayable, portable, transmittable representation of the object, beginning with { (left brace) and ending - with } (right brace).
-
-
-
- -

-toString

-
-public java.lang.String toString()
-
-
Deprecated. 
-
Overrides:
toString in class java.lang.Object
-
-
-
-
-
-
- -

-getGroupListSimple

-
-public java.util.List<java.lang.String> getGroupListSimple()
-
-
Deprecated. 
- -
Returns:
the mGroupListSimple
-
-
-
- -

-getPhoneListSimple

-
-public int[] getPhoneListSimple()
-
-
Deprecated. 
- -
Returns:
the mPhoneListSimple
-
-
-
- -

-getPhoneList

-
-public java.util.List<PhoneOld> getPhoneList()
-
-
Deprecated. 
- -
Returns:
the mPhoneList
-
-
-
- -

-getVoicemailGreetingsList

-
-public java.util.List<Greeting> getVoicemailGreetingsList()
-
-
Deprecated. 
- -
Returns:
the mVoicemailGreetingsList
-
-
-
- -

-getGroupSettingsList

-
-public java.util.List<Group> getGroupSettingsList()
-
-
Deprecated. 
- -
Returns:
the mGroupList
-
-
-
- -

-getDisabledIdList

-
-public java.util.List<DisabledId> getDisabledIdList()
-
-
Deprecated. 
- -
Returns:
the mDisabledIdList
-
-
-
- -

-getWebCallButtonList

-
-public java.util.List<WebCallButton> getWebCallButtonList()
-
-
Deprecated. 
- -
Returns:
the mWebCallButtonList
-
-
-
- -

-getDefaultGreetingId

-
-public int getDefaultGreetingId()
-
-
Deprecated. 
- -
Returns:
the mDefaultGreetingId
-
-
-
- -

-getEmailAddressList

-
-public java.util.List<EmailAddress> getEmailAddressList()
-
-
Deprecated. 
- -
Returns:
the mEmailAddressList
-
-
-
- -

-getBaseUrl

-
-public java.lang.String getBaseUrl()
-
-
Deprecated. 
- -
Returns:
the mBaseUrl
-
-
-
- -

-getActiveForwardingList

-
-public java.util.List<java.lang.Integer> getActiveForwardingList()
-
-
Deprecated. 
- -
Returns:
the mActiveForwardingList
-
-
- -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - + with } (right brace).
+
+
+
+ +

+toString

+
+public java.lang.String toString()
+
+
Deprecated. 
+
Overrides:
toString in class java.lang.Object
+
+
+
+
+
+
+ +

+getGroupListSimple

+
+public java.util.List<java.lang.String> getGroupListSimple()
+
+
Deprecated. 
+ +
Returns:
the mGroupListSimple
+
+
+
+ +

+getPhoneListSimple

+
+public int[] getPhoneListSimple()
+
+
Deprecated. 
+ +
Returns:
the mPhoneListSimple
+
+
+
+ +

+getPhoneList

+
+public java.util.List<PhoneOld> getPhoneList()
+
+
Deprecated. 
+ +
Returns:
the mPhoneList
+
+
+
+ +

+getVoicemailGreetingsList

+
+public java.util.List<Greeting> getVoicemailGreetingsList()
+
+
Deprecated. 
+ +
Returns:
the mVoicemailGreetingsList
+
+
+
+ +

+getGroupSettingsList

+
+public java.util.List<Group> getGroupSettingsList()
+
+
Deprecated. 
+ +
Returns:
the mGroupList
+
+
+
+ +

+getDisabledIdList

+
+public java.util.List<DisabledId> getDisabledIdList()
+
+
Deprecated. 
+ +
Returns:
the mDisabledIdList
+
+
+
+ +

+getWebCallButtonList

+
+public java.util.List<WebCallButton> getWebCallButtonList()
+
+
Deprecated. 
+ +
Returns:
the mWebCallButtonList
+
+
+
+ +

+getDefaultGreetingId

+
+public int getDefaultGreetingId()
+
+
Deprecated. 
+ +
Returns:
the mDefaultGreetingId
+
+
+
+ +

+getEmailAddressList

+
+public java.util.List<EmailAddress> getEmailAddressList()
+
+
Deprecated. 
+ +
Returns:
the mEmailAddressList
+
+
+
+ +

+getBaseUrl

+
+public java.lang.String getBaseUrl()
+
+
Deprecated. 
+ +
Returns:
the mBaseUrl
+
+
+
+ +

+getActiveForwardingList

+
+public java.util.List<java.lang.Integer> getActiveForwardingList()
+
+
Deprecated. 
+ +
Returns:
the mActiveForwardingList
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/doc/com/techventus/server/voice/datatypes/class-use/PhoneOld.html b/doc/com/techventus/server/voice/datatypes/class-use/PhoneOld.html index 00f22b2..df7b941 100644 --- a/doc/com/techventus/server/voice/datatypes/class-use/PhoneOld.html +++ b/doc/com/techventus/server/voice/datatypes/class-use/PhoneOld.html @@ -1,226 +1,226 @@ - - - - - - -Uses of Class com.techventus.server.voice.datatypes.PhoneOld - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Class
com.techventus.server.voice.datatypes.PhoneOld

-
- - - - - - - - - - - - - -
-Packages that use PhoneOld
com.techventus.server.voice  
com.techventus.server.voice.datatypes  
-  -

- - - - - -
-Uses of PhoneOld in com.techventus.server.voice
-  -

- - - - - - - - + +
Methods in com.techventus.server.voice that return types with arguments of type PhoneOld
- java.util.List<PhoneOld>Voice.getPhoneList(boolean forceUpdate) - -
+ + + + + + +Uses of Class com.techventus.server.voice.datatypes.PhoneOld + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Uses of Class
com.techventus.server.voice.datatypes.PhoneOld

+
+ + + + + + + + + + + + + +
+Packages that use PhoneOld
com.techventus.server.voice  
com.techventus.server.voice.datatypes  
+  +

+ + + + + +
+Uses of PhoneOld in com.techventus.server.voice
+  +

+ + + + + + + + - -
Methods in com.techventus.server.voice that return types with arguments of type PhoneOld
+ java.util.List<PhoneOld>Voice.getPhoneList(boolean forceUpdate) + +
          Returns the phone list - Lazy - TODO move this function in the Settings class
-  -

- - - - - -
-Uses of PhoneOld in com.techventus.server.voice.datatypes
-  -

- - - - - - - - - -
Methods in com.techventus.server.voice.datatypes that return PhoneOld
-static PhoneOld[]PhoneOld.jsonObjectToPhone(gvjava.org.json.JSONObject jsonObject) - -
-          Deprecated.  
-  -

- - - - - - - - - -
Methods in com.techventus.server.voice.datatypes that return types with arguments of type PhoneOld
- java.util.List<PhoneOld>Settings.getPhoneList() - -
-          Deprecated.  
-  -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - + TODO move this function in the Settings class
+  +

+ + + + + +
+Uses of PhoneOld in com.techventus.server.voice.datatypes
+  +

+ + + + + + + + + +
Methods in com.techventus.server.voice.datatypes that return PhoneOld
+static PhoneOld[]PhoneOld.jsonObjectToPhone(gvjava.org.json.JSONObject jsonObject) + +
+          Deprecated.  
+  +

+ + + + + + + + + +
Methods in com.techventus.server.voice.datatypes that return types with arguments of type PhoneOld
+ java.util.List<PhoneOld>Settings.getPhoneList() + +
+          Deprecated.  
+  +

+


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/doc/com/techventus/server/voice/datatypes/class-use/Settings.html b/doc/com/techventus/server/voice/datatypes/class-use/Settings.html index b3e6872..14a8ef6 100644 --- a/doc/com/techventus/server/voice/datatypes/class-use/Settings.html +++ b/doc/com/techventus/server/voice/datatypes/class-use/Settings.html @@ -1,144 +1,144 @@ - - - - - - -Uses of Class com.techventus.server.voice.datatypes.Settings - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Class
com.techventus.server.voice.datatypes.Settings

-
-No usage of com.techventus.server.voice.datatypes.Settings -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - + + + + + + +Uses of Class com.techventus.server.voice.datatypes.Settings + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Uses of Class
com.techventus.server.voice.datatypes.Settings

+
+No usage of com.techventus.server.voice.datatypes.Settings +

+


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/doc/com/techventus/server/voice/datatypes/records/Record.html b/doc/com/techventus/server/voice/datatypes/records/Record.html index 2c1748e..2c1bcd3 100644 --- a/doc/com/techventus/server/voice/datatypes/records/Record.html +++ b/doc/com/techventus/server/voice/datatypes/records/Record.html @@ -105,8 +105,8 @@

A Record is one entry in a Voice record list(like the Inbox) - An implemented Class is a call entry or an SMS or a Voicemail - + An implemented Class is a call entry or an SMS or a Voicemail + TODO give better name?

diff --git a/doc/com/techventus/server/voice/datatypes/records/Transcript.html b/doc/com/techventus/server/voice/datatypes/records/Transcript.html index 0c84c2c..2046fe9 100644 --- a/doc/com/techventus/server/voice/datatypes/records/Transcript.html +++ b/doc/com/techventus/server/voice/datatypes/records/Transcript.html @@ -126,7 +126,7 @@


          Creates a Transcript out of a List of Elements - usage: - + List transElementList = new ArrayList(); // go through the array and create transscript elments for (int i = 0; i < transElementsAsString.length; i++) { @@ -203,7 +203,7 @@

public Transcript(java.util.List<TranscriptElement> elements)
Creates a Transcript out of a List of Elements - usage: - + List transElementList = new ArrayList(); // go through the array and create transscript elments for (int i = 0; i < transElementsAsString.length; i++) { diff --git a/doc/com/techventus/server/voice/datatypes/records/TranscriptElement.RecognitionLevel.html b/doc/com/techventus/server/voice/datatypes/records/TranscriptElement.RecognitionLevel.html index 5547edc..dec577a 100644 --- a/doc/com/techventus/server/voice/datatypes/records/TranscriptElement.RecognitionLevel.html +++ b/doc/com/techventus/server/voice/datatypes/records/TranscriptElement.RecognitionLevel.html @@ -279,7 +279,7 @@

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an -enum constant in this type. (Extraneous whitespace characters are +enum constant in this type. (Extraneous whitespace characters are not permitted.)

diff --git a/doc/com/techventus/server/voice/datatypes/records/TranscriptElement.html b/doc/com/techventus/server/voice/datatypes/records/TranscriptElement.html index 3e9bd5a..d6cf11b 100644 --- a/doc/com/techventus/server/voice/datatypes/records/TranscriptElement.html +++ b/doc/com/techventus/server/voice/datatypes/records/TranscriptElement.html @@ -102,7 +102,7 @@

One Element in a Transcript - normally a word. - Each Element has a ReccognitionLevel indicating how sure google is + Each Element has a ReccognitionLevel indicating how sure google is that the word is recognised correctly.

diff --git a/doc/com/techventus/server/voice/datatypes/records/class-use/TranscriptElement.html b/doc/com/techventus/server/voice/datatypes/records/class-use/TranscriptElement.html index d7a392d..825d614 100644 --- a/doc/com/techventus/server/voice/datatypes/records/class-use/TranscriptElement.html +++ b/doc/com/techventus/server/voice/datatypes/records/class-use/TranscriptElement.html @@ -164,7 +164,7 @@


          Creates a Transcript out of a List of Elements - usage: - + List transElementList = new ArrayList(); // go through the array and create transscript elments for (int i = 0; i < transElementsAsString.length; i++) { diff --git a/doc/com/techventus/server/voice/datatypes/records/package-summary.html b/doc/com/techventus/server/voice/datatypes/records/package-summary.html index cf49e22..84f2556 100644 --- a/doc/com/techventus/server/voice/datatypes/records/package-summary.html +++ b/doc/com/techventus/server/voice/datatypes/records/package-summary.html @@ -95,8 +95,8 @@

Record A Record is one entry in a Voice record list(like the Inbox) - An implemented Class is a call entry or an SMS or a Voicemail - + An implemented Class is a call entry or an SMS or a Voicemail + TODO give better name? diff --git a/doc/com/techventus/server/voice/datatypes/records/package-use.html b/doc/com/techventus/server/voice/datatypes/records/package-use.html index ce78871..c8623ef 100644 --- a/doc/com/techventus/server/voice/datatypes/records/package-use.html +++ b/doc/com/techventus/server/voice/datatypes/records/package-use.html @@ -130,8 +130,8 @@


          A Record is one entry in a Voice record list(like the Inbox) - An implemented Class is a call entry or an SMS or a Voicemail - + An implemented Class is a call entry or an SMS or a Voicemail + TODO give better name? diff --git a/doc/com/techventus/server/voice/exception/CaptchaRequiredException.html b/doc/com/techventus/server/voice/exception/CaptchaRequiredException.html index 4c5a8ef..9e38e0b 100644 --- a/doc/com/techventus/server/voice/exception/CaptchaRequiredException.html +++ b/doc/com/techventus/server/voice/exception/CaptchaRequiredException.html @@ -221,8 +221,8 @@

-
Returns:
Token representing the specific Captcha challenge. Google supplies this token - and the CAPTCHA image URL in a login failed response with the error code +
Returns:
Token representing the specific Captcha challenge. Google supplies this token + and the CAPTCHA image URL in a login failed response with the error code "CaptchaRequired".
diff --git a/doc/com/techventus/server/voice/exception/ERROR_CODE.html b/doc/com/techventus/server/voice/exception/ERROR_CODE.html index 152aec3..3d64731 100644 --- a/doc/com/techventus/server/voice/exception/ERROR_CODE.html +++ b/doc/com/techventus/server/voice/exception/ERROR_CODE.html @@ -392,7 +392,7 @@

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an -enum constant in this type. (Extraneous whitespace characters are +enum constant in this type. (Extraneous whitespace characters are not permitted.)

diff --git a/doc/index-files/index-1.html b/doc/index-files/index-1.html index f1183fe..55f647d 100644 --- a/doc/index-files/index-1.html +++ b/doc/index-files/index-1.html @@ -82,34 +82,34 @@

A

-
AccountDeletedException - Exception in com.techventus.server.voice.exception
 
AccountDeletedException() - +
AccountDeletedException - Exception in com.techventus.server.voice.exception
 
AccountDeletedException() - Constructor for exception com.techventus.server.voice.exception.AccountDeletedException
  -
AccountDisabledException - Exception in com.techventus.server.voice.exception
 
AccountDisabledException() - +
AccountDisabledException - Exception in com.techventus.server.voice.exception
 
AccountDisabledException() - Constructor for exception com.techventus.server.voice.exception.AccountDisabledException
  -
ActiveForwardingId - Class in com.techventus.server.voice.datatypes
 
ActiveForwardingId(JSONObject) - +
ActiveForwardingId - Class in com.techventus.server.voice.datatypes
 
ActiveForwardingId(JSONObject) - Constructor for class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
ActiveForwardingId(String, boolean) - +
ActiveForwardingId(String, boolean) - Constructor for class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
addSMS(SMS) - +
addSMS(SMS) - Method in class com.techventus.server.voice.datatypes.records.SMSThread
Adds a SMS object to this thread. -
AllSettings - Class in com.techventus.server.voice.datatypes
 
AllSettings(String) - +
AllSettings - Class in com.techventus.server.voice.datatypes
 
AllSettings(String) - Constructor for class com.techventus.server.voice.datatypes.AllSettings
  -
arrayToJsonObject(List<DisabledForwardingId>) - +
arrayToJsonObject(List<DisabledForwardingId>) - Static method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
AuthenticationException - Exception in com.techventus.server.voice.exception
 
AuthenticationException() - +
AuthenticationException - Exception in com.techventus.server.voice.exception
 
AuthenticationException() - Constructor for exception com.techventus.server.voice.exception.AuthenticationException
  -
AuthenticationException(ERROR_CODE) - +
AuthenticationException(ERROR_CODE) - Constructor for exception com.techventus.server.voice.exception.AuthenticationException
  -
AuthenticationException(Throwable, ERROR_CODE) - +
AuthenticationException(Throwable, ERROR_CODE) - Constructor for exception com.techventus.server.voice.exception.AuthenticationException
 
diff --git a/doc/index-files/index-10.html b/doc/index-files/index-10.html index 5779ecc..ee33cd6 100644 --- a/doc/index-files/index-10.html +++ b/doc/index-files/index-10.html @@ -82,17 +82,17 @@

L

-
listToJson(List<Group>) - +
listToJson(List<Group>) - Static method in class com.techventus.server.voice.datatypes.Group
Creates a complete json of a list of Group "groups":{"15":{..details of group id 15..},"12":{..details of group id 12..}} -
login() - +
login() - Method in class com.techventus.server.voice.Voice
Login Method to refresh authentication with Google Voice. -
login(String, String) - +
login(String, String) - Method in class com.techventus.server.voice.Voice
Use this login method to login - use captchaAnswer to answer a captcha challenge -
LONG_TEXT - +
LONG_TEXT - Variable in enum com.techventus.server.voice.exception.ERROR_CODE
 
diff --git a/doc/index-files/index-11.html b/doc/index-files/index-11.html index 8f21a7c..296cc2c 100644 --- a/doc/index-files/index-11.html +++ b/doc/index-files/index-11.html @@ -82,13 +82,13 @@

M

-
markAsRead(String) - +
markAsRead(String) - Method in class com.techventus.server.voice.Voice
Mark a Conversation with a known Message ID as read. -
markUnRead(String) - +
markUnRead(String) - Method in class com.techventus.server.voice.Voice
Mark a Conversation with a known Message ID as unread. -
MESSAGES - +
MESSAGES - Static variable in class com.techventus.server.voice.util.JSONContants
 
diff --git a/doc/index-files/index-12.html b/doc/index-files/index-12.html index 6a43e36..b543c9a 100644 --- a/doc/index-files/index-12.html +++ b/doc/index-files/index-12.html @@ -82,10 +82,10 @@

N

-
NOTE - +
NOTE - Static variable in class com.techventus.server.voice.util.JSONContants
  -
NotVerifiedException - Exception in com.techventus.server.voice.exception
 
NotVerifiedException() - +
NotVerifiedException - Exception in com.techventus.server.voice.exception
 
NotVerifiedException() - Constructor for exception com.techventus.server.voice.exception.NotVerifiedException
 
diff --git a/doc/index-files/index-13.html b/doc/index-files/index-13.html index 65e093a..05a3782 100644 --- a/doc/index-files/index-13.html +++ b/doc/index-files/index-13.html @@ -82,41 +82,41 @@

P

-
ParsingUtil - Class in com.techventus.server.voice.util
Collection of useful html parsing methods
ParsingUtil() - +
ParsingUtil - Class in com.techventus.server.voice.util
Collection of useful html parsing methods
ParsingUtil() - Constructor for class com.techventus.server.voice.util.ParsingUtil
  -
Phone - Class in com.techventus.server.voice.datatypes
 
Phone(int, String, String) - +
Phone - Class in com.techventus.server.voice.datatypes
 
Phone(int, String, String) - Constructor for class com.techventus.server.voice.datatypes.Phone
  -
Phone(JSONObject) - +
Phone(JSONObject) - Constructor for class com.techventus.server.voice.datatypes.Phone
saveMode is off -
Phone(JSONObject, boolean) - +
Phone(JSONObject, boolean) - Constructor for class com.techventus.server.voice.datatypes.Phone
Instantiates a new Phone Object. -
phoneDisable(int) - +
phoneDisable(int) - Method in class com.techventus.server.voice.Voice
Disable one of the the phones attached to the account from ringing. -
phoneEnable(int) - +
phoneEnable(int) - Method in class com.techventus.server.voice.Voice
Enables one of the the phones attached to the account from ringing. -
phonesArrayToJsonObject(Phone[]) - +
phonesArrayToJsonObject(Phone[]) - Static method in class com.techventus.server.voice.datatypes.Phone
  -
phonesDisable(int[]) - +
phonesDisable(int[]) - Method in class com.techventus.server.voice.Voice
Disables multiple phones in one post - + TODO Test this with multiple phones in an account Make faster - spawn threads Best would be to be able to construct a url which can switch multiple phones at a time. -
phonesEnable(int[]) - +
phonesEnable(int[]) - Method in class com.techventus.server.voice.Voice
Enables multiple phones in one post - + TODO Test this with multiple phones in an account Best would be to be able to construct a url which can switch multiple phones at a time. -
PRINT_TO_CONSOLE - +
PRINT_TO_CONSOLE - Variable in class com.techventus.server.voice.Voice
The PRIN t_ t o_ console.
diff --git a/doc/index-files/index-14.html b/doc/index-files/index-14.html index 52000f0..082cf89 100644 --- a/doc/index-files/index-14.html +++ b/doc/index-files/index-14.html @@ -83,15 +83,15 @@ R

Record - Class in com.techventus.server.voice.datatypes.records
A Record is one entry in a Voice record list(like the Inbox) - An implemented Class is a call entry or an SMS or a Voicemail - - TODO give better name?
Record(String, String, Date, Contact, boolean) - + An implemented Class is a call entry or an SMS or a Voicemail + + TODO give better name?
Record(String, String, Date, Contact, boolean) - Constructor for class com.techventus.server.voice.datatypes.records.Record
  -
removeSMS(SMS) - +
removeSMS(SMS) - Method in class com.techventus.server.voice.datatypes.records.SMSThread
Removes a SMS object from this thread. -
removeUninterestingParts(String, String, String, boolean) - +
removeUninterestingParts(String, String, String, boolean) - Static method in class com.techventus.server.voice.util.ParsingUtil
Strips the text from the uninteresting parts before and after the interesting part.
diff --git a/doc/index-files/index-15.html b/doc/index-files/index-15.html index 3674bf4..388a242 100644 --- a/doc/index-files/index-15.html +++ b/doc/index-files/index-15.html @@ -82,335 +82,335 @@

S

-
sendSMS(String, String, String) - +
sendSMS(String, String, String) - Method in class com.techventus.server.voice.Voice
Send an SMS. -
sendSMS(String, String, SMSThread) - +
sendSMS(String, String, SMSThread) - Method in class com.techventus.server.voice.Voice
Send an SMS. -
sendSMS(String, String) - +
sendSMS(String, String) - Method in class com.techventus.server.voice.Voice
Send an SMS. -
ServiceDisabledException - Exception in com.techventus.server.voice.exception
 
ServiceDisabledException() - +
ServiceDisabledException - Exception in com.techventus.server.voice.exception
 
ServiceDisabledException() - Constructor for exception com.techventus.server.voice.exception.ServiceDisabledException
  -
ServiceUnavailableException - Exception in com.techventus.server.voice.exception
 
ServiceUnavailableException() - +
ServiceUnavailableException - Exception in com.techventus.server.voice.exception
 
ServiceUnavailableException() - Constructor for exception com.techventus.server.voice.exception.ServiceUnavailableException
  -
setActive(boolean) - +
setActive(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setAddress(String) - +
setAddress(String) - Method in class com.techventus.server.voice.datatypes.EmailAddress
  -
setAllDay(boolean) - +
setAllDay(boolean) - Method in class com.techventus.server.voice.datatypes.Wd
  -
setAllDay(boolean) - +
setAllDay(boolean) - Method in class com.techventus.server.voice.datatypes.We
  -
setBaseUrl(String) - +
setBaseUrl(String) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setBehaviorOnRedirect(int) - +
setBehaviorOnRedirect(int) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setCallPresentation(boolean) - +
setCallPresentation(boolean) - Method in class com.techventus.server.voice.Voice
Enables/disables the call Announcement setting (general for all phones). -
setCarrier(String) - +
setCarrier(String) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setContact(Contact) - +
setContact(Contact) - Method in class com.techventus.server.voice.datatypes.records.Record
  -
setCredits(int) - +
setCredits(int) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setCustomDirectConnect(boolean) - +
setCustomDirectConnect(boolean) - Method in class com.techventus.server.voice.datatypes.Group
  -
setCustomForwarding(boolean) - +
setCustomForwarding(boolean) - Method in class com.techventus.server.voice.datatypes.Group
  -
setCustomGreeting(boolean) - +
setCustomGreeting(boolean) - Method in class com.techventus.server.voice.datatypes.Group
  -
setCustomOverrideState(int) - +
setCustomOverrideState(int) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setDate(Date) - +
setDate(Date) - Method in class com.techventus.server.voice.datatypes.records.Record
  -
setDefaultGreetingId(int) - +
setDefaultGreetingId(int) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setdEPRECATEDDisabled(boolean) - +
setdEPRECATEDDisabled(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setDirectConnect(boolean) - +
setDirectConnect(boolean) - Method in class com.techventus.server.voice.datatypes.Group
  -
setDirectConnect(boolean) - +
setDirectConnect(boolean) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setDisabled(boolean) - +
setDisabled(boolean) - Method in class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
setDisabled(boolean) - +
setDisabled(boolean) - Method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
setDisabled(boolean) - +
setDisabled(boolean) - Method in class com.techventus.server.voice.datatypes.DisabledId
  -
setDisabledForwardingIds(List<DisabledForwardingId>) - +
setDisabledForwardingIds(List<DisabledForwardingId>) - Method in class com.techventus.server.voice.datatypes.Group
  -
setDoNotDisturb(boolean) - +
setDoNotDisturb(boolean) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setDoNotDisturb(boolean) - +
setDoNotDisturb(boolean) - Method in class com.techventus.server.voice.Voice
Activated or deactivated the Do Not disturb function.
Enable this to send to voicemail all calls made to your Google number. -
setElements(List<TranscriptElement>) - +
setElements(List<TranscriptElement>) - Method in class com.techventus.server.voice.datatypes.records.Transcript
  -
setEmailAddresses(EmailAddress[]) - +
setEmailAddresses(EmailAddress[]) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setEmailNotificationActive(boolean) - +
setEmailNotificationActive(boolean) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setEmailNotificationAddress(String) - +
setEmailNotificationAddress(String) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setEnabledForOthers(boolean) - +
setEnabledForOthers(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setErrorCode(String) - +
setErrorCode(String) - Method in exception com.techventus.server.voice.exception.AuthenticationException
  -
setErrorCode(ERROR_CODE) - +
setErrorCode(ERROR_CODE) - Method in exception com.techventus.server.voice.exception.AuthenticationException
  -
setFormattedNumber(String) - +
setFormattedNumber(String) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setGreetingId(int) - +
setGreetingId(int) - Method in class com.techventus.server.voice.datatypes.Group
  -
setGreetings(Greeting[]) - +
setGreetings(Greeting[]) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setGroupList(String[]) - +
setGroupList(String[]) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setGroups(Group[]) - +
setGroups(Group[]) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setId(String) - +
setId(String) - Method in class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
setId(String) - +
setId(String) - Method in class com.techventus.server.voice.datatypes.Contact
  -
setId(String) - +
setId(String) - Method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
setId(String) - +
setId(String) - Method in class com.techventus.server.voice.datatypes.DisabledId
  -
setId(int) - +
setId(int) - Method in class com.techventus.server.voice.datatypes.Greeting
  -
setId(String) - +
setId(String) - Method in class com.techventus.server.voice.datatypes.Group
  -
setId(int) - +
setId(int) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setId(String) - +
setId(String) - Method in class com.techventus.server.voice.datatypes.records.Record
Sets the id. -
setId(String) - +
setId(String) - Method in class com.techventus.server.voice.datatypes.records.TranscriptElement
  -
setId(String) - +
setId(String) - Method in class com.techventus.server.voice.datatypes.records.Voicemail
  -
setImageUrl(String) - +
setImageUrl(String) - Method in class com.techventus.server.voice.datatypes.Contact
Sets the Url of the Contacts image on the web -
setIncomingAccessNumber(String) - +
setIncomingAccessNumber(String) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setJobberName(String) - +
setJobberName(String) - Method in class com.techventus.server.voice.datatypes.Greeting
  -
setLanguage(String) - +
setLanguage(String) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setLevel(TranscriptElement.RecognitionLevel) - +
setLevel(TranscriptElement.RecognitionLevel) - Method in class com.techventus.server.voice.datatypes.records.TranscriptElement
  -
setmActiveForwardingList(int[]) - +
setmActiveForwardingList(int[]) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setmDidInfos(String[]) - +
setmDidInfos(String[]) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setmDisabledIdList(DisabledId[]) - +
setmDisabledIdList(DisabledId[]) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setMp3Url(String) - +
setMp3Url(String) - Method in class com.techventus.server.voice.datatypes.records.Voicemail
  -
setName(String) - +
setName(String) - Method in class com.techventus.server.voice.datatypes.Contact
Gets the Display name of the contact -
setName(String) - +
setName(String) - Method in class com.techventus.server.voice.datatypes.Greeting
  -
setName(String) - +
setName(String) - Method in class com.techventus.server.voice.datatypes.Group
  -
setName(String) - +
setName(String) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setNewGroupSettings(Group) - +
setNewGroupSettings(Group) - Method in class com.techventus.server.voice.Voice
Applies the settings for this group. -
setNumber(String) - +
setNumber(String) - Method in class com.techventus.server.voice.datatypes.Contact
  -
setPhoneList(int[]) - +
setPhoneList(int[]) - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
setPhoneNumber(String) - +
setPhoneNumber(String) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setPhones(Phone[]) - +
setPhones(Phone[]) - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
setPolicyBitmask(int) - +
setPolicyBitmask(int) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setPrimaryDid(String) - +
setPrimaryDid(String) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setRedirectToVoicemail(boolean) - +
setRedirectToVoicemail(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setScheduleSet(boolean) - +
setScheduleSet(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setScreenBehavior(int) - +
setScreenBehavior(int) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setSettings(Setting) - +
setSettings(Setting) - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
setShowTranscripts(boolean) - +
setShowTranscripts(boolean) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setSmsEnabled(boolean) - +
setSmsEnabled(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setSmsNotifications(String[]) - +
setSmsNotifications(String[]) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setSmsToEmailActive(boolean) - +
setSmsToEmailActive(boolean) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setSmsToEmailSubject(boolean) - +
setSmsToEmailSubject(boolean) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setSpam(String) - +
setSpam(String) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setTelephonyVerified(boolean) - +
setTelephonyVerified(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setText(String) - +
setText(String) - Method in class com.techventus.server.voice.datatypes.records.TranscriptElement
  -
setTimes(List<String>) - +
setTimes(List<String>) - Method in class com.techventus.server.voice.datatypes.Wd
  -
setTimes(List<String>) - +
setTimes(List<String>) - Method in class com.techventus.server.voice.datatypes.We
  -
setTimezone(String) - +
setTimezone(String) - Method in class com.techventus.server.voice.datatypes.Setting
  -
Setting - Class in com.techventus.server.voice.datatypes
Accountsettings - subtype of AllSettings
Setting(JSONObject) - +
Setting - Class in com.techventus.server.voice.datatypes
Accountsettings - subtype of AllSettings
Setting(JSONObject) - Constructor for class com.techventus.server.voice.datatypes.Setting
  -
setTitle(String) - +
setTitle(String) - Method in class com.techventus.server.voice.datatypes.records.Record
  -
setTransscript(Transcript) - +
setTransscript(Transcript) - Method in class com.techventus.server.voice.datatypes.records.Voicemail
  -
setType(int) - +
setType(int) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setUseDidAsCallerId(boolean) - +
setUseDidAsCallerId(boolean) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setUseDidAsSource(boolean) - +
setUseDidAsSource(boolean) - Method in class com.techventus.server.voice.datatypes.Setting
  -
setVerified(boolean) - +
setVerified(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setVoicemailForwardingVerified(boolean) - +
setVoicemailForwardingVerified(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setVoicemailGreetingId(String) - +
setVoicemailGreetingId(String) - Method in class com.techventus.server.voice.Voice
This is the general voicemail greeting callers hear. -
setWd(Wd) - +
setWd(Wd) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setWe(We) - +
setWe(We) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setWeekdayAllDay(boolean) - +
setWeekdayAllDay(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setWeekdayTimes(String[]) - +
setWeekdayTimes(String[]) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setWeekendAllDay(boolean) - +
setWeekendAllDay(boolean) - Method in class com.techventus.server.voice.datatypes.Phone
  -
setWeekendTimes(String[]) - +
setWeekendTimes(String[]) - Method in class com.techventus.server.voice.datatypes.Phone
  -
ShortMessage - Class in com.techventus.server.voice.datatypes.records
 
ShortMessage(String, String, Date, Contact, boolean) - +
ShortMessage - Class in com.techventus.server.voice.datatypes.records
 
ShortMessage(String, String, Date, Contact, boolean) - Constructor for class com.techventus.server.voice.datatypes.records.ShortMessage
  -
SMS - Class in com.techventus.server.voice.datatypes.records
Represents a SMS message.
SMS(Contact, String, Date) - +
SMS - Class in com.techventus.server.voice.datatypes.records
Represents a SMS message.
SMS(Contact, String, Date) - Constructor for class com.techventus.server.voice.datatypes.records.SMS
Creates a SMS instance. -
SMSParser - Class in com.techventus.server.voice.util
This class parses the SMS messages from the Google Voice XML response.
SMSParser(String, Contact) - +
SMSParser - Class in com.techventus.server.voice.util
This class parses the SMS messages from the Google Voice XML response.
SMSParser(String, Contact) - Constructor for class com.techventus.server.voice.util.SMSParser
Creates a SMSParser instance. -
SMSParser(String, String) - +
SMSParser(String, String) - Constructor for class com.techventus.server.voice.util.SMSParser
Creates a SMSParser instance. -
SMSThread - Class in com.techventus.server.voice.datatypes.records
Represents a thread of SMS messages.
SMSThread(String, String, Date, Contact, boolean, boolean) - +
SMSThread - Class in com.techventus.server.voice.datatypes.records
Represents a thread of SMS messages.
SMSThread(String, String, Date, Contact, boolean, boolean) - Constructor for class com.techventus.server.voice.datatypes.records.SMSThread
Creates a SMSThread instance. -
STARRED - +
STARRED - Static variable in class com.techventus.server.voice.util.JSONContants
  -
START_TIME - +
START_TIME - Static variable in class com.techventus.server.voice.util.JSONContants
  -
stringListToJsonArray(List<String>) - +
stringListToJsonArray(List<String>) - Static method in class com.techventus.server.voice.util.ParsingUtil
String list to JSON array.
diff --git a/doc/index-files/index-16.html b/doc/index-files/index-16.html index 70c7734..8bd020a 100644 --- a/doc/index-files/index-16.html +++ b/doc/index-files/index-16.html @@ -82,104 +82,104 @@

T

-
TermsNotAgreedException - Exception in com.techventus.server.voice.exception
 
TermsNotAgreedException() - +
TermsNotAgreedException - Exception in com.techventus.server.voice.exception
 
TermsNotAgreedException() - Constructor for exception com.techventus.server.voice.exception.TermsNotAgreedException
  -
throwProperException(ERROR_CODE, String, String) - +
throwProperException(ERROR_CODE, String, String) - Static method in exception com.techventus.server.voice.exception.AuthenticationException
  -
toJson() - +
toJson() - Method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
toJson() - +
toJson() - Method in class com.techventus.server.voice.datatypes.DisabledId
  -
toJson() - +
toJson() - Method in class com.techventus.server.voice.datatypes.EmailAddress
  -
toJson() - +
toJson() - Method in class com.techventus.server.voice.datatypes.Group
  -
toJson() - +
toJson() - Method in class com.techventus.server.voice.datatypes.Phone
Make a JSON text of the Settings. -
toJson() - +
toJson() - Method in class com.techventus.server.voice.datatypes.Setting
Make a JSON text of the Settings. -
toJsonObject() - +
toJsonObject() - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
toJsonObject() - +
toJsonObject() - Method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
toJsonObject() - +
toJsonObject() - Method in class com.techventus.server.voice.datatypes.DisabledId
  -
toJsonObject() - +
toJsonObject() - Method in class com.techventus.server.voice.datatypes.Group
  -
toJsonObject() - +
toJsonObject() - Method in class com.techventus.server.voice.datatypes.Phone
  -
toJsonObject() - +
toJsonObject() - Method in class com.techventus.server.voice.datatypes.Setting
Convert this Settings Object to its JsonObject Representation. -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.Contact
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.DisabledId
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.EmailAddress
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.Greeting
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.Group
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.records.Call
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.records.Record
Returns a String representation -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.records.ShortMessage
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.records.SMS
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.records.SMSThread
  -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.records.Transcript
returns a simple String representation -
toString() - +
toString() - Method in class com.techventus.server.voice.datatypes.records.Voicemail
  -
Transcript - Class in com.techventus.server.voice.datatypes.records
A Transcript of a voicemail
Transcript(List<TranscriptElement>) - +
Transcript - Class in com.techventus.server.voice.datatypes.records
A Transcript of a voicemail
Transcript(List<TranscriptElement>) - Constructor for class com.techventus.server.voice.datatypes.records.Transcript
Creates a Transcript out of a List of Elements - usage: - + List transElementList = new ArrayList(); // go through the array and create transscript elments for (int i = 0; i < transElementsAsString.length; i++) { transElementList.add(TranscriptElement.extractTransscriptElement("Transcript(String) - +
Transcript(String) - Constructor for class com.techventus.server.voice.datatypes.records.Transcript
Creates a transcripts with only Text, with RecognitionLevel.UNKNOWN -
TranscriptElement - Class in com.techventus.server.voice.datatypes.records
One Element in a Transcript - normally a word.
TranscriptElement(String, String, TranscriptElement.RecognitionLevel) - +
TranscriptElement - Class in com.techventus.server.voice.datatypes.records
One Element in a Transcript - normally a word.
TranscriptElement(String, String, TranscriptElement.RecognitionLevel) - Constructor for class com.techventus.server.voice.datatypes.records.TranscriptElement
Standard constructor
TranscriptElement.RecognitionLevel - Enum in com.techventus.server.voice.datatypes.records
 
diff --git a/doc/index-files/index-17.html b/doc/index-files/index-17.html index 65c9cbb..1f7d345 100644 --- a/doc/index-files/index-17.html +++ b/doc/index-files/index-17.html @@ -82,39 +82,39 @@

V

-
valueOf(String) - +
valueOf(String) - Static method in enum com.techventus.server.voice.datatypes.records.TranscriptElement.RecognitionLevel
Returns the enum constant of this type with the specified name. -
valueOf(String) - +
valueOf(String) - Static method in enum com.techventus.server.voice.exception.ERROR_CODE
Returns the enum constant of this type with the specified name. -
values() - +
values() - Static method in enum com.techventus.server.voice.datatypes.records.TranscriptElement.RecognitionLevel
Returns an array containing the constants of this enum type, in the order they are declared. -
values() - +
values() - Static method in enum com.techventus.server.voice.exception.ERROR_CODE
Returns an array containing the constants of this enum type, in the order they are declared. -
Voice - Class in com.techventus.server.voice
The Class Voice.
Voice(String, String, String, String) - +
Voice - Class in com.techventus.server.voice
The Class Voice.
Voice(String, String, String, String) - Constructor for class com.techventus.server.voice.Voice
Deprecated.  -
Voice(String, String, String) - +
Voice(String, String, String) - Constructor for class com.techventus.server.voice.Voice
A constructor which which allows a custom source. -
Voice(String, String) - +
Voice(String, String) - Constructor for class com.techventus.server.voice.Voice
Instantiates a new Voice Object. -
Voice(String, String, String, boolean) - +
Voice(String, String, String, boolean) - Constructor for class com.techventus.server.voice.Voice
Instantiates a new voice. -
Voice(String, String, String, boolean, String) - +
Voice(String, String, String, boolean, String) - Constructor for class com.techventus.server.voice.Voice
Instantiates a new voice. -
Voice(String, String, String, boolean, String, String, String) - +
Voice(String, String, String, boolean, String, String, String) - Constructor for class com.techventus.server.voice.Voice
Instantiates a new voice. -
Voicemail - Class in com.techventus.server.voice.datatypes.records
 
Voicemail(String, String, Date, Contact, Transcript, boolean) - +
Voicemail - Class in com.techventus.server.voice.datatypes.records
 
Voicemail(String, String, Date, Contact, Transcript, boolean) - Constructor for class com.techventus.server.voice.datatypes.records.Voicemail
 
diff --git a/doc/index-files/index-18.html b/doc/index-files/index-18.html index ab6c22e..4eec1ee 100644 --- a/doc/index-files/index-18.html +++ b/doc/index-files/index-18.html @@ -82,13 +82,13 @@

W

-
Wd - Class in com.techventus.server.voice.datatypes
Weekday setting of a phone
Wd() - +
Wd - Class in com.techventus.server.voice.datatypes
Weekday setting of a phone
Wd() - Constructor for class com.techventus.server.voice.datatypes.Wd
  -
We - Class in com.techventus.server.voice.datatypes
Weekend setting of a phone
We() - +
We - Class in com.techventus.server.voice.datatypes
Weekend setting of a phone
We() - Constructor for class com.techventus.server.voice.datatypes.We
  -
WebCallButton - Class in com.techventus.server.voice.datatypes
TODO implement
WebCallButton() - +
WebCallButton - Class in com.techventus.server.voice.datatypes
TODO implement
WebCallButton() - Constructor for class com.techventus.server.voice.datatypes.WebCallButton
 
diff --git a/doc/index-files/index-19.html b/doc/index-files/index-19.html index e69bb8a..32cbb6e 100644 --- a/doc/index-files/index-19.html +++ b/doc/index-files/index-19.html @@ -1,173 +1,173 @@ - - - - - - -V-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -A B C D E F G H I J L M N P R S T U V W
-

-V

-
-
valueOf(String) - -Static method in enum com.techventus.server.voice.datatypes.records.TranscriptElement.RecognitionLevel -
Returns the enum constant of this type with the specified name. -
values() - -Static method in enum com.techventus.server.voice.datatypes.records.TranscriptElement.RecognitionLevel + + + + + + +V-Index + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +A B C D E F G H I J L M N P R S T U V W
+

+V

+
+
valueOf(String) - +Static method in enum com.techventus.server.voice.datatypes.records.TranscriptElement.RecognitionLevel +
Returns the enum constant of this type with the specified name. +
values() - +Static method in enum com.techventus.server.voice.datatypes.records.TranscriptElement.RecognitionLevel
Returns an array containing the constants of this enum type, in -the order they are declared. -
verified - -Variable in class com.techventus.server.voice.datatypes.PhoneOld -
Deprecated.  -
Voice - Class in com.techventus.server.voice
The Class Voice.
Voice(String, String, String, String) - -Constructor for class com.techventus.server.voice.Voice -
Deprecated.  -
Voice(String, String, String) - -Constructor for class com.techventus.server.voice.Voice -
A constructor which which allows a custom source. -
Voice(String, String) - -Constructor for class com.techventus.server.voice.Voice -
Instantiates a new Voice Object. -
Voice(String, String, String, boolean) - -Constructor for class com.techventus.server.voice.Voice -
Instantiates a new voice. -
Voicemail - Class in com.techventus.server.voice.datatypes.records
 
Voicemail(String, String, Date, Contact, Transcript, boolean) - -Constructor for class com.techventus.server.voice.datatypes.records.Voicemail -
  -
voicemailInfoURLString - -Static variable in class com.techventus.server.voice.Voice -
  -
voicemailURLString - -Static variable in class com.techventus.server.voice.Voice -
  -
-
- - - - - - - - - - - - - - - -
- -
- - - -A B C D E F G H I J L M N P R S T U V W
- - - +the order they are declared. +
verified - +Variable in class com.techventus.server.voice.datatypes.PhoneOld +
Deprecated.  +
Voice - Class in com.techventus.server.voice
The Class Voice.
Voice(String, String, String, String) - +Constructor for class com.techventus.server.voice.Voice +
Deprecated.  +
Voice(String, String, String) - +Constructor for class com.techventus.server.voice.Voice +
A constructor which which allows a custom source. +
Voice(String, String) - +Constructor for class com.techventus.server.voice.Voice +
Instantiates a new Voice Object. +
Voice(String, String, String, boolean) - +Constructor for class com.techventus.server.voice.Voice +
Instantiates a new voice. +
Voicemail - Class in com.techventus.server.voice.datatypes.records
 
Voicemail(String, String, Date, Contact, Transcript, boolean) - +Constructor for class com.techventus.server.voice.datatypes.records.Voicemail +
  +
voicemailInfoURLString - +Static variable in class com.techventus.server.voice.Voice +
  +
voicemailURLString - +Static variable in class com.techventus.server.voice.Voice +
  +
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +A B C D E F G H I J L M N P R S T U V W
+ + + diff --git a/doc/index-files/index-2.html b/doc/index-files/index-2.html index cb2199a..663eb64 100644 --- a/doc/index-files/index-2.html +++ b/doc/index-files/index-2.html @@ -82,7 +82,7 @@

B

-
BadAuthenticationException - Exception in com.techventus.server.voice.exception
 
BadAuthenticationException() - +
BadAuthenticationException - Exception in com.techventus.server.voice.exception
 
BadAuthenticationException() - Constructor for exception com.techventus.server.voice.exception.BadAuthenticationException
 
diff --git a/doc/index-files/index-20.html b/doc/index-files/index-20.html index 47d84af..4d9b7b8 100644 --- a/doc/index-files/index-20.html +++ b/doc/index-files/index-20.html @@ -1,151 +1,151 @@ - - - - - - -W-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -A B C D E F G H I J L M N P R S T U V W
-

-W

-
-
Wd - Class in com.techventus.server.voice.datatypes
Weekday setting of a phone
Wd() - -Constructor for class com.techventus.server.voice.datatypes.Wd -
  -
We - Class in com.techventus.server.voice.datatypes
Weekend setting of a phone
We() - -Constructor for class com.techventus.server.voice.datatypes.We -
  -
WebCallButton - Class in com.techventus.server.voice.datatypes
TODO implement
WebCallButton() - -Constructor for class com.techventus.server.voice.datatypes.WebCallButton -
  -
-
- - - - - - - - - - - - - - - -
- -
- - - -A B C D E F G H I J L M N P R S T U V W
- - - + + + + + + +W-Index + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +A B C D E F G H I J L M N P R S T U V W
+

+W

+
+
Wd - Class in com.techventus.server.voice.datatypes
Weekday setting of a phone
Wd() - +Constructor for class com.techventus.server.voice.datatypes.Wd +
  +
We - Class in com.techventus.server.voice.datatypes
Weekend setting of a phone
We() - +Constructor for class com.techventus.server.voice.datatypes.We +
  +
WebCallButton - Class in com.techventus.server.voice.datatypes
TODO implement
WebCallButton() - +Constructor for class com.techventus.server.voice.datatypes.WebCallButton +
  +
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +A B C D E F G H I J L M N P R S T U V W
+ + + diff --git a/doc/index-files/index-3.html b/doc/index-files/index-3.html index b73b213..bd84c91 100644 --- a/doc/index-files/index-3.html +++ b/doc/index-files/index-3.html @@ -82,81 +82,81 @@

C

-
Call - Class in com.techventus.server.voice.datatypes.records
 
Call(String, String, Date, Contact, boolean) - +
Call - Class in com.techventus.server.voice.datatypes.records
 
Call(String, String, Date, Contact, boolean) - Constructor for class com.techventus.server.voice.datatypes.records.Call
  -
call(String, String, String) - +
call(String, String, String) - Method in class com.techventus.server.voice.Voice
Place a call. -
cancelCall(String, String, String) - +
cancelCall(String, String, String) - Method in class com.techventus.server.voice.Voice
Cancel a call that was just placed. -
CaptchaRequiredException - Exception in com.techventus.server.voice.exception
 
CaptchaRequiredException(String, String) - +
CaptchaRequiredException - Exception in com.techventus.server.voice.exception
 
CaptchaRequiredException(String, String) - Constructor for exception com.techventus.server.voice.exception.CaptchaRequiredException
  -
com.techventus.server.voice - package com.techventus.server.voice
 
com.techventus.server.voice.datatypes - package com.techventus.server.voice.datatypes
 
com.techventus.server.voice.datatypes.records - package com.techventus.server.voice.datatypes.records
 
com.techventus.server.voice.exception - package com.techventus.server.voice.exception
 
com.techventus.server.voice.util - package com.techventus.server.voice.util
 
compareTo(Contact) - +
com.techventus.server.voice - package com.techventus.server.voice
 
com.techventus.server.voice.datatypes - package com.techventus.server.voice.datatypes
 
com.techventus.server.voice.datatypes.records - package com.techventus.server.voice.datatypes.records
 
com.techventus.server.voice.exception - package com.techventus.server.voice.exception
 
com.techventus.server.voice.util - package com.techventus.server.voice.util
 
compareTo(Contact) - Method in class com.techventus.server.voice.datatypes.Contact
  -
compareTo(Greeting) - +
compareTo(Greeting) - Method in class com.techventus.server.voice.datatypes.Greeting
  -
compareTo(Phone) - +
compareTo(Phone) - Method in class com.techventus.server.voice.datatypes.Phone
  -
compareTo(SMS) - +
compareTo(SMS) - Method in class com.techventus.server.voice.datatypes.records.SMS
 
Contact - Class in com.techventus.server.voice.datatypes
A Contact TODO I think we need to add several subclasses for the different contact infos - like phone numbers, Email addresses and such
Contact(String, String, String, String) - + like phone numbers, Email addresses and such
Contact(String, String, String, String) - Constructor for class com.techventus.server.voice.datatypes.Contact
  -
createActiveForwardingIdListFromJsonPartResponse(String) - +
createActiveForwardingIdListFromJsonPartResponse(String) - Static method in class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
createArrayFromJsonObject(JSONObject) - +
createArrayFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.DisabledId
  -
createArrayFromJsonObject(JSONObject) - +
createArrayFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.EmailAddress
  -
createArrayFromJsonObject(JSONObject) - +
createArrayFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.Greeting
  -
createArrayFromJsonObject(JSONObject) - +
createArrayFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.Group
  -
createArrayFromJsonObject(JSONObject) - +
createArrayFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.Phone
  -
createDisabledForwardingIdArrayFromJsonPartResponse(String) - +
createDisabledForwardingIdArrayFromJsonPartResponse(String) - Static method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
createDisabledForwardingIdListFromJsonPartResponse(String) - +
createDisabledForwardingIdListFromJsonPartResponse(String) - Static method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
createDisabledIdListFromJsonPartResponse(String) - +
createDisabledIdListFromJsonPartResponse(String) - Static method in class com.techventus.server.voice.datatypes.DisabledId
  -
createEmailAddressListFromJsonPartResponse(String) - +
createEmailAddressListFromJsonPartResponse(String) - Static method in class com.techventus.server.voice.datatypes.EmailAddress
  -
createGroupSettingsFromJsonResponse(String) - +
createGroupSettingsFromJsonResponse(String) - Static method in class com.techventus.server.voice.datatypes.Greeting
  -
createGroupSettingsFromJsonResponse(String) - +
createGroupSettingsFromJsonResponse(String) - Static method in class com.techventus.server.voice.datatypes.Group
Constructs an Object from the json Resonse -
createJSONObjectArrayFromJsonObject(JSONObject) - +
createJSONObjectArrayFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.Group
  -
createJSONObjectFromJsonObject(JSONObject) - +
createJSONObjectFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.Group
  -
createListFromJsonObject(JSONObject) - +
createListFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.DisabledId
  -
createListFromJsonObject(JSONObject) - +
createListFromJsonObject(JSONObject) - Static method in class com.techventus.server.voice.datatypes.Greeting
 
diff --git a/doc/index-files/index-4.html b/doc/index-files/index-4.html index 26c2181..3f21d68 100644 --- a/doc/index-files/index-4.html +++ b/doc/index-files/index-4.html @@ -82,22 +82,22 @@

D

-
deleteMessage(String) - +
deleteMessage(String) - Method in class com.techventus.server.voice.Voice
Delete message. -
DisabledForwardingId - Class in com.techventus.server.voice.datatypes
 
DisabledForwardingId(String, boolean) - +
DisabledForwardingId - Class in com.techventus.server.voice.datatypes
 
DisabledForwardingId(String, boolean) - Constructor for class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
DisabledForwardingId(JSONObject, boolean) - +
DisabledForwardingId(JSONObject, boolean) - Constructor for class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
DisabledId - Class in com.techventus.server.voice.datatypes
Holds the settings of the disabledIdMap json object
DisabledId(String, boolean) - +
DisabledId - Class in com.techventus.server.voice.datatypes
Holds the settings of the disabledIdMap json object
DisabledId(String, boolean) - Constructor for class com.techventus.server.voice.datatypes.DisabledId
  -
DisabledId(JSONObject, boolean) - +
DisabledId(JSONObject, boolean) - Constructor for class com.techventus.server.voice.datatypes.DisabledId
  -
downloadVoicemail(String) - +
downloadVoicemail(String) - Method in class com.techventus.server.voice.Voice
Downloads a voicemail.
diff --git a/doc/index-files/index-5.html b/doc/index-files/index-5.html index 76db64c..559db02 100644 --- a/doc/index-files/index-5.html +++ b/doc/index-files/index-5.html @@ -82,16 +82,16 @@

E

-
EmailAddress - Class in com.techventus.server.voice.datatypes
TODO support multiple email adresses, since its an array (but usually only has one address in there)
EmailAddress(String) - +
EmailAddress - Class in com.techventus.server.voice.datatypes
TODO support multiple email adresses, since its an array (but usually only has one address in there)
EmailAddress(String) - Constructor for class com.techventus.server.voice.datatypes.EmailAddress
  -
EmailAddress(JSONObject) - +
EmailAddress(JSONObject) - Constructor for class com.techventus.server.voice.datatypes.EmailAddress
  -
ERROR_CODE - Enum in com.techventus.server.voice.exception
 
extractContact(String) - +
ERROR_CODE - Enum in com.techventus.server.voice.exception
 
extractContact(String) - Static method in class com.techventus.server.voice.datatypes.Contact
Deprecated.  -
extractTransscriptElement(String) - +
extractTransscriptElement(String) - Static method in class com.techventus.server.voice.datatypes.records.TranscriptElement
Creates a TranscriptElement based on the html, for example: Hello World! diff --git a/doc/index-files/index-6.html b/doc/index-files/index-6.html index 0bafb2d..45f08f6 100644 --- a/doc/index-files/index-6.html +++ b/doc/index-files/index-6.html @@ -82,370 +82,370 @@

G

-
getAddress() - +
getAddress() - Method in class com.techventus.server.voice.datatypes.EmailAddress
  -
getAllDay() - +
getAllDay() - Method in class com.techventus.server.voice.datatypes.Wd
  -
getAllDay() - +
getAllDay() - Method in class com.techventus.server.voice.datatypes.We
  -
getAllSMS() - +
getAllSMS() - Method in class com.techventus.server.voice.datatypes.records.SMSThread
Returns all SMS that exist in this thread. -
getAsJsonObject() - +
getAsJsonObject() - Method in class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
getBaseUrl() - +
getBaseUrl() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getBehaviorOnRedirect() - +
getBehaviorOnRedirect() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getCaptchaToken() - +
getCaptchaToken() - Method in exception com.techventus.server.voice.exception.CaptchaRequiredException
  -
getCaptchaToken() - +
getCaptchaToken() - Method in class com.techventus.server.voice.Voice
Gets the captcha token. -
getCaptchaUrl() - +
getCaptchaUrl() - Method in exception com.techventus.server.voice.exception.CaptchaRequiredException
  -
getCaptchaUrl() - +
getCaptchaUrl() - Method in class com.techventus.server.voice.Voice
Gets the captcha url. -
getCarrier() - +
getCarrier() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getContact() - +
getContact() - Method in class com.techventus.server.voice.datatypes.records.Record
  -
getContent() - +
getContent() - Method in class com.techventus.server.voice.datatypes.records.SMS
Returns the message's content. -
getCredits() - +
getCredits() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getCustomOverrideState() - +
getCustomOverrideState() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getDate() - +
getDate() - Method in class com.techventus.server.voice.datatypes.records.Record
  -
getDateTime() - +
getDateTime() - Method in class com.techventus.server.voice.datatypes.records.SMS
Returns the message's timestamp. -
getDefaultGreetingId() - +
getDefaultGreetingId() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getDisabledForwardingIds() - +
getDisabledForwardingIds() - Method in class com.techventus.server.voice.datatypes.Group
  -
getElements() - +
getElements() - Method in class com.techventus.server.voice.datatypes.records.Transcript
  -
getEmailAddresses() - +
getEmailAddresses() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getEmailNotificationAddress() - +
getEmailNotificationAddress() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getError() - +
getError() - Method in exception com.techventus.server.voice.exception.AuthenticationException
  -
getError() - +
getError() - Method in class com.techventus.server.voice.Voice
Deprecated.  -
getFormattedNumber() - +
getFormattedNumber() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getFrom() - +
getFrom() - Method in class com.techventus.server.voice.datatypes.records.SMS
Returns the contact that sent the message. -
getGeneral() - +
getGeneral() - Method in class com.techventus.server.voice.Voice
Fetches the page Source Code for the Voice homepage. -
getGeneralPage(int) - +
getGeneralPage(int) - Method in class com.techventus.server.voice.Voice
The main Google Voice section is paginated. -
getGreetingId() - +
getGreetingId() - Method in class com.techventus.server.voice.datatypes.Group
  -
getGreetings() - +
getGreetings() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getGreetingsSorted() - +
getGreetingsSorted() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getGroupList() - +
getGroupList() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getGroupListAsList() - +
getGroupListAsList() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getGroups() - +
getGroups() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getGroupSettingsList(boolean) - +
getGroupSettingsList(boolean) - Method in class com.techventus.server.voice.Voice
Returns the Group list - Lazy. -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.Contact
  -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.DisabledId
  -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.Greeting
  -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.Group
  -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.records.Record
  -
getId() - +
getId() - Method in class com.techventus.server.voice.datatypes.records.TranscriptElement
  -
getIdAsInt() - +
getIdAsInt() - Method in class com.techventus.server.voice.datatypes.DisabledId
  -
getImageUrl() - +
getImageUrl() - Method in class com.techventus.server.voice.datatypes.Contact
Gets the Url of the Contacts image on the web -
getInbox() - +
getInbox() - Method in class com.techventus.server.voice.Voice
Fetches and returns the raw page source code for the Inbox. -
getInboxPage(int) - +
getInboxPage(int) - Method in class com.techventus.server.voice.Voice
Gets the inbox page. -
getIncomingAccessNumber() - +
getIncomingAccessNumber() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getJobberName() - +
getJobberName() - Method in class com.techventus.server.voice.datatypes.Greeting
  -
getLanguage() - +
getLanguage() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getLevel() - +
getLevel() - Method in class com.techventus.server.voice.datatypes.records.TranscriptElement
  -
getmActiveForwardingList() - +
getmActiveForwardingList() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getmDidInfos() - +
getmDidInfos() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getmDisabledIdList() - +
getmDisabledIdList() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getMissed() - +
getMissed() - Method in class com.techventus.server.voice.Voice
Gets the missed calls source code. -
getMissedPage(int) - +
getMissedPage(int) - Method in class com.techventus.server.voice.Voice
Gets the missed page. -
getMp3Url() - +
getMp3Url() - Method in class com.techventus.server.voice.datatypes.records.Voicemail
  -
getName() - +
getName() - Method in class com.techventus.server.voice.datatypes.Contact
  -
getName() - +
getName() - Method in class com.techventus.server.voice.datatypes.Greeting
  -
getName() - +
getName() - Method in class com.techventus.server.voice.datatypes.Group
  -
getName() - +
getName() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getNote() - +
getNote() - Method in class com.techventus.server.voice.datatypes.records.SMSThread
Returns the thread's note. -
getNumber() - +
getNumber() - Method in class com.techventus.server.voice.datatypes.Contact
Gets the phone number -
getPhoneList() - +
getPhoneList() - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
getPhoneListAsList() - +
getPhoneListAsList() - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
getPhoneListSorted() - +
getPhoneListSorted() - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
getPhoneNumber() - +
getPhoneNumber() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getPhoneNumber() - +
getPhoneNumber() - Method in class com.techventus.server.voice.Voice
Gets the phone number. -
getPhones() - +
getPhones() - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
getPhonesSorted() - +
getPhonesSorted() - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
getPlaced() - +
getPlaced() - Method in class com.techventus.server.voice.Voice
Gets the raw source code for the placed calls page. -
getPlacedPage(int) - +
getPlacedPage(int) - Method in class com.techventus.server.voice.Voice
Gets the placed page. -
getPolicyBitmask() - +
getPolicyBitmask() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getPrimaryDid() - +
getPrimaryDid() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getRawPhonesInfo() - +
getRawPhonesInfo() - Method in class com.techventus.server.voice.Voice
Gets the raw phones info. -
getRead() - +
getRead() - Method in class com.techventus.server.voice.datatypes.records.Record
Gets a boolean for whether or not the conversation has been read. -
getReceived() - +
getReceived() - Method in class com.techventus.server.voice.Voice
Gets the received calls source code. -
getReceivedPage(int) - +
getReceivedPage(int) - Method in class com.techventus.server.voice.Voice
Gets the received page. -
getRecent() - +
getRecent() - Method in class com.techventus.server.voice.Voice
Gets the raw page source code for the recent items. -
getRecentPage(int) - +
getRecentPage(int) - Method in class com.techventus.server.voice.Voice
Gets the recent page. -
getRecorded() - +
getRecorded() - Method in class com.techventus.server.voice.Voice
Gets the page source for the recorded calls. -
getRecordedPage(int) - +
getRecordedPage(int) - Method in class com.techventus.server.voice.Voice
Gets the recorded page. -
getScreenBehavior() - +
getScreenBehavior() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getSettings() - +
getSettings() - Method in class com.techventus.server.voice.datatypes.AllSettings
  -
getSettings(boolean) - +
getSettings(boolean) - Method in class com.techventus.server.voice.Voice
returns all users settings - lazy. -
getSMS() - +
getSMS() - Method in class com.techventus.server.voice.Voice
Gets the SMS page raw source code. -
getSmsNotifications() - +
getSmsNotifications() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getSMSPage(int) - +
getSMSPage(int) - Method in class com.techventus.server.voice.Voice
Gets the SMS page. -
getSMSThreads() - +
getSMSThreads() - Method in class com.techventus.server.voice.util.SMSParser
Returns the SMS threads. -
getSMSThreads() - +
getSMSThreads() - Method in class com.techventus.server.voice.Voice
Gets a collection of SMS threads. -
getSMSThreads(String) - +
getSMSThreads(String) - Method in class com.techventus.server.voice.Voice
Gets the SMS threads from a given Response Page. -
getSpam() - +
getSpam() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getSpam() - +
getSpam() - Method in class com.techventus.server.voice.Voice
Gets the page source for the spam. -
getSpamPage(int) - +
getSpamPage(int) - Method in class com.techventus.server.voice.Voice
Gets the spam page. -
getStarred() - +
getStarred() - Method in class com.techventus.server.voice.Voice
Gets the raw page source code for the starred items. -
getStarredPage(int) - +
getStarredPage(int) - Method in class com.techventus.server.voice.Voice
Gets the starred page. -
getText() - +
getText() - Method in class com.techventus.server.voice.datatypes.records.TranscriptElement
  -
getTimes() - +
getTimes() - Method in class com.techventus.server.voice.datatypes.Wd
  -
getTimes() - +
getTimes() - Method in class com.techventus.server.voice.datatypes.We
  -
getTimezone() - +
getTimezone() - Method in class com.techventus.server.voice.datatypes.Setting
  -
getTitle() - +
getTitle() - Method in class com.techventus.server.voice.datatypes.records.Record
  -
getTransscript() - +
getTransscript() - Method in class com.techventus.server.voice.datatypes.records.Voicemail
  -
getType() - +
getType() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getUnreadSMS() - +
getUnreadSMS() - Method in class com.techventus.server.voice.Voice
Gets the unread sms. -
getUnreadSMSPage(int) - +
getUnreadSMSPage(int) - Method in class com.techventus.server.voice.Voice
Gets the unread sms page. -
getUsername() - +
getUsername() - Method in class com.techventus.server.voice.Voice
Returns the username -
getVoicemail() - +
getVoicemail() - Method in class com.techventus.server.voice.Voice
Gets the Voicemail page raw source code. -
getVoicemailList(boolean) - +
getVoicemailList(boolean) - Method in class com.techventus.server.voice.Voice
Returns the Greeting list - Lazy -
getVoicemailPage(int) - +
getVoicemailPage(int) - Method in class com.techventus.server.voice.Voice
Gets the voicemail page. -
getWd() - +
getWd() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getWe() - +
getWe() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getWeekdayTimes() - +
getWeekdayTimes() - Method in class com.techventus.server.voice.datatypes.Phone
  -
getWeekendTimes() - +
getWeekendTimes() - Method in class com.techventus.server.voice.datatypes.Phone
  -
GOOGLE - +
GOOGLE - Static variable in class com.techventus.server.voice.Voice
The Constant GOOGLE. -
Greeting - Class in com.techventus.server.voice.datatypes
TODO Add jobberName
Greeting(int, String) - +
Greeting - Class in com.techventus.server.voice.datatypes
TODO Add jobberName
Greeting(int, String) - Constructor for class com.techventus.server.voice.datatypes.Greeting
  -
Greeting(int, String, String) - +
Greeting(int, String, String) - Constructor for class com.techventus.server.voice.datatypes.Greeting
  -
Group - Class in com.techventus.server.voice.datatypes
 
Group(String, String, boolean, List<DisabledForwardingId>, boolean, boolean, boolean, int) - +
Group - Class in com.techventus.server.voice.datatypes
 
Group(String, String, boolean, List<DisabledForwardingId>, boolean, boolean, boolean, int) - Constructor for class com.techventus.server.voice.datatypes.Group
  -
Group(String, String, boolean, DisabledForwardingId[], boolean, boolean, boolean, int) - +
Group(String, String, boolean, DisabledForwardingId[], boolean, boolean, boolean, int) - Constructor for class com.techventus.server.voice.datatypes.Group
  -
Group(JSONObject) - +
Group(JSONObject) - Constructor for class com.techventus.server.voice.datatypes.Group
  -
groupsArrayToJsonObject(Group[]) - +
groupsArrayToJsonObject(Group[]) - Static method in class com.techventus.server.voice.datatypes.Group
Groups array to json object.
diff --git a/doc/index-files/index-7.html b/doc/index-files/index-7.html index fc3c042..0d80e52 100644 --- a/doc/index-files/index-7.html +++ b/doc/index-files/index-7.html @@ -82,13 +82,13 @@

H

-
HOSTED - +
HOSTED - Static variable in class com.techventus.server.voice.Voice
The Constant HOSTED. -
HOSTED_OR_GOOGLE - +
HOSTED_OR_GOOGLE - Static variable in class com.techventus.server.voice.Voice
The Constant HOSTED_OR_GOOGLE. -
htmlEntitiesDecode(String) - +
htmlEntitiesDecode(String) - Static method in class com.techventus.server.voice.util.ParsingUtil
Replaces some speciel htmlEntities with a corresponding String.
diff --git a/doc/index-files/index-8.html b/doc/index-files/index-8.html index e4bc21a..5a83732 100644 --- a/doc/index-files/index-8.html +++ b/doc/index-files/index-8.html @@ -82,109 +82,109 @@

I

-
ID - +
ID - Static variable in class com.techventus.server.voice.util.JSONContants
  -
IS_READ - +
IS_READ - Static variable in class com.techventus.server.voice.util.JSONContants
  -
isActive() - +
isActive() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isCall() - +
isCall() - Method in class com.techventus.server.voice.datatypes.records.Record
  -
isCustomDirectConnect() - +
isCustomDirectConnect() - Method in class com.techventus.server.voice.datatypes.Group
  -
isCustomForwarding() - +
isCustomForwarding() - Method in class com.techventus.server.voice.datatypes.Group
  -
isCustomGreeting() - +
isCustomGreeting() - Method in class com.techventus.server.voice.datatypes.Group
  -
isdEPRECATEDDisabled() - +
isdEPRECATEDDisabled() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isDirectConnect() - +
isDirectConnect() - Method in class com.techventus.server.voice.datatypes.Group
  -
isDirectConnect() - +
isDirectConnect() - Method in class com.techventus.server.voice.datatypes.Setting
  -
isDisabled() - +
isDisabled() - Method in class com.techventus.server.voice.datatypes.ActiveForwardingId
  -
isDisabled() - +
isDisabled() - Method in class com.techventus.server.voice.datatypes.DisabledForwardingId
  -
isDisabled() - +
isDisabled() - Method in class com.techventus.server.voice.datatypes.DisabledId
  -
isDoNotDisturb() - +
isDoNotDisturb() - Method in class com.techventus.server.voice.datatypes.Setting
  -
isEmailNotificationActive() - +
isEmailNotificationActive() - Method in class com.techventus.server.voice.datatypes.Setting
  -
isEnabledForOthers() - +
isEnabledForOthers() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isLoggedIn() - +
isLoggedIn() - Method in class com.techventus.server.voice.Voice
Fires a Get request for Recent Items. -
isPhoneDisabled(int) - +
isPhoneDisabled(int) - Method in class com.techventus.server.voice.datatypes.AllSettings
Query disabled status - if id not found, then it returned false, which normally means enabled. -
isPhoneDisabled(int) - +
isPhoneDisabled(int) - Method in class com.techventus.server.voice.datatypes.Group
Query disabled status - if id not found, then it returns false, which means enabled. -
isRedirectToVoicemail() - +
isRedirectToVoicemail() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isScheduleSet() - +
isScheduleSet() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isShortMessage() - +
isShortMessage() - Method in class com.techventus.server.voice.datatypes.records.Record
  -
isShowTranscripts() - +
isShowTranscripts() - Method in class com.techventus.server.voice.datatypes.Setting
  -
isSmsEnabled() - +
isSmsEnabled() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isSmsToEmailActive() - +
isSmsToEmailActive() - Method in class com.techventus.server.voice.datatypes.Setting
  -
isSmsToEmailSubject() - +
isSmsToEmailSubject() - Method in class com.techventus.server.voice.datatypes.Setting
  -
isStarred() - +
isStarred() - Method in class com.techventus.server.voice.datatypes.records.SMSThread
Returns whether this thread is starred. -
isTelephonyVerified() - +
isTelephonyVerified() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isUseDidAsCallerId() - +
isUseDidAsCallerId() - Method in class com.techventus.server.voice.datatypes.Setting
  -
isUseDidAsSource() - +
isUseDidAsSource() - Method in class com.techventus.server.voice.datatypes.Setting
  -
isVerified() - +
isVerified() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isVoicemail() - +
isVoicemail() - Method in class com.techventus.server.voice.datatypes.records.Record
  -
isVoicemailForwardingVerified() - +
isVoicemailForwardingVerified() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isWeekdayAllDay() - +
isWeekdayAllDay() - Method in class com.techventus.server.voice.datatypes.Phone
  -
isWeekendAllDay() - +
isWeekendAllDay() - Method in class com.techventus.server.voice.datatypes.Phone
 
diff --git a/doc/index-files/index-9.html b/doc/index-files/index-9.html index 3bb1379..5d5fe50 100644 --- a/doc/index-files/index-9.html +++ b/doc/index-files/index-9.html @@ -82,19 +82,19 @@

J

-
JSONContants - Class in com.techventus.server.voice.util
JSON keys used in the Google Voice response.
JSONContants() - +
JSONContants - Class in com.techventus.server.voice.util
JSON keys used in the Google Voice response.
JSONContants() - Constructor for class com.techventus.server.voice.util.JSONContants
  -
jsonIntArrayToIntArray(JSONArray) - +
jsonIntArrayToIntArray(JSONArray) - Static method in class com.techventus.server.voice.util.ParsingUtil
Json int array to int array. -
jsonIntArrayToIntegerList(JSONObject, List<Integer>, String) - +
jsonIntArrayToIntegerList(JSONObject, List<Integer>, String) - Static method in class com.techventus.server.voice.util.ParsingUtil
Converts a Json Integer array to an ArrayList of Integers. -
jsonStringArrayToStringArray(JSONArray) - +
jsonStringArrayToStringArray(JSONArray) - Static method in class com.techventus.server.voice.util.ParsingUtil
Json string array to string array. -
jsonStringArrayToStringList(JSONObject, List<String>, String) - +
jsonStringArrayToStringList(JSONObject, List<String>, String) - Static method in class com.techventus.server.voice.util.ParsingUtil
Json string array to string list.
diff --git a/doc/package-use.html b/doc/package-use.html index a067c6a..4983342 100644 --- a/doc/package-use.html +++ b/doc/package-use.html @@ -4,7 +4,7 @@ -Uses of Package +Uses of Package @@ -83,7 +83,7 @@

Uses of Package

-No usage of +No usage of


diff --git a/doc/serialized-form.html b/doc/serialized-form.html index 5bccd69..bb456fa 100644 --- a/doc/serialized-form.html +++ b/doc/serialized-form.html @@ -190,7 +190,7 @@

 java.lang.String captchaToken
-
Token representing the specific Captcha challenge. Google supplies this token and the +
Token representing the specific Captcha challenge. Google supplies this token and the CAPTCHA image URL in a login failed response with the error code "CaptchaRequired".

diff --git a/doc/stylesheet.css b/doc/stylesheet.css index 6ea9e51..d81286d 100644 --- a/doc/stylesheet.css +++ b/doc/stylesheet.css @@ -26,4 +26,3 @@ h1 { font-size: 145% } .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} - diff --git a/doc/test/class-use/test.html b/doc/test/class-use/test.html index 5dfff44..3f92d6c 100644 --- a/doc/test/class-use/test.html +++ b/doc/test/class-use/test.html @@ -1,144 +1,144 @@ - - - - - - -Uses of Class test.test - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Class
test.test

-
-No usage of test.test -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - + + + + + + +Uses of Class test.test + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Uses of Class
test.test

+
+No usage of test.test +

+


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/doc/test/package-frame.html b/doc/test/package-frame.html index 1f18312..7e22dc8 100644 --- a/doc/test/package-frame.html +++ b/doc/test/package-frame.html @@ -1,32 +1,32 @@ - - - - - - -test - - - - - - - - - - - -test - - - - -
-Classes  - -
-test
- - - - + + + + + + +test + + + + + + + + + + + +test + + + + +
+Classes  + +
+test
+ + + + diff --git a/doc/test/package-summary.html b/doc/test/package-summary.html index 16ffaa8..23c3798 100644 --- a/doc/test/package-summary.html +++ b/doc/test/package-summary.html @@ -1,157 +1,157 @@ - - - - - - -test - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-

-Package test -

- - - - - - - - - -
-Class Summary
test 
-  - -

-

-
-
- - - - - - - - - - - - - - - -
- -
- - - -
- - - + + + + + + +test + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package test +

+ + + + + + + + + +
+Class Summary
test 
+  + +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/doc/test/package-tree.html b/doc/test/package-tree.html index 8e751da..6acc46e 100644 --- a/doc/test/package-tree.html +++ b/doc/test/package-tree.html @@ -1,153 +1,153 @@ - - - - - - -test Class Hierarchy - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Hierarchy For Package test -

-
-
-
Package Hierarchies:
All Packages
-
-

-Class Hierarchy -

-
    -
  • java.lang.Object -
-
- - - - - - - - - - - - - - - -
- -
- - - -
- - - + + + + + + +test Class Hierarchy + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package test +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+
    +
  • java.lang.Object +
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/doc/test/package-use.html b/doc/test/package-use.html index 03c7044..ab755d7 100644 --- a/doc/test/package-use.html +++ b/doc/test/package-use.html @@ -1,144 +1,144 @@ - - - - - - -Uses of Package test - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Package
test

-
-No usage of test -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - + + + + + + +Uses of Package test + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Uses of Package
test

+
+No usage of test +

+


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/doc/test/test.html b/doc/test/test.html index 96dc688..f629666 100644 --- a/doc/test/test.html +++ b/doc/test/test.html @@ -1,360 +1,360 @@ - - - - - - -test - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

- -test -
-Class test

-
-java.lang.Object
-  extended by test.test
-
-
-
-
public class test
extends java.lang.Object
- - -

-


- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Field Summary
-(package private) static java.io.BufferedReaderbr - -
-           
-(package private) static booleanconnectOnStartup - -
-           
-(package private) static java.lang.Stringpass - -
-           
-(package private) static java.util.PropertiestestProps - -
-           
-(package private) static java.lang.StringuserName - -
-           
-  - - - - - - - - - - -
-Constructor Summary
test() - -
-           
-  - - - - - - - - - - - -
-Method Summary
-static voidmain(java.lang.String[] args) - -
-           
- - - - - - - -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-  -

- - - - - - - - -
-Field Detail
- -

-br

-
-static java.io.BufferedReader br
-
-
-
-
-
- -

-userName

-
-static java.lang.String userName
-
-
-
-
-
- -

-pass

-
-static java.lang.String pass
-
-
-
-
-
- -

-connectOnStartup

-
-static boolean connectOnStartup
-
-
-
-
-
- -

-testProps

-
-static java.util.Properties testProps
-
-
-
-
- - - - - - - - -
-Constructor Detail
- -

-test

-
-public test()
-
-
- - - - - - - - -
-Method Detail
- -

-main

-
-public static void main(java.lang.String[] args)
-
-
-
-
-
- -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - + + + + + + +test + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +test +
+Class test

+
+java.lang.Object
+  extended by test.test
+
+
+
+
public class test
extends java.lang.Object
+ + +

+


+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Field Summary
+(package private) static java.io.BufferedReaderbr + +
+           
+(package private) static booleanconnectOnStartup + +
+           
+(package private) static java.lang.Stringpass + +
+           
+(package private) static java.util.PropertiestestProps + +
+           
+(package private) static java.lang.StringuserName + +
+           
+  + + + + + + + + + + +
+Constructor Summary
test() + +
+           
+  + + + + + + + + + + + +
+Method Summary
+static voidmain(java.lang.String[] args) + +
+           
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+br

+
+static java.io.BufferedReader br
+
+
+
+
+
+ +

+userName

+
+static java.lang.String userName
+
+
+
+
+
+ +

+pass

+
+static java.lang.String pass
+
+
+
+
+
+ +

+connectOnStartup

+
+static boolean connectOnStartup
+
+
+
+
+
+ +

+testProps

+
+static java.util.Properties testProps
+
+
+
+
+ + + + + + + + +
+Constructor Detail
+ +

+test

+
+public test()
+
+
+ + + + + + + + +
+Method Detail
+ +

+main

+
+public static void main(java.lang.String[] args)
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/libs/dom4j-1.6.1.jar b/libs/dom4j-1.6.1.jar deleted file mode 100644 index c8c4dbb..0000000 Binary files a/libs/dom4j-1.6.1.jar and /dev/null differ diff --git a/libs/jaxen-1.1.3.jar b/libs/jaxen-1.1.3.jar deleted file mode 100644 index ddb470d..0000000 Binary files a/libs/jaxen-1.1.3.jar and /dev/null differ diff --git a/libs/json.jar b/libs/json.jar deleted file mode 100644 index aeea6c6..0000000 Binary files a/libs/json.jar and /dev/null differ diff --git a/libs/jtidy.jar b/libs/jtidy.jar deleted file mode 100644 index efde902..0000000 Binary files a/libs/jtidy.jar and /dev/null differ diff --git a/libs/junit-4.11.jar b/libs/junit-4.11.jar deleted file mode 100644 index aaf7444..0000000 Binary files a/libs/junit-4.11.jar and /dev/null differ diff --git a/src/main/java/.gitkeep b/src/main/java/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/com/techventus/server/voice/GVCookieManager.java b/src/main/java/com/techventus/server/voice/GVCookieManager.java new file mode 100644 index 0000000..ff67a17 --- /dev/null +++ b/src/main/java/com/techventus/server/voice/GVCookieManager.java @@ -0,0 +1,193 @@ +package com.techventus.server.voice; + +import com.techventus.server.voice.util.ArrayUtil; + +import java.io.IOException; +import java.net.CookieManager; +import java.net.URI; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.io.File; // Added +import java.io.FileInputStream; // Added +import java.io.InputStream; // Already present, but good to confirm +import java.util.Properties; // Already present + +/** + * Created by josephmalone on 2016-11-18. + */ +public class GVCookieManager extends CookieManager{ + + private static final String TAG = GVCookieManager.class.getSimpleName(); + + private static volatile GVCookieManager mInstance; + + private static Map COOKIE_MAP; + + + /** + * Set the cookie value in the persistent cookie manager. + * If the cookie map changes, set the updated flag to true so the PersistenceManager can + * store the values to shared preferences. + * + * @param cookieTuple + * @return + */ + public void setCookie(final String[] cookieTuple) + { + if (!ArrayUtil.isNullOrContainsEmpty(cookieTuple) && cookieTuple.length == 2 && !(COOKIE_MAP.containsKey(cookieTuple[0]) && COOKIE_MAP.get( + cookieTuple[0]).equals(cookieTuple[1]))) + { + setCookie(cookieTuple[0], cookieTuple[1]); + } + } + + public Map getCookies() + { + return COOKIE_MAP; + } + + public void setCookie(final String key, final String value) + { + COOKIE_MAP.put(key, value); + } + + public static GVCookieManager getInstance() + { + if (mInstance == null) + { + synchronized (GVCookieManager.class) + { + if (mInstance == null) + { + mInstance = new GVCookieManager(); + } + } + } + + return mInstance; + } + + private GVCookieManager() + { + super(); + + if (COOKIE_MAP == null) + { + COOKIE_MAP = new HashMap<>(); + } + loadCookiesFromFile(); +// loadMap(); + } + + private void loadCookiesFromFile() { + Properties props = new Properties(); + File propertiesFile = new File( + System.getProperty("user.home") + File.separator + + ".credentials" + File.separator + "google-voice-java" + File.separator + + "google-auth.properties" + ); + + if (!propertiesFile.exists()) { + System.err.println("Properties file not found: " + propertiesFile.getAbsolutePath()); + return; + } + + InputStream input = null; + try { + input = new FileInputStream(propertiesFile); + props.load(input); + for (String key : props.stringPropertyNames()) { + String value = props.getProperty(key); + COOKIE_MAP.put(key, value); + // System.out.println("Loaded cookie/token: " + key + "=" + value); // Optional + } + } catch (IOException ex) { + System.err.println("Error reading properties file '" + propertiesFile.getAbsolutePath() + "': " + ex.getMessage()); + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException e) { + // Log or ignore + } + } + } + } +// +// private void saveMap() +// { +// PreferencesManager.getInstance().setAuthToken(mAuthToken); +// PreferencesManager.getInstance().setSerialisedCookieMap(COOKIE_MAP, true); +// } +// +// private void loadMap() +// { +// mAuthToken = PreferencesManager.getInstance().getAuthToken(); +// COOKIE_MAP.putAll(PreferencesManager.getInstance().getSerialisedCookieMap()); +// } + + public void clearCookies() + { + COOKIE_MAP.clear(); +// PreferencesManager.getInstance().clearCookieMap(); +// saveCookiesIfNeeded(); + + } + + + + + private static String[] getCookieKeyValue(final String flatCookieString) + { + if (ArrayUtil.isNotEmpty(flatCookieString) && flatCookieString.contains(";")) + { + String trimmed = flatCookieString.substring(0, flatCookieString.indexOf(";", 0)); + if (trimmed.contains("=")) + { + return trimmed.split("=", 2); + } + } + + return null; + } + + @Override + public Map> get(final URI uri, final Map> requestHeaders) throws IOException + { + Map> ret = super.get(uri, requestHeaders); + return ret; + } + + @Override + public void put(final URI uri, final Map> stringListMap) throws IOException + { + super.put(uri, stringListMap); + + if (stringListMap != null && stringListMap.get("Set-Cookie") != null) + { + for (String string : stringListMap.get("Set-Cookie")) + { + setCookie(getCookieKeyValue(string)); + } + } +// saveCookiesIfNeeded(); + } + + public String listAllOutgoingCookies() + { + Map cookieMap = getCookies(); + StringBuilder sb = new StringBuilder(); + + for (String key : cookieMap.keySet()) + { + sb.append(key + "=").append(cookieMap.get(key)).append("; "); + } + return sb.toString(); + } + + public void setCookies(Map cookieMap) { + clearCookies(); + COOKIE_MAP = cookieMap; + } +} diff --git a/src/com/techventus/server/voice/Voice.java b/src/main/java/com/techventus/server/voice/Voice.java similarity index 81% rename from src/com/techventus/server/voice/Voice.java rename to src/main/java/com/techventus/server/voice/Voice.java index ba36c51..e334d90 100644 --- a/src/com/techventus/server/voice/Voice.java +++ b/src/main/java/com/techventus/server/voice/Voice.java @@ -1,2146 +1,2255 @@ -/* - * Voice.java - * - * Created: Sat Mar 13 14:41:11 2010 - * - * Copyright (C) 2010-2012 Techventus, LLC - * - * Techventus, LLC is not responsible for any use or misuse of this product. - * In using this software you agree to hold harmless Techventus, LLC and any other - * contributors to this project from any damages or liabilities which might result - * from its use. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 3 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -package com.techventus.server.voice; - -import gvjava.org.json.JSONException; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import com.techventus.server.voice.datatypes.AllSettings; -import com.techventus.server.voice.datatypes.Greeting; -import com.techventus.server.voice.datatypes.Group; -import com.techventus.server.voice.datatypes.Phone; -import com.techventus.server.voice.datatypes.records.SMSThread; -import com.techventus.server.voice.exception.AuthenticationException; -import com.techventus.server.voice.exception.ERROR_CODE; -import com.techventus.server.voice.util.ParsingUtil; -import com.techventus.server.voice.util.SMSParser; - -/** - * The Class Voice. This class is the basis of the entire API and contains all - * the components necessary to connect and authenticate with Google Voice, place - * calls and SMS, and pull in the raw data from the account. - * - * @author Techventus, LLC - */ -@SuppressWarnings("deprecation") -public class Voice { - - /** The PRINT to Console FLAG setting. */ - public boolean PRINT_TO_CONSOLE; - - /** keeps the list of phones - lazy. */ - - private AllSettings settings; - - /** The general. */ - String general = null; - - /** The phones info. */ - String phonesInfo = null; - - /** The rnr see. */ - String rnrSEE = null; - - /** The error. */ - private ERROR_CODE error; - - /** - * Short string identifying your application, for logging purposes. This string should take the form: - * "companyName-applicationName-versionID". See: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Request - */ - String source = null; - /** - * User's full email address. It must include the domain (i.e. johndoe@gmail.com). - */ - private String user = null; - /** - * User's password. - */ - private String pass = null; - /** - * Google Voice Phone Number. - */ - private String phoneNumber = null; - /** - * Once the login information has been successfully authenticated, Google returns a token, which your - * application will reference each time it requests access to the user's account. - * This token must be included in all subsequent requests to the Google service for this account. - * Authorization tokens should be closely guarded and should not be given to any other application, - * as they represent access to the user's account. The time limit on the token varies depending on - * which service issued it. - */ - private String authToken = null; - /** - * (optional) Token representing the specific CAPTCHA challenge. Google supplies this token and the - * CAPTCHA image URL in a login failed response with the error code "CaptchaRequired". - */ - private String captchaToken = null; - - /** Url of the image with the captcha - only filled after a captacha response to a login try. */ - private String captchaUrl = null; - - /** The captcha url2. */ - private String captchaUrl2 = null; - - /** Counts the amount of redirects we are doing in the get(String url) method to avoid infinite loop. */ - private int redirectCounter = 0; - - /** Maximum amount of redirects before we throw an exception. */ - private static int MAX_REDIRECTS = 5; - - /** The Constant enc. */ - final static String enc = "UTF-8"; - - /** The Constant USER_AGENT. */ - final static String USER_AGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13"; - - /** The Constant GOOGLE. */ - public final static String GOOGLE = "GOOGLE"; - - /** The Constant HOSTED. */ - public final static String HOSTED = "HOSTED"; - - /** The Constant HOSTED_OR_GOOGLE. */ - public final static String HOSTED_OR_GOOGLE = "HOSTED_OR_GOOGLE"; - /** - * Type of account to request authorization for. Possible values are:

- * -GOOGLE (get authorization for a Google account only)
- * -HOSTED (get authorization for a hosted account only)
- * -HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get - * authorization for a Google account)

- * Use HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. - * If the user information matches both a hosted and a Google account, only the hosted account is authorized. - */ - private String account_type = GOOGLE; - - /** - * Name of the Google service you're requesting authorization for. Each service using the Authorization - * service is assigned a name value; for example, the name associated with Google Calendar is 'cl'. - * This parameter is required when accessing services based on Google Data APIs. For specific service - * names, refer to the service documentation. - */ - final static String SERVICE = "grandcentral"; - - /** The Constant generalURLString. */ - final static String generalURLString = "https://www.google.com/voice/b/0"; - - /** The Constant loginURLString. */ - final static String loginURLString = "https://www.google.com/accounts/ClientLogin"; - - /** The Constant inboxURLString. */ - final static String inboxURLString = "https://www.google.com/voice/b/0/inbox/recent/inbox/"; - - /** The Constant starredURLString. */ - final static String starredURLString = "https://www.google.com/voice/b/0/inbox/recent/starred/"; - - /** The Constant recentAllURLString. */ - final static String recentAllURLString = "https://www.google.com/voice/b/0/inbox/recent/all/"; - - /** The Constant spamURLString. */ - final static String spamURLString = "https://www.google.com/voice/b/0/inbox/recent/spam/"; - - /** The Constant trashURLString. */ - final static String trashURLString = "https://www.google.com/voice/b/0/inbox/recent/spam/"; - - /** The Constant voicemailURLString. */ - final static String voicemailURLString = "https://www.google.com/voice/b/0/inbox/recent/voicemail/"; - - /** The Constant smsURLString. */ - final static String smsURLString = "https://www.google.com/voice/b/0/inbox/recent/sms/"; - - /** The Constant recordedURLString. */ - final static String recordedURLString = "https://www.google.com/voice/b/0/inbox/recent/recorded/"; - - /** The Constant placedURLString. */ - final static String placedURLString = "https://www.google.com/voice/b/0/inbox/recent/placed/"; - - /** The Constant receivedURLString. */ - final static String receivedURLString = "https://www.google.com/voice/b/0/inbox/recent/received/"; - - /** The Constant missedURLString. */ - final static String missedURLString = "https://www.google.com/voice/b/0/inbox/recent/missed/"; - - /** The Constant phoneEnableURLString. */ - final static String phoneEnableURLString = "https://www.google.com/voice/b/0/settings/editDefaultForwarding/"; - - /** The Constant generalSettingsURLString. */ - final static String generalSettingsURLString = "https://www.google.com/voice/b/0/settings/editGeneralSettings/"; - - /** The Constant editForwardingSMSURLString. */ - final static String editForwardingSMSURLString = "https://www.google.com/voice/b/0/settings/editForwardingSms/"; - - /** The Constant phonesInfoURLString. */ - final static String phonesInfoURLString = "https://www.google.com/voice/b/0/settings/tab/phones"; - - /** The Constant groupsInfoURLString. */ - final static String groupsInfoURLString = "https://www.google.com/voice/b/0/settings/tab/groups"; - - /** The Constant voicemailInfoURLString. */ - final static String voicemailInfoURLString = "https://www.google.com/voice/b/0/settings/tab/voicemailsettings"; - - /** The Constant groupsSettingsURLString. */ - final static String groupsSettingsURLString = "https://www.google.com/voice/b/0/settings/editGroup/"; - - /** The Constant voicemailDownloadURLString. */ - final static String voicemailDownloadURLString = "https://www.google.com/voice/media/send_voicemail/"; - - /** The Constant markAsReadString. */ - final static String markAsReadString = "https://www.google.com/voice/b/0/inbox/mark/"; - - /** The Constant unreadSMSString. */ - final static String unreadSMSString = "https://www.google.com/voice/b/0/inbox/recent/sms/unread/"; - - //Experimental keyFlag is just there to overload method - public Voice(String authToken ) throws IOException{ - this.authToken = authToken; - this.pass = "UNKNOWN"; - this.user = "UNKNOWN"; - - this.source = "GoogleVoiceJava"; - - - this.general = getGeneral(); - this.setRNRSEE(); - - String response = this.getRawPhonesInfo(); - int phoneIndex = response.indexOf("gc-user-number-value\">"); - this.phoneNumber = response.substring(phoneIndex + 22, phoneIndex + 36); - this.phoneNumber = this.phoneNumber.replaceAll("[^a-zA-Z0-9]", ""); - if (this.phoneNumber.indexOf("+") == -1) { - this.phoneNumber = "+1" + this.phoneNumber; - } - - } - - /** - * Instantiates a new voice. This constructor is deprecated. Try - * Voice(String user, String pass) which automatically determines rnrSee and - * assigns a source. - * - * @param user - * the user - * @param pass - * the pass - * @param source - * the source - * @param rnrSee - * the rnr see - * @throws IOException - * Signals that an I/O exception has occurred. - */ - @Deprecated - public Voice(String user, String pass, String source, String rnrSee) - throws IOException { - - this.user = user; - this.pass = pass; - this.rnrSEE = rnrSee; - this.source = source; - - login(); - } - - /** - * A constructor which which allows a custom source. - * This Constructor enables verbose output. - * - * @param user - * the username in the format of user@gmail.com or user@googlemail.com - * @param pass - * the password - * @param source - * Short string identifying your application, for logging purposes. This string should take the form: - "companyName-applicationName-versionID". See: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Request - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public Voice(String user, String pass, String source) throws IOException { - init(user, pass, source, true, GOOGLE, null, null); - - } - - /** - * Instantiates a new Voice Object. This is generally the simplest and - * preferred constructor. This Constructor enables verbose output. - * - * @param user - * the username in the format of user@gmail.com or user@googlemail.com - * @param pass - * the pass - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public Voice(String user, String pass) throws IOException { - init(user, pass, null, true, GOOGLE, null, null); - } - - /** - * Instantiates a new voice. Custom Source Variable allowed, and - * printDebugIntoSystemOut which allows for Verbose output. - * - * @param user - * the username in the format of user@gmail.com or user@googlemail.com - * @param pass - * the password - * @param source - * the arbitrary source identifier. Can be anything. - * @param printDebugIntoToSystemOut - * the print debug into to system out - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public Voice(String user, String pass, String source, - boolean printDebugIntoToSystemOut) throws IOException { - init(user, pass, source, printDebugIntoToSystemOut, GOOGLE, null, null); - } - - /** - * Instantiates a new voice. Custom Source Variable allowed, and - * printDebugIntoSystemOut which allows for Verbose output. - * - * @param user - * the username in the format of user@gmail.com or user@googlemail.com - * @param pass - * the password - * @param source - * the arbitrary source identifier. Can be anything. - * @param printDebugIntoToSystemOut - * the print debug into to system out - * @param accountType - * Type of account to request authorization for. Possible values are: - * Voice.GOOGLE (get authorization for a Google account only) - * Voice.HOSTED (get authorization for a hosted account only) - * Voice.HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account) - * Use Voice.HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized. - * - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public Voice(String user, String pass, String source, - boolean printDebugIntoToSystemOut, String accountType) throws IOException { - init(user, pass, source, printDebugIntoToSystemOut, accountType, null, null); - } - - /** - * Instantiates a new voice. Custom Source Variable allowed, and - * printDebugIntoSystemOut which allows for Verbose output. - * - * @param user - * the username in the format of user@gmail.com or user@googlemail.com - * @param pass - * the password - * @param source - * the arbitrary source identifier. Can be anything. - * @param printDebugIntoToSystemOut - * the print debug into to system out - * @param accountType - * Type of account to request authorization for. Possible values are: - * Voice.GOOGLE (get authorization for a Google account only) - * Voice.HOSTED (get authorization for a hosted account only) - * Voice.HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account) - * Use Voice.HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized. - * @param captchaResponse - * response to a captcha challenge, set to null if normal login - * @param captchaToken - * (optional) token which matches the response/url from the captcha challenge - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public Voice(String user, String pass, String source, - boolean printDebugIntoToSystemOut, String accountType, String captchaResponse, String captchaToken) throws IOException { - init(user, pass, source, printDebugIntoToSystemOut, accountType, captchaResponse, captchaToken); - } - - /** - * Internal function used by all constructors to fully initiate the Voice - * Object without chaptcha Response. - * - * @param user the username in the format of user@gmail.com or user@googlemail.com - * @param pass the password for the google account - * @param source the source - * @param printDebugIntoToSystemOut the print debug into to system out - * @param accountType Type of account to request authorization for. Possible values are: - * Voice.GOOGLE (get authorization for a Google account only) - * Voice.HOSTED (get authorization for a hosted account only) - * Voice.HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account) - * Use Voice.HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized. - * @param captchaResponse response to a captcha challenge, set to null if normal login - * @param captchaToken token which matches the response/url from the captcha challenge - * @throws IOException Signals that an I/O exception has occurred. - */ - private void init(String user, String pass, String source, - boolean printDebugIntoToSystemOut, String accountType, String captchaResponse, String captchaToken) throws IOException { - if(accountType==GOOGLE||accountType==HOSTED||accountType==HOSTED_OR_GOOGLE) { - this.account_type = accountType; - this.PRINT_TO_CONSOLE = printDebugIntoToSystemOut; - this.user = user; - this.pass = pass; - // this.rnrSEE = rnrSee; - if (source != null) { - this.source = source; - } else { - this.source = "GoogleVoiceJava"; - } - - login(captchaResponse,captchaToken); - this.general = getGeneral(); - setRNRSEE(); - } else { - throw new IOException("AccountType not valid"); - } - } - - /** - * Returns the username - * @return username for gvoice account - */ - public String getUsername() - { - return this.user; - } - - /** - * Returns the Greeting list - Lazy - * @param forceUpdate set to true to force a List update from the server - * @return List of Greeting objects - * @throws IOException Signals that an I/O exception has occurred. - * @throws JSONException the jSON exception - */ - public List getVoicemailList(boolean forceUpdate) throws IOException, JSONException { - List lGList = new ArrayList(); - Greeting[] lGArray = getSettings(forceUpdate).getSettings().getGreetings(); - for (int i = 0; i < lGArray.length; i++) { - lGList.add(lGArray[i]); - } - return lGList; - } - - /** - * Returns the Group list - Lazy. Not yet Implemented - * - * @param forceUpdate the force update - * @return List of Greeting objects - * @throws IOException Signals that an I/O exception has occurred. - */ - public List getGroupSettingsList(boolean forceUpdate) throws IOException { -// return getSettings(forceUpdate).getGroupSettingsList(); -// List lGList = new ArrayList(); -// String[] lGArray = getSettings(forceUpdate).getSettings().getGroups().; -// for (int i = 0; i < lGArray.length; i++) { -// lGList.add(lGArray[i]); -// } -// return lGList; - //TODO implement getGroupSettingsList - return null; - } - - /** - * returns all users settings - lazy. - * - * @param forceUpdate the force update - * @return the settings - * @throws JSONException the jSON exception - * @throws IOException Signals that an I/O exception has occurred. - */ - public AllSettings getSettings(boolean forceUpdate) throws JSONException, IOException { - if(settings==null || forceUpdate) { - if(isLoggedIn()==false || forceUpdate) { - login(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - - e.printStackTrace(); - } - } - if(PRINT_TO_CONSOLE) System.out.println("Fetching Settings."); - // remove html overhead - String lJson = ParsingUtil.removeUninterestingParts(get(groupsInfoURLString), "", false); - try { - settings = new AllSettings(lJson); - } catch (JSONException e) { - throw new JSONException(e.getMessage()+lJson); - } - } - return settings; - } - - // public Voice(){ - // authToken = "abcde"; - // } - - /** - * Fetches and returns the raw page source code for the Inbox. - * - * @return the inbox - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getInbox() throws IOException { - return get(inboxURLString); - } - - /** - * Gets the inbox page. - * - * @param page the page - * @return the inbox page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getInboxPage(int page) throws IOException { - return get(inboxURLString,page); - } - - /** - * Fetches the page Source Code for the Voice homepage. This file contains - * most of the useful information for the Google Voice Account such as - * attached PhoneOld info and Contacts. - * - * @return the general - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getGeneral() throws IOException { - return get(generalURLString); - } - - /** - * The main Google Voice section is paginated. Access the raw HTML for - * specific page of the main section. - * - * @param page the page - * @return the general page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getGeneralPage(int page) throws IOException { - return get(generalURLString,page); - } - - /** - * Gets the raw page source code for the starred items. - * - * @return the starred item page source - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getStarred() throws IOException { - return get(starredURLString); - } - - /** - * Gets the starred page. - * - * @param page the page - * @return the starred page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getStarredPage(int page) throws IOException { - return get(starredURLString,page); - } - - - /** - * Gets the raw page source code for the recent items. - * - * @return the recent raw source code - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getRecent() throws IOException { - return get(recentAllURLString); - } - - /** - * Gets the recent page. - * - * @param page the page - * @return the recent page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getRecentPage(int page) throws IOException { - return get(recentAllURLString,page); - } - - /** - * Gets the page source for the spam. - * - * @return the spam - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getSpam() throws IOException { - return get(spamURLString); - } - - /** - * Gets the spam page. - * - * @param page the page - * @return the spam page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getSpamPage(int page) throws IOException { - return get(spamURLString,page); - } - - /** - * Gets the page source for the recorded calls. - * - * @return the recorded - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getRecorded() throws IOException { - return get(recordedURLString); - } - - /** - * Gets the recorded page. - * - * @param page the page - * @return the recorded page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getRecordedPage(int page) throws IOException { - return get(recordedURLString,page); - } - - /** - * Gets the raw source code for the placed calls page. - * - * @return the placed calls source code - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getPlaced() throws IOException { - return get(placedURLString); - } - - /** - * Gets the placed page. - * - * @param page the page - * @return the placed page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getPlacedPage(int page) throws IOException { - return get(placedURLString,page); - } - - /** - * Gets the received calls source code. - * - * @return the received - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getReceived() throws IOException { - return get(receivedURLString); - } - - /** - * Gets the received page. - * - * @param page the page - * @return the received page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getReceivedPage(int page) throws IOException { - return get(receivedURLString,page); - } - - /** - * Gets the missed calls source code. - * - * @return the missed - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getMissed() throws IOException { - return get(missedURLString); - } - - /** - * Gets the missed page. - * - * @param page the page - * @return the missed page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getMissedPage(int page) throws IOException { - return get(missedURLString,page); - } - - - /** - * Gets the unread sms. - * - * @return the unread sms - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getUnreadSMS() throws IOException{ - return get(unreadSMSString); - } - - /** - * Gets the unread sms page. - * - * @param page the page - * @return the unread sms page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getUnreadSMSPage(int page) throws IOException{ - return get(unreadSMSString,page); - } - - - - - - - - - /** - * Gets the Voicemail page raw source code. - * - * @return the Voicemail - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getVoicemail() throws IOException { - return get(voicemailURLString); - } - - /** - * Gets the voicemail page. - * - * @param page the page - * @return the voicemail page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getVoicemailPage(int page) throws IOException { - return get(voicemailURLString,page); - } - - /** - * Downloads a voicemail. - * - * @param msgID the msg id - * @return byte output stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public ByteArrayOutputStream downloadVoicemail(String msgID) throws IOException - { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - - try - { - URL u = new URL (voicemailDownloadURLString + msgID); - HttpURLConnection huc = (HttpURLConnection)u.openConnection () ; - huc.setRequestProperty("Authorization", "GoogleLogin auth="+authToken); - huc.setRequestProperty("User-agent", USER_AGENT); - huc.setRequestMethod ("GET"); - huc.connect() ; - InputStream is = huc.getInputStream(); - - if(huc.getResponseCode() == HttpURLConnection.HTTP_OK) - { - byte[] buffer = new byte [4096]; - int bytes = 0; - - while(true) - { - bytes = is.read(buffer); - if(bytes <= 0) - break; - outputStream.write(buffer, 0, bytes); - } - - outputStream.flush(); - } - - huc.disconnect (); - - return outputStream; - } - catch(IOException e) - { - System.out.println ( "Exception\n" + e ) ; - } - - return null; - } - - /** - * Gets the SMS page raw source code. - * - * @return the sMS - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String getSMS() throws IOException { - return get(smsURLString); - } - - - - /** - * Gets the SMS page. - * - * @param page the page - * @return the sMS page - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getSMSPage(int page) throws IOException { - return get(smsURLString,page); - } - - - - /** - * Gets a collection of SMS threads. Each SMS thread has a collection of SMS - * objects which contains contact, text and timestamp information. - * - * @return a collection of SMS threads. - * @throws IOException Signals that an I/O exception has occurred. - */ - public Collection getSMSThreads() throws IOException { - SMSParser parser = new SMSParser(get(smsURLString), phoneNumber); - return parser.getSMSThreads(); - } - - /** - * Gets a collection of SMS threads. Each SMS thread has a collection of SMS - * objects which contains contact, text and timestamp information. - * - * @return a collection of SMS threads. - * @throws IOException Signals that an I/O exception has occurred. - */ - public Collection getSMSThreads(int page ) throws IOException { - SMSParser parser = new SMSParser(get(smsURLString, page), phoneNumber); - return parser.getSMSThreads(); - } - - - /** - * Gets the SMS threads from a given Response Page. - * - * @param response the response - * @return the SMS threads - */ - public Collection getSMSThreads(String response){ - SMSParser parser= new SMSParser(response, phoneNumber); - return parser.getSMSThreads(); - } - - - /** - * Gets the rNRSEE. - * - * @return the rNRSEE - */ - public String getRNRSEE(){ - return rnrSEE; - } - - /** - * Internal method which parses the Homepage source code to determine the - * rnrsee variable, this variable is passed into most fuctions for placing - * calls and sms. - * - * @throws IOException Signals that an I/O exception has occurred. - */ - private void setRNRSEE() throws IOException { - if (general != null) { - if(general.contains("'_rnr_se': '")) { - String p1 = general.split("'_rnr_se': '", 2)[1]; - rnrSEE = p1.split("',", 2)[0]; - if(PRINT_TO_CONSOLE) - System.out.println("Successfully Received rnr_se."); - p1 = null; - } else if(general.contains("
")) { - String gcNotice = ParsingUtil.removeUninterestingParts(general, "
", "
", false); - System.out.println(gcNotice+ "(Answer did not contain rnr_se)"); - throw new IOException(gcNotice + "(Answer did not contain rnr_se)"); - } else { - System.out.println("Answer did not contain rnr_se! "+ general); - throw new IOException("Answer did not contain rnr_se! "+ general); - } - } else { - System.out.println("setRNRSEE(): Answer was null!"); - throw new IOException("setRNRSEE(): Answer was null!"); - } - } - - /** - * Gets the phone number. - * - * @return the phone number - */ - public String getPhoneNumber() - { - return this.phoneNumber; - } - - //TODO Combine with or replace setPhoneInfo - /** - * Gets the raw phones info. - * - * @return the raw phones info - * @throws IOException Signals that an I/O exception has occurred. - */ - public String getRawPhonesInfo() throws IOException{ - return get(phonesInfoURLString); - } - - /** - * Place a call. - * - * @param originNumber - * the origin number - * @param destinationNumber - * the destination number - * @param phoneType - * the phone type, this is a number such as 1,2,7 formatted as a String - * @return the raw response string received from Google Voice. - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String call(String originNumber, String destinationNumber, - String phoneType) throws IOException { - String out = ""; - StringBuffer calldata = new StringBuffer(); - - - // POST /voice/call/connect/ - // outgoingNumber=[number to call] - // &forwardingNumber=[forwarding number] - // &subscriberNumber=undefined - // &phoneType=[phone type from google] - // &remember=0 - // &_rnr_se=[pull from page] - - calldata.append("outgoingNumber="); - calldata.append(URLEncoder.encode(destinationNumber, enc)); - calldata.append("&forwardingNumber="); - calldata.append(URLEncoder.encode(originNumber, enc)); - calldata.append("&subscriberNumber=undefined"); - calldata.append("&phoneType="); - calldata.append(URLEncoder.encode(phoneType, enc)); - calldata.append("&remember=0"); - calldata.append("&_rnr_se="); - calldata.append(URLEncoder.encode(rnrSEE, enc)); - - - URL callURL = new URL("https://www.google.com/voice/b/0/call/connect/"); - - URLConnection callconn = callURL.openConnection(); - callconn.setRequestProperty("Authorization","GoogleLogin auth="+authToken); - callconn.setRequestProperty("User-agent",USER_AGENT); - - callconn.setDoOutput(true); - OutputStreamWriter callwr = new OutputStreamWriter(callconn - .getOutputStream()); - - callwr.write(calldata.toString()); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader( - callconn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - - } - - /** - * Cancel a call that was just placed. - * - * @param originNumber - * the origin number - * @param destinationNumber - * the destination number - * @param phoneType - * the phone type - * @return the string - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String cancelCall(String originNumber, String destinationNumber, - String phoneType) throws IOException { - String out = ""; - String calldata = ""; - calldata += URLEncoder.encode("outgoingNumber", enc) + "=" - + URLEncoder.encode("undefined", enc); - calldata += "&" + URLEncoder.encode("forwardingNumber", enc) + "=" - + URLEncoder.encode("undefined", enc); - - calldata += "&" + URLEncoder.encode("cancelType", enc) + "=" - + URLEncoder.encode("C2C", enc); - calldata += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - // POST /voice/call/connect/ outgoingNumber=[number to - // call]&forwardingNumber=[forwarding - // number]&subscriberNumber=undefined&remember=0&_rnr_se=[pull from - // page] - URL callURL = new URL("https://www.google.com/voice/b/0/call/cancel/"); - - URLConnection callconn = callURL.openConnection(); - callconn.setRequestProperty( "Authorization", - "GoogleLogin auth="+authToken ); - callconn - .setRequestProperty( - "User-agent", - USER_AGENT); - - callconn.setDoOutput(true); - OutputStreamWriter callwr = new OutputStreamWriter(callconn - .getOutputStream()); - callwr.write(calldata); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader( - callconn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - - } - - /** - * Mark a Conversation with a known Message ID as read. - * - * @param msgID the msg id - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String markAsRead(String msgID) throws IOException - { - String out = ""; - StringBuffer calldata = new StringBuffer(); - - - // POST /voice/inbox/mark/ - // messages=[messageID] - // &read=1 - // &_rnr_se=[pull from page] - - calldata.append("messages="); - calldata.append(URLEncoder.encode(msgID, enc)); - calldata.append("&read=1"); - calldata.append("&_rnr_se="); - calldata.append(URLEncoder.encode(rnrSEE, enc)); - - - URL callURL = new URL(markAsReadString); - - URLConnection callconn = callURL.openConnection(); - callconn.setRequestProperty("Authorization","GoogleLogin auth="+authToken); - callconn.setRequestProperty("User-agent",USER_AGENT); - - callconn.setDoOutput(true); - OutputStreamWriter callwr = new OutputStreamWriter(callconn - .getOutputStream()); - - callwr.write(calldata.toString()); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader( - callconn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - } - - /** - * Mark a Conversation with a known Message ID as unread. - * - * @param msgID the msg id - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String markUnRead(String msgID) throws IOException - { - String out = ""; - StringBuffer calldata = new StringBuffer(); - - - // POST /voice/inbox/mark/ - // messages=[messageID] - // &read=0 - // &_rnr_se=[pull from page] - - calldata.append("messages="); - calldata.append(URLEncoder.encode(msgID, enc)); - calldata.append("&read=0"); - calldata.append("&_rnr_se="); - calldata.append(URLEncoder.encode(rnrSEE, enc)); - - - URL callURL = new URL("https://www.google.com/voice/b/0/inbox/mark"); - - URLConnection callconn = callURL.openConnection(); - callconn.setRequestProperty("Authorization","GoogleLogin auth="+authToken); - callconn.setRequestProperty("User-agent",USER_AGENT); - - callconn.setDoOutput(true); - OutputStreamWriter callwr = new OutputStreamWriter(callconn - .getOutputStream()); - - callwr.write(calldata.toString()); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader( - callconn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - } - - /** - * Delete message. - * - * @param msgID the msg id - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String deleteMessage(String msgID) throws IOException - { - String out = ""; - StringBuffer calldata = new StringBuffer(); - - - // POST /voice/inbox/deleteMessages/ - // messages=[messageID] - // &trash=1 - // &_rnr_se=[pull from page] - - calldata.append("messages="); - calldata.append(URLEncoder.encode(msgID, enc)); - calldata.append("&trash=1"); - calldata.append("&_rnr_se="); - calldata.append(URLEncoder.encode(rnrSEE, enc)); - - - URL callURL = new URL("https://www.google.com/voice/b/0/inbox/deleteMessages/"); - - URLConnection callconn = callURL.openConnection(); - callconn.setRequestProperty("Authorization","GoogleLogin auth="+authToken); - callconn.setRequestProperty("User-agent",USER_AGENT); - - callconn.setDoOutput(true); - OutputStreamWriter callwr = new OutputStreamWriter(callconn - .getOutputStream()); - - callwr.write(calldata.toString()); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader( - callconn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - } - - /** - * Enables multiple phones in one post - * - * TODO Test this with multiple phones in an account - * Best would be to be able to construct a url which can switch multiple phones at a time. - * - * @param IDs Array of Phones to enable - * @throws IOException Signals that an I/O exception has occurred. - */ - public void phonesEnable(int[] IDs) throws IOException { - - if(IDs.length<1) { - return; - } else if(IDs.length==1) { - //launch single (no thread overhead) - phoneEnable(IDs[0]); - } else { - for (int i = 0; i < IDs.length; i++) { - //TODO spawn threads! - int j = IDs[i]; - String paraString = URLEncoder.encode("enabled", enc) + "=" - + URLEncoder.encode("1", enc); - paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" - + URLEncoder.encode(Integer.toString(j), enc); - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - - phonesEnableDisableApply(paraString); - } - } - - } - - /** - * Enables one of the the phones attached to the account from ringing. - * Requires the internal ID for that phone, as an integer, usually 1,2,3, - * etc. - * - * @param ID - * the iD - * @return the raw response of the enable action. - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String phoneEnable(int ID) throws IOException { - String paraString = URLEncoder.encode("enabled", enc) + "=" - + URLEncoder.encode("1", enc); - paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" - + URLEncoder.encode(Integer.toString(ID), enc); - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - return phonesEnableDisableApply(paraString); - } - - /** - * Disables multiple phones in one post - * - * TODO Test this with multiple phones in an account - * Make faster - spawn threads - * Best would be to be able to construct a url which can switch multiple phones at a time. - * - * @param IDs Array of Phones to disable - * @return the raw response of the disable action. - * @throws IOException Signals that an I/O exception has occurred. - */ - public void phonesDisable(int[] IDs) throws IOException { - - if(IDs.length<1) { - return; - } else if(IDs.length==1) { - //launch single (no thread overhead) - phoneDisable(IDs[0]); - } else { - for (int i = 0; i < IDs.length; i++) { - //TODO spawn threads! - int j = IDs[i]; - String paraString = URLEncoder.encode("enabled", enc) + "=" - + URLEncoder.encode("0", enc); - paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" - + URLEncoder.encode(Integer.toString(j), enc); - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - - phonesEnableDisableApply(paraString); - } - } - - } - - /** - * Disable one of the the phones attached to the account from ringing. - * Requires the internal ID for that phone, as an integer, usually 1,2,3, - * etc. - * - * @param ID - * the iD - * @return the raw response of the disable action. - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public String phoneDisable(int ID) throws IOException { - String paraString = URLEncoder.encode("enabled", enc) + "=" - + URLEncoder.encode("0", enc); - paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" - + URLEncoder.encode(Integer.toString(ID), enc); - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - return phonesEnableDisableApply(paraString); - } - - /** - * Executes the enable/disable action with the provided url params. - * - * @param paraString the URL Parameters (encoded), ie ?auth=3248sdf7234&enable=0&phoneId=1&enable=1&phoneId=2&_rnr_se=734682ghdsf - * @return the raw response of the disable action. - * @throws IOException Signals that an I/O exception has occurred. - */ - private String phonesEnableDisableApply(String paraString) throws IOException { - String out = ""; - - - // POST /voice/call/connect/ outgoingNumber=[number to - // call]&forwardingNumber=[forwarding - // number]&subscriberNumber=undefined&remember=0&_rnr_se=[pull from - // page] - - // - if (PRINT_TO_CONSOLE) System.out.println(phoneEnableURLString); - if (PRINT_TO_CONSOLE) System.out.println(paraString); - URL requestURL = new URL(phoneEnableURLString); - - URLConnection conn = requestURL.openConnection(); - conn.setRequestProperty( "Authorization", - "GoogleLogin auth="+authToken ); - conn - .setRequestProperty( - "User-agent", - USER_AGENT); - - conn.setDoOutput(true); - conn.setDoInput(true); - - OutputStreamWriter callwr = new OutputStreamWriter(conn - .getOutputStream()); - callwr.write(paraString); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader( - conn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - - } - - /** - * Enables/disables the call Announcement setting (general for all phones). - * - * @param announceCaller
- * true Announces caller's name and gives answering options
- * false Directly connects calls when phones are answered - * @return the raw response of the disable action. - * @throws IOException Signals that an I/O exception has occurred. - */ - public String setCallPresentation(boolean announceCaller) throws IOException { - String out = ""; - - URL requestURL = new URL(generalSettingsURLString); - /** 0 for enable, 1 for disable **/ - String announceCallerStr=""; - - if(announceCaller) { - announceCallerStr = "0"; - if (PRINT_TO_CONSOLE) System.out.println("Turning caller announcement on."); - } - else { - announceCallerStr = "1"; - if (PRINT_TO_CONSOLE) System.out.println("Turning caller announcement off."); - } - - String paraString = ""; - paraString += URLEncoder.encode("directConnect", enc) + "=" - + URLEncoder.encode(announceCallerStr, enc); - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - - - URLConnection conn = requestURL.openConnection(); - conn.setRequestProperty( "Authorization", - "GoogleLogin auth="+authToken ); - conn.setRequestProperty("User-agent", - USER_AGENT); - - conn.setDoOutput(true); - conn.setDoInput(true); - - OutputStreamWriter callwr = new OutputStreamWriter(conn.getOutputStream()); - callwr.write(paraString); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader(conn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - } - - /** - * This is the general voicemail greeting callers hear. - * - * @param greetingToSet
- * number of the greeting to choose - * @return the raw response of the disable action. - * @throws IOException Signals that an I/O exception has occurred. - */ - public String setVoicemailGreetingId(String greetingToSet) throws IOException { - - URL requestURL = new URL(generalSettingsURLString); - - if (PRINT_TO_CONSOLE) System.out.println("Activating Greeting#"+greetingToSet); - - String paraString = ""; - // URLEncoder.encode("auth", enc) + "="+ URLEncoder.encode(authToken, enc); - paraString += URLEncoder.encode("greetingId", enc) + "=" - + URLEncoder.encode(greetingToSet+"", enc); - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - - - return postSettings(requestURL, paraString); - } - - /** - * Activated or deactivated the Do Not disturb function.
- * Enable this to send to voicemail all calls made to your Google number. - * - * @param dndEnabled true to enable dnd, false to disable it - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String setDoNotDisturb(boolean dndEnabled) throws IOException { - - URL requestURL = new URL(generalSettingsURLString); - - String enabled; - - if(dndEnabled) { - if (PRINT_TO_CONSOLE) System.out.println("Enabling dnd"); - enabled = "1"; - } else { - if (PRINT_TO_CONSOLE) System.out.println("Disabling dnd"); - enabled = "0"; - } - - String paraString = ""; - // URLEncoder.encode("auth", enc) + "="+ URLEncoder.encode(authToken, enc); - paraString += URLEncoder.encode("doNotDisturb", enc) + "=" - + URLEncoder.encode(enabled+"", enc); - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - - - return postSettings(requestURL, paraString); - } - - /** - * Activated or deactivated the SMS Forwarding for a particular phone - * - * @param smsEnable true to enable sms forwarding, false to disable it - * @param ID The id of the phone to enable/disable - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String setSmsEnabled(boolean smsEnable, int ID) throws IOException { - - // only allow editing of type 2 phones - for (int i = 0; i < settings.getPhones().length; i++) { - Phone ph = settings.getPhones()[i]; - if(ph.getId() == ID) { - if(ph.getType() != 2) { - if (PRINT_TO_CONSOLE) System.out.println("Cannot change sms Enabled on phone of type "+ph.getType() + " only availible on type 2"); - return null; - } - } - } - - String enabled; - - if(smsEnable &! settings.isPhoneSmsEnabled(ID)) { - if (PRINT_TO_CONSOLE) System.out.println("Enabling sms for phone "+ID); - enabled = "1"; - } else if(settings.isPhoneSmsEnabled(ID)) { - if (PRINT_TO_CONSOLE) System.out.println("Disabling sms for phone "+ID); - enabled = "0"; - } else { - // do not make changes to phones that are already in the same state - if (PRINT_TO_CONSOLE) System.out.println("Phone "+ID + " is already in the requested state. "+smsEnable); - return null; - } - - URL requestURL = new URL(editForwardingSMSURLString); - - String paraString = ""; - paraString += URLEncoder.encode("enabled", enc) + "=" - + URLEncoder.encode(enabled+"", enc); - paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" - + URLEncoder.encode(ID+"", enc); - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - - if (PRINT_TO_CONSOLE) System.out.println(requestURL); - if (PRINT_TO_CONSOLE) System.out.println(paraString); - - return postSettings(requestURL, paraString); - - } - - /** - * Applies the settings for this group. - * - * @param group the group - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String setNewGroupSettings(Group group) throws IOException { - URL requestURL = new URL(groupsSettingsURLString); - - String paraString = ""; - // URLEncoder.encode("auth", enc) + "="+ URLEncoder.encode(authToken, enc);; - - // 1=true 0=false - int isCustomGreeting = 0; - if(group.isCustomGreeting()) { - isCustomGreeting = 1; - } - paraString += URLEncoder.encode("isCustomGreeting", enc) + "=" - + URLEncoder.encode(isCustomGreeting+"", enc); - - int greetingId = group.getGreetingId(); - paraString += "&" + URLEncoder.encode("greetingId", enc) + "=" - + URLEncoder.encode(greetingId+"", enc); - - for (int i = 0; i < group.getDisabledForwardingIds().size(); i++) { - paraString += "&" + URLEncoder.encode("disabledPhoneIds", enc) + "=" - + URLEncoder.encode(group.getDisabledForwardingIds().get(i).getId(), enc); - } - - int directConnect = 0; - if(group.isDirectConnect()) { - directConnect = 1; - } - paraString += "&" + URLEncoder.encode("directConnect", enc) + "=" - + URLEncoder.encode(directConnect+"", enc); - - int isCustomDirectConnect = 0; - if(group.isCustomDirectConnect()) { - isCustomDirectConnect = 1; - } - paraString += "&" + URLEncoder.encode("isCustomDirectConnect", enc) + "=" - + URLEncoder.encode(isCustomDirectConnect+"", enc); - - int isCustomForwarding = 0; - if(group.isCustomForwarding()) { - isCustomForwarding = 1; - } - paraString += "&" + URLEncoder.encode("isCustomForwarding", enc) + "=" - + URLEncoder.encode(isCustomForwarding+"", enc); - - paraString += "&" + URLEncoder.encode("id", enc) + "=" - + URLEncoder.encode(group.getId(), enc); - - paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - - return postSettings(requestURL, paraString); - } - - /** - * Posts a settings change. - * - * @param requestURL the request url - * @param paraString the para string - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - private String postSettings(URL requestURL, String paraString) - throws IOException { - String out = ""; - HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection(); - conn.setRequestProperty( "Authorization", - "GoogleLogin auth="+authToken ); - conn.setRequestProperty("User-agent", - USER_AGENT); - - conn.setDoOutput(true); - conn.setDoInput(true); - - OutputStreamWriter callwr = new OutputStreamWriter(conn.getOutputStream()); - callwr.write(paraString); - callwr.flush(); - - // Get the response - conn.connect(); - int responseCode = conn.getResponseCode(); - if(PRINT_TO_CONSOLE) - System.out.println(requestURL + " - " + conn.getResponseMessage()); - InputStream is; - if(responseCode==200) { - is = conn.getInputStream(); - } else { - is = conn.getErrorStream(); - } - InputStreamReader isr = new InputStreamReader(is); - BufferedReader callrd = new BufferedReader(isr); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - if(PRINT_TO_CONSOLE) System.out.println(out); - - return out; - } - - /** - * Send an SMS. - * - * @param destinationNumber the destination number - * @param txt the Text of the message. Messages longer than the allowed - * character length will be split into multiple messages. - * @param id the Text of the message. Messages longer than the allowed - * character length will be split into multiple messages. - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String sendSMS(String destinationNumber, String txt, String id) - throws IOException { - String out = ""; - String smsdata = ""; - smsdata += URLEncoder.encode("id", enc) + "=" - + URLEncoder.encode(id, enc); - smsdata += "&" +URLEncoder.encode("phoneNumber", enc) + "=" - + URLEncoder.encode(destinationNumber, enc); - smsdata += "&" +URLEncoder.encode("conversationId", enc) + "=" - + URLEncoder.encode(id, enc); - smsdata += "&" + URLEncoder.encode("text", enc) + "=" - + URLEncoder.encode(txt, enc); - smsdata += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - System.out.println("smsdata: "+smsdata); - - URL smsurl = new URL("https://www.google.com/voice/b/0/sms/send/"); - - URLConnection smsconn = smsurl.openConnection(); - smsconn.setRequestProperty( "Authorization", - "GoogleLogin auth="+authToken ); - smsconn - .setRequestProperty( - "User-agent", - USER_AGENT); - - smsconn.setDoOutput(true); - OutputStreamWriter callwr = new OutputStreamWriter(smsconn.getOutputStream()); - callwr.write(smsdata); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader( - smsconn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - } - - - /** - * Send an SMS. - * - * @param destinationNumber the destination number - * @param txt the Text of the message. Messages longer than the allowed - * character length will be split into multiple messages. - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String sendSMS(String destinationNumber, String txt, SMSThread thread) - throws IOException { - - String id = thread.getId(); - return sendSMS(destinationNumber,txt,id); - } - - - - /** - * Send an SMS. - * - * @param destinationNumber the destination number - * @param txt the Text of the message. Messages longer than the allowed - * character length will be split into multiple messages. - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String sendSMS(String destinationNumber, String txt) - throws IOException { - String out = ""; - String smsdata = ""; - - smsdata += URLEncoder.encode("phoneNumber", enc) + "=" - + URLEncoder.encode(destinationNumber, enc); - smsdata += "&" + URLEncoder.encode("text", enc) + "=" - + URLEncoder.encode(txt, enc); - smsdata += "&" + URLEncoder.encode("_rnr_se", enc) + "=" - + URLEncoder.encode(rnrSEE, enc); - URL smsurl = new URL("https://www.google.com/voice/b/0/sms/send/"); - - URLConnection smsconn = smsurl.openConnection(); - smsconn.setRequestProperty( "Authorization", - "GoogleLogin auth="+authToken ); - smsconn - .setRequestProperty( - "User-agent", - USER_AGENT); - - smsconn.setDoOutput(true); - OutputStreamWriter callwr = new OutputStreamWriter(smsconn.getOutputStream()); - callwr.write(smsdata); - callwr.flush(); - - BufferedReader callrd = new BufferedReader(new InputStreamReader( - smsconn.getInputStream())); - - String line; - while ((line = callrd.readLine()) != null) { - out += line + "\n\r"; - - } - - callwr.close(); - callrd.close(); - - if (out.equals("")) { - throw new IOException("No Response Data Received."); - } - - return out; - } - - - /** - * HTTP GET request for a given URL String. - * - * @param urlString - * the url string - * @return the string - * @throws IOException - * Signals that an I/O exception has occurred. - */ - String get(String urlString) throws IOException { - URL url = new URL(urlString); - //+ "?auth=" + URLEncoder.encode(authToken, enc)); - - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestProperty( "Authorization", - "GoogleLogin auth="+authToken ); - conn.setRequestProperty( - "User-agent", - USER_AGENT); - conn.setInstanceFollowRedirects(false); // will follow redirects of same protocol http to http, but does not follow from http to https for example if set to true - - // Get the response - conn.connect(); - int responseCode = conn.getResponseCode(); - if(PRINT_TO_CONSOLE) - System.out.println(urlString + " - " + conn.getResponseMessage()); - InputStream is; - if(responseCode==200) { - is = conn.getInputStream(); - } else if(responseCode==HttpURLConnection.HTTP_MOVED_PERM || responseCode==HttpURLConnection.HTTP_MOVED_TEMP || responseCode==HttpURLConnection.HTTP_SEE_OTHER || responseCode==307) { - redirectCounter++; - if(redirectCounter > MAX_REDIRECTS) { - redirectCounter = 0; - throw new IOException(urlString + " : " + conn.getResponseMessage() + "("+responseCode+") : Too manny redirects. exiting."); - } - String location = conn.getHeaderField("Location"); - if(location!=null && !location.equals("")) { - System.out.println(urlString + " - " + responseCode + " - new URL: " + location); - return get(location); - } else { - throw new IOException(urlString + " : " + conn.getResponseMessage() + "("+responseCode+") : Received moved answer but no Location. exiting."); - } - } else { - is = conn.getErrorStream(); - } - redirectCounter = 0; - - if(is==null) { - throw new IOException(urlString + " : " + conn.getResponseMessage() + "("+responseCode+") : InputStream was null : exiting."); - } - - String result=""; - try { - // Get the response - BufferedReader rd = new BufferedReader(new InputStreamReader(is)); - - StringBuffer sb = new StringBuffer(); - String line; - while ((line = rd.readLine()) != null) { - sb.append(line + "\n\r"); - } - rd.close(); - result = sb.toString(); - } catch (Exception e) { - throw new IOException(urlString + " - " + conn.getResponseMessage() + "("+responseCode+") - " +e.getLocalizedMessage()); - } - return result; - } - - - /** - * HTTP GET request for a given URL String and a given page number. - * - * @param urlString the url string - * @param page number must be a natural number - * @return the string - * @throws IOException Signals that an I/O exception has occurred. - */ - public String get(String urlString,int page) throws IOException { - URL url = new URL(urlString + "?page=p"+page); - //url+="&page="+page; - URLConnection conn = url.openConnection(); - conn.setRequestProperty( "Authorization", - "GoogleLogin auth="+authToken ); - conn - .setRequestProperty( - "User-agent", - USER_AGENT); - - // Get the response - BufferedReader rd = new BufferedReader(new InputStreamReader(conn - .getInputStream())); - StringBuffer sb = new StringBuffer(); - String line; - while ((line = rd.readLine()) != null) { - sb.append(line + "\n\r"); - } - rd.close(); - String result = sb.toString(); - - return result; - } - - /** - * Login Method to refresh authentication with Google Voice. - * - * @throws IOException - * Signals that an I/O exception has occurred. - */ - public void login() throws IOException { - login(null,null); - } - - - - /** - * Use this login method to login - use captchaAnswer to answer a captcha challenge - * @param pCaptchaAnswer (optional) String entered by the user as an answer to a CAPTCHA challenge. - null to make a normal login attempt - * @param pCaptchaToken (optional) token which matches the response/url from the captcha challenge - * @throws IOException if login encounters a connection error - */ - public void login(String pCaptchaAnswer, String pCaptchaToken) throws IOException { - - String data = URLEncoder.encode("accountType", enc) + "=" - + URLEncoder.encode(account_type, enc); - data += "&" + URLEncoder.encode("Email", enc) + "=" - + URLEncoder.encode(user, enc); - data += "&" + URLEncoder.encode("Passwd", enc) + "=" - + URLEncoder.encode(pass, enc); - data += "&" + URLEncoder.encode("service", enc) + "=" - + URLEncoder.encode(SERVICE, enc); - data += "&" + URLEncoder.encode("source", enc) + "=" - + URLEncoder.encode(source, enc); - if(pCaptchaAnswer!=null && pCaptchaToken!=null) { - data += "&" + URLEncoder.encode("logintoken", enc) + "=" - + URLEncoder.encode(pCaptchaToken, enc); - data += "&" + URLEncoder.encode("logincaptcha", enc) + "=" - + URLEncoder.encode(pCaptchaAnswer, enc); - } - - // Send data - URL url = new URL(loginURLString); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn - .setRequestProperty( - "User-agent", - USER_AGENT); - - conn.setDoOutput(true); - OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); - wr.write(data); - wr.flush(); - - // Get the response - conn.connect(); - int responseCode = conn.getResponseCode(); - if(PRINT_TO_CONSOLE) - System.out.println(loginURLString + " - " + conn.getResponseMessage()); - InputStream is; - if(responseCode==200) { - is = conn.getInputStream(); - } else { - is = conn.getErrorStream(); - } - InputStreamReader isr = new InputStreamReader(is); - BufferedReader rd = new BufferedReader(isr); - String line; - String completelineDebug=""; - - /* - * A failure response contains an error code and a URL to an error page that can be displayed to the user. - * If the error code is a CAPTCHA challenge, the response also includes a URL to a CAPTCHA image and a special - * token. Your application should be able to solicit an answer from the user and then retry the login request. - * To display the CAPTCHA image to the user, prefix the CaptchaUrl value with "http://www.google.com/accounts/", - * for example: " http://www.google.com/accounts/Captcha?ctoken=HiteT4b0Bk5Xg18_AcVoP6-yFkHPibe7O9EqxeiI7lUSN". - */ - String lErrorString = "Unknown Connection Error."; // ex: Error=CaptchaRequired - - // String AuthToken = null; - while ((line = rd.readLine()) != null) { - completelineDebug += line+"\n"; - if (line.contains("Auth=")) { - this.authToken = line.split("=", 2)[1].trim(); - if (PRINT_TO_CONSOLE){ - System.out.println("Logged in to Google - Auth token received"); - } - } else if (line.contains("Error=")) { - lErrorString = line.split("=", 2)[1].trim(); - //error = getErrorEnumByCode(lErrorString); - error = ERROR_CODE.valueOf(lErrorString); - if (PRINT_TO_CONSOLE) - System.out.println("Login error - "+lErrorString); - - - } - if (line.contains("CaptchaToken=")) { - captchaToken = line.split("=", 2)[1].trim(); - } - - if (line.contains("CaptchaUrl=")) { - captchaUrl = "http://www.google.com/accounts/" + line.split("=", 2)[1].trim(); - } - if (line.contains("Url=")) { - captchaUrl2 = line.split("=", 2)[1].trim(); - } - - - } - wr.close(); - rd.close(); - -// if (PRINT_TO_CONSOLE){ -// System.out.println(completelineDebug); -// } - - if (this.authToken == null) { - AuthenticationException.throwProperException(error, captchaToken, captchaUrl); - } - - String response = this.getRawPhonesInfo(); - int phoneIndex = response.indexOf("gc-user-number-value\">"); - this.phoneNumber = response.substring(phoneIndex + 22, phoneIndex + 36); - this.phoneNumber = this.phoneNumber.replaceAll("[^a-zA-Z0-9]", ""); - if (this.phoneNumber.indexOf("+") == -1) { - this.phoneNumber = "+1" + this.phoneNumber; - } - } - - /** - * Gets the error enum by code. - * - * @param pErrorCodeString the error code string - * @return the error enum by code - */ - @Deprecated - private ERROR_CODE getErrorEnumByCode(String pErrorCodeString) { - if(pErrorCodeString.equals(ERROR_CODE.AccountDeleted.name())) { - return ERROR_CODE.AccountDeleted; - } else if(pErrorCodeString.equals(ERROR_CODE.AccountDisabled.name())) { - return ERROR_CODE.AccountDisabled; - } else if(pErrorCodeString.equals(ERROR_CODE.BadAuthentication.name())) { - return ERROR_CODE.BadAuthentication; - } else if(pErrorCodeString.equals(ERROR_CODE.CaptchaRequired.name())) { - return ERROR_CODE.CaptchaRequired; - } else if(pErrorCodeString.equals(ERROR_CODE.NotVerified.name())) { - return ERROR_CODE.NotVerified; - } else if(pErrorCodeString.equals(ERROR_CODE.ServiceDisabled.name())) { - return ERROR_CODE.ServiceDisabled; - } else if(pErrorCodeString.equals(ERROR_CODE.TermsNotAgreed.name())) { - return ERROR_CODE.TermsNotAgreed; - } else { - return ERROR_CODE.Unknown; - } - } - - /** - * Gets the error. - * - * @return the error - */ - @Deprecated - public ERROR_CODE getError() { - return error; - } - - /** - * Gets the captcha url. - * - * @return the captcha url - */ - public String getCaptchaUrl() { - return captchaUrl; - } - - /** - * Gets the captcha token. - * - * @return the captcha token - */ - public String getCaptchaToken() { - return captchaToken; - } - - /** - * Fires a Get request for Recent Items. If the Response requests login - * authentication or if an exception is thrown, a false is returned, - * otherwise if arbitrary text is contained for a logged in account, a true - * is returned. - * - *TODO Examine methodology. Perhaps Could Establish greater persistence with - *an option to force an update. Currently this is an expensive - *and slow method. - * - * @return true, if is logged in - */ - public boolean isLoggedIn() { - String res; - try { - res = getRecent(); - } catch (IOException e) { - return false; - } - if (res - .contains("
+ * -GOOGLE (get authorization for a Google account only)
+ * -HOSTED (get authorization for a hosted account only)
+ * -HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get + * authorization for a Google account)

+ * Use HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. + * If the user information matches both a hosted and a Google account, only the hosted account is authorized. + */ + private String account_type = GOOGLE; + + /** + * Name of the Google service you're requesting authorization for. Each service using the Authorization + * service is assigned a name value; for example, the name associated with Google Calendar is 'cl'. + * This parameter is required when accessing services based on Google Data APIs. For specific service + * names, refer to the service documentation. + */ + final static String SERVICE = "grandcentral"; + + /** The Constant generalURLString. */ + final static String generalURLString = "https://www.google.com/voice/b/0"; + + /** The Constant loginURLString. */ + final static String loginURLString = "https://www.google.com/accounts/ClientLogin"; + + /** The Constant inboxURLString. */ + final static String inboxURLString = "https://www.google.com/voice/b/0/inbox/recent/inbox/"; + + /** The Constant starredURLString. */ + final static String starredURLString = "https://www.google.com/voice/b/0/inbox/recent/starred/"; + + /** The Constant recentAllURLString. */ + final static String recentAllURLString = "https://www.google.com/voice/b/0/inbox/recent/all/"; + + /** The Constant spamURLString. */ + final static String spamURLString = "https://www.google.com/voice/b/0/inbox/recent/spam/"; + + /** The Constant trashURLString. */ + final static String trashURLString = "https://www.google.com/voice/b/0/inbox/recent/spam/"; + + /** The Constant voicemailURLString. */ + final static String voicemailURLString = "https://www.google.com/voice/b/0/inbox/recent/voicemail/"; + + /** The Constant smsURLString. */ + final static String smsURLString = "https://www.google.com/voice/b/0/inbox/recent/sms/"; + + /** The Constant recordedURLString. */ + final static String recordedURLString = "https://www.google.com/voice/b/0/inbox/recent/recorded/"; + + /** The Constant placedURLString. */ + final static String placedURLString = "https://www.google.com/voice/b/0/inbox/recent/placed/"; + + /** The Constant receivedURLString. */ + final static String receivedURLString = "https://www.google.com/voice/b/0/inbox/recent/received/"; + + /** The Constant missedURLString. */ + final static String missedURLString = "https://www.google.com/voice/b/0/inbox/recent/missed/"; + + /** The Constant phoneEnableURLString. */ + final static String phoneEnableURLString = "https://www.google.com/voice/b/0/settings/editDefaultForwarding/"; + + /** The Constant generalSettingsURLString. */ + final static String generalSettingsURLString = "https://www.google.com/voice/b/0/settings/editGeneralSettings/"; + + /** The Constant editForwardingSMSURLString. */ + final static String editForwardingSMSURLString = "https://www.google.com/voice/b/0/settings/editForwardingSms/"; + + /** The Constant phonesInfoURLString. */ + final static String phonesInfoURLString = "https://www.google.com/voice/b/0/settings/tab/phones"; + + /** The Constant groupsInfoURLString. */ + final static String groupsInfoURLString = "https://www.google.com/voice/b/0/settings/tab/groups"; + + /** The Constant voicemailInfoURLString. */ + final static String voicemailInfoURLString = "https://www.google.com/voice/b/0/settings/tab/voicemailsettings"; + + /** The Constant groupsSettingsURLString. */ + final static String groupsSettingsURLString = "https://www.google.com/voice/b/0/settings/editGroup/"; + + /** The Constant voicemailDownloadURLString. */ + final static String voicemailDownloadURLString = "https://www.google.com/voice/media/send_voicemail/"; + + /** The Constant markAsReadString. */ + final static String markAsReadString = "https://www.google.com/voice/b/0/inbox/mark/"; + + /** The Constant unreadSMSString. */ + final static String unreadSMSString = "https://www.google.com/voice/b/0/inbox/recent/sms/unread/"; + + //Experimental keyFlag is just there to overload method + public Voice(String authToken ) throws IOException{ + this.authToken = authToken; + + + this.source = "GoogleVoiceJava"; + + this.general = getGeneral(); + this.setRNRSEE(); + + String response = this.getRawPhonesInfo(); + int phoneIndex = response.indexOf("gc-user-number-value\">"); + this.phoneNumber = response.substring(phoneIndex + 22, phoneIndex + 36); + this.phoneNumber = this.phoneNumber.replaceAll("[^a-zA-Z0-9]", ""); + if (this.phoneNumber.indexOf("+") == -1) { + this.phoneNumber = "+1" + this.phoneNumber; + } + + } + + /** + * Instantiates a new voice. This constructor is deprecated. Try + * Voice(String user, String pass) which automatically determines rnrSee and + * assigns a source. + * + * @param user + * the user + * @param pass + * the pass + * @param source + * the source + * @param rnrSee + * the rnr see + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Deprecated + public Voice(String user, String pass, String source, String rnrSee) + throws IOException { + this.rnrSEE = rnrSee; + this.source = source; + + login(); + } + + + + + /** + * Instantiates a new voice. Custom Source Variable allowed, and + * printDebugIntoSystemOut which allows for Verbose output. + * + * @param user + * the username in the format of user@gmail.com or user@googlemail.com + * @param pass + * the password + * @param source + * the arbitrary source identifier. Can be anything. + * @param printDebugIntoToSystemOut + * the print debug into to system out + * @param accountType + * Type of account to request authorization for. Possible values are: + * Voice.GOOGLE (get authorization for a Google account only) + * Voice.HOSTED (get authorization for a hosted account only) + * Voice.HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account) + * Use Voice.HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public Voice(String user, String pass, String source, + boolean printDebugIntoToSystemOut, String accountType) throws IOException { + init(user, pass, source, printDebugIntoToSystemOut, accountType, null, null); + } + + /** + * Instantiates a new voice. Custom Source Variable allowed, and + * printDebugIntoSystemOut which allows for Verbose output. + * + * @param user + * the username in the format of user@gmail.com or user@googlemail.com + * @param pass + * the password + * @param source + * the arbitrary source identifier. Can be anything. + * @param printDebugIntoToSystemOut + * the print debug into to system out + * @param accountType + * Type of account to request authorization for. Possible values are: + * Voice.GOOGLE (get authorization for a Google account only) + * Voice.HOSTED (get authorization for a hosted account only) + * Voice.HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account) + * Use Voice.HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized. + * @param captchaResponse + * response to a captcha challenge, set to null if normal login + * @param captchaToken + * (optional) token which matches the response/url from the captcha challenge + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public Voice(String user, String pass, String source, + boolean printDebugIntoToSystemOut, String accountType, String captchaResponse, String captchaToken) throws IOException { + init(user, pass, source, printDebugIntoToSystemOut, accountType, captchaResponse, captchaToken); + } + + /** + * Internal function used by all constructors to fully initiate the Voice + * Object without chaptcha Response. + * + * @param user the username in the format of user@gmail.com or user@googlemail.com + * @param pass the password for the google account + * @param source the source + * @param printDebugIntoToSystemOut the print debug into to system out + * @param accountType Type of account to request authorization for. Possible values are: + * Voice.GOOGLE (get authorization for a Google account only) + * Voice.HOSTED (get authorization for a hosted account only) + * Voice.HOSTED_OR_GOOGLE (get authorization first for a hosted account; if attempt fails, get authorization for a Google account) + * Use Voice.HOSTED_OR_GOOGLE if you're not sure which type of account you want authorization for. If the user information matches both a hosted and a Google account, only the hosted account is authorized. + * @param captchaResponse response to a captcha challenge, set to null if normal login + * @param captchaToken token which matches the response/url from the captcha challenge + * @throws IOException Signals that an I/O exception has occurred. + */ + private void init(String user, String pass, String source, + boolean printDebugIntoToSystemOut, String accountType, String captchaResponse, String captchaToken) throws IOException { + if(accountType==GOOGLE||accountType==HOSTED||accountType==HOSTED_OR_GOOGLE) { + this.account_type = accountType; + this.PRINT_TO_CONSOLE = printDebugIntoToSystemOut; + + // this.rnrSEE = rnrSee; + if (source != null) { + this.source = source; + } else { + this.source = "GoogleVoiceJava"; + } + + login(captchaResponse,captchaToken); + this.general = getGeneral(); + setRNRSEE(); + } else { + throw new IOException("AccountType not valid"); + } + } + + /** + * Returns the Greeting list - Lazy + * @param forceUpdate set to true to force a List update from the server + * @return List of Greeting objects + * @throws IOException Signals that an I/O exception has occurred. + * @throws JSONException the jSON exception + */ + public List getVoicemailList(boolean forceUpdate) throws IOException, JSONException { + List lGList = new ArrayList(); + Greeting[] lGArray = getSettings(forceUpdate).getSettings().getGreetings(); + for (int i = 0; i < lGArray.length; i++) { + lGList.add(lGArray[i]); + } + return lGList; + } + + /** + * Returns the Group list - Lazy. Not yet Implemented + * + * @param forceUpdate the force update + * @return List of Greeting objects + * @throws IOException Signals that an I/O exception has occurred. + */ + public List getGroupSettingsList(boolean forceUpdate) throws IOException { +// return getSettings(forceUpdate).getGroupSettingsList(); +// List lGList = new ArrayList(); +// String[] lGArray = getSettings(forceUpdate).getSettings().getGroups().; +// for (int i = 0; i < lGArray.length; i++) { +// lGList.add(lGArray[i]); +// } +// return lGList; + //TODO implement getGroupSettingsList + return null; + } + + /** + * returns all users settings - lazy. + * + * @param forceUpdate the force update + * @return the settings + * @throws JSONException the jSON exception + * @throws IOException Signals that an I/O exception has occurred. + */ + public AllSettings getSettings(boolean forceUpdate) throws JSONException, IOException { + if(settings==null || forceUpdate) { + if(isLoggedIn()==false || forceUpdate) { + login(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + + e.printStackTrace(); + } + } + if(PRINT_TO_CONSOLE) System.out.println("Fetching Settings."); + // remove html overhead + String lJson = ParsingUtil.removeUninterestingParts(get(groupsInfoURLString), "", false); + try { + settings = new AllSettings(lJson); + } catch (JSONException e) { + throw new JSONException(e.getMessage()+lJson); + } + } + return settings; + } + + public Voice(){ + authToken = "abcde"; + } + + /** + * Fetches and returns the raw page source code for the Inbox. + * + * @return the inbox + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getInbox() throws IOException { + return get(inboxURLString); + } + + /** + * Gets the inbox page. + * + * @param page the page + * @return the inbox page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getInboxPage(int page) throws IOException { + return get(inboxURLString,page); + } + + /** + * Fetches the page Source Code for the Voice homepage. This file contains + * most of the useful information for the Google Voice Account such as + * attached PhoneOld info and Contacts. + * + * @return the general + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getGeneral() throws IOException { + return get(generalURLString); + } + + /** + * The main Google Voice section is paginated. Access the raw HTML for + * specific page of the main section. + * + * @param page the page + * @return the general page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getGeneralPage(int page) throws IOException { + return get(generalURLString,page); + } + + /** + * Gets the raw page source code for the starred items. + * + * @return the starred item page source + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getStarred() throws IOException { + return get(starredURLString); + } + + /** + * Gets the starred page. + * + * @param page the page + * @return the starred page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getStarredPage(int page) throws IOException { + return get(starredURLString,page); + } + + + /** + * Gets the raw page source code for the recent items. + * + * @return the recent raw source code + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getRecent() throws IOException { + return get(recentAllURLString); + } + + /** + * Gets the recent page. + * + * @param page the page + * @return the recent page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getRecentPage(int page) throws IOException { + return get(recentAllURLString,page); + } + + /** + * Gets the page source for the spam. + * + * @return the spam + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getSpam() throws IOException { + return get(spamURLString); + } + + /** + * Gets the spam page. + * + * @param page the page + * @return the spam page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getSpamPage(int page) throws IOException { + return get(spamURLString,page); + } + + /** + * Gets the page source for the recorded calls. + * + * @return the recorded + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getRecorded() throws IOException { + return get(recordedURLString); + } + + /** + * Gets the recorded page. + * + * @param page the page + * @return the recorded page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getRecordedPage(int page) throws IOException { + return get(recordedURLString,page); + } + + /** + * Gets the raw source code for the placed calls page. + * + * @return the placed calls source code + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getPlaced() throws IOException { + return get(placedURLString); + } + + /** + * Gets the placed page. + * + * @param page the page + * @return the placed page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getPlacedPage(int page) throws IOException { + return get(placedURLString,page); + } + + /** + * Gets the received calls source code. + * + * @return the received + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getReceived() throws IOException { + return get(receivedURLString); + } + + /** + * Gets the received page. + * + * @param page the page + * @return the received page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getReceivedPage(int page) throws IOException { + return get(receivedURLString,page); + } + + /** + * Gets the missed calls source code. + * + * @return the missed + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getMissed() throws IOException { + return get(missedURLString); + } + + /** + * Gets the missed page. + * + * @param page the page + * @return the missed page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getMissedPage(int page) throws IOException { + return get(missedURLString,page); + } + + + /** + * Gets the unread sms. + * + * @return the unread sms + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getUnreadSMS() throws IOException{ + return get(unreadSMSString); + } + + /** + * Gets the unread sms page. + * + * @param page the page + * @return the unread sms page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getUnreadSMSPage(int page) throws IOException{ + return get(unreadSMSString,page); + } + + + + + + + + + /** + * Gets the Voicemail page raw source code. + * + * @return the Voicemail + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getVoicemail() throws IOException { + return get(voicemailURLString); + } + + /** + * Gets the voicemail page. + * + * @param page the page + * @return the voicemail page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getVoicemailPage(int page) throws IOException { + return get(voicemailURLString,page); + } + + /** + * Downloads a voicemail. + * + * @param msgID the msg id + * @return byte output stream + * @throws IOException Signals that an I/O exception has occurred. + */ + public ByteArrayOutputStream downloadVoicemail(String msgID) throws IOException + { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + + try + { + URL u = new URL (voicemailDownloadURLString + msgID); + HttpURLConnection huc = (HttpURLConnection)u.openConnection () ; + // Authorization Header Logic + String oauthToken_downloadVoicemail = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_downloadVoicemail = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_downloadVoicemail != null && !oauthToken_downloadVoicemail.isEmpty()) { + huc.setRequestProperty("Authorization", "Bearer " + oauthToken_downloadVoicemail); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + huc.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in downloadVoicemail."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in downloadVoicemail."); + } + // End Authorization Header Logic + huc.setRequestProperty("User-agent", USER_AGENT); + huc.setRequestMethod ("GET"); + huc.connect() ; + InputStream is = huc.getInputStream(); + + if(huc.getResponseCode() == HttpURLConnection.HTTP_OK) + { + byte[] buffer = new byte [4096]; + int bytes = 0; + + while(true) + { + bytes = is.read(buffer); + if(bytes <= 0) + break; + outputStream.write(buffer, 0, bytes); + } + + outputStream.flush(); + } + + huc.disconnect (); + + return outputStream; + } + catch(IOException e) + { + System.out.println ( "Exception\n" + e ) ; + } + + return null; + } + + /** + * Gets the SMS page raw source code. + * + * @return the sMS + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String getSMS() throws IOException { + return get(smsURLString); + } + + + + /** + * Gets the SMS page. + * + * @param page the page + * @return the sMS page + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getSMSPage(int page) throws IOException { + return get(smsURLString,page); + } + + + + /** + * Gets a collection of SMS threads. Each SMS thread has a collection of SMS + * objects which contains contact, text and timestamp information. + * + * @return a collection of SMS threads. + * @throws IOException Signals that an I/O exception has occurred. + */ + public Collection getSMSThreads() throws IOException { + SMSParser parser = new SMSParser(get(smsURLString), phoneNumber); + return parser.getSMSThreads(); + } + + /** + * Gets a collection of SMS threads. Each SMS thread has a collection of SMS + * objects which contains contact, text and timestamp information. + * + * @return a collection of SMS threads. + * @throws IOException Signals that an I/O exception has occurred. + */ + public Collection getSMSThreads(int page ) throws IOException { + SMSParser parser = new SMSParser(get(smsURLString, page), phoneNumber); + return parser.getSMSThreads(); + } + + + /** + * Gets the SMS threads from a given Response Page. + * + * @param response the response + * @return the SMS threads + */ + public Collection getSMSThreads(String response){ + SMSParser parser= new SMSParser(response, phoneNumber); + return parser.getSMSThreads(); + } + + + /** + * Gets the rNRSEE. + * + * @return the rNRSEE + */ + public String getRNRSEE(){ + return rnrSEE; + } + + /** + * Internal method which parses the Homepage source code to determine the + * rnrsee variable, this variable is passed into most fuctions for placing + * calls and sms. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + private void setRNRSEE() throws IOException { + if (general != null) { + if(general.contains("'_rnr_se': '")) { + String p1 = general.split("'_rnr_se': '", 2)[1]; + rnrSEE = p1.split("',", 2)[0]; + if(PRINT_TO_CONSOLE) + System.out.println("Successfully Received rnr_se."); + p1 = null; + } else if(general.contains("
")) { + String gcNotice = ParsingUtil.removeUninterestingParts(general, "
", "
", false); + System.out.println(gcNotice+ "(Answer did not contain rnr_se)"); + throw new IOException(gcNotice + "(Answer did not contain rnr_se)"); + } else { + System.out.println("Answer did not contain rnr_se! "+ general); + throw new IOException("Answer did not contain rnr_se! "+ general); + } + } else { + System.out.println("setRNRSEE(): Answer was null!"); + throw new IOException("setRNRSEE(): Answer was null!"); + } + } + + /** + * Gets the phone number. + * + * @return the phone number + */ + public String getPhoneNumber() + { + return this.phoneNumber; + } + + //TODO Combine with or replace setPhoneInfo + /** + * Gets the raw phones info. + * + * @return the raw phones info + * @throws IOException Signals that an I/O exception has occurred. + */ + public String getRawPhonesInfo() throws IOException{ + return get(phonesInfoURLString); + } + + /** + * Place a call. + * + * @param originNumber + * the origin number + * @param destinationNumber + * the destination number + * @param phoneType + * the phone type, this is a number such as 1,2,7 formatted as a String + * @return the raw response string received from Google Voice. + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String call(String originNumber, String destinationNumber, + String phoneType) throws IOException { + String out = ""; + StringBuffer calldata = new StringBuffer(); + + + // POST /voice/call/connect/ + // outgoingNumber=[number to call] + // &forwardingNumber=[forwarding number] + // &subscriberNumber=undefined + // &phoneType=[phone type from google] + // &remember=0 + // &_rnr_se=[pull from page] + + calldata.append("outgoingNumber="); + calldata.append(URLEncoder.encode(destinationNumber, enc)); + calldata.append("&forwardingNumber="); + calldata.append(URLEncoder.encode(originNumber, enc)); + calldata.append("&subscriberNumber=undefined"); + calldata.append("&phoneType="); + calldata.append(URLEncoder.encode(phoneType, enc)); + calldata.append("&remember=0"); + if(rnrSEE!=null) + { + calldata.append("&_rnr_se="); + calldata.append(URLEncoder.encode(rnrSEE, enc)); + } + + URL callURL = new URL("https://www.google.com/voice/b/0/call/connect/"); + + URLConnection callconn = callURL.openConnection(); + // Authorization Header Logic + String oauthToken_call = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_call = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_call != null && !oauthToken_call.isEmpty()) { + callconn.setRequestProperty("Authorization", "Bearer " + oauthToken_call); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in call."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in call."); + } + // End Authorization Header Logic + callconn.setRequestProperty("User-agent",USER_AGENT); + callconn.setRequestProperty("Cookie", GVCookieManager.getInstance().listAllOutgoingCookies()); + + callconn.setDoOutput(true); + OutputStreamWriter callwr = new OutputStreamWriter(callconn + .getOutputStream()); + + callwr.write(calldata.toString()); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader( + callconn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + + } + + /** + * Cancel a call that was just placed. + * + * @param originNumber + * the origin number + * @param destinationNumber + * the destination number + * @param phoneType + * the phone type + * @return the string + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String cancelCall(String originNumber, String destinationNumber, + String phoneType) throws IOException { + String out = ""; + String calldata = ""; + calldata += URLEncoder.encode("outgoingNumber", enc) + "=" + + URLEncoder.encode("undefined", enc); + calldata += "&" + URLEncoder.encode("forwardingNumber", enc) + "=" + + URLEncoder.encode("undefined", enc); + + calldata += "&" + URLEncoder.encode("cancelType", enc) + "=" + + URLEncoder.encode("C2C", enc); + calldata += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + // POST /voice/call/connect/ outgoingNumber=[number to + // call]&forwardingNumber=[forwarding + // number]&subscriberNumber=undefined&remember=0&_rnr_se=[pull from + // page] + URL callURL = new URL("https://www.google.com/voice/b/0/call/cancel/"); + + URLConnection callconn = callURL.openConnection(); + // Authorization Header Logic + String oauthToken_cancelCall = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_cancelCall = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_cancelCall != null && !oauthToken_cancelCall.isEmpty()) { + callconn.setRequestProperty("Authorization", "Bearer " + oauthToken_cancelCall); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in cancelCall."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in cancelCall."); + } + // End Authorization Header Logic + callconn + .setRequestProperty( + "User-agent", + USER_AGENT); + + callconn.setDoOutput(true); + OutputStreamWriter callwr = new OutputStreamWriter(callconn + .getOutputStream()); + callwr.write(calldata); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader( + callconn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + + } + + /** + * Mark a Conversation with a known Message ID as read. + * + * @param msgID the msg id + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String markAsRead(String msgID) throws IOException + { + String out = ""; + StringBuffer calldata = new StringBuffer(); + + + // POST /voice/inbox/mark/ + // messages=[messageID] + // &read=1 + // &_rnr_se=[pull from page] + + calldata.append("messages="); + calldata.append(URLEncoder.encode(msgID, enc)); + calldata.append("&read=1"); + calldata.append("&_rnr_se="); + calldata.append(URLEncoder.encode(rnrSEE, enc)); + + + URL callURL = new URL(markAsReadString); + + URLConnection callconn = callURL.openConnection(); + // Authorization Header Logic + String oauthToken_markAsRead = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_markAsRead = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_markAsRead != null && !oauthToken_markAsRead.isEmpty()) { + callconn.setRequestProperty("Authorization", "Bearer " + oauthToken_markAsRead); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in markAsRead."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in markAsRead."); + } + // End Authorization Header Logic + callconn.setRequestProperty("User-agent",USER_AGENT); + + callconn.setDoOutput(true); + OutputStreamWriter callwr = new OutputStreamWriter(callconn + .getOutputStream()); + + callwr.write(calldata.toString()); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader( + callconn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + } + + /** + * Mark a Conversation with a known Message ID as unread. + * + * @param msgID the msg id + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String markUnRead(String msgID) throws IOException + { + String out = ""; + StringBuffer calldata = new StringBuffer(); + + + // POST /voice/inbox/mark/ + // messages=[messageID] + // &read=0 + // &_rnr_se=[pull from page] + + calldata.append("messages="); + calldata.append(URLEncoder.encode(msgID, enc)); + calldata.append("&read=0"); + calldata.append("&_rnr_se="); + calldata.append(URLEncoder.encode(rnrSEE, enc)); + + + URL callURL = new URL("https://www.google.com/voice/b/0/inbox/mark"); + + URLConnection callconn = callURL.openConnection(); + // Authorization Header Logic + String oauthToken_markUnRead = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_markUnRead = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_markUnRead != null && !oauthToken_markUnRead.isEmpty()) { + callconn.setRequestProperty("Authorization", "Bearer " + oauthToken_markUnRead); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in markUnRead."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in markUnRead."); + } + // End Authorization Header Logic + callconn.setRequestProperty("User-agent",USER_AGENT); + + callconn.setDoOutput(true); + OutputStreamWriter callwr = new OutputStreamWriter(callconn + .getOutputStream()); + + callwr.write(calldata.toString()); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader( + callconn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + } + + /** + * Delete message. + * + * @param msgID the msg id + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String deleteMessage(String msgID) throws IOException + { + String out = ""; + StringBuffer calldata = new StringBuffer(); + + + // POST /voice/inbox/deleteMessages/ + // messages=[messageID] + // &trash=1 + // &_rnr_se=[pull from page] + + calldata.append("messages="); + calldata.append(URLEncoder.encode(msgID, enc)); + calldata.append("&trash=1"); + calldata.append("&_rnr_se="); + calldata.append(URLEncoder.encode(rnrSEE, enc)); + + + URL callURL = new URL("https://www.google.com/voice/b/0/inbox/deleteMessages/"); + + URLConnection callconn = callURL.openConnection(); + // Authorization Header Logic + String oauthToken_deleteMessage = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_deleteMessage = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_deleteMessage != null && !oauthToken_deleteMessage.isEmpty()) { + callconn.setRequestProperty("Authorization", "Bearer " + oauthToken_deleteMessage); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in deleteMessage."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in deleteMessage."); + } + // End Authorization Header Logic + callconn.setRequestProperty("User-agent",USER_AGENT); + + callconn.setDoOutput(true); + OutputStreamWriter callwr = new OutputStreamWriter(callconn + .getOutputStream()); + + callwr.write(calldata.toString()); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader( + callconn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + } + + /** + * Enables multiple phones in one post + * + * TODO Test this with multiple phones in an account + * Best would be to be able to construct a url which can switch multiple phones at a time. + * + * @param IDs Array of Phones to enable + * @throws IOException Signals that an I/O exception has occurred. + */ + public void phonesEnable(int[] IDs) throws IOException { + + if(IDs.length<1) { + return; + } else if(IDs.length==1) { + //launch single (no thread overhead) + phoneEnable(IDs[0]); + } else { + for (int i = 0; i < IDs.length; i++) { + //TODO spawn threads! + int j = IDs[i]; + String paraString = URLEncoder.encode("enabled", enc) + "=" + + URLEncoder.encode("1", enc); + paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" + + URLEncoder.encode(Integer.toString(j), enc); + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + + phonesEnableDisableApply(paraString); + } + } + + } + + /** + * Enables one of the the phones attached to the account from ringing. + * Requires the internal ID for that phone, as an integer, usually 1,2,3, + * etc. + * + * @param ID + * the iD + * @return the raw response of the enable action. + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String phoneEnable(int ID) throws IOException { + String paraString = URLEncoder.encode("enabled", enc) + "=" + + URLEncoder.encode("1", enc); + paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" + + URLEncoder.encode(Integer.toString(ID), enc); + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + return phonesEnableDisableApply(paraString); + } + + /** + * Disables multiple phones in one post + * + * TODO Test this with multiple phones in an account + * Make faster - spawn threads + * Best would be to be able to construct a url which can switch multiple phones at a time. + * + * @param IDs Array of Phones to disable + * @return the raw response of the disable action. + * @throws IOException Signals that an I/O exception has occurred. + */ + public void phonesDisable(int[] IDs) throws IOException { + + if(IDs.length<1) { + return; + } else if(IDs.length==1) { + //launch single (no thread overhead) + phoneDisable(IDs[0]); + } else { + for (int i = 0; i < IDs.length; i++) { + //TODO spawn threads! + int j = IDs[i]; + String paraString = URLEncoder.encode("enabled", enc) + "=" + + URLEncoder.encode("0", enc); + paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" + + URLEncoder.encode(Integer.toString(j), enc); + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + + phonesEnableDisableApply(paraString); + } + } + + } + + /** + * Disable one of the the phones attached to the account from ringing. + * Requires the internal ID for that phone, as an integer, usually 1,2,3, + * etc. + * + * @param ID + * the iD + * @return the raw response of the disable action. + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String phoneDisable(int ID) throws IOException { + String paraString = URLEncoder.encode("enabled", enc) + "=" + + URLEncoder.encode("0", enc); + paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" + + URLEncoder.encode(Integer.toString(ID), enc); + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + return phonesEnableDisableApply(paraString); + } + + /** + * Executes the enable/disable action with the provided url params. + * + * @param paraString the URL Parameters (encoded), ie ?auth=3248sdf7234&enable=0&phoneId=1&enable=1&phoneId=2&_rnr_se=734682ghdsf + * @return the raw response of the disable action. + * @throws IOException Signals that an I/O exception has occurred. + */ + private String phonesEnableDisableApply(String paraString) throws IOException { + String out = ""; + + + // POST /voice/call/connect/ outgoingNumber=[number to + // call]&forwardingNumber=[forwarding + // number]&subscriberNumber=undefined&remember=0&_rnr_se=[pull from + // page] + + // + if (PRINT_TO_CONSOLE) System.out.println(phoneEnableURLString); + if (PRINT_TO_CONSOLE) System.out.println(paraString); + URL requestURL = new URL(phoneEnableURLString); + + URLConnection conn = requestURL.openConnection(); + // Authorization Header Logic + String oauthToken_phonesEnableDisableApply = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_phonesEnableDisableApply = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_phonesEnableDisableApply != null && !oauthToken_phonesEnableDisableApply.isEmpty()) { + conn.setRequestProperty("Authorization", "Bearer " + oauthToken_phonesEnableDisableApply); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + conn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in phonesEnableDisableApply."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in phonesEnableDisableApply."); + } + // End Authorization Header Logic + conn + .setRequestProperty( + "User-agent", + USER_AGENT); + + conn.setDoOutput(true); + conn.setDoInput(true); + + OutputStreamWriter callwr = new OutputStreamWriter(conn + .getOutputStream()); + callwr.write(paraString); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader( + conn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + + } + + /** + * Enables/disables the call Announcement setting (general for all phones). + * + * @param announceCaller
+ * true Announces caller's name and gives answering options
+ * false Directly connects calls when phones are answered + * @return the raw response of the disable action. + * @throws IOException Signals that an I/O exception has occurred. + */ + public String setCallPresentation(boolean announceCaller) throws IOException { + String out = ""; + + URL requestURL = new URL(generalSettingsURLString); + /** 0 for enable, 1 for disable **/ + String announceCallerStr=""; + + if(announceCaller) { + announceCallerStr = "0"; + if (PRINT_TO_CONSOLE) System.out.println("Turning caller announcement on."); + } + else { + announceCallerStr = "1"; + if (PRINT_TO_CONSOLE) System.out.println("Turning caller announcement off."); + } + + String paraString = ""; + paraString += URLEncoder.encode("directConnect", enc) + "=" + + URLEncoder.encode(announceCallerStr, enc); + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + + + URLConnection conn = requestURL.openConnection(); + // Authorization Header Logic + String oauthToken_setCallPresentation = null; // Changed from postSettings to be specific + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_setCallPresentation = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_setCallPresentation != null && !oauthToken_setCallPresentation.isEmpty()) { + conn.setRequestProperty("Authorization", "Bearer " + oauthToken_setCallPresentation); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + conn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in setCallPresentation (via postSettings)."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in setCallPresentation (via postSettings)."); + } + // End Authorization Header Logic + conn.setRequestProperty("User-agent", + USER_AGENT); + + conn.setDoOutput(true); + conn.setDoInput(true); + + OutputStreamWriter callwr = new OutputStreamWriter(conn.getOutputStream()); + callwr.write(paraString); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader(conn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + } + + /** + * This is the general voicemail greeting callers hear. + * + * @param greetingToSet
+ * number of the greeting to choose + * @return the raw response of the disable action. + * @throws IOException Signals that an I/O exception has occurred. + */ + public String setVoicemailGreetingId(String greetingToSet) throws IOException { + + URL requestURL = new URL(generalSettingsURLString); + + if (PRINT_TO_CONSOLE) System.out.println("Activating Greeting#"+greetingToSet); + + String paraString = ""; + // URLEncoder.encode("auth", enc) + "="+ URLEncoder.encode(authToken, enc); + paraString += URLEncoder.encode("greetingId", enc) + "=" + + URLEncoder.encode(greetingToSet+"", enc); + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + + + return postSettings(requestURL, paraString); + } + + /** + * Activated or deactivated the Do Not disturb function.
+ * Enable this to send to voicemail all calls made to your Google number. + * + * @param dndEnabled true to enable dnd, false to disable it + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String setDoNotDisturb(boolean dndEnabled) throws IOException { + + URL requestURL = new URL(generalSettingsURLString); + + String enabled; + + if(dndEnabled) { + if (PRINT_TO_CONSOLE) System.out.println("Enabling dnd"); + enabled = "1"; + } else { + if (PRINT_TO_CONSOLE) System.out.println("Disabling dnd"); + enabled = "0"; + } + + String paraString = ""; + // URLEncoder.encode("auth", enc) + "="+ URLEncoder.encode(authToken, enc); + paraString += URLEncoder.encode("doNotDisturb", enc) + "=" + + URLEncoder.encode(enabled+"", enc); + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + + + return postSettings(requestURL, paraString); + } + + /** + * Activated or deactivated the SMS Forwarding for a particular phone + * + * @param smsEnable true to enable sms forwarding, false to disable it + * @param ID The id of the phone to enable/disable + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String setSmsEnabled(boolean smsEnable, int ID) throws IOException { + + // only allow editing of type 2 phones + for (int i = 0; i < settings.getPhones().length; i++) { + Phone ph = settings.getPhones()[i]; + if(ph.getId() == ID) { + if(ph.getType() != 2) { + if (PRINT_TO_CONSOLE) System.out.println("Cannot change sms Enabled on phone of type "+ph.getType() + " only availible on type 2"); + return null; + } + } + } + + String enabled; + + if(smsEnable &! settings.isPhoneSmsEnabled(ID)) { + if (PRINT_TO_CONSOLE) System.out.println("Enabling sms for phone "+ID); + enabled = "1"; + } else if(settings.isPhoneSmsEnabled(ID)) { + if (PRINT_TO_CONSOLE) System.out.println("Disabling sms for phone "+ID); + enabled = "0"; + } else { + // do not make changes to phones that are already in the same state + if (PRINT_TO_CONSOLE) System.out.println("Phone "+ID + " is already in the requested state. "+smsEnable); + return null; + } + + URL requestURL = new URL(editForwardingSMSURLString); + + String paraString = ""; + paraString += URLEncoder.encode("enabled", enc) + "=" + + URLEncoder.encode(enabled+"", enc); + paraString += "&" + URLEncoder.encode("phoneId", enc) + "=" + + URLEncoder.encode(ID+"", enc); + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + + if (PRINT_TO_CONSOLE) System.out.println(requestURL); + if (PRINT_TO_CONSOLE) System.out.println(paraString); + + return postSettings(requestURL, paraString); + + } + + /** + * Applies the settings for this group. + * + * @param group the group + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String setNewGroupSettings(Group group) throws IOException { + URL requestURL = new URL(groupsSettingsURLString); + + String paraString = ""; + // URLEncoder.encode("auth", enc) + "="+ URLEncoder.encode(authToken, enc);; + + // 1=true 0=false + int isCustomGreeting = 0; + if(group.isCustomGreeting()) { + isCustomGreeting = 1; + } + paraString += URLEncoder.encode("isCustomGreeting", enc) + "=" + + URLEncoder.encode(isCustomGreeting+"", enc); + + int greetingId = group.getGreetingId(); + paraString += "&" + URLEncoder.encode("greetingId", enc) + "=" + + URLEncoder.encode(greetingId+"", enc); + + for (int i = 0; i < group.getDisabledForwardingIds().size(); i++) { + paraString += "&" + URLEncoder.encode("disabledPhoneIds", enc) + "=" + + URLEncoder.encode(group.getDisabledForwardingIds().get(i).getId(), enc); + } + + int directConnect = 0; + if(group.isDirectConnect()) { + directConnect = 1; + } + paraString += "&" + URLEncoder.encode("directConnect", enc) + "=" + + URLEncoder.encode(directConnect+"", enc); + + int isCustomDirectConnect = 0; + if(group.isCustomDirectConnect()) { + isCustomDirectConnect = 1; + } + paraString += "&" + URLEncoder.encode("isCustomDirectConnect", enc) + "=" + + URLEncoder.encode(isCustomDirectConnect+"", enc); + + int isCustomForwarding = 0; + if(group.isCustomForwarding()) { + isCustomForwarding = 1; + } + paraString += "&" + URLEncoder.encode("isCustomForwarding", enc) + "=" + + URLEncoder.encode(isCustomForwarding+"", enc); + + paraString += "&" + URLEncoder.encode("id", enc) + "=" + + URLEncoder.encode(group.getId(), enc); + + paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + + return postSettings(requestURL, paraString); + } + + /** + * Posts a settings change. + * + * @param requestURL the request url + * @param paraString the para string + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + private String postSettings(URL requestURL, String paraString) + throws IOException { + String out = ""; + HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection(); + // Authorization Header Logic + String oauthToken_postSettings = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_postSettings = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_postSettings != null && !oauthToken_postSettings.isEmpty()) { + conn.setRequestProperty("Authorization", "Bearer " + oauthToken_postSettings); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + conn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in postSettings for URL: " + requestURL.toString()); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in postSettings for URL: " + requestURL.toString()); + } + // End Authorization Header Logic + conn.setRequestProperty("User-agent", + USER_AGENT); + + conn.setDoOutput(true); + conn.setDoInput(true); + + OutputStreamWriter callwr = new OutputStreamWriter(conn.getOutputStream()); + callwr.write(paraString); + callwr.flush(); + + // Get the response + conn.connect(); + int responseCode = conn.getResponseCode(); + if(PRINT_TO_CONSOLE) + System.out.println(requestURL + " - " + conn.getResponseMessage()); + InputStream is; + if(responseCode==200) { + is = conn.getInputStream(); + } else { + is = conn.getErrorStream(); + } + InputStreamReader isr = new InputStreamReader(is); + BufferedReader callrd = new BufferedReader(isr); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + if(PRINT_TO_CONSOLE) System.out.println(out); + + return out; + } + + /** + * Send an SMS. + * + * @param destinationNumber the destination number + * @param txt the Text of the message. Messages longer than the allowed + * character length will be split into multiple messages. + * @param id the Text of the message. Messages longer than the allowed + * character length will be split into multiple messages. + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String sendSMS(String destinationNumber, String txt, String id) + throws IOException { + String out = ""; + String smsdata = ""; + smsdata += URLEncoder.encode("id", enc) + "=" + + URLEncoder.encode(id, enc); + smsdata += "&" +URLEncoder.encode("phoneNumber", enc) + "=" + + URLEncoder.encode(destinationNumber, enc); + smsdata += "&" +URLEncoder.encode("conversationId", enc) + "=" + + URLEncoder.encode(id, enc); + smsdata += "&" + URLEncoder.encode("text", enc) + "=" + + URLEncoder.encode(txt, enc); + smsdata += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + System.out.println("smsdata: "+smsdata); + + URL smsurl = new URL("https://www.google.com/voice/b/0/sms/send/"); + + URLConnection smsconn = smsurl.openConnection(); + // Authorization Header Logic + String oauthToken_sendSmsId = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_sendSmsId = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_sendSmsId != null && !oauthToken_sendSmsId.isEmpty()) { + smsconn.setRequestProperty("Authorization", "Bearer " + oauthToken_sendSmsId); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + smsconn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in sendSMS(dest, txt, id)."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in sendSMS(dest, txt, id)."); + } + // End Authorization Header Logic + smsconn + .setRequestProperty( + "User-agent", + USER_AGENT); + + smsconn.setDoOutput(true); + OutputStreamWriter callwr = new OutputStreamWriter(smsconn.getOutputStream()); + callwr.write(smsdata); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader( + smsconn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + } + + + /** + * Send an SMS. + * + * @param destinationNumber the destination number + * @param txt the Text of the message. Messages longer than the allowed + * character length will be split into multiple messages. + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String sendSMS(String destinationNumber, String txt, SMSThread thread) + throws IOException { + + String id = thread.getId(); + return sendSMS(destinationNumber,txt,id); + } + + + + /** + * Send an SMS. + * + * @param destinationNumber the destination number + * @param txt the Text of the message. Messages longer than the allowed + * character length will be split into multiple messages. + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String sendSMS(String destinationNumber, String txt) + throws IOException { + String out = ""; + String smsdata = ""; + + smsdata += URLEncoder.encode("phoneNumber", enc) + "=" + + URLEncoder.encode(destinationNumber, enc); + smsdata += "&" + URLEncoder.encode("text", enc) + "=" + + URLEncoder.encode(txt, enc); + smsdata += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + + URLEncoder.encode(rnrSEE, enc); + URL smsurl = new URL("https://www.google.com/voice/b/0/sms/send/"); + + URLConnection smsconn = smsurl.openConnection(); + // Authorization Header Logic + String oauthToken_sendSms = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_sendSms = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_sendSms != null && !oauthToken_sendSms.isEmpty()) { + smsconn.setRequestProperty("Authorization", "Bearer " + oauthToken_sendSms); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + smsconn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in sendSMS(dest, txt)."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in sendSMS(dest, txt)."); + } + // End Authorization Header Logic + smsconn + .setRequestProperty( + "User-agent", + USER_AGENT); + + smsconn.setDoOutput(true); + OutputStreamWriter callwr = new OutputStreamWriter(smsconn.getOutputStream()); + callwr.write(smsdata); + callwr.flush(); + + BufferedReader callrd = new BufferedReader(new InputStreamReader( + smsconn.getInputStream())); + + String line; + while ((line = callrd.readLine()) != null) { + out += line + "\n\r"; + + } + + callwr.close(); + callrd.close(); + + if (out.equals("")) { + throw new IOException("No Response Data Received."); + } + + return out; + } + + + public void updateCookies(Map cookieMap) + { + GVCookieManager.getInstance().setCookies(cookieMap); + } + + + /** + * HTTP GET request for a given URL String. + * + * @param urlString + * the url string + * @return the string + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public String get(String urlString) throws IOException { + URL url = new URL(urlString); + //+ "?auth=" + URLEncoder.encode(authToken, enc)); + + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + // Authorization Header Logic + String oauthToken_get = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_get = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_get != null && !oauthToken_get.isEmpty()) { + conn.setRequestProperty("Authorization", "Bearer " + oauthToken_get); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + conn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in get(String urlString)."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in get(String urlString)."); + } + // End Authorization Header Logic + conn.setRequestProperty( + "User-agent", + USER_AGENT); + conn.setRequestProperty("Cookie", GVCookieManager.getInstance().listAllOutgoingCookies()); + conn.setInstanceFollowRedirects(false); // will follow redirects of same protocol http to http, but does not follow from http to https for example if set to true + + // Get the response + conn.connect(); + int responseCode = conn.getResponseCode(); + if(PRINT_TO_CONSOLE) + System.out.println(urlString + " - " + conn.getResponseMessage()); + InputStream is; + if(responseCode==200) { + is = conn.getInputStream(); + } else if(responseCode==HttpURLConnection.HTTP_MOVED_PERM || responseCode==HttpURLConnection.HTTP_MOVED_TEMP || responseCode==HttpURLConnection.HTTP_SEE_OTHER || responseCode==307) { + redirectCounter++; + if(redirectCounter > MAX_REDIRECTS) { + redirectCounter = 0; + throw new IOException(urlString + " : " + conn.getResponseMessage() + "("+responseCode+") : Too manny redirects. exiting."); + } + String location = conn.getHeaderField("Location"); + if(location!=null && !location.equals("")) { + System.out.println(urlString + " - " + responseCode + " - new URL: " + location); + return get(location); + } else { + throw new IOException(urlString + " : " + conn.getResponseMessage() + "("+responseCode+") : Received moved answer but no Location. exiting."); + } + } else { + is = conn.getErrorStream(); + } + redirectCounter = 0; + + if(is==null) { + throw new IOException(urlString + " : " + conn.getResponseMessage() + "("+responseCode+") : InputStream was null : exiting."); + } + + String result=""; + try { + // Get the response + BufferedReader rd = new BufferedReader(new InputStreamReader(is)); + + StringBuffer sb = new StringBuffer(); + String line; + while ((line = rd.readLine()) != null) { + sb.append(line + "\n\r"); + } + rd.close(); + result = sb.toString(); + } catch (Exception e) { + throw new IOException(urlString + " - " + conn.getResponseMessage() + "("+responseCode+") - " +e.getLocalizedMessage()); + } + return result; + } + + + /** + * HTTP GET request for a given URL String and a given page number. + * + * @param urlString the url string + * @param page number must be a natural number + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public String get(String urlString,int page) throws IOException { + URL url = new URL(urlString + "?page=p"+page); + //url+="&page="+page; + URLConnection conn = url.openConnection(); + // Authorization Header Logic + String oauthToken_getPage = null; + if (GVCookieManager.getInstance() != null && GVCookieManager.getInstance().getCookies() != null) { + oauthToken_getPage = GVCookieManager.getInstance().getCookies().get("AUTH_TOKEN"); + } + + if (oauthToken_getPage != null && !oauthToken_getPage.isEmpty()) { + conn.setRequestProperty("Authorization", "Bearer " + oauthToken_getPage); + } else if (this.authToken != null && !this.authToken.isEmpty()) { + conn.setRequestProperty("Authorization", "GoogleLogin auth=" + this.authToken); + if(PRINT_TO_CONSOLE) System.out.println("Using legacy authToken for Authorization header in get(String urlString, int page)."); + } else { + if(PRINT_TO_CONSOLE) System.out.println("Warning: No OAuth token or legacy authToken available for Authorization header in get(String urlString, int page)."); + } + // End Authorization Header Logic + conn + .setRequestProperty( + "User-agent", + USER_AGENT); + + // Get the response + BufferedReader rd = new BufferedReader(new InputStreamReader(conn + .getInputStream())); + StringBuffer sb = new StringBuffer(); + String line; + while ((line = rd.readLine()) != null) { + sb.append(line + "\n\r"); + } + rd.close(); + String result = sb.toString(); + + return result; + } + + /** + * Login Method to refresh authentication with Google Voice. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public void login() throws IOException { + login(null,null); + } + + + + /** + * Use this login method to login - use captchaAnswer to answer a captcha challenge + * @param pCaptchaAnswer (optional) String entered by the user as an answer to a CAPTCHA challenge. - null to make a normal login attempt + * @param pCaptchaToken (optional) token which matches the response/url from the captcha challenge + * @throws IOException if login encounters a connection error + */ + public void login(String pCaptchaAnswer, String pCaptchaToken) throws IOException { + + String data = URLEncoder.encode("accountType", enc) + "=" + + URLEncoder.encode(account_type, enc); + + data += "&" + URLEncoder.encode("service", enc) + "=" + + URLEncoder.encode(SERVICE, enc); + data += "&" + URLEncoder.encode("source", enc) + "=" + + URLEncoder.encode(source, enc); + if(pCaptchaAnswer!=null && pCaptchaToken!=null) { + data += "&" + URLEncoder.encode("logintoken", enc) + "=" + + URLEncoder.encode(pCaptchaToken, enc); + data += "&" + URLEncoder.encode("logincaptcha", enc) + "=" + + URLEncoder.encode(pCaptchaAnswer, enc); + } + + // Send data + URL url = new URL(loginURLString); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn + .setRequestProperty( + "User-agent", + USER_AGENT); + + conn.setDoOutput(true); + OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); + wr.write(data); + wr.flush(); + + // Get the response + conn.connect(); + int responseCode = conn.getResponseCode(); + if(PRINT_TO_CONSOLE) + System.out.println(loginURLString + " - " + conn.getResponseMessage()); + InputStream is; + if(responseCode==200) { + is = conn.getInputStream(); + } else { + is = conn.getErrorStream(); + } + InputStreamReader isr = new InputStreamReader(is); + BufferedReader rd = new BufferedReader(isr); + String line; + String completelineDebug=""; + + /* + * A failure response contains an error code and a URL to an error page that can be displayed to the user. + * If the error code is a CAPTCHA challenge, the response also includes a URL to a CAPTCHA image and a special + * token. Your application should be able to solicit an answer from the user and then retry the login request. + * To display the CAPTCHA image to the user, prefix the CaptchaUrl value with "http://www.google.com/accounts/", + * for example: " http://www.google.com/accounts/Captcha?ctoken=HiteT4b0Bk5Xg18_AcVoP6-yFkHPibe7O9EqxeiI7lUSN". + */ + String lErrorString = "Unknown Connection Error."; // ex: Error=CaptchaRequired + + // String AuthToken = null; + while ((line = rd.readLine()) != null) { + completelineDebug += line+"\n"; + if (line.contains("Auth=")) { + this.authToken = line.split("=", 2)[1].trim(); + if (PRINT_TO_CONSOLE){ + System.out.println("Logged in to Google - Auth token received"); + } + } else if (line.contains("Error=")) { + lErrorString = line.split("=", 2)[1].trim(); + //error = getErrorEnumByCode(lErrorString); + error = ERROR_CODE.valueOf(lErrorString); + if (PRINT_TO_CONSOLE) + System.out.println("Login error - "+lErrorString); + + + } + if (line.contains("CaptchaToken=")) { + captchaToken = line.split("=", 2)[1].trim(); + } + + if (line.contains("CaptchaUrl=")) { + captchaUrl = "http://www.google.com/accounts/" + line.split("=", 2)[1].trim(); + } + if (line.contains("Url=")) { + captchaUrl2 = line.split("=", 2)[1].trim(); + } + + + } + wr.close(); + rd.close(); + +// if (PRINT_TO_CONSOLE){ +// System.out.println(completelineDebug); +// } + + if (this.authToken == null) { + AuthenticationException.throwProperException(error, captchaToken, captchaUrl); + } + + String response = this.getRawPhonesInfo(); + int phoneIndex = response.indexOf("gc-user-number-value\">"); + this.phoneNumber = response.substring(phoneIndex + 22, phoneIndex + 36); + this.phoneNumber = this.phoneNumber.replaceAll("[^a-zA-Z0-9]", ""); + if (this.phoneNumber.indexOf("+") == -1) { + this.phoneNumber = "+1" + this.phoneNumber; + } + } + + /** + * Gets the error enum by code. + * + * @param pErrorCodeString the error code string + * @return the error enum by code + */ + @Deprecated + private ERROR_CODE getErrorEnumByCode(String pErrorCodeString) { + if(pErrorCodeString.equals(ERROR_CODE.AccountDeleted.name())) { + return ERROR_CODE.AccountDeleted; + } else if(pErrorCodeString.equals(ERROR_CODE.AccountDisabled.name())) { + return ERROR_CODE.AccountDisabled; + } else if(pErrorCodeString.equals(ERROR_CODE.BadAuthentication.name())) { + return ERROR_CODE.BadAuthentication; + } else if(pErrorCodeString.equals(ERROR_CODE.CaptchaRequired.name())) { + return ERROR_CODE.CaptchaRequired; + } else if(pErrorCodeString.equals(ERROR_CODE.NotVerified.name())) { + return ERROR_CODE.NotVerified; + } else if(pErrorCodeString.equals(ERROR_CODE.ServiceDisabled.name())) { + return ERROR_CODE.ServiceDisabled; + } else if(pErrorCodeString.equals(ERROR_CODE.TermsNotAgreed.name())) { + return ERROR_CODE.TermsNotAgreed; + } else { + return ERROR_CODE.Unknown; + } + } + + /** + * Gets the error. + * + * @return the error + */ + @Deprecated + public ERROR_CODE getError() { + return error; + } + + /** + * Gets the captcha url. + * + * @return the captcha url + */ + public String getCaptchaUrl() { + return captchaUrl; + } + + /** + * Gets the captcha token. + * + * @return the captcha token + */ + public String getCaptchaToken() { + return captchaToken; + } + + /** + * Fires a Get request for Recent Items. If the Response requests login + * authentication or if an exception is thrown, a false is returned, + * otherwise if arbitrary text is contained for a logged in account, a true + * is returned. + * + *TODO Examine methodology. Perhaps Could Establish greater persistence with + *an option to force an update. Currently this is an expensive + *and slow method. + * + * @return true, if is logged in + */ + public boolean isLoggedIn() { + String res; + try { + res = getRecent(); + } catch (IOException e) { + return false; + } + if (res + .contains(" SCOPES = Arrays.asList( + "https://www.googleapis.com/auth/userinfo.email", + "https://www.googleapis.com/auth/userinfo.profile" + // Potentially, scopes for Google Voice if an API is being targeted + ); + + // Path to client_secret.json. Users must download this from Google Cloud Console. + // Place it in the project root or a known location. + private static final String CLIENT_SECRETS_FILE_PATH = "client_secret.json"; + + // Directory to store user credentials. + private static final File CREDENTIALS_DIRECTORY = new File( + System.getProperty("user.home"), ".credentials/google-voice-java"); + + // Properties file to store the final token for GVCookieManager + private static final String OUTPUT_PROPERTIES_FILENAME = "google-auth.properties"; + // Store it in the same directory as credentials or project root for simplicity for now + private static final File OUTPUT_PROPERTIES_FILE = new File(CREDENTIALS_DIRECTORY, OUTPUT_PROPERTIES_FILENAME); + + + public static void main(String[] args) { + try { + System.out.println("Attempting to authorize..."); + System.out.println("Looking for Client Secrets file at: " + new File(CLIENT_SECRETS_FILE_PATH).getAbsolutePath()); + System.out.println("Credentials will be stored at: " + CREDENTIALS_DIRECTORY.getAbsolutePath()); + System.out.println("Output properties will be stored at: " + OUTPUT_PROPERTIES_FILE.getAbsolutePath()); + + // Check if client_secret.json exists + File clientSecretsFile = new File(CLIENT_SECRETS_FILE_PATH); + if (!clientSecretsFile.exists()) { + System.err.println("ERROR: Client secrets file not found!"); + System.err.println("Please download your 'client_secret.json' from the Google Cloud Console"); + System.err.println("and place it in the project root directory: " + clientSecretsFile.getAbsolutePath()); + System.exit(1); + } + + Reader clientSecretReader = new FileReader(clientSecretsFile); // Use the File object + GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader); + + FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(CREDENTIALS_DIRECTORY); + + GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( + HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) + .setDataStoreFactory(dataStoreFactory) + .setAccessType("offline") // Request refresh token + .build(); + + LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build(); + // The port 8888 is a common example; ensure it's free or configurable. + // The redirect URI in Google Cloud Console must match: http://localhost:8888/Callback + + System.out.println("Attempting to authorize. Please follow the instructions in your browser."); + Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user"); + + if (credential != null && credential.getAccessToken() != null) { + System.out.println("Authorization successful!"); + System.out.println("Access Token: " + credential.getAccessToken()); + if (credential.getRefreshToken() != null) { + System.out.println("Refresh Token available."); + } + + saveTokenToProperties(credential.getAccessToken()); + + System.out.println("Access token saved to: " + OUTPUT_PROPERTIES_FILE.getAbsolutePath()); + System.out.println("The application should now be able to use this token via GVCookieManager."); + + } else { + System.err.println("Authorization failed or access token was not retrieved."); + } + + } catch (IOException e) { + System.err.println("IOException during authorization: " + e.getMessage()); + e.printStackTrace(); + System.err.println("Please ensure '" + CLIENT_SECRETS_FILE_PATH + "' is present and correctly configured, and that the redirect URIs match in your Google Cloud Console (e.g., http://localhost:8888/Callback)."); + } catch (Exception e) { + System.err.println("An unexpected error occurred: " + e.getMessage()); + e.printStackTrace(); + } + } + + private static void saveTokenToProperties(String accessToken) throws IOException { + Properties props = new Properties(); + // GVCookieManager and Voice.java used 'authToken'. + // OAuth Access Tokens are typically used as Bearer tokens. + // For now, let's save it as AUTH_TOKEN. Voice.java might need adjustment + // to use it as "Authorization: Bearer " instead of "GoogleLogin auth=". + props.setProperty("AUTH_TOKEN", accessToken); + // If other specific cookie values were expected by GVCookieManager, + // they are not directly available from this OAuth flow. This might be a + // point of incompatibility with the old GVCookieManager if it expects specific cookies. + + if (!OUTPUT_PROPERTIES_FILE.getParentFile().exists()) { + OUTPUT_PROPERTIES_FILE.getParentFile().mkdirs(); + } + + try (OutputStreamWriter writer = new OutputStreamWriter( + new FileOutputStream(OUTPUT_PROPERTIES_FILE), StandardCharsets.UTF_8)) { + props.store(writer, "Google OAuth Access Token"); + } + } +} diff --git a/src/com/techventus/server/voice/datatypes/ActiveForwardingId.java b/src/main/java/com/techventus/server/voice/datatypes/ActiveForwardingId.java similarity index 96% rename from src/com/techventus/server/voice/datatypes/ActiveForwardingId.java rename to src/main/java/com/techventus/server/voice/datatypes/ActiveForwardingId.java index 09a7a69..b69606a 100644 --- a/src/com/techventus/server/voice/datatypes/ActiveForwardingId.java +++ b/src/main/java/com/techventus/server/voice/datatypes/ActiveForwardingId.java @@ -1,5 +1,5 @@ /** - * + * */ package com.techventus.server.voice.datatypes; @@ -18,7 +18,7 @@ public class ActiveForwardingId { String id; boolean disabled; - + public ActiveForwardingId(JSONObject jsonObject) throws JSONException { id = jsonObject.getString("id"); disabled = jsonObject.getBoolean("disabled"); @@ -28,13 +28,13 @@ public ActiveForwardingId(String pId, boolean pDisabled) { disabled = pDisabled; } - public final static List createActiveForwardingIdListFromJsonPartResponse(String jsonPart){ + public final static List createActiveForwardingIdListFromJsonPartResponse(String jsonPart){ //TODO do with json parser List activeForwardingIds = new ArrayList(); if(jsonPart!=null &! jsonPart.equals("")) { jsonPart = jsonPart.replaceAll(",\"", ",#"); String[] activeForwardingIdsStrings = jsonPart.split(Pattern.quote(",")); - for (int j = 0; j < activeForwardingIdsStrings.length; j++) { + for (int j = 0; j < activeForwardingIdsStrings.length; j++) { String gId = ParsingUtil.removeUninterestingParts(activeForwardingIdsStrings[j], "\"", "\"", false); boolean gState = Boolean.parseBoolean(activeForwardingIdsStrings[j].substring(activeForwardingIdsStrings[j].indexOf(":")+1)); activeForwardingIds.add(new ActiveForwardingId(gId, gState)); @@ -42,7 +42,7 @@ public final static List createActiveForwardingIdListFromJso } return activeForwardingIds; } - + public String toString() { try { return getAsJsonObject().toString(); @@ -50,7 +50,7 @@ public String toString() { return null; } } - + public JSONObject getAsJsonObject() throws JSONException { JSONObject retO = new JSONObject(); retO.put("id", id); @@ -69,5 +69,5 @@ public void setId(String id) { public void setDisabled(boolean disabled) { this.disabled = disabled; } - + } diff --git a/src/com/techventus/server/voice/datatypes/AllSettings.java b/src/main/java/com/techventus/server/voice/datatypes/AllSettings.java similarity index 72% rename from src/com/techventus/server/voice/datatypes/AllSettings.java rename to src/main/java/com/techventus/server/voice/datatypes/AllSettings.java index 1a4720f..eec9d8c 100644 --- a/src/com/techventus/server/voice/datatypes/AllSettings.java +++ b/src/main/java/com/techventus/server/voice/datatypes/AllSettings.java @@ -1,391 +1,391 @@ -package com.techventus.server.voice.datatypes; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import com.techventus.server.voice.util.ParsingUtil; - -public class AllSettings{ - - private int[] phoneList; - private Phone[] phones; - private Setting settings; - - public AllSettings(String json) throws JSONException { - JSONObject lObj = new JSONObject(json); - - phoneList = ParsingUtil.jsonIntArrayToIntArray(lObj.getJSONArray("phoneList")); - - phones = Phone.createArrayFromJsonObject(lObj.getJSONObject("phones")); - - settings = new Setting(lObj.getJSONObject("settings")); - } - - public JSONObject toJsonObject() throws JSONException { - JSONObject lObj = new JSONObject(); - lObj.put("phoneList",phoneList); - lObj.put("phones",Phone.phonesArrayToJsonObject(phones)); - lObj.put("settings",settings.toJsonObject()); - return lObj; - } - - //TODO Perhaps this should throw an Exception rather than return false - /** - * - * Query disabled status - if id not found, then it returned false, which normally means enabled. - * @param phoneId - * @return true if the Phone is Disabled. Otherwise it return false. - */ - public boolean isPhoneDisabled(int phoneId) { - boolean ret = false; - try { - if(settings.getmDisabledIdList()!=null) { - for (int i = 0; i < settings.getmDisabledIdList().length; i++) { - if(settings.getmDisabledIdList()[i].getId().equals(phoneId+"")) { - ret = true; - } - } - } else { - // list is empty, we will return false - ret = false; - } - } catch (NullPointerException e) { - ret = false; - } - return ret; - } - - public void setPhoneDisabled(int phoneId) { - for (DisabledId lDisId : settings.getmDisabledIdList()) { - if(lDisId.getId().equals(phoneId+"")) { - lDisId.setDisabled(true); - return; - } - } - // if not in array we create a new one - DisabledId[] lNewDisabledList = new DisabledId[settings.getmDisabledIdList().length+1]; - for (int i = 0; i < settings.getmDisabledIdList().length; i++) { - lNewDisabledList[i] = settings.getmDisabledIdList()[i]; - } - lNewDisabledList[lNewDisabledList.length-1] = new DisabledId(phoneId+"", true); - settings.setmDisabledIdList(lNewDisabledList); - } - - public void setPhoneEnabled(int phoneId) { - for (DisabledId lDisId : settings.getmDisabledIdList()) { - if(lDisId.getId().equals(phoneId+"")) { - lDisId.setDisabled(false); - return; - } - } - // if not in array we create a new one - DisabledId[] lNewDisabledList = new DisabledId[settings.getmDisabledIdList().length+1]; - for (int i = 0; i < settings.getmDisabledIdList().length; i++) { - lNewDisabledList[i] = settings.getmDisabledIdList()[i]; - } - lNewDisabledList[lNewDisabledList.length-1] = new DisabledId(phoneId+"", false); - settings.setmDisabledIdList(lNewDisabledList); - } - - /** - * - * Query smsEnabled status - if id not found, then it returnes false - * @param phoneId - * @return true if the Phone is smsEnabled. Otherwise it returns false. - */ - public boolean isPhoneSmsEnabled(int phoneId) { - boolean ret = false; - try { - for (int i = 0; i < phones.length; i++) { - if(phones[i].getId() == phoneId) { - ret = phones[i].getSmsEnabled(); - } - } - } catch (NullPointerException e) { - ret = false; - } - return ret; - } - - /** - * @return the phoneList - */ - public int[] getPhoneList() { - return phoneList; - } - - /** - * @return the phoneList sorted - */ - public int[] getPhoneListSorted() { - Arrays.sort(phoneList); - return phoneList; - } - - /** - * @return the phoneList as List - */ - public List getPhoneListAsList() { - List lresult = new ArrayList(); - for (int i = 0; i < phoneList.length; i++) { - lresult.add(phoneList[i]); - } - return lresult; - } - - /** - * @return the phones - */ - public Phone[] getPhones() { - return phones; - } - - /** - * @return the phones sorted by their id number - */ - public Phone[] getPhonesSorted() { - Arrays.sort(phones); - return phones; - } - - /** - * @return the settings - */ - public Setting getSettings() { - return settings; - } - - /** - * @param phoneList the phoneList to set - */ - public void setPhoneList(int[] phoneList) { - this.phoneList = phoneList; - } - - /** - * @param phones the phones to set - */ - public void setPhones(Phone[] phones) { - this.phones = phones; - } - - /** - * @param settings the settings to set - */ - public void setSettings(Setting settings) { - this.settings = settings; - } - - - - - /* -{ - "phoneList": [ - 1, - 2 - ], - "phones": { - "1": { - "active": true, - "behaviorOnRedirect": 0, - "carrier": "", - "customOverrideState": 0, - "dEPRECATEDDisabled": false, - "enabledForOthers": true, - "formattedNumber": "(912) 342-2319", - "id": 1, - "incomingAccessNumber": "", - "name": "SkypeUS#", - "phoneNumber": "+19123422319", - "policyBitmask": 0, - "redirectToVoicemail": false, - "scheduleSet": false, - "smsEnabled": false, - "telephonyVerified": true, - "type": 1, - "verified": true, - "voicemailForwardingVerified": false, - "wd": { - "allDay": false, - "times": [] - }, - "we": { - "allDay": false, - "times": [] - }, - "weekdayAllDay": false, - "weekdayTimes": [], - "weekendAllDay": false, - "weekendTimes": [] - }, - "2": { - "active": true, - "behaviorOnRedirect": 0, - "carrier": "", - "customOverrideState": 0, - "dEPRECATEDDisabled": false, - "enabledForOthers": true, - "formattedNumber": "(747) 477-2719", - "id": 2, - "incomingAccessNumber": "", - "name": "Gizmo5", - "phoneNumber": "+17474772719", - "policyBitmask": 0, - "redirectToVoicemail": false, - "scheduleSet": false, - "smsEnabled": false, - "telephonyVerified": true, - "type": 7, - "verified": true, - "voicemailForwardingVerified": false, - "wd": { - "allDay": false, - "times": [] - }, - "we": { - "allDay": false, - "times": [] - }, - "weekdayAllDay": false, - "weekdayTimes": [], - "weekendAllDay": false, - "weekendTimes": [] - } - }, - "settings": {"settings": { - "activeForwardingIds": [ - 1, - 2 - ], - "baseUrl": "https://www.google.com/voice", - "credits": 1000, - "defaultGreetingId": 0, - "didInfos": [], - "directConnect": false, - "disabledIdMap": [{ - "disabled": true, - "id": "6" - }], - "doNotDisturb": false, - "emailAddresses": [{}], - "emailNotificationActive": true, - "emailNotificationAddress": "teisentraeger@gmail.com", - "greetings": [ - { - "id": "0", - "name": "System Standard" - }, - { - "id": "2", - "name": "Testgreeting 1" - }, - { - "id": "3", - "name": "Testgreeting 2" - } - ], - "groupList": [ - "15", - "13", - "14", - "2934992504966866256", - "7546022145019939053", - "4645700645618079676", - "8611236118126468131" - ], - "groups": { - "13": { - "directConnect": false, - "disabledForwardingIds": {}, - "greetingId": 2, - "id": "13", - "isCustomDirectConnect": false, - "isCustomForwarding": false, - "isCustomGreeting": true, - "name": "Friends" - }, - "14": { - "directConnect": false, - "disabledForwardingIds": {}, - "greetingId": 0, - "id": "14", - "isCustomDirectConnect": false, - "isCustomForwarding": false, - "isCustomGreeting": false, - "name": "Family" - }, - "15": { - "directConnect": true, - "disabledForwardingIds": {"1": true}, - "greetingId": 0, - "id": "15", - "isCustomDirectConnect": true, - "isCustomForwarding": true, - "isCustomGreeting": false, - "name": "Coworkers" - }, - "2934992504966866256": { - "directConnect": false, - "disabledForwardingIds": {}, - "greetingId": 0, - "id": "2934992504966866256", - "isCustomDirectConnect": false, - "isCustomForwarding": false, - "isCustomGreeting": false, - "name": "GMail Contacts only - no phone sync" - }, - "4645700645618079676": { - "directConnect": false, - "disabledForwardingIds": {}, - "greetingId": 0, - "id": "4645700645618079676", - "isCustomDirectConnect": false, - "isCustomForwarding": false, - "isCustomGreeting": false, - "name": "Mailing Addresses" - }, - "7546022145019939053": { - "directConnect": false, - "disabledForwardingIds": {}, - "greetingId": 0, - "id": "7546022145019939053", - "isCustomDirectConnect": false, - "isCustomForwarding": false, - "isCustomGreeting": false, - "name": "Starred in Android" - }, - "8611236118126468131": { - "directConnect": false, - "disabledForwardingIds": {}, - "greetingId": 0, - "id": "8611236118126468131", - "isCustomDirectConnect": false, - "isCustomForwarding": false, - "isCustomGreeting": false, - "name": "Church" - } - }, - - "language": "en", - "primaryDid": "+19122891115", - "screenBehavior": 0, - "showTranscripts": true, - "smsNotifications": "[]", - "smsToEmailActive": true, - "smsToEmailSubject": false, - "spam": 0, - "timezone": "Europe/Berlin", - "useDidAsCallerId": false, - "useDidAsSource": true - }} -} - - */ - - -} +package com.techventus.server.voice.datatypes; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import com.techventus.server.voice.util.ParsingUtil; + +public class AllSettings{ + + private int[] phoneList; + private Phone[] phones; + private Setting settings; + + public AllSettings(String json) throws JSONException { + JSONObject lObj = new JSONObject(json); + + phoneList = ParsingUtil.jsonIntArrayToIntArray(lObj.getJSONArray("phoneList")); + + phones = Phone.createArrayFromJsonObject(lObj.getJSONObject("phones")); + + settings = new Setting(lObj.getJSONObject("settings")); + } + + public JSONObject toJsonObject() throws JSONException { + JSONObject lObj = new JSONObject(); + lObj.put("phoneList",phoneList); + lObj.put("phones",Phone.phonesArrayToJsonObject(phones)); + lObj.put("settings",settings.toJsonObject()); + return lObj; + } + + //TODO Perhaps this should throw an Exception rather than return false + /** + * + * Query disabled status - if id not found, then it returned false, which normally means enabled. + * @param phoneId + * @return true if the Phone is Disabled. Otherwise it return false. + */ + public boolean isPhoneDisabled(int phoneId) { + boolean ret = false; + try { + if(settings.getmDisabledIdList()!=null) { + for (int i = 0; i < settings.getmDisabledIdList().length; i++) { + if(settings.getmDisabledIdList()[i].getId().equals(phoneId+"")) { + ret = true; + } + } + } else { + // list is empty, we will return false + ret = false; + } + } catch (NullPointerException e) { + ret = false; + } + return ret; + } + + public void setPhoneDisabled(int phoneId) { + for (DisabledId lDisId : settings.getmDisabledIdList()) { + if(lDisId.getId().equals(phoneId+"")) { + lDisId.setDisabled(true); + return; + } + } + // if not in array we create a new one + DisabledId[] lNewDisabledList = new DisabledId[settings.getmDisabledIdList().length+1]; + for (int i = 0; i < settings.getmDisabledIdList().length; i++) { + lNewDisabledList[i] = settings.getmDisabledIdList()[i]; + } + lNewDisabledList[lNewDisabledList.length-1] = new DisabledId(phoneId+"", true); + settings.setmDisabledIdList(lNewDisabledList); + } + + public void setPhoneEnabled(int phoneId) { + for (DisabledId lDisId : settings.getmDisabledIdList()) { + if(lDisId.getId().equals(phoneId+"")) { + lDisId.setDisabled(false); + return; + } + } + // if not in array we create a new one + DisabledId[] lNewDisabledList = new DisabledId[settings.getmDisabledIdList().length+1]; + for (int i = 0; i < settings.getmDisabledIdList().length; i++) { + lNewDisabledList[i] = settings.getmDisabledIdList()[i]; + } + lNewDisabledList[lNewDisabledList.length-1] = new DisabledId(phoneId+"", false); + settings.setmDisabledIdList(lNewDisabledList); + } + + /** + * + * Query smsEnabled status - if id not found, then it returnes false + * @param phoneId + * @return true if the Phone is smsEnabled. Otherwise it returns false. + */ + public boolean isPhoneSmsEnabled(int phoneId) { + boolean ret = false; + try { + for (int i = 0; i < phones.length; i++) { + if(phones[i].getId() == phoneId) { + ret = phones[i].getSmsEnabled(); + } + } + } catch (NullPointerException e) { + ret = false; + } + return ret; + } + + /** + * @return the phoneList + */ + public int[] getPhoneList() { + return phoneList; + } + + /** + * @return the phoneList sorted + */ + public int[] getPhoneListSorted() { + Arrays.sort(phoneList); + return phoneList; + } + + /** + * @return the phoneList as List + */ + public List getPhoneListAsList() { + List lresult = new ArrayList(); + for (int i = 0; i < phoneList.length; i++) { + lresult.add(phoneList[i]); + } + return lresult; + } + + /** + * @return the phones + */ + public Phone[] getPhones() { + return phones; + } + + /** + * @return the phones sorted by their id number + */ + public Phone[] getPhonesSorted() { + Arrays.sort(phones); + return phones; + } + + /** + * @return the settings + */ + public Setting getSettings() { + return settings; + } + + /** + * @param phoneList the phoneList to set + */ + public void setPhoneList(int[] phoneList) { + this.phoneList = phoneList; + } + + /** + * @param phones the phones to set + */ + public void setPhones(Phone[] phones) { + this.phones = phones; + } + + /** + * @param settings the settings to set + */ + public void setSettings(Setting settings) { + this.settings = settings; + } + + + + + /* +{ + "phoneList": [ + 1, + 2 + ], + "phones": { + "1": { + "active": true, + "behaviorOnRedirect": 0, + "carrier": "", + "customOverrideState": 0, + "dEPRECATEDDisabled": false, + "enabledForOthers": true, + "formattedNumber": "(912) 342-2319", + "id": 1, + "incomingAccessNumber": "", + "name": "SkypeUS#", + "phoneNumber": "+19123422319", + "policyBitmask": 0, + "redirectToVoicemail": false, + "scheduleSet": false, + "smsEnabled": false, + "telephonyVerified": true, + "type": 1, + "verified": true, + "voicemailForwardingVerified": false, + "wd": { + "allDay": false, + "times": [] + }, + "we": { + "allDay": false, + "times": [] + }, + "weekdayAllDay": false, + "weekdayTimes": [], + "weekendAllDay": false, + "weekendTimes": [] + }, + "2": { + "active": true, + "behaviorOnRedirect": 0, + "carrier": "", + "customOverrideState": 0, + "dEPRECATEDDisabled": false, + "enabledForOthers": true, + "formattedNumber": "(747) 477-2719", + "id": 2, + "incomingAccessNumber": "", + "name": "Gizmo5", + "phoneNumber": "+17474772719", + "policyBitmask": 0, + "redirectToVoicemail": false, + "scheduleSet": false, + "smsEnabled": false, + "telephonyVerified": true, + "type": 7, + "verified": true, + "voicemailForwardingVerified": false, + "wd": { + "allDay": false, + "times": [] + }, + "we": { + "allDay": false, + "times": [] + }, + "weekdayAllDay": false, + "weekdayTimes": [], + "weekendAllDay": false, + "weekendTimes": [] + } + }, + "settings": {"settings": { + "activeForwardingIds": [ + 1, + 2 + ], + "baseUrl": "https://www.google.com/voice", + "credits": 1000, + "defaultGreetingId": 0, + "didInfos": [], + "directConnect": false, + "disabledIdMap": [{ + "disabled": true, + "id": "6" + }], + "doNotDisturb": false, + "emailAddresses": [{}], + "emailNotificationActive": true, + "emailNotificationAddress": "teisentraeger@gmail.com", + "greetings": [ + { + "id": "0", + "name": "System Standard" + }, + { + "id": "2", + "name": "Testgreeting 1" + }, + { + "id": "3", + "name": "Testgreeting 2" + } + ], + "groupList": [ + "15", + "13", + "14", + "2934992504966866256", + "7546022145019939053", + "4645700645618079676", + "8611236118126468131" + ], + "groups": { + "13": { + "directConnect": false, + "disabledForwardingIds": {}, + "greetingId": 2, + "id": "13", + "isCustomDirectConnect": false, + "isCustomForwarding": false, + "isCustomGreeting": true, + "name": "Friends" + }, + "14": { + "directConnect": false, + "disabledForwardingIds": {}, + "greetingId": 0, + "id": "14", + "isCustomDirectConnect": false, + "isCustomForwarding": false, + "isCustomGreeting": false, + "name": "Family" + }, + "15": { + "directConnect": true, + "disabledForwardingIds": {"1": true}, + "greetingId": 0, + "id": "15", + "isCustomDirectConnect": true, + "isCustomForwarding": true, + "isCustomGreeting": false, + "name": "Coworkers" + }, + "2934992504966866256": { + "directConnect": false, + "disabledForwardingIds": {}, + "greetingId": 0, + "id": "2934992504966866256", + "isCustomDirectConnect": false, + "isCustomForwarding": false, + "isCustomGreeting": false, + "name": "GMail Contacts only - no phone sync" + }, + "4645700645618079676": { + "directConnect": false, + "disabledForwardingIds": {}, + "greetingId": 0, + "id": "4645700645618079676", + "isCustomDirectConnect": false, + "isCustomForwarding": false, + "isCustomGreeting": false, + "name": "Mailing Addresses" + }, + "7546022145019939053": { + "directConnect": false, + "disabledForwardingIds": {}, + "greetingId": 0, + "id": "7546022145019939053", + "isCustomDirectConnect": false, + "isCustomForwarding": false, + "isCustomGreeting": false, + "name": "Starred in Android" + }, + "8611236118126468131": { + "directConnect": false, + "disabledForwardingIds": {}, + "greetingId": 0, + "id": "8611236118126468131", + "isCustomDirectConnect": false, + "isCustomForwarding": false, + "isCustomGreeting": false, + "name": "Church" + } + }, + + "language": "en", + "primaryDid": "+19122891115", + "screenBehavior": 0, + "showTranscripts": true, + "smsNotifications": "[]", + "smsToEmailActive": true, + "smsToEmailSubject": false, + "spam": 0, + "timezone": "Europe/Berlin", + "useDidAsCallerId": false, + "useDidAsSource": true + }} +} + + */ + + +} diff --git a/src/com/techventus/server/voice/datatypes/Contact.java b/src/main/java/com/techventus/server/voice/datatypes/Contact.java similarity index 97% rename from src/com/techventus/server/voice/datatypes/Contact.java rename to src/main/java/com/techventus/server/voice/datatypes/Contact.java index 571a033..bf8be60 100644 --- a/src/com/techventus/server/voice/datatypes/Contact.java +++ b/src/main/java/com/techventus/server/voice/datatypes/Contact.java @@ -3,11 +3,11 @@ import com.techventus.server.voice.util.ParsingUtil; /** - * + * * A Contact * TODO I think we need to add several subclasses for the different contact infos * like phone numbers, Email addresses and such - * + * * @author Tobias Eisentraeger * */ @@ -20,7 +20,7 @@ public class Contact implements Comparable{ private String number; /** The Url of the Contacts image on the web **/ private String imageUrl; - + public Contact(String name, String id, String number, String imageUrl) { super(); this.name = name; @@ -80,7 +80,7 @@ public String getId() { public void setId(String id) { this.id = id; } - + /* (non-Javadoc) * @see java.lang.Object#toString() */ @@ -101,7 +101,7 @@ public String toString() { } return ret+"}"; } - + /** * Deprecated Method. Creates a Contact out of a html * TODO DummyData - Implement. @@ -112,15 +112,15 @@ public String toString() { @Deprecated public static Contact extractContact(String html) { html = ParsingUtil.removeUninterestingParts(html,"","
", true); - - //if it shows a name John Doe + + //if it shows a name John Doe String lname; try { lname = ParsingUtil.removeUninterestingParts(html,"","",false); } catch (Exception e) { lname = "Parsing Error (name)"; } - + String lid; try { String comingCloser = ParsingUtil.removeUninterestingParts(html,"","",true); @@ -128,8 +128,8 @@ public static Contact extractContact(String html) { } catch (Exception e) { lid = "Parsing Error (id)"; } - - + + // if it shows a phone number (912) 230-0029 - mobile String lnumber; try { @@ -138,27 +138,27 @@ public static Contact extractContact(String html) { } catch (Exception e) { lnumber = "Parsing Error (number)"; } - + //if it shows an image for the contact String limageUrl; try { // Get the correct part:
limageUrl = ParsingUtil.removeUninterestingParts(html,"","
or - limageUrl= ParsingUtil.removeUninterestingParts(html,"",false); + limageUrl= ParsingUtil.removeUninterestingParts(html,"",false); // now we have alt="Blue_ghost" src="/voice/resources/1366864992-blue_ghost.jpg"> or createDisabledForwardingIdListFromJsonPartResponse(String jsonPart) { + public final static List createDisabledForwardingIdListFromJsonPartResponse(String jsonPart) { List disabledForwardingIds = new ArrayList(); try { String[] disNames = JSONObject.getNames(new JSONObject(jsonPart)); @@ -42,7 +42,7 @@ public final static List createDisabledForwardingIdListFro if(jsonPart!=null &! jsonPart.equals("")) { jsonPart = jsonPart.replaceAll(",\"", ",#"); String[] disabledForwardingIdsStrings = jsonPart.split(Pattern.quote(",")); - for (int j = 0; j < disabledForwardingIdsStrings.length; j++) { + for (int j = 0; j < disabledForwardingIdsStrings.length; j++) { try { String gId = ParsingUtil.removeUninterestingParts(disabledForwardingIdsStrings[j], "\"", "\"", false); boolean gState = Boolean.parseBoolean(disabledForwardingIdsStrings[j].substring(disabledForwardingIdsStrings[j].indexOf(":")+1,disabledForwardingIdsStrings[j].indexOf("}"))); @@ -58,7 +58,7 @@ public final static List createDisabledForwardingIdListFro return disabledForwardingIds; */ } - + public final static DisabledForwardingId[] createDisabledForwardingIdArrayFromJsonPartResponse(String jsonPart) { List list = createDisabledForwardingIdListFromJsonPartResponse(jsonPart); DisabledForwardingId[] result = new DisabledForwardingId[list.size()]; @@ -67,20 +67,20 @@ public final static DisabledForwardingId[] createDisabledForwardingIdArrayFromJs } return result; } - - public String toJson(){ + + public String toJson(){ return toJsonObject().toString(); } - + public JSONObject toJsonObject(){ JSONObject resultO = new JSONObject(); - try { + try { resultO.putOpt("id", id); resultO.putOpt("disabled", disabled); } catch (JSONException e) { return null; } - + return resultO; } @@ -116,6 +116,6 @@ public void setId(String id) { public void setDisabled(boolean disabled) { this.disabled = disabled; } - - -} + + +} diff --git a/src/com/techventus/server/voice/datatypes/DisabledId.java b/src/main/java/com/techventus/server/voice/datatypes/DisabledId.java similarity index 92% rename from src/com/techventus/server/voice/datatypes/DisabledId.java rename to src/main/java/com/techventus/server/voice/datatypes/DisabledId.java index 9b3a386..51f377a 100644 --- a/src/com/techventus/server/voice/datatypes/DisabledId.java +++ b/src/main/java/com/techventus/server/voice/datatypes/DisabledId.java @@ -1,5 +1,5 @@ /** - * + * */ package com.techventus.server.voice.datatypes; @@ -19,9 +19,9 @@ public class DisabledId { String id; boolean disabled; - + /** - * + * * @param pId * @param pDisabled */ @@ -29,9 +29,9 @@ public DisabledId(String pId, boolean pDisabled) { id = pId; disabled = pDisabled; } - + /** - * + * * @param jsonObject * @param saveMode * @throws JSONException @@ -40,24 +40,24 @@ public DisabledId(JSONObject jsonObject, boolean saveMode) throws JSONException if(!saveMode || saveMode && jsonObject.has("id")) id = jsonObject.getString("id"); if(!saveMode || saveMode && jsonObject.has("disabled")) disabled = jsonObject.getBoolean("disabled"); } - + public String toString() { String ret="{id="+id+";"; - ret+="disabled="+disabled+"}"; + ret+="disabled="+disabled+"}"; return ret; } - + /** - * + * * @param jsonPart * @return List */ - public final static List createDisabledIdListFromJsonPartResponse(String jsonPart) { + public final static List createDisabledIdListFromJsonPartResponse(String jsonPart) { List disabledIds = new ArrayList(); if(jsonPart!=null &! jsonPart.equals("")) { jsonPart = jsonPart.replaceAll(",\"", ",#"); String[] disabledIdsStrings = jsonPart.split(Pattern.quote(",")); - for (int j = 0; j < disabledIdsStrings.length; j++) { + for (int j = 0; j < disabledIdsStrings.length; j++) { String gId = ParsingUtil.removeUninterestingParts(disabledIdsStrings[j], "\"", "\"", false); boolean gState = Boolean.parseBoolean(disabledIdsStrings[j].substring(disabledIdsStrings[j].indexOf(":")+1)); disabledIds.add(new DisabledId(gId, gState)); @@ -65,14 +65,14 @@ public final static List createDisabledIdListFromJsonPartResponse(St } return disabledIds; } - + /** - * + * * @param disabledIdMapJSON * @return List * @throws JSONException */ - public final static List createListFromJsonObject(JSONObject disabledIdMapJSON) throws JSONException { + public final static List createListFromJsonObject(JSONObject disabledIdMapJSON) throws JSONException { List disabledIds = new ArrayList(); JSONArray disabledNames = disabledIdMapJSON.names(); if(disabledNames!=null) { @@ -83,13 +83,13 @@ public final static List createListFromJsonObject(JSONObject disable } } // if null, then no phones are disabled. return disabledIds; - /* + /* if(settingsJSON.has("disabledIdMap")) { JSONArray lArray; try { lArray = settingsJSON.getJSONArray("disabledIdMap"); // JSONArray objectNames = lArray.names(); - + for (int i = 0; i < lArray.length(); i++) { String lId = lArray.getJSONObject(i).getString(i+""); boolean lDisabled; @@ -105,34 +105,34 @@ public final static List createListFromJsonObject(JSONObject disable } } - + return disabledIds; */ } - + /** - * + * * @param settingsJSON * @return DisabledId[] * @throws JSONException */ //TODO dotn create list first, direct transform - public final static DisabledId[] createArrayFromJsonObject(JSONObject settingsJSON) throws JSONException { + public final static DisabledId[] createArrayFromJsonObject(JSONObject settingsJSON) throws JSONException { List tList = createListFromJsonObject(settingsJSON.getJSONObject("disabledIdMap")); return (DisabledId[]) tList.toArray(new DisabledId[tList.size()]); } - + /** * @return "1":true */ public String toJson() { return "\""+id+"\":"+disabled; } - + public String getId() { return id; } - + public int getIdAsInt() { int ret; try { @@ -142,34 +142,34 @@ public int getIdAsInt() { } return ret; } - + public boolean isDisabled() { return disabled; } - + public JSONObject toJsonObject(){ JSONObject resultO = new JSONObject(); - try { + try { resultO.accumulate(id, disabled); } catch (JSONException e) { return null; } - + return resultO; } - + /** * @param id the id to set */ public void setId(String id) { this.id = id; } - + /** * @param disabled the disabled to set */ public void setDisabled(boolean disabled) { this.disabled = disabled; } - + } diff --git a/src/com/techventus/server/voice/datatypes/EmailAddress.java b/src/main/java/com/techventus/server/voice/datatypes/EmailAddress.java similarity index 91% rename from src/com/techventus/server/voice/datatypes/EmailAddress.java rename to src/main/java/com/techventus/server/voice/datatypes/EmailAddress.java index 170bdb7..9277ccb 100644 --- a/src/com/techventus/server/voice/datatypes/EmailAddress.java +++ b/src/main/java/com/techventus/server/voice/datatypes/EmailAddress.java @@ -1,5 +1,5 @@ /** - * + * */ package com.techventus.server.voice.datatypes; @@ -18,40 +18,40 @@ */ public class EmailAddress { String address; - + /** - * + * * @param pId */ public EmailAddress(String pId) { address = pId; } - + public String toString() { - String ret="{address="+address+"}"; + String ret="{address="+address+"}"; return ret; } - + /** - * + * * @param phonesJSON * @throws JSONException */ public EmailAddress(JSONObject phonesJSON) throws JSONException { if(phonesJSON.has("emailAddresses")) address = phonesJSON.getString("emailAddresses"); } - + /** - * + * * @param jsonPart * @return List */ - public final static List createEmailAddressListFromJsonPartResponse(String jsonPart) { + public final static List createEmailAddressListFromJsonPartResponse(String jsonPart) { List emailAddresses = new ArrayList(); if(jsonPart!=null &! jsonPart.equals("")) { jsonPart = jsonPart.replaceAll(",\"", ",#"); String[] emailAddressesStrings = jsonPart.split(Pattern.quote(",")); - for (int j = 0; j < emailAddressesStrings.length; j++) { + for (int j = 0; j < emailAddressesStrings.length; j++) { String gId = ParsingUtil.removeUninterestingParts(emailAddressesStrings[j], "\"", "\"", false); emailAddresses.add(new EmailAddress(gId)); } @@ -64,11 +64,11 @@ public String toJson() { } /** - * + * * @param settingsJSON * @return EmailAddress[] */ - public final static EmailAddress[] createArrayFromJsonObject(JSONObject settingsJSON) { + public final static EmailAddress[] createArrayFromJsonObject(JSONObject settingsJSON) { JSONArray addresses; EmailAddress[] ret; try { @@ -87,19 +87,19 @@ public final static EmailAddress[] createArrayFromJsonObject(JSONObject settings } return ret; } - + /** * @return the address */ public String getAddress() { return address; } - + /** * @param address the address to set */ public void setAddress(String address) { this.address = address; } - + } diff --git a/src/com/techventus/server/voice/datatypes/Greeting.java b/src/main/java/com/techventus/server/voice/datatypes/Greeting.java similarity index 91% rename from src/com/techventus/server/voice/datatypes/Greeting.java rename to src/main/java/com/techventus/server/voice/datatypes/Greeting.java index 1fc6b65..a42a7c7 100644 --- a/src/com/techventus/server/voice/datatypes/Greeting.java +++ b/src/main/java/com/techventus/server/voice/datatypes/Greeting.java @@ -1,165 +1,165 @@ -package com.techventus.server.voice.datatypes; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import gvjava.org.json.JSONArray; -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import com.techventus.server.voice.util.ParsingUtil; - -/** - * - * TODO Add jobberName - * @author Tobias Eisentraeger - * - */ -public class Greeting implements Comparable { - - - private int id; - private String name; - private String jobberName; - - public Greeting(int id,String name){ - this.id = id; - this.name = name; - this.jobberName = ""; - } - - public Greeting(int id,String jobberName, String name){ - this.id = id; - this.name = name; - this.jobberName = jobberName; - } - - public String toString(){ - String ret="{id="+id+";"; - ret+="name="+name+","; - ret+="jobberName="+jobberName+"}"; - return ret; - } - - - public final static List createGroupSettingsFromJsonResponse(String json) { - List result = new ArrayList(); - json = ParsingUtil.removeUninterestingParts(json, "\"greetings\":[", "],", false); - String[] greetingsStrings = json.split(Pattern.quote("},{")); - // Add System standard greeting - result.add(new Greeting(0, "System Standard")); - for (int i = 1; i < greetingsStrings.length; i++) { - int lId = Integer.parseInt(ParsingUtil.removeUninterestingParts(greetingsStrings[i] , "\"id\":" , ",", false)); - String lName = ParsingUtil.removeUninterestingParts(greetingsStrings[i], "\"name\":\"", "\",\"", false); - Greeting lGreeting = new Greeting(lId, lName); - result.add(lGreeting); - } - return result; - } - - /* -"greetings": [ - { - "id": "0", - "jobberName": "", - "name": "System Standard" - }, - { - "id": 2, - "jobberName": "", - "name": "Testgreeting 1" - }, - { - "id": 3, - "jobberName": "47ee52c084.3.greeting.mulaw", - "name": "Testgreeting 2" - } - ], - */ - public final static List createListFromJsonObject(JSONObject settingsJSON) { - List greetingss = new ArrayList(); - if(settingsJSON.has("greetings")) { - try { - JSONArray lArray = (JSONArray) settingsJSON.getJSONArray("greetings"); - for (int i = 0; i < lArray.length(); i++) { - int lId = lArray.getJSONObject(i).getInt("id"); - String lJobberName = lArray.getJSONObject(i).getString("jobberName"); - String lName = lArray.getJSONObject(i).getString("name"); - greetingss.add(new Greeting(lId,lJobberName,lName)); - } - } catch (JSONException e1) { - // Nothing - will return empty List at exception - } - - } - - return greetingss; - } - - /** - * @return the id - */ - public int getId() { - return id; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the jobberName - */ - public String getJobberName() { - return jobberName; - } - - - /** - * @param id the id to set - */ - public void setId(int id) { - this.id = id; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @param jobberName the jobberName to set - */ - public void setJobberName(String jobberName) { - this.jobberName = jobberName; - } - - //TODO dotn create list first, direct transform - public final static Greeting[] createArrayFromJsonObject(JSONObject settingsJSON) { - List tList = createListFromJsonObject(settingsJSON); - return (Greeting[]) tList.toArray(new Greeting[tList.size()]); - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(Greeting o) { - if( id < (o.getId() )) - return -1; - if( id > (o.getId() )) - return 1; - - return 0; - } - - - - -} +package com.techventus.server.voice.datatypes; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +import gvjava.org.json.JSONArray; +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import com.techventus.server.voice.util.ParsingUtil; + +/** + * + * TODO Add jobberName + * @author Tobias Eisentraeger + * + */ +public class Greeting implements Comparable { + + + private int id; + private String name; + private String jobberName; + + public Greeting(int id,String name){ + this.id = id; + this.name = name; + this.jobberName = ""; + } + + public Greeting(int id,String jobberName, String name){ + this.id = id; + this.name = name; + this.jobberName = jobberName; + } + + public String toString(){ + String ret="{id="+id+";"; + ret+="name="+name+","; + ret+="jobberName="+jobberName+"}"; + return ret; + } + + + public final static List createGroupSettingsFromJsonResponse(String json) { + List result = new ArrayList(); + json = ParsingUtil.removeUninterestingParts(json, "\"greetings\":[", "],", false); + String[] greetingsStrings = json.split(Pattern.quote("},{")); + // Add System standard greeting + result.add(new Greeting(0, "System Standard")); + for (int i = 1; i < greetingsStrings.length; i++) { + int lId = Integer.parseInt(ParsingUtil.removeUninterestingParts(greetingsStrings[i] , "\"id\":" , ",", false)); + String lName = ParsingUtil.removeUninterestingParts(greetingsStrings[i], "\"name\":\"", "\",\"", false); + Greeting lGreeting = new Greeting(lId, lName); + result.add(lGreeting); + } + return result; + } + + /* +"greetings": [ + { + "id": "0", + "jobberName": "", + "name": "System Standard" + }, + { + "id": 2, + "jobberName": "", + "name": "Testgreeting 1" + }, + { + "id": 3, + "jobberName": "47ee52c084.3.greeting.mulaw", + "name": "Testgreeting 2" + } + ], + */ + public final static List createListFromJsonObject(JSONObject settingsJSON) { + List greetingss = new ArrayList(); + if(settingsJSON.has("greetings")) { + try { + JSONArray lArray = (JSONArray) settingsJSON.getJSONArray("greetings"); + for (int i = 0; i < lArray.length(); i++) { + int lId = lArray.getJSONObject(i).getInt("id"); + String lJobberName = lArray.getJSONObject(i).getString("jobberName"); + String lName = lArray.getJSONObject(i).getString("name"); + greetingss.add(new Greeting(lId,lJobberName,lName)); + } + } catch (JSONException e1) { + // Nothing - will return empty List at exception + } + + } + + return greetingss; + } + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the jobberName + */ + public String getJobberName() { + return jobberName; + } + + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @param jobberName the jobberName to set + */ + public void setJobberName(String jobberName) { + this.jobberName = jobberName; + } + + //TODO dotn create list first, direct transform + public final static Greeting[] createArrayFromJsonObject(JSONObject settingsJSON) { + List tList = createListFromJsonObject(settingsJSON); + return (Greeting[]) tList.toArray(new Greeting[tList.size()]); + } + + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(Greeting o) { + if( id < (o.getId() )) + return -1; + if( id > (o.getId() )) + return 1; + + return 0; + } + + + + +} diff --git a/src/com/techventus/server/voice/datatypes/Group.java b/src/main/java/com/techventus/server/voice/datatypes/Group.java similarity index 88% rename from src/com/techventus/server/voice/datatypes/Group.java rename to src/main/java/com/techventus/server/voice/datatypes/Group.java index e413c8e..cada1f4 100644 --- a/src/com/techventus/server/voice/datatypes/Group.java +++ b/src/main/java/com/techventus/server/voice/datatypes/Group.java @@ -1,381 +1,381 @@ -package com.techventus.server.voice.datatypes; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Pattern; - -import gvjava.org.json.JSONArray; -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import com.techventus.server.voice.util.ParsingUtil; - -/** - * - * - * @author Tobias Eisentraeger - * - */ -public class Group { - - private boolean saveMode = true; - private String id; - private String name; - private boolean isCustomForwarding; - private List disabledForwardingIds; - private DisabledForwardingId[] disabledForwardingIdsNeu; - private boolean isCustomDirectConnect; - private boolean directConnect; - private boolean isCustomGreeting; - private int greetingId; - - public Group(String id, String name, boolean isCustomForwarding, - List disabledForwardingIds, - boolean isCustomDirectConnect, boolean directConnect, - boolean isCustomGreeting, int greetingId) { - super(); - this.id = id; - this.name = name; - this.isCustomForwarding = isCustomForwarding; - this.disabledForwardingIds = disabledForwardingIds; - this.isCustomDirectConnect = isCustomDirectConnect; - this.directConnect = directConnect; - this.isCustomGreeting = isCustomGreeting; - this.greetingId = greetingId; - } - - public Group(String id, String name, boolean isCustomForwarding, - DisabledForwardingId[] disabledForwardingIdsNeu, - boolean isCustomDirectConnect, boolean directConnect, - boolean isCustomGreeting, int greetingId) { - super(); - this.id = id; - this.name = name; - this.isCustomForwarding = isCustomForwarding; - this.disabledForwardingIdsNeu = disabledForwardingIdsNeu; - this.isCustomDirectConnect = isCustomDirectConnect; - this.directConnect = directConnect; - this.isCustomGreeting = isCustomGreeting; - this.greetingId = greetingId; - } - - /** - * @param jsonObject - * @throws JSONException - */ - public Group(JSONObject jsonObject) throws JSONException { - if(!saveMode || saveMode && jsonObject.has("id")) id = jsonObject.getString("id"); - if(!saveMode || saveMode && jsonObject.has("name")) name = jsonObject.getString("name"); - if(!saveMode || saveMode && jsonObject.has("isCustomForwarding")) isCustomForwarding = jsonObject.getBoolean("isCustomForwarding"); - if(!saveMode || saveMode && jsonObject.has("isCustomGreeting")) isCustomGreeting = jsonObject.getBoolean("isCustomGreeting"); - if(!saveMode || saveMode && jsonObject.has("isCustomDirectConnect")) isCustomDirectConnect = jsonObject.getBoolean("isCustomDirectConnect"); - if(!saveMode || saveMode && jsonObject.has("directConnect")) directConnect = jsonObject.getBoolean("directConnect"); - if(!saveMode || saveMode && jsonObject.has("greetingId")) greetingId = jsonObject.getInt("greetingId"); - if(!saveMode || saveMode && jsonObject.has("disabledForwardingIds")) { - JSONObject disabledForwardingIdsObject = jsonObject.getJSONObject("disabledForwardingIds"); - disabledForwardingIds = DisabledForwardingId.createDisabledForwardingIdListFromJsonPartResponse(disabledForwardingIdsObject.toString()); - } - } - - /** - * Constructs an Object from the json Resonse - * @param json - */ - public final static List createGroupSettingsFromJsonResponse(String json) { - List result = new ArrayList(); - - json = ParsingUtil.removeUninterestingParts(json, "\"groups\":{", ",\"groupList\"", false); - json = json.replaceAll("\\},\"isCustomForwarding\"", "!,\"isCustomForwarding\""); - - String[] groupsStrings = json.split(Pattern.quote("},")); - - for (int i = 0; i < groupsStrings.length; i++) { - String id = ParsingUtil.removeUninterestingParts(groupsStrings[i] , "\"id\":\"" , "\"", false); - String name = ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"name\":\"", "\",\"", false); - boolean isCustomForwarding = Boolean.parseBoolean(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"isCustomForwarding\":", ",", false)); - boolean isCustomGreeting = Boolean.parseBoolean(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"isCustomGreeting\":", ",", false)); - boolean isCustomDirectConnect = Boolean.parseBoolean(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"isCustomDirectConnect\":", ",", false)); - boolean directConnect = Boolean.parseBoolean(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"directConnect\":", ",", false)); - int greetingId = Integer.parseInt(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"greetingId\":", ",", false)); - String disabledForwardingIdsStr = ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"disabledForwardingIds\":{", "!,\"", false); - - List disabledForwardingIds = new ArrayList(); - if(disabledForwardingIdsStr!=null &! disabledForwardingIdsStr.equals("")) { - disabledForwardingIds = DisabledForwardingId.createDisabledForwardingIdListFromJsonPartResponse(disabledForwardingIdsStr); - } - - result.add(new Group(id, name, isCustomForwarding, disabledForwardingIds, isCustomDirectConnect, directConnect, isCustomGreeting, greetingId)); - } - - return result; - - } - - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString(){ - String ret="{id="+id+";"; - ret+="name="+name+";"; - ret+="isCustomDirectConnect="+isCustomDirectConnect+";"; - ret+="directConnect="+directConnect+";"; - ret+="isCustomGreeting="+isCustomGreeting+";"; - ret+="isCustomForwarding="+isCustomForwarding+";"; - ret+="greetingId="+greetingId+";"; - ret+="disabledForwardingIds="+disabledForwardingIds+"}"; - return ret; - } - public String toJson(){ - return toJsonObject().toString(); - } - - public JSONObject toJsonObject(){ - JSONObject resultO = new JSONObject(); - try { - resultO.putOpt("id", id); - resultO.putOpt("name", name); - resultO.putOpt("isCustomForwarding", isCustomForwarding); - resultO.accumulate("disabledForwardingIds", DisabledForwardingId.arrayToJsonObject(disabledForwardingIds)); - resultO.putOpt("isCustomDirectConnect", isCustomDirectConnect); - resultO.putOpt("directConnect", directConnect); - resultO.putOpt("greetingId", greetingId); - resultO.putOpt("isCustomGreeting", isCustomGreeting); - } catch (JSONException e) { - return null; - } - - return resultO; - } - /* - public String toJson(){ - String ret = "\""+id+"\":{"; - ret+="\"id\":\""+id+"\","; - ret+="\"name\":\""+name+"\","; - ret+="\"disabledForwardingIds\":{"; - for (Iterator iterator = disabledForwardingIds.iterator(); iterator.hasNext();) { - DisabledForwardingId element = (DisabledForwardingId) iterator.next(); - ret+=element.toJson(); - if(iterator.hasNext()) { - ret+=","; - } - } - ret+="},"; - ret+="\"isCustomForwarding\":"+isCustomForwarding+","; - ret+="\"isCustomGreeting\":"+isCustomGreeting+","; - ret+="\"isCustomDirectConnect\":"+isCustomDirectConnect+","; - ret+="\"directConnect\":"+directConnect+","; - ret+="\"greetingId\":"+greetingId+"}"; - return ret; - } - */ - /** - * Creates a complete json of a list of Group - * "groups":{"15":{..details of group id 15..},"12":{..details of group id 12..}} - * - * @param pGroupSettings the group settings - * @return the JSON string - */ - public static String listToJson(List pGroupSettings) { - String ret = "\"groups\":{"; - for (Iterator iterator = pGroupSettings.iterator(); iterator.hasNext();) { - Group setting = (Group) iterator.next(); - String id = ParsingUtil.removeUninterestingParts(setting.toString(), "{id=", ";name", false); - ret+= "\"" + id + "\":" + setting.toJson(); - if(iterator.hasNext()) { - ret+=","; - } - } - ret+="}"; - return ret; - } - - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the isCustomForwarding - Call Presentation - */ - public boolean isCustomForwarding() { - return isCustomForwarding; - } - - /** - * @return the disabledForwardingIds - */ - public List getDisabledForwardingIds() { - return disabledForwardingIds; - } - - /** - * @return the isCustomDirectConnect - */ - public boolean isCustomDirectConnect() { - return isCustomDirectConnect; - } - - /** - * @return the directConnect - */ - public boolean isDirectConnect() { - return directConnect; - } - - /** - * @return the isCustomGreeting - */ - public boolean isCustomGreeting() { - return isCustomGreeting; - } - - - - /** - * @return the greetingId - */ - public int getGreetingId() { - return greetingId; - } - - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @param isCustomForwarding the isCustomForwarding to set - */ - public void setCustomForwarding(boolean isCustomForwarding) { - this.isCustomForwarding = isCustomForwarding; - } - - /** - * @param disabledForwardingIds the disabledForwardingIds to set - */ - public void setDisabledForwardingIds( - List disabledForwardingIds) { - this.disabledForwardingIds = disabledForwardingIds; - } - - /** - * @param isCustomDirectConnect the isCustomDirectConnect to set - */ - public void setCustomDirectConnect(boolean isCustomDirectConnect) { - this.isCustomDirectConnect = isCustomDirectConnect; - } - - /** - * @param directConnect the directConnect to set - */ - public void setDirectConnect(boolean directConnect) { - this.directConnect = directConnect; - } - - /** - * @param isCustomGreeting the isCustomGreeting to set - */ - public void setCustomGreeting(boolean isCustomGreeting) { - this.isCustomGreeting = isCustomGreeting; - } - - /** - * @param greetingId the greetingId to set - */ - public void setGreetingId(int greetingId) { - this.greetingId = greetingId; - } - - - //TODO dotn create list first, direct transform - public final static Group[] createArrayFromJsonObject(JSONObject groupsJSON) throws JSONException { - JSONArray groupNames = groupsJSON.names(); - Group[] result = new Group[groupsJSON.length()]; - for (int i = 0; i < groupNames.length(); i++) { - result[i] = new Group(groupsJSON.getJSONObject(groupNames.getString(i))); - } - return result; - } - - public final static JSONObject[] createJSONObjectArrayFromJsonObject(JSONObject settingsJSON) throws JSONException { - Group[] lGroupsArray = Group.createArrayFromJsonObject(settingsJSON); - JSONObject[] result = new JSONObject[lGroupsArray.length]; - for (int i = 0; i < lGroupsArray.length; i++) { - result[i] = new JSONObject(); - result[i].put(lGroupsArray[i].getId(), lGroupsArray[i]); - } - return result; - } - - public final static JSONObject createJSONObjectFromJsonObject(JSONObject settingsJSON) throws JSONException { - Group[] lGroupsArray = Group.createArrayFromJsonObject(settingsJSON); - JSONObject result = new JSONObject(); - for (int i = 0; i < lGroupsArray.length; i++) { - result = new JSONObject(); - result.put(lGroupsArray[i].getId(), lGroupsArray[i]); - } - return result; - } - - /** - * Groups array to json object. - * - * @param groups the groups - * @return the object - * @throws JSONException the jSON exception - */ - public static Object groupsArrayToJsonObject(Group[] groups) throws JSONException { - JSONObject groupO = new JSONObject(); - for (int i = 0; i < groups.length; i++) { - groupO.put(groups[i].getId()+"",groups[i].toJsonObject()); - } - return groupO; - } - - /** - * Query disabled status - if id not found, then it returns false, which means enabled. - * - * @param phoneId the phone id - * @return true, if is phone disabled - */ - public boolean isPhoneDisabled(int phoneId) { - boolean ret = false; - try { - if(disabledForwardingIds!=null) { - for (int i = 0; i < disabledForwardingIds.size(); i++) { - if(disabledForwardingIds.get(i).getId().equals(phoneId+"")) { - ret = true; - } - } - } else { - // list is null, so we return false - ret = false; - } - } catch (NullPointerException e) { - ret = false; - } - return ret; - } - -} +package com.techventus.server.voice.datatypes; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Pattern; + +import gvjava.org.json.JSONArray; +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import com.techventus.server.voice.util.ParsingUtil; + +/** + * + * + * @author Tobias Eisentraeger + * + */ +public class Group { + + private boolean saveMode = true; + private String id; + private String name; + private boolean isCustomForwarding; + private List disabledForwardingIds; + private DisabledForwardingId[] disabledForwardingIdsNeu; + private boolean isCustomDirectConnect; + private boolean directConnect; + private boolean isCustomGreeting; + private int greetingId; + + public Group(String id, String name, boolean isCustomForwarding, + List disabledForwardingIds, + boolean isCustomDirectConnect, boolean directConnect, + boolean isCustomGreeting, int greetingId) { + super(); + this.id = id; + this.name = name; + this.isCustomForwarding = isCustomForwarding; + this.disabledForwardingIds = disabledForwardingIds; + this.isCustomDirectConnect = isCustomDirectConnect; + this.directConnect = directConnect; + this.isCustomGreeting = isCustomGreeting; + this.greetingId = greetingId; + } + + public Group(String id, String name, boolean isCustomForwarding, + DisabledForwardingId[] disabledForwardingIdsNeu, + boolean isCustomDirectConnect, boolean directConnect, + boolean isCustomGreeting, int greetingId) { + super(); + this.id = id; + this.name = name; + this.isCustomForwarding = isCustomForwarding; + this.disabledForwardingIdsNeu = disabledForwardingIdsNeu; + this.isCustomDirectConnect = isCustomDirectConnect; + this.directConnect = directConnect; + this.isCustomGreeting = isCustomGreeting; + this.greetingId = greetingId; + } + + /** + * @param jsonObject + * @throws JSONException + */ + public Group(JSONObject jsonObject) throws JSONException { + if(!saveMode || saveMode && jsonObject.has("id")) id = jsonObject.getString("id"); + if(!saveMode || saveMode && jsonObject.has("name")) name = jsonObject.getString("name"); + if(!saveMode || saveMode && jsonObject.has("isCustomForwarding")) isCustomForwarding = jsonObject.getBoolean("isCustomForwarding"); + if(!saveMode || saveMode && jsonObject.has("isCustomGreeting")) isCustomGreeting = jsonObject.getBoolean("isCustomGreeting"); + if(!saveMode || saveMode && jsonObject.has("isCustomDirectConnect")) isCustomDirectConnect = jsonObject.getBoolean("isCustomDirectConnect"); + if(!saveMode || saveMode && jsonObject.has("directConnect")) directConnect = jsonObject.getBoolean("directConnect"); + if(!saveMode || saveMode && jsonObject.has("greetingId")) greetingId = jsonObject.getInt("greetingId"); + if(!saveMode || saveMode && jsonObject.has("disabledForwardingIds")) { + JSONObject disabledForwardingIdsObject = jsonObject.getJSONObject("disabledForwardingIds"); + disabledForwardingIds = DisabledForwardingId.createDisabledForwardingIdListFromJsonPartResponse(disabledForwardingIdsObject.toString()); + } + } + + /** + * Constructs an Object from the json Resonse + * @param json + */ + public final static List createGroupSettingsFromJsonResponse(String json) { + List result = new ArrayList(); + + json = ParsingUtil.removeUninterestingParts(json, "\"groups\":{", ",\"groupList\"", false); + json = json.replaceAll("\\},\"isCustomForwarding\"", "!,\"isCustomForwarding\""); + + String[] groupsStrings = json.split(Pattern.quote("},")); + + for (int i = 0; i < groupsStrings.length; i++) { + String id = ParsingUtil.removeUninterestingParts(groupsStrings[i] , "\"id\":\"" , "\"", false); + String name = ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"name\":\"", "\",\"", false); + boolean isCustomForwarding = Boolean.parseBoolean(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"isCustomForwarding\":", ",", false)); + boolean isCustomGreeting = Boolean.parseBoolean(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"isCustomGreeting\":", ",", false)); + boolean isCustomDirectConnect = Boolean.parseBoolean(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"isCustomDirectConnect\":", ",", false)); + boolean directConnect = Boolean.parseBoolean(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"directConnect\":", ",", false)); + int greetingId = Integer.parseInt(ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"greetingId\":", ",", false)); + String disabledForwardingIdsStr = ParsingUtil.removeUninterestingParts(groupsStrings[i], "\"disabledForwardingIds\":{", "!,\"", false); + + List disabledForwardingIds = new ArrayList(); + if(disabledForwardingIdsStr!=null &! disabledForwardingIdsStr.equals("")) { + disabledForwardingIds = DisabledForwardingId.createDisabledForwardingIdListFromJsonPartResponse(disabledForwardingIdsStr); + } + + result.add(new Group(id, name, isCustomForwarding, disabledForwardingIds, isCustomDirectConnect, directConnect, isCustomGreeting, greetingId)); + } + + return result; + + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString(){ + String ret="{id="+id+";"; + ret+="name="+name+";"; + ret+="isCustomDirectConnect="+isCustomDirectConnect+";"; + ret+="directConnect="+directConnect+";"; + ret+="isCustomGreeting="+isCustomGreeting+";"; + ret+="isCustomForwarding="+isCustomForwarding+";"; + ret+="greetingId="+greetingId+";"; + ret+="disabledForwardingIds="+disabledForwardingIds+"}"; + return ret; + } + public String toJson(){ + return toJsonObject().toString(); + } + + public JSONObject toJsonObject(){ + JSONObject resultO = new JSONObject(); + try { + resultO.putOpt("id", id); + resultO.putOpt("name", name); + resultO.putOpt("isCustomForwarding", isCustomForwarding); + resultO.accumulate("disabledForwardingIds", DisabledForwardingId.arrayToJsonObject(disabledForwardingIds)); + resultO.putOpt("isCustomDirectConnect", isCustomDirectConnect); + resultO.putOpt("directConnect", directConnect); + resultO.putOpt("greetingId", greetingId); + resultO.putOpt("isCustomGreeting", isCustomGreeting); + } catch (JSONException e) { + return null; + } + + return resultO; + } + /* + public String toJson(){ + String ret = "\""+id+"\":{"; + ret+="\"id\":\""+id+"\","; + ret+="\"name\":\""+name+"\","; + ret+="\"disabledForwardingIds\":{"; + for (Iterator iterator = disabledForwardingIds.iterator(); iterator.hasNext();) { + DisabledForwardingId element = (DisabledForwardingId) iterator.next(); + ret+=element.toJson(); + if(iterator.hasNext()) { + ret+=","; + } + } + ret+="},"; + ret+="\"isCustomForwarding\":"+isCustomForwarding+","; + ret+="\"isCustomGreeting\":"+isCustomGreeting+","; + ret+="\"isCustomDirectConnect\":"+isCustomDirectConnect+","; + ret+="\"directConnect\":"+directConnect+","; + ret+="\"greetingId\":"+greetingId+"}"; + return ret; + } + */ + /** + * Creates a complete json of a list of Group + * "groups":{"15":{..details of group id 15..},"12":{..details of group id 12..}} + * + * @param pGroupSettings the group settings + * @return the JSON string + */ + public static String listToJson(List pGroupSettings) { + String ret = "\"groups\":{"; + for (Iterator iterator = pGroupSettings.iterator(); iterator.hasNext();) { + Group setting = (Group) iterator.next(); + String id = ParsingUtil.removeUninterestingParts(setting.toString(), "{id=", ";name", false); + ret+= "\"" + id + "\":" + setting.toJson(); + if(iterator.hasNext()) { + ret+=","; + } + } + ret+="}"; + return ret; + } + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the isCustomForwarding - Call Presentation + */ + public boolean isCustomForwarding() { + return isCustomForwarding; + } + + /** + * @return the disabledForwardingIds + */ + public List getDisabledForwardingIds() { + return disabledForwardingIds; + } + + /** + * @return the isCustomDirectConnect + */ + public boolean isCustomDirectConnect() { + return isCustomDirectConnect; + } + + /** + * @return the directConnect + */ + public boolean isDirectConnect() { + return directConnect; + } + + /** + * @return the isCustomGreeting + */ + public boolean isCustomGreeting() { + return isCustomGreeting; + } + + + + /** + * @return the greetingId + */ + public int getGreetingId() { + return greetingId; + } + + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @param isCustomForwarding the isCustomForwarding to set + */ + public void setCustomForwarding(boolean isCustomForwarding) { + this.isCustomForwarding = isCustomForwarding; + } + + /** + * @param disabledForwardingIds the disabledForwardingIds to set + */ + public void setDisabledForwardingIds( + List disabledForwardingIds) { + this.disabledForwardingIds = disabledForwardingIds; + } + + /** + * @param isCustomDirectConnect the isCustomDirectConnect to set + */ + public void setCustomDirectConnect(boolean isCustomDirectConnect) { + this.isCustomDirectConnect = isCustomDirectConnect; + } + + /** + * @param directConnect the directConnect to set + */ + public void setDirectConnect(boolean directConnect) { + this.directConnect = directConnect; + } + + /** + * @param isCustomGreeting the isCustomGreeting to set + */ + public void setCustomGreeting(boolean isCustomGreeting) { + this.isCustomGreeting = isCustomGreeting; + } + + /** + * @param greetingId the greetingId to set + */ + public void setGreetingId(int greetingId) { + this.greetingId = greetingId; + } + + + //TODO dotn create list first, direct transform + public final static Group[] createArrayFromJsonObject(JSONObject groupsJSON) throws JSONException { + JSONArray groupNames = groupsJSON.names(); + Group[] result = new Group[groupsJSON.length()]; + for (int i = 0; i < groupNames.length(); i++) { + result[i] = new Group(groupsJSON.getJSONObject(groupNames.getString(i))); + } + return result; + } + + public final static JSONObject[] createJSONObjectArrayFromJsonObject(JSONObject settingsJSON) throws JSONException { + Group[] lGroupsArray = Group.createArrayFromJsonObject(settingsJSON); + JSONObject[] result = new JSONObject[lGroupsArray.length]; + for (int i = 0; i < lGroupsArray.length; i++) { + result[i] = new JSONObject(); + result[i].put(lGroupsArray[i].getId(), lGroupsArray[i]); + } + return result; + } + + public final static JSONObject createJSONObjectFromJsonObject(JSONObject settingsJSON) throws JSONException { + Group[] lGroupsArray = Group.createArrayFromJsonObject(settingsJSON); + JSONObject result = new JSONObject(); + for (int i = 0; i < lGroupsArray.length; i++) { + result = new JSONObject(); + result.put(lGroupsArray[i].getId(), lGroupsArray[i]); + } + return result; + } + + /** + * Groups array to json object. + * + * @param groups the groups + * @return the object + * @throws JSONException the jSON exception + */ + public static Object groupsArrayToJsonObject(Group[] groups) throws JSONException { + JSONObject groupO = new JSONObject(); + for (int i = 0; i < groups.length; i++) { + groupO.put(groups[i].getId()+"",groups[i].toJsonObject()); + } + return groupO; + } + + /** + * Query disabled status - if id not found, then it returns false, which means enabled. + * + * @param phoneId the phone id + * @return true, if is phone disabled + */ + public boolean isPhoneDisabled(int phoneId) { + boolean ret = false; + try { + if(disabledForwardingIds!=null) { + for (int i = 0; i < disabledForwardingIds.size(); i++) { + if(disabledForwardingIds.get(i).getId().equals(phoneId+"")) { + ret = true; + } + } + } else { + // list is null, so we return false + ret = false; + } + } catch (NullPointerException e) { + ret = false; + } + return ret; + } + +} diff --git a/src/com/techventus/server/voice/datatypes/Phone.java b/src/main/java/com/techventus/server/voice/datatypes/Phone.java similarity index 60% rename from src/com/techventus/server/voice/datatypes/Phone.java rename to src/main/java/com/techventus/server/voice/datatypes/Phone.java index a7ee7c0..bfd661d 100644 --- a/src/com/techventus/server/voice/datatypes/Phone.java +++ b/src/main/java/com/techventus/server/voice/datatypes/Phone.java @@ -1,559 +1,559 @@ - -package com.techventus.server.voice.datatypes; - -import gvjava.org.json.JSONArray; -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import com.techventus.server.voice.util.ParsingUtil; - -public class Phone implements Comparable{ - //TODO - implement - - private boolean saveMode; - - private boolean active; - private int behaviorOnRedirect; - private String carrier; - private int customOverrideState; - private boolean dEPRECATEDDisabled; - private boolean enabledForOthers; - private String formattedNumber; - private int id; - private String incomingAccessNumber; - private String name; - private String phoneNumber; - private int policyBitmask; - private boolean redirectToVoicemail; - private boolean scheduleSet; - private boolean smsEnabled; - private boolean telephonyVerified; - private int type; - private boolean verified; - private boolean voicemailForwardingVerified; - private Wd wd; //TODO - private We we; //TODO - private boolean weekdayAllDay; - private String[] weekdayTimes; - private boolean weekendAllDay; - private String[] weekendTimes; - - public Phone(int id, String name, String phoneNumber) { - this.id = id; - this.name = name; - this.phoneNumber = phoneNumber; - } - - /** - * - * saveMode is off - * - * @param phonesJSON - * - */ - public Phone(JSONObject phonesJSON) throws JSONException { - this(phonesJSON, false); - } - - /** - * Instantiates a new Phone Object. - * - * @param phonesJSON the JSON representation of the Phone object - * @param pSaveMode the Save Mode boolean - * @throws JSONException the JSONException - */ - public Phone(JSONObject phonesJSON, boolean pSaveMode) throws JSONException { - if(!saveMode || (saveMode && phonesJSON.has("id")) ) id = phonesJSON.getInt("id"); - if(!saveMode || (saveMode && phonesJSON.has("name")) ) name = phonesJSON.getString("name"); - if(!saveMode || (saveMode && phonesJSON.has("phoneNumber")) ) phoneNumber = phonesJSON.getString("phoneNumber"); - if(!saveMode || (saveMode && phonesJSON.has("active")) ) active = phonesJSON.getBoolean("active"); - if(!saveMode || (saveMode && phonesJSON.has("behaviorOnRedirect")) ) behaviorOnRedirect = phonesJSON.getInt("behaviorOnRedirect"); - if(!saveMode || (saveMode && phonesJSON.has("carrier")) ) carrier = phonesJSON.getString("carrier"); - if(!saveMode || (saveMode && phonesJSON.has("customOverrideState")) ) customOverrideState = phonesJSON.getInt("customOverrideState"); - if(!saveMode || (saveMode && phonesJSON.has("dEPRECATEDDisabled")) ) dEPRECATEDDisabled = phonesJSON.getBoolean("dEPRECATEDDisabled"); - if(!saveMode || (saveMode && phonesJSON.has("enabledForOthers")) ) enabledForOthers = phonesJSON.getBoolean("enabledForOthers"); - if(!saveMode || (saveMode && phonesJSON.has("formattedNumber")) ) formattedNumber = phonesJSON.getString("formattedNumber"); - if(!saveMode || (saveMode && phonesJSON.has("incomingAccessNumber")) ) incomingAccessNumber = phonesJSON.getString("incomingAccessNumber"); - if(!saveMode || (saveMode && phonesJSON.has("phoneNumber")) ) phoneNumber = phonesJSON.getString("phoneNumber"); - if(!saveMode || (saveMode && phonesJSON.has("policyBitmask")) ) policyBitmask = phonesJSON.getInt("policyBitmask"); - if(!saveMode || (saveMode && phonesJSON.has("redirectToVoicemail")) ) redirectToVoicemail = phonesJSON.getBoolean("redirectToVoicemail"); - if(!saveMode || (saveMode && phonesJSON.has("scheduleSet")) ) { - try { - // if not set, this value is "false", but if active it's 1 !! - this is not true... maybe - scheduleSet = phonesJSON.getBoolean("scheduleSet"); - } catch (JSONException jsE) { -// int positive = phonesJSON.getInt("scheduleSet"); -// if(positive==1) scheduleSet = true; - // we will just set false on error - scheduleSet = false; - } - } - if(!saveMode || (saveMode && phonesJSON.has("smsEnabled")) ) smsEnabled = phonesJSON.getBoolean("smsEnabled"); - if(!saveMode || (saveMode && phonesJSON.has("telephonyVerified")) ) telephonyVerified = phonesJSON.getBoolean("telephonyVerified"); - if(!saveMode || (saveMode && phonesJSON.has("type")) ) type = phonesJSON.getInt("type"); - if(!saveMode || (saveMode && phonesJSON.has("verified")) ) verified = phonesJSON.getBoolean("verified"); - if(!saveMode || (saveMode && phonesJSON.has("voicemailForwardingVerified")) ) voicemailForwardingVerified = phonesJSON.getBoolean("voicemailForwardingVerified"); -// if(!saveMode || (saveMode && phonesJSON.has("wd")) ) wd = phonesJSON.getInt("id"); //TODO -// if(!saveMode || (saveMode && phonesJSON.has("we")) ) wd = phonesJSON.getInt("id"); //TODO - if(!saveMode || (saveMode && phonesJSON.has("weekdayAllDay")) ) weekdayAllDay = phonesJSON.getBoolean("weekdayAllDay"); - if(!saveMode || (saveMode && phonesJSON.has("weekdayTimes")) ) weekdayTimes = ParsingUtil.jsonStringArrayToStringArray(phonesJSON.getJSONArray("weekdayTimes"));//Type correct?? - if(!saveMode || (saveMode && phonesJSON.has("weekendAllDay")) ) weekendAllDay = phonesJSON.getBoolean("weekendAllDay"); - if(!saveMode || (saveMode && phonesJSON.has("weekendTimes")) ) weekendTimes = ParsingUtil.jsonStringArrayToStringArray(phonesJSON.getJSONArray("weekendTimes"));//Type correct?? - } - - public static final Phone[] createArrayFromJsonObject(JSONObject phonesJSON) throws JSONException { - JSONArray phoneNames = phonesJSON.names(); - Phone[] result = new Phone[phoneNames.length()]; - for (int i = 0; i < phoneNames.length(); i++) { - result[i] = new Phone(phonesJSON.getJSONObject(phoneNames.getString(i))); - } - return result; - } - - /** - * Make a JSON text of the Settings. For compactness, no whitespace - * is added. If this would not result in a syntactically correct JSON text, - * then null will be returned instead. - *

- * Warning: This method assumes that the data structure is acyclical. - * - * @return a printable, displayable, portable, transmittable - * representation of the object, beginning - * with { (left brace) and ending - * with } (right brace). - */ - public String toJson(){ - return toJsonObject().toString(); - } - - public JSONObject toJsonObject(){ - JSONObject resultO = new JSONObject(); - try { - resultO.putOpt("id", id); - resultO.putOpt("name", name); - resultO.putOpt("active", active); - resultO.putOpt("behaviorOnRedirect", behaviorOnRedirect); - resultO.putOpt("carrier", carrier); - resultO.putOpt("customOverrideState", customOverrideState); - resultO.putOpt("dEPRECATEDDisabled", dEPRECATEDDisabled); - resultO.putOpt("enabledForOthers", enabledForOthers); - resultO.putOpt("formattedNumber", formattedNumber); - resultO.putOpt("id", id); - resultO.putOpt("incomingAccessNumber", incomingAccessNumber); - resultO.putOpt("name", name); - resultO.putOpt("phoneNumber", phoneNumber); - resultO.putOpt("policyBitmask", policyBitmask); - resultO.putOpt("redirectToVoicemail", redirectToVoicemail); - //Google json expects false or 1 - not anymore -// if(scheduleSet) { -// resultO.putOpt("scheduleSet", 1); -// } else { -// resultO.putOpt("scheduleSet", false); -// } - resultO.putOpt("scheduleSet", scheduleSet); - resultO.putOpt("smsEnabled", smsEnabled); - resultO.putOpt("telephonyVerified", telephonyVerified); - resultO.putOpt("type", type); - resultO.putOpt("verified", verified); - resultO.putOpt("voicemailForwardingVerified", voicemailForwardingVerified); -// private Wd wd", ); //TODO -// private We we", ); //TODO - resultO.putOpt("weekdayAllDay", weekdayAllDay); - resultO.putOpt("weekdayTimes", weekdayTimes);//Type correct?? - resultO.putOpt("weekendAllDay", weekendAllDay); - resultO.putOpt("weekendTimes", weekendTimes);//Type correct?? - } catch (JSONException e) { - return null; - } - - return resultO; - } - - /** - * @param phones - * @return Json Object - * @throws JSONException - */ - public static Object phonesArrayToJsonObject(Phone[] phones) throws JSONException { - JSONObject phoneO = new JSONObject(); - for (int i = 0; i < phones.length; i++) { - phoneO.accumulate(phones[i].getId()+"",phones[i].toJsonObject()); - } - return phoneO; - } - - /** - * @return the active - */ - public boolean isActive() { - return active; - } - - /** - * @return the behaviorOnRedirect - */ - public int getBehaviorOnRedirect() { - return behaviorOnRedirect; - } - - /** - * @return the carrier - */ - public String getCarrier() { - return carrier; - } - - /** - * @return the customOverrideState - */ - public int getCustomOverrideState() { - return customOverrideState; - } - - /** - * @return the dEPRECATEDDisabled - */ - public boolean isdEPRECATEDDisabled() { - return dEPRECATEDDisabled; - } - - /** - * @return the enabledForOthers - */ - public boolean isEnabledForOthers() { - return enabledForOthers; - } - - /** - * @return the formattedNumber - */ - public String getFormattedNumber() { - return formattedNumber; - } - - /** - * @return the id - */ - public int getId() { - return id; - } - - /** - * returns the value for smsEnabled for this phone - * @return - */ - public boolean getSmsEnabled() { - return smsEnabled; - } - - /** - * @return the incomingAccessNumber - */ - public String getIncomingAccessNumber() { - return incomingAccessNumber; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the phoneNumber - */ - public String getPhoneNumber() { - return phoneNumber; - } - - /** - * @return the policyBitmask - */ - public int getPolicyBitmask() { - return policyBitmask; - } - - /** - * @return the redirectToVoicemail - */ - public boolean isRedirectToVoicemail() { - return redirectToVoicemail; - } - - /** - * @return the scheduleSet - */ - public boolean isScheduleSet() { - return scheduleSet; - } - - /** - * @return the smsEnabled - */ - public boolean isSmsEnabled() { - return smsEnabled; - } - - /** - * @return the telephonyVerified - */ - public boolean isTelephonyVerified() { - return telephonyVerified; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @return the verified - */ - public boolean isVerified() { - return verified; - } - - /** - * @return the voicemailForwardingVerified - */ - public boolean isVoicemailForwardingVerified() { - return voicemailForwardingVerified; - } - - /** - * @return the wd - */ - public Wd getWd() { - return wd; - } - - /** - * @return the we - */ - public We getWe() { - return we; - } - - /** - * @return the weekdayAllDay - */ - public boolean isWeekdayAllDay() { - return weekdayAllDay; - } - - /** - * @return the weekdayTimes - */ - public String[] getWeekdayTimes() { - return weekdayTimes; - } - - /** - * @return the weekendAllDay - */ - public boolean isWeekendAllDay() { - return weekendAllDay; - } - - /** - * @return the weekendTimes - */ - public String[] getWeekendTimes() { - return weekendTimes; - } - - - - /** - * @param active the active to set - */ - public void setActive(boolean active) { - this.active = active; - } - - /** - * @param behaviorOnRedirect the behaviorOnRedirect to set - */ - public void setBehaviorOnRedirect(int behaviorOnRedirect) { - this.behaviorOnRedirect = behaviorOnRedirect; - } - - /** - * @param carrier the carrier to set - */ - public void setCarrier(String carrier) { - this.carrier = carrier; - } - - /** - * @param customOverrideState the customOverrideState to set - */ - public void setCustomOverrideState(int customOverrideState) { - this.customOverrideState = customOverrideState; - } - - /** - * @param dEPRECATEDDisabled the dEPRECATEDDisabled to set - */ - public void setdEPRECATEDDisabled(boolean dEPRECATEDDisabled) { - this.dEPRECATEDDisabled = dEPRECATEDDisabled; - } - - /** - * @param enabledForOthers the enabledForOthers to set - */ - public void setEnabledForOthers(boolean enabledForOthers) { - this.enabledForOthers = enabledForOthers; - } - - /** - * @param formattedNumber the formattedNumber to set - */ - public void setFormattedNumber(String formattedNumber) { - this.formattedNumber = formattedNumber; - } - - /** - * @param id the id to set - */ - public void setId(int id) { - this.id = id; - } - - /** - * @param incomingAccessNumber the incomingAccessNumber to set - */ - public void setIncomingAccessNumber(String incomingAccessNumber) { - this.incomingAccessNumber = incomingAccessNumber; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @param phoneNumber the phoneNumber to set - */ - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - /** - * @param policyBitmask the policyBitmask to set - */ - public void setPolicyBitmask(int policyBitmask) { - this.policyBitmask = policyBitmask; - } - - /** - * @param redirectToVoicemail the redirectToVoicemail to set - */ - public void setRedirectToVoicemail(boolean redirectToVoicemail) { - this.redirectToVoicemail = redirectToVoicemail; - } - - /** - * @param scheduleSet the scheduleSet to set - */ - public void setScheduleSet(boolean scheduleSet) { - this.scheduleSet = scheduleSet; - } - - /** - * @param smsEnabled the smsEnabled to set - */ - public void setSmsEnabled(boolean smsEnabled) { - this.smsEnabled = smsEnabled; - } - - /** - * @param telephonyVerified the telephonyVerified to set - */ - public void setTelephonyVerified(boolean telephonyVerified) { - this.telephonyVerified = telephonyVerified; - } - - /** - * @param type the type to set - */ - public void setType(int type) { - this.type = type; - } - - /** - * @param verified the verified to set - */ - public void setVerified(boolean verified) { - this.verified = verified; - } - - /** - * @param voicemailForwardingVerified the voicemailForwardingVerified to set - */ - public void setVoicemailForwardingVerified(boolean voicemailForwardingVerified) { - this.voicemailForwardingVerified = voicemailForwardingVerified; - } - - /** - * @param wd the wd to set - */ - public void setWd(Wd wd) { - this.wd = wd; - } - - /** - * @param we the we to set - */ - public void setWe(We we) { - this.we = we; - } - - /** - * @param weekdayAllDay the weekdayAllDay to set - */ - public void setWeekdayAllDay(boolean weekdayAllDay) { - this.weekdayAllDay = weekdayAllDay; - } - - /** - * @param weekdayTimes the weekdayTimes to set - */ - public void setWeekdayTimes(String[] weekdayTimes) { - this.weekdayTimes = weekdayTimes; - } - - /** - * @param weekendAllDay the weekendAllDay to set - */ - public void setWeekendAllDay(boolean weekendAllDay) { - this.weekendAllDay = weekendAllDay; - } - - /** - * @param weekendTimes the weekendTimes to set - */ - public void setWeekendTimes(String[] weekendTimes) { - this.weekendTimes = weekendTimes; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(Phone o) { - if( id < o.getId() ) - return -1; - if( id > o.getId() ) - return 1; - - return 0; - } - - -} + +package com.techventus.server.voice.datatypes; + +import gvjava.org.json.JSONArray; +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import com.techventus.server.voice.util.ParsingUtil; + +public class Phone implements Comparable{ + //TODO - implement + + private boolean saveMode; + + private boolean active; + private int behaviorOnRedirect; + private String carrier; + private int customOverrideState; + private boolean dEPRECATEDDisabled; + private boolean enabledForOthers; + private String formattedNumber; + private int id; + private String incomingAccessNumber; + private String name; + private String phoneNumber; + private int policyBitmask; + private boolean redirectToVoicemail; + private boolean scheduleSet; + private boolean smsEnabled; + private boolean telephonyVerified; + private int type; + private boolean verified; + private boolean voicemailForwardingVerified; + private Wd wd; //TODO + private We we; //TODO + private boolean weekdayAllDay; + private String[] weekdayTimes; + private boolean weekendAllDay; + private String[] weekendTimes; + + public Phone(int id, String name, String phoneNumber) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + } + + /** + * + * saveMode is off + * + * @param phonesJSON + * + */ + public Phone(JSONObject phonesJSON) throws JSONException { + this(phonesJSON, false); + } + + /** + * Instantiates a new Phone Object. + * + * @param phonesJSON the JSON representation of the Phone object + * @param pSaveMode the Save Mode boolean + * @throws JSONException the JSONException + */ + public Phone(JSONObject phonesJSON, boolean pSaveMode) throws JSONException { + if(!saveMode || (saveMode && phonesJSON.has("id")) ) id = phonesJSON.getInt("id"); + if(!saveMode || (saveMode && phonesJSON.has("name")) ) name = phonesJSON.getString("name"); + if(!saveMode || (saveMode && phonesJSON.has("phoneNumber")) ) phoneNumber = phonesJSON.getString("phoneNumber"); + if(!saveMode || (saveMode && phonesJSON.has("active")) ) active = phonesJSON.getBoolean("active"); + if(!saveMode || (saveMode && phonesJSON.has("behaviorOnRedirect")) ) behaviorOnRedirect = phonesJSON.getInt("behaviorOnRedirect"); + if(!saveMode || (saveMode && phonesJSON.has("carrier")) ) carrier = phonesJSON.getString("carrier"); + if(!saveMode || (saveMode && phonesJSON.has("customOverrideState")) ) customOverrideState = phonesJSON.getInt("customOverrideState"); + if(!saveMode || (saveMode && phonesJSON.has("dEPRECATEDDisabled")) ) dEPRECATEDDisabled = phonesJSON.getBoolean("dEPRECATEDDisabled"); + if(!saveMode || (saveMode && phonesJSON.has("enabledForOthers")) ) enabledForOthers = phonesJSON.getBoolean("enabledForOthers"); + if(!saveMode || (saveMode && phonesJSON.has("formattedNumber")) ) formattedNumber = phonesJSON.getString("formattedNumber"); + if(!saveMode || (saveMode && phonesJSON.has("incomingAccessNumber")) ) incomingAccessNumber = phonesJSON.getString("incomingAccessNumber"); + if(!saveMode || (saveMode && phonesJSON.has("phoneNumber")) ) phoneNumber = phonesJSON.getString("phoneNumber"); + if(!saveMode || (saveMode && phonesJSON.has("policyBitmask")) ) policyBitmask = phonesJSON.getInt("policyBitmask"); + if(!saveMode || (saveMode && phonesJSON.has("redirectToVoicemail")) ) redirectToVoicemail = phonesJSON.getBoolean("redirectToVoicemail"); + if(!saveMode || (saveMode && phonesJSON.has("scheduleSet")) ) { + try { + // if not set, this value is "false", but if active it's 1 !! - this is not true... maybe + scheduleSet = phonesJSON.getBoolean("scheduleSet"); + } catch (JSONException jsE) { +// int positive = phonesJSON.getInt("scheduleSet"); +// if(positive==1) scheduleSet = true; + // we will just set false on error + scheduleSet = false; + } + } + if(!saveMode || (saveMode && phonesJSON.has("smsEnabled")) ) smsEnabled = phonesJSON.getBoolean("smsEnabled"); + if(!saveMode || (saveMode && phonesJSON.has("telephonyVerified")) ) telephonyVerified = phonesJSON.getBoolean("telephonyVerified"); + if(!saveMode || (saveMode && phonesJSON.has("type")) ) type = phonesJSON.getInt("type"); + if(!saveMode || (saveMode && phonesJSON.has("verified")) ) verified = phonesJSON.getBoolean("verified"); + if(!saveMode || (saveMode && phonesJSON.has("voicemailForwardingVerified")) ) voicemailForwardingVerified = phonesJSON.getBoolean("voicemailForwardingVerified"); +// if(!saveMode || (saveMode && phonesJSON.has("wd")) ) wd = phonesJSON.getInt("id"); //TODO +// if(!saveMode || (saveMode && phonesJSON.has("we")) ) wd = phonesJSON.getInt("id"); //TODO + if(!saveMode || (saveMode && phonesJSON.has("weekdayAllDay")) ) weekdayAllDay = phonesJSON.getBoolean("weekdayAllDay"); + if(!saveMode || (saveMode && phonesJSON.has("weekdayTimes")) ) weekdayTimes = ParsingUtil.jsonStringArrayToStringArray(phonesJSON.getJSONArray("weekdayTimes"));//Type correct?? + if(!saveMode || (saveMode && phonesJSON.has("weekendAllDay")) ) weekendAllDay = phonesJSON.getBoolean("weekendAllDay"); + if(!saveMode || (saveMode && phonesJSON.has("weekendTimes")) ) weekendTimes = ParsingUtil.jsonStringArrayToStringArray(phonesJSON.getJSONArray("weekendTimes"));//Type correct?? + } + + public static final Phone[] createArrayFromJsonObject(JSONObject phonesJSON) throws JSONException { + JSONArray phoneNames = phonesJSON.names(); + Phone[] result = new Phone[phoneNames.length()]; + for (int i = 0; i < phoneNames.length(); i++) { + result[i] = new Phone(phonesJSON.getJSONObject(phoneNames.getString(i))); + } + return result; + } + + /** + * Make a JSON text of the Settings. For compactness, no whitespace + * is added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable + * representation of the object, beginning + * with { (left brace) and ending + * with } (right brace). + */ + public String toJson(){ + return toJsonObject().toString(); + } + + public JSONObject toJsonObject(){ + JSONObject resultO = new JSONObject(); + try { + resultO.putOpt("id", id); + resultO.putOpt("name", name); + resultO.putOpt("active", active); + resultO.putOpt("behaviorOnRedirect", behaviorOnRedirect); + resultO.putOpt("carrier", carrier); + resultO.putOpt("customOverrideState", customOverrideState); + resultO.putOpt("dEPRECATEDDisabled", dEPRECATEDDisabled); + resultO.putOpt("enabledForOthers", enabledForOthers); + resultO.putOpt("formattedNumber", formattedNumber); + resultO.putOpt("id", id); + resultO.putOpt("incomingAccessNumber", incomingAccessNumber); + resultO.putOpt("name", name); + resultO.putOpt("phoneNumber", phoneNumber); + resultO.putOpt("policyBitmask", policyBitmask); + resultO.putOpt("redirectToVoicemail", redirectToVoicemail); + //Google json expects false or 1 - not anymore +// if(scheduleSet) { +// resultO.putOpt("scheduleSet", 1); +// } else { +// resultO.putOpt("scheduleSet", false); +// } + resultO.putOpt("scheduleSet", scheduleSet); + resultO.putOpt("smsEnabled", smsEnabled); + resultO.putOpt("telephonyVerified", telephonyVerified); + resultO.putOpt("type", type); + resultO.putOpt("verified", verified); + resultO.putOpt("voicemailForwardingVerified", voicemailForwardingVerified); +// private Wd wd", ); //TODO +// private We we", ); //TODO + resultO.putOpt("weekdayAllDay", weekdayAllDay); + resultO.putOpt("weekdayTimes", weekdayTimes);//Type correct?? + resultO.putOpt("weekendAllDay", weekendAllDay); + resultO.putOpt("weekendTimes", weekendTimes);//Type correct?? + } catch (JSONException e) { + return null; + } + + return resultO; + } + + /** + * @param phones + * @return Json Object + * @throws JSONException + */ + public static Object phonesArrayToJsonObject(Phone[] phones) throws JSONException { + JSONObject phoneO = new JSONObject(); + for (int i = 0; i < phones.length; i++) { + phoneO.accumulate(phones[i].getId()+"",phones[i].toJsonObject()); + } + return phoneO; + } + + /** + * @return the active + */ + public boolean isActive() { + return active; + } + + /** + * @return the behaviorOnRedirect + */ + public int getBehaviorOnRedirect() { + return behaviorOnRedirect; + } + + /** + * @return the carrier + */ + public String getCarrier() { + return carrier; + } + + /** + * @return the customOverrideState + */ + public int getCustomOverrideState() { + return customOverrideState; + } + + /** + * @return the dEPRECATEDDisabled + */ + public boolean isdEPRECATEDDisabled() { + return dEPRECATEDDisabled; + } + + /** + * @return the enabledForOthers + */ + public boolean isEnabledForOthers() { + return enabledForOthers; + } + + /** + * @return the formattedNumber + */ + public String getFormattedNumber() { + return formattedNumber; + } + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * returns the value for smsEnabled for this phone + * @return + */ + public boolean getSmsEnabled() { + return smsEnabled; + } + + /** + * @return the incomingAccessNumber + */ + public String getIncomingAccessNumber() { + return incomingAccessNumber; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the phoneNumber + */ + public String getPhoneNumber() { + return phoneNumber; + } + + /** + * @return the policyBitmask + */ + public int getPolicyBitmask() { + return policyBitmask; + } + + /** + * @return the redirectToVoicemail + */ + public boolean isRedirectToVoicemail() { + return redirectToVoicemail; + } + + /** + * @return the scheduleSet + */ + public boolean isScheduleSet() { + return scheduleSet; + } + + /** + * @return the smsEnabled + */ + public boolean isSmsEnabled() { + return smsEnabled; + } + + /** + * @return the telephonyVerified + */ + public boolean isTelephonyVerified() { + return telephonyVerified; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @return the verified + */ + public boolean isVerified() { + return verified; + } + + /** + * @return the voicemailForwardingVerified + */ + public boolean isVoicemailForwardingVerified() { + return voicemailForwardingVerified; + } + + /** + * @return the wd + */ + public Wd getWd() { + return wd; + } + + /** + * @return the we + */ + public We getWe() { + return we; + } + + /** + * @return the weekdayAllDay + */ + public boolean isWeekdayAllDay() { + return weekdayAllDay; + } + + /** + * @return the weekdayTimes + */ + public String[] getWeekdayTimes() { + return weekdayTimes; + } + + /** + * @return the weekendAllDay + */ + public boolean isWeekendAllDay() { + return weekendAllDay; + } + + /** + * @return the weekendTimes + */ + public String[] getWeekendTimes() { + return weekendTimes; + } + + + + /** + * @param active the active to set + */ + public void setActive(boolean active) { + this.active = active; + } + + /** + * @param behaviorOnRedirect the behaviorOnRedirect to set + */ + public void setBehaviorOnRedirect(int behaviorOnRedirect) { + this.behaviorOnRedirect = behaviorOnRedirect; + } + + /** + * @param carrier the carrier to set + */ + public void setCarrier(String carrier) { + this.carrier = carrier; + } + + /** + * @param customOverrideState the customOverrideState to set + */ + public void setCustomOverrideState(int customOverrideState) { + this.customOverrideState = customOverrideState; + } + + /** + * @param dEPRECATEDDisabled the dEPRECATEDDisabled to set + */ + public void setdEPRECATEDDisabled(boolean dEPRECATEDDisabled) { + this.dEPRECATEDDisabled = dEPRECATEDDisabled; + } + + /** + * @param enabledForOthers the enabledForOthers to set + */ + public void setEnabledForOthers(boolean enabledForOthers) { + this.enabledForOthers = enabledForOthers; + } + + /** + * @param formattedNumber the formattedNumber to set + */ + public void setFormattedNumber(String formattedNumber) { + this.formattedNumber = formattedNumber; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @param incomingAccessNumber the incomingAccessNumber to set + */ + public void setIncomingAccessNumber(String incomingAccessNumber) { + this.incomingAccessNumber = incomingAccessNumber; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @param phoneNumber the phoneNumber to set + */ + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + /** + * @param policyBitmask the policyBitmask to set + */ + public void setPolicyBitmask(int policyBitmask) { + this.policyBitmask = policyBitmask; + } + + /** + * @param redirectToVoicemail the redirectToVoicemail to set + */ + public void setRedirectToVoicemail(boolean redirectToVoicemail) { + this.redirectToVoicemail = redirectToVoicemail; + } + + /** + * @param scheduleSet the scheduleSet to set + */ + public void setScheduleSet(boolean scheduleSet) { + this.scheduleSet = scheduleSet; + } + + /** + * @param smsEnabled the smsEnabled to set + */ + public void setSmsEnabled(boolean smsEnabled) { + this.smsEnabled = smsEnabled; + } + + /** + * @param telephonyVerified the telephonyVerified to set + */ + public void setTelephonyVerified(boolean telephonyVerified) { + this.telephonyVerified = telephonyVerified; + } + + /** + * @param type the type to set + */ + public void setType(int type) { + this.type = type; + } + + /** + * @param verified the verified to set + */ + public void setVerified(boolean verified) { + this.verified = verified; + } + + /** + * @param voicemailForwardingVerified the voicemailForwardingVerified to set + */ + public void setVoicemailForwardingVerified(boolean voicemailForwardingVerified) { + this.voicemailForwardingVerified = voicemailForwardingVerified; + } + + /** + * @param wd the wd to set + */ + public void setWd(Wd wd) { + this.wd = wd; + } + + /** + * @param we the we to set + */ + public void setWe(We we) { + this.we = we; + } + + /** + * @param weekdayAllDay the weekdayAllDay to set + */ + public void setWeekdayAllDay(boolean weekdayAllDay) { + this.weekdayAllDay = weekdayAllDay; + } + + /** + * @param weekdayTimes the weekdayTimes to set + */ + public void setWeekdayTimes(String[] weekdayTimes) { + this.weekdayTimes = weekdayTimes; + } + + /** + * @param weekendAllDay the weekendAllDay to set + */ + public void setWeekendAllDay(boolean weekendAllDay) { + this.weekendAllDay = weekendAllDay; + } + + /** + * @param weekendTimes the weekendTimes to set + */ + public void setWeekendTimes(String[] weekendTimes) { + this.weekendTimes = weekendTimes; + } + + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(Phone o) { + if( id < o.getId() ) + return -1; + if( id > o.getId() ) + return 1; + + return 0; + } + + +} diff --git a/src/com/techventus/server/voice/datatypes/Setting.java b/src/main/java/com/techventus/server/voice/datatypes/Setting.java similarity index 95% rename from src/com/techventus/server/voice/datatypes/Setting.java rename to src/main/java/com/techventus/server/voice/datatypes/Setting.java index e97f9bc..8637f20 100644 --- a/src/com/techventus/server/voice/datatypes/Setting.java +++ b/src/main/java/com/techventus/server/voice/datatypes/Setting.java @@ -1,537 +1,537 @@ -package com.techventus.server.voice.datatypes; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import gvjava.org.json.JSONArray; -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import com.techventus.server.voice.util.ParsingUtil; -/** - * Accountsettings - subtype of AllSettings - * - * @author tobias eisentraeger - * - */ -public class Setting { - - private final static boolean saveMode = true; - - // Settings in order of the json - private int[] mActiveForwardingList; - private String baseUrl; - private int credits; - private int defaultGreetingId; - private String[] mDidInfos; - private boolean directConnect; - private DisabledId[] mDisabledIdMap; - private boolean doNotDisturb; - private EmailAddress[] emailAddresses; - private boolean emailNotificationActive; - private String emailNotificationAddress; - private Greeting[] greetings; - private String[] groupList; - private Group[] groups; - private String language; - private String primaryDid; - private int screenBehavior; - private boolean showTranscripts; - private String[] smsNotifications; - private boolean smsToEmailActive; - private boolean smsToEmailSubject; - private String spam; - private String timezone; - private boolean useDidAsCallerId; - private boolean useDidAsSource; - - public Setting(JSONObject settingsJSON) throws JSONException { - if(!saveMode || saveMode && settingsJSON.has("activeForwardingIds")) mActiveForwardingList = ParsingUtil.jsonIntArrayToIntArray(settingsJSON.getJSONArray("activeForwardingIds")); - if(!saveMode || saveMode && settingsJSON.has("baseUrl")) baseUrl = settingsJSON.getString("baseUrl"); - if(!saveMode || saveMode && settingsJSON.has("credits")) credits = settingsJSON.getInt("credits"); - if(!saveMode || saveMode && settingsJSON.has("defaultGreetingId")) defaultGreetingId = settingsJSON.getInt("defaultGreetingId"); - if(!saveMode || saveMode && settingsJSON.has("didInfos")) mDidInfos = ParsingUtil.jsonStringArrayToStringArray(settingsJSON.getJSONArray("didInfos")); - if(!saveMode || saveMode && settingsJSON.has("directConnect")) directConnect = settingsJSON.getBoolean("directConnect"); - if(!saveMode || saveMode && settingsJSON.has("disabledIdMap")) mDisabledIdMap = DisabledId.createArrayFromJsonObject(settingsJSON); - if(!saveMode || saveMode && settingsJSON.has("doNotDisturb")) doNotDisturb = settingsJSON.getBoolean("doNotDisturb"); - if(!saveMode || saveMode && settingsJSON.has("emailAddresses")) emailAddresses = EmailAddress.createArrayFromJsonObject(settingsJSON); - if(!saveMode || saveMode && settingsJSON.has("emailNotificationActive")) emailNotificationActive = settingsJSON.getBoolean("emailNotificationActive"); - if(!saveMode || saveMode && settingsJSON.has("emailNotificationAddress")) emailNotificationAddress = settingsJSON.getString("emailNotificationAddress"); - if(!saveMode || saveMode && settingsJSON.has("greetings")) greetings = Greeting.createArrayFromJsonObject(settingsJSON); - if(!saveMode || saveMode && settingsJSON.has("groupList")) groupList = ParsingUtil.jsonStringArrayToStringArray(settingsJSON.getJSONArray("groupList")); - if(!saveMode || saveMode && settingsJSON.has("groups")) groups = Group.createArrayFromJsonObject(settingsJSON.getJSONObject("groups")); - if(!saveMode || saveMode && settingsJSON.has("language")) language = settingsJSON.getString("language"); - if(!saveMode || saveMode && settingsJSON.has("primaryDid")) primaryDid = settingsJSON.getString("primaryDid"); - if(!saveMode || saveMode && settingsJSON.has("screenBehavior")) screenBehavior = settingsJSON.getInt("screenBehavior"); - if(!saveMode || saveMode && settingsJSON.has("showTranscripts")) showTranscripts = settingsJSON.getBoolean("showTranscripts"); - if(!saveMode || saveMode && settingsJSON.has("smsNotifications")) smsNotifications = ParsingUtil.jsonStringArrayToStringArray(settingsJSON.getJSONArray("smsNotifications")); - if(!saveMode || saveMode && settingsJSON.has("smsToEmailActive")) smsToEmailActive = settingsJSON.getBoolean("smsToEmailActive"); - if(!saveMode || saveMode && settingsJSON.has("smsToEmailSubject")) smsToEmailSubject = settingsJSON.getBoolean("smsToEmailSubject"); - if(!saveMode || saveMode && settingsJSON.has("spam")) spam = settingsJSON.getString("spam"); - if(!saveMode || saveMode && settingsJSON.has("timezone")) timezone = settingsJSON.getString("timezone"); - if(!saveMode || saveMode && settingsJSON.has("useDidAsCallerId")) useDidAsCallerId = settingsJSON.getBoolean("useDidAsCallerId"); - if(!saveMode || saveMode && settingsJSON.has("useDidAsSource")) useDidAsSource = settingsJSON.getBoolean("useDidAsSource"); - //TODO webCallButtons - } - - /** - * Make a JSON text of the Settings. For compactness, no whitespace - * is added. If this would not result in a syntactically correct JSON text, - * then null will be returned instead. - *

- * Warning: This method assumes that the data structure is acyclical. - * - * @return a printable, displayable, portable, transmittable - * representation of the object, beginning - * with { (left brace) and ending - * with } (right brace). - */ - public String toJson(){ - return toJsonObject().toString(); - } - - /** - * Convert this Settings Object to its JsonObject Representation. - * - * @return the jSON object - */ - public JSONObject toJsonObject(){ - JSONObject settingsO = new JSONObject(); - try { - //JSONObject settingsO = new JSONObject(); - - settingsO.putOpt("activeForwardingIds", mActiveForwardingList); - settingsO.putOpt("baseUrl", baseUrl); - settingsO.putOpt("credits", credits); - settingsO.putOpt("defaultGreetingId", defaultGreetingId); - settingsO.putOpt("didInfos", mDidInfos); - settingsO.putOpt("directConnect", directConnect); - if(mDisabledIdMap!=null) { - Map disMap = new HashMap(); - for (DisabledId disId : mDisabledIdMap) { - disMap.put(disId.getId(), disId.isDisabled()); - } - settingsO.putOpt("disabledIdMap", disMap); - } else { - // need to put this "disabledIdMap": {} - } - settingsO.putOpt("doNotDisturb", doNotDisturb); - if(emailAddresses!=null) { - for (int i = 0; i < emailAddresses.length; i++) { - settingsO.accumulate("emailAddresses", emailAddresses[i].getAddress()); - } - } else { - // need to put this "emailAddresses": {} - } - settingsO.putOpt("emailNotificationActive", emailNotificationActive); - settingsO.putOpt("emailNotificationAddress", emailNotificationAddress); - settingsO.putOpt("greetings", greetings); // An Object Array uses the Bean get Methods - no toJson() needed in Greeting - settingsO.putOpt("groupList", groupList); - - settingsO.accumulate("groups", Group.groupsArrayToJsonObject(groups)); - -// JSONObject groupObject = new JSONObject(); -// JSONArray groupNames = groups.names(); -// if(groupNames!=null && groupNames.length()>0) { -// for (int i = 0; i < groupNames.length(); i++) { -// JSONObject oneGroupObject = groups; -// groupObject.putOpt(groupNames.getString(i), oneGroupObject); -// } -// } - - settingsO.putOpt("language", language); - settingsO.putOpt("primaryDid", primaryDid); - settingsO.putOpt("screenBehavior", screenBehavior); - settingsO.putOpt("showTranscripts", showTranscripts); - settingsO.putOpt("smsNotifications", smsNotifications); - settingsO.putOpt("smsToEmailActive", smsToEmailActive); - settingsO.putOpt("smsToEmailSubject", smsToEmailSubject); - settingsO.putOpt("spam", spam); - settingsO.putOpt("timezone", timezone); - settingsO.putOpt("useDidAsCallerId", useDidAsCallerId); - settingsO.putOpt("useDidAsSource", useDidAsSource); - - //resultO.put("settings", settingsO); - } catch (JSONException e) { - System.out.println(e.getLocalizedMessage()); - return null; - } - - return settingsO; - } - - /** - * @return the mActiveForwardingList - */ - public int[] getmActiveForwardingList() { - return mActiveForwardingList; - } - - /** - * @return the baseUrl - */ - public String getBaseUrl() { - return baseUrl; - } - - /** - * @return the credits - */ - public int getCredits() { - return credits; - } - - /** - * @return the defaultGreetingId - */ - public int getDefaultGreetingId() { - return defaultGreetingId; - } - - /** - * @return the mDidInfos - */ - public String[] getmDidInfos() { - return mDidInfos; - } - - /** - * @return the directConnect - */ - public boolean isDirectConnect() { - return directConnect; - } - - /** - * @return the mDisabledIdMap - */ - public DisabledId[] getmDisabledIdList() { - return mDisabledIdMap; - } - - /** - * @return the doNotDisturb - */ - public boolean isDoNotDisturb() { - return doNotDisturb; - } - - /** - * @return the emailAddresses - */ - public EmailAddress[] getEmailAddresses() { - return emailAddresses; - } - - /** - * @return the emailNotificationActive - */ - public boolean isEmailNotificationActive() { - return emailNotificationActive; - } - - /** - * @return the emailNotificationAddress - */ - public String getEmailNotificationAddress() { - return emailNotificationAddress; - } - - /** - * @return the greetings - */ - public Greeting[] getGreetings() { - return greetings; - } - /** - * @return the greetings - */ - public Greeting[] getGreetingsSorted() { - Arrays.sort(greetings); - return greetings; - } - - /** - * @return the groupList - */ - public String[] getGroupList() { - return groupList; - } - - /** - * @return the groupList as List - */ - public List getGroupListAsList() { - List lresult = new ArrayList(); - for (int i = 0; i < groupList.length; i++) { - lresult.add(groupList[i]); - } - return lresult; - } - - /** - * @return the groups - */ - public Group[] getGroups() { - return groups; - } - - - /** - * @return the language - */ - public String getLanguage() { - return language; - } - - /** - * @return the primaryDid - */ - public String getPrimaryDid() { - return primaryDid; - } - - /** - * @return the screenBehavior - */ - public int getScreenBehavior() { - return screenBehavior; - } - - /** - * @return the showTranscripts - */ - public boolean isShowTranscripts() { - return showTranscripts; - } - - /** - * @return the smsNotifications - */ - public String[] getSmsNotifications() { - return smsNotifications; - } - - /** - * @return the smsToEmailActive - */ - public boolean isSmsToEmailActive() { - return smsToEmailActive; - } - - /** - * @return the smsToEmailSubject - */ - public boolean isSmsToEmailSubject() { - return smsToEmailSubject; - } - - /** - * @return the spam - */ - public String getSpam() { - return spam; - } - - /** - * @return the timezone - */ - public String getTimezone() { - return timezone; - } - - /** - * @return the useDidAsCallerId - */ - public boolean isUseDidAsCallerId() { - return useDidAsCallerId; - } - - /** - * @return the useDidAsSource - */ - public boolean isUseDidAsSource() { - return useDidAsSource; - } - - /** - * @param mActiveForwardingList the mActiveForwardingList to set - */ - public void setmActiveForwardingList(int[] mActiveForwardingList) { - this.mActiveForwardingList = mActiveForwardingList; - } - - /** - * @param baseUrl the baseUrl to set - */ - public void setBaseUrl(String baseUrl) { - this.baseUrl = baseUrl; - } - - /** - * @param credits the credits to set - */ - public void setCredits(int credits) { - this.credits = credits; - } - - /** - * @param defaultGreetingId the defaultGreetingId to set - */ - public void setDefaultGreetingId(int defaultGreetingId) { - this.defaultGreetingId = defaultGreetingId; - } - - /** - * @param mDidInfos the mDidInfos to set - */ - public void setmDidInfos(String[] mDidInfos) { - this.mDidInfos = mDidInfos; - } - - /** - * @param directConnect the directConnect to set - */ - public void setDirectConnect(boolean directConnect) { - this.directConnect = directConnect; - } - - /** - * @param mDisabledIdMap the mDisabledIdMap to set - */ - public void setmDisabledIdList(DisabledId[] mDisabledIdList) { - this.mDisabledIdMap = mDisabledIdList; - } - - /** - * @param doNotDisturb the doNotDisturb to set - */ - public void setDoNotDisturb(boolean doNotDisturb) { - this.doNotDisturb = doNotDisturb; - } - - /** - * @param emailAddresses the emailAddresses to set - */ - public void setEmailAddresses(EmailAddress[] emailAddresses) { - this.emailAddresses = emailAddresses; - } - - /** - * @param emailNotificationActive the emailNotificationActive to set - */ - public void setEmailNotificationActive(boolean emailNotificationActive) { - this.emailNotificationActive = emailNotificationActive; - } - - /** - * @param emailNotificationAddress the emailNotificationAddress to set - */ - public void setEmailNotificationAddress(String emailNotificationAddress) { - this.emailNotificationAddress = emailNotificationAddress; - } - - /** - * @param greetings the greetings to set - */ - public void setGreetings(Greeting[] greetings) { - this.greetings = greetings; - } - - /** - * @param groupList the groupList to set - */ - public void setGroupList(String[] groupList) { - this.groupList = groupList; - } - - /** - * @param groups the groups to set - */ - public void setGroups(Group[] groups) { - this.groups = groups; - } - - /** - * @param language the language to set - */ - public void setLanguage(String language) { - this.language = language; - } - - /** - * @param primaryDid the primaryDid to set - */ - public void setPrimaryDid(String primaryDid) { - this.primaryDid = primaryDid; - } - - /** - * @param screenBehavior the screenBehavior to set - */ - public void setScreenBehavior(int screenBehavior) { - this.screenBehavior = screenBehavior; - } - - /** - * @param showTranscripts the showTranscripts to set - */ - public void setShowTranscripts(boolean showTranscripts) { - this.showTranscripts = showTranscripts; - } - - /** - * @param smsNotifications the smsNotifications to set - */ - public void setSmsNotifications(String[] smsNotifications) { - this.smsNotifications = smsNotifications; - } - - /** - * @param smsToEmailActive the smsToEmailActive to set - */ - public void setSmsToEmailActive(boolean smsToEmailActive) { - this.smsToEmailActive = smsToEmailActive; - } - - /** - * @param smsToEmailSubject the smsToEmailSubject to set - */ - public void setSmsToEmailSubject(boolean smsToEmailSubject) { - this.smsToEmailSubject = smsToEmailSubject; - } - - /** - * @param spam the spam to set - */ - public void setSpam(String spam) { - this.spam = spam; - } - - /** - * @param timezone the timezone to set - */ - public void setTimezone(String timezone) { - this.timezone = timezone; - } - - /** - * @param useDidAsCallerId the useDidAsCallerId to set - */ - public void setUseDidAsCallerId(boolean useDidAsCallerId) { - this.useDidAsCallerId = useDidAsCallerId; - } - - /** - * @param useDidAsSource the useDidAsSource to set - */ - public void setUseDidAsSource(boolean useDidAsSource) { - this.useDidAsSource = useDidAsSource; - } - - - -} +package com.techventus.server.voice.datatypes; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import gvjava.org.json.JSONArray; +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import com.techventus.server.voice.util.ParsingUtil; +/** + * Accountsettings - subtype of AllSettings + * + * @author tobias eisentraeger + * + */ +public class Setting { + + private final static boolean saveMode = true; + + // Settings in order of the json + private int[] mActiveForwardingList; + private String baseUrl; + private int credits; + private int defaultGreetingId; + private String[] mDidInfos; + private boolean directConnect; + private DisabledId[] mDisabledIdMap; + private boolean doNotDisturb; + private EmailAddress[] emailAddresses; + private boolean emailNotificationActive; + private String emailNotificationAddress; + private Greeting[] greetings; + private String[] groupList; + private Group[] groups; + private String language; + private String primaryDid; + private int screenBehavior; + private boolean showTranscripts; + private String[] smsNotifications; + private boolean smsToEmailActive; + private boolean smsToEmailSubject; + private String spam; + private String timezone; + private boolean useDidAsCallerId; + private boolean useDidAsSource; + + public Setting(JSONObject settingsJSON) throws JSONException { + if(!saveMode || saveMode && settingsJSON.has("activeForwardingIds")) mActiveForwardingList = ParsingUtil.jsonIntArrayToIntArray(settingsJSON.getJSONArray("activeForwardingIds")); + if(!saveMode || saveMode && settingsJSON.has("baseUrl")) baseUrl = settingsJSON.getString("baseUrl"); + if(!saveMode || saveMode && settingsJSON.has("credits")) credits = settingsJSON.getInt("credits"); + if(!saveMode || saveMode && settingsJSON.has("defaultGreetingId")) defaultGreetingId = settingsJSON.getInt("defaultGreetingId"); + if(!saveMode || saveMode && settingsJSON.has("didInfos")) mDidInfos = ParsingUtil.jsonStringArrayToStringArray(settingsJSON.getJSONArray("didInfos")); + if(!saveMode || saveMode && settingsJSON.has("directConnect")) directConnect = settingsJSON.getBoolean("directConnect"); + if(!saveMode || saveMode && settingsJSON.has("disabledIdMap")) mDisabledIdMap = DisabledId.createArrayFromJsonObject(settingsJSON); + if(!saveMode || saveMode && settingsJSON.has("doNotDisturb")) doNotDisturb = settingsJSON.getBoolean("doNotDisturb"); + if(!saveMode || saveMode && settingsJSON.has("emailAddresses")) emailAddresses = EmailAddress.createArrayFromJsonObject(settingsJSON); + if(!saveMode || saveMode && settingsJSON.has("emailNotificationActive")) emailNotificationActive = settingsJSON.getBoolean("emailNotificationActive"); + if(!saveMode || saveMode && settingsJSON.has("emailNotificationAddress")) emailNotificationAddress = settingsJSON.getString("emailNotificationAddress"); + if(!saveMode || saveMode && settingsJSON.has("greetings")) greetings = Greeting.createArrayFromJsonObject(settingsJSON); + if(!saveMode || saveMode && settingsJSON.has("groupList")) groupList = ParsingUtil.jsonStringArrayToStringArray(settingsJSON.getJSONArray("groupList")); + if(!saveMode || saveMode && settingsJSON.has("groups")) groups = Group.createArrayFromJsonObject(settingsJSON.getJSONObject("groups")); + if(!saveMode || saveMode && settingsJSON.has("language")) language = settingsJSON.getString("language"); + if(!saveMode || saveMode && settingsJSON.has("primaryDid")) primaryDid = settingsJSON.getString("primaryDid"); + if(!saveMode || saveMode && settingsJSON.has("screenBehavior")) screenBehavior = settingsJSON.getInt("screenBehavior"); + if(!saveMode || saveMode && settingsJSON.has("showTranscripts")) showTranscripts = settingsJSON.getBoolean("showTranscripts"); + if(!saveMode || saveMode && settingsJSON.has("smsNotifications")) smsNotifications = ParsingUtil.jsonStringArrayToStringArray(settingsJSON.getJSONArray("smsNotifications")); + if(!saveMode || saveMode && settingsJSON.has("smsToEmailActive")) smsToEmailActive = settingsJSON.getBoolean("smsToEmailActive"); + if(!saveMode || saveMode && settingsJSON.has("smsToEmailSubject")) smsToEmailSubject = settingsJSON.getBoolean("smsToEmailSubject"); + if(!saveMode || saveMode && settingsJSON.has("spam")) spam = settingsJSON.getString("spam"); + if(!saveMode || saveMode && settingsJSON.has("timezone")) timezone = settingsJSON.getString("timezone"); + if(!saveMode || saveMode && settingsJSON.has("useDidAsCallerId")) useDidAsCallerId = settingsJSON.getBoolean("useDidAsCallerId"); + if(!saveMode || saveMode && settingsJSON.has("useDidAsSource")) useDidAsSource = settingsJSON.getBoolean("useDidAsSource"); + //TODO webCallButtons + } + + /** + * Make a JSON text of the Settings. For compactness, no whitespace + * is added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable + * representation of the object, beginning + * with { (left brace) and ending + * with } (right brace). + */ + public String toJson(){ + return toJsonObject().toString(); + } + + /** + * Convert this Settings Object to its JsonObject Representation. + * + * @return the jSON object + */ + public JSONObject toJsonObject(){ + JSONObject settingsO = new JSONObject(); + try { + //JSONObject settingsO = new JSONObject(); + + settingsO.putOpt("activeForwardingIds", mActiveForwardingList); + settingsO.putOpt("baseUrl", baseUrl); + settingsO.putOpt("credits", credits); + settingsO.putOpt("defaultGreetingId", defaultGreetingId); + settingsO.putOpt("didInfos", mDidInfos); + settingsO.putOpt("directConnect", directConnect); + if(mDisabledIdMap!=null) { + Map disMap = new HashMap(); + for (DisabledId disId : mDisabledIdMap) { + disMap.put(disId.getId(), disId.isDisabled()); + } + settingsO.putOpt("disabledIdMap", disMap); + } else { + // need to put this "disabledIdMap": {} + } + settingsO.putOpt("doNotDisturb", doNotDisturb); + if(emailAddresses!=null) { + for (int i = 0; i < emailAddresses.length; i++) { + settingsO.accumulate("emailAddresses", emailAddresses[i].getAddress()); + } + } else { + // need to put this "emailAddresses": {} + } + settingsO.putOpt("emailNotificationActive", emailNotificationActive); + settingsO.putOpt("emailNotificationAddress", emailNotificationAddress); + settingsO.putOpt("greetings", greetings); // An Object Array uses the Bean get Methods - no toJson() needed in Greeting + settingsO.putOpt("groupList", groupList); + + settingsO.accumulate("groups", Group.groupsArrayToJsonObject(groups)); + +// JSONObject groupObject = new JSONObject(); +// JSONArray groupNames = groups.names(); +// if(groupNames!=null && groupNames.length()>0) { +// for (int i = 0; i < groupNames.length(); i++) { +// JSONObject oneGroupObject = groups; +// groupObject.putOpt(groupNames.getString(i), oneGroupObject); +// } +// } + + settingsO.putOpt("language", language); + settingsO.putOpt("primaryDid", primaryDid); + settingsO.putOpt("screenBehavior", screenBehavior); + settingsO.putOpt("showTranscripts", showTranscripts); + settingsO.putOpt("smsNotifications", smsNotifications); + settingsO.putOpt("smsToEmailActive", smsToEmailActive); + settingsO.putOpt("smsToEmailSubject", smsToEmailSubject); + settingsO.putOpt("spam", spam); + settingsO.putOpt("timezone", timezone); + settingsO.putOpt("useDidAsCallerId", useDidAsCallerId); + settingsO.putOpt("useDidAsSource", useDidAsSource); + + //resultO.put("settings", settingsO); + } catch (JSONException e) { + System.out.println(e.getLocalizedMessage()); + return null; + } + + return settingsO; + } + + /** + * @return the mActiveForwardingList + */ + public int[] getmActiveForwardingList() { + return mActiveForwardingList; + } + + /** + * @return the baseUrl + */ + public String getBaseUrl() { + return baseUrl; + } + + /** + * @return the credits + */ + public int getCredits() { + return credits; + } + + /** + * @return the defaultGreetingId + */ + public int getDefaultGreetingId() { + return defaultGreetingId; + } + + /** + * @return the mDidInfos + */ + public String[] getmDidInfos() { + return mDidInfos; + } + + /** + * @return the directConnect + */ + public boolean isDirectConnect() { + return directConnect; + } + + /** + * @return the mDisabledIdMap + */ + public DisabledId[] getmDisabledIdList() { + return mDisabledIdMap; + } + + /** + * @return the doNotDisturb + */ + public boolean isDoNotDisturb() { + return doNotDisturb; + } + + /** + * @return the emailAddresses + */ + public EmailAddress[] getEmailAddresses() { + return emailAddresses; + } + + /** + * @return the emailNotificationActive + */ + public boolean isEmailNotificationActive() { + return emailNotificationActive; + } + + /** + * @return the emailNotificationAddress + */ + public String getEmailNotificationAddress() { + return emailNotificationAddress; + } + + /** + * @return the greetings + */ + public Greeting[] getGreetings() { + return greetings; + } + /** + * @return the greetings + */ + public Greeting[] getGreetingsSorted() { + Arrays.sort(greetings); + return greetings; + } + + /** + * @return the groupList + */ + public String[] getGroupList() { + return groupList; + } + + /** + * @return the groupList as List + */ + public List getGroupListAsList() { + List lresult = new ArrayList(); + for (int i = 0; i < groupList.length; i++) { + lresult.add(groupList[i]); + } + return lresult; + } + + /** + * @return the groups + */ + public Group[] getGroups() { + return groups; + } + + + /** + * @return the language + */ + public String getLanguage() { + return language; + } + + /** + * @return the primaryDid + */ + public String getPrimaryDid() { + return primaryDid; + } + + /** + * @return the screenBehavior + */ + public int getScreenBehavior() { + return screenBehavior; + } + + /** + * @return the showTranscripts + */ + public boolean isShowTranscripts() { + return showTranscripts; + } + + /** + * @return the smsNotifications + */ + public String[] getSmsNotifications() { + return smsNotifications; + } + + /** + * @return the smsToEmailActive + */ + public boolean isSmsToEmailActive() { + return smsToEmailActive; + } + + /** + * @return the smsToEmailSubject + */ + public boolean isSmsToEmailSubject() { + return smsToEmailSubject; + } + + /** + * @return the spam + */ + public String getSpam() { + return spam; + } + + /** + * @return the timezone + */ + public String getTimezone() { + return timezone; + } + + /** + * @return the useDidAsCallerId + */ + public boolean isUseDidAsCallerId() { + return useDidAsCallerId; + } + + /** + * @return the useDidAsSource + */ + public boolean isUseDidAsSource() { + return useDidAsSource; + } + + /** + * @param mActiveForwardingList the mActiveForwardingList to set + */ + public void setmActiveForwardingList(int[] mActiveForwardingList) { + this.mActiveForwardingList = mActiveForwardingList; + } + + /** + * @param baseUrl the baseUrl to set + */ + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + } + + /** + * @param credits the credits to set + */ + public void setCredits(int credits) { + this.credits = credits; + } + + /** + * @param defaultGreetingId the defaultGreetingId to set + */ + public void setDefaultGreetingId(int defaultGreetingId) { + this.defaultGreetingId = defaultGreetingId; + } + + /** + * @param mDidInfos the mDidInfos to set + */ + public void setmDidInfos(String[] mDidInfos) { + this.mDidInfos = mDidInfos; + } + + /** + * @param directConnect the directConnect to set + */ + public void setDirectConnect(boolean directConnect) { + this.directConnect = directConnect; + } + + /** + * @param mDisabledIdMap the mDisabledIdMap to set + */ + public void setmDisabledIdList(DisabledId[] mDisabledIdList) { + this.mDisabledIdMap = mDisabledIdList; + } + + /** + * @param doNotDisturb the doNotDisturb to set + */ + public void setDoNotDisturb(boolean doNotDisturb) { + this.doNotDisturb = doNotDisturb; + } + + /** + * @param emailAddresses the emailAddresses to set + */ + public void setEmailAddresses(EmailAddress[] emailAddresses) { + this.emailAddresses = emailAddresses; + } + + /** + * @param emailNotificationActive the emailNotificationActive to set + */ + public void setEmailNotificationActive(boolean emailNotificationActive) { + this.emailNotificationActive = emailNotificationActive; + } + + /** + * @param emailNotificationAddress the emailNotificationAddress to set + */ + public void setEmailNotificationAddress(String emailNotificationAddress) { + this.emailNotificationAddress = emailNotificationAddress; + } + + /** + * @param greetings the greetings to set + */ + public void setGreetings(Greeting[] greetings) { + this.greetings = greetings; + } + + /** + * @param groupList the groupList to set + */ + public void setGroupList(String[] groupList) { + this.groupList = groupList; + } + + /** + * @param groups the groups to set + */ + public void setGroups(Group[] groups) { + this.groups = groups; + } + + /** + * @param language the language to set + */ + public void setLanguage(String language) { + this.language = language; + } + + /** + * @param primaryDid the primaryDid to set + */ + public void setPrimaryDid(String primaryDid) { + this.primaryDid = primaryDid; + } + + /** + * @param screenBehavior the screenBehavior to set + */ + public void setScreenBehavior(int screenBehavior) { + this.screenBehavior = screenBehavior; + } + + /** + * @param showTranscripts the showTranscripts to set + */ + public void setShowTranscripts(boolean showTranscripts) { + this.showTranscripts = showTranscripts; + } + + /** + * @param smsNotifications the smsNotifications to set + */ + public void setSmsNotifications(String[] smsNotifications) { + this.smsNotifications = smsNotifications; + } + + /** + * @param smsToEmailActive the smsToEmailActive to set + */ + public void setSmsToEmailActive(boolean smsToEmailActive) { + this.smsToEmailActive = smsToEmailActive; + } + + /** + * @param smsToEmailSubject the smsToEmailSubject to set + */ + public void setSmsToEmailSubject(boolean smsToEmailSubject) { + this.smsToEmailSubject = smsToEmailSubject; + } + + /** + * @param spam the spam to set + */ + public void setSpam(String spam) { + this.spam = spam; + } + + /** + * @param timezone the timezone to set + */ + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + /** + * @param useDidAsCallerId the useDidAsCallerId to set + */ + public void setUseDidAsCallerId(boolean useDidAsCallerId) { + this.useDidAsCallerId = useDidAsCallerId; + } + + /** + * @param useDidAsSource the useDidAsSource to set + */ + public void setUseDidAsSource(boolean useDidAsSource) { + this.useDidAsSource = useDidAsSource; + } + + + +} diff --git a/src/com/techventus/server/voice/datatypes/Wd.java b/src/main/java/com/techventus/server/voice/datatypes/Wd.java similarity index 68% rename from src/com/techventus/server/voice/datatypes/Wd.java rename to src/main/java/com/techventus/server/voice/datatypes/Wd.java index e864615..60db504 100644 --- a/src/com/techventus/server/voice/datatypes/Wd.java +++ b/src/main/java/com/techventus/server/voice/datatypes/Wd.java @@ -1,25 +1,25 @@ - -package com.techventus.server.voice.datatypes; - -import java.util.List; -/** - * Weekday setting of a phone - * - */ -public class Wd{ - private boolean allDay; - private List times; - - public boolean getAllDay(){ - return this.allDay; - } - public void setAllDay(boolean allDay){ - this.allDay = allDay; - } - public List getTimes(){ - return this.times; - } - public void setTimes(List times){ - this.times = times; - } -} + +package com.techventus.server.voice.datatypes; + +import java.util.List; +/** + * Weekday setting of a phone + * + */ +public class Wd{ + private boolean allDay; + private List times; + + public boolean getAllDay(){ + return this.allDay; + } + public void setAllDay(boolean allDay){ + this.allDay = allDay; + } + public List getTimes(){ + return this.times; + } + public void setTimes(List times){ + this.times = times; + } +} diff --git a/src/com/techventus/server/voice/datatypes/We.java b/src/main/java/com/techventus/server/voice/datatypes/We.java similarity index 67% rename from src/com/techventus/server/voice/datatypes/We.java rename to src/main/java/com/techventus/server/voice/datatypes/We.java index 49fafe8..bdf70be 100644 --- a/src/com/techventus/server/voice/datatypes/We.java +++ b/src/main/java/com/techventus/server/voice/datatypes/We.java @@ -1,26 +1,26 @@ - -package com.techventus.server.voice.datatypes; - -import java.util.List; -/** - * - * Weekend setting of a phone - * - */ -public class We{ - private boolean allDay; - private List times; - - public boolean getAllDay(){ - return this.allDay; - } - public void setAllDay(boolean allDay){ - this.allDay = allDay; - } - public List getTimes(){ - return this.times; - } - public void setTimes(List times){ - this.times = times; - } -} + +package com.techventus.server.voice.datatypes; + +import java.util.List; +/** + * + * Weekend setting of a phone + * + */ +public class We{ + private boolean allDay; + private List times; + + public boolean getAllDay(){ + return this.allDay; + } + public void setAllDay(boolean allDay){ + this.allDay = allDay; + } + public List getTimes(){ + return this.times; + } + public void setTimes(List times){ + this.times = times; + } +} diff --git a/src/com/techventus/server/voice/datatypes/WebCallButton.java b/src/main/java/com/techventus/server/voice/datatypes/WebCallButton.java similarity index 96% rename from src/com/techventus/server/voice/datatypes/WebCallButton.java rename to src/main/java/com/techventus/server/voice/datatypes/WebCallButton.java index 1930d4a..1e16027 100644 --- a/src/com/techventus/server/voice/datatypes/WebCallButton.java +++ b/src/main/java/com/techventus/server/voice/datatypes/WebCallButton.java @@ -1,5 +1,5 @@ /** - * + * */ package com.techventus.server.voice.datatypes; diff --git a/src/com/techventus/server/voice/datatypes/records/Call.java b/src/main/java/com/techventus/server/voice/datatypes/records/Call.java similarity index 99% rename from src/com/techventus/server/voice/datatypes/records/Call.java rename to src/main/java/com/techventus/server/voice/datatypes/records/Call.java index fc4cd28..f4c4fbc 100644 --- a/src/com/techventus/server/voice/datatypes/records/Call.java +++ b/src/main/java/com/techventus/server/voice/datatypes/records/Call.java @@ -20,7 +20,7 @@ public Call(String id, String title, Date date, Contact contact, boolean read) { super(id, title, date, contact, read); // TODO Auto-generated constructor stub } - + @Override public String toString() { String ret = ""; @@ -40,5 +40,5 @@ public String toString() { return ret; } - + } diff --git a/src/com/techventus/server/voice/datatypes/records/Record.java b/src/main/java/com/techventus/server/voice/datatypes/records/Record.java similarity index 98% rename from src/com/techventus/server/voice/datatypes/records/Record.java rename to src/main/java/com/techventus/server/voice/datatypes/records/Record.java index 8b172e5..9bdb503 100644 --- a/src/com/techventus/server/voice/datatypes/records/Record.java +++ b/src/main/java/com/techventus/server/voice/datatypes/records/Record.java @@ -6,12 +6,12 @@ /** - * + * * A Record is one entry in a Voice record list(like the Inbox) - * An implemented Class is a call entry or an SMS or a Voicemail - * + * An implemented Class is a call entry or an SMS or a Voicemail + * * TODO give better name? - * + * * @author Tobias Eisentraeger * */ @@ -26,7 +26,7 @@ public abstract class Record { protected Contact contact; /** true if the message is read, false if not **/ protected boolean read; - + public Record(String id, String title, Date date, Contact contact, boolean read) { super(); this.id = id; @@ -35,7 +35,7 @@ public Record(String id, String title, Date date, Contact contact, boolean read) this.contact = contact; this.read = read; } - + /** * @return the id */ @@ -51,7 +51,7 @@ public String getId() { public void setId(String id) { this.id = id; } - + /** * Gets a boolean for whether or not the conversation has been read. * @@ -99,7 +99,7 @@ public void setContact(Contact pContact) { } /** Returns a String representation **/ public abstract String toString(); - + public boolean isVoicemail() { if(this instanceof Voicemail) { return true; @@ -121,5 +121,5 @@ public boolean isShortMessage() { return false; } } - + } diff --git a/src/com/techventus/server/voice/datatypes/records/SMS.java b/src/main/java/com/techventus/server/voice/datatypes/records/SMS.java similarity index 98% rename from src/com/techventus/server/voice/datatypes/records/SMS.java rename to src/main/java/com/techventus/server/voice/datatypes/records/SMS.java index c46962a..fe06e27 100644 --- a/src/com/techventus/server/voice/datatypes/records/SMS.java +++ b/src/main/java/com/techventus/server/voice/datatypes/records/SMS.java @@ -6,9 +6,9 @@ /** * Represents a SMS message. - * + * * @author Tiago Proenca (tproenca) - * + * */ public class SMS implements Comparable { @@ -23,7 +23,7 @@ public class SMS implements Comparable { /** * Creates a SMS instance. - * + * * @param from * the contact that sent the message * @param the @@ -39,7 +39,7 @@ public SMS(Contact from, String content, Date dateTime) { /** * Returns the contact that sent the message. - * + * * @return the contact that sent the message */ public Contact getFrom() { @@ -48,7 +48,7 @@ public Contact getFrom() { /** * Returns the message's content. - * + * * @return the message's content */ public String getContent() { @@ -57,7 +57,7 @@ public String getContent() { /** * Returns the message's timestamp. - * + * * @return the message's timestamp */ public Date getDateTime() { @@ -66,7 +66,7 @@ public Date getDateTime() { /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ @Override diff --git a/src/com/techventus/server/voice/datatypes/records/SMSThread.java b/src/main/java/com/techventus/server/voice/datatypes/records/SMSThread.java similarity index 97% rename from src/com/techventus/server/voice/datatypes/records/SMSThread.java rename to src/main/java/com/techventus/server/voice/datatypes/records/SMSThread.java index 7fbfed0..d84536f 100644 --- a/src/com/techventus/server/voice/datatypes/records/SMSThread.java +++ b/src/main/java/com/techventus/server/voice/datatypes/records/SMSThread.java @@ -9,9 +9,9 @@ /** * Represents a thread of SMS messages. - * + * * @author Tiago Proenca (tproenca) - * + * */ public class SMSThread extends Record { @@ -23,7 +23,7 @@ public class SMSThread extends Record { /** * Creates a SMSThread instance. - * + * * @param id * the thread's ID * @param note @@ -45,7 +45,7 @@ public SMSThread(String id, String note, Date date, Contact contact, /** * Adds a SMS object to this thread. - * + * * @param sms * a SMS object. */ @@ -55,7 +55,7 @@ public void addSMS(SMS sms) { /** * Removes a SMS object from this thread. - * + * * @param sms * a SMS object. */ @@ -65,7 +65,7 @@ public void removeSMS(SMS sms) { /** * Returns all SMS that exist in this thread. - * + * * @return all SMS objects. */ public Collection getAllSMS() { @@ -74,7 +74,7 @@ public Collection getAllSMS() { /** * Returns the thread's note. - * + * * @return the thread's note. */ public String getNote() { @@ -83,7 +83,7 @@ public String getNote() { /** * Returns whether this thread is starred. - * + * * @return whether this thread is starred */ public boolean isStarred() { @@ -92,7 +92,7 @@ public boolean isStarred() { /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ @Override diff --git a/src/com/techventus/server/voice/datatypes/records/ShortMessage.java b/src/main/java/com/techventus/server/voice/datatypes/records/ShortMessage.java similarity index 99% rename from src/com/techventus/server/voice/datatypes/records/ShortMessage.java rename to src/main/java/com/techventus/server/voice/datatypes/records/ShortMessage.java index d33bfab..a851239 100644 --- a/src/com/techventus/server/voice/datatypes/records/ShortMessage.java +++ b/src/main/java/com/techventus/server/voice/datatypes/records/ShortMessage.java @@ -20,7 +20,7 @@ public ShortMessage(String id, String title, Date date, Contact contact, boolean super(id, title, date, contact, read); // TODO Auto-generated constructor stub } - + @Override public String toString() { String ret = ""; @@ -41,5 +41,5 @@ public String toString() { } - + } diff --git a/src/com/techventus/server/voice/datatypes/records/Transcript.java b/src/main/java/com/techventus/server/voice/datatypes/records/Transcript.java similarity index 100% rename from src/com/techventus/server/voice/datatypes/records/Transcript.java rename to src/main/java/com/techventus/server/voice/datatypes/records/Transcript.java diff --git a/src/com/techventus/server/voice/datatypes/records/TranscriptElement.java b/src/main/java/com/techventus/server/voice/datatypes/records/TranscriptElement.java similarity index 97% rename from src/com/techventus/server/voice/datatypes/records/TranscriptElement.java rename to src/main/java/com/techventus/server/voice/datatypes/records/TranscriptElement.java index 45d271d..2098fef 100644 --- a/src/com/techventus/server/voice/datatypes/records/TranscriptElement.java +++ b/src/main/java/com/techventus/server/voice/datatypes/records/TranscriptElement.java @@ -4,9 +4,9 @@ /** * One Element in a Transcript - normally a word. - * Each Element has a ReccognitionLevel indicating how sure google is + * Each Element has a ReccognitionLevel indicating how sure google is * that the word is recognised correctly. - * + * * @author Tobias Eisentraeger * */ @@ -20,7 +20,7 @@ public enum RecognitionLevel { HIGH, UNKNOWN; } - + /** * Standard constructor * @param text @@ -32,7 +32,7 @@ public TranscriptElement(String text, String id, RecognitionLevel level) { this.id = id; this.level = level; } - + /** * Creates a TranscriptElement based on the html, for example: * Hello World! @@ -41,26 +41,26 @@ public TranscriptElement(String text, String id, RecognitionLevel level) { public static TranscriptElement extractTransscriptElement(String html) { String lId; try { - lId = ParsingUtil.removeUninterestingParts(html,"id=\"","\"",false); + lId = ParsingUtil.removeUninterestingParts(html,"id=\"","\"",false); } catch (Exception e) { lId = ""; } - + String levelSt; try { - levelSt = ParsingUtil.removeUninterestingParts(html,"class=\"gc-word-","\"",false); + levelSt = ParsingUtil.removeUninterestingParts(html,"class=\"gc-word-","\"",false); } catch (Exception e) { levelSt = ""; } - + String ltext; try { - ltext = ParsingUtil.removeUninterestingParts(html,">","",false); + ltext = ParsingUtil.removeUninterestingParts(html,">","",false); ltext = ParsingUtil.htmlEntitiesDecode(ltext); } catch (Exception e) { ltext = ""; } - + if(levelSt!=null) { if(levelSt.equals("med1")) { return new TranscriptElement(ltext, lId, RecognitionLevel.MED1); @@ -117,6 +117,6 @@ public RecognitionLevel getLevel() { public void setLevel(RecognitionLevel level) { this.level = level; } - - + + } diff --git a/src/com/techventus/server/voice/datatypes/records/Voicemail.java b/src/main/java/com/techventus/server/voice/datatypes/records/Voicemail.java similarity index 98% rename from src/com/techventus/server/voice/datatypes/records/Voicemail.java rename to src/main/java/com/techventus/server/voice/datatypes/records/Voicemail.java index 79bd717..a19cbd4 100644 --- a/src/com/techventus/server/voice/datatypes/records/Voicemail.java +++ b/src/main/java/com/techventus/server/voice/datatypes/records/Voicemail.java @@ -6,7 +6,7 @@ /** - * + * * @author Tobias Eisentraeger * */ @@ -16,9 +16,9 @@ public class Voicemail extends Record { private Transcript transcript; /** The url of the mp3 file with the voicemail **/ private String mp3Url; - + /** - * + * * @param title * @param date * @param contact @@ -29,7 +29,7 @@ public Voicemail(String id, String title, Date date, Contact contact, Transcript this.transcript = transcript; this.mp3Url = "https://www.google.com/voice/media/send_voicemail/"+id; } - + @Override public void setId(String id) { this.id = id; @@ -63,8 +63,8 @@ public String getMp3Url() { public void setMp3Url(String mp3Url) { this.mp3Url = mp3Url; } - - + + @Override public String toString() { String ret = ""; @@ -89,9 +89,9 @@ public String toString() { ret+="read="+read+";"; return ret; } - - - - + + + + } diff --git a/src/com/techventus/server/voice/exception/AccountDeletedException.java b/src/main/java/com/techventus/server/voice/exception/AccountDeletedException.java similarity index 100% rename from src/com/techventus/server/voice/exception/AccountDeletedException.java rename to src/main/java/com/techventus/server/voice/exception/AccountDeletedException.java diff --git a/src/com/techventus/server/voice/exception/AccountDisabledException.java b/src/main/java/com/techventus/server/voice/exception/AccountDisabledException.java similarity index 100% rename from src/com/techventus/server/voice/exception/AccountDisabledException.java rename to src/main/java/com/techventus/server/voice/exception/AccountDisabledException.java diff --git a/src/com/techventus/server/voice/exception/AuthenticationException.java b/src/main/java/com/techventus/server/voice/exception/AuthenticationException.java similarity index 100% rename from src/com/techventus/server/voice/exception/AuthenticationException.java rename to src/main/java/com/techventus/server/voice/exception/AuthenticationException.java diff --git a/src/com/techventus/server/voice/exception/BadAuthenticationException.java b/src/main/java/com/techventus/server/voice/exception/BadAuthenticationException.java similarity index 100% rename from src/com/techventus/server/voice/exception/BadAuthenticationException.java rename to src/main/java/com/techventus/server/voice/exception/BadAuthenticationException.java diff --git a/src/com/techventus/server/voice/exception/CaptchaRequiredException.java b/src/main/java/com/techventus/server/voice/exception/CaptchaRequiredException.java similarity index 100% rename from src/com/techventus/server/voice/exception/CaptchaRequiredException.java rename to src/main/java/com/techventus/server/voice/exception/CaptchaRequiredException.java diff --git a/src/com/techventus/server/voice/exception/ERROR_CODE.java b/src/main/java/com/techventus/server/voice/exception/ERROR_CODE.java similarity index 100% rename from src/com/techventus/server/voice/exception/ERROR_CODE.java rename to src/main/java/com/techventus/server/voice/exception/ERROR_CODE.java diff --git a/src/com/techventus/server/voice/exception/NotVerifiedException.java b/src/main/java/com/techventus/server/voice/exception/NotVerifiedException.java similarity index 100% rename from src/com/techventus/server/voice/exception/NotVerifiedException.java rename to src/main/java/com/techventus/server/voice/exception/NotVerifiedException.java diff --git a/src/com/techventus/server/voice/exception/ServiceDisabledException.java b/src/main/java/com/techventus/server/voice/exception/ServiceDisabledException.java similarity index 100% rename from src/com/techventus/server/voice/exception/ServiceDisabledException.java rename to src/main/java/com/techventus/server/voice/exception/ServiceDisabledException.java diff --git a/src/com/techventus/server/voice/exception/ServiceUnavailableException.java b/src/main/java/com/techventus/server/voice/exception/ServiceUnavailableException.java similarity index 100% rename from src/com/techventus/server/voice/exception/ServiceUnavailableException.java rename to src/main/java/com/techventus/server/voice/exception/ServiceUnavailableException.java diff --git a/src/com/techventus/server/voice/exception/TermsNotAgreedException.java b/src/main/java/com/techventus/server/voice/exception/TermsNotAgreedException.java similarity index 100% rename from src/com/techventus/server/voice/exception/TermsNotAgreedException.java rename to src/main/java/com/techventus/server/voice/exception/TermsNotAgreedException.java diff --git a/src/main/java/com/techventus/server/voice/util/ArrayUtil.java b/src/main/java/com/techventus/server/voice/util/ArrayUtil.java new file mode 100644 index 0000000..ccc76f2 --- /dev/null +++ b/src/main/java/com/techventus/server/voice/util/ArrayUtil.java @@ -0,0 +1,73 @@ +package com.techventus.server.voice.util; + +import java.util.Collection; + +/** + * Created by josephmalone on 2016-11-18. + */ +public class ArrayUtil { + public static boolean isNullOrContainsEmpty(T[] array) + { + if (array == null || array.length == 0) + { + return true; + } + + for (T val : array) + { + if (val == null) + { + return true; + } + } + + return false; + } + + public static boolean isNullOrEmpty(Collection collection) + { + return collection == null || collection.isEmpty(); + } + + /** + *

Checks if a CharSequence is empty ("") or null.

+ * + *
+     * StringUtils.isEmpty(null)      = true
+     * StringUtils.isEmpty("")        = true
+     * StringUtils.isEmpty(" ")       = false
+     * StringUtils.isEmpty("bob")     = false
+     * StringUtils.isEmpty("  bob  ") = false
+     * 
+ * + *

NOTE: This method changed in Lang version 2.0. + * It no longer trims the CharSequence. + * That functionality is available in isBlank().

+ * + * @param cs the CharSequence to check, may be null + * @return {@code true} if the CharSequence is empty or null + * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence) + */ + public static boolean isEmpty(final CharSequence cs) { + return cs == null || cs.length() == 0; + } + + /** + *

Checks if a CharSequence is not empty ("") and not null.

+ * + *
+     * StringUtils.isNotEmpty(null)      = false
+     * StringUtils.isNotEmpty("")        = false
+     * StringUtils.isNotEmpty(" ")       = true
+     * StringUtils.isNotEmpty("bob")     = true
+     * StringUtils.isNotEmpty("  bob  ") = true
+     * 
+ * + * @param cs the CharSequence to check, may be null + * @return {@code true} if the CharSequence is not empty and not null + * @since 3.0 Changed signature from isNotEmpty(String) to isNotEmpty(CharSequence) + */ + public static boolean isNotEmpty(final CharSequence cs) { + return !isEmpty(cs); + } +} diff --git a/src/com/techventus/server/voice/util/JSONContants.java b/src/main/java/com/techventus/server/voice/util/JSONContants.java similarity index 100% rename from src/com/techventus/server/voice/util/JSONContants.java rename to src/main/java/com/techventus/server/voice/util/JSONContants.java diff --git a/src/com/techventus/server/voice/util/ParsingUtil.java b/src/main/java/com/techventus/server/voice/util/ParsingUtil.java similarity index 97% rename from src/com/techventus/server/voice/util/ParsingUtil.java rename to src/main/java/com/techventus/server/voice/util/ParsingUtil.java index dd94e99..32aad7b 100644 --- a/src/com/techventus/server/voice/util/ParsingUtil.java +++ b/src/main/java/com/techventus/server/voice/util/ParsingUtil.java @@ -9,7 +9,7 @@ /** * Collection of useful html parsing methods - * + * * @author Tobias Eisentraeger * */ @@ -35,7 +35,7 @@ public static final String removeUninterestingParts(String text, String startBor String ret=""; try { if(text!=null&&startBorder!=null&&endBorder!=null&&(text.indexOf(startBorder)!=-1)&&(text.indexOf(endBorder)!=-1) ) { - + if(includeBorders) { text = text.substring(text.indexOf(startBorder)); if(text!=null) { @@ -51,7 +51,7 @@ public static final String removeUninterestingParts(String text, String startBor ret = null; } } - + } else { ret = null; } @@ -65,8 +65,8 @@ public static final String removeUninterestingParts(String text, String startBor } return ret; } - - + + //TODO use Apache commons StringEscapeUtils.unescapeHTML() ? /** * Replaces some speciel htmlEntities with a corresponding String. @@ -75,13 +75,13 @@ public static final String removeUninterestingParts(String text, String startBor * @return the Decoded HTML in String format */ public static String htmlEntitiesDecode(String s) { - s=s.replaceAll("'", "'"); + s=s.replaceAll("'", "'"); return s; } - + /** * Json int array to int array. - * + * * @param array the array * @return the int[] */ @@ -96,10 +96,10 @@ public static final int[] jsonIntArrayToIntArray(JSONArray array) { } return result; } - + /** * Json string array to string array. - * + * * @param array the array * @return the string[] */ @@ -114,10 +114,10 @@ public static final String[] jsonStringArrayToStringArray(JSONArray array) { } return result; } - + /** * Json string array to string list. - * + * * @param settingsJSON the settings json * @param stringList the string list * @param key the key @@ -131,10 +131,10 @@ public static final List jsonStringArrayToStringList(JSONObject settings } return stringList; } - + /** * Converts a Json Integer array to an ArrayList of Integers. - * + * * @param settingsJSON the settings json * @param integerList the integer list * @param key the key corresponding to the JSON formatted integer array @@ -149,18 +149,18 @@ public static final List jsonIntArrayToIntegerList(JSONObject settingsJ } return integerList; } - + /** * String list to JSON array. - * + * * @param stringList the string list input * @return the JSON array * @throws JSONException the JSON exception */ - public static final JSONArray stringListToJsonArray(List stringList) throws JSONException { + public static final JSONArray stringListToJsonArray(List stringList) throws JSONException { String[] lArray = (String[]) stringList.toArray(new String[stringList.size()]); return new JSONArray(lArray); } - - + + } \ No newline at end of file diff --git a/src/com/techventus/server/voice/util/SMSParser.java b/src/main/java/com/techventus/server/voice/util/SMSParser.java similarity index 97% rename from src/com/techventus/server/voice/util/SMSParser.java rename to src/main/java/com/techventus/server/voice/util/SMSParser.java index 92749b9..a835787 100644 --- a/src/com/techventus/server/voice/util/SMSParser.java +++ b/src/main/java/com/techventus/server/voice/util/SMSParser.java @@ -7,12 +7,7 @@ import java.io.StringReader; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import org.dom4j.Document; import org.dom4j.Element; @@ -26,9 +21,9 @@ /** * This class parses the SMS messages from the Google Voice XML response. - * + * * @author Tiago Proenca (tproenca) - * + * */ public class SMSParser { @@ -40,7 +35,7 @@ public class SMSParser { /** * Creates a SMSParser instance. - * + * * @param response * the server's HTML response. * @param me @@ -53,7 +48,7 @@ public SMSParser(String response, Contact me) { /** * Creates a SMSParser instance. - * + * * @param response * the server's HTML response. * @param myPhoneNumber @@ -66,7 +61,7 @@ public SMSParser(String response, String myPhoneNumber) { /** * Returns the SMS threads. - * + * * @return the SMS threads. */ public Collection getSMSThreads() { @@ -120,7 +115,7 @@ public void write(int b) { // } // if(contact==null){ // System.err.println("NULL CONTACT "+element); -// +// // } SMSThread smsthread = threadMap.get(element.attribute( GoogleVoice.THREAD_ID).getText()); @@ -133,7 +128,7 @@ public void write(int b) { /** * Parses the contact information from the DOM Element. - * + * * @param element * the DOM Element * @return the Contact @@ -147,13 +142,13 @@ private Contact parseContact(Element element) { .selectSingleNode(XPathQuery.MESSAGE_PORTRAIT)); String phoneNumber = phoneNumberNode == null ? name : parsePhoneNumber(phoneNumberNode.getText()); - - + + //TODO TEST SIMPLIFY // System.out.println("Parsing Contact..."); //JLM Phone Number Correction List e = element.selectNodes(XPathQuery.MESSAGE_QUICKCALL); - + for(Object o:e){ Node n = (Node)o; String res = n.selectSingleNode(XPathQuery.MESSAGE_BOLD).getText(); @@ -164,16 +159,16 @@ private Contact parseContact(Element element) { phoneNumber = "+1" + phoneNumber; } // System.out.println(phoneNumber); - - } - - + + } + + return new Contact(name, "", phoneNumber, imgURL); } /** * Adds SMSs to their respective thread. - * + * * @param thread * the SMSThread object. * @param messages @@ -181,9 +176,10 @@ private Contact parseContact(Element element) { */ private void addSMSsToThread(SMSThread thread, Element messages) { SimpleDateFormat dateFormat = new SimpleDateFormat( - GoogleVoice.DATE_FORMAT); + GoogleVoice.DATE_FORMAT, Locale.US); SimpleDateFormat dateTimeFormat = new SimpleDateFormat( - GoogleVoice.DATETIME_FORMAT); + GoogleVoice.DATETIME_FORMAT,Locale.US); + @SuppressWarnings("unchecked") List elements = messages .selectNodes(XPathQuery.MESSAGE_SMS_ROW); @@ -206,6 +202,10 @@ private void addSMSsToThread(SMSThread thread, Element messages) { && from.equals(GoogleVoice.CONTACT_ME)) { contact = me; } + Date t = new Date(); + System.out.println("parse datetimeformat "+dateTimeFormat.format(t)); + System.out.println("parse dateFormat "+dateFormat.format(t)); + Date time = dateTimeFormat.parse(dateFormat.format(thread .getDate()) + " " + dateTime); @@ -224,7 +224,7 @@ private void addSMSsToThread(SMSThread thread, Element messages) { * Builds a map between the thread id and a SMSThread object. Since we need * to look for a SMSThread object quite often, this approach is preferable * than a List, since it reduces the lookup operations from O(n) to O(1). - * + * * @param response * the server's HTML response. * @return a map between the thread id and a SMSThread object. @@ -266,7 +266,7 @@ private Map buildSMSThreadMap(String response) { /** * Parses the contact's phone number from the server's HTML response. - * + * * @param phoneNumber * the phone number from the server's HTML response. * @return the contact's phone number. @@ -281,7 +281,7 @@ private String parsePhoneNumber(String phoneNumber) { /** * Parses the contact's image URL from the DOM Element. - * + * * @param element * the DOM Element * @return the contact's image URL. diff --git a/src/main/kotlin/.gitkeep b/src/main/kotlin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/.gitkeep b/src/main/resources/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/.gitkeep b/src/test/java/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/techventus/server/voice/GVCookieManagerTest.java b/src/test/java/com/techventus/server/voice/GVCookieManagerTest.java new file mode 100644 index 0000000..02e0d70 --- /dev/null +++ b/src/test/java/com/techventus/server/voice/GVCookieManagerTest.java @@ -0,0 +1,108 @@ +package com.techventus.server.voice; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Map; +import java.util.Properties; + +public class GVCookieManagerTest { + + private static final String TEST_PROPERTIES_FILENAME = "google-auth.properties"; + // Store the properties file in the same directory as the test class, + // assuming the build system adds this to the classpath. + private static final File TEST_PROPERTIES_FILE = new File("src/test/com/techventus/server/voice/" + TEST_PROPERTIES_FILENAME); + + @Before + public void setUp() throws IOException { + // Create a dummy google-auth.properties file for testing + Properties props = new Properties(); + props.setProperty("COOKIE_ONE", "VALUE_ONE"); + props.setProperty("COOKIE_TWO", "VALUE_TWO"); + props.setProperty("SID", "TEST_SID_VALUE"); + + OutputStream output = null; + try { + // Ensure parent directory exists + TEST_PROPERTIES_FILE.getParentFile().mkdirs(); + output = new FileOutputStream(TEST_PROPERTIES_FILE); + props.store(output, "Test cookies for GVCookieManagerTest"); + } finally { + if (output != null) { + try { + output.close(); + } catch (IOException e) { + // Ignore + } + } + } + + // Reset GVCookieManager's cookies before each test. + // This is a simplified approach. A more robust way might involve + // resetting the singleton instance or having a dedicated clear/reload method. + if (GVCookieManager.getInstance() != null) { + GVCookieManager.getInstance().clearCookies(); + // Manually trigger reload for the test, as the constructor might not re-run + // or might not find the file if classpath issues exist during test execution. + // This relies on the fact that COOKIE_MAP is static or the instance is a singleton. + // The actual GVCookieManager.loadCookiesFromFile() is private, so we can't call it directly. + // We rely on the constructor calling it. For testing, we might need to expose a reload method + // or use reflection if this proves insufficient. + // For now, clearing and getting a new instance (if possible) or just re-evaluating after clear. + // The current GVCookieManager loads in its constructor, so clearing and then + // re-accessing the map via getInstance() should show the effects of the new file + // IF the classloader picks up the new file. + // The most reliable way is that GVCookieManager's constructor is called again + // or it has a public method to reload. + // Let's assume for now clearing existing cookies and then relying on a fresh load + // when getInstance() is called if the instance was null, or that the existing instance's map is tested. + // The critical part is that loadCookiesFromFile() populates COOKIE_MAP. + } + } + + @Test + public void testLoadCookiesFromFile() { + // Force GVCookieManager to load from the properties file by getting the instance. + // The setUp method should have cleared previous state and created the new properties file. + // We need to ensure GVCookieManager re-initializes or re-loads. + // One way: If GVCookieManager.mInstance could be set to null (e.g. via reflection or a test-only method) + // For now, we assume that if the properties file is in the classpath, a new instantiation + // or the existing one's loadMap (if called on init) will pick it up. + // The current GVCookieManager loads in its constructor. + // Let's try to force re-initialization by clearing the static map and calling load again. + // This is a bit of a hack due to the singleton nature and private load method. + + GVCookieManager manager = GVCookieManager.getInstance(); // Should trigger load if not already loaded + // or if load is part of constructor logic. + + // If the load happens only once in the constructor and the instance is a singleton, + // we need a way to force a reload or test the map directly after setup. + // The GVCookieManager was modified to call loadCookiesFromFile() in its constructor. + // So, getting the instance *should* have loaded it if it was the first time, + // or if the class was reloaded. + + Map cookies = manager.getCookies(); + + assertNotNull("Cookie map should not be null", cookies); + assertEquals("Should load COOKIE_ONE", "VALUE_ONE", cookies.get("COOKIE_ONE")); + assertEquals("Should load COOKIE_TWO", "VALUE_TWO", cookies.get("COOKIE_TWO")); + assertEquals("Should load SID", "TEST_SID_VALUE", cookies.get("SID")); + assertEquals("Should have loaded 3 cookies", 3, cookies.size()); + } + + @After + public void tearDown() { + // Delete the dummy properties file + if (TEST_PROPERTIES_FILE.exists()) { + TEST_PROPERTIES_FILE.delete(); + } + // Clean up GVCookieManager state if necessary + GVCookieManager.getInstance().clearCookies(); + } +} diff --git a/src/test/datatypes/ActiveForwardingIdTest.java b/src/test/java/datatypes/ActiveForwardingIdTest.java similarity index 100% rename from src/test/datatypes/ActiveForwardingIdTest.java rename to src/test/java/datatypes/ActiveForwardingIdTest.java diff --git a/src/test/datatypes/AllSettingsTest.java b/src/test/java/datatypes/AllSettingsTest.java similarity index 100% rename from src/test/datatypes/AllSettingsTest.java rename to src/test/java/datatypes/AllSettingsTest.java diff --git a/src/test/datatypes/ContactTest.java b/src/test/java/datatypes/ContactTest.java similarity index 100% rename from src/test/datatypes/ContactTest.java rename to src/test/java/datatypes/ContactTest.java diff --git a/src/test/datatypes/DisabledForwardingIdTest.java b/src/test/java/datatypes/DisabledForwardingIdTest.java similarity index 100% rename from src/test/datatypes/DisabledForwardingIdTest.java rename to src/test/java/datatypes/DisabledForwardingIdTest.java diff --git a/src/test/datatypes/DisabledIdTest.java b/src/test/java/datatypes/DisabledIdTest.java similarity index 94% rename from src/test/datatypes/DisabledIdTest.java rename to src/test/java/datatypes/DisabledIdTest.java index d84a260..9cd3640 100644 --- a/src/test/datatypes/DisabledIdTest.java +++ b/src/test/java/datatypes/DisabledIdTest.java @@ -1,140 +1,140 @@ -package test.datatypes; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; - -import gvjava.org.json.JSONArray; -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import org.junit.Test; - -import com.techventus.server.voice.datatypes.DisabledId; - -/** - * - * @author Brett Futral @ Catalyst IT Services - * - */ -public class DisabledIdTest { - - // Golden DisabledId Object - final DisabledId goldDisabledID = new DisabledId("1", false); - - // Test Object - DisabledId testDisabledID; - JSONObject tesJSONtDId = new JSONObject(); - String testString; - List testList = new ArrayList(); - - @Test - public void testDisabledIDJSONNullObjectSaveModeTrue() - throws JSONException { - - final JSONObject testJSONDId = new JSONObject(); - - testDisabledID = new DisabledId(testJSONDId, true); - - Assert.assertNotNull(testDisabledID); - } - - @Test - public void testDisabledIDJSONNullObjectSaveModeFalse() { - - try { - testDisabledID = new DisabledId(tesJSONtDId, false); - } catch (Exception e) { - testDisabledID = goldDisabledID; - } - - Assert.assertEquals(goldDisabledID, testDisabledID); - } - - @Test - public void testDisabledIdJSONSaveModeFalse() throws JSONException { - - tesJSONtDId.put("id", "1"); - tesJSONtDId.put("disabled", false); - - testDisabledID = new DisabledId(tesJSONtDId, false); - - final boolean test = goldDisabledID.toString().equals( - testDisabledID.toString()); - - Assert.assertEquals(true, test); - } - - @Test - public void testDisabledIdJSONSaveModeTrue() throws JSONException { - - tesJSONtDId.put("id", "1"); - tesJSONtDId.put("disabled", false); - - testDisabledID = new DisabledId(tesJSONtDId, true); - - final boolean test = goldDisabledID.toString().equals( - testDisabledID.toString()); - - Assert.assertEquals(true, test); - } - - @Test - public void testCreateDisabledIdListFromJsonPartResponseEmptyString() { - - testString = ""; - - Assert.assertEquals(testList, DisabledId.createDisabledIdListFromJsonPartResponse(testString)); - - } - - @Test - public void testCreateDisabledIdListFromJsonPartResponseNullString() { - - List testNullString = new ArrayList(); - - try { - testNullString = DisabledId.createDisabledIdListFromJsonPartResponse(testString); - } - catch(Exception e) { - testString = "exception Caught"; - } - - Assert.assertEquals(testString = "exception Caught", testString); - Assert.assertEquals(testList, testNullString); - - } - - @Test - public void testCreateDisabledIdListFromJsonPartResponse() throws JSONException { - - final JSONArray testArray = new JSONArray(); - testArray.put("1"); - final JSONObject testObject = testArray.toJSONObject(testArray); - testString = testObject.toString(); - testList.add(goldDisabledID); - - Assert.assertEquals(testList.toString(), DisabledId.createDisabledIdListFromJsonPartResponse(testString).toString()); - - } - - @Test - public void testCreateDisabledIdListFromJsonObjectNullObject() throws JSONException { - - Assert.assertEquals(testList.toString(), DisabledId.createListFromJsonObject(tesJSONtDId).toString()); - - } - - @Test - public void testCreateDisabledIdListFromJsonObject() throws JSONException { - - tesJSONtDId.put("1", false); - testList.add(goldDisabledID); - - Assert.assertEquals(testList.toString(), DisabledId.createListFromJsonObject(tesJSONtDId).toString()); - - } - - -} +package test.datatypes; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; + +import gvjava.org.json.JSONArray; +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import org.junit.Test; + +import com.techventus.server.voice.datatypes.DisabledId; + +/** + * + * @author Brett Futral @ Catalyst IT Services + * + */ +public class DisabledIdTest { + + // Golden DisabledId Object + final DisabledId goldDisabledID = new DisabledId("1", false); + + // Test Object + DisabledId testDisabledID; + JSONObject tesJSONtDId = new JSONObject(); + String testString; + List testList = new ArrayList(); + + @Test + public void testDisabledIDJSONNullObjectSaveModeTrue() + throws JSONException { + + final JSONObject testJSONDId = new JSONObject(); + + testDisabledID = new DisabledId(testJSONDId, true); + + Assert.assertNotNull(testDisabledID); + } + + @Test + public void testDisabledIDJSONNullObjectSaveModeFalse() { + + try { + testDisabledID = new DisabledId(tesJSONtDId, false); + } catch (Exception e) { + testDisabledID = goldDisabledID; + } + + Assert.assertEquals(goldDisabledID, testDisabledID); + } + + @Test + public void testDisabledIdJSONSaveModeFalse() throws JSONException { + + tesJSONtDId.put("id", "1"); + tesJSONtDId.put("disabled", false); + + testDisabledID = new DisabledId(tesJSONtDId, false); + + final boolean test = goldDisabledID.toString().equals( + testDisabledID.toString()); + + Assert.assertEquals(true, test); + } + + @Test + public void testDisabledIdJSONSaveModeTrue() throws JSONException { + + tesJSONtDId.put("id", "1"); + tesJSONtDId.put("disabled", false); + + testDisabledID = new DisabledId(tesJSONtDId, true); + + final boolean test = goldDisabledID.toString().equals( + testDisabledID.toString()); + + Assert.assertEquals(true, test); + } + + @Test + public void testCreateDisabledIdListFromJsonPartResponseEmptyString() { + + testString = ""; + + Assert.assertEquals(testList, DisabledId.createDisabledIdListFromJsonPartResponse(testString)); + + } + + @Test + public void testCreateDisabledIdListFromJsonPartResponseNullString() { + + List testNullString = new ArrayList(); + + try { + testNullString = DisabledId.createDisabledIdListFromJsonPartResponse(testString); + } + catch(Exception e) { + testString = "exception Caught"; + } + + Assert.assertEquals(testString = "exception Caught", testString); + Assert.assertEquals(testList, testNullString); + + } + + @Test + public void testCreateDisabledIdListFromJsonPartResponse() throws JSONException { + + final JSONArray testArray = new JSONArray(); + testArray.put("1"); + final JSONObject testObject = testArray.toJSONObject(testArray); + testString = testObject.toString(); + testList.add(goldDisabledID); + + Assert.assertEquals(testList.toString(), DisabledId.createDisabledIdListFromJsonPartResponse(testString).toString()); + + } + + @Test + public void testCreateDisabledIdListFromJsonObjectNullObject() throws JSONException { + + Assert.assertEquals(testList.toString(), DisabledId.createListFromJsonObject(tesJSONtDId).toString()); + + } + + @Test + public void testCreateDisabledIdListFromJsonObject() throws JSONException { + + tesJSONtDId.put("1", false); + testList.add(goldDisabledID); + + Assert.assertEquals(testList.toString(), DisabledId.createListFromJsonObject(tesJSONtDId).toString()); + + } + + +} diff --git a/src/test/datatypes/EmailAddressTest.java b/src/test/java/datatypes/EmailAddressTest.java similarity index 100% rename from src/test/datatypes/EmailAddressTest.java rename to src/test/java/datatypes/EmailAddressTest.java diff --git a/src/test/datatypes/GreetingTest.java b/src/test/java/datatypes/GreetingTest.java similarity index 100% rename from src/test/datatypes/GreetingTest.java rename to src/test/java/datatypes/GreetingTest.java diff --git a/src/test/datatypes/GroupTest.java b/src/test/java/datatypes/GroupTest.java similarity index 95% rename from src/test/datatypes/GroupTest.java rename to src/test/java/datatypes/GroupTest.java index 5363e9e..84a46e6 100644 --- a/src/test/datatypes/GroupTest.java +++ b/src/test/java/datatypes/GroupTest.java @@ -1,265 +1,265 @@ -package test.datatypes; - -import gvjava.org.json.JSONArray; -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; - -import com.techventus.server.voice.datatypes.DisabledForwardingId; -import com.techventus.server.voice.datatypes.Group; - -/** - * - * @author Brett Futral @ Catalyst IT Services - * - */ -public class GroupTest { - // testGroups - Group testGroup; - Group testGroup1; - Group testGroup2; - Group testGroup3; - - String testString; - String resultString; - private final static String TEST_ID = "testID"; - - // DisabledForwardingIDs - final DisabledForwardingId testDFId = new DisabledForwardingId( - "2", true); - final DisabledForwardingId testDFId1 = new DisabledForwardingId( - "3", true); - - List testList = new ArrayList(); - List testList1 = new ArrayList(); - List resultList = new ArrayList(); - List testGrouplist = new ArrayList(); - - JSONArray testJSArray1 = new JSONArray(); - JSONObject disabledFIDs = new JSONObject(); - JSONObject testJSONOb1 = new JSONObject(); - JSONObject testJSONOb3 = new JSONObject(); - JSONObject testGroupObject = new JSONObject(); - - @Before - public void setUp() throws Exception { - - // Populate DFID List1 - testList1.add(testDFId1); - testList1.add(testDFId); - - // JSON Array to attempt to mirror populated list. - testJSArray1.put(3); - testJSArray1.put(2); - - // New JSON objects to mirror lists above. - final JSONObject disabledFIDs1 = testJSArray1.toJSONObject(testJSArray1); - - // Construct Object 1 - testJSONOb1.put("id", TEST_ID); - testJSONOb1.put("name", "testName"); - testJSONOb1.put("isCustomForwarding", false); - testJSONOb1.put("isCustomGreeting", false); - testJSONOb1.put("isCustomDirectConnect", false); - testJSONOb1.put("directConnect", false); - testJSONOb1.put("greetingId", 0); - testJSONOb1.put("disabledForwardingIds", disabledFIDs); - - // Construct Object 3 - testJSONOb3.put("id", "testID1"); - testJSONOb3.put("name", "testName1"); - testJSONOb3.put("isCustomForwarding", false); - testJSONOb3.put("isCustomGreeting", false); - testJSONOb3.put("isCustomDirectConnect", false); - testJSONOb3.put("directConnect", false); - testJSONOb3.put("greetingId", 0); - testJSONOb3.put("disabledForwardingIds", disabledFIDs1); - - // Instantiate testGroups - testGroup = new Group(TEST_ID, "testName", false, testList, false, - false, false, 0); - testGroup1 = new Group(testJSONOb1); - testGroup2 = new Group("testID1", "testName1", false, testList1, false, - false, false, 0); - testGroup3 = new Group(testJSONOb3); - - } - - @Test - public void testJSONNullGroupObject() throws JSONException { - - - final Group nullGroup = new Group(testGroupObject); - - resultString = "{id=null;name=null;isCustomDirectConnect=false;directConnect=false;isCustomGreeting=false;isCustomForwarding=false;greetingId=0;disabledForwardingIds=null}"; - - Assert.assertEquals(resultString, nullGroup.toString()); - - } - - @Test - public void testJSONGroupObjectEqualsJavaGroupObject() { - - final boolean test = testGroup.toString().equals(testGroup1.toString()); - - Assert.assertEquals(true, test); - } - - @Test - public void testCreateGroupSettingsFromJsonResponse() { - - resultList.add(testGroup); - - testString = "\"groups\":{\"testID\":{\"id\":\"testID\",\"name\":\"testName\",\"disabledForwardingIds\":{1},\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"isCustomDirectConnect\":false,\"directConnect\":false,\"greetingId\":0,\"isCircle\":true,\"isCustomTranscriptionLanguage\":false,\"transcriptionLanguage\":\"\"},\"groupList\""; - - testGrouplist = Group.createGroupSettingsFromJsonResponse(testString); - - Assert.assertEquals(resultList.toString(), testGrouplist.toString()); - } - - @Test - public void testCreateGroupSettingsFromJsonResponseNullDisabledForwardingID() { - - testString = "\"groups\":{\"testID\":{\"id\":\"testID\",\"name\":\"testName\",\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"isCustomDirectConnect\":false,\"directConnect\":false,\"greetingId\":0,\"isCircle\":true,\"isCustomTranscriptionLanguage\":false,\"transcriptionLanguage\":\"\"},\"groupList\""; - - try { - testGrouplist = Group.createGroupSettingsFromJsonResponse(testString); - } - catch(Exception e) { - testGrouplist = resultList; - } - Assert.assertEquals(resultList, testGrouplist); - } - - @Test - public void testCreateGroupSettingsFromJsonResponseEmptyDisabledForwardingID() { - - resultList.add(testGroup); - - testString = "\"groups\":{\"testID\":{\"id\":\"testID\",\"name\":\"testName\",\"disabledForwardingIds\":{},\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"isCustomDirectConnect\":false,\"directConnect\":false,\"greetingId\":0,\"isCircle\":true,\"isCustomTranscriptionLanguage\":false,\"transcriptionLanguage\":\"\"},\"groupList\""; - - testGrouplist = Group.createGroupSettingsFromJsonResponse(testString); - - Assert.assertEquals(resultList.toString(), testGrouplist.toString()); - } - - @Test - public void testListToJson() { - - testGrouplist.add(testGroup1); - testGrouplist.add(testGroup3); - - resultString = "\"groups\":{\"testID\":{\"id\":\"testID\",\"greetingId\":0,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{},\"name\":\"testName\",\"isCustomDirectConnect\":false,\"directConnect\":false},\"testID1\":{\"id\":\"testID1\",\"greetingId\":0,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{\"3\":true,\"2\":true},\"name\":\"testName1\",\"isCustomDirectConnect\":false,\"directConnect\":false}}"; - - Assert.assertEquals(resultString, Group.listToJson(testGrouplist).toString()); - - } - - @Test - public void testCreateArrayFromJsonObject() throws JSONException { - - testGroupObject.put(TEST_ID,testJSONOb1); - - final Group[] resultGroupArray = {testGroup}; - final Group[] testGroupArray = Group.createArrayFromJsonObject(testGroupObject); - - Assert.assertEquals(resultGroupArray[0].toString(), testGroupArray[0].toString()); - - } - - @Test - public void testCreateJSONObjectArrayFromJsonObject() throws JSONException { - - resultString = "{\"testID\":\"{id=testID;name=testName;isCustomDirectConnect=false;directConnect=false;isCustomGreeting=false;isCustomForwarding=false;greetingId=0;disabledForwardingIds=[]}\"}"; - - testGroupObject.put("obj1", testJSONOb1); - - final JSONObject[] testObjectArray = Group.createJSONObjectArrayFromJsonObject(testGroupObject); - - Assert.assertEquals(resultString, testObjectArray[0].toString()); - } - - @Test - public void testCreateJSONObjectFromJsonObject() throws JSONException { - - resultString = "{\"testID\":\"{id=testID;name=testName;isCustomDirectConnect=false;directConnect=false;isCustomGreeting=false;isCustomForwarding=false;greetingId=0;disabledForwardingIds=[]}\"}"; - - testGroupObject.put("obj1", testJSONOb1); - - final JSONObject testObject = Group.createJSONObjectFromJsonObject(testGroupObject); - - Assert.assertEquals(resultString, testObject.toString()); - - } - - @Test - public void testGroupsArrayToJsonObject() throws JSONException { - - resultString = "{\"testID\":{\"id\":\"testID\",\"greetingId\":0,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{},\"name\":\"testName\",\"isCustomDirectConnect\":false,\"directConnect\":false}}"; - - final Group[] testObjectArray = {testGroup}; - - Assert.assertEquals(resultString, Group.groupsArrayToJsonObject(testObjectArray).toString()); - } - - @Test - public void testIsPhoneDisabledFalseNullList() throws JSONException { - - - - final JSONObject testJSONOb4 = new JSONObject(); - testJSONOb4.put("id", TEST_ID); - testJSONOb4.put("name", "testName"); - testJSONOb4.put("isCustomForwarding", false); - testJSONOb4.put("isCustomGreeting", false); - testJSONOb4.put("isCustomDirectConnect", false); - testJSONOb4.put("directConnect", false); - testJSONOb4.put("greetingId", 0); - - final Group testGroup4 = new Group(testJSONOb4); - - final boolean testNullList = testGroup4.isPhoneDisabled(1); - - Assert.assertEquals(false, testNullList); - - - } - - @Test - public void testIsPhoneDisabledFalseEmptyList() { - - final boolean test = testGroup.isPhoneDisabled(1); - final boolean test1 = testGroup1.isPhoneDisabled(1); - - Assert.assertEquals(false, test); - Assert.assertEquals(false, test1); - } - - @Test - public void testIsPhoneDisabledFalseNotInList() throws JSONException { - - final boolean test = testGroup2.isPhoneDisabled(1); - final boolean test1 = testGroup3.isPhoneDisabled(1); - - Assert.assertEquals(false, test); - Assert.assertEquals(false, test1); - } - - @Test - public void testIsPhoneDisabledTrue() throws JSONException { - - final boolean test = testGroup2.isPhoneDisabled(2); - final boolean test1 = testGroup3.isPhoneDisabled(2); - - Assert.assertEquals(true, test); - Assert.assertEquals(true, test1); - } - -} +package test.datatypes; + +import gvjava.org.json.JSONArray; +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; + +import com.techventus.server.voice.datatypes.DisabledForwardingId; +import com.techventus.server.voice.datatypes.Group; + +/** + * + * @author Brett Futral @ Catalyst IT Services + * + */ +public class GroupTest { + // testGroups + Group testGroup; + Group testGroup1; + Group testGroup2; + Group testGroup3; + + String testString; + String resultString; + private final static String TEST_ID = "testID"; + + // DisabledForwardingIDs + final DisabledForwardingId testDFId = new DisabledForwardingId( + "2", true); + final DisabledForwardingId testDFId1 = new DisabledForwardingId( + "3", true); + + List testList = new ArrayList(); + List testList1 = new ArrayList(); + List resultList = new ArrayList(); + List testGrouplist = new ArrayList(); + + JSONArray testJSArray1 = new JSONArray(); + JSONObject disabledFIDs = new JSONObject(); + JSONObject testJSONOb1 = new JSONObject(); + JSONObject testJSONOb3 = new JSONObject(); + JSONObject testGroupObject = new JSONObject(); + + @Before + public void setUp() throws Exception { + + // Populate DFID List1 + testList1.add(testDFId1); + testList1.add(testDFId); + + // JSON Array to attempt to mirror populated list. + testJSArray1.put(3); + testJSArray1.put(2); + + // New JSON objects to mirror lists above. + final JSONObject disabledFIDs1 = testJSArray1.toJSONObject(testJSArray1); + + // Construct Object 1 + testJSONOb1.put("id", TEST_ID); + testJSONOb1.put("name", "testName"); + testJSONOb1.put("isCustomForwarding", false); + testJSONOb1.put("isCustomGreeting", false); + testJSONOb1.put("isCustomDirectConnect", false); + testJSONOb1.put("directConnect", false); + testJSONOb1.put("greetingId", 0); + testJSONOb1.put("disabledForwardingIds", disabledFIDs); + + // Construct Object 3 + testJSONOb3.put("id", "testID1"); + testJSONOb3.put("name", "testName1"); + testJSONOb3.put("isCustomForwarding", false); + testJSONOb3.put("isCustomGreeting", false); + testJSONOb3.put("isCustomDirectConnect", false); + testJSONOb3.put("directConnect", false); + testJSONOb3.put("greetingId", 0); + testJSONOb3.put("disabledForwardingIds", disabledFIDs1); + + // Instantiate testGroups + testGroup = new Group(TEST_ID, "testName", false, testList, false, + false, false, 0); + testGroup1 = new Group(testJSONOb1); + testGroup2 = new Group("testID1", "testName1", false, testList1, false, + false, false, 0); + testGroup3 = new Group(testJSONOb3); + + } + + @Test + public void testJSONNullGroupObject() throws JSONException { + + + final Group nullGroup = new Group(testGroupObject); + + resultString = "{id=null;name=null;isCustomDirectConnect=false;directConnect=false;isCustomGreeting=false;isCustomForwarding=false;greetingId=0;disabledForwardingIds=null}"; + + Assert.assertEquals(resultString, nullGroup.toString()); + + } + + @Test + public void testJSONGroupObjectEqualsJavaGroupObject() { + + final boolean test = testGroup.toString().equals(testGroup1.toString()); + + Assert.assertEquals(true, test); + } + + @Test + public void testCreateGroupSettingsFromJsonResponse() { + + resultList.add(testGroup); + + testString = "\"groups\":{\"testID\":{\"id\":\"testID\",\"name\":\"testName\",\"disabledForwardingIds\":{1},\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"isCustomDirectConnect\":false,\"directConnect\":false,\"greetingId\":0,\"isCircle\":true,\"isCustomTranscriptionLanguage\":false,\"transcriptionLanguage\":\"\"},\"groupList\""; + + testGrouplist = Group.createGroupSettingsFromJsonResponse(testString); + + Assert.assertEquals(resultList.toString(), testGrouplist.toString()); + } + + @Test + public void testCreateGroupSettingsFromJsonResponseNullDisabledForwardingID() { + + testString = "\"groups\":{\"testID\":{\"id\":\"testID\",\"name\":\"testName\",\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"isCustomDirectConnect\":false,\"directConnect\":false,\"greetingId\":0,\"isCircle\":true,\"isCustomTranscriptionLanguage\":false,\"transcriptionLanguage\":\"\"},\"groupList\""; + + try { + testGrouplist = Group.createGroupSettingsFromJsonResponse(testString); + } + catch(Exception e) { + testGrouplist = resultList; + } + Assert.assertEquals(resultList, testGrouplist); + } + + @Test + public void testCreateGroupSettingsFromJsonResponseEmptyDisabledForwardingID() { + + resultList.add(testGroup); + + testString = "\"groups\":{\"testID\":{\"id\":\"testID\",\"name\":\"testName\",\"disabledForwardingIds\":{},\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"isCustomDirectConnect\":false,\"directConnect\":false,\"greetingId\":0,\"isCircle\":true,\"isCustomTranscriptionLanguage\":false,\"transcriptionLanguage\":\"\"},\"groupList\""; + + testGrouplist = Group.createGroupSettingsFromJsonResponse(testString); + + Assert.assertEquals(resultList.toString(), testGrouplist.toString()); + } + + @Test + public void testListToJson() { + + testGrouplist.add(testGroup1); + testGrouplist.add(testGroup3); + + resultString = "\"groups\":{\"testID\":{\"id\":\"testID\",\"greetingId\":0,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{},\"name\":\"testName\",\"isCustomDirectConnect\":false,\"directConnect\":false},\"testID1\":{\"id\":\"testID1\",\"greetingId\":0,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{\"3\":true,\"2\":true},\"name\":\"testName1\",\"isCustomDirectConnect\":false,\"directConnect\":false}}"; + + Assert.assertEquals(resultString, Group.listToJson(testGrouplist).toString()); + + } + + @Test + public void testCreateArrayFromJsonObject() throws JSONException { + + testGroupObject.put(TEST_ID,testJSONOb1); + + final Group[] resultGroupArray = {testGroup}; + final Group[] testGroupArray = Group.createArrayFromJsonObject(testGroupObject); + + Assert.assertEquals(resultGroupArray[0].toString(), testGroupArray[0].toString()); + + } + + @Test + public void testCreateJSONObjectArrayFromJsonObject() throws JSONException { + + resultString = "{\"testID\":\"{id=testID;name=testName;isCustomDirectConnect=false;directConnect=false;isCustomGreeting=false;isCustomForwarding=false;greetingId=0;disabledForwardingIds=[]}\"}"; + + testGroupObject.put("obj1", testJSONOb1); + + final JSONObject[] testObjectArray = Group.createJSONObjectArrayFromJsonObject(testGroupObject); + + Assert.assertEquals(resultString, testObjectArray[0].toString()); + } + + @Test + public void testCreateJSONObjectFromJsonObject() throws JSONException { + + resultString = "{\"testID\":\"{id=testID;name=testName;isCustomDirectConnect=false;directConnect=false;isCustomGreeting=false;isCustomForwarding=false;greetingId=0;disabledForwardingIds=[]}\"}"; + + testGroupObject.put("obj1", testJSONOb1); + + final JSONObject testObject = Group.createJSONObjectFromJsonObject(testGroupObject); + + Assert.assertEquals(resultString, testObject.toString()); + + } + + @Test + public void testGroupsArrayToJsonObject() throws JSONException { + + resultString = "{\"testID\":{\"id\":\"testID\",\"greetingId\":0,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{},\"name\":\"testName\",\"isCustomDirectConnect\":false,\"directConnect\":false}}"; + + final Group[] testObjectArray = {testGroup}; + + Assert.assertEquals(resultString, Group.groupsArrayToJsonObject(testObjectArray).toString()); + } + + @Test + public void testIsPhoneDisabledFalseNullList() throws JSONException { + + + + final JSONObject testJSONOb4 = new JSONObject(); + testJSONOb4.put("id", TEST_ID); + testJSONOb4.put("name", "testName"); + testJSONOb4.put("isCustomForwarding", false); + testJSONOb4.put("isCustomGreeting", false); + testJSONOb4.put("isCustomDirectConnect", false); + testJSONOb4.put("directConnect", false); + testJSONOb4.put("greetingId", 0); + + final Group testGroup4 = new Group(testJSONOb4); + + final boolean testNullList = testGroup4.isPhoneDisabled(1); + + Assert.assertEquals(false, testNullList); + + + } + + @Test + public void testIsPhoneDisabledFalseEmptyList() { + + final boolean test = testGroup.isPhoneDisabled(1); + final boolean test1 = testGroup1.isPhoneDisabled(1); + + Assert.assertEquals(false, test); + Assert.assertEquals(false, test1); + } + + @Test + public void testIsPhoneDisabledFalseNotInList() throws JSONException { + + final boolean test = testGroup2.isPhoneDisabled(1); + final boolean test1 = testGroup3.isPhoneDisabled(1); + + Assert.assertEquals(false, test); + Assert.assertEquals(false, test1); + } + + @Test + public void testIsPhoneDisabledTrue() throws JSONException { + + final boolean test = testGroup2.isPhoneDisabled(2); + final boolean test1 = testGroup3.isPhoneDisabled(2); + + Assert.assertEquals(true, test); + Assert.assertEquals(true, test1); + } + +} diff --git a/src/test/datatypes/PhoneTest.java b/src/test/java/datatypes/PhoneTest.java similarity index 100% rename from src/test/datatypes/PhoneTest.java rename to src/test/java/datatypes/PhoneTest.java diff --git a/src/test/datatypes/SettingTest.java b/src/test/java/datatypes/SettingTest.java similarity index 95% rename from src/test/datatypes/SettingTest.java rename to src/test/java/datatypes/SettingTest.java index 82e9878..e2d4c19 100644 --- a/src/test/datatypes/SettingTest.java +++ b/src/test/java/datatypes/SettingTest.java @@ -1,295 +1,295 @@ -/** - * - */ -package test.datatypes; - -import junit.framework.Assert; -import gvjava.org.json.JSONArray; -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import org.junit.Before; -import org.junit.Test; - -import com.techventus.server.voice.datatypes.DisabledId; -import com.techventus.server.voice.datatypes.Group; -import com.techventus.server.voice.datatypes.Setting; - -/** - * @author Brett Futral @ Catalyst IT Services - * - */ -public class SettingTest { - - Setting testSetting; - Setting testSetting1; - Setting testSetting2; - Group testGroup; - String resultString; - - final static String DIRECT_CONNECT = "directConnect"; - final static String A_F_IDS = "activeForwardingIds"; - final static String BASE_URL = "baseUrl"; - final static String TEST_URL = "testURL"; - final static String CREDITS = "credits"; - final static String DFID = "defaultGreetingId"; - final static String DID_INFOS = "didInfos"; - final static String DID_MAP = "disabledIdMap"; - final static String D_N_D = "doNotDisturb"; - final static String EMAIL_ADD = "emailAddresses"; - final static String EMAIL_NOTE_ACTIVE = "emailNotificationActive"; - final static String TEST_E_ADDRESS = "testEmailAddress"; - final static String EMAIL_NOTE_ADD = "emailNotificationAddress"; - final static String GREETINGS = "greetings"; - final static String GROUPLIST = "groupList"; - final static String GROUPS = "groups"; - final static String LANGUAGE = "language"; - final static String ENGLISH = "English"; - final static String PRIME_DID = "primaryDid"; - final static String TEST_DID = "testDiD"; - final static String SCREEN_BEHAVE = "screenBehavior"; - final static String SHOW_TRANS = "showTranscripts"; - final static String SMS_NOTE = "smsNotifications"; - final static String SMS_EMAIL_ACTIVE = "smsToEmailActive"; - final static String SMS_EMAIL_SUB = "smsToEmailSubject"; - final static String SPAM = "spam"; - final static String TIME_ZONE = "timezone"; - final static String TEST_T_ZONE = "testTimeZone"; - final static String USE_DID_CID = "useDidAsCallerId"; - final static String USE_DID_SOURCE = "useDidAsSource"; - - final JSONArray emptyJSONArray = new JSONArray(); - JSONArray testGroupList = new JSONArray(); - JSONArray testGroupArray = new JSONArray(); - - final JSONObject emptyJSONObject = new JSONObject(); - final static JSONObject TEST_NULL_OBJECT = null; - JSONObject testJSONGroupOb = new JSONObject(); - JSONObject testJSONGroupOb1 = new JSONObject(); - JSONObject jsonPreSetting = new JSONObject(); - JSONObject jsonSetting = new JSONObject(); - JSONObject testJSONObject = new JSONObject(); - - final DisabledId testDisabledID = new DisabledId("3", true); - final DisabledId testDisabledID1 = new DisabledId("4", true); - - DisabledId[] testDisArray = { testDisabledID, testDisabledID1 }; - - @Before - public void setUp() throws Exception { - - // Build groups - testJSONGroupOb.put("id", "testID"); - testJSONGroupOb.put("name", "testName"); - testJSONGroupOb.put("isCustomForwarding", false); - testJSONGroupOb.put("isCustomGreeting", false); - testJSONGroupOb.put("isCustomDirectConnect", false); - testJSONGroupOb.put(DIRECT_CONNECT, false); - testJSONGroupOb.put("greetingId", 1); - testJSONGroupOb.put("disabledForwardingIds", emptyJSONObject); - testGroup = new Group(testJSONGroupOb); - // Insert testGroup into an array - testGroupArray.put(testGroup); - // And move it into a new Object - testJSONGroupOb1.put("testID", testJSONGroupOb); - - testGroupList.put("testID"); - testGroupList.put("testID1"); - - jsonPreSetting.put(A_F_IDS, emptyJSONArray); - jsonPreSetting.put(BASE_URL, TEST_URL); - jsonPreSetting.put(CREDITS, 1); - jsonPreSetting.put(DFID, 1); - jsonPreSetting.put(DID_INFOS, emptyJSONArray); - jsonPreSetting.put(DIRECT_CONNECT, true); - jsonPreSetting.put(DID_MAP, emptyJSONObject); - jsonPreSetting.put(D_N_D, false); - jsonPreSetting.put(EMAIL_ADD, emptyJSONObject); - jsonPreSetting.put(EMAIL_NOTE_ACTIVE, true); - jsonPreSetting.put(EMAIL_NOTE_ADD, TEST_E_ADDRESS); - jsonPreSetting.put(GREETINGS, emptyJSONObject); - jsonPreSetting.put(GROUPLIST, testGroupList); - jsonPreSetting.put(GROUPS, testJSONGroupOb1); - jsonPreSetting.put(LANGUAGE, ENGLISH); - jsonPreSetting.put(PRIME_DID, TEST_DID); - jsonPreSetting.put(SCREEN_BEHAVE, 1); - jsonPreSetting.put(SHOW_TRANS, false); - jsonPreSetting.put(SMS_NOTE, emptyJSONArray); - jsonPreSetting.put(SMS_EMAIL_ACTIVE, true); - jsonPreSetting.put(SMS_EMAIL_SUB, false); - jsonPreSetting.put(SPAM, SPAM); - jsonPreSetting.put(TIME_ZONE, TEST_T_ZONE); - jsonPreSetting.put(USE_DID_CID, true); - jsonPreSetting.put(USE_DID_SOURCE, false); - testSetting = new Setting(jsonPreSetting); - testSetting.setmDisabledIdList(null); - - } - - /** - * Test method for - * {@link com.techventus.server.voice.datatypes.Setting#Setting(gvjava.org.json.JSONObject)} - * . - * - * @throws JSONException - */ - @Test - public void testSettingNullObject() throws JSONException { - - testSetting = new Setting(testJSONObject); - - Assert.assertNull(testSetting.getmActiveForwardingList()); - - } - - @Test - public void testSettings() throws JSONException { - - Assert.assertEquals(1,testSetting.getCredits()); - - } - - /** - * Test method for - * {@link com.techventus.server.voice.datatypes.Setting#toJsonObject()}. - * @throws JSONException - */ - @Test - public void testToJsonObjectNullEmailAndDiD() throws JSONException { - - jsonPreSetting.put(A_F_IDS, emptyJSONArray); - jsonPreSetting.put(BASE_URL, TEST_URL); - jsonPreSetting.put(CREDITS, 1); - jsonPreSetting.put(DFID, 1); - jsonPreSetting.put(DID_INFOS, emptyJSONArray); - jsonPreSetting.put(DIRECT_CONNECT, true); - jsonPreSetting.put(DID_MAP, emptyJSONObject); - jsonPreSetting.put(D_N_D, false); - jsonPreSetting.put(EMAIL_ADD, TEST_NULL_OBJECT); - jsonPreSetting.put(EMAIL_NOTE_ACTIVE, true); - jsonPreSetting.put(EMAIL_NOTE_ADD, TEST_E_ADDRESS); - jsonPreSetting.put(GREETINGS, emptyJSONObject); - jsonPreSetting.put(GROUPLIST, testGroupList); - jsonPreSetting.put(GROUPS, testJSONGroupOb1); - jsonPreSetting.put(LANGUAGE, ENGLISH); - jsonPreSetting.put(PRIME_DID, TEST_DID); - jsonPreSetting.put(SCREEN_BEHAVE, 1); - jsonPreSetting.put(SHOW_TRANS, false); - jsonPreSetting.put(SMS_NOTE, emptyJSONArray); - jsonPreSetting.put(SMS_EMAIL_ACTIVE, true); - jsonPreSetting.put(SMS_EMAIL_SUB, false); - jsonPreSetting.put(SPAM, SPAM); - jsonPreSetting.put(TIME_ZONE, TEST_T_ZONE); - jsonPreSetting.put(USE_DID_CID, true); - jsonPreSetting.put(USE_DID_SOURCE, false); - - testSetting = new Setting(jsonPreSetting); - testSetting.setmDisabledIdList(null); - - testJSONObject = testSetting.toJsonObject(); - - resultString = "{\"primaryDid\":\"testDiD\",\"defaultGreetingId\":1,\"useDidAsSource\":false,\"doNotDisturb\":false,\"smsNotifications\":[],\"emailNotificationActive\":true,\"credits\":1,\"activeForwardingIds\":[],\"emailNotificationAddress\":\"testEmailAddress\",\"smsToEmailSubject\":false,\"baseUrl\":\"testURL\",\"timezone\":\"testTimeZone\",\"groupList\":[\"testID\",\"testID1\"],\"didInfos\":[],\"greetings\":[],\"showTranscripts\":false,\"directConnect\":true,\"screenBehavior\":1,\"language\":\"English\",\"spam\":\"spam\",\"useDidAsCallerId\":true,\"smsToEmailActive\":true,\"groups\":{\"testID\":{\"id\":\"testID\",\"greetingId\":1,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{},\"name\":\"testName\",\"isCustomDirectConnect\":false,\"directConnect\":false}}}"; - - Assert.assertEquals(resultString, testJSONObject.toString()); - - } - - /** - * Test method for - * {@link com.techventus.server.voice.datatypes.Setting#toJsonObject()}. - * @throws JSONException - */ - @Test - public void testToJsonObject() throws JSONException { - - final JSONArray testEmailArray = new JSONArray(); - testEmailArray.put("test@email.com"); - - final JSONObject testDiDObject = new JSONObject(); - testDiDObject.put("1", true); - - jsonPreSetting.put(A_F_IDS, emptyJSONArray); - jsonPreSetting.put(BASE_URL, TEST_URL); - jsonPreSetting.put(CREDITS, 1); - jsonPreSetting.put(DFID, 1); - jsonPreSetting.put(DID_INFOS, emptyJSONArray); - jsonPreSetting.put(DIRECT_CONNECT, true); - jsonPreSetting.put(DID_MAP, testDiDObject); - jsonPreSetting.put(D_N_D, false); - jsonPreSetting.put(EMAIL_ADD, testEmailArray); - jsonPreSetting.put(EMAIL_NOTE_ACTIVE, true); - jsonPreSetting.put(EMAIL_NOTE_ADD, TEST_E_ADDRESS); - jsonPreSetting.put(GREETINGS, emptyJSONObject); - jsonPreSetting.put(GROUPLIST, testGroupList); - jsonPreSetting.put(GROUPS, testJSONGroupOb1); - jsonPreSetting.put(LANGUAGE, ENGLISH); - jsonPreSetting.put(PRIME_DID, TEST_DID); - jsonPreSetting.put(SCREEN_BEHAVE, 1); - jsonPreSetting.put(SHOW_TRANS, false); - jsonPreSetting.put(SMS_NOTE, emptyJSONArray); - jsonPreSetting.put(SMS_EMAIL_ACTIVE, true); - jsonPreSetting.put(SMS_EMAIL_SUB, false); - jsonPreSetting.put(SPAM, SPAM); - jsonPreSetting.put(TIME_ZONE, TEST_T_ZONE); - jsonPreSetting.put(USE_DID_CID, true); - jsonPreSetting.put(USE_DID_SOURCE, false); - - testSetting = new Setting(jsonPreSetting); - - testJSONObject = testSetting.toJsonObject(); - - resultString = "{\"doNotDisturb\":false,\"disabledIdMap\":{\"1\":true},\"smsNotifications\":[],\"credits\":1,\"baseUrl\":\"testURL\",\"groupList\":[\"testID\",\"testID1\"],\"timezone\":\"testTimeZone\",\"greetings\":[],\"showTranscripts\":false,\"useDidAsCallerId\":true,\"groups\":{\"testID\":{\"id\":\"testID\",\"greetingId\":1,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{},\"name\":\"testName\",\"isCustomDirectConnect\":false,\"directConnect\":false}},\"primaryDid\":\"testDiD\",\"defaultGreetingId\":1,\"useDidAsSource\":false,\"emailNotificationActive\":true,\"emailNotificationAddress\":\"testEmailAddress\",\"activeForwardingIds\":[],\"smsToEmailSubject\":false,\"didInfos\":[],\"directConnect\":true,\"screenBehavior\":1,\"language\":\"English\",\"spam\":\"spam\",\"smsToEmailActive\":true,\"emailAddresses\":\"test@email.com\"}"; - - Assert.assertEquals(resultString, testJSONObject.toString()); - - } - - /** - * Test method for - * {@link com.techventus.server.voice.datatypes.Setting#getGroupListAsList()} - * . - * @throws JSONException - */ - @Test - public void testGetGroupListAsList() throws JSONException { - - final JSONArray testEmailArray = new JSONArray(); - testEmailArray.put("test@email.com"); - - final JSONObject testDiDObject = new JSONObject(); - testDiDObject.put("1", true); - - jsonPreSetting.put(A_F_IDS, emptyJSONArray); - jsonPreSetting.put(BASE_URL, TEST_URL); - jsonPreSetting.put(CREDITS, 1); - jsonPreSetting.put(DFID, 1); - jsonPreSetting.put(DID_INFOS, emptyJSONArray); - jsonPreSetting.put(DIRECT_CONNECT, true); - jsonPreSetting.put(DID_MAP, testDiDObject); - jsonPreSetting.put(D_N_D, false); - jsonPreSetting.put(EMAIL_ADD, testEmailArray); - jsonPreSetting.put(EMAIL_NOTE_ACTIVE, true); - jsonPreSetting.put(EMAIL_NOTE_ADD, TEST_E_ADDRESS); - jsonPreSetting.put(GREETINGS, emptyJSONObject); - jsonPreSetting.put(GROUPLIST, testGroupList); - jsonPreSetting.put(GROUPS, testJSONGroupOb1); - jsonPreSetting.put(LANGUAGE, ENGLISH); - jsonPreSetting.put(PRIME_DID, TEST_DID); - jsonPreSetting.put(SCREEN_BEHAVE, 1); - jsonPreSetting.put(SHOW_TRANS, false); - jsonPreSetting.put(SMS_NOTE, emptyJSONArray); - jsonPreSetting.put(SMS_EMAIL_ACTIVE, true); - jsonPreSetting.put(SMS_EMAIL_SUB, false); - jsonPreSetting.put(SPAM, SPAM); - jsonPreSetting.put(TIME_ZONE, TEST_T_ZONE); - jsonPreSetting.put(USE_DID_CID, true); - jsonPreSetting.put(USE_DID_SOURCE, false); - - testSetting = new Setting(jsonPreSetting); - - resultString = "[testID, testID1]"; - - Assert.assertEquals(resultString, testSetting.getGroupListAsList().toString()); - } - -} +/** + * + */ +package test.datatypes; + +import junit.framework.Assert; +import gvjava.org.json.JSONArray; +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import org.junit.Before; +import org.junit.Test; + +import com.techventus.server.voice.datatypes.DisabledId; +import com.techventus.server.voice.datatypes.Group; +import com.techventus.server.voice.datatypes.Setting; + +/** + * @author Brett Futral @ Catalyst IT Services + * + */ +public class SettingTest { + + Setting testSetting; + Setting testSetting1; + Setting testSetting2; + Group testGroup; + String resultString; + + final static String DIRECT_CONNECT = "directConnect"; + final static String A_F_IDS = "activeForwardingIds"; + final static String BASE_URL = "baseUrl"; + final static String TEST_URL = "testURL"; + final static String CREDITS = "credits"; + final static String DFID = "defaultGreetingId"; + final static String DID_INFOS = "didInfos"; + final static String DID_MAP = "disabledIdMap"; + final static String D_N_D = "doNotDisturb"; + final static String EMAIL_ADD = "emailAddresses"; + final static String EMAIL_NOTE_ACTIVE = "emailNotificationActive"; + final static String TEST_E_ADDRESS = "testEmailAddress"; + final static String EMAIL_NOTE_ADD = "emailNotificationAddress"; + final static String GREETINGS = "greetings"; + final static String GROUPLIST = "groupList"; + final static String GROUPS = "groups"; + final static String LANGUAGE = "language"; + final static String ENGLISH = "English"; + final static String PRIME_DID = "primaryDid"; + final static String TEST_DID = "testDiD"; + final static String SCREEN_BEHAVE = "screenBehavior"; + final static String SHOW_TRANS = "showTranscripts"; + final static String SMS_NOTE = "smsNotifications"; + final static String SMS_EMAIL_ACTIVE = "smsToEmailActive"; + final static String SMS_EMAIL_SUB = "smsToEmailSubject"; + final static String SPAM = "spam"; + final static String TIME_ZONE = "timezone"; + final static String TEST_T_ZONE = "testTimeZone"; + final static String USE_DID_CID = "useDidAsCallerId"; + final static String USE_DID_SOURCE = "useDidAsSource"; + + final JSONArray emptyJSONArray = new JSONArray(); + JSONArray testGroupList = new JSONArray(); + JSONArray testGroupArray = new JSONArray(); + + final JSONObject emptyJSONObject = new JSONObject(); + final static JSONObject TEST_NULL_OBJECT = null; + JSONObject testJSONGroupOb = new JSONObject(); + JSONObject testJSONGroupOb1 = new JSONObject(); + JSONObject jsonPreSetting = new JSONObject(); + JSONObject jsonSetting = new JSONObject(); + JSONObject testJSONObject = new JSONObject(); + + final DisabledId testDisabledID = new DisabledId("3", true); + final DisabledId testDisabledID1 = new DisabledId("4", true); + + DisabledId[] testDisArray = { testDisabledID, testDisabledID1 }; + + @Before + public void setUp() throws Exception { + + // Build groups + testJSONGroupOb.put("id", "testID"); + testJSONGroupOb.put("name", "testName"); + testJSONGroupOb.put("isCustomForwarding", false); + testJSONGroupOb.put("isCustomGreeting", false); + testJSONGroupOb.put("isCustomDirectConnect", false); + testJSONGroupOb.put(DIRECT_CONNECT, false); + testJSONGroupOb.put("greetingId", 1); + testJSONGroupOb.put("disabledForwardingIds", emptyJSONObject); + testGroup = new Group(testJSONGroupOb); + // Insert testGroup into an array + testGroupArray.put(testGroup); + // And move it into a new Object + testJSONGroupOb1.put("testID", testJSONGroupOb); + + testGroupList.put("testID"); + testGroupList.put("testID1"); + + jsonPreSetting.put(A_F_IDS, emptyJSONArray); + jsonPreSetting.put(BASE_URL, TEST_URL); + jsonPreSetting.put(CREDITS, 1); + jsonPreSetting.put(DFID, 1); + jsonPreSetting.put(DID_INFOS, emptyJSONArray); + jsonPreSetting.put(DIRECT_CONNECT, true); + jsonPreSetting.put(DID_MAP, emptyJSONObject); + jsonPreSetting.put(D_N_D, false); + jsonPreSetting.put(EMAIL_ADD, emptyJSONObject); + jsonPreSetting.put(EMAIL_NOTE_ACTIVE, true); + jsonPreSetting.put(EMAIL_NOTE_ADD, TEST_E_ADDRESS); + jsonPreSetting.put(GREETINGS, emptyJSONObject); + jsonPreSetting.put(GROUPLIST, testGroupList); + jsonPreSetting.put(GROUPS, testJSONGroupOb1); + jsonPreSetting.put(LANGUAGE, ENGLISH); + jsonPreSetting.put(PRIME_DID, TEST_DID); + jsonPreSetting.put(SCREEN_BEHAVE, 1); + jsonPreSetting.put(SHOW_TRANS, false); + jsonPreSetting.put(SMS_NOTE, emptyJSONArray); + jsonPreSetting.put(SMS_EMAIL_ACTIVE, true); + jsonPreSetting.put(SMS_EMAIL_SUB, false); + jsonPreSetting.put(SPAM, SPAM); + jsonPreSetting.put(TIME_ZONE, TEST_T_ZONE); + jsonPreSetting.put(USE_DID_CID, true); + jsonPreSetting.put(USE_DID_SOURCE, false); + testSetting = new Setting(jsonPreSetting); + testSetting.setmDisabledIdList(null); + + } + + /** + * Test method for + * {@link com.techventus.server.voice.datatypes.Setting#Setting(gvjava.org.json.JSONObject)} + * . + * + * @throws JSONException + */ + @Test + public void testSettingNullObject() throws JSONException { + + testSetting = new Setting(testJSONObject); + + Assert.assertNull(testSetting.getmActiveForwardingList()); + + } + + @Test + public void testSettings() throws JSONException { + + Assert.assertEquals(1,testSetting.getCredits()); + + } + + /** + * Test method for + * {@link com.techventus.server.voice.datatypes.Setting#toJsonObject()}. + * @throws JSONException + */ + @Test + public void testToJsonObjectNullEmailAndDiD() throws JSONException { + + jsonPreSetting.put(A_F_IDS, emptyJSONArray); + jsonPreSetting.put(BASE_URL, TEST_URL); + jsonPreSetting.put(CREDITS, 1); + jsonPreSetting.put(DFID, 1); + jsonPreSetting.put(DID_INFOS, emptyJSONArray); + jsonPreSetting.put(DIRECT_CONNECT, true); + jsonPreSetting.put(DID_MAP, emptyJSONObject); + jsonPreSetting.put(D_N_D, false); + jsonPreSetting.put(EMAIL_ADD, TEST_NULL_OBJECT); + jsonPreSetting.put(EMAIL_NOTE_ACTIVE, true); + jsonPreSetting.put(EMAIL_NOTE_ADD, TEST_E_ADDRESS); + jsonPreSetting.put(GREETINGS, emptyJSONObject); + jsonPreSetting.put(GROUPLIST, testGroupList); + jsonPreSetting.put(GROUPS, testJSONGroupOb1); + jsonPreSetting.put(LANGUAGE, ENGLISH); + jsonPreSetting.put(PRIME_DID, TEST_DID); + jsonPreSetting.put(SCREEN_BEHAVE, 1); + jsonPreSetting.put(SHOW_TRANS, false); + jsonPreSetting.put(SMS_NOTE, emptyJSONArray); + jsonPreSetting.put(SMS_EMAIL_ACTIVE, true); + jsonPreSetting.put(SMS_EMAIL_SUB, false); + jsonPreSetting.put(SPAM, SPAM); + jsonPreSetting.put(TIME_ZONE, TEST_T_ZONE); + jsonPreSetting.put(USE_DID_CID, true); + jsonPreSetting.put(USE_DID_SOURCE, false); + + testSetting = new Setting(jsonPreSetting); + testSetting.setmDisabledIdList(null); + + testJSONObject = testSetting.toJsonObject(); + + resultString = "{\"primaryDid\":\"testDiD\",\"defaultGreetingId\":1,\"useDidAsSource\":false,\"doNotDisturb\":false,\"smsNotifications\":[],\"emailNotificationActive\":true,\"credits\":1,\"activeForwardingIds\":[],\"emailNotificationAddress\":\"testEmailAddress\",\"smsToEmailSubject\":false,\"baseUrl\":\"testURL\",\"timezone\":\"testTimeZone\",\"groupList\":[\"testID\",\"testID1\"],\"didInfos\":[],\"greetings\":[],\"showTranscripts\":false,\"directConnect\":true,\"screenBehavior\":1,\"language\":\"English\",\"spam\":\"spam\",\"useDidAsCallerId\":true,\"smsToEmailActive\":true,\"groups\":{\"testID\":{\"id\":\"testID\",\"greetingId\":1,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{},\"name\":\"testName\",\"isCustomDirectConnect\":false,\"directConnect\":false}}}"; + + Assert.assertEquals(resultString, testJSONObject.toString()); + + } + + /** + * Test method for + * {@link com.techventus.server.voice.datatypes.Setting#toJsonObject()}. + * @throws JSONException + */ + @Test + public void testToJsonObject() throws JSONException { + + final JSONArray testEmailArray = new JSONArray(); + testEmailArray.put("test@email.com"); + + final JSONObject testDiDObject = new JSONObject(); + testDiDObject.put("1", true); + + jsonPreSetting.put(A_F_IDS, emptyJSONArray); + jsonPreSetting.put(BASE_URL, TEST_URL); + jsonPreSetting.put(CREDITS, 1); + jsonPreSetting.put(DFID, 1); + jsonPreSetting.put(DID_INFOS, emptyJSONArray); + jsonPreSetting.put(DIRECT_CONNECT, true); + jsonPreSetting.put(DID_MAP, testDiDObject); + jsonPreSetting.put(D_N_D, false); + jsonPreSetting.put(EMAIL_ADD, testEmailArray); + jsonPreSetting.put(EMAIL_NOTE_ACTIVE, true); + jsonPreSetting.put(EMAIL_NOTE_ADD, TEST_E_ADDRESS); + jsonPreSetting.put(GREETINGS, emptyJSONObject); + jsonPreSetting.put(GROUPLIST, testGroupList); + jsonPreSetting.put(GROUPS, testJSONGroupOb1); + jsonPreSetting.put(LANGUAGE, ENGLISH); + jsonPreSetting.put(PRIME_DID, TEST_DID); + jsonPreSetting.put(SCREEN_BEHAVE, 1); + jsonPreSetting.put(SHOW_TRANS, false); + jsonPreSetting.put(SMS_NOTE, emptyJSONArray); + jsonPreSetting.put(SMS_EMAIL_ACTIVE, true); + jsonPreSetting.put(SMS_EMAIL_SUB, false); + jsonPreSetting.put(SPAM, SPAM); + jsonPreSetting.put(TIME_ZONE, TEST_T_ZONE); + jsonPreSetting.put(USE_DID_CID, true); + jsonPreSetting.put(USE_DID_SOURCE, false); + + testSetting = new Setting(jsonPreSetting); + + testJSONObject = testSetting.toJsonObject(); + + resultString = "{\"doNotDisturb\":false,\"disabledIdMap\":{\"1\":true},\"smsNotifications\":[],\"credits\":1,\"baseUrl\":\"testURL\",\"groupList\":[\"testID\",\"testID1\"],\"timezone\":\"testTimeZone\",\"greetings\":[],\"showTranscripts\":false,\"useDidAsCallerId\":true,\"groups\":{\"testID\":{\"id\":\"testID\",\"greetingId\":1,\"isCustomForwarding\":false,\"isCustomGreeting\":false,\"disabledForwardingIds\":{},\"name\":\"testName\",\"isCustomDirectConnect\":false,\"directConnect\":false}},\"primaryDid\":\"testDiD\",\"defaultGreetingId\":1,\"useDidAsSource\":false,\"emailNotificationActive\":true,\"emailNotificationAddress\":\"testEmailAddress\",\"activeForwardingIds\":[],\"smsToEmailSubject\":false,\"didInfos\":[],\"directConnect\":true,\"screenBehavior\":1,\"language\":\"English\",\"spam\":\"spam\",\"smsToEmailActive\":true,\"emailAddresses\":\"test@email.com\"}"; + + Assert.assertEquals(resultString, testJSONObject.toString()); + + } + + /** + * Test method for + * {@link com.techventus.server.voice.datatypes.Setting#getGroupListAsList()} + * . + * @throws JSONException + */ + @Test + public void testGetGroupListAsList() throws JSONException { + + final JSONArray testEmailArray = new JSONArray(); + testEmailArray.put("test@email.com"); + + final JSONObject testDiDObject = new JSONObject(); + testDiDObject.put("1", true); + + jsonPreSetting.put(A_F_IDS, emptyJSONArray); + jsonPreSetting.put(BASE_URL, TEST_URL); + jsonPreSetting.put(CREDITS, 1); + jsonPreSetting.put(DFID, 1); + jsonPreSetting.put(DID_INFOS, emptyJSONArray); + jsonPreSetting.put(DIRECT_CONNECT, true); + jsonPreSetting.put(DID_MAP, testDiDObject); + jsonPreSetting.put(D_N_D, false); + jsonPreSetting.put(EMAIL_ADD, testEmailArray); + jsonPreSetting.put(EMAIL_NOTE_ACTIVE, true); + jsonPreSetting.put(EMAIL_NOTE_ADD, TEST_E_ADDRESS); + jsonPreSetting.put(GREETINGS, emptyJSONObject); + jsonPreSetting.put(GROUPLIST, testGroupList); + jsonPreSetting.put(GROUPS, testJSONGroupOb1); + jsonPreSetting.put(LANGUAGE, ENGLISH); + jsonPreSetting.put(PRIME_DID, TEST_DID); + jsonPreSetting.put(SCREEN_BEHAVE, 1); + jsonPreSetting.put(SHOW_TRANS, false); + jsonPreSetting.put(SMS_NOTE, emptyJSONArray); + jsonPreSetting.put(SMS_EMAIL_ACTIVE, true); + jsonPreSetting.put(SMS_EMAIL_SUB, false); + jsonPreSetting.put(SPAM, SPAM); + jsonPreSetting.put(TIME_ZONE, TEST_T_ZONE); + jsonPreSetting.put(USE_DID_CID, true); + jsonPreSetting.put(USE_DID_SOURCE, false); + + testSetting = new Setting(jsonPreSetting); + + resultString = "[testID, testID1]"; + + Assert.assertEquals(resultString, testSetting.getGroupListAsList().toString()); + } + +} diff --git a/src/test/datatypes/records/CallTest.java b/src/test/java/datatypes/records/CallTest.java similarity index 90% rename from src/test/datatypes/records/CallTest.java rename to src/test/java/datatypes/records/CallTest.java index fed233a..6afe8f2 100644 --- a/src/test/datatypes/records/CallTest.java +++ b/src/test/java/datatypes/records/CallTest.java @@ -1,64 +1,64 @@ -package test.datatypes.records; - -import java.util.Date; - -import junit.framework.Assert; - -import org.junit.Test; - -import com.techventus.server.voice.datatypes.Contact; -import com.techventus.server.voice.datatypes.records.Call; - -/** - * - * @author Brett Futral @ Catalyst IT Services - * - */ -public class CallTest { - - private final static Date DATE = new Date(1321038671000l); - private final static Contact CONTACT = new Contact("testName", "testID", "testNumber", "testURL"); - - private Call testCall = new Call("testID", "testTitle", DATE, CONTACT, true); - - @Test - public void testCallToStringOverrideFull() { - - Assert.assertEquals("id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};read=true;", testCall.toString()); - - } - - @Test - public void testCallToStringOverrideNoID() { - - testCall.setId(null); - - Assert.assertEquals("title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};read=true;", testCall.toString()); - - } - - @Test - public void testCallToStringOverrideNoTitle() { - - testCall.setTitle(null); - - Assert.assertEquals("id=testID;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};read=true;", testCall.toString()); - } - - @Test - public void testCallToStringOverrideNoDate() { - - testCall.setDate(null); - - Assert.assertEquals("id=testID;title=testTitle;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};read=true;", testCall.toString()); - } - - @Test - public void testCallToStringOverrideNoContact() { - - testCall.setContact(null); - - Assert.assertEquals("id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;read=true;", testCall.toString()); - } - -} +package test.datatypes.records; + +import java.util.Date; + +import junit.framework.Assert; + +import org.junit.Test; + +import com.techventus.server.voice.datatypes.Contact; +import com.techventus.server.voice.datatypes.records.Call; + +/** + * + * @author Brett Futral @ Catalyst IT Services + * + */ +public class CallTest { + + private final static Date DATE = new Date(1321038671000l); + private final static Contact CONTACT = new Contact("testName", "testID", "testNumber", "testURL"); + + private Call testCall = new Call("testID", "testTitle", DATE, CONTACT, true); + + @Test + public void testCallToStringOverrideFull() { + + Assert.assertEquals("id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};read=true;", testCall.toString()); + + } + + @Test + public void testCallToStringOverrideNoID() { + + testCall.setId(null); + + Assert.assertEquals("title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};read=true;", testCall.toString()); + + } + + @Test + public void testCallToStringOverrideNoTitle() { + + testCall.setTitle(null); + + Assert.assertEquals("id=testID;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};read=true;", testCall.toString()); + } + + @Test + public void testCallToStringOverrideNoDate() { + + testCall.setDate(null); + + Assert.assertEquals("id=testID;title=testTitle;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};read=true;", testCall.toString()); + } + + @Test + public void testCallToStringOverrideNoContact() { + + testCall.setContact(null); + + Assert.assertEquals("id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;read=true;", testCall.toString()); + } + +} diff --git a/src/test/datatypes/records/RecordTest.java b/src/test/java/datatypes/records/RecordTest.java similarity index 100% rename from src/test/datatypes/records/RecordTest.java rename to src/test/java/datatypes/records/RecordTest.java diff --git a/src/test/datatypes/records/SMSTest.java b/src/test/java/datatypes/records/SMSTest.java similarity index 100% rename from src/test/datatypes/records/SMSTest.java rename to src/test/java/datatypes/records/SMSTest.java diff --git a/src/test/datatypes/records/ShortMessageTest.java b/src/test/java/datatypes/records/ShortMessageTest.java similarity index 100% rename from src/test/datatypes/records/ShortMessageTest.java rename to src/test/java/datatypes/records/ShortMessageTest.java diff --git a/src/test/datatypes/records/TranscriptElementTest.java b/src/test/java/datatypes/records/TranscriptElementTest.java similarity index 100% rename from src/test/datatypes/records/TranscriptElementTest.java rename to src/test/java/datatypes/records/TranscriptElementTest.java diff --git a/src/test/datatypes/records/TranscriptTest.java b/src/test/java/datatypes/records/TranscriptTest.java similarity index 100% rename from src/test/datatypes/records/TranscriptTest.java rename to src/test/java/datatypes/records/TranscriptTest.java diff --git a/src/test/datatypes/records/VoicemailTest.java b/src/test/java/datatypes/records/VoicemailTest.java similarity index 96% rename from src/test/datatypes/records/VoicemailTest.java rename to src/test/java/datatypes/records/VoicemailTest.java index 4e3ea2e..38fb875 100644 --- a/src/test/datatypes/records/VoicemailTest.java +++ b/src/test/java/datatypes/records/VoicemailTest.java @@ -1,112 +1,112 @@ -package test.datatypes.records; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; - -import com.techventus.server.voice.datatypes.Contact; -import com.techventus.server.voice.datatypes.records.Transcript; -import com.techventus.server.voice.datatypes.records.TranscriptElement; -import com.techventus.server.voice.datatypes.records.Voicemail; - -/** - * - * @author Brett Futral @ Catalyst IT Services - * - */ -public class VoicemailTest { - - Voicemail testVoicemail; - // Params for testVoicemail - final Date DATE = new Date(1321038671000l); - final Contact CONTACT = new Contact("testName", "testID", "testNumber", - "testURL"); - final TranscriptElement.RecognitionLevel testLevel = TranscriptElement.RecognitionLevel.HIGH; - final TranscriptElement testElement = new TranscriptElement("testText", - "testID", testLevel); - - @Before - public void setUp() { - //Params for testVoicemail - final List testList = new ArrayList(); - testList.add(testElement); - final Transcript TRANSCRIPT = new Transcript(testList); - //instantiate testVoicemail - testVoicemail = new Voicemail("testID", "testTitle", DATE, CONTACT, TRANSCRIPT, - true); - } - - @Test - public void testToStringOverrideFull() { - - Assert.assertEquals( - "id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", - testVoicemail.toString()); - } - - @Test - public void testToStringOverrideNoID() { - - testVoicemail.setId(null); - - Assert.assertEquals( - "title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/null;read=true;", - testVoicemail.toString()); - } - - @Test - public void testToStringOverrideNoTitle() { - - testVoicemail.setTitle(null); - - Assert.assertEquals( - "id=testID;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", - testVoicemail.toString()); - } - - @Test - public void testToStringOverrideNoDate() { - - testVoicemail.setDate(null); - - Assert.assertEquals( - "id=testID;title=testTitle;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", - testVoicemail.toString()); - } - - @Test - public void testToStringOverrideContact() { - - testVoicemail.setContact(null); - - Assert.assertEquals( - "id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", - testVoicemail.toString()); - } - - @Test - public void testToStringOverrideNoTranscript() { - - testVoicemail.setTransscript(null); - - Assert.assertEquals( - "id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", - testVoicemail.toString()); - } - - @Test - public void testToStringOverrideNoMP3() { - - testVoicemail.setMp3Url(null); - - Assert.assertEquals( - "id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;read=true;", - testVoicemail.toString()); - } - -} +package test.datatypes.records; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; + +import com.techventus.server.voice.datatypes.Contact; +import com.techventus.server.voice.datatypes.records.Transcript; +import com.techventus.server.voice.datatypes.records.TranscriptElement; +import com.techventus.server.voice.datatypes.records.Voicemail; + +/** + * + * @author Brett Futral @ Catalyst IT Services + * + */ +public class VoicemailTest { + + Voicemail testVoicemail; + // Params for testVoicemail + final Date DATE = new Date(1321038671000l); + final Contact CONTACT = new Contact("testName", "testID", "testNumber", + "testURL"); + final TranscriptElement.RecognitionLevel testLevel = TranscriptElement.RecognitionLevel.HIGH; + final TranscriptElement testElement = new TranscriptElement("testText", + "testID", testLevel); + + @Before + public void setUp() { + //Params for testVoicemail + final List testList = new ArrayList(); + testList.add(testElement); + final Transcript TRANSCRIPT = new Transcript(testList); + //instantiate testVoicemail + testVoicemail = new Voicemail("testID", "testTitle", DATE, CONTACT, TRANSCRIPT, + true); + } + + @Test + public void testToStringOverrideFull() { + + Assert.assertEquals( + "id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", + testVoicemail.toString()); + } + + @Test + public void testToStringOverrideNoID() { + + testVoicemail.setId(null); + + Assert.assertEquals( + "title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/null;read=true;", + testVoicemail.toString()); + } + + @Test + public void testToStringOverrideNoTitle() { + + testVoicemail.setTitle(null); + + Assert.assertEquals( + "id=testID;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", + testVoicemail.toString()); + } + + @Test + public void testToStringOverrideNoDate() { + + testVoicemail.setDate(null); + + Assert.assertEquals( + "id=testID;title=testTitle;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", + testVoicemail.toString()); + } + + @Test + public void testToStringOverrideContact() { + + testVoicemail.setContact(null); + + Assert.assertEquals( + "id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;transcript=testText;mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", + testVoicemail.toString()); + } + + @Test + public void testToStringOverrideNoTranscript() { + + testVoicemail.setTransscript(null); + + Assert.assertEquals( + "id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};mp3Url=https://www.google.com/voice/media/send_voicemail/testID;read=true;", + testVoicemail.toString()); + } + + @Test + public void testToStringOverrideNoMP3() { + + testVoicemail.setMp3Url(null); + + Assert.assertEquals( + "id=testID;title=testTitle;date=Fri Nov 11 11:11:11 PST 2011;contact={id=testID;name=testName;number=testNumber;imageUrl=testURL;};transcript=testText;read=true;", + testVoicemail.toString()); + } + +} diff --git a/src/test/test.java b/src/test/java/test.java similarity index 100% rename from src/test/test.java rename to src/test/java/test.java diff --git a/src/test/util/ParsingUtilTest.java b/src/test/java/util/ParsingUtilTest.java similarity index 92% rename from src/test/util/ParsingUtilTest.java rename to src/test/java/util/ParsingUtilTest.java index dc1fded..dfda210 100644 --- a/src/test/util/ParsingUtilTest.java +++ b/src/test/java/util/ParsingUtilTest.java @@ -1,153 +1,153 @@ -package test.util; - -import java.util.ArrayList; -import java.util.List; - -import gvjava.org.json.JSONArray; -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import org.junit.Assert; -import org.junit.Test; - -import com.techventus.server.voice.util.ParsingUtil; - -/** - * - * @author Brett Futral @ Catalyst IT Services - * - */ -// Coverage Holes: -// removeUninterestingParts line 41 unable to make null. -// removeUninterestingParts line 48 unable to make null. -public class ParsingUtilTest { - - private final static String TEST_TEXT = "Hello Toby, How are you today? Fine."; - private final static String TEST_START_BORDER = "How are"; - private final static String TEST_END_BORDER = "?"; - private final static String ARRAY_ONE = "one"; - private final static String TEST_KEY = "testKey"; - - JSONArray testJSONArray = new JSONArray(); - JSONObject testJSONObject = new JSONObject(); - - @Test - public void testRemoveUninterestingPartsNullEndBorder() { - - Assert.assertEquals(null, ParsingUtil.removeUninterestingParts( - TEST_TEXT, TEST_START_BORDER, null, true)); - } - - @Test - public void testRemoveUninterestingPartsNullStartBorder() { - - Assert.assertEquals(null, ParsingUtil.removeUninterestingParts( - TEST_TEXT, null, TEST_END_BORDER, true)); - } - - @Test - public void testRemoveUninterestingPartsNullText() { - - Assert.assertEquals(null, ParsingUtil.removeUninterestingParts(null, - TEST_START_BORDER, TEST_END_BORDER, true)); - } - - @Test - public void testRemoveUninterestingPartsIncludeBordersNoSuchStartIndex() { - - Assert.assertNull(ParsingUtil.removeUninterestingParts( - TEST_TEXT, "Does Not Exist", TEST_END_BORDER, - true)); - } - - @Test - public void testRemoveUninterestingPartsIncludeBordersNoSuchEndIndex() { - - Assert.assertNull(ParsingUtil.removeUninterestingParts( - TEST_TEXT, TEST_START_BORDER, - "Does not exist", true)); - } - - @Test - public void testRemoveUninterestingPartsIncludeBorders() { - - Assert.assertEquals("How are you today?", ParsingUtil - .removeUninterestingParts( - TEST_TEXT, TEST_START_BORDER, TEST_END_BORDER, - true)); - } - - @Test - public void testRemoveUninterestingPartsIncludeBordersFalse() { - - Assert.assertEquals(" you today", ParsingUtil.removeUninterestingParts( - TEST_TEXT, TEST_START_BORDER, TEST_END_BORDER, false)); - } - - @Test - public void testJsonIntArrayToIntArrayPass() { - - testJSONArray.put(1); - testJSONArray.put(2); - - final int[] testArray = { 1, 2 }; - - Assert.assertArrayEquals(testArray, - ParsingUtil.jsonIntArrayToIntArray(testJSONArray)); - - } - - @Test - public void testJsonStringArrayToStringArrayPass() { - - testJSONArray.put(ARRAY_ONE); - - final String[] testArray = { ARRAY_ONE }; - - final String[] testJSString = ParsingUtil - .jsonStringArrayToStringArray(testJSONArray); - - Assert.assertEquals(testArray[0], testJSString[0]); - } - - @Test - public void testJsonStringArrayToStringList() throws JSONException { - - testJSONArray.put(ARRAY_ONE); - testJSONArray.put("two"); - - testJSONObject.put(TEST_KEY, testJSONArray); - - final List testInputList = new ArrayList(); - final List testList = new ArrayList(); - testList.add(ARRAY_ONE); - testList.add("two"); - - Assert.assertEquals( - testList.toString(), - ParsingUtil.jsonStringArrayToStringList(testJSONObject, - testInputList, TEST_KEY).toString()); - - } - - @Test - public void testJsonIntArrayToIntegerList() throws JSONException { - - testJSONArray.put(1); - testJSONArray.put(2); - - testJSONObject.put(TEST_KEY, testJSONArray); - - final List testInputList = new ArrayList(); - final List testList = new ArrayList(); - testList.add(1); - testList.add(2); - - Assert.assertEquals( - testList.toString(), - ParsingUtil.jsonIntArrayToIntegerList(testJSONObject, - testInputList, TEST_KEY).toString()); - - } - -} +package test.util; + +import java.util.ArrayList; +import java.util.List; + +import gvjava.org.json.JSONArray; +import gvjava.org.json.JSONException; +import gvjava.org.json.JSONObject; + +import org.junit.Assert; +import org.junit.Test; + +import com.techventus.server.voice.util.ParsingUtil; + +/** + * + * @author Brett Futral @ Catalyst IT Services + * + */ +// Coverage Holes: +// removeUninterestingParts line 41 unable to make null. +// removeUninterestingParts line 48 unable to make null. +public class ParsingUtilTest { + + private final static String TEST_TEXT = "Hello Toby, How are you today? Fine."; + private final static String TEST_START_BORDER = "How are"; + private final static String TEST_END_BORDER = "?"; + private final static String ARRAY_ONE = "one"; + private final static String TEST_KEY = "testKey"; + + JSONArray testJSONArray = new JSONArray(); + JSONObject testJSONObject = new JSONObject(); + + @Test + public void testRemoveUninterestingPartsNullEndBorder() { + + Assert.assertEquals(null, ParsingUtil.removeUninterestingParts( + TEST_TEXT, TEST_START_BORDER, null, true)); + } + + @Test + public void testRemoveUninterestingPartsNullStartBorder() { + + Assert.assertEquals(null, ParsingUtil.removeUninterestingParts( + TEST_TEXT, null, TEST_END_BORDER, true)); + } + + @Test + public void testRemoveUninterestingPartsNullText() { + + Assert.assertEquals(null, ParsingUtil.removeUninterestingParts(null, + TEST_START_BORDER, TEST_END_BORDER, true)); + } + + @Test + public void testRemoveUninterestingPartsIncludeBordersNoSuchStartIndex() { + + Assert.assertNull(ParsingUtil.removeUninterestingParts( + TEST_TEXT, "Does Not Exist", TEST_END_BORDER, + true)); + } + + @Test + public void testRemoveUninterestingPartsIncludeBordersNoSuchEndIndex() { + + Assert.assertNull(ParsingUtil.removeUninterestingParts( + TEST_TEXT, TEST_START_BORDER, + "Does not exist", true)); + } + + @Test + public void testRemoveUninterestingPartsIncludeBorders() { + + Assert.assertEquals("How are you today?", ParsingUtil + .removeUninterestingParts( + TEST_TEXT, TEST_START_BORDER, TEST_END_BORDER, + true)); + } + + @Test + public void testRemoveUninterestingPartsIncludeBordersFalse() { + + Assert.assertEquals(" you today", ParsingUtil.removeUninterestingParts( + TEST_TEXT, TEST_START_BORDER, TEST_END_BORDER, false)); + } + + @Test + public void testJsonIntArrayToIntArrayPass() { + + testJSONArray.put(1); + testJSONArray.put(2); + + final int[] testArray = { 1, 2 }; + + Assert.assertArrayEquals(testArray, + ParsingUtil.jsonIntArrayToIntArray(testJSONArray)); + + } + + @Test + public void testJsonStringArrayToStringArrayPass() { + + testJSONArray.put(ARRAY_ONE); + + final String[] testArray = { ARRAY_ONE }; + + final String[] testJSString = ParsingUtil + .jsonStringArrayToStringArray(testJSONArray); + + Assert.assertEquals(testArray[0], testJSString[0]); + } + + @Test + public void testJsonStringArrayToStringList() throws JSONException { + + testJSONArray.put(ARRAY_ONE); + testJSONArray.put("two"); + + testJSONObject.put(TEST_KEY, testJSONArray); + + final List testInputList = new ArrayList(); + final List testList = new ArrayList(); + testList.add(ARRAY_ONE); + testList.add("two"); + + Assert.assertEquals( + testList.toString(), + ParsingUtil.jsonStringArrayToStringList(testJSONObject, + testInputList, TEST_KEY).toString()); + + } + + @Test + public void testJsonIntArrayToIntegerList() throws JSONException { + + testJSONArray.put(1); + testJSONArray.put(2); + + testJSONObject.put(TEST_KEY, testJSONArray); + + final List testInputList = new ArrayList(); + final List testList = new ArrayList(); + testList.add(1); + testList.add(2); + + Assert.assertEquals( + testList.toString(), + ParsingUtil.jsonIntArrayToIntegerList(testJSONObject, + testInputList, TEST_KEY).toString()); + + } + +} diff --git a/src/test/util/SMSParserTest.java b/src/test/java/util/SMSParserTest.java similarity index 96% rename from src/test/util/SMSParserTest.java rename to src/test/java/util/SMSParserTest.java index 6e3eee2..ae65f5c 100644 --- a/src/test/util/SMSParserTest.java +++ b/src/test/java/util/SMSParserTest.java @@ -1,135 +1,135 @@ -package test.util; - -import com.techventus.server.voice.datatypes.records.SMSThread; -import com.techventus.server.voice.util.SMSParser; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author Brett Futral @ Catalyst IT Services - * - */ -// Holes in coverage: -// SMSParser.parsePhoneNumber line 258 will always == -1 due to line -// regex filter in line 257) -// Cannot test getSMSThreads due to private method call inside method. -// Cannot test parseContact due to private method call inside method. -// addSMSsToThread is void -@SuppressWarnings("rawtypes") -public class SMSParserTest { - - // TestSMSParser - final SMSParser testSMSParser = new SMSParser("test", "5030000000"); - private static final long DATE_LONG = 1334348667447L; - - // Reflection Setup buildSMSThreadMap - private Method bSMSTM; - private static final String TEST_PPN = "parsePhoneNumber"; - private static final String TEST_BSMSTM = "buildSMSThreadMap"; - private Class[] bSMSTMParamTypes = new Class[1]; - private Object[] bSMSTMParams = new Object[1]; - - @Before - public void setUp() throws NoSuchMethodException, SecurityException { - - // Reflect class/method buildSMSThreadMap - bSMSTMParamTypes[0] = java.lang.String.class; - bSMSTM = testSMSParser.getClass().getDeclaredMethod(TEST_BSMSTM, - bSMSTMParamTypes); - bSMSTM.setAccessible(true); - } - - @Test - public void testParsePhoneNumber() throws NoSuchMethodException, - SecurityException, IllegalAccessException, - IllegalArgumentException, InvocationTargetException { - - // Reflect class/method parsePhoneNumber - Method pPN; - Class[] pPNParamTypes = new Class[1]; - Object[] pPNParams = new Object[1]; - pPNParamTypes[0] = java.lang.String.class; - pPN = testSMSParser.getClass().getDeclaredMethod(TEST_PPN, - pPNParamTypes); - pPN.setAccessible(true); - pPNParams[0] = "5035551212"; - - final String testPPNumber = (String) pPN.invoke(testSMSParser, - pPNParams); - - Assert.assertEquals("+15035551212", testPPNumber); - - } - - @Test - public void testBuildSMSThreadMap() throws IllegalAccessException, - IllegalArgumentException, InvocationTargetException { - - // Reflect class/method parsePhoneNumber - final String testSMSResponse = ""; - bSMSTMParams[0] = testSMSResponse; - final Map testBSMSTMap = (Map) bSMSTM.invoke(testSMSParser, - bSMSTMParams); - - // Expected object - final Date validDate = new Date(DATE_LONG); - final SMSThread expectedSMSThread = new SMSThread("testID", - "test note", validDate, null, true, true); - final Map expectedMap = new HashMap(); - expectedMap.put("testID", expectedSMSThread); - - Assert.assertEquals(expectedMap.toString(), testBSMSTMap.toString()); - - } - - @Test - public void testBuildSMSThreadMapNoInputs() throws IllegalAccessException, - IllegalArgumentException, InvocationTargetException { - - // Reflect class/method parsePhoneNumber - final String testSMSResponse = ""; - bSMSTMParams[0] = testSMSResponse; - final Map testNoInputs = (Map) bSMSTM.invoke(testSMSParser, - bSMSTMParams); - - // Expected object - final Date epochDate = new Date(0); - final SMSThread expectedSMSThread = new SMSThread("", "", epochDate, - null, false, false); - final Map expectedMap = new HashMap(); - expectedMap.put("", expectedSMSThread); - - Assert.assertEquals(expectedMap.toString(), testNoInputs.toString()); - - } - -} +package test.util; + +import com.techventus.server.voice.datatypes.records.SMSThread; +import com.techventus.server.voice.util.SMSParser; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author Brett Futral @ Catalyst IT Services + * + */ +// Holes in coverage: +// SMSParser.parsePhoneNumber line 258 will always == -1 due to line +// regex filter in line 257) +// Cannot test getSMSThreads due to private method call inside method. +// Cannot test parseContact due to private method call inside method. +// addSMSsToThread is void +@SuppressWarnings("rawtypes") +public class SMSParserTest { + + // TestSMSParser + final SMSParser testSMSParser = new SMSParser("test", "5030000000"); + private static final long DATE_LONG = 1334348667447L; + + // Reflection Setup buildSMSThreadMap + private Method bSMSTM; + private static final String TEST_PPN = "parsePhoneNumber"; + private static final String TEST_BSMSTM = "buildSMSThreadMap"; + private Class[] bSMSTMParamTypes = new Class[1]; + private Object[] bSMSTMParams = new Object[1]; + + @Before + public void setUp() throws NoSuchMethodException, SecurityException { + + // Reflect class/method buildSMSThreadMap + bSMSTMParamTypes[0] = java.lang.String.class; + bSMSTM = testSMSParser.getClass().getDeclaredMethod(TEST_BSMSTM, + bSMSTMParamTypes); + bSMSTM.setAccessible(true); + } + + @Test + public void testParsePhoneNumber() throws NoSuchMethodException, + SecurityException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException { + + // Reflect class/method parsePhoneNumber + Method pPN; + Class[] pPNParamTypes = new Class[1]; + Object[] pPNParams = new Object[1]; + pPNParamTypes[0] = java.lang.String.class; + pPN = testSMSParser.getClass().getDeclaredMethod(TEST_PPN, + pPNParamTypes); + pPN.setAccessible(true); + pPNParams[0] = "5035551212"; + + final String testPPNumber = (String) pPN.invoke(testSMSParser, + pPNParams); + + Assert.assertEquals("+15035551212", testPPNumber); + + } + + @Test + public void testBuildSMSThreadMap() throws IllegalAccessException, + IllegalArgumentException, InvocationTargetException { + + // Reflect class/method parsePhoneNumber + final String testSMSResponse = ""; + bSMSTMParams[0] = testSMSResponse; + final Map testBSMSTMap = (Map) bSMSTM.invoke(testSMSParser, + bSMSTMParams); + + // Expected object + final Date validDate = new Date(DATE_LONG); + final SMSThread expectedSMSThread = new SMSThread("testID", + "test note", validDate, null, true, true); + final Map expectedMap = new HashMap(); + expectedMap.put("testID", expectedSMSThread); + + Assert.assertEquals(expectedMap.toString(), testBSMSTMap.toString()); + + } + + @Test + public void testBuildSMSThreadMapNoInputs() throws IllegalAccessException, + IllegalArgumentException, InvocationTargetException { + + // Reflect class/method parsePhoneNumber + final String testSMSResponse = ""; + bSMSTMParams[0] = testSMSResponse; + final Map testNoInputs = (Map) bSMSTM.invoke(testSMSParser, + bSMSTMParams); + + // Expected object + final Date epochDate = new Date(0); + final SMSThread expectedSMSThread = new SMSThread("", "", epochDate, + null, false, false); + final Map expectedMap = new HashMap(); + expectedMap.put("", expectedSMSThread); + + Assert.assertEquals(expectedMap.toString(), testNoInputs.toString()); + + } + +} diff --git a/src/test/kotlin/.gitkeep b/src/test/kotlin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/.gitkeep b/src/test/resources/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/privateTestData_template.properties b/src/test/resources/test/privateTestData_template.properties similarity index 100% rename from test/privateTestData_template.properties rename to src/test/resources/test/privateTestData_template.properties diff --git a/test/test.java b/test/test.java deleted file mode 100644 index 85260c5..0000000 --- a/test/test.java +++ /dev/null @@ -1,581 +0,0 @@ -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; - -import gvjava.org.json.JSONException; -import gvjava.org.json.JSONObject; - -import com.techventus.server.voice.Voice; -import com.techventus.server.voice.datatypes.AllSettings; -import com.techventus.server.voice.datatypes.DisabledForwardingId; -import com.techventus.server.voice.datatypes.Group; -import com.techventus.server.voice.datatypes.Phone; -import com.techventus.server.voice.datatypes.Greeting; -import com.techventus.server.voice.datatypes.records.SMS; -import com.techventus.server.voice.datatypes.records.SMSThread; -import com.techventus.server.voice.exception.CaptchaRequiredException; -import com.techventus.server.voice.util.ParsingUtil; - -@SuppressWarnings("deprecation") -public class test { - - static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - static String userName = null; - static String pass = null; - static boolean connectOnStartup = false; - static Properties testProps = null; - private static Voice voice; - private static String jsonData; - - public static void main(String[] args){ - - try { - testProps = load("privateTestData.properties"); - userName = testProps.getProperty("username"); - pass = testProps.getProperty("password"); - connectOnStartup = Boolean.parseBoolean(testProps.getProperty("connectOnStartup")); - jsonData = testProps.getProperty("jsonData"); - } catch (Exception e) { - System.out.println("Could not read the testProps, falling back to input. ("+e.getMessage()+")"); - System.out.println("Enter Your Google Voice Username, eg user@gmail.com:"); - //Added this line, otherwise fails all tests. - connectOnStartup = true; - try { - userName = br.readLine(); - } catch (IOException ioe) { - System.out.println("IO error trying to read your name!"); - System.exit(1); - } - - System.out.println("Enter Your Password:"); - - - try { - pass = br.readLine(); - } catch (IOException ioe) { - System.out.println("IO error trying to read your name!"); - System.exit(1); - } - } - - try { - if(connectOnStartup) voice = new Voice(userName, pass,"GoogleVoiceJava",true,Voice.GOOGLE); - } catch(CaptchaRequiredException captEx) { - System.out.println("A captcha is required."); - System.out.println("Image URL = "+captEx.getCaptchaUrl()); - System.out.println("Capt Token = "+captEx.getCaptchaToken()); - System.out.println("Goodbye."); - System.exit(1); - } catch (IOException e) { - System.out.println("IO error creating voice! - "+e.getLocalizedMessage()); - System.out.println("Goodbye."); - System.exit(1); - } - - listTests(); - - /* - System.out.println("Enter A \"Source\" for the Log:"); - String source = null; - try { - source = br.readLine(); - } catch (IOException ioe) { - System.out.println("IO error trying to read your name!"); - System.exit(1); - } - - System.out.println("Log into Google Voice and find the _rnr_se variable in the page Source. "); - System.out.println("Enter rnr_se_ value:"); - String rnrSee = null; - try { - rnrSee = br.readLine(); - } catch (IOException ioe) { - System.out.println("IO error trying to read your name!"); - System.exit(1); - } - */ - - - } - - /** - * Lets the Tester choose the Test to run - */ - private static void listTests() { - System.out.println("Availible Tests for "+userName); - System.out.println("0: Exit"); - System.out.println("1: Multi phone enable / disable"); - System.out.println("2: Inbox paging"); - System.out.println("3: Call Announcement Settings (Presentation)"); - System.out.println("4: Set Default Voicemail Greeting"); - System.out.println("5: Change do not disturb setting."); - System.out.println("6: Change Group settings."); - System.out.println("7: Read all settings and print them (cached)"); - System.out.println("8: Read all settings and print them (uncached)"); - System.out.println("9: Read all settings - pure json driven - flat data"); - System.out.println("10: Read all settings - pure json driven - actual account data"); - System.out.println("11: Update Group Settings"); - System.out.println("12: Group settings isPhoneEnabled tests"); - System.out.println("13: List Default Phones and Enabled/Disabled Setting"); - System.out.println("14: Send SMS"); - System.out.println("15: Check SMS"); - System.out.println("16: Captcha Test"); - - int testNr = 0; - try { - testNr = Integer.parseInt(br.readLine()); - } catch (Exception e) { - System.out.println("Error trying to read the testNr!"+e.getMessage()); - System.exit(1); - } - - runTest(userName, pass, testNr); - } - - /** - * @param userName - * @param pass - * @param testNr - */ - private static void runTest(String userName, String pass, int testNr) { - if(testNr==0) {// 0: Exit - System.out.println("Exiting."); - System.exit(1); - } - try { - - - //Voice voice = new Voice(); -// try { - if(connectOnStartup) System.out.println(voice.isLoggedIn()); - //Thread.sleep(2000); - - switch (testNr) { - case 1: // 1: Multi phone enable / disable - System.out.println("******** Starting Test "+testNr+" ********"); - Phone[] phones = voice.getSettings(false).getPhones(); - // create int Array from all phone ids - int[] phonesToChangeStatus = new int[phones.length]; - - System.out.println("Current phone status:"); - for (int j = 0; j < phones.length; j++) { - phonesToChangeStatus[j] = phones[j].getId(); - System.out.println(phones[j].getName() + " " + phones[j].getId() + " " + !voice.getSettings(false).isPhoneDisabled(phones[j].getId())); - } - - //Disable all phones - for (int j = 0; j < phones.length; j++) { - voice.phoneDisable(phones[j].getId()); - } - - - phones = voice.getSettings(true).getPhones(); - // Output - System.out.println("After deactivate multi:"); - for (int j = 0; j < phones.length; j++) { - System.out.println(phones[j].getName() + " " + phones[j].getId() + " " + !voice.getSettings(false).isPhoneDisabled(phones[j].getId())); - } - - //Enable all phones - for (int j = 0; j < phones.length; j++) { - voice.phoneEnable(phones[j].getId()); - } - - // Output - phones = voice.getSettings(true).getPhones(); - System.out.println("After activate multi:"); - for (int j = 0; j < phones.length; j++) { - System.out.println(phones[j].getName() + " " + phones[j].getId() + " " + !voice.getSettings(false).isPhoneDisabled(phones[j].getId())); - } - - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 2: // 2: Inbox paging - System.out.println("******** Starting Test "+testNr+" ********"); -// Thread.sleep(2000); - System.out.println(voice.getInboxPage(1000)); - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 3: // 3: Call Announcement settings (Presentation) - System.out.println("******** Starting Test "+testNr+" ********"); - System.out.println("Type 'true' for enable, 'false' for disable"); - boolean choice = false; - try { - choice = Boolean.parseBoolean(br.readLine()); - } catch (Exception e) { - System.out.println("Error trying to read the choice!"+e.getMessage()); - System.exit(1); - } -// Thread.sleep(2000); - System.out.println(voice.setCallPresentation(choice)); - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 4: // 4: Caller ID in - System.out.println("******** Starting Test "+testNr+" ********"); - for (Iterator iterator = voice.getVoicemailList(true).iterator(); iterator.hasNext();) { - Greeting type = (Greeting) iterator.next(); - System.out.println(type.toString()); - } - System.out.println("Choose the id of the voicemail greeting to use. ie '0' system standard or '1','2'"); - String voicemailNr = "0"; - try { - voicemailNr = br.readLine(); - } catch (Exception e) { - System.out.println("Error trying to read the choice!"+e.getMessage()); - System.exit(1); - } -// Thread.sleep(2000); - voice.setVoicemailGreetingId(voicemailNr); - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 5: // 5: Do not disturb - System.out.println("******** Starting Test "+testNr+" ********"); - System.out.println("Type 'true' for enable, 'false' for disable"); - boolean dndChoice = false; - try { - dndChoice = Boolean.parseBoolean(br.readLine()); - } catch (Exception e) { - System.out.println("Error trying to read the choice!"+e.getMessage()); - System.exit(1); - } - voice.setDoNotDisturb(dndChoice); - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 6: // 6: Group settings - System.out.println("******** Starting Test "+testNr+" ********"); - Group[] groups1 = voice.getSettings(false).getSettings().getGroups(); - String jsonGroups=""; - for (int i = 0; i < groups1.length; i++) { - jsonGroups+=groups1[i].toJson(); - } - System.out.println("All to json:"+jsonGroups); - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 7: // 7: Read all settings - cached - System.out.println("******** Starting Test "+testNr+" ********"); - System.out.println(voice.getSettings(false).getSettings().toJson()); - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 8: // 8: Read all settings - uncached - System.out.println("******** Starting Test "+testNr+" ********"); - System.out.println(voice.getSettings(true).getSettings().toJson()); - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 9: // 9: Read all settings - pure json driven - System.out.println("******** Starting Test "+testNr+" ********"); - try { - System.out.println("******** Original JSON Data ********"); - JSONObject origSettings = new JSONObject(jsonData); - System.out.println(origSettings.toString(4)); - - System.out.println("******* Parsed back and forth ******"); - AllSettings settings2 = new AllSettings(jsonData); - System.out.println(settings2.toJsonObject().toString(4)); - - System.out.println("******* Creating new AllSettings from old JSON ******"); - AllSettings settings4 = new AllSettings(settings2.toJsonObject().toString()); - System.out.println(settings4.toJsonObject().toString(4)); - } catch (JSONException e) { - System.out.println("Error displaying json:"+e.getLocalizedMessage()); - e.printStackTrace(); - } - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 10: // 10: Read all settings - pure json driven - account data - System.out.println("******** Starting Test "+testNr+" ********"); -// try { - System.out.println("******** Test REMOVED FOR NOW ********"); -// System.out.println("******** Original JSON Data ********"); -// String lJson = ParsingUtil.removeUninterestingParts(voice.getONLYFORTEST("https://www.google.com/voice/settings/tab/groups"), "", false); -// JSONObject origSettings = new JSONObject(lJson); -// System.out.println(origSettings.toString(4)); -// -// System.out.println("******* JsonObject from AllSettings ******"); -// AllSettings settings2 = new AllSettings(lJson); -// JSONObject objFromAllSettings = settings2.toJsonObject(); -// System.out.println(objFromAllSettings.toString(4)); -// -// System.out.println("******* Creating new AllSettings from old JSON ******"); -// AllSettings settings3 = new AllSettings(objFromAllSettings.toString()); -// System.out.println(settings3.toJsonObject().toString(4)); -// -// } catch (JSONException e) { -// System.out.println("Error displaying json:"+e.getLocalizedMessage()); -// e.printStackTrace(); -// } - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 11: // 11: Update Group settings - System.out.println("******** Starting Test "+testNr+" ********"); - try { - System.out.println("******** Before ********"); - - AllSettings settings2 = voice.getSettings(false); - JSONObject objFromAllSettings = settings2.toJsonObject(); - System.out.println(objFromAllSettings.toString(4)); - - System.out.println("Choose group to change settings (15)"); - String groupId = "0"; - try { - groupId = br.readLine(); - } catch (Exception e) { - System.out.println("Error trying to read the choice!"+e.getMessage()); - System.exit(1); - } - - Group[] groups = voice.getSettings(false).getSettings().getGroups(); - for (int j = 0; j < groups.length; j++) { - /* New Settings - "directConnect": true, - "disabledForwardingIds": {"1": true}, - "greetingId": 2, - "id": "15", - "isCustomDirectConnect": true, - "isCustomForwarding": true, - "isCustomGreeting": true, - */ - if(groups[j].getId().equals(groupId)) { - System.out.println("Changing settings for Group: "+groups[j].getName()); - groups[j].setCustomDirectConnect(true); - groups[j].setDirectConnect(true); - groups[j].setCustomForwarding(true); - List disList = new ArrayList(); - disList.add(new DisabledForwardingId("1", true)); - groups[j].setDisabledForwardingIds(disList); - groups[j].setCustomGreeting(true); - groups[j].setGreetingId(2); - voice.setNewGroupSettings(groups[j]); - } - } - - System.out.println("******** After ********"); - AllSettings settings3 = voice.getSettings(true); - System.out.println(settings3.toJsonObject().toString(4)); - - } catch (JSONException e) { - System.out.println("Error displaying json:"+e.getLocalizedMessage()); - e.printStackTrace(); - } - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 12: // 12: Group isPhoneEnabled Tests - System.out.println("******** Starting Test "+testNr+" ********"); - try { - AllSettings settings3 = voice.getSettings(true); - Group[] groups = settings3.getSettings().getGroups(); - int[] phoneIds = settings3.getPhoneList(); - for (int j = 0; j < groups.length; j++) { - System.out.println("+++ Disabled Phones in "+groups[j].getName()+" +++"); - for (int j2 = 0; j2 < phoneIds.length; j2++) { - System.out.println(phoneIds[j2] + ":" + groups[j].isPhoneDisabled(phoneIds[j2])); - } - - } - } catch (JSONException e) { - System.out.println("Error displaying json:"+e.getLocalizedMessage()); - e.printStackTrace(); - } - System.out.println("******** Finished Test "+testNr+" ********"); - break; - - case 13: // 13: List Default Phones and Enabled/Disabled Setting - System.out.println("*********Starting Test "+testNr+" *******"); - - AllSettings settings3 = voice.getSettings(true); - List phoneList =settings3.getPhoneListAsList(); - Phone[] actualPhoneArray = settings3.getPhones(); - for(Integer phoneint:phoneList){ - inner: for(int ig=0;ig threads = voice.getSMSThreads(); - for (SMSThread thread : threads) { - System.out.println("\tThread " + thread.getId()); - for (SMS sms : thread.getAllSMS()) { - System.out.println("\t\tMessage: " + sms.getContent()); - } - } - System.out.println("******** Finished Test "+testNr+" ********"); - break; - case 16: // 15: Captcha Test - System.out.println("*********Starting Test "+testNr+" *******"); - System.out.println("Enter Fake Password:"); - String tempPass = br.readLine(); - - boolean tryAgain = true; - int counter = 0; - while(tryAgain) { - System.out.println("\n\rAttempting new Login... " + counter++); - try { - voice = null; - /* (Toby) added here the counter to the tempPass, so that we actually get the CaptchaEx - bc without - * it I had 300 tries only getting the IO Error, with counter (each time a different password) - * I got the captcha after 30 tries - */ - voice = new Voice(userName, tempPass+counter,"GoogleVoiceJavaUnitTests",true,Voice.GOOGLE); - } catch (CaptchaRequiredException e) { - System.out.println("Captcha found! - " + e.getLocalizedMessage()); - System.out.println("Token: " + e.getCaptchaToken()); - System.out.println("URL : " + e.getCaptchaUrl()); - System.out.println("Please enter the captcha challenge response from the URL:"); - String response = br.readLine(); - // create the voice object with the response - voice = new Voice(userName, pass,"GoogleVoiceJavaUnitTests",true,Voice.GOOGLE,response,e.getCaptchaToken()); - tryAgain = false; - } catch (IOException e) { - System.out.println("IO error creating voice! - "+e.getLocalizedMessage()); - - //System.out.println("Try Again? (Y/N):"); - //tryAgain = br.readLine().equalsIgnoreCase("Y"); - //System.out.println(); - } - - } - - - - -// voice = null; -// voice = new Voice(userName, tempPass,"GoogleVoiceJavaUnitTests",true,Voice.GOOGLE); - - System.out.println(""); - break; - default: - System.out.println("Test "+testNr+" not found, exiting."); - System.exit(1); - break; - } - - -// Thread.sleep(2000); - - //System.out.println(voice.getSMS()); - //System.out.println(voice.getInbox()); -// System.out.println(voice.getInboxPage(1000)); - //System.out.println(voice.getInboxPage(100)); - /* - System.out.println(voice.getInbox()); - Thread.sleep(2000); - System.out.println(voice.phoneDisable(6)); - - - System.out.println(voice.getInbox()); - Thread.sleep(2000); - System.out.println("**********************************"); - System.out.println(voice.getMissed()); - Thread.sleep(2000); - System.out.println("**********************************"); - System.out.println(voice.getPlaced()); - Thread.sleep(2000); - System.out.println("**********************************"); - System.out.println(voice.getReceived()); - Thread.sleep(2000); - System.out.println("**********************************"); - - System.out.println("**********************************"); - System.out.println(voice.getRecorded()); - Thread.sleep(2000); - System.out.println("**********************************"); - System.out.println(voice.getSMS()); - Thread.sleep(2000); - System.out.println("**********************************"); - System.out.println(voice.getSpam()); - Thread.sleep(2000); - System.out.println("**********************************"); - System.out.println(voice.getStarred()); - Thread.sleep(2000); - System.out.println("**********************************"); - */ - -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } - } catch (IOException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } - listTests(); // List the Tests again - } - - /** - * Load a Properties File - * @param propsFile - * @return Properties - * @throws IOException - */ - private static Properties load(String propsFile) throws IOException { -// Properties props = new Properties(); -// -// ResourceBundle.getBundle(propsFile); -// final ResourceBundle rb = ResourceBundle.getBundle(propsFile, Locale.getDefault (), ClassLoader.getSystemClassLoader()); -// for (Enumeration keys = rb.getKeys (); keys.hasMoreElements ();) -// { -// final String key = (String) keys.nextElement (); -// final String value = rb.getString (key); -// -// props.put (key, value); -// } -// return props; - - Properties result = null; - InputStream in = null; - - if (! propsFile.endsWith (".properties")) - propsFile = propsFile.concat (".properties"); - - // Returns null on lookup failures: - in = ClassLoader.getSystemClassLoader().getResourceAsStream (propsFile); - if (in != null) - { - result = new Properties (); - result.load (in); // Can throw IOException - } - testProps = result; - return result; - } - -} diff --git a/wiki/ApplicationGallery.wiki b/wiki/ApplicationGallery.wiki new file mode 100644 index 0000000..cc9ed68 --- /dev/null +++ b/wiki/ApplicationGallery.wiki @@ -0,0 +1,12 @@ +#summary A listing of Applications which rely on Google Voice Java +#labels Featured + +Please let us know about your application which uses Google Voice Java + +==Google Voice Locations== + +The Android Application built by the founder of Google-Voice-Java, [http://code.google.com/p/android-google-voice-locations/ Google Voice Locations], is now Open Source under the GPL. It was built on this Google Voice Java Library. It uses the Enable/Disable functionality of Google Voice Java to allow location aware phone activation preferences to be set on Android. + +==Locale Google Voice Plugin== + +[http://sites.google.com/site/steelgirderdevelopmentsite/home/ Steelgirder Development] has a wonderful plugin for Locale which incorporates the latest Google Voice Java API updates such as custom greeting, enable/disable, do not disturb, group settings, etc. \ No newline at end of file diff --git a/wiki/Changelog.wiki b/wiki/Changelog.wiki new file mode 100644 index 0000000..bbca38b --- /dev/null +++ b/wiki/Changelog.wiki @@ -0,0 +1,18 @@ +#summary A list of changes in the new version of google-voice-java + += Changelog = + +New in version 1.4 + + Version 1.4 contains many upgrades. Some breaking changes may exist from 1.3 so test your code thoroughly. + + *TThe Phone objects created at startup and placed in the phoneList now contain an enabled/disabled boolean parameter corresponding to whether the phones are set to ring or not. + + *CCall Presentation can now be toggled on and off + + *NNew Record Objects and a parser have been added for things like Voicemail, Call, SMS, Transcript + + +New in version 1.3 + + *CCalls to Google are now "spoofed" to appear as though they originate from Google Chrome. This was done because in developing Google Voice Locations for the Android platform, it was observed that Google would not properly deliver webpage content to the API if it originated from a mobile device. Spoofing solved the problem. We have thus hard-coded the user-agent property to Chrome to make the behaviour consistent from every device. \ No newline at end of file diff --git a/wiki/ClassHierarchy.wiki b/wiki/ClassHierarchy.wiki new file mode 100644 index 0000000..230fcf1 --- /dev/null +++ b/wiki/ClassHierarchy.wiki @@ -0,0 +1,14 @@ +#summary The class Structure of the Project. +#labels Phase-Design + += Introduction = + +The class Structure of the Project + + += Class Diagram only class names and relations = +[http://google-voice-java.googlecode.com/files/class_diagram_classnames.gif http://google-voice-java.googlecode.com/files/class_diagram_classnames.gif] + += Class Diagram detailed = +Download detailed diagram with all methods and fields +http://code.google.com/p/google-voice-java/downloads/detail?name=class_diagram_detailed.jpeg&can=2&q=#makechanges \ No newline at end of file diff --git a/wiki/Contributing.wiki b/wiki/Contributing.wiki new file mode 100644 index 0000000..840ff46 --- /dev/null +++ b/wiki/Contributing.wiki @@ -0,0 +1,67 @@ +=Setting Up a Development Enviorment and Contributing= + +Are you looking to start contributing to the google-voice-java project? Or perhaps just hack some custom changes in on your own? Here are a couple tips to help you get set up. + +== Mailing List == +The easiest way to get in contact with the contributers is through the mailing list located here: http://groups.google.com/group/google-voice-java + +== Setting Up a Development Environment== + +=== Downloading the Source Code === + +There are instructions on how to download the source here: + +[http://code.google.com/p/google-voice-java/source/checkout] + +For a one liner run the following command from your shell: + +{{{ +svn checkout http://google-voice-java.googlecode.com/svn/trunk/ google-voice-java-read-only +}}} + +=== Building from Source === + +Currently the project is developed in Eclipse, using its automated build tools. If you don't already have it, you will need a copy of Eclipse from: + +http://www.eclipse.org/downloads/ + +The IDE for Java Developers is fine. You don't need to worry about the other versions offered. + +Once you have Eclipse installed, start the IDE and do the following: + +*File Menu > New > Java Project +*Check the create project from existing source radio, and navigate to the folder you downloaded earlier. +*Make sure you are using Java 1.6 or greater! You may have compile errors with a lower version. +*Click finish. + +Click the round green run button. This will build the source and execute it. You may need to specify, run as "Java Application" or a startup class. Choose test/test.java. + +If everything has gone according to plan, you will see: + +{{{ +Could not read the testProps, falling back to input. (null) +Enter Your Google Voice Username, eg user@gmail.com: +}}} + +You have built from source! + +We're working on Eclipse independent build tools for the project such as Maven and Ant. If you prefer a different coding environment than Eclipse, you can wait for these scripts or write your own and contribute them. + +=== Contributing === + +Remember back when we told you how to download the source... Well, it turns out that is read-only. If you want to contribute back to the project, you will need committer status on the project and a different url. You need a google account (We hope you can figure this out on your own!). Once you have an account, request commit permission from the current project maintainer. If you aren't too shady, you get commit access. Then when you visit: + +[http://code.google.com/p/google-voice-java/source/checkout] + +you will see a new url that looks like this: + +{{{ +# Project members authenticate over HTTPS to allow committing changes. +svn checkout https://google-voice-java.googlecode.com/svn/trunk/ google-voice-java --username user.name@gmail.com + +When prompted, enter your generated googlecode.com password. +}}} + +If you checkout from that, you will be able to push upstream. + +Happy hacking! \ No newline at end of file diff --git a/wiki/GettingStarted.wiki b/wiki/GettingStarted.wiki new file mode 100644 index 0000000..30d199f --- /dev/null +++ b/wiki/GettingStarted.wiki @@ -0,0 +1,175 @@ += IMPORTANT NOTE = +This Getting Started guide is significantly outdated, especially regarding project building and authentication. +The project has been migrated to Gradle (from Ant) and now uses OAuth 2.0 for authentication (ClientLogin is defunct). + +'''Please refer to the main [Project_Root_README.md] file for current instructions on building the project and setting up authentication.''' + +The API usage examples below might still offer some insight but should be used with caution, keeping in mind the authentication mechanism has changed. + + +#summary Simple Overview of this Simple Library. +#labels Featured,Phase-Deploy,Phase-Implementation,Phase-Support,Phase-Requirements,Phase-Design + + +(This rough guide was written for version 1.3. Much new functionality has been added to future versions. We could definitely use some updated documentation for the new functionality if anyone wishes to volunteer.) + + + + += Getting Started = + +Google Voice Java is an API. You must first have a Google Voice Account and know how to hack some Java for this to be useful. + +So far our tests of this library have worked well. To do a simple command line test, enter the following in your commandline: + +{{{ + + java -jar {path}/google-voice-java-{version}.jar + +}}} + +This simply logs in, displays your auth key, fetches contents of your inbox and sentbox, and displays the HTML. It runs the test.jar script. Add the jar to your classpath and access the Voice.class to do whatever you need. + + + + + +Now you must create a Voice object + +{{{ + +import com.techventus.server.voice.Voice; + +... + + Voice voice = new Voice(userName, pass); // Note: This constructor is legacy. See new auth flow. + +... + +}}} + +Now, for example, to view the Inbox, call the function: + +{{{ + + voice.getInbox(); + +}}} + + +This function, and the other similar functions return raw HTML or XML code which must be parsed by you. We may add some kind of parser in the future. Since this project is FOSS, feel free to contribute one. + + + +== Placing Calls == + + +To place a call, you simply pass the number from which you wish to call (originNumber) and the number being called (destinationNumber). Google Voice only allows you to use an Origin Number which has already been registered with them as associated with that Google Voice Account. + +We havent tried otherwise, but would recommend against using special characters in the phone numbers. However, we have tested using '+' with International calling and it works just fine. + +{{{ +... + + String originNumber = "2125551234"; + + String destinationNumber = "4155557895"; + + voice.call(originNumber, destinationNumber); + +... +}}} + + +When this code is run, the originNumber should ring (assuming the registration checks out). + + + + +== Sending SMS Text Messages == + + +Sending an SMS is also trivial. + +{{{ +... + + voice.sendSMS(destinationNumber, txt); + +... +}}} + + + +== Logging In (OAuth 2.0) == +Authentication is now handled via OAuth 2.0. This involves a one-time setup using the `initiateGoogleAuth` Gradle task, which guides you through browser-based Google login and consent. + +'''For detailed steps, please see the [Project_Root_README.md#authentication-oauth-20-setup---one-time Authentication Section in the README.md].''' + +The old method of `Voice voice = new Voice(userName, pass);` is no longer applicable for primary authentication. The library will automatically use tokens obtained through the OAuth flow, which are loaded by `GVCookieManager`. The `Voice` class constructors that accept username and password still exist but rely on the deprecated ClientLogin mechanism, which is unlikely to work and should not be the primary way to use the library. + +If something is off and you trigger a CAPTCHA from Google Voice, you will probably have to log back into the account manually. This API is not equipped to handle the CAPTCHA request in any meaningful way at this time. (Note: CAPTCHA issues are less common with OAuth 2.0 but can still occur in rare circumstances with Google's systems). + +== Enable/Disable Phones to Receive Calls == + +To enable or disable a phone, you must determine the integer identification of that phone. Upon creating a successful Voice object, a list of Phone objects is created and populated from the information in your Google Voice account, phoneList. Each Phone object in the phoneList has the following protected variables + +{{{ + + protected String id; + protected String number; + protected String formattedNumber; + protected String type; + protected String name; + protected String carrier; + protected Boolean verified; + +}}} + +perhaps the easist way to determine the id of the phone you wish to enable or disable is to search the name variable of Phones in the list and then call the id variable. + +Once the id is determined, enable or disable with: + +{{{ + voice. phoneEnable(int ID); + + voice. phoneDisable(int ID); + +}}} + +A String is returned with Google's result output of this action. + + +== Other Callable Functions == + +A complete list of available functions to check to pull recent info from the Google Voice Account. Again, it is up to you to do the parsing. All functions return a String or throw an IOException. + + +{{{ + + getGeneral() + + getInbox() + + getStarred() + + getRecent() + + getSpam() + + getRecorded() + + getPlaced() + + getReceived() + + getMissed() + + getSMS() + + +}}} + +== Where to get help == + +You can subscribe to our mailing list at http://groups.google.com/group/google-voice-java and post your questions there. \ No newline at end of file diff --git a/wiki/MavenBranch.wiki b/wiki/MavenBranch.wiki new file mode 100644 index 0000000..c79b272 --- /dev/null +++ b/wiki/MavenBranch.wiki @@ -0,0 +1,63 @@ +#summary Using Maven to manage project + += Introduction = + +The Maven branch provides an example of automating the project build, allowing it to be built outside the Eclipse IDE. + +Using Maven removes the need for libraries, Javadocs, and Eclipse files to be in Subversion.
+Libraries are managed as dependencies in the project pom.xml, downloaded by Maven to the local repository.
+Javadocs can be generated by a Maven plugin goal, see example below.
+Eclipse files can be generated by a Maven plugin, see example below, or these are not needed if using m2eclipse. + +The project depends on the modified json library (different package name). These source files were added to Subversion. + +The current branch represents the fewest changes to the codebase with more extensive changes described in the future steps below. + +The Maven pom contains project metadata, including the version. For the branch, the working version is assumed to be 2.0 and since it is under development (non-release) the -SNAPSHOT qualifier is included (2.0-SNAPSHOT). + +The scm urls in the pom point to the trunk location in Subversion, instead of the Maven branch location. + +The end of the pom includes a profile for possibly deploying the released project artifacts to the Sonatype Maven repository and Maven central repository. + += Command Line Goals = + +These goals require [http://www.oracle.com/technetwork/java/javase/downloads/index.html Java JDK6] and [http://maven.apache.org/download.html Maven] (2.2.1 used here) to be installed.
+As specified by the Maven README, the JAVA_HOME environment variable is expected to be set to the JDK location,
+and the PATH environment variable is expected to include the Maven bin directory. + +Run the following commands from the project base directory, containing the pom.xml + +Build the project: + * Run: mvn clean install + * The built jar is located at target/google-voice-java-2.0-SNAPSHOT.jar + +Generate Javadocs: + * Run: mvn javadoc:javadoc + * The generated HTML files are located at target/site/apidocs + +Generate Eclipse project: + * Run: mvn eclipse:configure-workspace -Declipse.workspace=/path/to/workspace + * Run: mvn eclipse:eclipse + * The .project and .classpath files are generated + * Each time the pom dependencies are changed, these can be updated running eclipse:eclipse + += Future Steps = + * Remove lib and doc directories + * Remove .project and .classpath files + * Use Maven convention for source directory: + * The src directory could be changed to src/main/java + * The source directory build property in the pom.xml can be removed + * The google-voice and json libraries can be separated: + * Change to multi-module project + * Change existing pom to parent pom + * Move json classes to new module directory with pom.xml + * Move google-voice classes to new module directory with pom.xml, with dependency on json module + * Separate jars are built for json and google-voice + * Trim dependencies if needed: + * Maven brings in transitive dependencies (icu4j, jdom, xalan, xercesImpl, xml-apis, xmlParserAPIs, xom) + * Unnecessary dependencies can be excluded + * Cleanup existing test: + * The test directory could be moved to src/test/java and src/test/resources + * The test class name could be changed to ManualVoiceTest, excluded from build testing as necessary + * The test class package could be changed to com.techventus.server.voice + * Add junit tests to src/test/java and junit test dependency to pom.xml \ No newline at end of file