Commit 6929ee593629c78f48452d543131c3d246f762ae

Authored by kristinlaahneolsen
1 parent f69d6506

Laget en ny kolonnefamilie, aksesslogg, som skal fungere som en slags sikring fo…

…r konfidensialitet. Dette er blitt brukt av helsenord, hvor pasienten selv kan følge med på hvem som har sett på journalen. Til nå fungerer Api, og har kommet så langt at jeg får hentet ut aksesslogg fra server. Mangler å lage ny aksesslog-entry ved at bruker klikker inn på hendelsene. Viktig at vi får laget det slik at vi sjekker at det er eieren av saken som får opp knappen om aksesslogg, og at det ikke blir logget noe hvis det er brukeren som er inne på saken
Risiko/app/src/main/AndroidManifest.xml
... ... @@ -26,10 +26,10 @@
26 26 <activity android:name="activity.Evaluations" />
27 27 <activity android:name="activity.SequenceOfActivities" />
28 28 <activity android:name="activity.EditIncident" />
29   - <activity android:name="activity.Log" />
30 29 <activity android:name="activity.EditEvaluation" />
31 30 <activity android:name="activity.EvaluationLog" />
32   - <activity android:name="activity.Information"></activity>
  31 + <activity android:name="activity.Information" />
  32 + <activity android:name="activity.Accesslog"></activity>
33 33 </application>
34 34  
35 35 </manifest>
36 36 \ No newline at end of file
... ...
Risiko/app/src/main/java/activity/Log.java renamed to Risiko/app/src/main/java/activity/Accesslog.java
... ... @@ -6,11 +6,25 @@ import android.os.Bundle;
6 6 import android.support.v7.widget.Toolbar;
7 7 import android.view.Menu;
8 8 import android.view.MenuItem;
  9 +import android.widget.ListView;
