├── .gitignore ├── BUILDING.md ├── CONTRIBUTING.md ├── Client ├── android-client-mock │ ├── AndroidManifest.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── divide │ │ └── client │ │ └── android │ │ └── mock │ │ ├── AndroidDebugConfig.java │ │ ├── DebugAuthActivity.java │ │ ├── DivideDrawer.java │ │ └── MockAndroidModule.java ├── android-client │ ├── .gitignore │ ├── AndroidManifest.xml │ ├── pom.xml │ ├── proguard.cfg │ ├── res │ │ ├── layout │ │ │ ├── act_login.xml │ │ │ └── act_register.xml │ │ └── values │ │ │ └── strings.xml │ ├── sample │ │ ├── .gitignore │ │ ├── AndroidManifest.xml │ │ ├── pom.xml │ │ ├── proguard-project.txt │ │ ├── res │ │ │ ├── drawable-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-ldpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── layout │ │ │ │ ├── creds_row.xml │ │ │ │ └── main.xml │ │ │ ├── values │ │ │ │ └── strings.xml │ │ │ └── xml │ │ │ │ ├── account_prefs.xml │ │ │ │ ├── authenticator.xml │ │ │ │ └── prefs.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── client_sample │ │ │ ├── BackendObjectAdaper.java │ │ │ ├── MyActivity.java │ │ │ ├── MyApplication.java │ │ │ └── Settings.java │ └── src │ │ └── main │ │ └── java │ │ ├── com │ │ └── google │ │ │ └── android │ │ │ └── gcm │ │ │ ├── GCMBaseIntentService.java │ │ │ ├── GCMBroadcastReceiver.java │ │ │ ├── GCMConstants.java │ │ │ └── GCMRegistrar.java │ │ └── io │ │ └── divide │ │ └── client │ │ └── android │ │ ├── AndroidBackend.java │ │ ├── AndroidConfig.java │ │ ├── AndroidModule.java │ │ ├── AuthActivity.java │ │ ├── CredentialView.java │ │ ├── MenuHandler.java │ │ ├── cache │ │ ├── DatabaseInitializer.java │ │ ├── LocalStorageSQLite.java │ │ ├── NameValuePair.java │ │ └── SQLiteUtils.java │ │ ├── push │ │ ├── PushEvent.java │ │ ├── PushListener.java │ │ ├── PushManager.java │ │ └── PushWebService.java │ │ └── security │ │ ├── PRNGFixes.java │ │ └── UserUtils.java ├── java-client │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── divide │ │ │ └── client │ │ │ ├── Backend.java │ │ │ ├── BackendConfig.java │ │ │ ├── BackendModule.java │ │ │ ├── BackendObject.java │ │ │ ├── BackendServices.java │ │ │ ├── BackendUser.java │ │ │ ├── Config.java │ │ │ ├── auth │ │ │ ├── AccountStorage.java │ │ │ ├── AuthActivity.java │ │ │ ├── AuthManager.java │ │ │ ├── AuthService.java │ │ │ ├── AuthUtils.java │ │ │ ├── AuthWebService.java │ │ │ ├── CredentialView.java │ │ │ ├── LoginEvent.java │ │ │ ├── LoginListener.java │ │ │ ├── LoginState.java │ │ │ ├── RecoveryResponse.java │ │ │ ├── SignInResponse.java │ │ │ ├── SignUpResponse.java │ │ │ └── credentials │ │ │ │ ├── GenericAccountStorage.java │ │ │ │ ├── LocalCredentials.java │ │ │ │ ├── LoginCredentials.java │ │ │ │ ├── SignUpCredentials.java │ │ │ │ ├── ValidCredentials.java │ │ │ │ └── XmlAccoutStorage.java │ │ │ ├── cache │ │ │ ├── LocalStorageIBoxDb.java │ │ │ └── Wrapper.java │ │ │ ├── data │ │ │ ├── CountObject.java │ │ │ ├── DataManager.java │ │ │ ├── DataWebService.java │ │ │ ├── EmptyCallback.java │ │ │ ├── ObjectManager.java │ │ │ └── ServerResponse.java │ │ │ ├── http │ │ │ ├── Metadata.java │ │ │ └── Status.java │ │ │ └── web │ │ │ ├── AbstractWebManager.java │ │ │ ├── ConnectionListener.java │ │ │ ├── OnRequestInterceptor.java │ │ │ └── RequestObject.java │ │ └── test │ │ └── java │ │ └── io │ │ └── divide │ │ └── client │ │ ├── BackendObjectTest.java │ │ └── cache │ │ └── LocalStorageIBoxDbTest.java ├── mock-client │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── divide │ │ │ └── client │ │ │ ├── DebugModule.java │ │ │ ├── GsonResponse.java │ │ │ ├── MockBackendModule.java │ │ │ ├── MockLocalStorage.java │ │ │ ├── auth │ │ │ ├── MockAuthManager.java │ │ │ ├── MockAuthWebService.java │ │ │ └── MockKeyManager.java │ │ │ ├── data │ │ │ ├── MockDataManager.java │ │ │ └── MockDataWebService.java │ │ │ ├── push │ │ │ ├── MockPushManager.java │ │ │ └── MockPushWebService.java │ │ │ └── ui │ │ │ └── DebugUIContainer.java │ │ └── test │ │ └── java │ │ └── io │ │ └── divide │ │ └── client │ │ ├── BackendObjectTest.java │ │ ├── BackendTest.java │ │ ├── BackendUserTest.java │ │ ├── ClientTest.java │ │ ├── auth │ │ └── AuthManagerTest.java │ │ ├── cache │ │ ├── CustomSQLiteShadow.java │ │ ├── DBHelper.java │ │ ├── LocalStorageNoSQLTest.java │ │ └── LocalStorageSQLiteTest.java │ │ └── data │ │ └── DataManagerTest.java └── pom.xml ├── Dao ├── common │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── divide │ │ │ └── dao │ │ │ └── ServerDAO.java │ │ └── test │ │ └── java │ │ └── io │ │ └── divide │ │ └── dao │ │ ├── DAOTest.java │ │ ├── Keyable.java │ │ ├── TestObject1.java │ │ └── TestObject2.java ├── dao-objectify │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── divide │ │ │ └── dao │ │ │ └── appengine │ │ │ ├── BackendToOfy.java │ │ │ ├── KeyObject.java │ │ │ ├── ObjectifyDAO.java │ │ │ ├── OfyObject.java │ │ │ └── OfyService.java │ │ └── test │ │ └── java │ │ └── io │ │ └── divide │ │ └── dao │ │ └── appengine │ │ ├── BackendToOfyTest.java │ │ └── ObjectifyDAOTest.java ├── dao-orientdb │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── divide │ │ │ └── dao │ │ │ └── orientdb │ │ │ ├── HighLanderIndexFactory.java │ │ │ ├── ODocumentWrapper.java │ │ │ ├── OIndexHighLander.java │ │ │ └── OrientDBDao.java │ │ └── test │ │ └── java │ │ └── io │ │ └── divide │ │ └── dao │ │ └── orientdb │ │ ├── ODocumentWrapperTest.java │ │ └── OrientDBDaoTest.java └── pom.xml ├── LICENSE.txt ├── README.md ├── Server ├── pom.xml ├── sample │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── divide │ │ │ └── server │ │ │ └── sample │ │ │ └── SomeApplication.java │ │ └── webapp │ │ ├── WEB-INF │ │ ├── appengine-web.xml │ │ ├── logging.properties │ │ └── web.xml │ │ └── stylesheets │ │ └── main.css └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── divide │ │ │ └── server │ │ │ ├── AuthApplication.java │ │ │ ├── GZIPReaderInterceptor.java │ │ │ ├── auth │ │ │ ├── EnforcePath.java │ │ │ ├── EnforcePathProcessor.java │ │ │ ├── ResponseFilter.java │ │ │ ├── SecManager.java │ │ │ ├── SecurityFilter.java │ │ │ └── UserContext.java │ │ │ ├── dao │ │ │ ├── CredentialBodyHandler.java │ │ │ ├── DAOManager.java │ │ │ ├── GsonMessageBodyHandler.java │ │ │ ├── ServerCredentials.java │ │ │ ├── ServerObject.java │ │ │ └── Session.java │ │ │ ├── endpoints │ │ │ ├── AuthenticationEndpoint.java │ │ │ ├── DataEndpoint.java │ │ │ ├── MetaEndpoint.java │ │ │ └── PushEndpoint.java │ │ │ └── utils │ │ │ └── ResponseUtils.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── javax.annotation.processing.Processor │ └── test │ └── java │ └── io │ └── divide │ └── server │ ├── AuthApplicationTest.java │ ├── AuthServerHelper.java │ ├── ServerTest.java │ ├── TestApplication.java │ ├── TestEndpoint.java │ ├── TestUtils.java │ ├── WebContainerFactory.java │ ├── auth │ └── SecurityFilterTest.java │ ├── dao │ └── ServerCredentialsTest.java │ └── endpoints │ ├── AuthenticationEndpointTest.java │ ├── DataEndpointTest.java │ └── PushEndpointTest.java ├── Shared ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ ├── io │ │ └── divide │ │ │ ├── otto │ │ │ ├── AnnotatedHandlerFinder.java │ │ │ ├── Bus.java │ │ │ ├── DeadEvent.java │ │ │ ├── EventHandler.java │ │ │ ├── EventProducer.java │ │ │ ├── HandlerFinder.java │ │ │ ├── Produce.java │ │ │ ├── Subscribe.java │ │ │ ├── SubscriberHandlerFinder.java │ │ │ └── ThreadEnforcer.java │ │ │ └── shared │ │ │ ├── event │ │ │ ├── AutoSubscriber.java │ │ │ ├── Event.java │ │ │ ├── EventManager.java │ │ │ └── Subscriber.java │ │ │ ├── file │ │ │ ├── FileUtils.java │ │ │ ├── QueuedWork.java │ │ │ ├── Storage.java │ │ │ ├── XmlStorage.java │ │ │ └── XmlUtils.java │ │ │ ├── logging │ │ │ └── Logger.java │ │ │ ├── server │ │ │ ├── AuthServerLogic.java │ │ │ ├── DAO.java │ │ │ ├── KeyManager.java │ │ │ └── ServerLogic.java │ │ │ ├── transitory │ │ │ ├── Credentials.java │ │ │ ├── DBObject.java │ │ │ ├── EncryptedEntity.java │ │ │ ├── FilePermissions.java │ │ │ ├── TransientObject.java │ │ │ └── query │ │ │ │ ├── Clause.java │ │ │ │ ├── Count.java │ │ │ │ ├── MetaDataClause.java │ │ │ │ ├── OPERAND.java │ │ │ │ ├── Query.java │ │ │ │ ├── QueryBuilder.java │ │ │ │ ├── SelectOperation.java │ │ │ │ └── UserDataClause.java │ │ │ └── util │ │ │ ├── AuthTokenUtils.java │ │ │ ├── Base64.java │ │ │ ├── BitMask.java │ │ │ ├── Crypto.java │ │ │ ├── DaoUtils.java │ │ │ ├── IOUtils.java │ │ │ ├── NetUtils.java │ │ │ ├── ObjectUtils.java │ │ │ ├── ReflectionUtils.java │ │ │ └── Uuid32Generator.java │ │ └── org │ │ └── apache │ │ └── http │ │ └── HttpStatus.java │ └── test │ └── java │ └── io │ └── divide │ └── shared │ ├── file │ └── XmlStorageTest.java │ ├── transitory │ ├── FilePermissionsTest.java │ ├── TransientObjectTest.java │ └── query │ │ └── QueryTest.java │ └── util │ └── BitMaskTest.java ├── dependency_setup ├── .gitignore ├── iboxdb │ ├── iBoxDB-1.5.2.jar │ └── pom.xml ├── objectify │ ├── objectify-custom.jar │ └── pom.xml ├── pom.xml ├── setup.bat └── setup.sh └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | .idea 3 | *.iml 4 | target/ 5 | gen-external-apklibs/ 6 | *.DS_Store 7 | dependency-reduced-pom.xml -------------------------------------------------------------------------------- /BUILDING.md: -------------------------------------------------------------------------------- 1 | Building Divide.io 2 | =========== 3 | ##Prerequisites 4 | You must have git, Maven, and JDK (version 6 or above) installed. 5 | 6 | ##Step 1 7 | Clone the repo: 8 | 9 | ``` 10 | git clone https://github.com/HiddenStage/divide.git 11 | ``` 12 | ##Step 2 13 | **For OS X:** 14 | 15 | Go to the `dependency_setup` directory and run `setup.sh` 16 | 17 | ``` 18 | cd dependency_setup 19 | sh setup.sh 20 | ``` 21 | 22 | **For Windows:** 23 | 24 | Go to the `dependency_setup` directory and run `setup.bat` 25 | 26 | ``` 27 | cd dependency_setup 28 | setup.bat 29 | ``` 30 | 31 | *If you run into ‘cmd’ is not recognized as an internal or external command, make sure you have “C:\Windows\System32” in your Path variable.* 32 | 33 | ##Step 3 34 | Go the the root directory then clean and build the project. (This may take awhile as libraries will download and tests will be run) 35 | 36 | ``` 37 | mvn clean install 38 | ``` 39 | 40 | **Notes:** 41 | * SDK API 19 requires all Google APIs and Google Wear APIs. 42 | * You’ll need to have 'Google Cloud Messaging for Android Library’ installed. You may have to search for obsolete libraries in the Android SDK Manager. 43 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | =========== 3 | We're always looking to make Divide.io better. If you would like to contribute code, all you have to do is fork our repository and send a pull request. 4 | 5 | Before sending a pull request please make sure the code compiles and all tests are passing by running `mvn clean verify`. 6 | -------------------------------------------------------------------------------- /Client/android-client-mock/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /Client/android-client-mock/src/main/java/io/divide/client/android/mock/DebugAuthActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android.mock; 18 | 19 | import android.content.Context; 20 | import android.os.Bundle; 21 | import io.divide.client.BackendServices; 22 | import io.divide.client.BackendUser; 23 | import io.divide.client.android.AuthActivity; 24 | import io.divide.client.android.CredentialView; 25 | import io.divide.client.auth.LoginListener; 26 | import io.divide.shared.logging.Logger; 27 | 28 | public class DebugAuthActivity extends AuthActivity { 29 | Logger logger = Logger.getLogger(AuthActivity.class); 30 | 31 | public static final String TITLE_EXTRA = "title_extra_key"; 32 | 33 | /** 34 | * Called when the activity is first created. 35 | */ 36 | @Override 37 | public void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | String title = this.getIntent().getStringExtra(TITLE_EXTRA); 40 | if(title == null) title = getApplicationName(this); 41 | CredentialView credentialView = new CredentialView(this,title); 42 | DivideDrawer.attach(this,credentialView); 43 | BackendServices.addLoginListener(new LoginListener() { 44 | @Override 45 | public void onNext(BackendUser backendUser) { 46 | if (backendUser != null) { 47 | DebugAuthActivity.this.finish(); 48 | } 49 | } 50 | }); 51 | 52 | this.closeOptionsMenu(); 53 | } 54 | 55 | private static String getApplicationName(Context context) { 56 | int stringId = context.getApplicationInfo().labelRes; 57 | return context.getString(stringId); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Client/android-client-mock/src/main/java/io/divide/client/android/mock/MockAndroidModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android.mock; 18 | 19 | import com.google.inject.Singleton; 20 | import com.google.inject.TypeLiteral; 21 | import io.divide.client.MockLocalStorage; 22 | import io.divide.client.android.AndroidConfig; 23 | import io.divide.client.android.AndroidModule; 24 | import io.divide.client.auth.MockAuthManager; 25 | import io.divide.client.auth.MockKeyManager; 26 | import io.divide.client.data.MockDataManager; 27 | import io.divide.shared.server.DAO; 28 | import io.divide.shared.server.KeyManager; 29 | import io.divide.shared.transitory.TransientObject; 30 | 31 | import java.security.NoSuchAlgorithmException; 32 | 33 | public class MockAndroidModule extends AndroidModule { 34 | 35 | public MockAndroidModule(){ 36 | setAuthManagerClass(MockAuthManager.class); 37 | setDataManagerClass(MockDataManager.class); 38 | } 39 | 40 | @Override 41 | protected void additionalConfig(AndroidConfig config){ 42 | super.additionalConfig(config); 43 | // ORDER MATTER 44 | try { 45 | bind(KeyManager.class).toInstance(new MockKeyManager("someKey")); 46 | } 47 | catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } 48 | 49 | bind(new TypeLiteral>(){}) 50 | .to(new TypeLiteral>() { 51 | }).in(Singleton.class); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Client/android-client/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml -------------------------------------------------------------------------------- /Client/android-client/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Client/android-client/res/layout/act_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 19 | 20 | 28 | 29 | 35 | 36 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Client/android-client/res/layout/act_register.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 20 | 21 | 30 | 31 | 40 | 41 | 48 | 49 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /Client/android-client/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Email address 4 | Password 5 | Sign in 6 | New user? 7 | Name 8 | Create Account 9 | Already a member? 10 | -------------------------------------------------------------------------------- /Client/android-client/sample/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml -------------------------------------------------------------------------------- /Client/android-client/sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Client/android-client/sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.divide 9 | client 10 | 0.5.3 11 | ../../pom.xml 12 | 13 | client-sample 14 | apk 15 | 16 | 17 | 18 | io.divide 19 | client-android 20 | ${project.parent.version} 21 | aar 22 | 23 | 24 | io.divide 25 | client-android-mock 26 | ${project.parent.version} 27 | aar 28 | 29 | 30 | com.google.android 31 | android 32 | 4.1.1.4 33 | provided 34 | 35 | 36 | com.jakewharton 37 | butterknife 38 | 5.1.1 39 | 40 | 41 | com.jug6ernaut 42 | alogger-base 43 | 0.5.0 44 | 45 | 46 | 47 | 48 | ${project.artifactId} 49 | src/main/java 50 | 51 | 52 | 53 | com.jayway.maven.plugins.android.generation2 54 | android-maven-plugin 55 | 3.9.0-rc.2 56 | true 57 | 58 | 59 | 60 | 61 | 62 | com.jayway.maven.plugins.android.generation2 63 | android-maven-plugin 64 | 65 | 66 | 67 | ${android.platform} 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Client/android-client/sample/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Client/android-client/sample/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/Client/android-client/sample/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/android-client/sample/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/Client/android-client/sample/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/android-client/sample/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/Client/android-client/sample/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/android-client/sample/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/Client/android-client/sample/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Client/android-client/sample/res/layout/creds_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 12 | 13 | 17 | -------------------------------------------------------------------------------- /Client/android-client/sample/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 17 | 18 | 24 | 25 | 26 | 33 | 34 | 41 | 42 | 49 | 50 | 56 | 57 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Client/android-client/sample/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | io.divide.client-sample 4 | com.example.client_sample 5 | http://williams-mbp:8888/api 6 | http://authenticator-test.appspot.com/api 7 | 8 | -------------------------------------------------------------------------------- /Client/android-client/sample/res/xml/account_prefs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Client/android-client/sample/res/xml/authenticator.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /Client/android-client/sample/res/xml/prefs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Client/android-client/sample/src/main/java/com/example/client_sample/MyApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.example.client_sample; 19 | 20 | import android.app.Application; 21 | import android.os.Handler; 22 | import android.widget.Toast; 23 | import com.jug6ernaut.android.logging.ALogger; 24 | import com.jug6ernaut.android.logging.Logger; 25 | import io.divide.client.Backend; 26 | import io.divide.client.android.AndroidBackend; 27 | import io.divide.client.android.mock.AndroidDebugConfig; 28 | import io.divide.client.android.push.PushEvent; 29 | import io.divide.client.android.push.PushListener; 30 | 31 | public class MyApplication extends Application { 32 | 33 | private static Logger logger; 34 | private Handler handler = new Handler(); 35 | 36 | @Override 37 | public void onCreate(){ 38 | ALogger.init(this, "Backend", true); 39 | logger = Logger.getLogger(MyApplication.class); 40 | 41 | AndroidBackend b = Backend.init(new AndroidDebugConfig(this,getProdUrl(),getDevUrl())); 42 | // BackendServices.addPushListener(listener); 43 | } 44 | 45 | @Override 46 | public void onTerminate() { 47 | 48 | } 49 | 50 | private String getProdUrl(){ 51 | return getString(R.string.prodUrl); 52 | } 53 | 54 | private String getDevUrl(){ 55 | return getString(R.string.devUrl); 56 | } 57 | 58 | private PushListener listener = new PushListener() { 59 | 60 | @Override 61 | public void onEvent(final PushEvent event) { 62 | logger.debug("Push Message: " + event); 63 | handler.post(new Runnable() { 64 | @Override 65 | public void run() { 66 | Toast.makeText(MyApplication.this, "Push Message: " + event, Toast.LENGTH_LONG).show(); 67 | } 68 | }); 69 | } 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /Client/android-client/sample/src/main/java/com/example/client_sample/Settings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.example.client_sample; 19 | 20 | import android.os.Bundle; 21 | import android.preference.PreferenceActivity; 22 | import android.preference.PreferenceManager; 23 | 24 | public class Settings extends PreferenceActivity { 25 | 26 | public static final String PREFERENCE_NAME = "preferences"; 27 | 28 | @Override 29 | public void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | 32 | PreferenceManager manager = getPreferenceManager(); 33 | manager.setSharedPreferencesName(PREFERENCE_NAME); 34 | 35 | addPreferencesFromResource(R.xml.prefs); 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Client/android-client/src/main/java/io/divide/client/android/AndroidBackend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android; 18 | 19 | import com.google.inject.Inject; 20 | import io.divide.client.Backend; 21 | import io.divide.client.android.push.PushManager; 22 | 23 | public class AndroidBackend extends Backend { 24 | 25 | @Inject PushManager pushManager; 26 | @Inject AndroidConfig config; 27 | 28 | @Inject 29 | private AndroidBackend(){ 30 | super(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Client/android-client/src/main/java/io/divide/client/android/AndroidConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android; 18 | 19 | import android.app.Application; 20 | import io.divide.client.Config; 21 | import io.divide.client.android.security.PRNGFixes; 22 | import rx.android.schedulers.AndroidSchedulers; 23 | 24 | import java.io.File; 25 | 26 | public class AndroidConfig extends Config{ 27 | 28 | static { PRNGFixes.apply(); } 29 | 30 | public Application app; 31 | 32 | public AndroidConfig(Application application, String url) { 33 | this(application, url, AndroidModule.class); 34 | } 35 | 36 | protected AndroidConfig(Application application, String url, Class type){ 37 | super(application.getFilesDir().getPath() + File.separator, url, type); 38 | this.app = application; 39 | this.observeOn(AndroidSchedulers.mainThread()); 40 | } 41 | 42 | @Override 43 | public Class getModuleType() { 44 | return AndroidBackend.class; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Client/android-client/src/main/java/io/divide/client/android/AndroidModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android; 18 | 19 | import io.divide.client.BackendModule; 20 | 21 | public class AndroidModule extends BackendModule { 22 | 23 | @Override 24 | protected void additionalConfig(AndroidConfig config){ 25 | bind(AndroidConfig.class).toInstance(config); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Client/android-client/src/main/java/io/divide/client/android/AuthActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android; 18 | 19 | import android.app.Activity; 20 | import android.content.Context; 21 | import android.os.Bundle; 22 | import io.divide.client.BackendServices; 23 | import io.divide.client.BackendUser; 24 | import io.divide.client.auth.LoginListener; 25 | 26 | /** 27 | * The AuthUtils activity. 28 | * 29 | * Called by the AuthUtils and in charge of identifying the user. 30 | * 31 | * It sends back to the AuthUtils the result. 32 | */ 33 | 34 | public class AuthActivity extends Activity { 35 | 36 | public static final String EXTRA_TITLE = "title_extra_key"; 37 | public static final String EXTRA_ENABLE_ANONYMOUS_LOGIN = "enable_anonymous_login_key"; 38 | 39 | /** 40 | * Called when the activity is first created. 41 | */ 42 | @Override 43 | public void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | String title = this.getIntent().getStringExtra(EXTRA_TITLE); 46 | if(title == null) title = getApplicationName(this); 47 | boolean enableAnonymous = this.getIntent().getBooleanExtra(EXTRA_ENABLE_ANONYMOUS_LOGIN,false); 48 | CredentialView credentialView = new CredentialView(this,title); 49 | if(enableAnonymous)credentialView.enableAnonymousLogin(); 50 | 51 | setContentView(credentialView); 52 | BackendServices.addLoginListener(new LoginListener() { 53 | @Override 54 | public void onNext(BackendUser backendUser) { 55 | if(backendUser != null){ 56 | AuthActivity.this.finish(); 57 | } 58 | } 59 | }); 60 | 61 | this.closeOptionsMenu(); 62 | } 63 | 64 | private static String getApplicationName(Context context) { 65 | int stringId = context.getApplicationInfo().labelRes; 66 | return context.getString(stringId); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Client/android-client/src/main/java/io/divide/client/android/cache/NameValuePair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android.cache; 18 | 19 | public class NameValuePair { 20 | String name; 21 | String value; 22 | public NameValuePair(String name, String value){ 23 | this.name = name; 24 | this.value = value; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Client/android-client/src/main/java/io/divide/client/android/push/PushEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android.push; 18 | 19 | import io.divide.shared.event.Event; 20 | 21 | public class PushEvent extends Event { 22 | private String message; 23 | protected PushEvent(String message) { 24 | super(PushManager.class); 25 | this.message = message; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Client/android-client/src/main/java/io/divide/client/android/push/PushListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android.push; 18 | 19 | import io.divide.shared.event.Subscriber; 20 | 21 | public interface PushListener extends Subscriber {} 22 | -------------------------------------------------------------------------------- /Client/android-client/src/main/java/io/divide/client/android/push/PushWebService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.android.push; 18 | 19 | import io.divide.shared.transitory.EncryptedEntity; 20 | import retrofit.Callback; 21 | import retrofit.http.Body; 22 | import retrofit.http.DELETE; 23 | import retrofit.http.POST; 24 | 25 | public interface PushWebService { 26 | 27 | @POST("/push") 28 | public Boolean register(@Body EncryptedEntity entity); 29 | @POST("/push") 30 | public void register(@Body EncryptedEntity entity, Callback callback); 31 | 32 | @DELETE("/push") 33 | public Boolean unregister(); 34 | @DELETE("/push") 35 | public void unregister(Callback callback); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Client/java-client/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/BackendConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client; 18 | 19 | public final class BackendConfig extends Config{ 20 | 21 | /** 22 | * Default @see Config implementation used by Divide. Used for the default implementation returning a @see Backend object. 23 | * @return 24 | */ 25 | 26 | @Override 27 | public Class getModuleType() { 28 | return Backend.class; 29 | } 30 | 31 | public BackendConfig(String fileSavePath, String url){ 32 | this(fileSavePath, url, BackendModule.class); 33 | } 34 | 35 | public BackendConfig(String fileSavePath, String url, Class moduleClass){ 36 | super(fileSavePath,url,moduleClass); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/BackendObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client; 18 | 19 | import io.divide.shared.transitory.Credentials; 20 | import io.divide.shared.transitory.FilePermissions; 21 | import io.divide.shared.transitory.TransientObject; 22 | 23 | public class BackendObject extends TransientObject { 24 | // FIXME stupidness of all this is just to have the 25 | // "this.setUserId()" in the constructor, all this nastyness is to hide 26 | // implementation info from TransientObject. Possible fix, have two implementations of same 27 | // class, data struct just needs to match, not implementation. Lose type safety...Is it really needed? 28 | private static final String USER_DATA = TransientObject.USER_DATA; 29 | private static final MetaKey OJBECT_TYPE_KEY = TransientObject.OBJECT_TYPE_KEY; 30 | private static final MetaKey USER_ID_KEY = TransientObject.OWNER_ID_KEY; 31 | 32 | public BackendObject() { 33 | FilePermissions fp = new FilePermissions(); 34 | fp.setWritable(true, FilePermissions.Level.GROUP, FilePermissions.Level.WORLD); 35 | setFilePermissions(fp); 36 | } 37 | 38 | @Override 39 | protected final Credentials getLoggedInUser(){ 40 | return BackendUser.getUser(); 41 | } 42 | 43 | /** 44 | * Sets the user id for this object. Once set this can not be changed. 45 | * @param userId user id to be set. 46 | */ 47 | @Override 48 | public void setOwnerId(Integer userId){ 49 | super.setOwnerId(userId); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/BackendServices.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client; 18 | 19 | import io.divide.client.auth.AuthManager; 20 | import io.divide.client.auth.LoginListener; 21 | import io.divide.client.data.ObjectManager; 22 | import io.divide.shared.server.DAO; 23 | 24 | import javax.inject.Inject; 25 | 26 | public class BackendServices { 27 | 28 | @Inject private static AuthManager authManager; 29 | @Inject private static ObjectManager objectManager; 30 | 31 | private BackendServices(){ } 32 | 33 | /** 34 | * @return @see RemoteStorage instance used to interface with the remote server. 35 | */ 36 | public static ObjectManager.RemoteStorage remote(){ 37 | checkIsInitialized(objectManager); 38 | return objectManager.remote(); 39 | } 40 | 41 | /** 42 | * @return LocalStorage instanced used to store and manage @see BackendObject locally. 43 | */ 44 | public static DAO local(){ 45 | checkIsInitialized(objectManager); 46 | return objectManager.local(); 47 | } 48 | 49 | /** 50 | * Subscribe to login events. 51 | * @param loginListener 52 | */ 53 | public static void addLoginListener(LoginListener loginListener){ 54 | checkIsInitialized(authManager); 55 | authManager.addLoginListener(loginListener); 56 | } 57 | 58 | private static void checkIsInitialized(Object o){ 59 | if( o == null ) 60 | throw new RuntimeException("Backend not initialized!"); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/AccountStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import io.divide.client.auth.credentials.LocalCredentials; 20 | 21 | import java.util.List; 22 | 23 | public interface AccountStorage { 24 | 25 | public void addAcccount(LocalCredentials credentials); 26 | public void removeAccount(String accountName); 27 | public LocalCredentials getAccount(String accountName); 28 | public boolean isAuthenticated(String accountName); 29 | public void setAuthToken(String accountName, String token); 30 | public void setRecoveryToken(String accountName, String token); 31 | public List getAccounts(); 32 | public boolean exists(String name); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/AuthActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | //package io.divide.client.auth; 18 | // 19 | //import android.accounts.AccountAuthenticatorActivity; 20 | //import android.os.Bundle; 21 | //import com.jug6ernaut.android.logging.Logger; 22 | //import io.divide.client.BackendServices; 23 | // 24 | ///** 25 | // * The AuthUtils activity. 26 | // * 27 | // * Called by the AuthUtils and in charge of identifing the user. 28 | // * 29 | // * It sends back to the AuthUtils the result. 30 | // */ 31 | //public class AuthActivity extends AccountAuthenticatorActivity { 32 | // Logger logger = Logger.getLogger(AuthActivity.class); 33 | // 34 | // /** 35 | // * Called when the activity is first created. 36 | // */ 37 | // @Override 38 | // public void onCreate(Bundle savedInstanceState) { 39 | // super.onCreate(savedInstanceState); 40 | // setContentView(new CredentialView(this,"client-example")); 41 | // BackendServices.addLoginListener(new LoginListener() { 42 | // 43 | // @Override 44 | // public void onNext(LoginEvent loginEvent) { 45 | // switch(loginEvent.state){ 46 | // case LOGGED_IN: 47 | // AuthActivity.this.finish(); 48 | // break; 49 | // } 50 | // } 51 | // }); 52 | // } 53 | // 54 | //} 55 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/AuthService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | //package io.divide.client.auth; 18 | // 19 | //import android.app.Service; 20 | //import android.content.Intent; 21 | //import android.os.IBinder; 22 | // 23 | ///** 24 | // * Created with IntelliJ IDEA. 25 | // * User: Udini 26 | // * Date: 19/03/13 27 | // * Time: 19:10 28 | // */ 29 | //public class AuthService extends Service { 30 | // @Override 31 | // public IBinder onBind(Intent intent) { 32 | // 33 | // BackendAuthenticator authenticator = new BackendAuthenticator(this); 34 | // return authenticator.getIBinder(); 35 | // } 36 | //} 37 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/AuthWebService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import io.divide.client.auth.credentials.LoginCredentials; 20 | import io.divide.client.auth.credentials.SignUpCredentials; 21 | import io.divide.client.auth.credentials.ValidCredentials; 22 | import retrofit.client.Response; 23 | import retrofit.http.*; 24 | import rx.Observable; 25 | 26 | import java.util.Map; 27 | 28 | /* 29 | * Interface defining relationship with server. 30 | */ 31 | public interface AuthWebService { 32 | 33 | @POST("/auth") 34 | public Response userSignUp(@Body SignUpCredentials credentials); 35 | 36 | @POST("/auth") 37 | public Observable userSignUpA(@Body SignUpCredentials credentials); 38 | 39 | @PUT("/auth") 40 | public Response login(@Body LoginCredentials credentials); 41 | @PUT("/auth") 42 | public Observable loginA(@Body LoginCredentials credentials); 43 | 44 | @GET("/auth/key") 45 | public Observable getPublicKeyA(); 46 | 47 | @GET("/auth/key") 48 | public byte[] getPublicKey(); 49 | 50 | @GET("/auth/from/{token}") 51 | public Observable getUserFromAuthToken(@Path("token")String authToken); 52 | 53 | @GET("/auth/recover/{token}") 54 | public Observable getUserFromRecoveryToken(@Path("token")String authToken); 55 | 56 | @POST("/auth/user/data/{userId}") 57 | public Observable sendUserData(@Header("Authorization") String authToken, @Path("userId") String userId, @Body Map map); 58 | 59 | @GET("/auth/user/data/{userId}") 60 | public Observable> getUserData(@Header("Authorization") String authToken, @Path("userId") String userId); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/LoginEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import io.divide.client.BackendUser; 20 | 21 | public class LoginEvent { 22 | public BackendUser user; 23 | public LoginState state; 24 | } 25 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/LoginListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import io.divide.client.BackendUser; 20 | import rx.Observer; 21 | import rx.Subscription; 22 | 23 | public abstract class LoginListener implements Observer { 24 | 25 | private Subscription subscription; 26 | 27 | @Override 28 | public void onCompleted() { } 29 | 30 | @Override 31 | public void onError(Throwable throwable) { } 32 | 33 | public void unsubscribe(){ 34 | if(subscription!=null){ 35 | subscription.unsubscribe(); 36 | } 37 | } 38 | 39 | protected void setSubscription(Subscription subscription){ 40 | this.subscription = subscription; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/LoginState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | public enum LoginState { 20 | LOGGED_IN, 21 | LOGGED_OUT, 22 | LOGGING_IN 23 | } 24 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/RecoveryResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import io.divide.client.BackendUser; 20 | import io.divide.client.data.ServerResponse; 21 | import io.divide.client.http.Status; 22 | 23 | public class RecoveryResponse extends ServerResponse { 24 | protected RecoveryResponse(BackendUser backendUser, Status status, String error) { 25 | super(backendUser, status, error); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/SignInResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import io.divide.client.BackendUser; 20 | import io.divide.client.data.ServerResponse; 21 | import io.divide.client.http.Status; 22 | 23 | public class SignInResponse extends ServerResponse { 24 | 25 | public SignInResponse(BackendUser user, Status status, String error) { 26 | super(user, status, error); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/SignUpResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import io.divide.client.BackendUser; 20 | import io.divide.client.data.ServerResponse; 21 | import io.divide.client.http.Status; 22 | 23 | public class SignUpResponse extends ServerResponse { 24 | 25 | public SignUpResponse(BackendUser user, Status status, String error) { 26 | super(user, status, error); 27 | } 28 | } -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/credentials/LocalCredentials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth.credentials; 18 | 19 | public class LocalCredentials { 20 | private String emailAddress; 21 | private String authToken; 22 | private String recoveryToken; 23 | 24 | public String getName() { 25 | return emailAddress; 26 | } 27 | 28 | public void setName(String emailAddress) { 29 | this.emailAddress = emailAddress; 30 | } 31 | 32 | public String getAuthToken() { 33 | return authToken; 34 | } 35 | 36 | public void setAuthToken(String authToken) { 37 | this.authToken = authToken; 38 | } 39 | 40 | public String getRecoveryToken() { 41 | return recoveryToken; 42 | } 43 | 44 | public void setRecoveryToken(String recoveryToken) { 45 | this.recoveryToken = recoveryToken; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "LocalCredentials{" + 51 | "emailAddress='" + emailAddress + '\'' + 52 | ", authToken='" + authToken + '\'' + 53 | ", recoveryToken='" + recoveryToken + '\'' + 54 | '}'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/credentials/LoginCredentials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth.credentials; 18 | 19 | import io.divide.shared.transitory.Credentials; 20 | 21 | import java.security.PrivateKey; 22 | import java.security.PublicKey; 23 | 24 | /* 25 | * Credentials used for logging in 26 | */ 27 | public class LoginCredentials extends Credentials { 28 | 29 | private boolean isEncrypted = false; 30 | 31 | public LoginCredentials(String email, String password){ 32 | this.setEmailAddress(email); 33 | this.setPassword(password); 34 | } 35 | 36 | @Override 37 | public void decryptPassword(PrivateKey privateKey){ 38 | if(isEncrypted()){ 39 | super.decryptPassword(privateKey); 40 | setEncrypted(false); 41 | } 42 | } 43 | 44 | @Override 45 | public void encryptPassword(PublicKey publicKey){ 46 | if(!isEncrypted()){ 47 | super.encryptPassword(publicKey); 48 | setEncrypted(true); 49 | } 50 | } 51 | 52 | public boolean isEncrypted(){ 53 | return isEncrypted; 54 | } 55 | 56 | public void setEncrypted(boolean isEncrypted){ 57 | this.isEncrypted = isEncrypted; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/credentials/SignUpCredentials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth.credentials; 18 | 19 | import io.divide.shared.transitory.Credentials; 20 | 21 | /* 22 | * Credentials used for Signing up 23 | */ 24 | public class SignUpCredentials extends Credentials { 25 | 26 | public SignUpCredentials(String username, String email, String password){ 27 | this.setUsername(username); 28 | this.setEmailAddress(email); 29 | this.setPassword(password); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/auth/credentials/ValidCredentials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth.credentials; 18 | 19 | import io.divide.shared.transitory.Credentials; 20 | 21 | /* 22 | * Credentials used for for a valid signin/login 23 | */ 24 | public class ValidCredentials extends Credentials { 25 | 26 | ValidCredentials(){} 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/data/CountObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.data; 18 | 19 | import io.divide.client.BackendObject; 20 | 21 | public class CountObject extends BackendObject { 22 | 23 | public int getCount(){ 24 | return get(Integer.class,"count"); 25 | } 26 | 27 | public String getFrom(){ 28 | return get(String.class,"from"); 29 | } 30 | 31 | public void setCount(int count){ 32 | put("count",count); 33 | } 34 | 35 | public void setFrom(String from){ 36 | put("from",from); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/data/DataWebService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.data; 18 | 19 | import io.divide.client.BackendObject; 20 | import io.divide.shared.transitory.query.Query; 21 | import retrofit.client.Response; 22 | import retrofit.http.*; 23 | import rx.Observable; 24 | 25 | import java.util.Collection; 26 | 27 | public interface DataWebService { 28 | 29 | @POST("/data/get/{objectType}") 30 | public Response get(@Header("Authorization") String authToken, @EncodedPath("objectType") String objectType,@Body Collection keys); 31 | 32 | @POST("/data/query") 33 | public Response query(@Header("Authorization") String authToken, @Body Query query); 34 | 35 | @POST("/data/save") 36 | public Observable save(@Header("Authorization") String authToken, @Body Collection objects); 37 | 38 | @GET("/data/count/{objectType}") 39 | public Observable count(@Header("Authorization") String authToken, @EncodedPath("objectType") String objectType); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/data/EmptyCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.data; 18 | 19 | import io.divide.shared.logging.Logger; 20 | import retrofit.client.Response; 21 | 22 | /* 23 | * Callback to be provided when no actual callback is needed. 24 | */ 25 | public class EmptyCallback implements retrofit.Callback { 26 | private static Logger logger = Logger.getLogger(EmptyCallback.class); 27 | @Override 28 | public void success(B bs, Response response) { 29 | 30 | } 31 | 32 | @Override 33 | public void failure(retrofit.RetrofitError retrofitError) { 34 | logger.fatal("",retrofitError); 35 | } 36 | }; -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/web/ConnectionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.web; 18 | 19 | import rx.Observer; 20 | 21 | public abstract class ConnectionListener { 22 | 23 | public abstract void onEvent(boolean connected); 24 | 25 | protected Observer getObserver(){ return connectionObserver; } 26 | 27 | private Observer connectionObserver = new Observer() { 28 | 29 | @Override public void onCompleted() { } 30 | 31 | @Override public void onError(Throwable throwable) { } 32 | 33 | @Override 34 | public void onNext(Boolean aBoolean) { 35 | onEvent(aBoolean); 36 | } 37 | }; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/web/OnRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.web; 18 | 19 | import static retrofit.RequestInterceptor.RequestFacade; 20 | 21 | public interface OnRequestInterceptor { 22 | RequestFacade onRequest(RequestFacade requestFacade); 23 | } 24 | -------------------------------------------------------------------------------- /Client/java-client/src/main/java/io/divide/client/web/RequestObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.web; 18 | 19 | import static retrofit.Profiler.RequestInformation; 20 | 21 | public class RequestObject { 22 | public final RequestInformation info; 23 | public final long l; 24 | public final int i; 25 | public final Object o; 26 | 27 | public RequestObject(RequestInformation info,long l, int i, Object o){ 28 | this.info = info; 29 | this.l = l; 30 | this.i = i; 31 | this.o = o; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Client/java-client/src/test/java/io/divide/client/BackendObjectTest.java: -------------------------------------------------------------------------------- 1 | package io.divide.client; 2 | 3 | import io.divide.shared.transitory.query.Query; 4 | import junit.framework.TestCase; 5 | import org.junit.Test; 6 | 7 | public class BackendObjectTest extends TestCase { 8 | 9 | @Test 10 | public void testExtend(){ 11 | assertEquals(Query.safeTable(A.class),new A().getObjectType()); 12 | } 13 | 14 | private static class A extends BackendObject { } 15 | } -------------------------------------------------------------------------------- /Client/java-client/src/test/java/io/divide/client/cache/LocalStorageIBoxDbTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.cache; 18 | 19 | import iBoxDB.LocalServer.BoxSystem; 20 | import io.divide.dao.DAOTest; 21 | import io.divide.dao.Keyable; 22 | import io.divide.shared.transitory.TransientObject; 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Rule; 26 | import org.junit.rules.TemporaryFolder; 27 | 28 | import java.util.List; 29 | 30 | public class LocalStorageIBoxDbTest extends DAOTest { 31 | 32 | @Rule 33 | public TemporaryFolder folder = new TemporaryFolder(); 34 | 35 | public LocalStorageIBoxDbTest() { 36 | super(null); 37 | } 38 | 39 | @Before 40 | public void setUp() { 41 | dao = new LocalStorageIBoxDb(folder.getRoot().getPath()); 42 | super.setUp(); 43 | } 44 | 45 | @After 46 | public void tearDown() { 47 | if (!BoxSystem.DBDebug.DeleteDBFiles(1, 10, 20, -10)) { 48 | System.out.println("delete=false,system locks"); 49 | } 50 | } 51 | 52 | @Override 53 | public KeyedWrapper toBaseObject(TransientObject object) { 54 | return new KeyedWrapper(object); 55 | } 56 | 57 | @Override 58 | public void rawSave(List keyedWrappers) { 59 | for(KeyedWrapper kw : keyedWrappers){ 60 | dao.save(kw.toTransientObject()); 61 | } 62 | } 63 | 64 | public static class KeyedWrapper extends Wrapper implements Keyable{ 65 | 66 | private KeyedWrapper(TransientObject transientObject){ 67 | super(transientObject); 68 | } 69 | 70 | @Override 71 | public String getKey() { 72 | return this.Key(); 73 | } 74 | 75 | public TransientObject toTransientObject(){ 76 | return this.toObject(TransientObject.class); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /Client/mock-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | io.divide 7 | client 8 | 0.5.3 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | client-mock 14 | 15 | 16 | 17 | io.divide 18 | client-java 19 | ${project.parent.version} 20 | provided 21 | 22 | 23 | org.mockito 24 | mockito-all 25 | 1.9.5 26 | test 27 | 28 | 29 | junit 30 | junit 31 | 4.11 32 | test 33 | 34 | 35 | io.divide 36 | server 37 | ${app.version} 38 | test-jar 39 | test 40 | 41 | 42 | io.divide 43 | server 44 | ${app.version} 45 | test 46 | 47 | 48 | io.divide 49 | dao-orientdb 50 | ${app.version} 51 | test 52 | 53 | 54 | io.divide 55 | dao-common 56 | ${app.version} 57 | test 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Client/mock-client/src/main/java/io/divide/client/DebugModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.divide.client; 17 | 18 | public class DebugModule extends BackendModule { 19 | } 20 | -------------------------------------------------------------------------------- /Client/mock-client/src/main/java/io/divide/client/GsonResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client; 18 | 19 | import com.google.gson.Gson; 20 | import io.divide.shared.util.IOUtils; 21 | import retrofit.client.Header; 22 | import retrofit.client.Response; 23 | import retrofit.mime.TypedInput; 24 | 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | public class GsonResponse{ 31 | 32 | static Gson gson = new Gson(); 33 | 34 | private final String url; 35 | private final int status; 36 | private final String reason; 37 | private final List headers; 38 | private String json; 39 | private InputStream is; 40 | private int length; 41 | 42 | public GsonResponse(String url, int status, String reason, List headers, Object o) { 43 | this.url = url; 44 | this.status = status; 45 | this.reason = reason; 46 | this.headers = headers; 47 | this.json = gson.toJson(o); 48 | 49 | try { 50 | is = IOUtils.toInputStream(json, "UTF-8"); 51 | length = json.length(); 52 | } catch (Exception e) { 53 | is = null; 54 | length = 0; 55 | } 56 | } 57 | 58 | public Response build(){ 59 | return new Response(url,status,reason,new ArrayList(),new TypedInput() { 60 | @Override 61 | public String mimeType() { 62 | return null; 63 | } 64 | 65 | @Override 66 | public long length() { 67 | return length; 68 | } 69 | 70 | @Override 71 | public InputStream in() throws IOException { 72 | return is; 73 | } 74 | }); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Client/mock-client/src/main/java/io/divide/client/MockBackendModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client; 18 | 19 | import com.google.inject.Singleton; 20 | import com.google.inject.TypeLiteral; 21 | import io.divide.client.auth.MockAuthManager; 22 | import io.divide.client.auth.MockKeyManager; 23 | import io.divide.client.data.MockDataManager; 24 | import io.divide.shared.server.DAO; 25 | import io.divide.shared.server.KeyManager; 26 | import io.divide.shared.transitory.TransientObject; 27 | 28 | import java.security.NoSuchAlgorithmException; 29 | 30 | class MockBackendModule extends BackendModule> { 31 | 32 | @Override 33 | public void init(Config config){ 34 | super.init(config); 35 | setAuthManagerClass(MockAuthManager.class); 36 | setDataManagerClass(MockDataManager.class); 37 | } 38 | 39 | @Override 40 | public void additionalConfig(Config config){ 41 | // ORDER MATTER 42 | try { 43 | bind(KeyManager.class).toInstance(new MockKeyManager("someKey")); 44 | } 45 | catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } 46 | 47 | bind(new TypeLiteral>(){}) 48 | .to(new TypeLiteral>() { }).in(Singleton.class); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /Client/mock-client/src/main/java/io/divide/client/MockLocalStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client; 18 | 19 | import com.google.inject.Inject; 20 | import io.divide.client.cache.LocalStorageIBoxDb; 21 | import io.divide.shared.transitory.TransientObject; 22 | 23 | import java.io.File; 24 | 25 | public class MockLocalStorage extends LocalStorageIBoxDb { 26 | 27 | @Inject 28 | public MockLocalStorage(Config config){ 29 | super(getPath(config.fileSavePath)); 30 | } 31 | 32 | private static String getPath(String path){ 33 | File f = new File(path + (path.length()>0?"/":"") + getCount()); 34 | f.mkdirs(); 35 | return f.getPath(); 36 | } 37 | 38 | private static int count=0; 39 | private static synchronized int getCount(){ 40 | return count++; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Client/mock-client/src/main/java/io/divide/client/auth/MockAuthManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import com.google.inject.Inject; 20 | import io.divide.client.Config; 21 | 22 | public class MockAuthManager extends AuthManager { 23 | 24 | MockAuthWebService mockAuthWebService; 25 | 26 | @Inject 27 | public MockAuthManager(Config config, AccountStorage storage, MockAuthWebService service) { 28 | super(config, storage); 29 | mockAuthWebService = service; 30 | mockAuthWebService.setAuthManger(this); 31 | } 32 | 33 | 34 | @Override 35 | public AuthWebService getWebService(){ 36 | return mockAuthWebService; 37 | } 38 | 39 | @Override 40 | public void initAdapter(Config config){} 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Client/mock-client/src/main/java/io/divide/client/auth/MockKeyManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.auth; 18 | 19 | import io.divide.shared.server.KeyManager; 20 | import io.divide.shared.util.Crypto; 21 | 22 | import java.security.KeyPair; 23 | import java.security.NoSuchAlgorithmException; 24 | import java.security.PrivateKey; 25 | import java.security.PublicKey; 26 | 27 | public class MockKeyManager implements KeyManager { 28 | 29 | private String encryptionKey; 30 | private String pushKey; 31 | private KeyPair keyPair; 32 | 33 | public MockKeyManager(String encryptionKey) throws NoSuchAlgorithmException { 34 | this.encryptionKey = encryptionKey; 35 | this.keyPair = Crypto.getNew(); 36 | } 37 | 38 | public PublicKey getPublicKey(){ 39 | return keyPair.getPublic(); 40 | } 41 | 42 | public PrivateKey getPrivateKey(){ 43 | return keyPair.getPrivate(); 44 | } 45 | 46 | public String getSymmetricKey(){ 47 | return encryptionKey; 48 | } 49 | 50 | public String getPushKey() { 51 | return pushKey; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Client/mock-client/src/main/java/io/divide/client/data/MockDataManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.client.data; 18 | 19 | import com.google.inject.Inject; 20 | import io.divide.client.Config; 21 | 22 | public class MockDataManager extends DataManager { 23 | 24 | @Inject MockDataWebService mockDataWebService; 25 | 26 | @Inject 27 | public MockDataManager(Config config) { 28 | super(config); 29 | } 30 | 31 | @Override 32 | public DataWebService getWebService(){ 33 | return mockDataWebService; 34 | } 35 | 36 | @Override 37 | public void initAdapter(Config config){}; 38 | } 39 | -------------------------------------------------------------------------------- /Client/mock-client/src/main/java/io/divide/client/push/MockPushManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | //package io.divide.client.debug.push; 18 | // 19 | //import com.google.inject.Inject; 20 | //import io.divide.client.BackendConfig; 21 | //import io.divide.client.push.PushManager; 22 | //import io.divide.client.push.PushWebService; 23 | // 24 | //public class MockPushManager extends PushManager { 25 | // 26 | // @Inject 27 | // MockPushWebService mockPushWebService; 28 | // 29 | // @Inject 30 | // public MockPushManager(BackendConfig config) { 31 | // super(config); 32 | // } 33 | // 34 | // @Override 35 | // public PushWebService getWebService(){ 36 | // return mockPushWebService; 37 | // } 38 | // 39 | // @Override 40 | // public void initAdapter(BackendConfig config){}; 41 | //} 42 | -------------------------------------------------------------------------------- /Client/mock-client/src/test/java/io/divide/client/BackendObjectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | //package io.divide.authenticator.client; 19 | // 20 | //import io.divide.shared.web.transitory.FilePermissions; 21 | //import org.junit.Before; 22 | //import org.junit.Test; 23 | // 24 | //import static org.junit.Assert.assertEquals; 25 | // 26 | //public class BackendObjectTest { 27 | // 28 | // @Before 29 | // public void setUp() throws Exception { 30 | //// super.setUp(); 31 | // } 32 | // 33 | // @Test 34 | // public void testIsReadable() throws Exception { 35 | // FilePermissions fp = new FilePermissions(); 36 | // BackendObject to = new BackendObject(); 37 | // 38 | // to.setFilePermissions(fp); 39 | // assertEquals(true, to.isReadable()); 40 | // 41 | // fp.setReadable(false, FilePermissions.Level.OWNER); 42 | // to.setFilePermissions(fp); 43 | // assertEquals(false,to.isReadable()); 44 | // 45 | // } 46 | // 47 | // @Test 48 | // public void testIsWritable() throws Exception { 49 | // FilePermissions fp = new FilePermissions(); 50 | // BackendObject to = new BackendObject(); 51 | // 52 | // to.setFilePermissions(fp); 53 | // assertEquals(true, to.isWritable()); 54 | // 55 | // fp.setWritable(false, FilePermissions.Level.OWNER); 56 | // to.setFilePermissions(fp); 57 | // assertEquals(false,to.isWritable()); 58 | // } 59 | // 60 | // @Test 61 | // public void testGetGroups() throws Exception { 62 | // FilePermissions fp = new FilePermissions(); 63 | // BackendObject to = new BackendObject(); 64 | // String group = "some_group"; 65 | // fp.setWritable(false, FilePermissions.Level.OWNER, FilePermissions.Level.WORLD); 66 | // fp.setReadable(false, FilePermissions.Level.OWNER, FilePermissions.Level.WORLD); 67 | //// to.setOwnerId(group); 68 | // 69 | // assertEquals(true,to.isWritable()); 70 | // } 71 | // 72 | //} 73 | -------------------------------------------------------------------------------- /Client/mock-client/src/test/java/io/divide/client/BackendTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | //package io.divide.client; 19 | // 20 | //import org.junit.Test; 21 | //import org.robolectric.Robolectric; 22 | // 23 | //import static org.junit.Assert.assertEquals; 24 | // 25 | //public class BackendTest extends ClientTest{ 26 | // 27 | // @Test 28 | // public void testInit() throws Exception { 29 | // Backend.init(Robolectric.application,url()); 30 | // } 31 | // 32 | //} 33 | -------------------------------------------------------------------------------- /Client/mock-client/src/test/java/io/divide/client/BackendUserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package io.divide.client; 19 | 20 | import org.junit.Test; 21 | 22 | public class BackendUserTest extends ClientTest{ 23 | 24 | @Test 25 | public void testGetAnonymousUser() throws Exception { 26 | // BackendUser.getAnonymousUser(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Client/mock-client/src/test/java/io/divide/client/ClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package io.divide.client; 19 | 20 | import iBoxDB.LocalServer.BoxSystem; 21 | import io.divide.client.auth.AuthManager; 22 | import io.divide.shared.logging.Logger; 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Rule; 26 | import org.junit.rules.TemporaryFolder; 27 | import org.mockito.MockitoAnnotations; 28 | 29 | public abstract class ClientTest { 30 | 31 | @MockitoAnnotations.Mock 32 | protected Backend backend; 33 | protected AuthManager authManager; 34 | 35 | @Rule 36 | public TemporaryFolder folder = new TemporaryFolder(); 37 | 38 | @Before 39 | public void setUp() throws Exception { 40 | // helper.setUp(baseUrl); 41 | MockitoAnnotations.initMocks(this); 42 | Logger.FORCE_LOGGING = true; 43 | 44 | BackendConfig config = new BackendConfig(folder.getRoot().getPath(),url(), MockBackendModule.class); 45 | 46 | backend = Backend.init(config); 47 | authManager = backend.getAuthManager(); 48 | 49 | // ReflectionUtils.setObjectField(utils, "mAccountManager", accountManager); 50 | // ReflectionUtils.setObjectField(authManager,"authUtils",utils); 51 | 52 | // when(accountManager.getAccountsByType(accountInfo.getAccountType())).thenReturn(new Account[]{new Account("email", accountInfo.getAccountType())}); 53 | 54 | authManager.logout(); 55 | } 56 | 57 | @After 58 | public void tearDown() throws Exception { 59 | authManager.logout(); 60 | // accountManager = null; 61 | backend = null; 62 | authManager = null; 63 | 64 | if (!BoxSystem.DBDebug.DeleteDBFiles(1, 10, 20, -10)) { 65 | System.out.println("delete=false,system locks"); 66 | } 67 | 68 | folder.delete(); 69 | } 70 | 71 | public String url(){ 72 | return "io/divide/client/mock"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Client/mock-client/src/test/java/io/divide/client/cache/CustomSQLiteShadow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | //package io.divide.client.cache; 19 | // 20 | //import android.database.Cursor; 21 | //import android.database.sqlite.SQLiteDatabase; 22 | //import android.os.CancellationSignal; 23 | //import org.robolectric.annotation.Implementation; 24 | //import org.robolectric.annotation.Implements; 25 | //import org.robolectric.shadows.ShadowSQLiteDatabase; 26 | // 27 | //@Implements(value = SQLiteDatabase.class, inheritImplementationMethods = true) 28 | //public class CustomSQLiteShadow extends ShadowSQLiteDatabase { 29 | // 30 | // @Implementation 31 | // public Cursor rawQueryWithFactory (SQLiteDatabase.CursorFactory cursorFactory, 32 | // String sql, 33 | // String[] selectionArgs, 34 | // String editTable, 35 | // CancellationSignal cancellationSignal) { 36 | // return rawQueryWithFactory(cursorFactory, 37 | // sql, 38 | // selectionArgs, 39 | // editTable); 40 | // } 41 | //} -------------------------------------------------------------------------------- /Client/mock-client/src/test/java/io/divide/client/cache/DBHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | //package io.divide.client.cache; 19 | // 20 | //import android.content.Context; 21 | //import android.database.sqlite.SQLiteDatabase; 22 | //import android.database.sqlite.SQLiteDatabase.CursorFactory; 23 | //import android.database.sqlite.SQLiteOpenHelper; 24 | // 25 | //public class DBHelper extends SQLiteOpenHelper { 26 | // 27 | // public DBHelper(Context context, String name, CursorFactory factory, 28 | // int version) { 29 | // super(context, name, factory, version); 30 | // } 31 | // 32 | // @Override 33 | // public void onCreate(SQLiteDatabase arg0) { 34 | // //TODO 35 | // } 36 | // 37 | // @Override 38 | // public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) { 39 | // //TODO 40 | // } 41 | // 42 | //} 43 | -------------------------------------------------------------------------------- /Client/mock-client/src/test/java/io/divide/client/data/DataManagerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package io.divide.client.data; 19 | 20 | import io.divide.client.BackendObject; 21 | import io.divide.client.BackendServices; 22 | import io.divide.client.ClientTest; 23 | import io.divide.client.auth.SignUpResponse; 24 | import io.divide.client.auth.credentials.SignUpCredentials; 25 | import org.junit.Test; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | 29 | public class DataManagerTest extends ClientTest { 30 | 31 | @Test 32 | public void testSend() throws Exception { 33 | SignUpResponse response = authManager.signUp(new SignUpCredentials("name", "email", "")); 34 | assertEquals(response.get().getUsername(), "name"); 35 | 36 | BackendServices.remote().save(new BackendObject()).toBlockingObservable(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | io.divide 8 | parent 9 | 0.5.2 10 | ../pom.xml 11 | 12 | client 13 | pom 14 | 0.5.3 15 | 16 | 17 | java-client 18 | android-client 19 | 20 | mock-client 21 | android-client-mock 22 | 23 | 24 | -------------------------------------------------------------------------------- /Dao/common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | io.divide 7 | dao 8 | 0.5.2 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | dao-common 14 | 15 | 16 | 17 | junit 18 | junit 19 | 4.11 20 | test 21 | 22 | 23 | org.apache.commons 24 | commons-lang3 25 | 3.2.1 26 | test 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-jar-plugin 35 | 2.2 36 | 37 | 38 | 39 | 40 | test-jar 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Dao/common/src/main/java/io/divide/dao/ServerDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao; 18 | 19 | import io.divide.shared.server.DAO; 20 | import io.divide.shared.transitory.TransientObject; 21 | 22 | import java.security.KeyPair; 23 | 24 | public interface ServerDAO extends DAO { 25 | public KeyPair keys(KeyPair keys); 26 | } 27 | -------------------------------------------------------------------------------- /Dao/common/src/test/java/io/divide/dao/Keyable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao; 18 | 19 | public interface Keyable { 20 | public String getKey(); 21 | } 22 | -------------------------------------------------------------------------------- /Dao/common/src/test/java/io/divide/dao/TestObject1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao; 18 | 19 | import io.divide.shared.transitory.FilePermissions; 20 | import io.divide.shared.transitory.TransientObject; 21 | 22 | public class TestObject1 extends TransientObject { 23 | 24 | public TestObject1(){ 25 | FilePermissions fp = this.getFilePermissions(); 26 | fp.setReadable(true, FilePermissions.Level.WORLD); 27 | fp.setWritable(true, FilePermissions.Level.WORLD); 28 | this.setFilePermissions(fp); 29 | } 30 | 31 | public TestObject1(String... vals) { 32 | if(vals.length%2!=0) throw new IllegalArgumentException("Must have valid pairs"); 33 | for(int x=0; x userData, Map metaData){ 41 | this.user_data = userData; 42 | this.meta_data = metaData; 43 | } 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /Dao/dao-objectify/src/main/java/io/divide/dao/appengine/KeyObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao.appengine; 18 | 19 | import com.google.gson.Gson; 20 | import com.googlecode.objectify.annotation.Entity; 21 | import com.googlecode.objectify.annotation.Id; 22 | 23 | @Entity 24 | public class KeyObject { 25 | 26 | private static final Gson gson = new Gson(); 27 | @Id 28 | private long id = 1; 29 | 30 | 31 | String pubKey; 32 | String priKey; 33 | 34 | public KeyObject(){} 35 | public KeyObject(byte[] pubKey, byte[] priKey){ 36 | setKeys(pubKey,priKey); 37 | } 38 | 39 | public void setKeys(byte[] pubKey, byte[] priKey){ 40 | this.pubKey = gson.toJson(pubKey,byte[].class); 41 | this.priKey = gson.toJson(priKey,byte[].class); 42 | } 43 | 44 | public byte[] getPublicKey(){ 45 | if(pubKey!=null) return gson.fromJson(pubKey,byte[].class); 46 | else return null; 47 | } 48 | 49 | public byte[] getPrivateKey(){ 50 | if(priKey!=null) return gson.fromJson(priKey,byte[].class); 51 | else return null; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Dao/dao-objectify/src/main/java/io/divide/dao/appengine/OfyObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao.appengine; 18 | 19 | import com.googlecode.objectify.annotation.EmbedMap; 20 | import com.googlecode.objectify.annotation.Entity; 21 | import com.googlecode.objectify.annotation.Id; 22 | import com.googlecode.objectify.annotation.Index; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | @Entity 28 | public class OfyObject { 29 | 30 | @Id 31 | public String object_key; 32 | 33 | @Index 34 | @EmbedMap 35 | public Map user_data = new HashMap(0); 36 | 37 | @Index 38 | @EmbedMap 39 | public Map meta_data = new HashMap(0); 40 | 41 | public OfyObject(){} 42 | 43 | public OfyObject(String key,Map userData, Map metaData){ 44 | this.object_key = key; 45 | this.user_data = userData; 46 | this.meta_data = metaData; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "OfyObject{" + 52 | "object_key='" + object_key + '\'' + 53 | ", user_data=" + user_data + 54 | ", meta_data=" + meta_data + 55 | '}'; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Dao/dao-objectify/src/main/java/io/divide/dao/appengine/OfyService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao.appengine; 18 | 19 | import com.googlecode.objectify.Objectify; 20 | import com.googlecode.objectify.ObjectifyFactory; 21 | import com.googlecode.objectify.ObjectifyService; 22 | 23 | public class OfyService { 24 | static { 25 | factory().register(OfyObject.class); 26 | factory().register(KeyObject.class); 27 | } 28 | 29 | protected static Objectify ofy() { 30 | return ObjectifyService.ofy(); 31 | } 32 | 33 | public static ObjectifyFactory factory() { 34 | return ObjectifyService.factory(); 35 | } 36 | } -------------------------------------------------------------------------------- /Dao/dao-objectify/src/test/java/io/divide/dao/appengine/BackendToOfyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao.appengine; 18 | 19 | import io.divide.dao.TestObject1; 20 | import org.junit.Test; 21 | 22 | import java.util.HashMap; 23 | 24 | public class BackendToOfyTest { 25 | @Test 26 | public void testGetOfy() throws Exception { 27 | TestObject1 object = new TestObject1(); 28 | BackendToOfy.getOfy(object); 29 | } 30 | 31 | @Test 32 | public void testGetBack() throws Exception { 33 | OfyObject object = new OfyObject("somekey",new HashMap(),new HashMap()); 34 | BackendToOfy.getBack(object); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Dao/dao-orientdb/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | io.divide 8 | dao 9 | 0.5.2 10 | ../pom.xml 11 | 12 | dao-orientdb 13 | 14 | 15 | 16 | io.divide 17 | dao-common 18 | ${app.version} 19 | 20 | 21 | io.divide 22 | dao-common 23 | ${app.version} 24 | test-jar 25 | 26 | 27 | com.orientechnologies 28 | orient-commons 29 | 1.6.4 30 | 31 | 32 | com.orientechnologies 33 | orientdb-core 34 | 1.6.4 35 | 36 | 37 | junit 38 | junit 39 | 4.11 40 | test 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Dao/dao-orientdb/src/main/java/io/divide/dao/orientdb/HighLanderIndexFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao.orientdb; 18 | 19 | import com.orientechnologies.orient.core.db.record.ODatabaseRecord; 20 | import com.orientechnologies.orient.core.db.record.OIdentifiable; 21 | import com.orientechnologies.orient.core.exception.OConfigurationException; 22 | import com.orientechnologies.orient.core.index.ODefaultIndexFactory; 23 | import com.orientechnologies.orient.core.index.OIndexFactory; 24 | import com.orientechnologies.orient.core.index.OIndexInternal; 25 | import com.orientechnologies.orient.core.index.engine.OMVRBTreeIndexEngine; 26 | 27 | import java.util.Collections; 28 | import java.util.Set; 29 | 30 | public class HighLanderIndexFactory implements OIndexFactory { 31 | 32 | @Override 33 | public Set getTypes() { 34 | return Collections.singleton(OIndexHighLander.ID); 35 | } 36 | 37 | @Override 38 | public OIndexInternal> createIndex(ODatabaseRecord database, String indexType, String algorithm, 39 | String valueContainerAlgorithm) throws OConfigurationException { 40 | return new OIndexHighLander(indexType, ODefaultIndexFactory.SBTREE_ALGORITHM, new OMVRBTreeIndexEngine(), valueContainerAlgorithm); 41 | } 42 | } -------------------------------------------------------------------------------- /Dao/dao-orientdb/src/main/java/io/divide/dao/orientdb/OIndexHighLander.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao.orientdb; 18 | 19 | import com.orientechnologies.orient.core.db.record.OIdentifiable; 20 | import com.orientechnologies.orient.core.index.OIndexDictionary; 21 | import com.orientechnologies.orient.core.index.OIndexEngine; 22 | import com.orientechnologies.orient.core.index.OIndexOneValue; 23 | 24 | public class OIndexHighLander extends OIndexDictionary { 25 | 26 | public static String ID = "HIGHLANDER_INDEX"; 27 | 28 | public OIndexHighLander(String typeId, String algorithm, OIndexEngine engine, String valueContainerAlgorithm) { 29 | super(typeId, algorithm, engine, valueContainerAlgorithm); 30 | } 31 | 32 | public OIndexOneValue put(final Object iKey, final OIdentifiable iSingleValue) { 33 | acquireExclusiveLock(); 34 | try { 35 | checkForKeyType(iKey); 36 | 37 | final OIdentifiable value = super.get(iKey); 38 | 39 | if (value != null){ 40 | // DELETE THE PREVIOUS INDEXED RECORD 41 | value.getRecord().delete(); 42 | } 43 | super.put(iKey, iSingleValue); 44 | 45 | return this; 46 | 47 | } finally { 48 | releaseExclusiveLock(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Dao/dao-orientdb/src/test/java/io/divide/dao/orientdb/ODocumentWrapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao.orientdb; 18 | 19 | import io.divide.dao.DAOTest; 20 | import io.divide.dao.TestObject1; 21 | import com.orientechnologies.orient.core.db.ODatabase; 22 | import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal; 23 | import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; 24 | import com.orientechnologies.orient.core.db.record.ODatabaseRecord; 25 | import org.junit.After; 26 | import org.junit.Before; 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.assertEquals; 30 | 31 | public class ODocumentWrapperTest { 32 | 33 | ODatabase db; 34 | 35 | @Before 36 | public void setUp(){ 37 | db = new ODatabaseDocumentTx("memory:test").create(); 38 | ODatabaseRecordThreadLocal.INSTANCE.set((ODatabaseRecord) db); 39 | } 40 | 41 | @After 42 | public void tearDown(){ 43 | db.drop(); 44 | } 45 | 46 | @Test 47 | public void flatten(){ 48 | TestObject1 to1 = DAOTest.testObject1; 49 | ODocumentWrapper wrapper = new ODocumentWrapper(to1); 50 | TestObject1 to2 = wrapper.toObject(TestObject1.class); 51 | assertEquals(to1,to2); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Dao/dao-orientdb/src/test/java/io/divide/dao/orientdb/OrientDBDaoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.dao.orientdb; 18 | 19 | import io.divide.dao.DAOTest; 20 | import io.divide.dao.Keyable; 21 | import io.divide.shared.transitory.TransientObject; 22 | import com.orientechnologies.orient.core.db.document.ODatabaseDocument; 23 | import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; 24 | import org.junit.After; 25 | import org.junit.Before; 26 | 27 | import java.util.List; 28 | 29 | public class OrientDBDaoTest extends DAOTest { 30 | 31 | ODatabaseDocument db; 32 | 33 | public OrientDBDaoTest() { 34 | super(null); 35 | } 36 | 37 | @Override 38 | public KeyedODocumentWrapper toBaseObject(TransientObject object) { 39 | return new KeyedODocumentWrapper(object); 40 | } 41 | 42 | @Override 43 | public void rawSave(List keyedWrappers) { 44 | for(KeyedODocumentWrapper kw: keyedWrappers){ 45 | db.save(kw); 46 | } 47 | } 48 | 49 | @Before 50 | public void setUp() { 51 | db = new ODatabaseDocumentTx(OrientDBDao.DEFAULT_CONFIG); 52 | if(db.exists()){ 53 | db.open("admin","admin"); 54 | } else { 55 | db.create(); 56 | } 57 | dao = new OrientDBDao(db); 58 | super.setUp(); 59 | } 60 | 61 | @After 62 | public void tearDown() { 63 | db.drop(); 64 | db.close(); 65 | } 66 | 67 | public static class KeyedODocumentWrapper extends ODocumentWrapper implements Keyable{ 68 | 69 | public KeyedODocumentWrapper(){ 70 | super(); 71 | } 72 | 73 | public KeyedODocumentWrapper(TransientObject t){ 74 | super(t); 75 | } 76 | 77 | @Override 78 | public String getKey() { 79 | return super.getKey(); 80 | } 81 | 82 | // public ODocumentWrapper getWrapper(){ 83 | // return new ODocumentWrapper(this); 84 | // } 85 | }; 86 | } 87 | -------------------------------------------------------------------------------- /Dao/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | parent 8 | io.divide 9 | 0.5.2 10 | 11 | dao 12 | pom 13 | 14 | 15 | common 16 | dao-objectify 17 | dao-orientdb 18 | 19 | 20 | 21 | 22 | 23 | io.divide 24 | shared 25 | ${app.version} 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Divide.io 2 | =========== 3 | 4 | ## Note: Development is currently halted for this project from the main developers. We will continue to maintain the project, so if you're interesting in helping with development please see [contributing](https://github.com/HiddenStage/divide/blob/master/CONTRIBUTING.md). 5 | 6 | Divide.io is an open source Backend-as-a-Service (BaaS). It provides tools to easily, securely, and efficiently communicate between your app and a server. It handles data storage, user registration & management, and push notifications. 7 | 8 | Deploy anywhere. Use any database you want. Never get locked into a platform. 9 | 10 | Visit [our website](http://www.divide.io/) for more information. 11 | 12 | ####How does it work? 13 | Divide.io provides easy to use APIs to connect your mobile app to a backend. Getting up and running is simple. 14 | 15 | 1. Choose your server provider. Any server that runs Java should suffice. 16 | 2. Download and initialize our backend library in your server. 17 | 3. Download and initialize our client library in your app. 18 | 4. That's it! 19 | 20 | You can now use our APIs to communicate back and forth to your backend. Saving data, querying, registering and logging in users, etc. are now just a few lines of code away! 21 | 22 | 23 | ####Getting Started Guides 24 | **Servers:** 25 | * [App Engine](http://www.divide.io/get_started/app_engine) 26 | 27 | **Clients:** 28 | 29 | * [Android](http://www.divide.io/get_started/android) 30 | 31 | ####Documentation 32 | 33 | * [Server docs](http://www.divide.io/docs/server) 34 | * [Android docs](http://www.divide.io/docs/android) 35 | * [Javadocs](http://hiddenstage.github.io/divide-docs/javadocs/) 36 | 37 | ####License 38 | ``` 39 | Copyright (C) 2016 Divide.io 40 | 41 | Licensed under the Apache License, Version 2.0 (the "License"); 42 | you may not use this file except in compliance with the License. 43 | You may obtain a copy of the License at 44 | 45 | http://www.apache.org/licenses/LICENSE-2.0 46 | 47 | Unless required by applicable law or agreed to in writing, software 48 | distributed under the License is distributed on an "AS IS" BASIS, 49 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 50 | See the License for the specific language governing permissions and 51 | limitations under the License. 52 | ``` 53 | 54 | [](https://android-arsenal.com/details/1/1059) 55 | -------------------------------------------------------------------------------- /Server/sample/src/main/java/io/divide/server/sample/SomeApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.sample; 18 | 19 | import io.divide.dao.appengine.ObjectifyDAO; 20 | import io.divide.server.AuthApplication; 21 | 22 | public class SomeApplication extends AuthApplication { 23 | 24 | public SomeApplication() { 25 | super(ObjectifyDAO.class, "saywhatwhat"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Server/sample/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | authenticator-test 4 | ${appengine.app.version} 5 | true 6 | 7 | 8 | 9 | 10 | true 11 | 12 | -------------------------------------------------------------------------------- /Server/sample/src/main/webapp/WEB-INF/logging.properties: -------------------------------------------------------------------------------- 1 | # A default java.util.logging configuration. 2 | # (All App Engine logging is through java.util.logging by default). 3 | # 4 | # To use this configuration, copy it into your application's WEB-INF 5 | # folder and add the following to your appengine-web.xml: 6 | # 7 | # 8 | # 9 | # 10 | # 11 | 12 | # Set the default logging level for all loggers to WARNING 13 | .level = WARNING 14 | -------------------------------------------------------------------------------- /Server/sample/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | jersey-serlvet 10 | org.glassfish.jersey.servlet.ServletContainer 11 | 12 | javax.ws.rs.Application 13 | io.divide.server.sample.SomeApplication 14 | 15 | 16 | com.sun.jersey.config.feature.DisableWADL 17 | true 18 | 19 | 20 | 21 | 1 22 | 23 | 24 | 25 | jersey-serlvet 26 | /api/* 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Server/sample/src/main/webapp/stylesheets/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Verdana, Helvetica, sans-serif; 3 | background-color: #FFFFCC; 4 | } 5 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/GZIPReaderInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server; 18 | 19 | import javax.ws.rs.WebApplicationException; 20 | import javax.ws.rs.ext.ReaderInterceptor; 21 | import javax.ws.rs.ext.ReaderInterceptorContext; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.util.zip.GZIPInputStream; 25 | 26 | public class GZIPReaderInterceptor implements ReaderInterceptor { 27 | 28 | @Override 29 | public Object aroundReadFrom(ReaderInterceptorContext context) 30 | throws IOException, WebApplicationException { 31 | final InputStream originalInputStream = context.getInputStream(); 32 | context.setInputStream(new GZIPInputStream(originalInputStream)); 33 | return context.proceed(); 34 | } 35 | } -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/auth/EnforcePath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.auth; 18 | 19 | import java.lang.annotation.*; 20 | 21 | @Inherited 22 | @Retention(RetentionPolicy.CLASS) 23 | @Target(ElementType.TYPE) 24 | public @interface EnforcePath { 25 | } 26 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/auth/EnforcePathProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.auth; 18 | 19 | import javax.annotation.processing.AbstractProcessor; 20 | import javax.annotation.processing.RoundEnvironment; 21 | import javax.annotation.processing.SupportedAnnotationTypes; 22 | import javax.annotation.processing.SupportedSourceVersion; 23 | import javax.lang.model.SourceVersion; 24 | import javax.lang.model.element.Element; 25 | import javax.lang.model.element.TypeElement; 26 | import javax.tools.Diagnostic; 27 | import javax.ws.rs.Path; 28 | import java.util.Set; 29 | 30 | @SupportedSourceVersion(SourceVersion.RELEASE_6) 31 | @SupportedAnnotationTypes({ // 32 | "io.divide.authenticator.server.auth.EnforcePath" // 33 | }) 34 | 35 | public class EnforcePathProcessor extends AbstractProcessor { 36 | 37 | public EnforcePathProcessor(){ 38 | super(); 39 | } 40 | 41 | @Override 42 | public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) { 43 | 44 | Set extends Element> elements = roundEnv.getElementsAnnotatedWith(EnforcePath.class); 45 | for(Element e : elements){ 46 | 47 | Path path = e.getAnnotation(Path.class); 48 | 49 | if(path==null || path.value() == null){ 50 | processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Java class " + e.getSimpleName().toString() + " must have a @Path annotation"); 51 | } else if(!path.value().equals("/auth")){ 52 | processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Java class " + e.getSimpleName().toString() + " must have a @Path(\"/auth\") annotation"); 53 | } 54 | 55 | } 56 | 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/auth/ResponseFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.auth; 18 | 19 | import io.divide.shared.transitory.Credentials; 20 | 21 | import javax.ws.rs.container.ContainerRequestContext; 22 | import javax.ws.rs.container.ContainerResponseContext; 23 | import javax.ws.rs.container.ContainerResponseFilter; 24 | import javax.ws.rs.core.SecurityContext; 25 | import java.io.IOException; 26 | 27 | public class ResponseFilter implements ContainerResponseFilter { 28 | 29 | @Override 30 | public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) 31 | throws IOException { 32 | 33 | SecurityContext context = requestContext.getSecurityContext(); 34 | if(context != null && context instanceof UserContext){ 35 | UserContext userContext = (UserContext)context; 36 | Credentials user = userContext.getUser(); 37 | if(user!=null && user.getAuthToken() != null){ 38 | responseContext.getHeaders().add("Authorization", user.getAuthToken()); 39 | } 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/auth/SecManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.auth; 18 | 19 | import io.divide.dao.ServerDAO; 20 | import io.divide.shared.server.KeyManager; 21 | import io.divide.shared.util.Crypto; 22 | 23 | import java.security.KeyPair; 24 | import java.security.NoSuchAlgorithmException; 25 | import java.security.PrivateKey; 26 | import java.security.PublicKey; 27 | import java.util.ArrayList; 28 | import java.util.Arrays; 29 | import java.util.List; 30 | 31 | public class SecManager implements KeyManager { 32 | 33 | private ServerDAO dao; 34 | private String encryptionKey; 35 | private String pushKey; 36 | 37 | public SecManager(ServerDAO dao, String encryptionKey){ 38 | this.dao = dao; 39 | this.encryptionKey = encryptionKey; 40 | } 41 | 42 | private KeyPair cachedKeys = null; 43 | private synchronized KeyPair getKeys(){ 44 | if(cachedKeys!=null) return cachedKeys; 45 | 46 | cachedKeys = dao.keys(null); 47 | if(cachedKeys == null){ 48 | try { 49 | cachedKeys = Crypto.getNew(); 50 | } catch (NoSuchAlgorithmException e) { 51 | e.printStackTrace(); 52 | } 53 | dao.keys(cachedKeys); 54 | } 55 | 56 | return cachedKeys; 57 | } 58 | 59 | public PublicKey getPublicKey(){ 60 | return getKeys().getPublic(); 61 | } 62 | 63 | public PrivateKey getPrivateKey(){ 64 | return getKeys().getPrivate(); 65 | } 66 | 67 | public String getSymmetricKey(){ 68 | return encryptionKey; 69 | } 70 | 71 | @Override 72 | public String getPushKey() { 73 | return pushKey; 74 | } 75 | 76 | private List safePaths = new ArrayList(Arrays.asList( 77 | "", 78 | "/" 79 | )); 80 | 81 | public List getSafePaths(){ 82 | return safePaths; 83 | } 84 | 85 | public void addSafePath(String path){ 86 | safePaths.add(path); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/auth/UserContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.auth; 18 | 19 | import io.divide.shared.transitory.Credentials; 20 | 21 | import javax.ws.rs.core.SecurityContext; 22 | import javax.ws.rs.core.UriInfo; 23 | import java.security.Principal; 24 | 25 | public class UserContext implements SecurityContext { 26 | private Credentials creds; 27 | private UriInfo uriInfo; 28 | 29 | public UserContext(UriInfo uriInfo, final Credentials user) { 30 | this.uriInfo = uriInfo; 31 | this.creds = user; 32 | //creds.setPassword(""); 33 | this.principal = new Principal() { 34 | public String getName() { 35 | return user.getEmailAddress(); 36 | } 37 | }; 38 | } 39 | 40 | private Principal principal; 41 | 42 | public Principal getUserPrincipal() { 43 | return this.principal; 44 | } 45 | 46 | 47 | public boolean isUserInRole(String role) { 48 | if ("admin".equals(role)) { 49 | return "admin".equals(this.principal.getName()); 50 | } else 51 | if ("user".equals(role)) { 52 | if ("admin".equals(this.principal.getName())) { 53 | return true; 54 | } 55 | String pathParam = uriInfo.getPathParameters().getFirst("username"); 56 | if ((pathParam != null) && 57 | this.principal.getName().endsWith(pathParam)) { 58 | return true; 59 | } 60 | } 61 | return false; 62 | } 63 | 64 | public boolean isSecure() { 65 | return "https".equals(uriInfo.getRequestUri().getScheme()); 66 | } 67 | 68 | public String getAuthenticationScheme() { 69 | return SecurityContext.BASIC_AUTH; 70 | } 71 | 72 | public Credentials getUser(){ 73 | return creds; 74 | } 75 | 76 | public UriInfo getUriInfo(){ 77 | return uriInfo; 78 | } 79 | } -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/dao/ServerCredentials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.dao; 18 | 19 | import io.divide.shared.util.ReflectionUtils; 20 | import io.divide.shared.transitory.Credentials; 21 | import io.divide.shared.transitory.TransientObject; 22 | 23 | import java.util.Map; 24 | 25 | public class ServerCredentials extends Credentials { 26 | 27 | public ServerCredentials(TransientObject serverObject){ 28 | try { 29 | Map meta = (Map) ReflectionUtils.getObjectField(serverObject, TransientObject.META_DATA); 30 | Map user = (Map) ReflectionUtils.getObjectField(serverObject,TransientObject.USER_DATA); 31 | 32 | ReflectionUtils.setObjectField(this, TransientObject.META_DATA, meta); 33 | ReflectionUtils.setObjectField(this, TransientObject.USER_DATA, user); 34 | } catch (NoSuchFieldException e) { 35 | e.printStackTrace(); 36 | } catch (IllegalAccessException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | @Override 42 | public void setOwnerId(Integer id){ 43 | super.setOwnerId(id); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/dao/ServerObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.dao; 18 | 19 | import io.divide.shared.transitory.Credentials; 20 | import io.divide.shared.transitory.TransientObject; 21 | 22 | import java.util.Map; 23 | 24 | public class ServerObject extends TransientObject { 25 | 26 | private static Credentials user = new SystemUser(); 27 | 28 | @Override 29 | protected final Credentials getLoggedInUser(){ 30 | return user; 31 | } 32 | 33 | public void setMaps(Map userData, Map metaData){ 34 | this.user_data = userData; 35 | this.meta_data = metaData; 36 | } 37 | 38 | private static class SystemUser extends Credentials { 39 | 40 | @Override 41 | protected boolean isSystemUser(){ 42 | return true; 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/dao/Session.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.dao; 18 | 19 | import io.divide.server.auth.UserContext; 20 | import io.divide.shared.transitory.Credentials; 21 | 22 | import javax.annotation.PostConstruct; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.ws.rs.core.Context; 25 | import javax.ws.rs.core.UriInfo; 26 | import java.util.logging.Logger; 27 | 28 | //@Provider 29 | public class Session { 30 | private Logger logger = Logger.getLogger(Session.class.getName()); 31 | @Context 32 | HttpServletRequest request; 33 | 34 | public static final String SESSION_KEY = "SESSION_KEY"; 35 | UserContext userContext; 36 | 37 | @PostConstruct 38 | private void setup(){ 39 | setup((UserContext) request.getAttribute(SESSION_KEY)); 40 | } 41 | 42 | public void setup(UserContext userContext){ 43 | this.userContext = userContext; 44 | logger.info("loggedIn: " + loggedIn()); 45 | } 46 | 47 | public boolean loggedIn(){ 48 | return (userContext != null && userContext.getUser() != null); 49 | } 50 | 51 | public UriInfo getUriInfo(){ 52 | return (userContext==null?null:userContext.getUriInfo()); 53 | } 54 | 55 | public Credentials getUser(){ 56 | return (userContext==null?null:userContext.getUser()); 57 | } 58 | 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/endpoints/MetaEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.endpoints; 18 | 19 | import io.divide.server.AuthApplication; 20 | import io.divide.server.dao.DAOManager; 21 | import io.divide.server.dao.Session; 22 | 23 | import javax.ws.rs.GET; 24 | import javax.ws.rs.Path; 25 | import javax.ws.rs.Produces; 26 | import javax.ws.rs.core.Context; 27 | import javax.ws.rs.core.MediaType; 28 | import javax.ws.rs.core.Response; 29 | import java.util.logging.Logger; 30 | 31 | @Path("/") 32 | public class MetaEndpoint { 33 | 34 | public static final String VERSION = "V1.0"; 35 | 36 | Logger logger = Logger.getLogger(MetaEndpoint.class.getName()); 37 | 38 | @Context DAOManager dao; 39 | 40 | @Context AuthApplication app; 41 | 42 | 43 | /* 44 | currently failing as the decryption key is probably different 45 | */ 46 | @Produces(MediaType.TEXT_PLAIN) 47 | @GET 48 | public Response apiInfo(@Context Session session){ 49 | 50 | 51 | return Response.ok().entity(VERSION).build(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Server/src/main/java/io/divide/server/utils/ResponseUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.utils; 18 | 19 | import io.divide.dao.ServerDAO; 20 | import io.divide.shared.transitory.Credentials; 21 | 22 | import javax.ws.rs.core.Response; 23 | 24 | public class ResponseUtils { 25 | 26 | public static Response notAuthReponse(String string){ 27 | return Response 28 | .status(Response.Status.UNAUTHORIZED) 29 | .entity(string + "\r\n") 30 | .build(); 31 | } 32 | 33 | public static Response fromDAOExpection(ServerDAO.DAOException exception){ 34 | return Response 35 | .status(exception.getStatusCode()) 36 | .build(); 37 | } 38 | 39 | public static Response ok(Credentials credentials){ 40 | return Response 41 | .ok() 42 | .entity(credentials) 43 | .build(); 44 | } 45 | 46 | public static Response errorResponse(Throwable error){ 47 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Server/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | io.divide.server.auth.EnforcePathProcessor -------------------------------------------------------------------------------- /Server/src/test/java/io/divide/server/AuthApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server; 18 | 19 | import io.divide.server.auth.ResponseFilter; 20 | import io.divide.server.auth.SecurityFilter; 21 | import io.divide.server.dao.CredentialBodyHandler; 22 | import io.divide.server.dao.GsonMessageBodyHandler; 23 | import io.divide.server.endpoints.AuthenticationEndpoint; 24 | import io.divide.server.endpoints.DataEndpoint; 25 | import io.divide.server.endpoints.MetaEndpoint; 26 | import io.divide.server.endpoints.PushEndpoint; 27 | import org.junit.Test; 28 | 29 | import java.util.Set; 30 | 31 | import static junit.framework.Assert.assertEquals; 32 | import static junit.framework.Assert.assertTrue; 33 | 34 | public class AuthApplicationTest extends ServerTest { 35 | 36 | // sanity test 37 | @Test 38 | public void sanity() { 39 | final String version = target("").request().get(String.class); 40 | assertEquals(MetaEndpoint.VERSION, version); 41 | } 42 | 43 | @Test 44 | public void classesRegistered(){ 45 | Set> classes = container.app.getClasses(); 46 | Set singletons = container.app.getSingletons(); 47 | 48 | assertTrue(classes.contains(AuthenticationEndpoint.class)); 49 | assertTrue(classes.contains(DataEndpoint.class)); 50 | assertTrue(classes.contains(PushEndpoint.class)); 51 | assertTrue(classes.contains(MetaEndpoint.class)); 52 | assertTrue(classes.contains(CredentialBodyHandler.class)); 53 | assertTrue(classes.contains(GsonMessageBodyHandler.class)); 54 | assertTrue(classes.contains(SecurityFilter.class)); 55 | assertTrue(classes.contains(ResponseFilter.class)); 56 | 57 | // assertTrue(classes.contains(UserContext.class)); 58 | // 59 | // assertTrue(singletons.contains(DAOManager.class)); 60 | // assertTrue(singletons.contains(KeyManager.class)); 61 | // assertTrue(classes.contains(Session.class)); 62 | } 63 | 64 | 65 | } -------------------------------------------------------------------------------- /Server/src/test/java/io/divide/server/ServerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server; 18 | 19 | import io.divide.dao.ServerDAO; 20 | import org.glassfish.jersey.test.JerseyTest; 21 | import org.glassfish.jersey.test.TestProperties; 22 | import org.glassfish.jersey.test.spi.TestContainerFactory; 23 | import org.junit.After; 24 | 25 | import javax.ws.rs.core.Application; 26 | 27 | public abstract class ServerTest extends JerseyTest { 28 | protected TestUtils.TestWrapper container; 29 | 30 | @Override 31 | protected TestContainerFactory getTestContainerFactory() { 32 | return new WebContainerFactory(); 33 | } 34 | 35 | @Override 36 | protected Application configure() { 37 | container = TestUtils.setUp(); 38 | enable(TestProperties.LOG_TRAFFIC); 39 | enable(TestProperties.DUMP_ENTITY); 40 | return container.app; 41 | } 42 | 43 | @After 44 | public void tearDown() throws ServerDAO.DAOException { 45 | container.tearDown(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Server/src/test/java/io/divide/server/TestApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server; 18 | 19 | import io.divide.dao.ServerDAO; 20 | import io.divide.dao.orientdb.OrientDBDao; 21 | 22 | public class TestApplication extends AuthApplication { 23 | 24 | public TestApplication(){ 25 | super(OrientDBDao.class, TestUtils.KEY); 26 | register(TestEndpoint.class); 27 | } 28 | public TestApplication(ServerDAO serverDao) { 29 | super(serverDao, TestUtils.KEY); 30 | register(TestEndpoint.class); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Server/src/test/java/io/divide/server/auth/SecurityFilterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.auth; 18 | 19 | import org.junit.Test; 20 | 21 | public class SecurityFilterTest { 22 | @Test 23 | public void testFilter() throws Exception { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Server/src/test/java/io/divide/server/dao/ServerCredentialsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.dao; 18 | 19 | import io.divide.shared.transitory.Credentials; 20 | import org.junit.Test; 21 | 22 | public class ServerCredentialsTest { 23 | 24 | @Test 25 | public void constructor() throws Exception{ 26 | new ServerCredentials(new Credentials("","","")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Server/src/test/java/io/divide/server/endpoints/DataEndpointTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.server.endpoints; 18 | 19 | public class DataEndpointTest /*extends JerseyTest*/ { 20 | 21 | // @Path("hello") 22 | // public static class HelloResource { 23 | // @GET 24 | // public String getHello() { 25 | // return "Hello World!"; 26 | // } 27 | // } 28 | // 29 | // @Override 30 | // protected Application configure() { 31 | // return new ResourceConfig(HelloResource.class); 32 | // } 33 | // 34 | //// @Test 35 | // public void test() { 36 | // final String hello = target("hello").request().get(String.class); 37 | // assertEquals("Hello World!", hello); 38 | // } 39 | 40 | // @Before 41 | // public void setUp() throws Exception { 42 | // 43 | // } 44 | // 45 | // @After 46 | // public void tearDown() throws Exception { 47 | // 48 | // } 49 | // 50 | // @Test 51 | // public void testGet() throws Exception { 52 | // 53 | // } 54 | // 55 | // @Test 56 | // public void testQuery() throws Exception { 57 | // 58 | // } 59 | // 60 | // @Test 61 | // public void testSave() throws Exception { 62 | // 63 | // } 64 | } 65 | -------------------------------------------------------------------------------- /Shared/.gitignore: -------------------------------------------------------------------------------- 1 | storage -------------------------------------------------------------------------------- /Shared/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.divide 9 | parent 10 | 0.5.2 11 | ../pom.xml 12 | 13 | shared 14 | 15 | 16 | 17 | com.intellij 18 | annotations 19 | 12.0 20 | 21 | 22 | org.mindrot 23 | jbcrypt 24 | 0.3m 25 | 26 | 27 | com.google.code.gson 28 | gson 29 | 2.2.4 30 | 31 | 32 | org.jasypt 33 | jasypt 34 | 1.9.1 35 | lite 36 | compile 37 | 38 | 39 | junit 40 | junit 41 | 4.11 42 | test 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-compiler-plugin 51 | 3.1 52 | 53 | 54 | default-compile 55 | 56 | -proc:none 57 | ${java.version} 58 | ${java.version} 59 | 60 | 61 | 62 | default-testCompile 63 | 64 | ${java.version} 65 | ${java.version} 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/otto/DeadEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.otto; 18 | 19 | /** 20 | * Wraps an event that was posted, but which had no subscribers and thus could not be delivered. 21 | * 22 | * Subscribing a DeadEvent handler is useful for debugging or logging, as it can detect misconfigurations in a 23 | * system's event distribution. 24 | * 25 | * @author Cliff Biffle 26 | */ 27 | public class DeadEvent { 28 | 29 | public final Object source; 30 | public final Object event; 31 | 32 | /** 33 | * Creates a new DeadEvent. 34 | * 35 | * @param source object broadcasting the DeadEvent (generally the {@link io.divide.otto.Bus}). 36 | * @param event the event that could not be delivered. 37 | */ 38 | public DeadEvent(Object source, Object event) { 39 | this.source = source; 40 | this.event = event; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/otto/HandlerFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Square, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.otto; 18 | 19 | import java.util.Map; 20 | import java.util.Set; 21 | 22 | /** Finds producer and subscriber methods. */ 23 | public interface HandlerFinder { 24 | 25 | Map, EventProducer> findAllProducers(Object listener); 26 | 27 | Map, Set> findAllSubscribers(Object listener); 28 | 29 | 30 | HandlerFinder ANNOTATED = new HandlerFinder() { 31 | @Override 32 | public Map, EventProducer> findAllProducers(Object listener) { 33 | return AnnotatedHandlerFinder.findAllProducers(listener); 34 | } 35 | 36 | @Override 37 | public Map, Set> findAllSubscribers(Object listener) { 38 | return AnnotatedHandlerFinder.findAllSubscribers(listener); 39 | } 40 | }; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/otto/Produce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Square, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.otto; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Marks a method as an instance producer, as used by {@link io.divide.otto.AnnotatedHandlerFinder} and {@link io.divide.otto.Bus}. 26 | * 27 | * Otto infers the instance type from the annotated method's return type. Producer methods may return null when there is 28 | * no appropriate value to share. The calling {@link io.divide.otto.Bus} ignores such returns and posts nothing. 29 | * 30 | * @author Jake Wharton 31 | */ 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.METHOD) 34 | public @interface Produce { 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/otto/Subscribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.otto; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * Marks a method as an event handler, as used by {@link io.divide.otto.AnnotatedHandlerFinder} and {@link io.divide.otto.Bus}. 23 | * 24 | * The method's first (and only) parameter defines the event type. 25 | * If this annotation is applied to methods with zero parameters or more than one parameter, the object containing 26 | * the method will not be able to register for event delivery from the {@link io.divide.otto.Bus}. Otto fails fast by throwing 27 | * runtime exceptions in these cases. 28 | * 29 | * @author Cliff Biffle 30 | */ 31 | @Inherited 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.METHOD) 34 | public @interface Subscribe { 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/AutoSubscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | public abstract class AutoSubscriber implements Subscriber{ 20 | 21 | protected AutoSubscriber(){ 22 | EventManager.get().register(this); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | public abstract class Event { 20 | private Class> source; 21 | protected Event(Class> sourse){ 22 | this.source = sourse; 23 | } 24 | 25 | public Class> getSource(){ 26 | return source; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Event{" + 32 | "source=" + source + 33 | '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/EventManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | import io.divide.otto.Bus; 20 | import io.divide.otto.SubscriberHandlerFinder; 21 | import io.divide.otto.ThreadEnforcer; 22 | 23 | import java.util.Map; 24 | import java.util.concurrent.ConcurrentHashMap; 25 | 26 | public class EventManager { 27 | 28 | private static Map busMap = new ConcurrentHashMap(); 29 | private Bus eventBus = new Bus(ThreadEnforcer.ANY); 30 | 31 | public static EventManager get(){ 32 | return EventManager.get("default"); 33 | } 34 | 35 | public static EventManager get(String identifier){ 36 | EventManager bus = busMap.get(identifier); 37 | if(bus == null){ 38 | bus = new EventManager(identifier); 39 | busMap.put(identifier,bus); 40 | } 41 | return bus; 42 | } 43 | 44 | private EventManager(String identifier){ 45 | eventBus = new Bus(ThreadEnforcer.ANY,identifier, new SubscriberHandlerFinder()); 46 | } 47 | 48 | 49 | public void fire(Event event){ 50 | eventBus.post(event); 51 | } 52 | 53 | public void register(Subscriber subscriber){ 54 | eventBus.register(subscriber); 55 | } 56 | 57 | public void unregister(S subscriber){ 58 | eventBus.unregister(subscriber); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/Subscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | import io.divide.otto.Subscribe; 20 | 21 | public interface Subscriber{ 22 | 23 | @Subscribe 24 | public void onEvent(final E event); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/file/Storage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.file; 18 | 19 | import java.util.Map; 20 | import java.util.Set; 21 | 22 | public interface Storage { 23 | 24 | public static final int MODE_PRIVATE = 0x0000; 25 | public static final int MODE_WORLD_READABLE = 0x0001; 26 | public static final int MODE_WORLD_WRITEABLE = 0x0002; 27 | public static final int MODE_APPEND = 0x8000; 28 | 29 | public interface Editor { 30 | 31 | Editor putString(String key, String value); 32 | 33 | Editor putStringSet(String key, Set values); 34 | 35 | Editor putInt(String key, int value); 36 | 37 | Editor putLong(String key, long value); 38 | 39 | Editor putFloat(String key, float value); 40 | 41 | Editor putBoolean(String key, boolean value); 42 | 43 | Editor remove(String key); 44 | 45 | Editor clear(); 46 | 47 | boolean commit(); 48 | 49 | void apply(); 50 | } 51 | 52 | Map getAll(); 53 | 54 | String getString(String key, String defValue); 55 | 56 | Set getStringSet(String key, Set defValues); 57 | 58 | int getInt(String key, int defValue); 59 | 60 | long getLong(String key, long defValue); 61 | 62 | float getFloat(String key, float defValue); 63 | 64 | boolean getBoolean(String key, boolean defValue); 65 | 66 | boolean contains(String key); 67 | 68 | Editor edit(); 69 | } -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/DAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | import io.divide.shared.transitory.query.Query; 21 | 22 | import java.util.Collection; 23 | import java.util.List; 24 | 25 | public interface DAO { 26 | public List query(Query query) throws DAOException; // Object, returns different types 27 | public Collection get(String type, String... keys) throws DAOException; 28 | public void save(IN... objects) throws DAOException; 29 | public void delete(IN... objects) throws DAOException; 30 | public boolean exists(IN... objects); 31 | public int count(String objectType); 32 | 33 | public static class DAOException extends RuntimeException{ 34 | int httpStatusCode = -1; 35 | 36 | public DAOException(Throwable throwable){ 37 | this(500,throwable); 38 | } 39 | 40 | public DAOException(int statusCode, String cause){ 41 | super(cause); 42 | this.httpStatusCode = statusCode; 43 | } 44 | 45 | public DAOException(int httpStatusCode, Throwable thrown){ 46 | super(thrown); 47 | this.httpStatusCode = httpStatusCode; 48 | } 49 | 50 | public int getStatusCode(){ 51 | return httpStatusCode; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/KeyManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import java.security.PrivateKey; 20 | import java.security.PublicKey; 21 | 22 | public interface KeyManager { 23 | 24 | public PublicKey getPublicKey(); 25 | public PrivateKey getPrivateKey(); 26 | public String getSymmetricKey(); 27 | public String getPushKey(); 28 | } 29 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/ServerLogic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public abstract class ServerLogic { 22 | 23 | protected DAO dao; 24 | 25 | public ServerLogic(DAO dao){ 26 | this.dao = dao; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/DBObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | public interface DBObject { 20 | public String getId(); 21 | } 22 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/Clause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | public class Clause { 20 | private String preOperator = ""; 21 | private String before; 22 | private String operand; 23 | private String after; 24 | 25 | private Clause(){} 26 | 27 | protected Clause(String before,OPERAND operand, String after){ 28 | this.before = before; 29 | this.after = after; 30 | this.operand = operand.symbol; 31 | } 32 | 33 | protected Clause(OPERAND.Conditional preOperator, String before,OPERAND operand, String after){ 34 | this.preOperator = preOperator.symbol; 35 | this.before = before; 36 | this.after = after; 37 | this.operand = operand.symbol; 38 | } 39 | 40 | public String getBefore(){ 41 | return before; 42 | } 43 | 44 | public String getOperand(){ 45 | return operand; 46 | } 47 | 48 | public String getAfter(){ 49 | return after; 50 | } 51 | 52 | public void setBefore(String before){ 53 | this.before = before; 54 | } 55 | 56 | public void setOperand(OPERAND operand){ 57 | this.operand = operand.symbol; 58 | } 59 | 60 | public String getPreOperator(){ 61 | return preOperator; 62 | } 63 | 64 | public void setAfter(String after){ 65 | this.after = after; 66 | } 67 | 68 | public String getCoded(){ 69 | return getBefore() + " " + getOperand() + " '" + getAfter() +"'"; 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "Clause{" + 75 | "before='" + before + '\'' + 76 | ", operand='" + operand + '\'' + 77 | ", after='" + after + '\'' + 78 | '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/Count.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class Count extends TransientObject { 22 | public Count(int count, String from) { 23 | setCount(count); 24 | setFrom(from); 25 | } 26 | 27 | public int getCount(){ 28 | return get(Integer.class,"count"); 29 | } 30 | 31 | public String getFrom(){ 32 | return get(String.class,"from"); 33 | } 34 | 35 | public void setCount(int count){ 36 | put("count",count); 37 | } 38 | 39 | public void setFrom(String from){ 40 | put("from",from); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/MetaDataClause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class MetaDataClause extends Clause 22 | { 23 | protected MetaDataClause(String before, OPERAND operand, String after) { 24 | super(TransientObject.META_DATA + "." + before, operand, after); 25 | } 26 | 27 | protected MetaDataClause(OPERAND.Conditional conditional,String before, OPERAND operand, String after) { 28 | super(conditional,TransientObject.META_DATA + "." + before, operand, after); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/OPERAND.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | public enum OPERAND{ 20 | 21 | GREATER_THAN(">"), 22 | LESS_THAN("<"), 23 | GREATER_THAN_EQ(">="), 24 | LESS_THAN_EQ("<="), 25 | EQ("=="), 26 | CONTAINS("CONTAINS"); 27 | 28 | String symbol; 29 | 30 | OPERAND(String symbol){ 31 | this.symbol = symbol; 32 | } 33 | 34 | public static OPERAND from(String symbol){ 35 | if(GREATER_THAN.symbol.equals(symbol)){ 36 | return GREATER_THAN; 37 | } else if(LESS_THAN.symbol.equals(symbol)){ 38 | return LESS_THAN; 39 | } else if(GREATER_THAN_EQ.symbol.equals(symbol)){ 40 | return GREATER_THAN_EQ; 41 | } else if(LESS_THAN_EQ.symbol.equals(symbol)){ 42 | return LESS_THAN_EQ; 43 | } else if(EQ.symbol.equals(symbol)){ 44 | return EQ; 45 | } else if(CONTAINS.symbol.equals(symbol)){ 46 | return CONTAINS; 47 | }else { 48 | return null; 49 | } 50 | } 51 | 52 | public static enum Conditional{ 53 | AND("AND"), 54 | OR("OR"); 55 | 56 | String symbol; 57 | 58 | Conditional(String symbol){ 59 | this.symbol = symbol; 60 | } 61 | 62 | public static Conditional from(String symbol){ 63 | if(AND.symbol.equals(symbol)){ 64 | return AND; 65 | } else if(OR.symbol.equals(symbol)){ 66 | return OR; 67 | } else { 68 | return null; 69 | } 70 | } 71 | } 72 | 73 | @Override 74 | public String toString(){ 75 | return symbol; 76 | } 77 | 78 | }; -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/SelectOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public enum SelectOperation { 22 | COUNT(Count.class); 23 | 24 | private transient Class> type; 25 | 26 | private SelectOperation(Class type){ 27 | this.type = type; 28 | } 29 | 30 | public Class> getType(){ 31 | return type; 32 | } 33 | 34 | public String getErrorMessage(){ 35 | return this.name() + " requires type " + type.getSimpleName(); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/UserDataClause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class UserDataClause extends Clause { 22 | protected UserDataClause(String before, OPERAND operand, String after) { 23 | super(TransientObject.USER_DATA + "." + before, operand, after); 24 | } 25 | 26 | protected UserDataClause(OPERAND.Conditional conditional,String before, OPERAND operand, String after) { 27 | super(conditional,TransientObject.USER_DATA + "." + before, operand, after); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/BitMask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.io.Serializable; 20 | 21 | public class BitMask implements Serializable { 22 | 23 | private int flags = 0; 24 | 25 | // private final void setclear(int mask, boolean set) { if (set) set(mask); else clear(mask); } 26 | 27 | public BitMask(Integer... set){ 28 | for(Integer i : set){ 29 | set(i); 30 | } 31 | } 32 | 33 | public void set(int mask, boolean set){ 34 | if(set)set(mask); 35 | else clear(mask); 36 | } 37 | 38 | private final void set(int mask) { flags |= 1 << mask; } 39 | public final void clear(int mask) { flags &= ~(1 << mask); } 40 | public final boolean get(int mask) { return (flags & 1 << mask) != 0; } 41 | 42 | public int getFlags(){ 43 | return flags; 44 | } 45 | 46 | /* 47 | 48 | Set union 49 | A | B 50 | Set intersection 51 | A & B 52 | Set subtraction 53 | A & ~B 54 | Set negation 55 | ALL_BITS ^ A 56 | Set bit 57 | A |= 1 << bit 58 | Clear bit 59 | A &= ~(1 << bit) 60 | Test bit 61 | (A & 1 << bit) != 0 62 | 63 | */ 64 | } 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.io.*; 20 | import java.nio.charset.Charset; 21 | 22 | public class IOUtils { 23 | 24 | public static String toString(InputStream in) throws IOException 25 | { 26 | BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 27 | StringBuilder out = new StringBuilder(); 28 | String newLine = System.getProperty("line.separator"); 29 | String line; 30 | while ((line = reader.readLine()) != null) { 31 | out.append(line); 32 | out.append(newLine); 33 | } 34 | return out.toString(); 35 | } 36 | 37 | public static InputStream toInputStream(String input, String encoding) throws IOException { 38 | byte[] bytes = input.getBytes(Charset.forName(encoding)); 39 | return new ByteArrayInputStream(bytes); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/NetUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.net.InetAddress; 20 | 21 | public class NetUtils { 22 | 23 | public static boolean ping(byte[] ip, int timeout){ 24 | try { 25 | return InetAddress.getByAddress(ip).isReachable(timeout); 26 | } catch (Exception e) { 27 | return false; 28 | } 29 | } 30 | 31 | public static boolean ping(String host, int timeout){ 32 | try { 33 | return InetAddress.getByName(host).isReachable(timeout); 34 | } catch (Exception e) { 35 | return false; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/FilePermissionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | public class FilePermissionsTest { } 20 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/TransientObjectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | import junit.framework.TestCase; 20 | 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | public class TransientObjectTest extends TestCase { 25 | 26 | public void testMeta_put() throws Exception { 27 | AObject o = new AObject(); 28 | List l = Arrays.asList(1,2); 29 | o.put("key", l); 30 | assertEquals(l, o.get(l.getClass(),"key")); 31 | } 32 | 33 | public void testMeta_get() throws Exception { 34 | 35 | } 36 | 37 | public void testMeta_remove() throws Exception { 38 | 39 | } 40 | 41 | public void testPut() throws Exception { 42 | 43 | } 44 | 45 | public void testPutAll() throws Exception { 46 | 47 | } 48 | 49 | public void testGet() throws Exception { 50 | 51 | } 52 | 53 | public void testRemove() throws Exception { 54 | 55 | } 56 | 57 | public void testRemoveAll() throws Exception { 58 | 59 | } 60 | 61 | private static class AObject extends TransientObject { } 62 | } 63 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/query/QueryTest.java: -------------------------------------------------------------------------------- 1 | package io.divide.shared.transitory.query; 2 | 3 | import io.divide.shared.transitory.TransientObject; 4 | import junit.framework.TestCase; 5 | 6 | public class QueryTest extends TestCase { 7 | 8 | public void testSafeTable() throws Exception { 9 | assertEquals(A.class.getName().replace('.','_'),Query.safeTable(A.class)); 10 | } 11 | 12 | public void testSafeTable1() throws Exception { 13 | assertEquals(A.class.getName().replace('.','_'),Query.safeTable(A.class.getName())); 14 | } 15 | 16 | public void testReverseTable() throws Exception { 17 | assertEquals(A.class.getName(),Query.reverseTable(Query.safeTable(A.class))); 18 | } 19 | 20 | private static class A extends TransientObject{}; 21 | } -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/util/BitMaskTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | public class BitMaskTest { 22 | @org.junit.Test 23 | public void testAll() throws Exception { 24 | BitMask bm = new BitMask(); 25 | 26 | bm.set(1,true); 27 | assertEquals("1=true",true,bm.get(1)); 28 | bm.set(3,true); 29 | assertEquals("3=true",true,bm.get(3)); 30 | bm.set(5,true); 31 | assertEquals("5=true",true,bm.get(5)); 32 | 33 | assertEquals("2=false",false,bm.get(2)); 34 | assertEquals("4=false",false,bm.get(4)); 35 | assertEquals("6=false",false,bm.get(6)); 36 | 37 | 38 | bm.set(1,false); 39 | assertEquals(false,bm.get(1)); 40 | bm.set(3,false); 41 | assertEquals(false,bm.get(3)); 42 | bm.set(5,false); 43 | assertEquals(false,bm.get(5)); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dependency_setup/.gitignore: -------------------------------------------------------------------------------- 1 | maven-android-sdk-deployer/ 2 | -------------------------------------------------------------------------------- /dependency_setup/iboxdb/iBoxDB-1.5.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/dependency_setup/iboxdb/iBoxDB-1.5.2.jar -------------------------------------------------------------------------------- /dependency_setup/iboxdb/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | io.divide 8 | dependency-setup 9 | 1.0 10 | ../pom.xml 11 | 12 | iboxdb 13 | pom 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-install-plugin 20 | 2.4 21 | 22 | 23 | install-iboxdb 24 | package 25 | 26 | install-file 27 | 28 | 29 | iBoxDB-1.5.2.jar 30 | iboxdb 31 | iboxdb 32 | 1.5.2 33 | jar 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /dependency_setup/objectify/objectify-custom.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/dependency_setup/objectify/objectify-custom.jar -------------------------------------------------------------------------------- /dependency_setup/objectify/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | io.divide 8 | dependency-setup 9 | 1.0 10 | ../pom.xml 11 | 12 | objectify 13 | pom 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-install-plugin 20 | 2.4 21 | 22 | 23 | install-objectify 24 | package 25 | 26 | install-file 27 | 28 | 29 | objectify-custom.jar 30 | com.googlecode.objectify 31 | objectify 32 | custom 33 | jar 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /dependency_setup/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | io.divide 7 | dependency-setup 8 | 1.0 9 | pom 10 | 11 | 12 | iboxdb 13 | objectify 14 | 15 | 16 | -------------------------------------------------------------------------------- /dependency_setup/setup.bat: -------------------------------------------------------------------------------- 1 | SET CURRENTDIR="%cd%" 2 | 3 | if exist maven-android-sdk-deployer ( 4 | cd maven-android-sdk-deployer 5 | git pull 6 | ) else ( 7 | git clone https://github.com/mosabua/maven-android-sdk-deployer.git 8 | cd maven-android-sdk-deployer 9 | ) 10 | 11 | call mvn clean install -P 4.4a 12 | 13 | cd extras\compatibility-v13 14 | 15 | call mvn clean install -Dextras.compatibility.v13.groupid=com.android.support - 16 | 17 | Dextras.compatibility.v13.artifactid=support-v13 18 | 19 | cd ..\compatibility-v4 20 | 21 | call mvn clean install -Dextras.compatibility.v4.groupid=com.android.support -Dextras.compatibility.v4.artifactid=support- 22 | 23 | v4 24 | 25 | cd ..\gcm\gcm-server 26 | 27 | call mvn clean install 28 | 29 | cd ../../../../iboxdb 30 | 31 | call mvn clean install 32 | 33 | cd ../objectify 34 | 35 | call maven clean install 36 | 37 | cd /d %CURRENTDIR% 38 | -------------------------------------------------------------------------------- /dependency_setup/setup.sh: -------------------------------------------------------------------------------- 1 | pwd=$(pwd) 2 | 3 | if [ -d "maven-android-sdk-deployer" ] 4 | then 5 | cd maven-android-sdk-deployer 6 | git pull 7 | else 8 | git clone https://github.com/mosabua/maven-android-sdk-deployer.git 9 | cd maven-android-sdk-deployer 10 | fi 11 | 12 | mvn clean install -P 4.4 13 | 14 | cd extras/compatibility-v13 15 | 16 | mvn clean install -Dextras.compatibility.v13.groupid=com.android.support -Dextras.compatibility.v13.artifactid=support-v13 17 | 18 | cd ../compatibility-v4 19 | 20 | mvn clean install -Dextras.compatibility.v4.groupid=com.android.support -Dextras.compatibility.v4.artifactid=support-v4 21 | 22 | cd ../gcm/gcm-server 23 | 24 | mvn clean install 25 | 26 | cd ../../../../iboxdb 27 | 28 | mvn clean install 29 | 30 | cd ../objectify/ 31 | 32 | mvn clean install 33 | 34 | cd $pwd 35 | --------------------------------------------------------------------------------
Subscribing a DeadEvent handler is useful for debugging or logging, as it can detect misconfigurations in a 23 | * system's event distribution. 24 | * 25 | * @author Cliff Biffle 26 | */ 27 | public class DeadEvent { 28 | 29 | public final Object source; 30 | public final Object event; 31 | 32 | /** 33 | * Creates a new DeadEvent. 34 | * 35 | * @param source object broadcasting the DeadEvent (generally the {@link io.divide.otto.Bus}). 36 | * @param event the event that could not be delivered. 37 | */ 38 | public DeadEvent(Object source, Object event) { 39 | this.source = source; 40 | this.event = event; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/otto/HandlerFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Square, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.otto; 18 | 19 | import java.util.Map; 20 | import java.util.Set; 21 | 22 | /** Finds producer and subscriber methods. */ 23 | public interface HandlerFinder { 24 | 25 | Map, EventProducer> findAllProducers(Object listener); 26 | 27 | Map, Set> findAllSubscribers(Object listener); 28 | 29 | 30 | HandlerFinder ANNOTATED = new HandlerFinder() { 31 | @Override 32 | public Map, EventProducer> findAllProducers(Object listener) { 33 | return AnnotatedHandlerFinder.findAllProducers(listener); 34 | } 35 | 36 | @Override 37 | public Map, Set> findAllSubscribers(Object listener) { 38 | return AnnotatedHandlerFinder.findAllSubscribers(listener); 39 | } 40 | }; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/otto/Produce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Square, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.otto; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Marks a method as an instance producer, as used by {@link io.divide.otto.AnnotatedHandlerFinder} and {@link io.divide.otto.Bus}. 26 | * 27 | * Otto infers the instance type from the annotated method's return type. Producer methods may return null when there is 28 | * no appropriate value to share. The calling {@link io.divide.otto.Bus} ignores such returns and posts nothing. 29 | * 30 | * @author Jake Wharton 31 | */ 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.METHOD) 34 | public @interface Produce { 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/otto/Subscribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.otto; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * Marks a method as an event handler, as used by {@link io.divide.otto.AnnotatedHandlerFinder} and {@link io.divide.otto.Bus}. 23 | * 24 | * The method's first (and only) parameter defines the event type. 25 | * If this annotation is applied to methods with zero parameters or more than one parameter, the object containing 26 | * the method will not be able to register for event delivery from the {@link io.divide.otto.Bus}. Otto fails fast by throwing 27 | * runtime exceptions in these cases. 28 | * 29 | * @author Cliff Biffle 30 | */ 31 | @Inherited 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.METHOD) 34 | public @interface Subscribe { 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/AutoSubscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | public abstract class AutoSubscriber implements Subscriber{ 20 | 21 | protected AutoSubscriber(){ 22 | EventManager.get().register(this); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | public abstract class Event { 20 | private Class> source; 21 | protected Event(Class> sourse){ 22 | this.source = sourse; 23 | } 24 | 25 | public Class> getSource(){ 26 | return source; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Event{" + 32 | "source=" + source + 33 | '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/EventManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | import io.divide.otto.Bus; 20 | import io.divide.otto.SubscriberHandlerFinder; 21 | import io.divide.otto.ThreadEnforcer; 22 | 23 | import java.util.Map; 24 | import java.util.concurrent.ConcurrentHashMap; 25 | 26 | public class EventManager { 27 | 28 | private static Map busMap = new ConcurrentHashMap(); 29 | private Bus eventBus = new Bus(ThreadEnforcer.ANY); 30 | 31 | public static EventManager get(){ 32 | return EventManager.get("default"); 33 | } 34 | 35 | public static EventManager get(String identifier){ 36 | EventManager bus = busMap.get(identifier); 37 | if(bus == null){ 38 | bus = new EventManager(identifier); 39 | busMap.put(identifier,bus); 40 | } 41 | return bus; 42 | } 43 | 44 | private EventManager(String identifier){ 45 | eventBus = new Bus(ThreadEnforcer.ANY,identifier, new SubscriberHandlerFinder()); 46 | } 47 | 48 | 49 | public void fire(Event event){ 50 | eventBus.post(event); 51 | } 52 | 53 | public void register(Subscriber subscriber){ 54 | eventBus.register(subscriber); 55 | } 56 | 57 | public void unregister(S subscriber){ 58 | eventBus.unregister(subscriber); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/Subscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | import io.divide.otto.Subscribe; 20 | 21 | public interface Subscriber{ 22 | 23 | @Subscribe 24 | public void onEvent(final E event); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/file/Storage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.file; 18 | 19 | import java.util.Map; 20 | import java.util.Set; 21 | 22 | public interface Storage { 23 | 24 | public static final int MODE_PRIVATE = 0x0000; 25 | public static final int MODE_WORLD_READABLE = 0x0001; 26 | public static final int MODE_WORLD_WRITEABLE = 0x0002; 27 | public static final int MODE_APPEND = 0x8000; 28 | 29 | public interface Editor { 30 | 31 | Editor putString(String key, String value); 32 | 33 | Editor putStringSet(String key, Set values); 34 | 35 | Editor putInt(String key, int value); 36 | 37 | Editor putLong(String key, long value); 38 | 39 | Editor putFloat(String key, float value); 40 | 41 | Editor putBoolean(String key, boolean value); 42 | 43 | Editor remove(String key); 44 | 45 | Editor clear(); 46 | 47 | boolean commit(); 48 | 49 | void apply(); 50 | } 51 | 52 | Map getAll(); 53 | 54 | String getString(String key, String defValue); 55 | 56 | Set getStringSet(String key, Set defValues); 57 | 58 | int getInt(String key, int defValue); 59 | 60 | long getLong(String key, long defValue); 61 | 62 | float getFloat(String key, float defValue); 63 | 64 | boolean getBoolean(String key, boolean defValue); 65 | 66 | boolean contains(String key); 67 | 68 | Editor edit(); 69 | } -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/DAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | import io.divide.shared.transitory.query.Query; 21 | 22 | import java.util.Collection; 23 | import java.util.List; 24 | 25 | public interface DAO { 26 | public List query(Query query) throws DAOException; // Object, returns different types 27 | public Collection get(String type, String... keys) throws DAOException; 28 | public void save(IN... objects) throws DAOException; 29 | public void delete(IN... objects) throws DAOException; 30 | public boolean exists(IN... objects); 31 | public int count(String objectType); 32 | 33 | public static class DAOException extends RuntimeException{ 34 | int httpStatusCode = -1; 35 | 36 | public DAOException(Throwable throwable){ 37 | this(500,throwable); 38 | } 39 | 40 | public DAOException(int statusCode, String cause){ 41 | super(cause); 42 | this.httpStatusCode = statusCode; 43 | } 44 | 45 | public DAOException(int httpStatusCode, Throwable thrown){ 46 | super(thrown); 47 | this.httpStatusCode = httpStatusCode; 48 | } 49 | 50 | public int getStatusCode(){ 51 | return httpStatusCode; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/KeyManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import java.security.PrivateKey; 20 | import java.security.PublicKey; 21 | 22 | public interface KeyManager { 23 | 24 | public PublicKey getPublicKey(); 25 | public PrivateKey getPrivateKey(); 26 | public String getSymmetricKey(); 27 | public String getPushKey(); 28 | } 29 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/ServerLogic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public abstract class ServerLogic { 22 | 23 | protected DAO dao; 24 | 25 | public ServerLogic(DAO dao){ 26 | this.dao = dao; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/DBObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | public interface DBObject { 20 | public String getId(); 21 | } 22 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/Clause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | public class Clause { 20 | private String preOperator = ""; 21 | private String before; 22 | private String operand; 23 | private String after; 24 | 25 | private Clause(){} 26 | 27 | protected Clause(String before,OPERAND operand, String after){ 28 | this.before = before; 29 | this.after = after; 30 | this.operand = operand.symbol; 31 | } 32 | 33 | protected Clause(OPERAND.Conditional preOperator, String before,OPERAND operand, String after){ 34 | this.preOperator = preOperator.symbol; 35 | this.before = before; 36 | this.after = after; 37 | this.operand = operand.symbol; 38 | } 39 | 40 | public String getBefore(){ 41 | return before; 42 | } 43 | 44 | public String getOperand(){ 45 | return operand; 46 | } 47 | 48 | public String getAfter(){ 49 | return after; 50 | } 51 | 52 | public void setBefore(String before){ 53 | this.before = before; 54 | } 55 | 56 | public void setOperand(OPERAND operand){ 57 | this.operand = operand.symbol; 58 | } 59 | 60 | public String getPreOperator(){ 61 | return preOperator; 62 | } 63 | 64 | public void setAfter(String after){ 65 | this.after = after; 66 | } 67 | 68 | public String getCoded(){ 69 | return getBefore() + " " + getOperand() + " '" + getAfter() +"'"; 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "Clause{" + 75 | "before='" + before + '\'' + 76 | ", operand='" + operand + '\'' + 77 | ", after='" + after + '\'' + 78 | '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/Count.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class Count extends TransientObject { 22 | public Count(int count, String from) { 23 | setCount(count); 24 | setFrom(from); 25 | } 26 | 27 | public int getCount(){ 28 | return get(Integer.class,"count"); 29 | } 30 | 31 | public String getFrom(){ 32 | return get(String.class,"from"); 33 | } 34 | 35 | public void setCount(int count){ 36 | put("count",count); 37 | } 38 | 39 | public void setFrom(String from){ 40 | put("from",from); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/MetaDataClause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class MetaDataClause extends Clause 22 | { 23 | protected MetaDataClause(String before, OPERAND operand, String after) { 24 | super(TransientObject.META_DATA + "." + before, operand, after); 25 | } 26 | 27 | protected MetaDataClause(OPERAND.Conditional conditional,String before, OPERAND operand, String after) { 28 | super(conditional,TransientObject.META_DATA + "." + before, operand, after); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/OPERAND.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | public enum OPERAND{ 20 | 21 | GREATER_THAN(">"), 22 | LESS_THAN("<"), 23 | GREATER_THAN_EQ(">="), 24 | LESS_THAN_EQ("<="), 25 | EQ("=="), 26 | CONTAINS("CONTAINS"); 27 | 28 | String symbol; 29 | 30 | OPERAND(String symbol){ 31 | this.symbol = symbol; 32 | } 33 | 34 | public static OPERAND from(String symbol){ 35 | if(GREATER_THAN.symbol.equals(symbol)){ 36 | return GREATER_THAN; 37 | } else if(LESS_THAN.symbol.equals(symbol)){ 38 | return LESS_THAN; 39 | } else if(GREATER_THAN_EQ.symbol.equals(symbol)){ 40 | return GREATER_THAN_EQ; 41 | } else if(LESS_THAN_EQ.symbol.equals(symbol)){ 42 | return LESS_THAN_EQ; 43 | } else if(EQ.symbol.equals(symbol)){ 44 | return EQ; 45 | } else if(CONTAINS.symbol.equals(symbol)){ 46 | return CONTAINS; 47 | }else { 48 | return null; 49 | } 50 | } 51 | 52 | public static enum Conditional{ 53 | AND("AND"), 54 | OR("OR"); 55 | 56 | String symbol; 57 | 58 | Conditional(String symbol){ 59 | this.symbol = symbol; 60 | } 61 | 62 | public static Conditional from(String symbol){ 63 | if(AND.symbol.equals(symbol)){ 64 | return AND; 65 | } else if(OR.symbol.equals(symbol)){ 66 | return OR; 67 | } else { 68 | return null; 69 | } 70 | } 71 | } 72 | 73 | @Override 74 | public String toString(){ 75 | return symbol; 76 | } 77 | 78 | }; -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/SelectOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public enum SelectOperation { 22 | COUNT(Count.class); 23 | 24 | private transient Class> type; 25 | 26 | private SelectOperation(Class type){ 27 | this.type = type; 28 | } 29 | 30 | public Class> getType(){ 31 | return type; 32 | } 33 | 34 | public String getErrorMessage(){ 35 | return this.name() + " requires type " + type.getSimpleName(); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/UserDataClause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class UserDataClause extends Clause { 22 | protected UserDataClause(String before, OPERAND operand, String after) { 23 | super(TransientObject.USER_DATA + "." + before, operand, after); 24 | } 25 | 26 | protected UserDataClause(OPERAND.Conditional conditional,String before, OPERAND operand, String after) { 27 | super(conditional,TransientObject.USER_DATA + "." + before, operand, after); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/BitMask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.io.Serializable; 20 | 21 | public class BitMask implements Serializable { 22 | 23 | private int flags = 0; 24 | 25 | // private final void setclear(int mask, boolean set) { if (set) set(mask); else clear(mask); } 26 | 27 | public BitMask(Integer... set){ 28 | for(Integer i : set){ 29 | set(i); 30 | } 31 | } 32 | 33 | public void set(int mask, boolean set){ 34 | if(set)set(mask); 35 | else clear(mask); 36 | } 37 | 38 | private final void set(int mask) { flags |= 1 << mask; } 39 | public final void clear(int mask) { flags &= ~(1 << mask); } 40 | public final boolean get(int mask) { return (flags & 1 << mask) != 0; } 41 | 42 | public int getFlags(){ 43 | return flags; 44 | } 45 | 46 | /* 47 | 48 | Set union 49 | A | B 50 | Set intersection 51 | A & B 52 | Set subtraction 53 | A & ~B 54 | Set negation 55 | ALL_BITS ^ A 56 | Set bit 57 | A |= 1 << bit 58 | Clear bit 59 | A &= ~(1 << bit) 60 | Test bit 61 | (A & 1 << bit) != 0 62 | 63 | */ 64 | } 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.io.*; 20 | import java.nio.charset.Charset; 21 | 22 | public class IOUtils { 23 | 24 | public static String toString(InputStream in) throws IOException 25 | { 26 | BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 27 | StringBuilder out = new StringBuilder(); 28 | String newLine = System.getProperty("line.separator"); 29 | String line; 30 | while ((line = reader.readLine()) != null) { 31 | out.append(line); 32 | out.append(newLine); 33 | } 34 | return out.toString(); 35 | } 36 | 37 | public static InputStream toInputStream(String input, String encoding) throws IOException { 38 | byte[] bytes = input.getBytes(Charset.forName(encoding)); 39 | return new ByteArrayInputStream(bytes); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/NetUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.net.InetAddress; 20 | 21 | public class NetUtils { 22 | 23 | public static boolean ping(byte[] ip, int timeout){ 24 | try { 25 | return InetAddress.getByAddress(ip).isReachable(timeout); 26 | } catch (Exception e) { 27 | return false; 28 | } 29 | } 30 | 31 | public static boolean ping(String host, int timeout){ 32 | try { 33 | return InetAddress.getByName(host).isReachable(timeout); 34 | } catch (Exception e) { 35 | return false; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/FilePermissionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | public class FilePermissionsTest { } 20 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/TransientObjectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | import junit.framework.TestCase; 20 | 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | public class TransientObjectTest extends TestCase { 25 | 26 | public void testMeta_put() throws Exception { 27 | AObject o = new AObject(); 28 | List l = Arrays.asList(1,2); 29 | o.put("key", l); 30 | assertEquals(l, o.get(l.getClass(),"key")); 31 | } 32 | 33 | public void testMeta_get() throws Exception { 34 | 35 | } 36 | 37 | public void testMeta_remove() throws Exception { 38 | 39 | } 40 | 41 | public void testPut() throws Exception { 42 | 43 | } 44 | 45 | public void testPutAll() throws Exception { 46 | 47 | } 48 | 49 | public void testGet() throws Exception { 50 | 51 | } 52 | 53 | public void testRemove() throws Exception { 54 | 55 | } 56 | 57 | public void testRemoveAll() throws Exception { 58 | 59 | } 60 | 61 | private static class AObject extends TransientObject { } 62 | } 63 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/query/QueryTest.java: -------------------------------------------------------------------------------- 1 | package io.divide.shared.transitory.query; 2 | 3 | import io.divide.shared.transitory.TransientObject; 4 | import junit.framework.TestCase; 5 | 6 | public class QueryTest extends TestCase { 7 | 8 | public void testSafeTable() throws Exception { 9 | assertEquals(A.class.getName().replace('.','_'),Query.safeTable(A.class)); 10 | } 11 | 12 | public void testSafeTable1() throws Exception { 13 | assertEquals(A.class.getName().replace('.','_'),Query.safeTable(A.class.getName())); 14 | } 15 | 16 | public void testReverseTable() throws Exception { 17 | assertEquals(A.class.getName(),Query.reverseTable(Query.safeTable(A.class))); 18 | } 19 | 20 | private static class A extends TransientObject{}; 21 | } -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/util/BitMaskTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | public class BitMaskTest { 22 | @org.junit.Test 23 | public void testAll() throws Exception { 24 | BitMask bm = new BitMask(); 25 | 26 | bm.set(1,true); 27 | assertEquals("1=true",true,bm.get(1)); 28 | bm.set(3,true); 29 | assertEquals("3=true",true,bm.get(3)); 30 | bm.set(5,true); 31 | assertEquals("5=true",true,bm.get(5)); 32 | 33 | assertEquals("2=false",false,bm.get(2)); 34 | assertEquals("4=false",false,bm.get(4)); 35 | assertEquals("6=false",false,bm.get(6)); 36 | 37 | 38 | bm.set(1,false); 39 | assertEquals(false,bm.get(1)); 40 | bm.set(3,false); 41 | assertEquals(false,bm.get(3)); 42 | bm.set(5,false); 43 | assertEquals(false,bm.get(5)); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dependency_setup/.gitignore: -------------------------------------------------------------------------------- 1 | maven-android-sdk-deployer/ 2 | -------------------------------------------------------------------------------- /dependency_setup/iboxdb/iBoxDB-1.5.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/dependency_setup/iboxdb/iBoxDB-1.5.2.jar -------------------------------------------------------------------------------- /dependency_setup/iboxdb/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | io.divide 8 | dependency-setup 9 | 1.0 10 | ../pom.xml 11 | 12 | iboxdb 13 | pom 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-install-plugin 20 | 2.4 21 | 22 | 23 | install-iboxdb 24 | package 25 | 26 | install-file 27 | 28 | 29 | iBoxDB-1.5.2.jar 30 | iboxdb 31 | iboxdb 32 | 1.5.2 33 | jar 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /dependency_setup/objectify/objectify-custom.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/dependency_setup/objectify/objectify-custom.jar -------------------------------------------------------------------------------- /dependency_setup/objectify/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | io.divide 8 | dependency-setup 9 | 1.0 10 | ../pom.xml 11 | 12 | objectify 13 | pom 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-install-plugin 20 | 2.4 21 | 22 | 23 | install-objectify 24 | package 25 | 26 | install-file 27 | 28 | 29 | objectify-custom.jar 30 | com.googlecode.objectify 31 | objectify 32 | custom 33 | jar 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /dependency_setup/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | io.divide 7 | dependency-setup 8 | 1.0 9 | pom 10 | 11 | 12 | iboxdb 13 | objectify 14 | 15 | 16 | -------------------------------------------------------------------------------- /dependency_setup/setup.bat: -------------------------------------------------------------------------------- 1 | SET CURRENTDIR="%cd%" 2 | 3 | if exist maven-android-sdk-deployer ( 4 | cd maven-android-sdk-deployer 5 | git pull 6 | ) else ( 7 | git clone https://github.com/mosabua/maven-android-sdk-deployer.git 8 | cd maven-android-sdk-deployer 9 | ) 10 | 11 | call mvn clean install -P 4.4a 12 | 13 | cd extras\compatibility-v13 14 | 15 | call mvn clean install -Dextras.compatibility.v13.groupid=com.android.support - 16 | 17 | Dextras.compatibility.v13.artifactid=support-v13 18 | 19 | cd ..\compatibility-v4 20 | 21 | call mvn clean install -Dextras.compatibility.v4.groupid=com.android.support -Dextras.compatibility.v4.artifactid=support- 22 | 23 | v4 24 | 25 | cd ..\gcm\gcm-server 26 | 27 | call mvn clean install 28 | 29 | cd ../../../../iboxdb 30 | 31 | call mvn clean install 32 | 33 | cd ../objectify 34 | 35 | call maven clean install 36 | 37 | cd /d %CURRENTDIR% 38 | -------------------------------------------------------------------------------- /dependency_setup/setup.sh: -------------------------------------------------------------------------------- 1 | pwd=$(pwd) 2 | 3 | if [ -d "maven-android-sdk-deployer" ] 4 | then 5 | cd maven-android-sdk-deployer 6 | git pull 7 | else 8 | git clone https://github.com/mosabua/maven-android-sdk-deployer.git 9 | cd maven-android-sdk-deployer 10 | fi 11 | 12 | mvn clean install -P 4.4 13 | 14 | cd extras/compatibility-v13 15 | 16 | mvn clean install -Dextras.compatibility.v13.groupid=com.android.support -Dextras.compatibility.v13.artifactid=support-v13 17 | 18 | cd ../compatibility-v4 19 | 20 | mvn clean install -Dextras.compatibility.v4.groupid=com.android.support -Dextras.compatibility.v4.artifactid=support-v4 21 | 22 | cd ../gcm/gcm-server 23 | 24 | mvn clean install 25 | 26 | cd ../../../../iboxdb 27 | 28 | mvn clean install 29 | 30 | cd ../objectify/ 31 | 32 | mvn clean install 33 | 34 | cd $pwd 35 | --------------------------------------------------------------------------------
27 | * Otto infers the instance type from the annotated method's return type. Producer methods may return null when there is 28 | * no appropriate value to share. The calling {@link io.divide.otto.Bus} ignores such returns and posts nothing. 29 | * 30 | * @author Jake Wharton 31 | */ 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.METHOD) 34 | public @interface Produce { 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/otto/Subscribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Guava Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.otto; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * Marks a method as an event handler, as used by {@link io.divide.otto.AnnotatedHandlerFinder} and {@link io.divide.otto.Bus}. 23 | * 24 | *
The method's first (and only) parameter defines the event type. 25 | *
If this annotation is applied to methods with zero parameters or more than one parameter, the object containing 26 | * the method will not be able to register for event delivery from the {@link io.divide.otto.Bus}. Otto fails fast by throwing 27 | * runtime exceptions in these cases. 28 | * 29 | * @author Cliff Biffle 30 | */ 31 | @Inherited 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.METHOD) 34 | public @interface Subscribe { 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/AutoSubscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | public abstract class AutoSubscriber implements Subscriber{ 20 | 21 | protected AutoSubscriber(){ 22 | EventManager.get().register(this); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | public abstract class Event { 20 | private Class> source; 21 | protected Event(Class> sourse){ 22 | this.source = sourse; 23 | } 24 | 25 | public Class> getSource(){ 26 | return source; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Event{" + 32 | "source=" + source + 33 | '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/EventManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | import io.divide.otto.Bus; 20 | import io.divide.otto.SubscriberHandlerFinder; 21 | import io.divide.otto.ThreadEnforcer; 22 | 23 | import java.util.Map; 24 | import java.util.concurrent.ConcurrentHashMap; 25 | 26 | public class EventManager { 27 | 28 | private static Map busMap = new ConcurrentHashMap(); 29 | private Bus eventBus = new Bus(ThreadEnforcer.ANY); 30 | 31 | public static EventManager get(){ 32 | return EventManager.get("default"); 33 | } 34 | 35 | public static EventManager get(String identifier){ 36 | EventManager bus = busMap.get(identifier); 37 | if(bus == null){ 38 | bus = new EventManager(identifier); 39 | busMap.put(identifier,bus); 40 | } 41 | return bus; 42 | } 43 | 44 | private EventManager(String identifier){ 45 | eventBus = new Bus(ThreadEnforcer.ANY,identifier, new SubscriberHandlerFinder()); 46 | } 47 | 48 | 49 | public void fire(Event event){ 50 | eventBus.post(event); 51 | } 52 | 53 | public void register(Subscriber subscriber){ 54 | eventBus.register(subscriber); 55 | } 56 | 57 | public void unregister(S subscriber){ 58 | eventBus.unregister(subscriber); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/event/Subscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.event; 18 | 19 | import io.divide.otto.Subscribe; 20 | 21 | public interface Subscriber{ 22 | 23 | @Subscribe 24 | public void onEvent(final E event); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/file/Storage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.file; 18 | 19 | import java.util.Map; 20 | import java.util.Set; 21 | 22 | public interface Storage { 23 | 24 | public static final int MODE_PRIVATE = 0x0000; 25 | public static final int MODE_WORLD_READABLE = 0x0001; 26 | public static final int MODE_WORLD_WRITEABLE = 0x0002; 27 | public static final int MODE_APPEND = 0x8000; 28 | 29 | public interface Editor { 30 | 31 | Editor putString(String key, String value); 32 | 33 | Editor putStringSet(String key, Set values); 34 | 35 | Editor putInt(String key, int value); 36 | 37 | Editor putLong(String key, long value); 38 | 39 | Editor putFloat(String key, float value); 40 | 41 | Editor putBoolean(String key, boolean value); 42 | 43 | Editor remove(String key); 44 | 45 | Editor clear(); 46 | 47 | boolean commit(); 48 | 49 | void apply(); 50 | } 51 | 52 | Map getAll(); 53 | 54 | String getString(String key, String defValue); 55 | 56 | Set getStringSet(String key, Set defValues); 57 | 58 | int getInt(String key, int defValue); 59 | 60 | long getLong(String key, long defValue); 61 | 62 | float getFloat(String key, float defValue); 63 | 64 | boolean getBoolean(String key, boolean defValue); 65 | 66 | boolean contains(String key); 67 | 68 | Editor edit(); 69 | } -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/DAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | import io.divide.shared.transitory.query.Query; 21 | 22 | import java.util.Collection; 23 | import java.util.List; 24 | 25 | public interface DAO { 26 | public List query(Query query) throws DAOException; // Object, returns different types 27 | public Collection get(String type, String... keys) throws DAOException; 28 | public void save(IN... objects) throws DAOException; 29 | public void delete(IN... objects) throws DAOException; 30 | public boolean exists(IN... objects); 31 | public int count(String objectType); 32 | 33 | public static class DAOException extends RuntimeException{ 34 | int httpStatusCode = -1; 35 | 36 | public DAOException(Throwable throwable){ 37 | this(500,throwable); 38 | } 39 | 40 | public DAOException(int statusCode, String cause){ 41 | super(cause); 42 | this.httpStatusCode = statusCode; 43 | } 44 | 45 | public DAOException(int httpStatusCode, Throwable thrown){ 46 | super(thrown); 47 | this.httpStatusCode = httpStatusCode; 48 | } 49 | 50 | public int getStatusCode(){ 51 | return httpStatusCode; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/KeyManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import java.security.PrivateKey; 20 | import java.security.PublicKey; 21 | 22 | public interface KeyManager { 23 | 24 | public PublicKey getPublicKey(); 25 | public PrivateKey getPrivateKey(); 26 | public String getSymmetricKey(); 27 | public String getPushKey(); 28 | } 29 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/server/ServerLogic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.server; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public abstract class ServerLogic { 22 | 23 | protected DAO dao; 24 | 25 | public ServerLogic(DAO dao){ 26 | this.dao = dao; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/DBObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | public interface DBObject { 20 | public String getId(); 21 | } 22 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/Clause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | public class Clause { 20 | private String preOperator = ""; 21 | private String before; 22 | private String operand; 23 | private String after; 24 | 25 | private Clause(){} 26 | 27 | protected Clause(String before,OPERAND operand, String after){ 28 | this.before = before; 29 | this.after = after; 30 | this.operand = operand.symbol; 31 | } 32 | 33 | protected Clause(OPERAND.Conditional preOperator, String before,OPERAND operand, String after){ 34 | this.preOperator = preOperator.symbol; 35 | this.before = before; 36 | this.after = after; 37 | this.operand = operand.symbol; 38 | } 39 | 40 | public String getBefore(){ 41 | return before; 42 | } 43 | 44 | public String getOperand(){ 45 | return operand; 46 | } 47 | 48 | public String getAfter(){ 49 | return after; 50 | } 51 | 52 | public void setBefore(String before){ 53 | this.before = before; 54 | } 55 | 56 | public void setOperand(OPERAND operand){ 57 | this.operand = operand.symbol; 58 | } 59 | 60 | public String getPreOperator(){ 61 | return preOperator; 62 | } 63 | 64 | public void setAfter(String after){ 65 | this.after = after; 66 | } 67 | 68 | public String getCoded(){ 69 | return getBefore() + " " + getOperand() + " '" + getAfter() +"'"; 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "Clause{" + 75 | "before='" + before + '\'' + 76 | ", operand='" + operand + '\'' + 77 | ", after='" + after + '\'' + 78 | '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/Count.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class Count extends TransientObject { 22 | public Count(int count, String from) { 23 | setCount(count); 24 | setFrom(from); 25 | } 26 | 27 | public int getCount(){ 28 | return get(Integer.class,"count"); 29 | } 30 | 31 | public String getFrom(){ 32 | return get(String.class,"from"); 33 | } 34 | 35 | public void setCount(int count){ 36 | put("count",count); 37 | } 38 | 39 | public void setFrom(String from){ 40 | put("from",from); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/MetaDataClause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class MetaDataClause extends Clause 22 | { 23 | protected MetaDataClause(String before, OPERAND operand, String after) { 24 | super(TransientObject.META_DATA + "." + before, operand, after); 25 | } 26 | 27 | protected MetaDataClause(OPERAND.Conditional conditional,String before, OPERAND operand, String after) { 28 | super(conditional,TransientObject.META_DATA + "." + before, operand, after); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/OPERAND.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | public enum OPERAND{ 20 | 21 | GREATER_THAN(">"), 22 | LESS_THAN("<"), 23 | GREATER_THAN_EQ(">="), 24 | LESS_THAN_EQ("<="), 25 | EQ("=="), 26 | CONTAINS("CONTAINS"); 27 | 28 | String symbol; 29 | 30 | OPERAND(String symbol){ 31 | this.symbol = symbol; 32 | } 33 | 34 | public static OPERAND from(String symbol){ 35 | if(GREATER_THAN.symbol.equals(symbol)){ 36 | return GREATER_THAN; 37 | } else if(LESS_THAN.symbol.equals(symbol)){ 38 | return LESS_THAN; 39 | } else if(GREATER_THAN_EQ.symbol.equals(symbol)){ 40 | return GREATER_THAN_EQ; 41 | } else if(LESS_THAN_EQ.symbol.equals(symbol)){ 42 | return LESS_THAN_EQ; 43 | } else if(EQ.symbol.equals(symbol)){ 44 | return EQ; 45 | } else if(CONTAINS.symbol.equals(symbol)){ 46 | return CONTAINS; 47 | }else { 48 | return null; 49 | } 50 | } 51 | 52 | public static enum Conditional{ 53 | AND("AND"), 54 | OR("OR"); 55 | 56 | String symbol; 57 | 58 | Conditional(String symbol){ 59 | this.symbol = symbol; 60 | } 61 | 62 | public static Conditional from(String symbol){ 63 | if(AND.symbol.equals(symbol)){ 64 | return AND; 65 | } else if(OR.symbol.equals(symbol)){ 66 | return OR; 67 | } else { 68 | return null; 69 | } 70 | } 71 | } 72 | 73 | @Override 74 | public String toString(){ 75 | return symbol; 76 | } 77 | 78 | }; -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/SelectOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public enum SelectOperation { 22 | COUNT(Count.class); 23 | 24 | private transient Class> type; 25 | 26 | private SelectOperation(Class type){ 27 | this.type = type; 28 | } 29 | 30 | public Class> getType(){ 31 | return type; 32 | } 33 | 34 | public String getErrorMessage(){ 35 | return this.name() + " requires type " + type.getSimpleName(); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/transitory/query/UserDataClause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory.query; 18 | 19 | import io.divide.shared.transitory.TransientObject; 20 | 21 | public class UserDataClause extends Clause { 22 | protected UserDataClause(String before, OPERAND operand, String after) { 23 | super(TransientObject.USER_DATA + "." + before, operand, after); 24 | } 25 | 26 | protected UserDataClause(OPERAND.Conditional conditional,String before, OPERAND operand, String after) { 27 | super(conditional,TransientObject.USER_DATA + "." + before, operand, after); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/BitMask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.io.Serializable; 20 | 21 | public class BitMask implements Serializable { 22 | 23 | private int flags = 0; 24 | 25 | // private final void setclear(int mask, boolean set) { if (set) set(mask); else clear(mask); } 26 | 27 | public BitMask(Integer... set){ 28 | for(Integer i : set){ 29 | set(i); 30 | } 31 | } 32 | 33 | public void set(int mask, boolean set){ 34 | if(set)set(mask); 35 | else clear(mask); 36 | } 37 | 38 | private final void set(int mask) { flags |= 1 << mask; } 39 | public final void clear(int mask) { flags &= ~(1 << mask); } 40 | public final boolean get(int mask) { return (flags & 1 << mask) != 0; } 41 | 42 | public int getFlags(){ 43 | return flags; 44 | } 45 | 46 | /* 47 | 48 | Set union 49 | A | B 50 | Set intersection 51 | A & B 52 | Set subtraction 53 | A & ~B 54 | Set negation 55 | ALL_BITS ^ A 56 | Set bit 57 | A |= 1 << bit 58 | Clear bit 59 | A &= ~(1 << bit) 60 | Test bit 61 | (A & 1 << bit) != 0 62 | 63 | */ 64 | } 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.io.*; 20 | import java.nio.charset.Charset; 21 | 22 | public class IOUtils { 23 | 24 | public static String toString(InputStream in) throws IOException 25 | { 26 | BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 27 | StringBuilder out = new StringBuilder(); 28 | String newLine = System.getProperty("line.separator"); 29 | String line; 30 | while ((line = reader.readLine()) != null) { 31 | out.append(line); 32 | out.append(newLine); 33 | } 34 | return out.toString(); 35 | } 36 | 37 | public static InputStream toInputStream(String input, String encoding) throws IOException { 38 | byte[] bytes = input.getBytes(Charset.forName(encoding)); 39 | return new ByteArrayInputStream(bytes); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Shared/src/main/java/io/divide/shared/util/NetUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import java.net.InetAddress; 20 | 21 | public class NetUtils { 22 | 23 | public static boolean ping(byte[] ip, int timeout){ 24 | try { 25 | return InetAddress.getByAddress(ip).isReachable(timeout); 26 | } catch (Exception e) { 27 | return false; 28 | } 29 | } 30 | 31 | public static boolean ping(String host, int timeout){ 32 | try { 33 | return InetAddress.getByName(host).isReachable(timeout); 34 | } catch (Exception e) { 35 | return false; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/FilePermissionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | public class FilePermissionsTest { } 20 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/TransientObjectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.transitory; 18 | 19 | import junit.framework.TestCase; 20 | 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | public class TransientObjectTest extends TestCase { 25 | 26 | public void testMeta_put() throws Exception { 27 | AObject o = new AObject(); 28 | List l = Arrays.asList(1,2); 29 | o.put("key", l); 30 | assertEquals(l, o.get(l.getClass(),"key")); 31 | } 32 | 33 | public void testMeta_get() throws Exception { 34 | 35 | } 36 | 37 | public void testMeta_remove() throws Exception { 38 | 39 | } 40 | 41 | public void testPut() throws Exception { 42 | 43 | } 44 | 45 | public void testPutAll() throws Exception { 46 | 47 | } 48 | 49 | public void testGet() throws Exception { 50 | 51 | } 52 | 53 | public void testRemove() throws Exception { 54 | 55 | } 56 | 57 | public void testRemoveAll() throws Exception { 58 | 59 | } 60 | 61 | private static class AObject extends TransientObject { } 62 | } 63 | -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/transitory/query/QueryTest.java: -------------------------------------------------------------------------------- 1 | package io.divide.shared.transitory.query; 2 | 3 | import io.divide.shared.transitory.TransientObject; 4 | import junit.framework.TestCase; 5 | 6 | public class QueryTest extends TestCase { 7 | 8 | public void testSafeTable() throws Exception { 9 | assertEquals(A.class.getName().replace('.','_'),Query.safeTable(A.class)); 10 | } 11 | 12 | public void testSafeTable1() throws Exception { 13 | assertEquals(A.class.getName().replace('.','_'),Query.safeTable(A.class.getName())); 14 | } 15 | 16 | public void testReverseTable() throws Exception { 17 | assertEquals(A.class.getName(),Query.reverseTable(Query.safeTable(A.class))); 18 | } 19 | 20 | private static class A extends TransientObject{}; 21 | } -------------------------------------------------------------------------------- /Shared/src/test/java/io/divide/shared/util/BitMaskTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Divide.io 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.divide.shared.util; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | public class BitMaskTest { 22 | @org.junit.Test 23 | public void testAll() throws Exception { 24 | BitMask bm = new BitMask(); 25 | 26 | bm.set(1,true); 27 | assertEquals("1=true",true,bm.get(1)); 28 | bm.set(3,true); 29 | assertEquals("3=true",true,bm.get(3)); 30 | bm.set(5,true); 31 | assertEquals("5=true",true,bm.get(5)); 32 | 33 | assertEquals("2=false",false,bm.get(2)); 34 | assertEquals("4=false",false,bm.get(4)); 35 | assertEquals("6=false",false,bm.get(6)); 36 | 37 | 38 | bm.set(1,false); 39 | assertEquals(false,bm.get(1)); 40 | bm.set(3,false); 41 | assertEquals(false,bm.get(3)); 42 | bm.set(5,false); 43 | assertEquals(false,bm.get(5)); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dependency_setup/.gitignore: -------------------------------------------------------------------------------- 1 | maven-android-sdk-deployer/ 2 | -------------------------------------------------------------------------------- /dependency_setup/iboxdb/iBoxDB-1.5.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/dependency_setup/iboxdb/iBoxDB-1.5.2.jar -------------------------------------------------------------------------------- /dependency_setup/iboxdb/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | io.divide 8 | dependency-setup 9 | 1.0 10 | ../pom.xml 11 | 12 | iboxdb 13 | pom 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-install-plugin 20 | 2.4 21 | 22 | 23 | install-iboxdb 24 | package 25 | 26 | install-file 27 | 28 | 29 | iBoxDB-1.5.2.jar 30 | iboxdb 31 | iboxdb 32 | 1.5.2 33 | jar 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /dependency_setup/objectify/objectify-custom.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiddenStage/divide/14e36598c50d92b4393e6649915e32b86141c598/dependency_setup/objectify/objectify-custom.jar -------------------------------------------------------------------------------- /dependency_setup/objectify/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | io.divide 8 | dependency-setup 9 | 1.0 10 | ../pom.xml 11 | 12 | objectify 13 | pom 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-install-plugin 20 | 2.4 21 | 22 | 23 | install-objectify 24 | package 25 | 26 | install-file 27 | 28 | 29 | objectify-custom.jar 30 | com.googlecode.objectify 31 | objectify 32 | custom 33 | jar 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /dependency_setup/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | io.divide 7 | dependency-setup 8 | 1.0 9 | pom 10 | 11 | 12 | iboxdb 13 | objectify 14 | 15 | 16 | -------------------------------------------------------------------------------- /dependency_setup/setup.bat: -------------------------------------------------------------------------------- 1 | SET CURRENTDIR="%cd%" 2 | 3 | if exist maven-android-sdk-deployer ( 4 | cd maven-android-sdk-deployer 5 | git pull 6 | ) else ( 7 | git clone https://github.com/mosabua/maven-android-sdk-deployer.git 8 | cd maven-android-sdk-deployer 9 | ) 10 | 11 | call mvn clean install -P 4.4a 12 | 13 | cd extras\compatibility-v13 14 | 15 | call mvn clean install -Dextras.compatibility.v13.groupid=com.android.support - 16 | 17 | Dextras.compatibility.v13.artifactid=support-v13 18 | 19 | cd ..\compatibility-v4 20 | 21 | call mvn clean install -Dextras.compatibility.v4.groupid=com.android.support -Dextras.compatibility.v4.artifactid=support- 22 | 23 | v4 24 | 25 | cd ..\gcm\gcm-server 26 | 27 | call mvn clean install 28 | 29 | cd ../../../../iboxdb 30 | 31 | call mvn clean install 32 | 33 | cd ../objectify 34 | 35 | call maven clean install 36 | 37 | cd /d %CURRENTDIR% 38 | -------------------------------------------------------------------------------- /dependency_setup/setup.sh: -------------------------------------------------------------------------------- 1 | pwd=$(pwd) 2 | 3 | if [ -d "maven-android-sdk-deployer" ] 4 | then 5 | cd maven-android-sdk-deployer 6 | git pull 7 | else 8 | git clone https://github.com/mosabua/maven-android-sdk-deployer.git 9 | cd maven-android-sdk-deployer 10 | fi 11 | 12 | mvn clean install -P 4.4 13 | 14 | cd extras/compatibility-v13 15 | 16 | mvn clean install -Dextras.compatibility.v13.groupid=com.android.support -Dextras.compatibility.v13.artifactid=support-v13 17 | 18 | cd ../compatibility-v4 19 | 20 | mvn clean install -Dextras.compatibility.v4.groupid=com.android.support -Dextras.compatibility.v4.artifactid=support-v4 21 | 22 | cd ../gcm/gcm-server 23 | 24 | mvn clean install 25 | 26 | cd ../../../../iboxdb 27 | 28 | mvn clean install 29 | 30 | cd ../objectify/ 31 | 32 | mvn clean install 33 | 34 | cd $pwd 35 | --------------------------------------------------------------------------------