Commit 4db99cdc7175857565341fed71a914017c081a35

Authored by kristinlaahneolsen
1 parent a235e595

Har tatt høyde for sletting av vurderinger i API, men her kom jeg over det probl…

…emet at hendelser er knyttet til risikoer, og vil få systemet til å kræsje hvis man sletter en vurdering som har en hendelse knyttet opp mot seg. Siden dette ikke har vært et krav i oppgaven, så foreslår jeg at vi avventer med å lage en fiks på dette til vi er ferdig med de faktiske kravene. Jeg har også begynt på dataklasse for brukere, ut i fra hvordan jeg ser for meg det bør være. Så, branchnavnet var misvisende iom at jeg avventer med integritet fram til autentisering er på plass
Risiko/app/src/main/java/activity/Activities.java
... ... @@ -31,18 +31,6 @@ public class Activities extends AppCompatActivity {
31 31 Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
32 32 setSupportActionBar(myToolbar);
33 33  
34   -
35   - /* //TODO Bytte ut Mockdata på sikt
36   - ArrayList<Activity> activityList = new ArrayList<>();
37   - activityList.add(new Activity(1, "Gi blodtrykksmedisin"));
38   - activityList.add(new Activity(2, "Kjøre bil"));
39   - activityList.add(new Activity(3, "Dosering av smertestillende"));
40   - activityList.add(new Activity(4, "Gå ned trappen"));
41   - insertActivities(activityList);*/
42   -
43   -
44   - //TESTING AV RETROFIT: FUNKER KUN VED Å BRUKE DELING AV MOBILNETT
45   -
46 34 Api.get().getAllActivities()
47 35 .enqueue(new Callback<List<Activity>>() {
48 36 @Override
... ...
Risiko/app/src/main/java/activity/Evaluations.java
... ... @@ -53,7 +53,6 @@ public class Evaluations extends AppCompatActivity {
53 53 String activityId = intent.getStringExtra("ID_OF_CHOSEN_ACTIVITY");
54 54 System.out.println(activityId);
55 55  
56   - //TESTING AV RETROFIT: FUNKER KUN VED Å BRUKE DELING AV MOBILNETT
57 56  
58 57 Api.get().getAllEvaluations()
59 58 .enqueue(new Callback<List<Evaluation>>() {
... ... @@ -70,7 +69,6 @@ public class Evaluations extends AppCompatActivity {
70 69 if (e.getAssociatedactivity().equals(activityId))
71 70 associatedEvaluations.add(e);
72 71 id = e.getId();
73   - //System.out.println("HALLOOOOOOOO" + uuid);
74 72 }
75 73 }
76 74 insertEvaluations(associatedEvaluations);
... ... @@ -128,13 +126,11 @@ public class Evaluations extends AppCompatActivity {
128 126 TextView probabilityLow = promptView.findViewById(R.id.pop_probability_low);
129 127 TextView probabilityMedium = promptView.findViewById(R.id.pop_probability_medium);
130 128 TextView probabilityHigh = promptView.findViewById(R.id.pop_probability_high);
131   - Button deleteEvaluation = promptView.findViewById(R.id.pop_delete_evaluation);
132   -
133 129 //TODO: IMPLEMENTERE DET SLIK AT VI FÅR HENTET UT HVILKEN BRUKER SOM HAR SKREVET SAKEN
134 130 TextView addedBy = promptView.findViewById(R.id.tv_added_by);
135 131  
136   - deleteEvaluation.setOnClickListener(view -> deleteEvaluationDialog());
137   -
  132 + //Button deleteEvaluation = promptView.findViewById(R.id.pop_delete_evaluation);
  133 + //deleteEvaluation.setOnClickListener(view -> deleteEvaluationDialog());
138 134  
139 135  
140 136 if (evaluation.getProbability() == 3) {
... ... @@ -173,6 +169,11 @@ public class Evaluations extends AppCompatActivity {
173 169 alert.show();
174 170 }
175 171  
  172 +
  173 + //TODO: Hvis vi får tid, må vi se på denne delen. Det bør ikke være mulig å slette en vurdering som har en hendelse knyttet opp til seg
  174 + //TODO: Derfor er denne delen av koden kommentert ut
  175 +
  176 + /*
176 177 private void deleteEvaluationDialog() {
177 178 new AlertDialog.Builder(this)
178 179 .setTitle(R.string.delete)
... ... @@ -182,8 +183,6 @@ public class Evaluations extends AppCompatActivity {
182 183 public void onClick(DialogInterface dialogInterface, int i) {
183 184 finish();
184 185  
185   - /*
186   - //TODO: HER ER DET KLART FOR SLETTING AV VURDERING HVIS VI TAR HØYDE FOR DET I API. OBS, bytt ut id med rett string
187 186 Api.get().deleteEvaluation(id).enqueue(new Callback<String>() {
188 187 @Override
189 188 public void onResponse(Call<String> call, Response<String> response) {
... ... @@ -196,13 +195,15 @@ public class Evaluations extends AppCompatActivity {
196 195 Log.d("Error", t.getMessage());
197 196 finish();
198 197 }
199   - });*/
  198 + });
200 199 }
201 200 })
202 201 .setNegativeButton(R.string.no, null)
203 202 .show();
204 203 }
205 204  
  205 + */
  206 +
206 207 @Override
207 208 public boolean onCreateOptionsMenu (Menu menu) {
208 209 getMenuInflater().inflate(R.menu.main, menu);
... ...
Risiko/app/src/main/java/activity/Incident.java
... ... @@ -100,6 +100,20 @@ public class Incident extends AppCompatActivity {
100 100 Button deleteEvent = promptView.findViewById(R.id.pop_delete_event);
101 101 Button editEvent = promptView.findViewById(R.id.pop_edit_event);
102 102  
  103 + //TODO TEST PÅ HASH
  104 + MessageDigest md = null;
  105 + try {
  106 + md = MessageDigest.getInstance("SHA-512");
  107 + } catch (NoSuchAlgorithmException e) {
  108 + System.out.println("FEIL MED HASH ");
  109 + }
  110 + byte[] digest = md.digest(chosenItem.getDescription().getBytes());
  111 + StringBuilder sb = new StringBuilder();
  112 + for (int i = 0; i<digest.length; i++) {
  113 + sb.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
  114 + }
  115 + System.out.println("SUKSESS MED HASH" + sb);
  116 +
103 117  
104 118 //TODO: IMPLEMENTERE DET SLIK AT VI FÅR HENTET UT HVILKEN BRUKER SOM HAR SKREVET SAKEN
105 119 TextView addedBy = promptView.findViewById(R.id.tv_added_by);
... ... @@ -125,19 +139,7 @@ public class Incident extends AppCompatActivity {
125 139 });
126 140  
127 141  
128   - //TODO TEST PÅ HASH
129   - MessageDigest md = null;
130   - try {
131   - md = MessageDigest.getInstance("SHA-512");
132   - } catch (NoSuchAlgorithmException e) {
133   - System.out.println("FEIL MED HASH ");
134   - }
135   - byte[] digest = md.digest(chosenItem.getDescription().getBytes());
136   - StringBuilder sb = new StringBuilder();
137   - for (int i = 0; i<digest.length; i++) {
138   - sb.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
139   - }
140   - System.out.println("SUKSESS MED HASH" + sb);
  142 +
141 143  
142 144  
143 145 tvTitle.setText(chosenItem.getTitle());
... ... @@ -177,7 +179,6 @@ public class Incident extends AppCompatActivity {
177 179 @Override
178 180 public void onClick(DialogInterface dialogInterface, int i) {
179 181  
180   - //TODO: ORDNE DETTE SLIK AT VURDERINGER FAKTISK BLIR SLETTET. MÅ HENTE UT UUID
181 182 Api.get().deleteIncident(chosenEventId).enqueue(new Callback<String>() {
182 183 @Override
183 184 public void onResponse(Call<String> call, Response<String> response) {
... ... @@ -197,11 +198,6 @@ public class Incident extends AppCompatActivity {
197 198 .show();
198 199 }
199 200  
200   -<<<<<<< HEAD
201   -
202   -
203   -
204   -=======
205 201 @Override
206 202 public boolean onCreateOptionsMenu (Menu menu) {
207 203 getMenuInflater().inflate(R.menu.main, menu);
... ... @@ -227,6 +223,5 @@ public class Incident extends AppCompatActivity {
227 223  
228 224 }
229 225 }
230   ->>>>>>> usability_improvements
231 226  
232 227 }
... ...
Risiko/app/src/main/java/dataclasses/User.java 0 → 100644
  1 +package dataclasses;
  2 +
  3 +/**
  4 + * Created by kristinlaahneolsen on 22.11.2018.
  5 + */
  6 +
  7 +public class User {
  8 +
  9 + public static final int READACCESS_ALL = 1, READACESS_NURSE_ANESTHETIST = 2, READACCESS_CHILD_NURSE = 3,
  10 + READACCESS_ALL_TYPES_NURSE = 4, READACCESS_DOCTOR = 5, READACCESS_CONSULTANT = 6, READACCESS_PARAMEDICS = 7;
  11 +
  12 + String userId;
  13 + String userName;
  14 + String firstname;
  15 + String lastname;
  16 + int groupNumber; //TODO: Gruppenummer er bare en lett måte å kunne implementere dette med begrenset innsyn
  17 + Boolean isOwner; //TODO: Tenker vi må lage høyde for en sjekk på om bruker er eier av en sak, slik at vi kan bruke det for å se om de har rettigheter til å endre/slette en sak
  18 +
  19 + public User(String userId, String userName, String firstname, String lastname, int groupNumber, Boolean isOwner) {
  20 + this.userId = userId;
  21 + this.userName = userName;
  22 + this.firstname = firstname;
  23 + this.lastname = lastname;
  24 + this.groupNumber = groupNumber;
  25 + this.isOwner = isOwner;
  26 + }
  27 +
  28 + public String getUserId() {
  29 + return userId;
  30 + }
  31 +
  32 + public void setUserId(String userId) {
  33 + this.userId = userId;
  34 + }
  35 +
  36 + public String getFirstname() {
  37 + return firstname;
  38 + }
  39 +
  40 + public void setFirstname(String firstname) {
  41 + this.firstname = firstname;
  42 + }
  43 +
  44 + public String getLastname() {
  45 + return lastname;
  46 + }
  47 +
  48 + public void setLastname(String lastname) {
  49 + this.lastname = lastname;
  50 + }
  51 +
  52 + public int getGroupNumber() {
  53 + return groupNumber;
  54 + }
  55 +
  56 + public void setGroupNumber(int groupNumber) {
  57 + this.groupNumber = groupNumber;
  58 + }
  59 +
  60 + public Boolean getOwner() {
  61 + return isOwner;
  62 + }
  63 +
  64 + public void setOwner(Boolean owner) {
  65 + isOwner = owner;
  66 + }
  67 +
  68 +
  69 + public String getReadAccessString() {
  70 + switch (groupNumber) {
  71 + case READACCESS_ALL: return "All helsepersonell";
  72 + case READACESS_NURSE_ANESTHETIST: return "Anestiesisykepleier";
  73 + case READACCESS_CHILD_NURSE: return "Barnesykepleier";
  74 + case READACCESS_ALL_TYPES_NURSE: return "Alle typer sykepleiere";
  75 + case READACCESS_DOCTOR: return "Lege";
  76 + case READACCESS_CONSULTANT: return "Overlege";
  77 + case READACCESS_PARAMEDICS: return "Ambulansepersonell";
  78 + default: return "Ukjent";
  79 + }
  80 + }
  81 +
  82 +
  83 +
  84 +
  85 +}
  86 +
  87 +
... ...
Risiko/app/src/main/res/layout/popup_evaluation.xml
... ... @@ -36,11 +36,6 @@
36 36 android:layout_height="30dp"
37 37 android:background="@drawable/ic_delete"/>
38 38  
39   - <Button
40   - android:id="@+id/pop_edit_evaluation"
41   - android:layout_width="30dp"
42   - android:layout_height="30dp"
43   - android:background="@drawable/ic_edit"/>
44 39 </LinearLayout>
45 40  
46 41 </LinearLayout>
... ...
restApi/.idea/workspace.xml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <project version="4">
3 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$/../Risiko/app/src/main/java/activity/Incident.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" />
  6 + <change beforePath="$PROJECT_DIR$/api/routes/routes.js" afterPath="$PROJECT_DIR$/api/routes/routes.js" />
  7 + </list>
5 8 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
6 9 <option name="TRACKING_ENABLED" value="true" />
7 10 <option name="SHOW_DIALOG" value="false" />
... ... @@ -48,8 +51,8 @@
48 51 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
49 52 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
50 53 <provider selected="true" editor-type-id="text-editor">
51   - <state relative-caret-position="592">
52   - <caret line="126" column="46" lean-forward="false" selection-start-line="126" selection-start-column="46" selection-end-line="126" selection-end-column="46" />
  54 + <state relative-caret-position="424">
  55 + <caret line="263" column="4" lean-forward="true" selection-start-line="263" selection-start-column="4" selection-end-line="263" selection-end-column="4" />
53 56 <folding />
54 57 </state>
55 58 </provider>
... ... @@ -99,7 +102,7 @@
99 102 <path value="$PROJECT_DIR$/package.json" />
100 103 </packageJsonPaths>
101 104 </component>
102   - <component name="ProjectFrameBounds" extendedState="6">
  105 + <component name="ProjectFrameBounds" fullScreen="true">
103 106 <option name="y" value="23" />
104 107 <option name="width" value="1440" />
105 108 <option name="height" value="873" />
... ... @@ -120,7 +123,6 @@
120 123 </navigator>
121 124 <panes>
122 125 <pane id="Scope" />
123   - <pane id="Scratches" />
124 126 <pane id="ProjectPane">
125 127 <subPane>
126 128 <expand>
... ... @@ -149,6 +151,7 @@
149 151 <select />
150 152 </subPane>
151 153 </pane>
  154 + <pane id="Scratches" />
152 155 </panes>
153 156 </component>
154 157 <component name="PropertiesComponent">
... ... @@ -219,23 +222,24 @@
219 222 <workItem from="1541596156631" duration="9351000" />
220 223 <workItem from="1541681303243" duration="9060000" />
221 224 <workItem from="1542189792461" duration="7537000" />
  225 + <workItem from="1542881688157" duration="125000" />
222 226 </task>
223 227 <servers />
224 228 </component>
225 229 <component name="TimeTrackingManager">
226   - <option name="totallyTimeSpent" value="29319000" />
  230 + <option name="totallyTimeSpent" value="29444000" />
227 231 </component>
228 232 <component name="ToolWindowManager">
229   - <frame x="0" y="23" width="1440" height="873" extended-state="6" />
  233 + <frame x="0" y="0" width="1440" height="900" extended-state="6" />
  234 + <editor active="true" />
230 235 <layout>
231   - <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.71128106" order="0" side_tool="false" content_ui="combo" />
  236 + <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.70495766" order="0" side_tool="false" content_ui="combo" />
232 237 <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" />
233 238 <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" />
234 239 <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" />
235   - <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" />
236 240 <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3277635" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
237 241 <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" />
238   - <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.28871894" order="2" side_tool="true" content_ui="tabs" />
  242 + <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.29504234" order="2" side_tool="true" content_ui="tabs" />
239 243 <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" />
240 244 <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" />
241 245 <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" />
... ... @@ -246,6 +250,7 @@
246 250 <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" />
247 251 <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" />
248 252 <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" />
  253 + <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" />
249 254 <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" />
250 255 </layout>
251 256 </component>
... ... @@ -285,8 +290,8 @@
285 290 </entry>
286 291 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
287 292 <provider selected="true" editor-type-id="text-editor">
288   - <state relative-caret-position="592">
289   - <caret line="126" column="46" lean-forward="false" selection-start-line="126" selection-start-column="46" selection-end-line="126" selection-end-column="46" />
  293 + <state relative-caret-position="424">
  294 + <caret line="263" column="4" lean-forward="true" selection-start-line="263" selection-start-column="4" selection-end-line="263" selection-end-column="4" />
290 295 <folding />
291 296 </state>
292 297 </provider>
... ...
restApi/api/routes/routes.js
... ... @@ -154,6 +154,7 @@ var appRouter = function(app) {
154 154 );
155 155 });
156 156  
  157 +
157 158 /**
158 159 * See an evaluation with id x
159 160 */
... ... @@ -234,6 +235,34 @@ var appRouter = function(app) {
234 235 }
235 236 });
236 237  
  238 +
  239 + /**
  240 + * Delete an evaluation (a delete request at http://localhost:3000/incident/{id} should delete incident with the id passed in)
  241 + */
  242 +
  243 + app.delete("/evaluation/:id", function (req, res) {
  244 + if (!req.params.id) {
  245 + logEndpoint("delete /evaluation", null, "ID missing");
  246 + return res.status(400).send("Missing id");
  247 + }
  248 +
  249 + const params = [req.params.id];
  250 + db.execute("DELETE FROM risk.evaluation " +
  251 + "WHERE id = ?",
  252 + params,
  253 + { prepare: true },
  254 + function (err) {
  255 + if (err) {
  256 + logEndpoint("delete /evaluation", err, "Bad request, see API log");
  257 + return res.status(400).send("Bad request");
  258 + }
  259 + logEndpoint("delete /evaluation", err, "Success, evaluation deleted");
  260 + return res.status(200).send("Evaluation deleted");
  261 + }
  262 + );
  263 + });
  264 +
  265 +
237 266 /**
238 267 * See an activity with id x
239 268 */
... ...