9 10 import android.widget.Toast;
10 11  
11 12 import com.risiko.risiko.R;
12 13  
13   -public class Log extends AppCompatActivity {
  14 +import java.util.ArrayList;
  15 +import java.util.List;
  16 +
  17 +import adapters.ListAdapterAccesslog;
  18 +import adapters.ListAdapterEvaluationLog;
  19 +import api.Api;
  20 +import dataclasses.*;
  21 +import dataclasses.EvaluationLog;
  22 +import retrofit2.Call;
  23 +import retrofit2.Callback;
  24 +import retrofit2.Response;
  25 +
  26 +public class Accesslog extends AppCompatActivity {
  27 + ListView lv;
14 28  
15 29 @Override
16 30 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -20,8 +34,42 @@ public class Log extends AppCompatActivity {
20 34 setSupportActionBar(myToolbar);
21 35  
22 36  
  37 + Api.get().getAccesslog("3caf2679-0ae3-4016-a8eb-39307a27c6fb").enqueue(new Callback<List<dataclasses.Accesslog>>() {
  38 + @Override
  39 + public void onResponse(Call<List<dataclasses.Accesslog>> call, Response<List<dataclasses.Accesslog>> response) {
  40 + if (response.isSuccessful()) {
  41 + List<dataclasses.Accesslog> log = response.body();
  42 + List<dataclasses.Accesslog> logs = new ArrayList<>();
  43 +
  44 + if (log != null) {
  45 + for (dataclasses.Accesslog e : log) {
  46 + logs.add(e);
  47 +
  48 + }
  49 +
  50 + insertLog(logs);
  51 + }
  52 + }
  53 +
  54 + }
  55 +
  56 + @Override
  57 + public void onFailure(Call<List<dataclasses.Accesslog>> call, Throwable t) {
  58 + t.printStackTrace();
  59 +
  60 + }
  61 + });
  62 +
  63 + }
  64 +
  65 + //TODO GJØRE DET SLIK AT VI FÅR SATT INN GRUPPENAVN i AKSSLOGGEN
  66 +
  67 + private void insertLog(List<dataclasses.Accesslog> log) {
  68 + lv = findViewById(R.id.lv_accesslog);
  69 + lv.setAdapter(new ListAdapterAccesslog(this, log));
23 70 }
24 71  
  72 +
25 73 @Override
26 74 public boolean onCreateOptionsMenu (Menu menu) {
27 75 getMenuInflater().inflate(R.menu.main, menu);
... ... @@ -34,7 +82,7 @@ public class Log extends AppCompatActivity {
34 82 switch (item.getItemId()) {
35 83 case R.id.action_logout:
36 84 //TODO: LEGG TIL LOGG-UT-FUNKSJON
37   - Toast.makeText(Log.this, "Logger ut",
  85 + Toast.makeText(Accesslog.this, "Logger ut",
38 86 Toast.LENGTH_LONG).show();
39 87 return true;
40 88  
... ...
Risiko/app/src/main/java/activity/Incident.java
... ... @@ -121,7 +121,7 @@ public class Incident extends AppCompatActivity {
121 121  
122 122 deleteEvent.setOnClickListener(view -> deleteEventDialog());
123 123 editEvent.setOnClickListener(view -> editIncident(chosenItem.getId(), chosenItem.getTitle(), chosenItem.getDate(), chosenItem.getDescription(), chosenItem.getLocation(), chosenItem.getAssociatedeval()));
124   - seeLog.setOnClickListener(view -> startActivity(new Intent(this, activity.Log.class)));
  124 + seeLog.setOnClickListener(view -> startActivity(new Intent(this, Accesslog.class)));
125 125  
126 126 System.out.println("EVALID" + chosenItem.getAssociatedeval());
127 127 Api.get().getEvaluation(chosenItem.getAssociatedeval()).enqueue(new Callback<Evaluation>() {
... ... @@ -159,6 +159,12 @@ public class Incident extends AppCompatActivity {
159 159  
160 160 }
161 161  
  162 + private void goToAccesslog(String id) {
  163 + Intent intentLog = new Intent(this, Log.class);
  164 + //intentLog.putExtra("associatedincitent", id);
  165 + startActivity(intentLog);
  166 + }
  167 +
162 168 private void editIncident(String id, String title, String date, String description, String location, String assosiatedEval) {
163 169 Intent intent = new Intent(this, EditIncident.class);
164 170 intent.putExtra("chosenEventId", id);
... ...
Risiko/app/src/main/java/adapters/ListAdapterAccesslog.java 0 → 100644
  1 +package adapters;
  2 +
  3 +import android.content.Context;
  4 +import android.support.annotation.NonNull;
  5 +import android.view.LayoutInflater;
  6 +import android.view.View;
  7 +import android.view.ViewGroup;
  8 +import android.widget.ArrayAdapter;
  9 +import android.widget.TextView;
  10 +
  11 +import com.risiko.risiko.R;
  12 +
  13 +import java.util.List;
  14 +
  15 +import dataclasses.Accesslog;
  16 +
  17 +
  18 +public class ListAdapterAccesslog extends ArrayAdapter<Accesslog> {
  19 +
  20 + public ListAdapterAccesslog(@NonNull Context context, List<Accesslog> log) {
  21 + super(context, R.layout.activity_log, log);
  22 + }
  23 +
  24 + @NonNull
  25 + @Override
  26 + public View getView(int position, View convertView, @NonNull ViewGroup parent) {
  27 + Accesslog accesslogg = getItem(position);
  28 + if (convertView == null) {
  29 + convertView = LayoutInflater.from(getContext()).inflate(R.layout.accessloglist, parent, false);
  30 + }
  31 +
  32 +
  33 +
  34 + TextView logDate = convertView.findViewById(R.id.tv_accesslog_date);
  35 + logDate.setText(accesslogg.getDate());
  36 +
  37 + TextView logName = convertView.findViewById(R.id.tv_accesslog_name);
  38 + logName.setText(accesslogg.getName());
  39 +
  40 + TextView logGroup = convertView.findViewById(R.id.tv_accesslog_group);
  41 + //TODO, HENT UT GRUPPENR
  42 + logGroup.setText("1");
  43 +
  44 +
  45 +
  46 +
  47 + return convertView;
  48 + }
  49 +
  50 +
  51 +
  52 +
  53 +}
  54 +
  55 +
  56 +
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -5,6 +5,7 @@ import java.util.HashMap;
5 5 import java.util.List;
6 6 import java.util.UUID;
7 7  
  8 +import dataclasses.Accesslog;
8 9 import dataclasses.Activity;
9 10 import dataclasses.Evaluation;
10 11 import dataclasses.EvaluationLog;
... ... @@ -30,6 +31,7 @@ public interface Endpoints {
30 31  
31 32 //HOS KRISTIN
32 33 String BASEURL = "http://192.168.84.71:3000/";
  34 + //String BASEURL = "http://172.20.10.2:3000/";
33 35  
34 36 //ØYVIN FIX
35 37 //String BASEURL ="http://risikoapi.harm.no/";
... ... @@ -84,4 +86,8 @@ public interface Endpoints {
84 86 @POST("evaluationlog")
85 87 Call<String> newLogEntry(@Field("name") String name, @Field("date") String date, @Field("changedfields") String changedfields, @Field("associatedeval") String associatedeval);
86 88  
  89 +
  90 + @GET("/incident/{associatedincident}/accesslog")
  91 + Call<List<Accesslog>> getAccesslog(@Path("associatedincident") String associatedincident);
  92 +
87 93 }
... ...
Risiko/app/src/main/java/dataclasses/Accesslog.java 0 → 100644
  1 +package dataclasses;
  2 +
  3 +/**
  4 + * Created by kristinlaahneolsen on 28.11.2018.
  5 + */
  6 +
  7 +public class Accesslog {
  8 + private String associatedincident;
  9 + private String name;
  10 + private int groupnr;
  11 + private String date;
  12 +
  13 + public Accesslog(String associatedincident, String name, int groupnr, String date) {
  14 + this.associatedincident = associatedincident;
  15 + this.name = name;
  16 + this.groupnr = groupnr;
  17 + this.date = date;
  18 +
  19 + }
  20 +
  21 + public String getAssociatedincident() {
  22 + return associatedincident;
  23 + }
  24 +
  25 + public void setAssociatedincident(String associatedincident) {
  26 + this.associatedincident = associatedincident;
  27 + }
  28 +
  29 + public String getName() {
  30 + return name;
  31 + }
  32 +
  33 + public void setName(String name) {
  34 + this.name = name;
  35 + }
  36 +
  37 + public int getGroupnr() {
  38 + return groupnr;
  39 + }
  40 +
  41 + public void setGroupnr(int groupnr) {
  42 + this.groupnr = groupnr;
  43 + }
  44 +
  45 + public String getDate() {
  46 + return date;
  47 + }
  48 +
  49 + public void setDate(String date) {
  50 + this.date = date;
  51 + }
  52 +
  53 +
  54 +}
... ...
Risiko/app/src/main/res/layout/accessloglist.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="wrap_content"
  5 + android:layout_margin="20dp"
  6 + android:orientation="horizontal">
  7 +
  8 + <LinearLayout
  9 + android:layout_width="match_parent"
  10 + android:layout_height="wrap_content"
  11 + android:orientation="vertical">
  12 +
  13 + <LinearLayout
  14 + android:layout_width="match_parent"
  15 + android:layout_height="wrap_content"
  16 + android:orientation="horizontal">
  17 +
  18 + <TextView
  19 + android:layout_alignParentLeft="true"
  20 + android:id="@+id/tv_accesslog_date"
  21 + android:layout_width="wrap_content"
  22 + android:layout_height="wrap_content"
  23 + android:layout_marginRight="10dp"
  24 + android:textSize="17dp"
  25 + android:text="Dato "/>
  26 +
  27 + <TextView
  28 + android:layout_alignParentLeft="true"
  29 + android:id="@+id/tv_accesslog_name"
  30 + android:layout_width="wrap_content"
  31 + android:layout_height="wrap_content"
  32 + android:layout_marginBottom="10dp"
  33 + android:textSize="17dp"
  34 + android:layout_marginRight="10dp"
  35 + android:text="Ola Nordmann"/>
  36 +
  37 + <TextView
  38 + android:layout_alignParentLeft="true"
  39 + android:id="@+id/tv_accesslog_group"
  40 + android:layout_width="wrap_content"
  41 + android:layout_height="wrap_content"
  42 + android:layout_marginBottom="10dp"
  43 + android:textSize="17dp"
  44 + android:text="Gruppe"/>
  45 +
  46 +
  47 + </LinearLayout>
  48 +
  49 +
  50 +
  51 + </LinearLayout>
  52 +
  53 +
  54 +
  55 +
  56 +
  57 +</RelativeLayout>
0 58 \ No newline at end of file
... ...
Risiko/app/src/main/res/layout/activity_log.xml
1 1 <?xml version="1.0" encoding="utf-8"?>
  2 +
2 3 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 4 xmlns:app="http://schemas.android.com/apk/res-auto"
4 5 xmlns:tools="http://schemas.android.com/tools"
5 6 android:layout_width="match_parent"
6   - android:layout_height="match_parent"
7   - tools:context="com.risiko.risiko.activity.Log">
  7 + android:layout_height="match_parent">
8 8  
9 9 <include layout="@layout/toolbar"/>
10 10  
11 11 <TextView
  12 + android:id="@+id/headline"
12 13 android:layout_width="wrap_content"
13 14 android:layout_height="wrap_content"
14   - android:text="HELLO"
15   - android:layout_marginTop="200dp"/>
  15 + android:text="@string/aksesslogg"
  16 + android:textStyle="bold"
  17 + android:textSize="25dp"
  18 + android:textColor="@color/colorPrimaryDark"
  19 + app:layout_constraintLeft_toLeftOf="parent"
  20 + app:layout_constraintRight_toRightOf="parent"
  21 + app:layout_constraintTop_toTopOf="parent"
  22 + android:layout_marginTop="70dp"
  23 + android:layout_marginBottom="100dp" />
  24 +
  25 +
  26 + <android.support.constraint.ConstraintLayout
  27 + app:layout_constraintTop_toBottomOf="@+id/headline"
  28 + android:layout_width="match_parent"
  29 + android:layout_height="match_parent"
  30 + android:layout_marginVertical="70dp"
  31 + android:layout_marginBottom="20dp">
  32 +
  33 +
  34 + <android.support.v4.widget.SwipeRefreshLayout
  35 + xmlns:android="http://schemas.android.com/apk/res/android"
  36 + android:id="@+id/swiperefresh"
  37 + android:layout_marginTop="50dp"
  38 + android:layout_width="match_parent"
  39 + android:layout_height="match_parent">
  40 +
  41 +
  42 + <LinearLayout
  43 + android:layout_marginTop="200dp"
  44 + android:background="@color/colorWhite"
  45 + android:layout_width="match_parent"
  46 + android:layout_height="match_parent"
  47 + android:orientation="vertical">
  48 +
  49 + <ListView
  50 + android:id="@+id/lv_accesslog"
  51 + android:layout_margin="10dp"
  52 + android:layout_width="match_parent"
  53 + android:layout_height="match_parent">
  54 + </ListView>
  55 +
  56 + </LinearLayout>
  57 + </android.support.v4.widget.SwipeRefreshLayout>
  58 +
  59 + </android.support.constraint.ConstraintLayout>
16 60  
17 61 </android.support.constraint.ConstraintLayout>
  62 +
... ...
Risiko/app/src/main/res/values/strings.xml
... ... @@ -40,6 +40,7 @@
40 40 <string name="areYouSureEvent">Er du sikker på at du vil slette denne hendelsen?</string>
41 41 <string name="added_by">Lagt til av:</string>
42 42 <string name="see_log">Se hendelseslogg</string>
  43 + <string name="aksesslogg">Aksesslogg</string>
43 44  
44 45  
45 46 </resources>
... ...
restApi/.idea/workspace.xml
... ... @@ -2,11 +2,18 @@
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/res/drawable/ic_info.xml" />
6   - <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/menu/info.xml" />
7   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/MainMenu.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/MainMenu.java" />
8   - <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/res/menu/main.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/menu/main.xml" />
  5 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Accesslog.java" />
  6 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/adapters/ListAdapterAccesslog.java" />
  7 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/dataclasses/Accesslog.java" />
  8 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/accessloglist.xml" />
  9 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" />
  10 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" />
  11 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Log.java" afterPath="" />
  12 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" />
  13 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/activity_log.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/activity_log.xml" />
  14 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/res/values/strings.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/values/strings.xml" />
9 15 <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
  16 + <change beforePath="$PROJECT_DIR$/api/routes/routes.js" afterPath="$PROJECT_DIR$/api/routes/routes.js" />
10 17 </list>
11 18 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
12 19 <option name="TRACKING_ENABLED" value="true" />
... ... @@ -54,8 +61,8 @@
54 61 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
55 62 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
56 63 <provider selected="true" editor-type-id="text-editor">
57   - <state relative-caret-position="395">
58   - <caret line="412" column="0" lean-forward="true" selection-start-line="412" selection-start-column="0" selection-end-line="412" selection-end-column="0" />
  64 + <state relative-caret-position="-179">
  65 + <caret line="415" column="13" lean-forward="true" selection-start-line="415" selection-start-column="13" selection-end-line="415" selection-end-column="52" />
59 66 <folding />
60 67 </state>
61 68 </provider>
... ... @@ -125,7 +132,7 @@
125 132 <path value="$PROJECT_DIR$/package.json" />
126 133 </packageJsonPaths>
127 134 </component>
128   - <component name="ProjectFrameBounds" extendedState="6" fullScreen="true">
  135 + <component name="ProjectFrameBounds" fullScreen="true">
129 136 <option name="width" value="450" />
130 137 <option name="height" value="900" />
131 138 </component>
... ... @@ -245,24 +252,24 @@
245 252 <workItem from="1541681303243" duration="9060000" />
246 253 <workItem from="1542189792461" duration="7537000" />
247 254 <workItem from="1542881688157" duration="372000" />
248   - <workItem from="1543226716067" duration="8181000" />
  255 + <workItem from="1543226716067" duration="9986000" />
249 256 </task>
250 257 <servers />
251 258 </component>
252 259 <component name="TimeTrackingManager">
253   - <option name="totallyTimeSpent" value="37872000" />
  260 + <option name="totallyTimeSpent" value="39677000" />
254 261 </component>
255 262 <component name="ToolWindowManager">
256   - <frame x="0" y="0" width="1030" height="900" extended-state="6" />
  263 + <frame x="0" y="0" width="1014" height="900" extended-state="0" />
257 264 <editor active="true" />
258 265 <layout>
259   - <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13676907" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
  266 + <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.1389728" sideWeight="0.69244605" order="0" side_tool="false" content_ui="combo" />
260 267 <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" />
261 268 <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" />
262 269 <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" />
263 270 <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" />
264 271 <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" />
265   - <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13676907" sideWeight="0.30755395" order="2" side_tool="true" content_ui="tabs" />
  272 + <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.1389728" sideWeight="0.30755395" order="2" side_tool="true" content_ui="tabs" />
266 273 <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" />
267 274 <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" />
268 275 <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" />
... ... @@ -369,8 +376,8 @@
369 376 </entry>
370 377 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
371 378 <provider selected="true" editor-type-id="text-editor">
372   - <state relative-caret-position="395">
373   - <caret line="412" column="0" lean-forward="true" selection-start-line="412" selection-start-column="0" selection-end-line="412" selection-end-column="0" />
  379 + <state relative-caret-position="-179">
  380 + <caret line="415" column="13" lean-forward="true" selection-start-line="415" selection-start-column="13" selection-end-line="415" selection-end-column="52" />
374 381 <folding />
375 382 </state>
376 383 </provider>
... ...
restApi/api/routes/routes.js
... ... @@ -409,6 +409,62 @@ var appRouter = function(app) {
409 409 }
410 410 });
411 411  
  412 +
  413 + /**
  414 + * See accesslog connected to a spesific incident
  415 + */
  416 + app.get("/incident/:associatedincident/accesslog", function (req, res) {
  417 + if (!req.params.associatedincident) {
  418 + logEndpoint("get /incident/{associatedincident}/accesslog", null, "ID missing");
  419 + return req.status(400).send("No id entered");
  420 + }
  421 +
  422 + const params = [req.params.associatedincident];
  423 + db.execute('SELECT * ' +
  424 + 'FROM risk.accesslog WHERE associatedincident = ? ALLOW FILTERING',
  425 + params,
  426 + { prepare : true},
  427 + function (err, result) {
  428 + if(err) {
  429 + logEndpoint("get /incident/:associatedincident/accesslog", err, "Bad request");
  430 + return res.status(400).send("Bad Request");
  431 + } else {
  432 + if (result.rows.length != 0) {
  433 + logEndpoint("get /incident/:associatedincident/accesslog", err, "Success, accesslog returned");
  434 + return res.status(200).send(result.rows);
  435 + } else {
  436 + logEndpoint("get /incident/:associatedincident/accesslog", err, "Success but no accesslog found in database");
  437 + return res.status(204).send("No logs");
  438 + }
  439 + }
  440 + }
  441 + );
  442 + });
  443 +
  444 +
  445 + /**
  446 + * New accesslogentry
  447 + */
  448 + app.post("/accesslog", function(req, res) {
  449 + if(!req.body.associatedincident || !req.body.name || !req.body.groupnr || !req.body.date) {
  450 + logEndpoint("post /accesslog", null, "Missing params in body");
  451 + return res.status(400).send("Missing params");
  452 + } else {
  453 + const query = 'INSERT INTO risk.accesslog(id, associatedincident, name, groupnr, date) ' +
  454 + 'VALUES(?,?,?,?,?)';
  455 + const params = [uuid(), req.body.associatedincident, req.body.name, req.body.groupnr, req.body.date];
  456 + db.execute(query, params, { prepare: true }, function (err) {
  457 + if (err) {
  458 + logEndpoint("post /access", err, "Bad request, see API log");
  459 + return res.status(400).send("Bad Request");
  460 + }
  461 + logEndpoint("post /accesslog", err, "Success, log created");
  462 + return res.status(200).send("Log Created");
  463 + })
  464 + }
  465 + });
  466 +
  467 +
412 468 };
413 469  
414 470 /**
... ... @@ -460,6 +516,10 @@ function setupTables(db) {
460 516 if (err) console.log("Failed to create table evaluationlog.\n" + err)
461 517 });
462 518  
  519 + db.execute("CREATE TABLE risk.accesslog(id uuid, associatedincident uuid, name text, groupnr int, date text, PRIMARY KEY(id));", function (err) {
  520 + if (err) console.log("Failed to create table accesslog.\n" + err)
  521 + });
  522 +
463 523 }
464 524 );
465 525 }
... ...