Commit f2f0b0141dda51a72d0b6a0839774b336158bc04

Authored by Ali B
2 parents 93215e20 d5a14569

Merge branch 'api_fixes'

Risiko/.idea/caches/build_file_checksums.ser
No preview for this file type
Risiko/app/src/main/java/activity/Activities.java
@@ -61,12 +61,12 @@ public class Activities extends AppCompatActivity { @@ -61,12 +61,12 @@ public class Activities extends AppCompatActivity {
61 lv.setAdapter(new ListAdapterActivities(this, activities)); 61 lv.setAdapter(new ListAdapterActivities(this, activities));
62 lv.setOnItemClickListener((parent, view, position, id) -> { 62 lv.setOnItemClickListener((parent, view, position, id) -> {
63 String nameOfChosenActivity = ((Activity) lv.getItemAtPosition(position)).getTitle(); 63 String nameOfChosenActivity = ((Activity) lv.getItemAtPosition(position)).getTitle();
64 - int activityId = ((Activity) lv.getItemAtPosition(position)).getId(); 64 + String activityId = ((Activity) lv.getItemAtPosition(position)).getId();
65 goToChosenActivity(nameOfChosenActivity, activityId); 65 goToChosenActivity(nameOfChosenActivity, activityId);
66 }); 66 });
67 } 67 }
68 68
69 - private void goToChosenActivity(String nameOfChosenActivity, int activityId) { 69 + private void goToChosenActivity(String nameOfChosenActivity, String activityId) {
70 Intent intent = new Intent(this, Evaluations.class); 70 Intent intent = new Intent(this, Evaluations.class);
71 intent.putExtra("NAME_OF_CHOSEN_ACTIVITY", nameOfChosenActivity); 71 intent.putExtra("NAME_OF_CHOSEN_ACTIVITY", nameOfChosenActivity);
72 intent.putExtra("ID_OF_CHOSEN_ACTIVITY", activityId); 72 intent.putExtra("ID_OF_CHOSEN_ACTIVITY", activityId);
Risiko/app/src/main/java/activity/Evaluations.java
@@ -41,7 +41,7 @@ public class Evaluations extends AppCompatActivity { @@ -41,7 +41,7 @@ public class Evaluations extends AppCompatActivity {
41 41
42 Intent intent = getIntent(); 42 Intent intent = getIntent();
43 String activityName = intent.getStringExtra("NAME_OF_CHOSEN_ACTIVITY"); 43 String activityName = intent.getStringExtra("NAME_OF_CHOSEN_ACTIVITY");
44 - int activityId = intent.getIntExtra("ID_OF_CHOSEN_ACTIVITY", -1); 44 + String activityId = intent.getStringExtra("ID_OF_CHOSEN_ACTIVITY");
45 System.out.println(activityId); 45 System.out.println(activityId);
46 46
47 //TESTING AV RETROFIT: FUNKER KUN VED Å BRUKE DELING AV MOBILNETT 47 //TESTING AV RETROFIT: FUNKER KUN VED Å BRUKE DELING AV MOBILNETT
@@ -53,12 +53,16 @@ public class Evaluations extends AppCompatActivity { @@ -53,12 +53,16 @@ public class Evaluations extends AppCompatActivity {
53 if (response.isSuccessful()) { 53 if (response.isSuccessful()) {
54 List<Evaluation> evaluations = response.body(); 54 List<Evaluation> evaluations = response.body();
55 List<Evaluation> associatedEvaluations = new ArrayList<>(); 55 List<Evaluation> associatedEvaluations = new ArrayList<>();
56 - for (Evaluation e : evaluations) {  
57 - System.out.println(e.getAssociatedactivity());  
58 - if (e.getAssociatedactivity() == activityId)  
59 - associatedEvaluations.add(e); 56 +
  57 + if (evaluations != null) {
  58 + for (Evaluation e : evaluations) {
  59 + System.out.println(e.getAssociatedactivity());
  60 + System.out.println(e.getTitle());
  61 + if (e.getAssociatedactivity().equals(activityId))
  62 + associatedEvaluations.add(e);
  63 + }
60 } 64 }
61 - insertEvaluations(associatedEvaluations); 65 + insertEvaluations(associatedEvaluations);
62 } 66 }
63 } 67 }
64 68
Risiko/app/src/main/java/activity/Incident.java
@@ -24,7 +24,7 @@ import retrofit2.Response; @@ -24,7 +24,7 @@ import retrofit2.Response;
24 24
25 public class Incident extends AppCompatActivity { 25 public class Incident extends AppCompatActivity {
26 ListView lv; 26 ListView lv;
27 - int chosenEventId; 27 + String chosenEventId;
28 DatabaseSource dbs; 28 DatabaseSource dbs;
29 29
30 @Override 30 @Override
@@ -34,9 +34,9 @@ public class Incident extends AppCompatActivity { @@ -34,9 +34,9 @@ public class Incident extends AppCompatActivity {
34 34
35 dbs = new DatabaseSource(this); 35 dbs = new DatabaseSource(this);
36 36
37 - ArrayList<dataclasses.Incident> incidentList = new ArrayList<>();  
38 - dbs.getAllIncidents(incidentList);  
39 - insertEvents(incidentList); 37 +// ArrayList<dataclasses.Incident> incidentList = new ArrayList<>();
  38 +// dbs.getAllIncidents(incidentList);
  39 +// insertEvents(incidentList);
40 40
41 41
42 Api.get().getAllIncidents() 42 Api.get().getAllIncidents()
@@ -46,7 +46,8 @@ public class Incident extends AppCompatActivity { @@ -46,7 +46,8 @@ public class Incident extends AppCompatActivity {
46 public void onResponse(Call<List<dataclasses.Incident>> call, Response<List<dataclasses.Incident>> response) { 46 public void onResponse(Call<List<dataclasses.Incident>> call, Response<List<dataclasses.Incident>> response) {
47 if (response.isSuccessful()) { 47 if (response.isSuccessful()) {
48 List<dataclasses.Incident> incidents = response.body(); 48 List<dataclasses.Incident> incidents = response.body();
49 - insertEvents(incidents); 49 + if (incidents != null)
  50 + insertEvents(incidents);
50 } 51 }
51 } 52 }
52 53
Risiko/app/src/main/java/activity/NewEvaluation.java
@@ -11,6 +11,7 @@ import android.widget.Spinner; @@ -11,6 +11,7 @@ import android.widget.Spinner;
11 import com.risiko.risiko.R; 11 import com.risiko.risiko.R;
12 12
13 import java.util.HashMap; 13 import java.util.HashMap;
  14 +import java.util.UUID;
14 15
15 import api.Api; 16 import api.Api;
16 import database.DatabaseSource; 17 import database.DatabaseSource;
@@ -32,7 +33,7 @@ public class NewEvaluation extends AppCompatActivity { @@ -32,7 +33,7 @@ public class NewEvaluation extends AppCompatActivity {
32 setContentView(R.layout.activity_new_evaluation); 33 setContentView(R.layout.activity_new_evaluation);
33 34
34 Intent intent = getIntent(); 35 Intent intent = getIntent();
35 - int activityId = intent.getIntExtra("ID_OF_CHOSEN_ACTIVITY", -1); 36 + String activityId = intent.getStringExtra("ID_OF_CHOSEN_ACTIVITY");
36 37
37 dbs = new DatabaseSource(this); 38 dbs = new DatabaseSource(this);
38 etNewEvalTitle = findViewById(R.id.et_newEval_title); 39 etNewEvalTitle = findViewById(R.id.et_newEval_title);
@@ -53,7 +54,7 @@ public class NewEvaluation extends AppCompatActivity { @@ -53,7 +54,7 @@ public class NewEvaluation extends AppCompatActivity {
53 int consequenceValue = getConsequenceValue(consequence); 54 int consequenceValue = getConsequenceValue(consequence);
54 int probabilityValue = getProbabilityValue(probability); 55 int probabilityValue = getProbabilityValue(probability);
55 56
56 - Api.get().newEvaluation(title, (int) (Math.random()*1000000),activityId,consequenceValue,action,outcome,probabilityValue).enqueue(new Callback<String>() { 57 + Api.get().newEvaluation(title, UUID.randomUUID().toString() ,activityId,consequenceValue,action,outcome,probabilityValue).enqueue(new Callback<String>() {
57 @Override 58 @Override
58 public void onResponse(Call<String> call, Response<String> response) { 59 public void onResponse(Call<String> call, Response<String> response) {
59 System.out.println(response); 60 System.out.println(response);
Risiko/app/src/main/java/activity/NewIncident.java
@@ -2,15 +2,19 @@ package activity; @@ -2,15 +2,19 @@ package activity;
2 2
3 import android.support.v7.app.AppCompatActivity; 3 import android.support.v7.app.AppCompatActivity;
4 import android.os.Bundle; 4 import android.os.Bundle;
  5 +import android.util.Log;
5 import android.widget.ArrayAdapter; 6 import android.widget.ArrayAdapter;
6 import android.widget.Button; 7 import android.widget.Button;
7 import android.widget.EditText; 8 import android.widget.EditText;
8 import android.widget.Spinner; 9 import android.widget.Spinner;
  10 +import android.widget.Toast;
9 11
10 import com.risiko.risiko.R; 12 import com.risiko.risiko.R;
11 13
12 import java.util.ArrayList; 14 import java.util.ArrayList;
13 import java.util.HashMap; 15 import java.util.HashMap;
  16 +import java.util.List;
  17 +import java.util.UUID;
14 18
15 import api.Api; 19 import api.Api;
16 import database.DatabaseSource; 20 import database.DatabaseSource;
@@ -39,47 +43,72 @@ public class NewIncident extends AppCompatActivity { @@ -39,47 +43,72 @@ public class NewIncident extends AppCompatActivity {
39 btnNewIncident = findViewById(R.id.btn_newIncident); 43 btnNewIncident = findViewById(R.id.btn_newIncident);
40 dbs = new DatabaseSource(this); 44 dbs = new DatabaseSource(this);
41 45
42 - ArrayList<Evaluation> evaluations = new ArrayList<>();  
43 - dbs.getAllEvaluation(evaluations);  
44 - HashMap<String, Integer> evalMap = convertToDictionaryWithIdAndTitle(evaluations);  
45 -  
46 spinnerAssociatedRisk = findViewById(R.id.spinner_associated_risk); 46 spinnerAssociatedRisk = findViewById(R.id.spinner_associated_risk);
47 - ArrayAdapter<Object> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, evalMap.keySet().toArray());  
48 - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
49 - spinnerAssociatedRisk.setAdapter(adapter);  
50 -  
51 - btnNewIncident.setOnClickListener(view -> {  
52 - if (inputAccepted()) {  
53 - String title = etTitle.getText().toString();  
54 - String date = etDate.getText().toString();  
55 - String location = etLocation.getText().toString();  
56 - String description = etDescription.getText().toString();  
57 -  
58 - String associatedRiskTitle = spinnerAssociatedRisk.getSelectedItem().toString();  
59 - int associatedRisk = evalMap.get(associatedRiskTitle);  
60 -  
61 - dataclasses.Incident newIncident = new Incident(date, location, title, description, associatedRisk); 47 +// dbs.getAllEvaluation(evaluations);
62 48
  49 + Api.get().getAllEvaluations()
  50 + .enqueue(new Callback<List<Evaluation>>() {
63 51
64 - Api.get().newIncident(date, title, (int) (Math.random()*1000000), associatedRisk, description, location).enqueue(new Callback<String>() {  
65 @Override 52 @Override
66 - public void onResponse(Call<String> call, Response<String> response) {  
67 - System.out.println(response); 53 + public void onResponse(Call<List<dataclasses.Evaluation>> call, Response<List<dataclasses.Evaluation>> response) {
  54 + if (response.isSuccessful()) {
  55 + List<dataclasses.Evaluation> evaluations = response.body();
  56 + if (evaluations != null){
  57 + HashMap<String, String> evalMap = convertToDictionaryWithIdAndTitle(evaluations);
  58 + ArrayAdapter<Object> adapter = new ArrayAdapter<>(NewIncident.this, android.R.layout.simple_spinner_item, evalMap.keySet().toArray());
  59 + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  60 + spinnerAssociatedRisk.setAdapter(adapter);
  61 +
  62 + btnNewIncident.setOnClickListener(view -> {
  63 + if (inputAccepted()) {
  64 + String id = UUID.randomUUID().toString();
  65 + String title = etTitle.getText().toString();
  66 + String date = etDate.getText().toString();
  67 + String location = etLocation.getText().toString();
  68 + String description = etDescription.getText().toString();
  69 +
  70 + String associatedRiskTitle = spinnerAssociatedRisk.getSelectedItem().toString();
  71 + String associatedRisk = evalMap.get(associatedRiskTitle);
  72 +
  73 + dataclasses.Incident newIncident = new Incident(id, date, location, title, description, associatedRisk);
  74 +
  75 +
  76 + Api.get().newIncident(date, title, id, associatedRisk, description, location).enqueue(new Callback<String>() {
  77 + @Override
  78 + public void onResponse(Call<String> call, Response<String> response) {
  79 + System.out.println(response);
  80 + }
  81 +
  82 + @Override
  83 + public void onFailure(Call<String> call, Throwable t) {
  84 + t.printStackTrace();
  85 +
  86 + }
  87 + });
  88 +
  89 +
  90 + dbs.insertIncident(newIncident);
  91 + finish();
  92 + }
  93 + });
  94 +
  95 + } else {
  96 + Toast.makeText(NewIncident.this, "Fant ingen risikoer, for å lage en ny hendelse må den knyttes til en risiko",
  97 + Toast.LENGTH_LONG).show();
  98 + finish();
  99 + }
  100 + }
68 } 101 }
69 102
70 @Override 103 @Override
71 - public void onFailure(Call<String> call, Throwable t) {  
72 - t.printStackTrace();  
73 - 104 + public void onFailure(Call<List<dataclasses.Evaluation>> call, Throwable t) {
  105 + //Something went completely south (maybe you lost internet connection)
  106 + Toast.makeText(NewIncident.this, "Something went wrong",
  107 + Toast.LENGTH_LONG).show();
  108 + Log.d("Error", t.getMessage());
74 } 109 }
75 }); 110 });
76 111
77 -  
78 - dbs.insertIncident(newIncident);  
79 - finish();  
80 - }  
81 - });  
82 -  
83 } 112 }
84 113
85 private boolean inputAccepted() { 114 private boolean inputAccepted() {
@@ -91,8 +120,8 @@ public class NewIncident extends AppCompatActivity { @@ -91,8 +120,8 @@ public class NewIncident extends AppCompatActivity {
91 return true; 120 return true;
92 } 121 }
93 122
94 - private HashMap<String, Integer> convertToDictionaryWithIdAndTitle(ArrayList<Evaluation> evaluations) {  
95 - HashMap<String, Integer> evalMap = new HashMap<>(); 123 + private HashMap<String, String> convertToDictionaryWithIdAndTitle(List<Evaluation> evaluations) {
  124 + HashMap<String, String> evalMap = new HashMap<>();
96 for (Evaluation e : evaluations) { 125 for (Evaluation e : evaluations) {
97 evalMap.put(e.getTitle(), e.getId()); 126 evalMap.put(e.getTitle(), e.getId());
98 } 127 }
Risiko/app/src/main/java/api/Endpoints.java
@@ -3,6 +3,7 @@ package api; @@ -3,6 +3,7 @@ package api;
3 import java.util.Date; 3 import java.util.Date;
4 import java.util.HashMap; 4 import java.util.HashMap;
5 import java.util.List; 5 import java.util.List;
  6 +import java.util.UUID;
6 7
7 import dataclasses.Activity; 8 import dataclasses.Activity;
8 import dataclasses.Evaluation; 9 import dataclasses.Evaluation;
@@ -22,13 +23,13 @@ public interface Endpoints { @@ -22,13 +23,13 @@ public interface Endpoints {
22 23
23 24
24 // THE BASEURL HAS TO BE CHANGE TO THE IP-ADDRESS YOU ARE CONNECTED TO AT LOCALHOST 25 // THE BASEURL HAS TO BE CHANGE TO THE IP-ADDRESS YOU ARE CONNECTED TO AT LOCALHOST
25 - String BASEURL = "http://172.20.10.2:3000/"; 26 + String BASEURL = "http://172.20.10.4:3000/";
26 27
27 @GET("evaluation") 28 @GET("evaluation")
28 Call<List<Evaluation>> getAllEvaluations(); 29 Call<List<Evaluation>> getAllEvaluations();
29 30
30 @GET("evaluation/{id}") 31 @GET("evaluation/{id}")
31 - Call<List<Evaluation>> getEvaluation(@Path("id") int id); 32 + Call<List<Evaluation>> getEvaluation(@Path("id") String id);
32 33
33 @GET("activity") 34 @GET("activity")
34 Call<List<Activity>> getAllActivities(); 35 Call<List<Activity>> getAllActivities();
@@ -37,16 +38,16 @@ public interface Endpoints { @@ -37,16 +38,16 @@ public interface Endpoints {
37 Call<List<Incident>> getAllIncidents(); 38 Call<List<Incident>> getAllIncidents();
38 39
39 @GET("incident/{id}") 40 @GET("incident/{id}")
40 - Call<List<Incident>> getIncident(@Path("id") int id); 41 + Call<List<Incident>> getIncident(@Path("id") String id);
41 42
42 @FormUrlEncoded 43 @FormUrlEncoded
43 @POST("incident") 44 @POST("incident")
44 - Call<String> newIncident(@Field("date") String date, @Field("title") String title, @Field("id") int id, @Field("associatedEval") int associatedEval, 45 + Call<String> newIncident(@Field("date") String date, @Field("title") String title, @Field("id") String id, @Field("associatedEval") String associatedEval,
45 @Field("description") String description, @Field("location") String location); 46 @Field("description") String description, @Field("location") String location);
46 47
47 @FormUrlEncoded 48 @FormUrlEncoded
48 @POST("evaluation") 49 @POST("evaluation")
49 - Call<String> newEvaluation(@Field("title") String title, @Field("id") int id, @Field("associatedActivity") int associatedactivity, 50 + Call<String> newEvaluation(@Field("title") String title, @Field("id") String id, @Field("associatedActivity") String associatedactivity,
50 @Field("consequence") int consequence, @Field("measures") String measures, @Field("outcome") String outcome, @Field("probability") int probability); 51 @Field("consequence") int consequence, @Field("measures") String measures, @Field("outcome") String outcome, @Field("probability") int probability);
51 52
52 53
Risiko/app/src/main/java/database/DatabaseSource.java
@@ -6,6 +6,7 @@ import android.database.Cursor; @@ -6,6 +6,7 @@ import android.database.Cursor;
6 import android.database.sqlite.SQLiteDatabase; 6 import android.database.sqlite.SQLiteDatabase;
7 7
8 import java.util.ArrayList; 8 import java.util.ArrayList;
  9 +import java.util.UUID;
9 10
10 import dataclasses.Evaluation; 11 import dataclasses.Evaluation;
11 import dataclasses.Incident; 12 import dataclasses.Incident;
@@ -36,7 +37,8 @@ public class DatabaseSource { @@ -36,7 +37,8 @@ public class DatabaseSource {
36 37
37 public boolean insertIncident(Incident incident) { 38 public boolean insertIncident(Incident incident) {
38 ContentValues values = new ContentValues(); 39 ContentValues values = new ContentValues();
39 - values.put(IncidentTable.INCIDENT_COL_ASSOCIATED_EVALUATION, incident.getAssociatedeval()); 40 + values.put(IncidentTable.INCIDENT_COL_ID, incident.getId());
  41 + values.put(IncidentTable.INCIDENT_COL_ASSOCIATED_EVALUATION, incident.getAssociatedeval().toString());
40 values.put(IncidentTable.INCIDENT_COL_TITLE, incident.getTitle()); 42 values.put(IncidentTable.INCIDENT_COL_TITLE, incident.getTitle());
41 values.put(IncidentTable.INCIDENT_COL_DATE, incident.getDate().toString()); 43 values.put(IncidentTable.INCIDENT_COL_DATE, incident.getDate().toString());
42 values.put(IncidentTable.INCIDENT_COL_LOCATION, incident.getLocation()); 44 values.put(IncidentTable.INCIDENT_COL_LOCATION, incident.getLocation());
@@ -62,7 +64,7 @@ public class DatabaseSource { @@ -62,7 +64,7 @@ public class DatabaseSource {
62 database.close(); 64 database.close();
63 } 65 }
64 66
65 - public Evaluation getEvaluationById(int id) { 67 + public Evaluation getEvaluationById(String id) {
66 SQLiteDatabase database = helper.getWritableDatabase(); 68 SQLiteDatabase database = helper.getWritableDatabase();
67 Cursor cursor = database.rawQuery("select * from " + EvaluationTable.EVALUATION_TABLE + " where " + EvaluationTable.EVALUATION_COL_ID + " = " + " ?", new String[]{String.valueOf(id)}); 69 Cursor cursor = database.rawQuery("select * from " + EvaluationTable.EVALUATION_TABLE + " where " + EvaluationTable.EVALUATION_COL_ID + " = " + " ?", new String[]{String.valueOf(id)});
68 cursor.moveToFirst(); 70 cursor.moveToFirst();
@@ -72,7 +74,7 @@ public class DatabaseSource { @@ -72,7 +74,7 @@ public class DatabaseSource {
72 return new Evaluation(); 74 return new Evaluation();
73 } 75 }
74 76
75 - public void getAllEvaluationsForActivity(int activityId, ArrayList<Evaluation> listToUpdate) { 77 + public void getAllEvaluationsForActivity(String activityId, ArrayList<Evaluation> listToUpdate) {
76 SQLiteDatabase database = helper.getWritableDatabase(); 78 SQLiteDatabase database = helper.getWritableDatabase();
77 Cursor cursor = database.rawQuery("select * from " + EvaluationTable.EVALUATION_TABLE + " where " + EvaluationTable.EVALUATION_COL_ASSOCIATED_ACTIVITY + " = " + " ?", new String[]{String.valueOf(activityId)}); 79 Cursor cursor = database.rawQuery("select * from " + EvaluationTable.EVALUATION_TABLE + " where " + EvaluationTable.EVALUATION_COL_ASSOCIATED_ACTIVITY + " = " + " ?", new String[]{String.valueOf(activityId)});
78 cursor.moveToFirst(); 80 cursor.moveToFirst();
@@ -108,8 +110,8 @@ public class DatabaseSource { @@ -108,8 +110,8 @@ public class DatabaseSource {
108 int consequenceIndex = cursor.getColumnIndexOrThrow(EvaluationTable.EVALUATION_COL_CONSEQUENCE); 110 int consequenceIndex = cursor.getColumnIndexOrThrow(EvaluationTable.EVALUATION_COL_CONSEQUENCE);
109 int probabilityIndex = cursor.getColumnIndexOrThrow(EvaluationTable.EVALUATION_COL_PROBABILITY); 111 int probabilityIndex = cursor.getColumnIndexOrThrow(EvaluationTable.EVALUATION_COL_PROBABILITY);
110 112
111 - data.setId(cursor.getInt(idIndex));  
112 - data.setAssociatedactivity(cursor.getInt(associatedActivityIndex)); 113 + data.setId(cursor.getString(idIndex));
  114 + data.setAssociatedactivity(cursor.getString(associatedActivityIndex));
113 data.setTitle(cursor.getString(titleIndex)); 115 data.setTitle(cursor.getString(titleIndex));
114 data.setOutcome(cursor.getString(outcomeIndex)); 116 data.setOutcome(cursor.getString(outcomeIndex));
115 data.setMeasures(cursor.getString(actionIndex)); 117 data.setMeasures(cursor.getString(actionIndex));
@@ -128,8 +130,8 @@ public class DatabaseSource { @@ -128,8 +130,8 @@ public class DatabaseSource {
128 int locationIndex = cursor.getColumnIndexOrThrow(IncidentTable.INCIDENT_COL_LOCATION); 130 int locationIndex = cursor.getColumnIndexOrThrow(IncidentTable.INCIDENT_COL_LOCATION);
129 int descriptionIndex = cursor.getColumnIndexOrThrow(IncidentTable.INCIDENT_COL_DESCRIPTION); 131 int descriptionIndex = cursor.getColumnIndexOrThrow(IncidentTable.INCIDENT_COL_DESCRIPTION);
130 132
131 - data.setId(cursor.getInt(idIndex));  
132 - data.setAssociatedeval(cursor.getInt(associatedEvaluationIndex)); 133 + data.setId(cursor.getString(idIndex));
  134 + data.setAssociatedeval(cursor.getString(associatedEvaluationIndex));
133 data.setTitle(cursor.getString(titleIndex)); 135 data.setTitle(cursor.getString(titleIndex));
134 data.setDate(cursor.getString(dateIndex)); 136 data.setDate(cursor.getString(dateIndex));
135 data.setLocation(cursor.getString(locationIndex)); 137 data.setLocation(cursor.getString(locationIndex));
Risiko/app/src/main/java/database/EvaluationTable.java
@@ -15,8 +15,8 @@ public class EvaluationTable { @@ -15,8 +15,8 @@ public class EvaluationTable {
15 15
16 private static final String EVALUATION_TABLE_CREATE = 16 private static final String EVALUATION_TABLE_CREATE =
17 "CREATE TABLE IF NOT EXISTS " + EVALUATION_TABLE + " (" 17 "CREATE TABLE IF NOT EXISTS " + EVALUATION_TABLE + " ("
18 - + EVALUATION_COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "  
19 - + EVALUATION_COL_ASSOCIATED_ACTIVITY + " INTEGER, " 18 + + EVALUATION_COL_ID + " TEXT PRIMARY KEY, "
  19 + + EVALUATION_COL_ASSOCIATED_ACTIVITY + " TEXT, "
20 + EVALUATION_COL_TITLE + " TEXT, " 20 + EVALUATION_COL_TITLE + " TEXT, "
21 + EVALUATION_COL_OUTCOME + " TEXT, " 21 + EVALUATION_COL_OUTCOME + " TEXT, "
22 + EVALUATION_COL_ACTION + " TEXT, " 22 + EVALUATION_COL_ACTION + " TEXT, "
Risiko/app/src/main/java/database/IncidentTable.java
@@ -14,8 +14,8 @@ public class IncidentTable { @@ -14,8 +14,8 @@ public class IncidentTable {
14 14
15 private static final String INCIDENT_TABLE_CREATE = 15 private static final String INCIDENT_TABLE_CREATE =
16 "CREATE TABLE IF NOT EXISTS " + INCIDENT_TABLE + " (" 16 "CREATE TABLE IF NOT EXISTS " + INCIDENT_TABLE + " ("
17 - + INCIDENT_COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "  
18 - + INCIDENT_COL_ASSOCIATED_EVALUATION + " INTEGER, " 17 + + INCIDENT_COL_ID + " TEXT PRIMARY KEY, "
  18 + + INCIDENT_COL_ASSOCIATED_EVALUATION + " TEXT, "
19 + INCIDENT_COL_TITLE + " TEXT, " 19 + INCIDENT_COL_TITLE + " TEXT, "
20 + INCIDENT_COL_DATE + " TEXT, " 20 + INCIDENT_COL_DATE + " TEXT, "
21 + INCIDENT_COL_LOCATION + " TEXT, " 21 + INCIDENT_COL_LOCATION + " TEXT, "
Risiko/app/src/main/java/dataclasses/Activity.java
@@ -9,31 +9,30 @@ import java.util.UUID; @@ -9,31 +9,30 @@ import java.util.UUID;
9 9
10 public class Activity { 10 public class Activity {
11 11
12 - private UUID uuid;  
13 - private int id; 12 + private String id;
14 private String title; 13 private String title;
15 private ArrayList<Activity> allActivities; 14 private ArrayList<Activity> allActivities;
16 15
17 public Activity(String title) { 16 public Activity(String title) {
18 allActivities = new ArrayList<>(); 17 allActivities = new ArrayList<>();
19 this.title = title; 18 this.title = title;
20 - uuid = UUID.randomUUID();  
21 } 19 }
22 20
23 - public Activity(int id, String name) { 21 + public Activity(String id, String name) {
24 this.id = id; 22 this.id = id;
25 allActivities = new ArrayList<>(); 23 allActivities = new ArrayList<>();
26 this.title = name; 24 this.title = name;
27 } 25 }
28 26
29 - public int getId() { 27 + public String getId() {
30 return id; 28 return id;
31 } 29 }
32 30
33 - public void setId(int id) { 31 + public void setId(String id) {
34 this.id = id; 32 this.id = id;
35 } 33 }
36 34
  35 +
37 public String getTitle() { 36 public String getTitle() {
38 return title; 37 return title;
39 } 38 }
Risiko/app/src/main/java/dataclasses/Evaluation.java
@@ -11,42 +11,39 @@ public class Evaluation { @@ -11,42 +11,39 @@ public class Evaluation {
11 public static final int CONSEQUENCE_HARMLESS = 1, CONSEQUENCE_MODERATE = 2, CONSEQUENCE_SEVERE = 3; 11 public static final int CONSEQUENCE_HARMLESS = 1, CONSEQUENCE_MODERATE = 2, CONSEQUENCE_SEVERE = 3;
12 public static final int PROBABILITY_LOW = 1, PROBABILITY_MEDIUM = 2, PROBABILITY_HIGH = 3; 12 public static final int PROBABILITY_LOW = 1, PROBABILITY_MEDIUM = 2, PROBABILITY_HIGH = 3;
13 13
14 - UUID uuid;  
15 - int id;  
16 - int associatedactivity; 14 + String id;
  15 + String associatedactivity;
17 String title; 16 String title;
18 String outcome; 17 String outcome;
19 String measures; 18 String measures;
20 int consequence; 19 int consequence;
21 int probability; 20 int probability;
22 21
23 - public Evaluation() {  
24 - uuid = UUID.randomUUID();  
25 - } 22 + public Evaluation() { }
26 23
27 - public Evaluation(int associatedactivity, String title, String outcome, String measures, int consequence, int probability) { 24 + public Evaluation(String associatedactivity, String title, String outcome, String measures, int consequence, int probability) {
28 this.title = title; 25 this.title = title;
29 this.associatedactivity = associatedactivity; 26 this.associatedactivity = associatedactivity;
30 this.outcome = outcome; 27 this.outcome = outcome;
31 this.measures = measures; 28 this.measures = measures;
32 this.consequence = consequence; 29 this.consequence = consequence;
33 this.probability = probability; 30 this.probability = probability;
34 - uuid = UUID.randomUUID();  
35 } 31 }
36 32
37 - public int getId() { 33 + public String getId() {
38 return id; 34 return id;
39 } 35 }
40 36
41 - public void setId(int id) { 37 + public void setId(String id) {
42 this.id = id; 38 this.id = id;
43 } 39 }
44 40
45 - public int getAssociatedactivity() { 41 +
  42 + public String getAssociatedactivity() {
46 return associatedactivity; 43 return associatedactivity;
47 } 44 }
48 45
49 - public void setAssociatedactivity(int associatedactivity) { 46 + public void setAssociatedactivity(String associatedactivity) {
50 this.associatedactivity = associatedactivity; 47 this.associatedactivity = associatedactivity;
51 } 48 }
52 49
Risiko/app/src/main/java/dataclasses/Incident.java
@@ -7,37 +7,35 @@ import java.util.UUID; @@ -7,37 +7,35 @@ import java.util.UUID;
7 7
8 public class Incident { 8 public class Incident {
9 9
10 - UUID uuid; 10 + private String id;
11 private String date; 11 private String date;
12 private String location; 12 private String location;
13 private String title; 13 private String title;
14 private String description; 14 private String description;
15 - private int id;  
16 - private int associatedeval; 15 + private String associatedeval;
17 16
18 17
19 public Incident() { 18 public Incident() {
20 - uuid = UUID.randomUUID();  
21 } 19 }
22 20
23 - public Incident(String date, String place, String title, String description, int associatedeval) { 21 + public Incident(String id, String date, String place, String title, String description, String associatedeval) {
  22 + this.id = id;
24 this.date = date; 23 this.date = date;
25 this.location = place; 24 this.location = place;
26 this.title = title; 25 this.title = title;
27 this.description = description; 26 this.description = description;
28 this.associatedeval = associatedeval; 27 this.associatedeval = associatedeval;
29 - uuid = UUID.randomUUID();  
30 } 28 }
31 29
32 public Incident(String title) { 30 public Incident(String title) {
33 this.title = title; 31 this.title = title;
34 } 32 }
35 33
36 - public int getAssociatedeval() { 34 + public String getAssociatedeval() {
37 return associatedeval; 35 return associatedeval;
38 } 36 }
39 37
40 - public void setAssociatedeval(int associatedeval) { 38 + public void setAssociatedeval(String associatedeval) {
41 this.associatedeval = associatedeval; 39 this.associatedeval = associatedeval;
42 } 40 }
43 41
@@ -73,11 +71,11 @@ public class Incident { @@ -73,11 +71,11 @@ public class Incident {
73 this.description = description; 71 this.description = description;
74 } 72 }
75 73
76 - public int getId() { 74 + public String getId() {
77 return id; 75 return id;
78 } 76 }
79 77
80 - public void setId(int id) { 78 + public void setId(String id) {
81 this.id = id; 79 this.id = id;
82 } 80 }
83 } 81 }
restApi/.idea/workspace.xml
@@ -2,60 +2,90 @@ @@ -2,60 +2,90 @@
2 <project version="4"> 2 <project version="4">
3 <component name="ChangeListManager"> 3 <component name="ChangeListManager">
4 <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment=""> 4 <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="">
5 - <change beforePath="$PROJECT_DIR$/../Rapport - Distribuert server-klient.docx" afterPath="$PROJECT_DIR$/../Rapport - Distribuert server-klient.docx" />  
6 - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Evaluations.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Evaluations.java" />  
7 - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/NewEvaluation.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/NewEvaluation.java" />  
8 - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" />  
9 - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/database/DatabaseSource.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/database/DatabaseSource.java" />  
10 - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Evaluation.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Evaluation.java" /> 5 + <change beforePath="$PROJECT_DIR$/../Risiko/.idea/caches/build_file_checksums.ser" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/.idea/caches/build_file_checksums.ser" afterDir="false" />
  6 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Activities.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Activities.java" afterDir="false" />
  7 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Evaluations.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Evaluations.java" afterDir="false" />
  8 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" afterDir="false" />
  9 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/NewEvaluation.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/NewEvaluation.java" afterDir="false" />
  10 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/NewIncident.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/NewIncident.java" afterDir="false" />
  11 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterDir="false" />
  12 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/database/DatabaseSource.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/database/DatabaseSource.java" afterDir="false" />
  13 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/database/EvaluationTable.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/database/EvaluationTable.java" afterDir="false" />
  14 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/database/IncidentTable.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/database/IncidentTable.java" afterDir="false" />
  15 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Activity.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Activity.java" afterDir="false" />
  16 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Evaluation.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Evaluation.java" afterDir="false" />
  17 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Incident.java" beforeDir="false" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Incident.java" afterDir="false" />
  18 + <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
  19 + <change beforePath="$PROJECT_DIR$/api/routes/routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/api/routes/routes.js" afterDir="false" />
11 </list> 20 </list>
12 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> 21 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
13 - <option name="TRACKING_ENABLED" value="true" />  
14 <option name="SHOW_DIALOG" value="false" /> 22 <option name="SHOW_DIALOG" value="false" />
15 <option name="HIGHLIGHT_CONFLICTS" value="true" /> 23 <option name="HIGHLIGHT_CONFLICTS" value="true" />
16 <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> 24 <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
17 <option name="LAST_RESOLUTION" value="IGNORE" /> 25 <option name="LAST_RESOLUTION" value="IGNORE" />
18 </component> 26 </component>
  27 + <component name="FUSProjectUsageTrigger">
  28 + <session id="535790383">
  29 + <usages-collector id="statistics.lifecycle.project">
  30 + <counts>
  31 + <entry key="project.closed" value="2" />
  32 + <entry key="project.open.time.1" value="1" />
  33 + <entry key="project.open.time.31" value="1" />
  34 + <entry key="project.opened" value="2" />
  35 + </counts>
  36 + </usages-collector>
  37 + <usages-collector id="statistics.file.extensions.edit">
  38 + <counts>
  39 + <entry key="js" value="3212" />
  40 + </counts>
  41 + </usages-collector>
  42 + <usages-collector id="statistics.file.types.edit">
  43 + <counts>
  44 + <entry key="JavaScript" value="3212" />
  45 + </counts>
  46 + </usages-collector>
  47 + <usages-collector id="statistics.file.types.open">
  48 + <counts>
  49 + <entry key="JavaScript" value="1" />
  50 + </counts>
  51 + </usages-collector>
  52 + <usages-collector id="statistics.vcs.git.usages" />
  53 + <usages-collector id="statistics.js.language.service.starts" />
  54 + <usages-collector id="statistics.file.extensions.open">
  55 + <counts>
  56 + <entry key="js" value="1" />
  57 + </counts>
  58 + </usages-collector>
  59 + </session>
  60 + </component>
19 <component name="FileEditorManager"> 61 <component name="FileEditorManager">
20 <leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> 62 <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
21 - <file leaf-file-name="routes.js" pinned="false" current-in-tab="false"> 63 + <file pinned="false" current-in-tab="true">
22 <entry file="file://$PROJECT_DIR$/api/routes/routes.js"> 64 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
23 <provider selected="true" editor-type-id="text-editor"> 65 <provider selected="true" editor-type-id="text-editor">
24 - <state relative-caret-position="308">  
25 - <caret line="71" column="52" lean-forward="true" selection-start-line="71" selection-start-column="52" selection-end-line="71" selection-end-column="52" />  
26 - <folding /> 66 + <state relative-caret-position="337">
  67 + <caret line="75" column="7" lean-forward="true" selection-start-line="75" selection-start-column="7" selection-end-line="75" selection-end-column="7" />
27 </state> 68 </state>
28 </provider> 69 </provider>
29 </entry> 70 </entry>
30 </file> 71 </file>
31 - <file leaf-file-name="package.json" pinned="false" current-in-tab="false"> 72 + <file pinned="false" current-in-tab="false">
32 <entry file="file://$PROJECT_DIR$/package.json"> 73 <entry file="file://$PROJECT_DIR$/package.json">
33 <provider selected="true" editor-type-id="text-editor"> 74 <provider selected="true" editor-type-id="text-editor">
34 - <state relative-caret-position="120">  
35 - <caret line="8" column="38" lean-forward="false" selection-start-line="8" selection-start-column="38" selection-end-line="8" selection-end-column="38" />  
36 - <folding /> 75 + <state relative-caret-position="136">
  76 + <caret line="8" column="48" selection-start-line="8" selection-start-column="48" selection-end-line="8" selection-end-column="48" />
37 </state> 77 </state>
38 </provider> 78 </provider>
39 </entry> 79 </entry>
40 </file> 80 </file>
41 - <file leaf-file-name="evaluation.js" pinned="false" current-in-tab="false"> 81 + <file pinned="false" current-in-tab="false">
42 <entry file="file://$PROJECT_DIR$/api/modules/evaluation.js"> 82 <entry file="file://$PROJECT_DIR$/api/modules/evaluation.js">
43 - <provider selected="true" editor-type-id="text-editor">  
44 - <state relative-caret-position="0">  
45 - <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />  
46 - <folding />  
47 - </state>  
48 - </provider> 83 + <provider selected="true" editor-type-id="text-editor" />
49 </entry> 84 </entry>
50 </file> 85 </file>
51 - <file leaf-file-name="incident.js" pinned="false" current-in-tab="true"> 86 + <file pinned="false" current-in-tab="false">
52 <entry file="file://$PROJECT_DIR$/api/modules/incident.js"> 87 <entry file="file://$PROJECT_DIR$/api/modules/incident.js">
53 - <provider selected="true" editor-type-id="text-editor">  
54 - <state relative-caret-position="0">  
55 - <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />  
56 - <folding />  
57 - </state>  
58 - </provider> 88 + <provider selected="true" editor-type-id="text-editor" />
59 </entry> 89 </entry>
60 </file> 90 </file>
61 </leaf> 91 </leaf>
@@ -66,8 +96,8 @@ @@ -66,8 +96,8 @@
66 <component name="IdeDocumentHistory"> 96 <component name="IdeDocumentHistory">
67 <option name="CHANGED_PATHS"> 97 <option name="CHANGED_PATHS">
68 <list> 98 <list>
69 - <option value="$PROJECT_DIR$/api/routes/routes.js" />  
70 <option value="$PROJECT_DIR$/package.json" /> 99 <option value="$PROJECT_DIR$/package.json" />
  100 + <option value="$PROJECT_DIR$/api/routes/routes.js" />
71 </list> 101 </list>
72 </option> 102 </option>
73 </component> 103 </component>
@@ -82,28 +112,23 @@ @@ -82,28 +112,23 @@
82 <component name="NodeModulesDirectoryManager"> 112 <component name="NodeModulesDirectoryManager">
83 <handled-path value="$PROJECT_DIR$/node_modules" /> 113 <handled-path value="$PROJECT_DIR$/node_modules" />
84 </component> 114 </component>
85 - <component name="ProjectFrameBounds" fullScreen="true">  
86 - <option name="x" value="1" />  
87 - <option name="y" value="23" />  
88 - <option name="width" value="1440" />  
89 - <option name="height" value="873" /> 115 + <component name="NodePackageJsonFileManager">
  116 + <packageJsonPaths>
  117 + <path value="$PROJECT_DIR$/package.json" />
  118 + </packageJsonPaths>
  119 + </component>
  120 + <component name="ProjectFrameBounds" extendedState="6">
  121 + <option name="x" value="352" />
  122 + <option name="y" value="96" />
  123 + <option name="width" value="1536" />
  124 + <option name="height" value="832" />
90 </component> 125 </component>
91 <component name="ProjectView"> 126 <component name="ProjectView">
92 - <navigator currentView="ProjectPane" proportions="" version="1">  
93 - <flattenPackages />  
94 - <showMembers />  
95 - <showModules />  
96 - <showLibraryContents />  
97 - <hideEmptyPackages />  
98 - <abbreviatePackageNames />  
99 - <autoscrollToSource />  
100 - <autoscrollFromSource />  
101 - <sortByType />  
102 - <manualOrder /> 127 + <navigator proportions="" version="1">
103 <foldersAlwaysOnTop value="true" /> 128 <foldersAlwaysOnTop value="true" />
104 </navigator> 129 </navigator>
105 <panes> 130 <panes>
106 - <pane id="Scratches" /> 131 + <pane id="Scope" />
107 <pane id="ProjectPane"> 132 <pane id="ProjectPane">
108 <subPane> 133 <subPane>
109 <expand> 134 <expand>
@@ -132,11 +157,11 @@ @@ -132,11 +157,11 @@
132 <select /> 157 <select />
133 </subPane> 158 </subPane>
134 </pane> 159 </pane>
135 - <pane id="Scope" />  
136 </panes> 160 </panes>
137 </component> 161 </component>
138 <component name="PropertiesComponent"> 162 <component name="PropertiesComponent">
139 <property name="WebServerToolWindowFactoryState" value="false" /> 163 <property name="WebServerToolWindowFactoryState" value="false" />
  164 + <property name="nodejs_package_manager_path" value="npm" />
140 </component> 165 </component>
141 <component name="RunDashboard"> 166 <component name="RunDashboard">
142 <option name="ruleStates"> 167 <option name="ruleStates">
@@ -151,7 +176,9 @@ @@ -151,7 +176,9 @@
151 </option> 176 </option>
152 </component> 177 </component>
153 <component name="RunManager" selected="npm.debug"> 178 <component name="RunManager" selected="npm.debug">
154 - <configuration name="server.js" type="NodeJSConfigurationType" factoryName="Node.js" temporary="true" path-to-js-file="server.js" working-dir="$PROJECT_DIR$" /> 179 + <configuration name="server.js" type="NodeJSConfigurationType" factoryName="Node.js" temporary="true" path-to-js-file="server.js" working-dir="$PROJECT_DIR$">
  180 + <method v="2" />
  181 + </configuration>
155 <configuration name="api" type="js.build_tools.npm" factoryName="npm" temporary="true" nameIsGenerated="true"> 182 <configuration name="api" type="js.build_tools.npm" factoryName="npm" temporary="true" nameIsGenerated="true">
156 <package-json value="$PROJECT_DIR$/package.json" /> 183 <package-json value="$PROJECT_DIR$/package.json" />
157 <command value="run" /> 184 <command value="run" />
@@ -160,6 +187,7 @@ @@ -160,6 +187,7 @@
160 </scripts> 187 </scripts>
161 <node-interpreter value="project" /> 188 <node-interpreter value="project" />
162 <envs /> 189 <envs />
  190 + <method v="2" />
163 </configuration> 191 </configuration>
164 <configuration name="debug" type="js.build_tools.npm" factoryName="npm" temporary="true" nameIsGenerated="true"> 192 <configuration name="debug" type="js.build_tools.npm" factoryName="npm" temporary="true" nameIsGenerated="true">
165 <package-json value="$PROJECT_DIR$/package.json" /> 193 <package-json value="$PROJECT_DIR$/package.json" />
@@ -169,23 +197,21 @@ @@ -169,23 +197,21 @@
169 </scripts> 197 </scripts>
170 <node-interpreter value="project" /> 198 <node-interpreter value="project" />
171 <envs /> 199 <envs />
  200 + <method v="2" />
172 </configuration> 201 </configuration>
173 - <list size="3">  
174 - <item index="0" class="java.lang.String" itemvalue="Node.js.server.js" />  
175 - <item index="1" class="java.lang.String" itemvalue="npm.api" />  
176 - <item index="2" class="java.lang.String" itemvalue="npm.debug" /> 202 + <list>
  203 + <item itemvalue="Node.js.server.js" />
  204 + <item itemvalue="npm.api" />
  205 + <item itemvalue="npm.debug" />
177 </list> 206 </list>
178 <recent_temporary> 207 <recent_temporary>
179 - <list size="3">  
180 - <item index="0" class="java.lang.String" itemvalue="npm.debug" />  
181 - <item index="1" class="java.lang.String" itemvalue="npm.api" />  
182 - <item index="2" class="java.lang.String" itemvalue="Node.js.server.js" /> 208 + <list>
  209 + <item itemvalue="npm.api" />
  210 + <item itemvalue="npm.debug" />
  211 + <item itemvalue="Node.js.server.js" />
183 </list> 212 </list>
184 </recent_temporary> 213 </recent_temporary>
185 </component> 214 </component>
186 - <component name="ShelveChangesManager" show_recycled="false">  
187 - <option name="remove_strategy" value="false" />  
188 - </component>  
189 <component name="SvnConfiguration"> 215 <component name="SvnConfiguration">
190 <configuration /> 216 <configuration />
191 </component> 217 </component>
@@ -199,33 +225,37 @@ @@ -199,33 +225,37 @@
199 <workItem from="1541088608198" duration="134000" /> 225 <workItem from="1541088608198" duration="134000" />
200 <workItem from="1541088784358" duration="1764000" /> 226 <workItem from="1541088784358" duration="1764000" />
201 <workItem from="1541155443683" duration="1473000" /> 227 <workItem from="1541155443683" duration="1473000" />
  228 + <workItem from="1541596156631" duration="9351000" />
  229 + <workItem from="1541681303243" duration="9060000" />
202 </task> 230 </task>
203 <servers /> 231 <servers />
204 </component> 232 </component>
205 <component name="TimeTrackingManager"> 233 <component name="TimeTrackingManager">
206 - <option name="totallyTimeSpent" value="3371000" /> 234 + <option name="totallyTimeSpent" value="21782000" />
207 </component> 235 </component>
208 <component name="ToolWindowManager"> 236 <component name="ToolWindowManager">
209 - <frame x="0" y="0" width="1440" height="900" extended-state="0" /> 237 + <frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
  238 + <editor active="true" />
210 <layout> 239 <layout>
211 - <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24947146" sideWeight="0.49369368" order="0" side_tool="false" content_ui="combo" />  
212 - <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />  
213 - <window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />  
214 - <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />  
215 - <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />  
216 - <window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32889965" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />  
217 - <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24947146" sideWeight="0.5063063" order="2" side_tool="true" content_ui="tabs" />  
218 - <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />  
219 - <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />  
220 - <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />  
221 - <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.39903265" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />  
222 - <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />  
223 - <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />  
224 - <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />  
225 - <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />  
226 - <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />  
227 - <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />  
228 - <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> 240 + <window_info content_ui="combo" id="Project" order="0" sideWeight="0.7223427" visible="true" weight="0.20073763" />
  241 + <window_info id="Structure" order="1" weight="0.25" />
  242 + <window_info id="npm" order="2" sideWeight="0.27765727" side_tool="true" visible="true" weight="0.20073763" />
  243 + <window_info id="Favorites" order="3" side_tool="true" />
  244 + <window_info anchor="bottom" id="Message" order="0" />
  245 + <window_info anchor="bottom" id="Find" order="1" />
  246 + <window_info anchor="bottom" id="Run" order="2" weight="0.3286334" />
  247 + <window_info anchor="bottom" id="Debug" order="3" weight="0.39903265" />
  248 + <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
  249 + <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
  250 + <window_info anchor="bottom" id="TODO" order="6" />
  251 + <window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
  252 + <window_info anchor="bottom" id="Version Control" order="8" />
  253 + <window_info anchor="bottom" id="Terminal" order="9" />
  254 + <window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
  255 + <window_info anchor="bottom" id="Messages" order="11" />
  256 + <window_info anchor="right" id="Commander" order="0" weight="0.4" />
  257 + <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
  258 + <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
229 </layout> 259 </layout>
230 </component> 260 </component>
231 <component name="TypeScriptGeneratedFilesManager"> 261 <component name="TypeScriptGeneratedFilesManager">
@@ -234,79 +264,33 @@ @@ -234,79 +264,33 @@
234 <component name="VcsContentAnnotationSettings"> 264 <component name="VcsContentAnnotationSettings">
235 <option name="myLimit" value="2678400000" /> 265 <option name="myLimit" value="2678400000" />
236 </component> 266 </component>
237 - <component name="XDebuggerManager">  
238 - <breakpoint-manager>  
239 - <breakpoints>  
240 - <line-breakpoint enabled="true" type="javascript">  
241 - <url>file://$PROJECT_DIR$/api/routes/routes.js</url>  
242 - <line>171</line>  
243 - <properties lambdaOrdinal="-1" />  
244 - </line-breakpoint>  
245 - <line-breakpoint enabled="true" type="javascript">  
246 - <url>file://$PROJECT_DIR$/api/routes/routes.js</url>  
247 - <line>170</line>  
248 - <properties lambdaOrdinal="-1" />  
249 - <option name="timeStamp" value="1" />  
250 - </line-breakpoint>  
251 - <line-breakpoint enabled="true" type="javascript">  
252 - <url>file://$PROJECT_DIR$/api/routes/routes.js</url>  
253 - <line>182</line>  
254 - <properties lambdaOrdinal="-1" />  
255 - <option name="timeStamp" value="2" />  
256 - </line-breakpoint>  
257 - </breakpoints>  
258 - <option name="time" value="3" />  
259 - </breakpoint-manager>  
260 - <watches-manager />  
261 - </component>  
262 <component name="editorHistoryManager"> 267 <component name="editorHistoryManager">
263 - <entry file="file://$PROJECT_DIR$/api/routes/routes.js"> 268 + <entry file="file://$PROJECT_DIR$/node_modules/cassandra-driver/lib/requests.js">
264 <provider selected="true" editor-type-id="text-editor"> 269 <provider selected="true" editor-type-id="text-editor">
265 - <state relative-caret-position="0">  
266 - <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />  
267 - <folding /> 270 + <state relative-caret-position="190">
  271 + <caret line="106" column="9" selection-start-line="106" selection-start-column="9" selection-end-line="106" selection-end-column="9" />
268 </state> 272 </state>
269 </provider> 273 </provider>
270 </entry> 274 </entry>
271 - <entry file="file://$PROJECT_DIR$/api/modules/evaluation.js"> 275 + <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
272 <provider selected="true" editor-type-id="text-editor"> 276 <provider selected="true" editor-type-id="text-editor">
273 - <state relative-caret-position="0">  
274 - <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />  
275 - <folding /> 277 + <state relative-caret-position="337">
  278 + <caret line="75" column="7" lean-forward="true" selection-start-line="75" selection-start-column="7" selection-end-line="75" selection-end-column="7" />
276 </state> 279 </state>
277 </provider> 280 </provider>
278 </entry> 281 </entry>
279 <entry file="file://$PROJECT_DIR$/package.json"> 282 <entry file="file://$PROJECT_DIR$/package.json">
280 <provider selected="true" editor-type-id="text-editor"> 283 <provider selected="true" editor-type-id="text-editor">
281 - <state relative-caret-position="120">  
282 - <caret line="8" column="38" lean-forward="false" selection-start-line="8" selection-start-column="38" selection-end-line="8" selection-end-column="38" />  
283 - <folding />  
284 - </state>  
285 - </provider>  
286 - </entry>  
287 - <entry file="file://$PROJECT_DIR$/api/routes/routes.js">  
288 - <provider selected="true" editor-type-id="text-editor">  
289 - <state relative-caret-position="308">  
290 - <caret line="71" column="52" lean-forward="true" selection-start-line="71" selection-start-column="52" selection-end-line="71" selection-end-column="52" />  
291 - <folding /> 284 + <state relative-caret-position="136">
  285 + <caret line="8" column="48" selection-start-line="8" selection-start-column="48" selection-end-line="8" selection-end-column="48" />
292 </state> 286 </state>
293 </provider> 287 </provider>
294 </entry> 288 </entry>
295 <entry file="file://$PROJECT_DIR$/api/modules/evaluation.js"> 289 <entry file="file://$PROJECT_DIR$/api/modules/evaluation.js">
296 - <provider selected="true" editor-type-id="text-editor">  
297 - <state relative-caret-position="0">  
298 - <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />  
299 - <folding />  
300 - </state>  
301 - </provider> 290 + <provider selected="true" editor-type-id="text-editor" />
302 </entry> 291 </entry>
303 <entry file="file://$PROJECT_DIR$/api/modules/incident.js"> 292 <entry file="file://$PROJECT_DIR$/api/modules/incident.js">
304 - <provider selected="true" editor-type-id="text-editor">  
305 - <state relative-caret-position="0">  
306 - <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />  
307 - <folding />  
308 - </state>  
309 - </provider> 293 + <provider selected="true" editor-type-id="text-editor" />
310 </entry> 294 </entry>
311 </component> 295 </component>
312 </project> 296 </project>
313 \ No newline at end of file 297 \ No newline at end of file
restApi/api/routes/routes.js
@@ -6,7 +6,7 @@ const Activity = require(&quot;../modules/activity.js&quot;); @@ -6,7 +6,7 @@ const Activity = require(&quot;../modules/activity.js&quot;);
6 const uuid = require('uuid'); 6 const uuid = require('uuid');
7 var cassandra = require("cassandra-driver"); 7 var cassandra = require("cassandra-driver");
8 8
9 -var client = setupDatabase('127.0.0.1'); 9 +var db = setupDatabase('127.0.0.1');
10 10
11 var appRouter = function(app) { 11 var appRouter = function(app) {
12 12
@@ -20,22 +20,32 @@ var appRouter = function(app) { @@ -20,22 +20,32 @@ var appRouter = function(app) {
20 * Get incident by id endpoint (a get request at http://localhost:3000/incident/1 will return incident with id 1) 20 * Get incident by id endpoint (a get request at http://localhost:3000/incident/1 will return incident with id 1)
21 */ 21 */
22 app.get("/incident/:id", function (req, res) { 22 app.get("/incident/:id", function (req, res) {
23 - if (!req.params.id) return req.status(400).send("No id entered"); 23 + if (!req.params.id) {
  24 + logEndpoint("get /incident/{id}", null, "ID missing");
  25 + return req.status(400).send("No id entered");
  26 + }
24 27
25 const params = [req.params.id]; 28 const params = [req.params.id];
26 - client.execute('SELECT * FROM risk.incident WHERE id = ?', params,{ prepare: true }, function(err, result) {  
27 - if(err) {  
28 - console.log(err);  
29 - return res.status(400).send("Bad Request, make sure to send a request with an id")  
30 - } else {  
31 - if (result.rows.length != 0)  
32 - return res.status(200).send(result.rows[0]);  
33 - else  
34 - return res.status(204).send("Id not found in database");  
35 - 29 + db.execute('SELECT * ' +
  30 + 'FROM risk.incident ' +
  31 + 'WHERE id = ?',
  32 + params,
  33 + { prepare: true },
  34 + function(err, result) {
  35 + if(err) {
  36 + logEndpoint("get /incident/{id}", err, null);
  37 + return res.status(400).send("Bad request, see API log");
  38 + } else {
  39 + if (result.rows.length != 0) {
  40 + logEndpoint("get /incident/{id}", err, "Success, incident returned");
  41 + return res.status(200).send(result.rows[0]);
  42 + } else {
  43 + logEndpoint("get /incident/{id}", err, "Success but id not found in database");
  44 + return res.status(204).send("Id not found in database");
  45 + }
  46 + }
36 } 47 }
37 - });  
38 - 48 + );
39 }); 49 });
40 50
41 /** 51 /**
@@ -43,20 +53,24 @@ var appRouter = function(app) { @@ -43,20 +53,24 @@ var appRouter = function(app) {
43 */ 53 */
44 app.get("/incident", function (req, res) { 54 app.get("/incident", function (req, res) {
45 55
46 - client.execute('SELECT * FROM risk.incident', function (err, result) {  
47 - if(err) {  
48 - console.log(err);  
49 - return res.status(400).send("Bad Request");  
50 -  
51 - } else {  
52 - if (result.rows.length != 0)  
53 - return res.status(200).send(result.rows);  
54 - else  
55 - return res.status(204).send("No registered incidents"); 56 + db.execute('SELECT * ' +
  57 + 'FROM risk.incident',
  58 + function (err, result) {
  59 + if(err) {
  60 + logEndpoint("get /incident", err, null);
  61 + return res.status(400).send("Bad request, see API log");
  62 +
  63 + } else {
  64 + if (result.rows.length != 0) {
  65 + logEndpoint("get /incident", err, "Success. All incidents returned");
  66 + return res.status(200).send(result.rows);
  67 + } else {
  68 + logEndpoint("get /incident", err, "Success but no incidents found in database");
  69 + return res.status(204).send("No registered incidents");
  70 + }
  71 + }
56 } 72 }
57 -  
58 - })  
59 - 73 + );
60 }); 74 });
61 75
62 /** 76 /**
@@ -65,21 +79,22 @@ var appRouter = function(app) { @@ -65,21 +79,22 @@ var appRouter = function(app) {
65 app.post("/incident", function(req, res) { 79 app.post("/incident", function(req, res) {
66 80
67 // All these parameters must exist in the body with the exact name for this method to work 81 // All these parameters must exist in the body with the exact name for this method to work
68 - if(!req.body.id || !req.body.date || !req.body.location || !req.body.title || !req.body.description || !req.body.associatedEval) { 82 + if(!req.body.date || !req.body.location || !req.body.title || !req.body.description || !req.body.associatedEval) {
  83 + logEndpoint("post /incident", null, "Missing params in body");
69 return res.status(400).send("Missing params"); 84 return res.status(400).send("Missing params");
70 } else { 85 } else {
71 - const query = 'INSERT INTO risk.incident(id, uuid, date, location, title, description, associatedEval) VALUES(?,?,?,?,?,?,?)';  
72 - const params = [req.body.id, uuid(), new Date(req.body.date), req.body.location, req.body.title, req.body.description, req.body.associatedEval];  
73 - client.execute(query, params, { prepare: true }, function (err) { 86 + const query = 'INSERT INTO risk.incident(id, date, location, title, description, associatedEval) ' +
  87 + 'VALUES(?,?,?,?,?,?)';
  88 + const params = [uuid(), new Date(req.body.date), req.body.location, req.body.title, req.body.description, req.body.associatedEval];
  89 + db.execute(query, params, { prepare: true }, function (err) {
74 if (err) { 90 if (err) {
75 - console.log(err); 91 + logEndpoint("post /incident", err, "Bad request, see API log");
76 return res.status(400).send("Bad Request"); 92 return res.status(400).send("Bad Request");
77 } 93 }
  94 + logEndpoint("post /incident", err, "Success, incident created");
78 return res.status(200).send("Incident Created"); 95 return res.status(200).send("Incident Created");
79 -  
80 - }) 96 + });
81 } 97 }
82 -  
83 }); 98 });
84 99
85 /** 100 /**
@@ -87,58 +102,88 @@ var appRouter = function(app) { @@ -87,58 +102,88 @@ var appRouter = function(app) {
87 */ 102 */
88 app.patch("/incident/:id", function (req, res) { 103 app.patch("/incident/:id", function (req, res) {
89 104
  105 + if (!req.params.id) {
  106 + logEndpoint("patch /incident", null, "ID missing");
  107 + return res.status(400).send("Missing id");
  108 + }
90 109
91 - if (!req.params.id) return res.status(400).send("Missing id");  
92 -  
93 - if(!req.body.date || !req.body.location || !req.body.title || !req.body.description || !req.body.associatedEval) { 110 + if (!req.body.date || !req.body.location || !req.body.title || !req.body.description || !req.body.associatedEval) {
  111 + logEndpoint("patch /incident", null, "Missing params in body");
94 return res.status(400).send("Missing params"); 112 return res.status(400).send("Missing params");
95 } 113 }
96 114
97 const params = [new Date(req.body.date), req.body.location, req.body.title, req.body.description, req.body.associatedEval, req.params.id]; 115 const params = [new Date(req.body.date), req.body.location, req.body.title, req.body.description, req.body.associatedEval, req.params.id];
98 - client.execute("UPDATE risk.incident SET date=?, location=?, title=?, description=?, associatedEval=? WHERE id=?", params,{ prepare: true }, function (err) {  
99 - if (err) {  
100 - console.log(err);  
101 - return res.status(400).send("Bad Request"); 116 + db.execute("UPDATE risk.incident " +
  117 + "SET date=?, location=?, title=?, description=?, associatedEval=? " +
  118 + "WHERE id=?",
  119 + params,
  120 + { prepare: true },
  121 + function (err) {
  122 + if (err) {
  123 + logEndpoint("patch /incident", err, "Bad request, see API log");
  124 + return res.status(400).send("Bad Request");
  125 + }
  126 + logEndpoint("patch /incident", err, "Success, incident updated");
  127 + return res.status(200).send("Incident updated");
102 } 128 }
103 - return res.status(200).send("Incident updated");  
104 - });  
105 -  
106 -  
107 - 129 + );
108 }); 130 });
109 131
110 /** 132 /**
111 - * Delete an incident (a delete request at http://localhost:3000/incident/{id} should delete incident with id=1) 133 + * Delete an incident (a delete request at http://localhost:3000/incident/{id} should delete incident with the id passed in)
112 */ 134 */
113 app.delete("/incident/:id", function (req, res) { 135 app.delete("/incident/:id", function (req, res) {
114 - if (!req.params.id) return res.status(400).send("Missing id");  
115 - const params = [req.params.id];  
116 - client.execute("DELETE FROM risk.incident WHERE id = ?", params,{ prepare: true }, function (err) {  
117 - if (err) return res.status(400).send("Bad request");  
118 - return res.status(200).send("Incident deleted"); 136 + if (!req.params.id) {
  137 + logEndpoint("delete /incident", null, "ID missing");
  138 + return res.status(400).send("Missing id");
  139 + }
119 140
120 - }); 141 + const params = [req.params.id];
  142 + db.execute("DELETE FROM risk.incident " +
  143 + "WHERE id = ?",
  144 + params,
  145 + { prepare: true },
  146 + function (err) {
  147 + if (err) {
  148 + logEndpoint("delete /incident", err, "Bad request, see API log");
  149 + return res.status(400).send("Bad request");
  150 + }
  151 + logEndpoint("delete /incident", err, "Success, incident deleted");
  152 + return res.status(200).send("Incident deleted");
  153 + }
  154 + );
121 }); 155 });
122 156
123 /** 157 /**
124 * See an evaluation with id x 158 * See an evaluation with id x
125 */ 159 */
126 app.get("/evaluation/:id", function (req, res) { 160 app.get("/evaluation/:id", function (req, res) {
127 - if (!req.params.id) return req.status(400).send("No id entered"); 161 + if (!req.params.id) {
  162 + logEndpoint("get /evaluation/{id}", null, "ID missing");
  163 + return req.status(400).send("No id entered");
  164 + }
128 165
129 const params = [req.params.id]; 166 const params = [req.params.id];
130 - client.execute('SELECT * FROM risk.evaluation WHERE id = ?', params,{ prepare: true}, function(err, result) {  
131 - if(err) {  
132 - console.log(err);  
133 - return res.status(400).send("Bad Request, make sure to send a request with an id")  
134 - } else {  
135 - if (result.rows.length != 0)  
136 - return res.status(200).send(result.rows[0]);  
137 - else  
138 - return res.status(204).send("Id not found in database"); 167 + db.execute('SELECT * ' +
  168 + 'FROM risk.evaluation ' +
  169 + 'WHERE id = ?',
  170 + params,
  171 + { prepare: true},
  172 + function(err, result) {
  173 + if(err) {
  174 + logEndpoint("get /evaluation/{id}", err, "Bad request, see API log");
  175 + return res.status(400).send("Bad request, see API log")
  176 + } else {
  177 + if (result.rows.length != 0) {
  178 + logEndpoint("get /evaluation/{id}", err, "Success, evaluation returned");
  179 + return res.status(200).send(result.rows[0]);
  180 + } else {
  181 + logEndpoint("get /evaluation/{id}", err, "Success but evaluation not found in database");
  182 + return res.status(204).send("Id not found in database");
  183 + }
  184 + }
139 } 185 }
140 - });  
141 - 186 + );
142 }); 187 });
143 188
144 189
@@ -147,92 +192,103 @@ var appRouter = function(app) { @@ -147,92 +192,103 @@ var appRouter = function(app) {
147 */ 192 */
148 app.get("/evaluation", function (req, res) { 193 app.get("/evaluation", function (req, res) {
149 194
150 - client.execute('SELECT * FROM risk.evaluation', [], function (err, result) {  
151 - if(err) {  
152 - console.log(err);  
153 - return res.status(400).send("Bad Request"); 195 + db.execute('SELECT * ' +
  196 + 'FROM risk.evaluation',
  197 + function (err, result) {
  198 + if(err) {
  199 + logEndpoint("get /evaluation/", err, "Bad request, see API log");
  200 + return res.status(400).send("Bad Request");
154 201
155 - } else {  
156 - if (result.rows.length != 0)  
157 - return res.status(200).send(result.rows);  
158 - else  
159 - return res.status(204).send("No registered evaluations"); 202 + } else {
  203 + if (result.rows.length != 0) {
  204 + logEndpoint("get /evaluation/", err, "Success, all evaluations returned");
  205 + return res.status(200).send(result.rows);
  206 + } else {
  207 + logEndpoint("get /evaluation/", err, "Success but no evaluations found in database");
  208 + return res.status(204).send("No registered evaluations");
  209 + }
  210 + }
160 } 211 }
161 -  
162 - })  
163 - 212 + );
164 }); 213 });
165 214
166 -  
167 /** 215 /**
168 * Add a new evaluation 216 * Add a new evaluation
169 */ 217 */
170 app.post("/evaluation", function(req, res) { 218 app.post("/evaluation", function(req, res) {
171 - console.log("hello?")  
172 - if(!req.body.id || !req.body.title || !req.body.outcome || !req.body.measures || !req.body.consequence || !req.body.probability || !req.body.associatedActivity) { 219 + if(!req.body.title || !req.body.outcome || !req.body.measures || !req.body.consequence || !req.body.probability || !req.body.associatedActivity) {
  220 + logEndpoint("post /evaluation/", null, "Missing params in body");
173 return res.status(400).send("Missing params"); 221 return res.status(400).send("Missing params");
174 } else { 222 } else {
175 - const query = 'INSERT INTO risk.evaluation(id, uuid, title, outcome, measures, consequence, probability, associatedActivity) VALUES(?,?,?,?,?,?,?,?)';  
176 - const params = [req.body.id, uuid(), req.body.title, req.body.outcome, req.body.measures, req.body.consequence, req.body.probability, req.body.associatedActivity];  
177 - client.execute(query, params, { prepare: true }, function (err) {  
178 - 223 + const query = 'INSERT INTO risk.evaluation(id, title, outcome, measures, consequence, probability, associatedActivity) ' +
  224 + 'VALUES(?,?,?,?,?,?,?)';
  225 + const params = [uuid(), req.body.title, req.body.outcome, req.body.measures, req.body.consequence, req.body.probability, req.body.associatedActivity];
  226 + db.execute(query, params, { prepare: true }, function (err) {
179 if (err) { 227 if (err) {
180 - console.log(err);  
181 - return res.status(400).send("Bad Request with error:\n" + err); 228 + logEndpoint("post /evaluation/", err, "Bad request, see API log");
  229 + return res.status(400).send("Bad Request");
182 } 230 }
  231 + logEndpoint("post /evaluation/", err, "Success, evaluation created");
183 return res.status(200).send("Evaluation Created"); 232 return res.status(200).send("Evaluation Created");
184 -  
185 }) 233 })
186 } 234 }
187 -  
188 }); 235 });
189 236
190 -  
191 /** 237 /**
192 * See an activity with id x 238 * See an activity with id x
193 */ 239 */
194 app.get("/activity/:id", function (req, res) { 240 app.get("/activity/:id", function (req, res) {
195 - if (!req.params.id) return req.status(400).send("No id entered"); 241 + if (!req.params.id) {
  242 + logEndpoint("get /activity/{id}", null, "ID missing");
  243 + return req.status(400).send("No id entered");
  244 + }
196 245
197 const params = [req.params.id]; 246 const params = [req.params.id];
198 - client.execute('SELECT * FROM risk.activity WHERE id = ?', params,{ prepare : true}, function(err, result) {  
199 - if(err) {  
200 - console.log(err);  
201 - return res.status(400).send("Bad Request, make sure to send a request with an id")  
202 - } else {  
203 - if (result.rows.length != 0)  
204 - return res.status(200).send(result.rows[0]);  
205 - else  
206 - return res.status(204).send("Id not found in database"); 247 + db.execute('SELECT * ' +
  248 + 'FROM risk.activity ' +
  249 + 'WHERE id = ?',
  250 + params,
  251 + { prepare : true},
  252 + function(err, result) {
  253 + if(err) {
  254 + logEndpoint("get /activity/{id}", err, "Bad request");
  255 + return res.status(400).send("Bad Request")
  256 + } else {
  257 + if (result.rows.length != 0) {
  258 + logEndpoint("get /activity/{id}", err, "Success, activity returned");
  259 + return res.status(200).send(result.rows[0]);
  260 + } else {
  261 + logEndpoint("get /activity/{id}", err, "Success but activity not foound in database");
  262 + return res.status(204).send("Id not found in database");
  263 + }
  264 + }
207 } 265 }
208 - });  
209 -  
210 - })  
211 -  
212 - 266 + );
  267 + });
213 268
214 /** 269 /**
215 * See all activities 270 * See all activities
216 */ 271 */
217 app.get("/activity", function (req, res) { 272 app.get("/activity", function (req, res) {
218 273
219 - client.execute('SELECT * FROM risk.activity', [], function (err, result) {  
220 - if(err) {  
221 - console.log(err);  
222 - return res.status(400).send("Bad Request");  
223 -  
224 - } else {  
225 - if (result.rows.length != 0)  
226 - return res.status(200).send(result.rows);  
227 - else  
228 - return res.status(204).send("No registered activities"); 274 + db.execute('SELECT * ' +
  275 + 'FROM risk.activity',
  276 + function (err, result) {
  277 + if(err) {
  278 + logEndpoint("get /activity/", err, "Bad request");
  279 + return res.status(400).send("Bad Request");
  280 + } else {
  281 + if (result.rows.length != 0) {
  282 + logEndpoint("get /activity/", err, "Success, all activities returned");
  283 + return res.status(200).send(result.rows);
  284 + } else {
  285 + logEndpoint("get /activity/", err, "Success but no activities found in database");
  286 + return res.status(204).send("No registered activities");
  287 + }
  288 + }
229 } 289 }
230 -  
231 - })  
232 - 290 + );
233 }); 291 });
234 -  
235 -  
236 }; 292 };
237 293
238 /** 294 /**
@@ -240,35 +296,70 @@ var appRouter = function(app) { @@ -240,35 +296,70 @@ var appRouter = function(app) {
240 * @param contactPoint: cassandra contact point to connect to 296 * @param contactPoint: cassandra contact point to connect to
241 */ 297 */
242 function setupDatabase(contactPoint) { 298 function setupDatabase(contactPoint) {
243 - var client = new cassandra.Client({contactPoints: [contactPoint]});  
244 - client.connect(function (err, result) {  
245 - if(err) console.log("Could not connect to Cassandra at " + contactPoint);  
246 - console.log('Successfully connected to Cassandra at ' + contactPoint);  
247 - setupTables(client); 299 + var db = new cassandra.Client({contactPoints: [contactPoint]});
  300 + db.connect(function (err, result) {
  301 + if(err)
  302 + console.log("Could not connect to Cassandra at " + contactPoint);
  303 + else{
  304 + console.log('Successfully connected to Cassandra at ' + contactPoint);
  305 + setupTables(db);