mirror of https://github.com/MISP/misp-bump
				
				
				
			improved error handling, added server model, added server request
							parent
							
								
									3ee88a028e
								
							
						
					
					
						commit
						b7111a47d8
					
				| 
						 | 
					@ -114,7 +114,7 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			||||||
		a.setDescription("Ferrari has nothing to share");
 | 
							a.setDescription("Ferrari has nothing to share");
 | 
				
			||||||
		a.setSector("Fast cars");
 | 
							a.setSector("Fast cars");
 | 
				
			||||||
		a.setNationality("Italy");
 | 
							a.setNationality("Italy");
 | 
				
			||||||
		a.setLocal(false);
 | 
							a.setLocal(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		externalOrganisations = new Organisation[]{a};
 | 
							externalOrganisations = new Organisation[]{a};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -163,7 +163,7 @@ public class SettingsActivity extends AppCompatActivity {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            	int orgID = user.getOrgId();
 | 
					            	int orgID = user.getOrgId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                request.OrganisationInformation(orgID, new MispRequest.OrganisationCallback() {
 | 
					                request.getOrganisation(orgID, new MispRequest.OrganisationCallback() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                	@Override
 | 
					                	@Override
 | 
				
			||||||
                    public void onResult(JSONObject organisationInformation) {
 | 
					                    public void onResult(JSONObject organisationInformation) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,24 +4,42 @@ import android.support.v7.app.AppCompatActivity;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
import com.android.volley.VolleyError;
 | 
					import com.android.volley.VolleyError;
 | 
				
			||||||
import de.overview.wg.its.mispauth.R;
 | 
					import de.overview.wg.its.mispauth.R;
 | 
				
			||||||
 | 
					import de.overview.wg.its.mispauth.auxiliary.PreferenceManager;
 | 
				
			||||||
import de.overview.wg.its.mispauth.model.Organisation;
 | 
					import de.overview.wg.its.mispauth.model.Organisation;
 | 
				
			||||||
import de.overview.wg.its.mispauth.network.MispRequest;
 | 
					import de.overview.wg.its.mispauth.network.MispRequest;
 | 
				
			||||||
import org.json.JSONObject;
 | 
					import org.json.JSONObject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SyncActivity extends AppCompatActivity {
 | 
					public class SyncActivity extends AppCompatActivity {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private PreferenceManager preferenceManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
						protected void onCreate(Bundle savedInstanceState) {
 | 
				
			||||||
		super.onCreate(savedInstanceState);
 | 
							super.onCreate(savedInstanceState);
 | 
				
			||||||
		setContentView(R.layout.activity_sync);
 | 
							setContentView(R.layout.activity_sync);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							preferenceManager = PreferenceManager.Instance(this);
 | 
				
			||||||
 | 
							uploadOrganisation(preferenceManager.getMyOrganisation());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private void uploadOrganisation(Organisation org) {
 | 
						private void uploadOrganisation(Organisation org) {
 | 
				
			||||||
		MispRequest mispRequest = MispRequest.Instance(this);
 | 
							MispRequest mispRequest = MispRequest.Instance(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		mispRequest.addOrganisation(org, new MispRequest.OrganisationCallback() {
 | 
					//		mispRequest.addOrganisation(org, new MispRequest.OrganisationCallback() {
 | 
				
			||||||
 | 
					//			@Override
 | 
				
			||||||
 | 
					//			public void onResult(JSONObject organisationInformation) {
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//			}
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//			@Override
 | 
				
			||||||
 | 
					//			public void onError(VolleyError volleyError) {
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//			}
 | 
				
			||||||
 | 
					//		});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							mispRequest.getServers(new MispRequest.ServerCallback() {
 | 
				
			||||||
			@Override
 | 
								@Override
 | 
				
			||||||
			public void onResult(JSONObject organisationInformation) {
 | 
								public void onResult(JSONObject servers) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ package de.overview.wg.its.mispauth.auxiliary;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.android.volley.AuthFailureError;
 | 
					import com.android.volley.AuthFailureError;
 | 
				
			||||||
import com.android.volley.NoConnectionError;
 | 
					import com.android.volley.NoConnectionError;
 | 
				
			||||||
 | 
					import com.android.volley.ServerError;
 | 
				
			||||||
import com.android.volley.VolleyError;
 | 
					import com.android.volley.VolleyError;
 | 
				
			||||||
import org.json.JSONException;
 | 
					import org.json.JSONException;
 | 
				
			||||||
import org.json.JSONObject;
 | 
					import org.json.JSONObject;
 | 
				
			||||||
| 
						 | 
					@ -35,8 +36,10 @@ public class ReadableError {
 | 
				
			||||||
			return "Connection failed";
 | 
								return "Connection failed";
 | 
				
			||||||
		} else if (volleyError instanceof AuthFailureError) {
 | 
							} else if (volleyError instanceof AuthFailureError) {
 | 
				
			||||||
			return "Authentication failed";
 | 
								return "Authentication failed";
 | 
				
			||||||
 | 
							} else if (volleyError instanceof ServerError) {
 | 
				
			||||||
 | 
								return "Server error";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return "Unknown error";
 | 
							return volleyError.toString();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					package de.overview.wg.its.mispauth.model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Server {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,7 @@ import com.android.volley.VolleyError;
 | 
				
			||||||
import com.android.volley.toolbox.JsonObjectRequest;
 | 
					import com.android.volley.toolbox.JsonObjectRequest;
 | 
				
			||||||
import com.android.volley.toolbox.Volley;
 | 
					import com.android.volley.toolbox.Volley;
 | 
				
			||||||
import de.overview.wg.its.mispauth.auxiliary.PreferenceManager;
 | 
					import de.overview.wg.its.mispauth.auxiliary.PreferenceManager;
 | 
				
			||||||
 | 
					import de.overview.wg.its.mispauth.auxiliary.ReadableError;
 | 
				
			||||||
import de.overview.wg.its.mispauth.model.Organisation;
 | 
					import de.overview.wg.its.mispauth.model.Organisation;
 | 
				
			||||||
import org.json.JSONException;
 | 
					import org.json.JSONException;
 | 
				
			||||||
import org.json.JSONObject;
 | 
					import org.json.JSONObject;
 | 
				
			||||||
| 
						 | 
					@ -47,7 +48,7 @@ public class MispRequest {
 | 
				
			||||||
	 * @param orgId    organisation ID on the MISP-Instance
 | 
						 * @param orgId    organisation ID on the MISP-Instance
 | 
				
			||||||
	 * @param callback returns a single Organisation-JSON
 | 
						 * @param callback returns a single Organisation-JSON
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void OrganisationInformation(int orgId, final OrganisationCallback callback) {
 | 
						public void getOrganisation(int orgId, final OrganisationCallback callback) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
 | 
							Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
 | 
				
			||||||
			@Override
 | 
								@Override
 | 
				
			||||||
| 
						 | 
					@ -162,6 +163,31 @@ public class MispRequest {
 | 
				
			||||||
		requestQueue.add(r);
 | 
							requestQueue.add(r);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public void getServers(ServerCallback callback) {
 | 
				
			||||||
 | 
							Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
 | 
				
			||||||
 | 
								@Override
 | 
				
			||||||
 | 
								public void onResponse(JSONObject response) {
 | 
				
			||||||
 | 
									Log.d(TAG, "onResponse: " + response.toString());
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Response.ErrorListener errorListener = new Response.ErrorListener() {
 | 
				
			||||||
 | 
								@Override
 | 
				
			||||||
 | 
								public void onErrorResponse(VolleyError error) {
 | 
				
			||||||
 | 
									Log.d(TAG, "onErrorResponse: " + ReadableError.toReadable(error));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Request r = objectRequest(
 | 
				
			||||||
 | 
									Request.Method.GET,
 | 
				
			||||||
 | 
									serverUrl + "/servers/view/",
 | 
				
			||||||
 | 
									null,
 | 
				
			||||||
 | 
									listener,
 | 
				
			||||||
 | 
									errorListener);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							requestQueue.add(r);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private JsonObjectRequest objectRequest(int method,
 | 
						private JsonObjectRequest objectRequest(int method,
 | 
				
			||||||
	                                        String url,
 | 
						                                        String url,
 | 
				
			||||||
| 
						 | 
					@ -205,16 +231,18 @@ public class MispRequest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void onError(VolleyError volleyError);
 | 
							void onError(VolleyError volleyError);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	public interface OrganisationCallback {
 | 
						public interface OrganisationCallback {
 | 
				
			||||||
		void onResult(JSONObject organisationInformation);
 | 
							void onResult(JSONObject organisationInformation);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void onError(VolleyError volleyError);
 | 
							void onError(VolleyError volleyError);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	public interface UserCallback {
 | 
						public interface UserCallback {
 | 
				
			||||||
		void onResult(JSONObject myOrganisationInformation);
 | 
							void onResult(JSONObject myOrganisationInformation);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void onError(VolleyError volleyError);
 | 
							void onError(VolleyError volleyError);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						public interface ServerCallback {
 | 
				
			||||||
 | 
							void onResult(JSONObject servers);
 | 
				
			||||||
 | 
							void onError(VolleyError volleyError);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue