From babaf2cd81ddb40bf2e76e2537d258d1b8f97221 Mon Sep 17 00:00:00 2001 From: Felix Prahl-Kamps Date: Sun, 22 Apr 2018 01:50:05 +0200 Subject: [PATCH] Initial commit --- .gitignore | 64 +++++ .idea/assetWizardSettings.xml | 60 ++++ .idea/codeStyles/Project.xml | 29 ++ .idea/misc.xml | 34 +++ .idea/modules.xml | 9 + .idea/runConfigurations.xml | 12 + app/.gitignore | 1 + app/build.gradle | 32 +++ app/proguard-rules.pro | 21 ++ .../mispauthv2/ExampleInstrumentedTest.java | 26 ++ app/src/main/AndroidManifest.xml | 24 ++ .../overview/mispauthv2/MainActivity.java | 209 ++++++++++++++ .../overview/mispauthv2/SyncActivity.java | 51 ++++ .../overview/mispauthv2/camera/QRScanner.java | 34 +++ .../mispauthv2/models/Organisation.java | 94 ++++++ .../models/OrganisationBuilder.java | 47 +++ .../overview/mispauthv2/models/Server.java | 77 +++++ .../mispauthv2/models/ServerBuilder.java | 35 +++ .../overview/mispauthv2/models/User.java | 80 ++++++ .../mispauthv2/models/UserBuilder.java | 35 +++ .../mispauthv2/network/MispRequests.java | 269 ++++++++++++++++++ .../main/res/drawable-hdpi/ic_action_name.png | Bin 0 -> 362 bytes .../main/res/drawable-mdpi/ic_action_name.png | Bin 0 -> 262 bytes .../drawable-v24/ic_launcher_foreground.xml | 34 +++ .../res/drawable-xhdpi/ic_action_name.png | Bin 0 -> 437 bytes .../res/drawable-xxhdpi/ic_action_name.png | Bin 0 -> 736 bytes .../res/drawable/ic_launcher_background.xml | 170 +++++++++++ app/src/main/res/layout/activity_main.xml | 33 +++ app/src/main/res/layout/activity_sync.xml | 32 +++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/secrets.xml | 4 + app/src/main/res/values/strings.xml | 9 + app/src/main/res/values/styles.xml | 11 + .../overview/mispauthv2/ExampleUnitTest.java | 17 ++ build.gradle | 29 ++ gradle.properties | 13 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54708 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 +++++++++++ gradlew.bat | 84 ++++++ settings.gradle | 1 + 53 files changed, 1874 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/assetWizardSettings.xml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/de/korrelator/overview/mispauthv2/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/MainActivity.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/SyncActivity.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/camera/QRScanner.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/models/Organisation.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/models/OrganisationBuilder.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/models/Server.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/models/ServerBuilder.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/models/User.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/models/UserBuilder.java create mode 100644 app/src/main/java/de/korrelator/overview/mispauthv2/network/MispRequests.java create mode 100644 app/src/main/res/drawable-hdpi/ic_action_name.png create mode 100644 app/src/main/res/drawable-mdpi/ic_action_name.png create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable-xhdpi/ic_action_name.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_name.png create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/activity_sync.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/secrets.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/de/korrelator/overview/mispauthv2/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d3df34 --- /dev/null +++ b/.gitignore @@ -0,0 +1,64 @@ +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/dictionaries +.idea/libraries +.idea/caches + +# Keystore files +# Uncomment the following line if you do not want to check your keystore files in. +#*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..ca00af2 --- /dev/null +++ b/.idea/assetWizardSettings.xml @@ -0,0 +1,60 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..99202cc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..80ed164 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..c7b0f66 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 27 + defaultConfig { + applicationId "de.korrelator.overview.mispauthv2" + minSdkVersion 21 + targetSdkVersion 27 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support.constraint:constraint-layout:1.1.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.1' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + + + implementation 'com.android.volley:volley:1.1.0' + implementation 'com.github.kenglxn.QRGen:android:2.4.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/de/korrelator/overview/mispauthv2/ExampleInstrumentedTest.java b/app/src/androidTest/java/de/korrelator/overview/mispauthv2/ExampleInstrumentedTest.java new file mode 100644 index 0000000..e729435 --- /dev/null +++ b/app/src/androidTest/java/de/korrelator/overview/mispauthv2/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package de.korrelator.overview.mispauthv2; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("de.korrelator.overview.mispauthv2", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ed16b17 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/MainActivity.java b/app/src/main/java/de/korrelator/overview/mispauthv2/MainActivity.java new file mode 100644 index 0000000..01f83ef --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/MainActivity.java @@ -0,0 +1,209 @@ +package de.korrelator.overview.mispauthv2; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.android.volley.VolleyError; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import de.korrelator.overview.mispauthv2.models.Organisation; +import de.korrelator.overview.mispauthv2.models.OrganisationBuilder; +import de.korrelator.overview.mispauthv2.models.Server; +import de.korrelator.overview.mispauthv2.models.ServerBuilder; +import de.korrelator.overview.mispauthv2.models.User; +import de.korrelator.overview.mispauthv2.models.UserBuilder; +import de.korrelator.overview.mispauthv2.network.MispRequests; + +public class MainActivity extends AppCompatActivity { + + private static final String TAG = "MISPAUTH"; + private static final int SYNC_EVENTS_REQUEST = 1000; + + private MispRequests mispRequests; + + private String myOrgName = "My Orgname"; + private String myEmail = "example@email.bar"; + private String baseURL = "http://192.168.178.200"; + + private TextView textViewResponse; + + private int tmpOrgID, tmpSyncUserID; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mispRequests = new MispRequests(getApplicationContext(), baseURL); + textViewResponse = findViewById(R.id.textview_json_result); + + Button syncEventsButton = findViewById(R.id.button_sync_events); + syncEventsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SyncEvents(); + } + }); + + Button shareEventsButton = findViewById(R.id.button_share_events); + shareEventsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ShareEvents(); + } + }); + + Button receiveEventsButton = findViewById(R.id.button_receive_events); + receiveEventsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ReceiveEvents(); + } + }); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode){ + case SYNC_EVENTS_REQUEST: + + String qrContent = data.getStringExtra("qr_data"); + + try { + + JSONArray qrData = new JSONArray(qrContent); + + JSONObject serverInfo = Server.fromJSON(qrData.getJSONObject(0)).toJSON(); + JSONObject userInfo = User.fromJSON(qrData.getJSONObject(1)).toJSON(); + JSONObject orgInfo = Organisation.fromJSON(qrData.getJSONObject(2)).toJSON(); + + mispRequests.EditOrganisation(tmpOrgID, orgInfo, new MispRequests.EditOrganisationResponse() { + @Override + public void result(boolean success) { + + } + + @Override + public void error(VolleyError volleyError) { + + } + }); + + mispRequests.EditUser(tmpSyncUserID, userInfo, new MispRequests.EditUserResponse() { + @Override + public void result(JSONObject msg) { + + } + + @Override + public void error(VolleyError volleyError) { + + } + }); + + mispRequests.AddServer(serverInfo, new MispRequests.AddServerResponse() { + @Override + public void result(JSONObject result) { + + } + + @Override + public void error(VolleyError volleyError) { + + } + }); + + } catch (JSONException e){ + e.printStackTrace(); + } + + break; + + default: + Log.e(TAG, "requestCode " + requestCode + " is not known!"); + } + } + + + private void SyncEvents(){ + + JSONObject tmpOrgBody = new OrganisationBuilder().local(true).build().toJSON(); + + mispRequests.AddOrganisation(tmpOrgBody, new MispRequests.AddOrganisationResponse() { + @Override + public void result(int orgID) { + + tmpOrgID = orgID; + + JSONObject tmpSyncUser = new UserBuilder().orgID(orgID).roleType(User.RoleType.SYNC_USER).build().toJSON(); + + mispRequests.AddUser(tmpSyncUser, new MispRequests.AddUserResponse() { + @Override + public void result(int id, String authKey) { + + tmpSyncUserID = id; + + JSONArray array = new JSONArray(); + + + JSONObject myServerInformation = new ServerBuilder() + .url(baseURL) + .name(myOrgName) + .authKey(authKey) + .build().toJSON(); + + JSONObject myUserInformation = new UserBuilder() + .email("felixpk@outlug.de") + .build() + .toJSON(); + + JSONObject myOrganisationInformation = new OrganisationBuilder() + .name(myOrgName) + .local(true) + .description("sample description") + .nationality("DE") + .sector("Programming") + .build() + .toJSON(); + + array.put(myServerInformation); + array.put(myUserInformation); + array.put(myOrganisationInformation); + + Intent syncIntent = new Intent(getApplicationContext(), SyncActivity.class); + syncIntent.putExtra("qr_data", array.toString()); + startActivityForResult(syncIntent, SYNC_EVENTS_REQUEST); + } + + @Override + public void error(VolleyError volleyError) { + textViewResponse.setText(volleyError.toString()); + } + }); + } + + @Override + public void error(VolleyError error) { + + } + }); + } + + private void ShareEvents(){ + + } + + private void ReceiveEvents(){ + + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/SyncActivity.java b/app/src/main/java/de/korrelator/overview/mispauthv2/SyncActivity.java new file mode 100644 index 0000000..9dc1983 --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/SyncActivity.java @@ -0,0 +1,51 @@ +package de.korrelator.overview.mispauthv2; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.Point; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.Display; +import android.widget.ImageView; + +import net.glxn.qrgen.android.QRCode; + +public class SyncActivity extends AppCompatActivity { + + private Point displaySize; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sync); + + Display display = getWindowManager().getDefaultDisplay(); + displaySize = new Point(); + display.getSize(displaySize); + + Intent intent = getIntent(); + + String qrData = intent.getStringExtra("qr_data"); + PopulateMyQR(qrData); + } + + private void PopulateMyQR(String qrData){ + ImageView qrView = findViewById(R.id.image_view_sync_qr); + + Bitmap bitmap = + QRCode.from(qrData) + .withSize(displaySize.x, displaySize.x) + .withColor(0xFF000000, 0x00000000) + .bitmap(); + + qrView.setImageBitmap(bitmap); + } + + private void returnQrData(String qrData){ + Intent resultIntent = new Intent(); + resultIntent.putExtra("qr_data", qrData); + setResult(Activity.RESULT_OK, resultIntent); + finish(); + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/camera/QRScanner.java b/app/src/main/java/de/korrelator/overview/mispauthv2/camera/QRScanner.java new file mode 100644 index 0000000..cc94585 --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/camera/QRScanner.java @@ -0,0 +1,34 @@ +package de.korrelator.overview.mispauthv2.camera; + +import android.Manifest; +import android.content.Context; +import android.hardware.camera2.CameraCharacteristics; +import android.hardware.camera2.CameraManager; +import android.support.v4.app.ActivityCompat; +import android.view.TextureView; + +public class QRScanner { + + private static final int CAM_REQUEST_CODE = 1; + + private Context context; + private TextureView textureView; + + private CameraManager cameraManager; + private int cameraFacing; + + + public QRScanner(Context context, TextureView textureView){ + this.context = context.getApplicationContext(); + this.textureView = textureView; + + Initialize(); + } + + private void Initialize(){ +// ActivityCompat.requestPermissions(, new String[]{Manifest.permission.CAMERA}, CAM_REQUEST_CODE); + +// cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); +// cameraFacing = CameraCharacteristics.LENS_FACING_BACK; + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/models/Organisation.java b/app/src/main/java/de/korrelator/overview/mispauthv2/models/Organisation.java new file mode 100644 index 0000000..d4a4702 --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/models/Organisation.java @@ -0,0 +1,94 @@ +package de.korrelator.overview.mispauthv2.models; + +import android.net.Uri; + +import org.json.JSONException; +import org.json.JSONObject; + +public class Organisation { + + private String name; + private String description; + private String nationality; + private String sector; + private String uuid; + private boolean local; + + + public Organisation(String name, boolean local, String description, String nationality, String sector, String uuid){ + this.name = name; + this.description = description; + this.nationality = nationality; + this.sector = sector; + this.uuid = uuid; + this.local = local; + } + + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getSector() { + return sector; + } + + public String getUuid() { + return uuid; + } + + public boolean isLocal() { + return local; + } + + + public JSONObject toJSON(){ + JSONObject organisation = new JSONObject(); + + try { + + organisation.put("local", local); + + if(!name.equals("")){ + organisation.put("name", Uri.decode(name)); + } + + if(!description.equals("")){ + organisation.put("description", Uri.decode(description)); + } + + if(!nationality.equals("")){ + organisation.put("nationality", Uri.decode(nationality)); + } + + if(!sector.equals("")){ + organisation.put("sector", Uri.decode(sector)); + } + + if(!uuid.equals("")){ + organisation.put("uuid", Uri.decode(uuid)); + } + + + } catch (JSONException e) { + e.printStackTrace(); + } + + return organisation; + } + + public static Organisation fromJSON(JSONObject json){ + return new OrganisationBuilder() + .name(json.optString("name", "")) + .local(json.optBoolean("local", true)) + .description(json.optString("description", "")) + .nationality(json.optString("nationality", "")) + .sector(json.optString("sector", "")) + .uuid(json.optString("uuid", "")) + .build(); + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/models/OrganisationBuilder.java b/app/src/main/java/de/korrelator/overview/mispauthv2/models/OrganisationBuilder.java new file mode 100644 index 0000000..5d65847 --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/models/OrganisationBuilder.java @@ -0,0 +1,47 @@ +package de.korrelator.overview.mispauthv2.models; + +public class OrganisationBuilder { + + private String name = "Default Org"; + private boolean local = true; + private String description = ""; + private String nationality = ""; + private String sector = ""; + private String uuid = ""; + + public OrganisationBuilder() {} + + public Organisation build(){ + return new Organisation(name, local, description, nationality, sector, uuid); + } + + public OrganisationBuilder name(String name){ + this.name = name; + return this; + } + + public OrganisationBuilder local(boolean local){ + this.local = local; + return this; + } + + public OrganisationBuilder description(String description){ + this.description = description; + return this; + } + + public OrganisationBuilder nationality(String nationality){ + this.nationality = nationality; + return this; + } + + public OrganisationBuilder sector(String sector){ + this.sector = sector; + return this; + } + + public OrganisationBuilder uuid(String uuid){ + this.uuid = uuid; + return this; + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/models/Server.java b/app/src/main/java/de/korrelator/overview/mispauthv2/models/Server.java new file mode 100644 index 0000000..978a5ed --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/models/Server.java @@ -0,0 +1,77 @@ +package de.korrelator.overview.mispauthv2.models; + +import android.support.annotation.NonNull; + +import org.json.JSONException; +import org.json.JSONObject; + +public class Server { + + private String url; + private String name; + private String organisationType; + private String authKey; + + + public Server(String url, String name, String organisationType, String authKey) { + this.url = url; + this.name = name; + this.organisationType = organisationType; + this.authKey = authKey; + } + + + public String getUrl() { + return url; + } + + public String getName() { + return name; + } + + public String getOrganisationType() { + return organisationType; + } + + public String getAuthKey() { + return authKey; + } + + + public JSONObject toJSON(){ + + JSONObject server = new JSONObject(); + + try { + + if(!url.equals("")){ + server.put("url", url); + } + + if(!name.equals("")){ + server.put("name", name); + } + + if(!organisationType.equals("")){ + server.put("organisation_type", organisationType); + } + + if(!authKey.equals("")){ + server.put("authkey", authKey); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + + return server; + } + + public static Server fromJSON(JSONObject json){ + return new Server( + json.optString("url", ""), + json.optString("name", ""), + json.optString("organisation_type", ""), + json.optString("authkey", "")); + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/models/ServerBuilder.java b/app/src/main/java/de/korrelator/overview/mispauthv2/models/ServerBuilder.java new file mode 100644 index 0000000..21edd33 --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/models/ServerBuilder.java @@ -0,0 +1,35 @@ +package de.korrelator.overview.mispauthv2.models; + +public class ServerBuilder { + + private String url = ""; + private String name = ""; + private String organisationType = ""; + private String authKey = ""; + + public ServerBuilder() {} + + public Server build(){ + return new Server(url, name, organisationType, authKey); + } + + public ServerBuilder url(String url){ + this.url = url; + return this; + } + + public ServerBuilder name(String name){ + this.name = name; + return this; + } + + public ServerBuilder organisationType(String organisationType){ + this.organisationType = organisationType; + return this; + } + + public ServerBuilder authKey(String authKey){ + this.authKey = authKey; + return this; + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/models/User.java b/app/src/main/java/de/korrelator/overview/mispauthv2/models/User.java new file mode 100644 index 0000000..b22cfde --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/models/User.java @@ -0,0 +1,80 @@ +package de.korrelator.overview.mispauthv2.models; + +import org.json.JSONException; +import org.json.JSONObject; + +public class User { + + private String email; + private int orgID; + private int roleType; + private String authKey; + + + public User(String email, int orgID, int roleType, String authKey) { + this.email = email; + this.orgID = orgID; + this.roleType = roleType; + this.authKey = authKey; + } + + + public String getEmail() { + return email; + } + + public int getOrgID() { + return orgID; + } + + public int getRoleType() { + return roleType; + } + + public String getAuthKey() { + return authKey; + } + + + public JSONObject toJSON(){ + JSONObject user = new JSONObject(); + + try { + + if(!email.equals("")){ + user.put("email", email); + } + + if(orgID > -1){ + user.put("org_id", orgID); + } + + if(roleType > -1){ + user.put("role_id", roleType); + } + + if(!authKey.equals("")){ + user.put("authkey", authKey); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + + return user; + } + + public static User fromJSON(JSONObject json){ + return new User( + json.optString("name", ""), + json.optInt("org_id", -1), + json.optInt("role_id", -1), + json.optString("authkey", "")); + } + + + public interface RoleType{ + int ADMIN = 0; + int SYNC_USER = 5; + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/models/UserBuilder.java b/app/src/main/java/de/korrelator/overview/mispauthv2/models/UserBuilder.java new file mode 100644 index 0000000..ee2f918 --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/models/UserBuilder.java @@ -0,0 +1,35 @@ +package de.korrelator.overview.mispauthv2.models; + +public class UserBuilder { + + private String email = "default@email.bar"; + private int orgID = -1; + private int roleType = -1; + private String authKey = ""; + + public UserBuilder(){} + + public User build(){ + return new User(email, orgID, roleType, authKey); + } + + public UserBuilder email(String email){ + this.email = email; + return this; + } + + public UserBuilder orgID(int orgID){ + this.orgID = orgID; + return this; + } + + public UserBuilder roleType(int roleType){ + this.roleType = roleType; + return this; + } + + public UserBuilder authKey(String authKey){ + this.authKey = authKey; + return this; + } +} diff --git a/app/src/main/java/de/korrelator/overview/mispauthv2/network/MispRequests.java b/app/src/main/java/de/korrelator/overview/mispauthv2/network/MispRequests.java new file mode 100644 index 0000000..500e040 --- /dev/null +++ b/app/src/main/java/de/korrelator/overview/mispauthv2/network/MispRequests.java @@ -0,0 +1,269 @@ +package de.korrelator.overview.mispauthv2.network; + +import android.content.Context; +import android.support.annotation.Nullable; + +import com.android.volley.AuthFailureError; +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.JsonArrayRequest; +import com.android.volley.toolbox.JsonObjectRequest; +import com.android.volley.toolbox.Volley; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import de.korrelator.overview.mispauthv2.R; + +public class MispRequests { + + private Context context; + private RequestQueue queue; + private String baseURL; + + + public MispRequests(Context context, String baseURL){ + + this.context = context.getApplicationContext(); + this.baseURL = baseURL; + + queue = Volley.newRequestQueue(this.context); + } + + + public void GetSyncUsers(final GetSyncUsersResponse resp){ + + String currentURL = baseURL + "/admin/users"; + + Response.Listener responseListener = new Response.Listener() { + @Override + public void onResponse(JSONArray response) { + + int userCount = response.length(); + + List userIDList = new ArrayList<>(); + + for(int i = 0; i < userCount; i++){ + try{ + JSONObject root = response.getJSONObject(i); + JSONObject role = root.getJSONObject("Role"); + JSONObject user = root.getJSONObject("User"); + + if(role.getInt("id") == 5){ + userIDList.add(user.getInt("id")); + } + + } catch (JSONException e){ + e.printStackTrace(); + } + } + + resp.result(userIDList.toArray(new Integer[userIDList.size()])); + } + }; + + Response.ErrorListener errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + resp.error(error); + } + }; + + queue.add(arrayRequest(Request.Method.GET, currentURL, null, responseListener, errorListener)); + } + + public void AddUser(JSONObject body, final AddUserResponse resp){ + + String currentURL = baseURL + "/admin/users/add"; + + Response.Listener responseListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + try { + JSONObject user = response.getJSONObject("User"); + resp.result(user.getInt("id"), user.getString("authkey")); + } catch (JSONException e){ + e.printStackTrace(); + } + } + }; + + Response.ErrorListener errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + resp.error(error); + } + }; + + queue.add(objectRequest(Request.Method.POST, currentURL, body, responseListener, errorListener)); + } + + public void EditUser(int userID, JSONObject body, final EditUserResponse resp){ + String currentURL = baseURL + "/admin/users/edit/" + userID; + + Response.Listener responseListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + resp.result(response); + } + }; + + Response.ErrorListener errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + resp.error(error); + } + }; + + queue.add(objectRequest(Request.Method.POST, currentURL, body, responseListener, errorListener)); + } + + public void AddOrganisation(JSONObject body, final AddOrganisationResponse response){ + + String currentURL = baseURL + "/admin/organisations/add"; + + Response.Listener responseListener = new Response.Listener() { + @Override + public void onResponse(JSONObject resp) { + try { + JSONObject org = resp.getJSONObject("Organisation"); + response.result(org.getInt("id")); + } catch (JSONException e){ + e.printStackTrace(); + } + } + }; + + Response.ErrorListener errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + response.error(error); + } + }; + + queue.add(objectRequest(Request.Method.POST, currentURL, body, responseListener, errorListener)); + } + + public void EditOrganisation(int orgID, JSONObject updateBody, final EditOrganisationResponse resp){ + + String currentURL = baseURL + "/admin/organisations/edit/" + orgID; + + Response.Listener responseListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + resp.result(true); + } + }; + + Response.ErrorListener errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + resp.error(error); + } + }; + + queue.add(objectRequest(Request.Method.POST, currentURL, updateBody, responseListener, errorListener)); + } + + public void AddServer(JSONObject body, final AddServerResponse resp){ + String currentURL = baseURL + "/servers/add"; + + Response.Listener responseListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + resp.result(response); + } + }; + + Response.ErrorListener errorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + resp.error(error); + } + }; + + queue.add(objectRequest(Request.Method.POST, currentURL, body, responseListener, errorListener)); + } + + + private JsonObjectRequest objectRequest(int method, String url, @Nullable JSONObject body, Response.Listener listener, Response.ErrorListener errorListener){ + return new JsonObjectRequest( + method, + url, + body, + listener, + errorListener) { + + @Override + public Map getHeaders() throws AuthFailureError { + Map params = new HashMap<>(); + + params.put("Authorization", context.getString(R.string.api_key)); + params.put("Accept", "application/json"); + params.put("Content-Type", "application/json; utf-8"); + + return params; + } + }; + } + + private JsonArrayRequest arrayRequest(int method, String url, @Nullable JSONArray body, Response.Listener listener, Response.ErrorListener errorListener){ + return new JsonArrayRequest( + method, + url, + body, + listener, + errorListener){ + + @Override + public Map getHeaders() throws AuthFailureError { + Map params = new HashMap<>(); + + params.put("Authorization", context.getString(R.string.api_key)); + params.put("Accept", "application/json"); + params.put("Content-Type", "application/json; utf-8"); + + return params; + } + }; + } + + + public interface GetSyncUsersResponse{ + void result(Integer[] userIDs); + void error(VolleyError volleyError); + } + + public interface AddOrganisationResponse{ + void result(int orgID); + void error(VolleyError error); + } + + public interface EditOrganisationResponse{ + void result(boolean success); + void error(VolleyError volleyError); + } + + public interface AddUserResponse { + void result(int id, String authKey); + void error(VolleyError volleyError); + } + + public interface EditUserResponse{ + void result(JSONObject msg); + void error(VolleyError volleyError); + } + + public interface AddServerResponse{ + void result(JSONObject result); + void error(VolleyError volleyError); + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_action_name.png b/app/src/main/res/drawable-hdpi/ic_action_name.png new file mode 100644 index 0000000000000000000000000000000000000000..895c2ec88f634a5f90ad9b2e88eceed6d7c0de27 GIT binary patch literal 362 zcmV-w0hRuVP)ST5CCaN;lc$AP_YOrAu$9CumeRVfC7mEMeIc0(nlheF~J1lcmAbo;A8%x2OASb z92^`R-o`x7DNq4DFxhYzd)lDKYo|wwZ$G%uSpqLwCkeElJP=S+E&_Vn3^p9bA2xVv zr|956qy|g?v4+F=!a|};d_zE7`0x-czycu%z;9v&DFMjKfC6ZM4r%aM=B)snzX2sM zS|+3sb8e>#?37i-*E?p`dQ0N!MPIp6=mRmGD}5AIFBv0#3wj!KZ_3HtmVHYcDMdHUc^_qH+7J;1ZR63)mrFheY_ZGx4ba zg|gHIzeaxbmjZaVfc+3wyN2u!(a%4{?Qd8^0DDWu-jwpT<;@;vFB{dK%0(eo@Bjb+ M07*qoM6N<$g3L{7)Bpeg literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable-xhdpi/ic_action_name.png b/app/src/main/res/drawable-xhdpi/ic_action_name.png new file mode 100644 index 0000000000000000000000000000000000000000..811f793ca14d3d3cb81683d1385a006226527859 GIT binary patch literal 437 zcmV;m0ZRUfP)U5JeF!CkQP!Nx=a)21TmW6mSDhlW>5g2zO$~l2<}2987Qo#_vnNK^`%F*n@33 ziV#8wA%qq*j$8`2m}BC00000 z0Kg#tiA{8}rMS{A^|R!(03;?A*9-fKUbjh41wh&t;-3{uSk<;T1ONvBZyVO~H{TCY zijA9@VeLpbQs>i!VgD4j+RugQkopLqHgxDAzKY{X+gLw)7-DMQI-eM-z3SlQP29x* zq2Kb0Jj|j*ePxT-t1pYMcbzB=b3V3+jSV%S^a(&U(}8wHd^;0g0e~q$5#%?>LWrd> zn<4KY_`Mwt{y>ByF%CsJ76$+T00000gbX0~OH#pKlMDW$WY||_C-X4O%hLZwLYUX( f5kd$dbV~gKGWK*>4L7B#00000NkvXXu0mjf(xkCP literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_name.png b/app/src/main/res/drawable-xxhdpi/ic_action_name.png new file mode 100644 index 0000000000000000000000000000000000000000..41734928e480574c8f00ff492bac4d3c9a63d7a5 GIT binary patch literal 736 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7Ro>U|R0!;uunK>+M|IzC#8AZqCgC zTv9B&xm-tB1;S4XzQ}kW^5qR{&;=*%e>C-nf}Qxr=3+bXFOILRuI@6gVcoAfZ>r#zS&Tbc zCmvhyRQX5uB<)~#hWa>*<^^ZZty$D{Mf5;q@}&aCgn+WmpVb&H&ESb)m=PAyX~pbe zTgsTg+Rz@ili|afpO&5bkM7=6R`72()4yw0b~$ZK=l3u8!lGQLzFu}t{qhFowTrjc zZ{R#|&Q-wnUPalKKA?}$fd$KgVjOZxdmdRVBJ{DEVRBF7pNl_VHt#$4=`N?>{`Xn8 zzLfdhdfs1Jw{3Obm%T>}GXL!_zoPyroT0dTfvo9?wdzl|d@*+K{`Ab{Use0=?HvC! zoM$R?bNpWQZpLf2gq(|Sj#!@R)t$B2kl{?{KF@h)l5_inf}P$jXWzfDIpchjh`5Hm z*_6FszBL@>-ul0D;c7`y4SS=Kz{&ml_+CW(J2v6dUEP4X>l04TlH1M8z;J=3Q1F?O zkNFg7!@MIBT?qz#2QBm&B>L(YIebo3upOB4gxet@=pU=XglS0}0-cdd)F#dHDAIfR za>??~4Q%}ymhT(T!x+dvuxaW!#tj9lpSMOw?z-{$(ovmzZ!16MO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..5a41dab --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,33 @@ + + + +