Commit 3a30cf416e9ac4c0dad400100d9cb7672cc7fbad

Authored by kristinlaahneolsen
1 parent d8c41850

Fått ordnet i Api det å hente ut log-objekter basert på hvilke evaluering logg-o…

…bjektene er knyttet til. Har også fått til å laget et endpoint som henter dette ut i app
Risiko/app/src/main/java/activity/EvaluationLog.java
... ... @@ -17,12 +17,17 @@ import java.util.List;
17 17  
18 18 import adapters.ListAdapterActivities;
19 19 import adapters.ListAdapterEvaluationLog;
  20 +import api.Api;
20 21 import dataclasses.Activity;
21 22 import dataclasses.Evaluation;
  23 +import retrofit2.Call;
  24 +import retrofit2.Callback;
  25 +import retrofit2.Response;
22 26  
23 27 public class EvaluationLog extends AppCompatActivity {
24 28 ListView lv;
25 29  
  30 +
26 31 @Override
27 32 protected void onCreate(Bundle savedInstanceState) {
28 33 super.onCreate(savedInstanceState);
... ... @@ -30,11 +35,42 @@ public class EvaluationLog extends AppCompatActivity {
30 35 Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
31 36 setSupportActionBar(myToolbar);
32 37  
33   -
  38 + Intent intent = getIntent();
  39 + Bundle b = intent.getExtras();
  40 + String assosiatedeval = b.getString("assosiatedeval");
  41 + System.out.println("ASSOSIATED EVAL" + assosiatedeval);
  42 +/*
34 43 List<dataclasses.EvaluationLog> log = new ArrayList<>();
35   - log.add(new dataclasses.EvaluationLog("Ola Nordmann", "2015-02-02", "Alle"));
36   - log.add(new dataclasses.EvaluationLog("Kari Nordmann", "2015-01-02", "Konsekvens"));
37   - insertLog(log);
  44 + log.add(new dataclasses.EvaluationLog("Ola Nordmann", "2015-02-02", "Alle", assosiatedeval));
  45 + log.add(new dataclasses.EvaluationLog("Kari Nordmann", "2015-01-02", "Tittel, konsekvens", assosiatedeval));
  46 + insertLog(log);*/
  47 +
  48 + Api.get().getEvaluationLog(assosiatedeval).enqueue(new Callback<List<dataclasses.EvaluationLog>>() {
  49 + @Override
  50 + public void onResponse(Call<List<dataclasses.EvaluationLog>> call, Response<List<dataclasses.EvaluationLog>> response) {
  51 + System.out.println("VÆÆÆR SÅ SNIIILL");
  52 + if (response.isSuccessful()) {
  53 + List<dataclasses.EvaluationLog> log = response.body();
  54 + List<dataclasses.EvaluationLog> logs = new ArrayList<>();
  55 +
  56 + if (log != null) {
  57 + for (dataclasses.EvaluationLog e : log) {
  58 + logs.add(e);
  59 +
  60 + }
  61 +
  62 + insertLog(logs);
  63 + }
  64 + }
  65 + }
  66 +
  67 +
  68 + @Override
  69 + public void onFailure(Call<List<dataclasses.EvaluationLog>> call, Throwable t) {
  70 + System.out.println("DIN DUST");
  71 +
  72 + }
  73 + });
38 74 }
39 75  
40 76 private void insertLog(List<dataclasses.EvaluationLog> log) {
... ...
Risiko/app/src/main/java/activity/Evaluations.java
... ... @@ -131,7 +131,8 @@ public class Evaluations extends AppCompatActivity {
131 131  
132 132 Button updateEvaluation = promptView.findViewById(R.id.pop_edit_evaluation);
133 133 Button evaluationLog = promptView.findViewById(R.id.pop_log);
134   - evaluationLog.setOnClickListener(view -> startActivity(new Intent(this, EvaluationLog.class)));
  134 +
  135 + evaluationLog.setOnClickListener(view -> evaluationlog(evaluation.getId()));
135 136 updateEvaluation.setOnClickListener(view -> editEvaluation(evaluation.getTitle(), evaluation.getOutcome(),
136 137 evaluation.getMeasures(), evaluation.getConsequence(), evaluation.getProbability(), evaluation.getId(), evaluation.getAssociatedactivity()));
137 138  
... ... @@ -171,6 +172,13 @@ public class Evaluations extends AppCompatActivity {
171 172 alert.show();
172 173 }
173 174  
  175 + private void evaluationlog(String id) {
  176 + System.out.println("SE PÅ DENNE ID: " + id);
  177 + Intent intent = new Intent(this, EvaluationLog.class);
  178 + intent.putExtra("assosiatedeval", id);
  179 + startActivity(intent);
  180 + }
  181 +
174 182 private void editEvaluation(String title, String outcome, String measures, int consequence, int probability, String id, String associatedactivity) {
175 183 Intent intent = new Intent(this, EditEvaluation.class);
176 184 intent.putExtra("title", title);
... ...
Risiko/app/src/main/java/adapters/ListAdapterEvaluationLog.java
... ... @@ -13,7 +13,6 @@ import com.risiko.risiko.R;
13 13  
14 14 import java.util.List;
15 15  
16   -import dataclasses.Activity;
17 16 import dataclasses.EvaluationLog;
18 17  
19 18 public class ListAdapterEvaluationLog extends ArrayAdapter<EvaluationLog> {
... ... @@ -37,7 +36,7 @@ public class ListAdapterEvaluationLog extends ArrayAdapter&lt;EvaluationLog&gt; {
37 36 logName.setText(log.getName());
38 37  
39 38 TextView logFieldsChanged = convertView.findViewById(R.id.tv_changed_fields);
40   - logFieldsChanged.setText(log.getChangedFields());
  39 + logFieldsChanged.setText(log.getChangedfields());
41 40  
42 41 return convertView;
43 42 }
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -7,6 +7,7 @@ import java.util.UUID;
7 7  
8 8 import dataclasses.Activity;
9 9 import dataclasses.Evaluation;
  10 +import dataclasses.EvaluationLog;
10 11 import dataclasses.Incident;
11 12 import retrofit2.Call;
12 13 import retrofit2.http.Body;
... ... @@ -77,4 +78,7 @@ public interface Endpoints {
77 78 @Field("title") String title, @Field("description") String description, @Field("associatedEval") String associatedEval);
78 79  
79 80  
  81 + @GET("evaluation/{assosiatedeval}/evaluationlog")
  82 + Call<List<EvaluationLog>> getEvaluationLog(@Path("assosiatedeval") String assosiatedeval);
  83 +
80 84 }
... ...
Risiko/app/src/main/java/dataclasses/EvaluationLog.java
... ... @@ -7,13 +7,15 @@ package dataclasses;
7 7 public class EvaluationLog {
8 8 private String name;
9 9 private String date;
10   - private String changedFields;
  10 + private String changedfields;
  11 + private String assosiatedeval;
11 12  
12 13  
13   - public EvaluationLog(String name, String date, String changedFields) {
  14 + public EvaluationLog(String name, String date, String changedfields, String assosiatedeval) {
14 15 this.name = name;
15 16 this.date = date;
16   - this.changedFields = changedFields;
  17 + this.changedfields = changedfields;
  18 + this.assosiatedeval = assosiatedeval;
17 19 }
18 20  
19 21 public String getName() {
... ... @@ -33,11 +35,19 @@ public class EvaluationLog {
33 35 this.date = date;
34 36 }
35 37  
36   - public String getChangedFields() {
37   - return changedFields;
  38 + public String getChangedfields() {
  39 + return changedfields;
38 40 }
39 41  
40   - public void setChangedFields(String changedFields) {
41   - this.changedFields = changedFields;
  42 + public void setChangedfields(String changedfields) {
  43 + this.changedfields = changedfields;
  44 + }
  45 +
  46 + public String getAssosiatedeval() {
  47 + return assosiatedeval;
  48 + }
  49 +
  50 + public void setAssosiatedeval(String assosiatedeval) {
  51 + this.assosiatedeval = assosiatedeval;
42 52 }
43 53 }
... ...
restApi/.idea/workspace.xml
... ... @@ -2,14 +2,7 @@
2 2 <project version="4">
3 3 <component name="ChangeListManager">
4 4 <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="">
5   - <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EvaluationLog.java" />
6   - <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/adapters/ListAdapterEvaluationLog.java" />
7   - <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/EvaluationLog.java" />
8   - <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/activity_evaluation_log.xml" />
9   - <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/evaluationloglist.xml" />
10   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" />
11   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditEvaluation.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditEvaluation.java" />
12   - <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
  5 + <change beforePath="$PROJECT_DIR$/api/routes/routes.js" afterPath="$PROJECT_DIR$/api/routes/routes.js" />
13 6 </list>
14 7 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
15 8 <option name="TRACKING_ENABLED" value="true" />
... ... @@ -57,8 +50,8 @@
57 50 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
58 51 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
59 52 <provider selected="true" editor-type-id="text-editor">
60   - <state relative-caret-position="4260">
61   - <caret line="284" column="25" lean-forward="true" selection-start-line="284" selection-start-column="25" selection-end-line="284" selection-end-column="25" />
  53 + <state relative-caret-position="169">
  54 + <caret line="367" column="35" lean-forward="false" selection-start-line="367" selection-start-column="35" selection-end-line="367" selection-end-column="35" />
62 55 <folding />
63 56 </state>
64 57 </provider>
... ... @@ -67,8 +60,8 @@
67 60 <file leaf-file-name="server.js" pinned="false" current-in-tab="false">
68 61 <entry file="file://$PROJECT_DIR$/server.js">
69 62 <provider selected="true" editor-type-id="text-editor">
70   - <state relative-caret-position="225">
71   - <caret line="15" column="17" lean-forward="false" selection-start-line="15" selection-start-column="17" selection-end-line="15" selection-end-column="17" />
  63 + <state relative-caret-position="105">
  64 + <caret line="7" column="47" lean-forward="false" selection-start-line="7" selection-start-column="47" selection-end-line="7" selection-end-column="47" />
72 65 <folding />
73 66 </state>
74 67 </provider>
... ... @@ -249,23 +242,24 @@
249 242 <workItem from="1541681303243" duration="9060000" />
250 243 <workItem from="1542189792461" duration="7537000" />
251 244 <workItem from="1542881688157" duration="372000" />
252   - <workItem from="1543226716067" duration="1426000" />
  245 + <workItem from="1543226716067" duration="4130000" />
253 246 </task>
254 247 <servers />
255 248 </component>
256 249 <component name="TimeTrackingManager">
257   - <option name="totallyTimeSpent" value="31117000" />
  250 + <option name="totallyTimeSpent" value="33821000" />
258 251 </component>
259 252 <component name="ToolWindowManager">
260   - <frame x="0" y="0" width="1440" height="900" extended-state="6" />
  253 + <frame x="0" y="0" width="1071" height="900" extended-state="6" />
  254 + <editor active="true" />
261 255 <layout>
262   - <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
  256 + <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2704762" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
263 257 <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" />
264 258 <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" />
265 259 <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="10" side_tool="true" content_ui="tabs" />
266   - <window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32769045" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
  260 + <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32769045" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
267 261 <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="8" side_tool="false" content_ui="tabs" />
268   - <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.30755395" order="2" side_tool="true" content_ui="tabs" />
  262 + <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2704762" sideWeight="0.30755395" order="2" side_tool="true" content_ui="tabs" />
269 263 <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" />
270 264 <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="9" side_tool="false" content_ui="tabs" />
271 265 <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" />
... ... @@ -364,16 +358,16 @@
364 358 </entry>
365 359 <entry file="file://$PROJECT_DIR$/server.js">
366 360 <provider selected="true" editor-type-id="text-editor">
367   - <state relative-caret-position="225">
368   - <caret line="15" column="17" lean-forward="false" selection-start-line="15" selection-start-column="17" selection-end-line="15" selection-end-column="17" />
  361 + <state relative-caret-position="105">
  362 + <caret line="7" column="47" lean-forward="false" selection-start-line="7" selection-start-column="47" selection-end-line="7" selection-end-column="47" />
369 363 <folding />
370 364 </state>
371 365 </provider>
372 366 </entry>
373 367 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
374 368 <provider selected="true" editor-type-id="text-editor">
375   - <state relative-caret-position="4260">
376   - <caret line="284" column="25" lean-forward="true" selection-start-line="284" selection-start-column="25" selection-end-line="284" selection-end-column="25" />
  369 + <state relative-caret-position="169">
  370 + <caret line="367" column="35" lean-forward="false" selection-start-line="367" selection-start-column="35" selection-end-line="367" selection-end-column="35" />
377 371 <folding />
378 372 </state>
379 373 </provider>
... ...
restApi/api/routes/routes.js
... ... @@ -334,6 +334,7 @@ var appRouter = function(app) {
334 334 */
335 335 app.get("/activity", function (req, res) {
336 336  
  337 +
337 338 db.execute('SELECT * ' +
338 339 'FROM risk.activity',
339 340 function (err, result) {
... ... @@ -351,6 +352,39 @@ var appRouter = function(app) {
351 352 }
352 353 }
353 354 );
  355 + })
  356 +
  357 +
  358 +
  359 + /**
  360 + * See evaluationlog
  361 + */
  362 + app.get("/evaluation/:assosiatedeval/evaluationlog", function (req, res) {
  363 + if (!req.params.assosiatedeval) {
  364 + logEndpoint("get /evaluation/{id}/evaluationlog", null, "ID missing");
  365 + return req.status(400).send("No id entered");
  366 + }
  367 +
  368 + const params = [req.params.assosiatedeval];
  369 + db.execute('SELECT * ' +
  370 + 'FROM risk.evaluationlog WHERE associatedeval = ? ALLOW FILTERING',
  371 + params,
  372 + { prepare : true},
  373 + function (err, result) {
  374 + if(err) {
  375 + logEndpoint("get /evaluation/::assosiatedeval/evaluationlog", err, "Bad request");
  376 + return res.status(400).send("Bad Request");
  377 + } else {
  378 + if (result.rows.length != 0) {
  379 + logEndpoint("get /evaluation/::assosiatedeval/evaluationlog", err, "Success, evaluationlog returned");
  380 + return res.status(200).send(result.rows);
  381 + } else {
  382 + logEndpoint("get /evaluation/::assosiatedeval/evaluationlog", err, "Success but no evaluationlogs found in database");
  383 + return res.status(204).send("No logs");
  384 + }
  385 + }
  386 + }
  387 + );
354 388 });
355 389 };
356 390  
... ... @@ -394,9 +428,15 @@ function setupTables(db) {
394 428 else {
395 429 insertActivity(db, 'Kjore bil');
396 430 insertActivity(db, 'Drikke alkohol');
  431 + insertActivity(db, 'Gi blodtrykksmedisin');
397 432 insertActivity(db, 'Gjore noe');
398 433 }
399 434 });
  435 +
  436 + db.execute("CREATE TABLE risk.evaluationlog(id uuid, name text, date text, changedfields text, associatedEval uuid, PRIMARY KEY(id));", function (err) {
  437 + if (err) console.log("Failed to create table evaluationlog.\n" + err)
  438 + });
  439 +
400 440 }
401 441 );
402 442 }
... ...