diff --git a/.DS_Store b/.DS_Store index 294fae28b3b91fc4fff6f7b71e7ea99379b5b707..a7cc044258099c475a7c644624015d3e6d174cfb 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Node/Node.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Node/Node.java index 7bfb06a310f512c5a11a32c9a9ac3da7dd4b748e..1c4df8ae75044e8065bbda3f2e53b931cb6b96ac 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Node/Node.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Node/Node.java @@ -1,5 +1,6 @@ package com.joelhelkala.watcherGui.Nodes.Node; +import java.awt.LayoutManager; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -9,9 +10,6 @@ import org.json.JSONObject; import com.joelhelkala.watcherGui.Nodes.Node.NodeData.NodeData; -/* - * Class that handles node information - */ public class Node { private String description; private String location; @@ -59,7 +57,6 @@ public class Node { } } - // get all of the measurements public List<NodeData> getData() { return data; } // Gets the temperature reading of the most recent measurement @@ -69,28 +66,26 @@ public class Node { return data.getTemperature(); } - // Get the most recent humidity data public Integer getRecentHumidity() { NodeData data = findRecentData(); if(data == null) return 0; return data.getHumidity(); } - // Get the most recent luminosity data + public Integer getRecentLuminosity() { NodeData data = findRecentData(); if(data == null) return 0; return data.getLuminosity(); } - // Get the date of the most recent measurement + public LocalDateTime getRecentDate() { NodeData data = findRecentData(); if(data == null) return null; return data.getTime(); } - // Get the newest data from a measurement private NodeData findRecentData() { if(data.size() == 0) return null; NodeData newest = data.get(0); @@ -107,7 +102,6 @@ public class Node { public Float getLatitude() { return latitude; } public Float getLongitude() { return longitude; } - // Update the nodes measurements public void updateData(JSONArray nodeData) { data = new ArrayList<NodeData>(); if(nodeData.length() == 0) return; diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Node/NodeData/NodeData.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Node/NodeData/NodeData.java index 93727649aa233ffddc68fa01f486e7ecbe61bfdf..9847fadac4e88b6053f7cf4e02f10f3b5d336297 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Node/NodeData/NodeData.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Node/NodeData/NodeData.java @@ -2,16 +2,12 @@ package com.joelhelkala.watcherGui.Nodes.Node.NodeData; import java.time.LocalDateTime; -/* - * Helper class for nodeData - */ public class NodeData { private final LocalDateTime measured_at; private final Integer temperature; private final Integer humidity; private final Integer luminosity; - // Default constructor public NodeData() { this.measured_at = null; this.temperature = null; @@ -19,7 +15,6 @@ public class NodeData { this.luminosity = null; } - // Constructor with data public NodeData(LocalDateTime measured_at, Integer temperature, Integer humidity, Integer luminosity) { this.measured_at = measured_at; this.temperature = temperature; @@ -27,7 +22,6 @@ public class NodeData { this.luminosity = luminosity; } - // GETTERS public LocalDateTime getTime() { return measured_at; } diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Nodes.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Nodes.java index 4530f2ce4c848c6da417169cb54d5d274ea44d87..1562a3a3c784ee483e0c00182555d4db6521842b 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Nodes.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Nodes.java @@ -6,11 +6,7 @@ import java.util.List; import com.joelhelkala.watcherGui.Nodes.Node.Node; import com.joelhelkala.watcherGui.httpRequests.HttpRequests; -/* - * Class to handle nodes - */ public class Nodes { - // list of the nodes private static List<Node> nodes = new ArrayList<Node>(); // Add a list of nodes @@ -25,22 +21,18 @@ public class Nodes { nodes.add(node); } - // get the amount of nodes public static int size() { return nodes.size(); } - // get the node at given index public static Node get(int index) { return nodes.get(index); } - // get all of the nodes public static List<Node> getAll() { return nodes; } - // get a node which matches the location given public static Node findByLocation(String location) { for(Node n : nodes) { if(n.getLocation() == location) return n; @@ -48,7 +40,6 @@ public class Nodes { return null; } - // reset nodes and get updated ones from server public static void updateNodes() { nodes.clear(); AddNodes(HttpRequests.getNodes()); diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/RegisterPage.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/RegisterPage.java index 7592e9ffec016b104f444f5c61182ff36e93e08e..a2d19cecce296716474243b0014d1786eff8f898 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/RegisterPage.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/RegisterPage.java @@ -23,7 +23,6 @@ public class RegisterPage implements ActionListener, KeyListener { private JButton cancelButton; private JButton confirmButton; - // Constructor RegisterPage(){ welcomeLabel.setBounds(122,32,200,35); welcomeLabel.setFont(new Font(null,Font.PLAIN,25)); @@ -101,9 +100,6 @@ public class RegisterPage implements ActionListener, KeyListener { } - /* - * Check if the cancel or confirm button has been pressed - */ public void actionPerformed(ActionEvent e) { if(e.getSource() == cancelButton) { frame.dispose(); @@ -123,9 +119,6 @@ public class RegisterPage implements ActionListener, KeyListener { } } - /* - * Validate a given email - */ private boolean validateEmail(String email) { // TODO: Create regex for email verification if (email.length() > 0) return true; @@ -148,10 +141,6 @@ public class RegisterPage implements ActionListener, KeyListener { return true; } - /* - * When a key is released then check if form is valid and - * set the confirm button as enabled if it is - */ public void keyReleased(KeyEvent e) { if(validateForm()) confirmButton.setEnabled(true); else confirmButton.setEnabled(false); diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/WelcomePage.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/WelcomePage.java index ba3e90b59e608b0ee0027e2bfee1e87d52aa5c2e..a6885d013d4b27d9bc63bfaa933736640fa521f1 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/WelcomePage.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/WelcomePage.java @@ -49,7 +49,6 @@ public class WelcomePage implements MouseListener, ActionListener { private static NodeDataFrame nodeDataFrame = new NodeDataFrame(leftPanelWidth, topPanelHeight, width-leftPanelWidth, height-topPanelHeight-bottomPanelHeight); private static NodeSettingsFrame nodeSettingFrame = new NodeSettingsFrame(width-leftPanelWidth, height-topPanelHeight-bottomPanelHeight); - // Constructor public WelcomePage(){ Nodes.updateNodes(); @@ -234,14 +233,12 @@ public class WelcomePage implements MouseListener, ActionListener { frame.setVisible(true); } - // When mouse is hovering on a navbar element then change the color @Override public void mouseEntered(MouseEvent arg0) { Object target = arg0.getSource(); ((JComponent) target).setBackground(darkwhite); } - // When mouse leaves a navbar element then reset the color unless it is the currently chosen tab @Override public void mouseExited(MouseEvent arg0) { Object target = arg0.getSource(); @@ -345,9 +342,6 @@ public class WelcomePage implements MouseListener, ActionListener { } - /* - * A dialog that reports of a timeout and logs the user out - */ public static void TimedOutSession() { String message = "\"The session has timed out.\"\n" + "You will be logged out..."; diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/FriendsFrame.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/FriendsFrame.java index 8152dc66f203a8e72d88d30c4e3efbb8bedadcec..4b7a2f527d56f64a7166f8e48ccd99f8b1a8067e 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/FriendsFrame.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/FriendsFrame.java @@ -8,13 +8,9 @@ import javax.swing.SwingConstants; import java.awt.BorderLayout; -/* - * A tab for friends - */ public class FriendsFrame extends JPanel { private static final Color gray = new Color(45, 45, 45); - // Constructor public FriendsFrame(int x, int y, int width, int height) { setLayout(new BorderLayout()); setBounds(x,y,width,height); diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/NodeDataFrame.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/NodeDataFrame.java index 356a8fd0f5309fc2bcce9810346280ba43728521..476f076023e9b9b84c88d50f4a319a2279d4ce40 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/NodeDataFrame.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/NodeDataFrame.java @@ -13,9 +13,6 @@ import com.joelhelkala.watcherGui.frames.panels.ProgressBarCirclePanel; import com.joelhelkala.watcherGui.frames.panels.TemperaturePanel; import com.joelhelkala.watcherGui.httpRequests.HttpRequests; -/* - * A tab for data visualization - */ public class NodeDataFrame extends JPanel { private static final int cardWidth = 300; @@ -29,7 +26,6 @@ public class NodeDataFrame extends JPanel { private LuminosityPanel lumiCard; private LineChartPanel chartCard; - // Constructor public NodeDataFrame(int x, int y, int width, int height) { setLayout(null); setBounds(x,y,width,height); diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/NodeSettingsFrame.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/NodeSettingsFrame.java index 35e4e3ccea7464f5a909679b9faf2aa153e1077f..643e0e488547bc038f7033fdba777b607e171e8d 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/NodeSettingsFrame.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/subframes/NodeSettingsFrame.java @@ -20,9 +20,6 @@ import java.awt.GridLayout; import java.awt.BorderLayout; import java.awt.event.*; -/* - * A tab for updating nodes - */ public class NodeSettingsFrame extends JPanel implements ActionListener{ private static final Color gray = new Color(45, 45, 45); private JTextField descField = new JTextField(); diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/httpRequests/HttpRequests.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/httpRequests/HttpRequests.java index 7235dafef29cf7a039edc632f192f45cb589eeb0..4baefa7a367f473751be521ab4bab033d21401e2 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/httpRequests/HttpRequests.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/httpRequests/HttpRequests.java @@ -264,7 +264,6 @@ public class HttpRequests { int status = con.getResponseCode(); con.disconnect(); if(status < 300) success = true; - // if status code is 403 (unauthorized) then session has expired and logout else if (status == 403) { WelcomePage.TimedOutSession(); // Set success to true so error dialog wont be shown diff --git a/arduinoSensor/arduinoSensor.ino b/arduinoSensor/arduinoSensor.ino deleted file mode 100644 index 1c2629858e3d4186a57696c62ba726876829b3cf..0000000000000000000000000000000000000000 --- a/arduinoSensor/arduinoSensor.ino +++ /dev/null @@ -1,155 +0,0 @@ -/* - Repeating WiFi Web Client - - This sketch connects to a a web server and makes a request - using a WiFi equipped Arduino board. - - created 23 April 2012 - modified 31 May 2012 - by Tom Igoe - modified 13 Jan 2014 - by Federico Vanzati - - http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating - This code is in the public domain. - */ - -#include <SPI.h> -#include <WiFiNINA.h> -#include <ArduinoHttpClient.h> -#include <ArduinoJson.h> -#include "arduino_secrets.h" - -#include <Wire.h> -#include <Adafruit_Sensor.h> -#include <Adafruit_BME280.h> -#include "Adafruit_TSL2591.h" - -// Initialize sensors -Adafruit_BME280 bme; // BME sensor which has pressure, humidity and temperature -Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // Luminosity sensor - -///////please enter your sensitive data in the Secret tab/arduino_secrets.h -char ssid[] = SECRET_SSID; // your network SSID (name) -char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) - -int keyIndex = 0; // your network key index number (needed only for WEP) - -int status = WL_IDLE_STATUS; - -int temp, humidity, luminosity; -boolean api_success = false; - -// server address: -char server[] = "192.168.0.8"; -IPAddress server_ip(192,168,0,8); -int port = 8080; - -// Initialize the WiFi client library -WiFiClient client; -HttpClient http = HttpClient(client, server, port); - -unsigned long lastConnectionTime = 0, lastConnectionTime2 = 0, lastMovementTime = 0; // last time you connected to the server, in milliseconds -const unsigned long postingInterval = 60L * 30L * 1000L; // delay (1 800 000 ms = 30 min) between updates, in milliseconds - -void setup() { - //Initialize serial and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only - } - - // Initialize pins - bme.begin(0x76); - tsl.begin(); - tsl.setGain(TSL2591_GAIN_MED); - tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS); - - // check for the WiFi module: - if (WiFi.status() == WL_NO_MODULE) { - Serial.println("Communication with WiFi module failed!"); - // don't continue - while (true); - } - - // attempt to connect to WiFi network: - while (status != WL_CONNECTED) { - Serial.print("Attempting to connect to SSID: "); - Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: - status = WiFi.begin(ssid, pass); - - // wait 10 seconds for connection: - delay(10000); - } - // you're connected now, so print out the status: - printWifiStatus(); -} - -// MAIN LOOP -void loop() { - // if there's incoming data from the net connection. - // send it out the serial port. This is for debugging - // purposes only: - while (client.available()) { - char c = client.read(); - Serial.write(c); - } - - // Send the data - // If 30 minutes has been passed since last posting, then take measurements and post again - if (millis() - lastConnectionTime > postingInterval) { - temp = bme.readTemperature(); - humidity = bme.readHumidity(); - luminosity = tsl.getLuminosity(TSL2591_VISIBLE); - httpRequest(); - } -} - -// Lähetetään pilveen sensori1:lle sensoreiden tiedot -void httpRequest() { - // close any connection before send a new request. - // This will free the socket on the NINA module - Serial.println("making POST request"); - String contentType = "application/x-www-form-urlencoded"; - String postData ="temperature="; - postData += temp; - postData += "&humidity="; - postData += humidity; - postData += "&luminosity="; - postData += luminosity; - postData += "&parent_id="; - postData += 1; - - http.post("/api/v1/nodeData", contentType, postData); - - // read the status code and body of the response - int statusCode = http.responseStatusCode(); - String response = http.responseBody(); - - Serial.print("Status code: "); - Serial.println(statusCode); - Serial.print("Response: "); - Serial.println(response); - - // note the time that the connection was made: - lastConnectionTime = millis(); -} - -// Tulostetaan wifin tiedot -void printWifiStatus() { - // print the SSID of the network you're attached to: - Serial.print("SSID: "); - Serial.println(WiFi.SSID()); - - // print your board's IP address: - IPAddress ip = WiFi.localIP(); - Serial.print("IP Address: "); - Serial.println(ip); - - // print the received signal strength: - long rssi = WiFi.RSSI(); - Serial.print("signal strength (RSSI):"); - Serial.print(rssi); - Serial.println(" dBm"); -} diff --git "a/erikoisty\303\266_raportti.pdf" "b/erikoisty\303\266_raportti.pdf" deleted file mode 100644 index b414798c163cfababd471dac1805192c177ff28a..0000000000000000000000000000000000000000 Binary files "a/erikoisty\303\266_raportti.pdf" and /dev/null differ diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/WatcherServerApplication.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/WatcherServerApplication.java index 71e284faf24541d438e0852c08cb261708b2144b..ef8a38ae52131c1b9f6df83b7876c6f02f552807 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/WatcherServerApplication.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/WatcherServerApplication.java @@ -3,7 +3,6 @@ package com.joelhelkala.watcherServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -// MAIN @SpringBootApplication public class WatcherServerApplication { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUser.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUser.java index d9beea5f5321f8eb399b23668c78cab50f48cb2e..d0e5f3dea420ae3e20921dc49ec6e04b24c5b414 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUser.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUser.java @@ -19,15 +19,8 @@ import java.util.Collections; @NoArgsConstructor @Entity @Table -/* - AppUser is a class for basic user which has two roles (user,admin) - User has locked and enabled booleans, which are part of the Spring Boot Security - When the user has made a GET request on given endpoint with token, the user will be - enabled and can log in to the system. -*/ public class AppUser implements UserDetails { - // Database information @SequenceGenerator( name="person_sequence", sequenceName = "person_sequence", @@ -71,7 +64,6 @@ public class AppUser implements UserDetails { this.email = email; } - // Returns the Spring Boot Security grantedAuthority entity from users role @Override public Collection<? extends GrantedAuthority> getAuthorities() { SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.name()); @@ -88,7 +80,6 @@ public class AppUser implements UserDetails { return email; } - // BELOW IS SPRING BOOT SECURITY FUNCTIONS FROM USERDETAILS @Override public boolean isAccountNonExpired() { return true; diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUserController.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUserController.java index 382ae5d014982600d5db25f44af6f78b1820041d..5a3a81fc8418ec54db360994a24e8fe514207222 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUserController.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUserController.java @@ -5,7 +5,6 @@ import org.springframework.web.bind.annotation.*; import java.util.List; -// Class for creating and handling AppUser endpoints @RestController @RequestMapping(path = "api/v1/appuser") public class AppUserController { @@ -30,12 +29,14 @@ public class AppUserController { } // Endpoint to delete a user with given id + // TODO: perhaps change to email? @DeleteMapping(path = "{personId}") public void deletePerson(@PathVariable("personId") Long id) { userService.deleteUser(id); } // Endpoint to update a user with given id + // TODO: perhaps change to email? @PutMapping(path = "{personId}") public void updateUser(@PathVariable("personId") Long id, @RequestParam(required = false) String name, diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUserRepository.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUserRepository.java index 9b98f8382e1833bba11c800daa39282aa2e09edb..6129d35ca05a5c9c44fd30804154d74e06c74540 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUserRepository.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/appuser/AppUserRepository.java @@ -8,7 +8,6 @@ import org.springframework.stereotype.Repository; import javax.transaction.Transactional; import java.util.Optional; -// Jpa Interface to handle database manipulation @Repository public interface AppUserRepository extends JpaRepository<AppUser, Long> { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/email/EmailService.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/email/EmailService.java index 826b33574a430b646608e41e9b9dca534a2ddd0f..02f96339075fa493be002d213dad7d8d8be19495 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/email/EmailService.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/email/EmailService.java @@ -13,7 +13,6 @@ import org.springframework.stereotype.Service; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; -// Class for handling the sending of a email @Service @AllArgsConstructor public class EmailService implements EmailSender { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/exception/ApiException.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/exception/ApiException.java index 2ca74fafc909a4335bc2974ba0f3ca7bde72c216..0de1a727477814eb0917f2d40b032116593db22e 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/exception/ApiException.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/exception/ApiException.java @@ -4,21 +4,18 @@ import org.springframework.http.HttpStatus; import java.time.ZonedDateTime; -// Custom exception public class ApiException { private final String message; private final HttpStatus httpStatus; private final ZonedDateTime timestamp; - // Constructor public ApiException(String message, HttpStatus httpStatus, ZonedDateTime timestamp) { this.message = message; this.httpStatus = httpStatus; this.timestamp = timestamp; } - // getters public String getMessage() { return message; } diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/exception/ApiExceptionHandler.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/exception/ApiExceptionHandler.java index 73877084e11b378bfd50f685fac0ad4f445938eb..80e137e4b0bd1daef1205e5659498abc2b653613 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/exception/ApiExceptionHandler.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/exception/ApiExceptionHandler.java @@ -8,7 +8,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import java.time.ZoneId; import java.time.ZonedDateTime; -// Class that creates a ResponseEntity exception @ControllerAdvice public class ApiExceptionHandler { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/filter/CustomAuthenticationFilter.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/filter/CustomAuthenticationFilter.java index 0ceeb616e48095657e0c5c673fa47548eebab6da..81eb2c758e103d8ad46efc1c2f296d59438dd661 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/filter/CustomAuthenticationFilter.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/filter/CustomAuthenticationFilter.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; -// Class that handles the filtering of endpoints based on authorization of the user @Slf4j public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter { private final AuthenticationManager authenticationManager; diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeController.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeController.java index a59309bd3a562c26ec2eab843a2a37a74d87719e..9b34d0d86b67a320342249465aab0e7c06af6a80 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeController.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeController.java @@ -8,12 +8,10 @@ import org.springframework.web.bind.annotation.*; import java.util.List; -// Class for creating and handling node endpoints @RestController @RequestMapping("api/v1/node") public class NodeController { private final NodeService nodeService; - // Constructor @Autowired public NodeController(NodeService nodeService) { this.nodeService = nodeService; } @@ -35,7 +33,6 @@ public class NodeController { nodeService.updateNode(node); } - // Delete a node with given ID @DeleteMapping(path = "{nodeId}") public void deleteNode(@PathVariable("nodeId") Long id) { nodeService.deleteNode(id); diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeRepository.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeRepository.java index ddecc14157e5782f987dbc860aeb7723a739e8c1..88c88158f9bbe1a7a65bfe7066d34ea5e68ec21a 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeRepository.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeRepository.java @@ -5,7 +5,6 @@ import org.springframework.data.jpa.repository.Query; import java.util.Optional; -// Repository for handling database public interface NodeRepository extends JpaRepository<Node, Long> { @Query("SELECT n FROM Node n WHERE n.location = ?1") diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeService.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeService.java index ee371d5a12733e24284740e1f381388bde089eca..a4f0bfb5d746cc3d721af2568e3f1509feea75c0 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeService.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/NodeService.java @@ -9,7 +9,6 @@ import javax.transaction.Transactional; import java.util.List; import java.util.Optional; -// Class that works between controller and database @Service @AllArgsConstructor @Slf4j diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/nodeData/NodeData.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/nodeData/NodeData.java index 2d61b0013d645862da79701a63f7d2be3c738091..3e2eb6ed155ce700daa293d76beb7c1383e9b5ae 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/nodeData/NodeData.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/nodeData/NodeData.java @@ -6,10 +6,6 @@ import lombok.NoArgsConstructor; import javax.persistence.*; import java.time.LocalDateTime; -/* - This class is for nodeData, which is a record of - Nodes measurements at given time -*/ @Entity @NoArgsConstructor public class NodeData { @@ -44,7 +40,6 @@ public class NodeData { this.measured_at = time; } - // GETTERS public Float getTemperature() { return temperature; } diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/nodeData/NodeDataController.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/nodeData/NodeDataController.java index 5215042ba01a134eb689e6649cbff6676aa34927..7af3dcdd5e881feeae0697f8f48dc92826ff18cc 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/nodeData/NodeDataController.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/node/nodeData/NodeDataController.java @@ -24,13 +24,6 @@ public class NodeDataController { return nodeDataService.addData(temperature, humidity, luminosity, parent_id); } - @GetMapping - public ResponseEntity<Object> addNodeDataGet(@RequestParam Float temperature, @RequestParam Integer humidity, - @RequestParam Float luminosity, @RequestParam Long parent_id) { - return nodeDataService.addData(temperature, humidity, luminosity, parent_id); - } - - /* Gets all the data history from given parent node */ diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/ping/PingController.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/ping/PingController.java index c56cde86cfeeff72079b65ea2688cb27e3cf575b..31792553bd8efe684f0bd80bac8d37d030d189fc 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/ping/PingController.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/ping/PingController.java @@ -4,7 +4,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -// Just a basic ping endpoint for checking if server is up @RestController @RequestMapping(path = "api/v1/ping") public class PingController { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/EmailValidator.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/EmailValidator.java index 2b3d23a3a1ddf05161c7ed2ced30a4ff3d7f3aac..037f2ba418461c4d6f3ce88df8014ae15a7ce9b5 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/EmailValidator.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/EmailValidator.java @@ -4,7 +4,6 @@ import org.springframework.stereotype.Service; import java.util.function.Predicate; -// Validator class for validating emails @Service public class EmailValidator implements Predicate<String> { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationToken.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationToken.java index 596b011e5e311cfecc633fc6c3a46b6ce03c22f4..0b4473601e3fe5b0b31ba5b464c0924fc27b8119 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationToken.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationToken.java @@ -8,17 +8,12 @@ import lombok.Setter; import javax.persistence.*; import java.time.LocalDateTime; -/* - ConfirmationToken which will be sent to the user - This token is used to verify the users email and enable access -*/ @Getter @Setter @NoArgsConstructor @Entity public class ConfirmationToken { - // Database table info @SequenceGenerator( name="confirmation_token_sequence", sequenceName = "confirmation_token_sequence", @@ -38,7 +33,6 @@ public class ConfirmationToken { private LocalDateTime expiresAt; private LocalDateTime confirmedAt; - // Foreign key creation, could use just a ID... @ManyToOne @JoinColumn( nullable = false, @@ -46,7 +40,6 @@ public class ConfirmationToken { ) private AppUser appUser; - // Constructor public ConfirmationToken(String token, LocalDateTime createdAt, LocalDateTime expiredAt, AppUser user) { this.token = token; this.createdAt = createdAt; diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationTokenRepository.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationTokenRepository.java index 1ca72723e6bf7569bebd7d28721af687f9d742f8..e7af774f94cedd1ecdce0e70da6e0f1e961299c6 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationTokenRepository.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationTokenRepository.java @@ -9,7 +9,6 @@ import javax.transaction.Transactional; import java.time.LocalDateTime; import java.util.Optional; -// JpaRepo for handling database @Repository public interface ConfirmationTokenRepository extends JpaRepository<ConfirmationToken, Long> { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationTokenService.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationTokenService.java index 4dc770f8ea2327dd833b8c71e0e5c6f82d8e0ab1..4b08fcec474a063cb5c862437f563740c2ffd3a2 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationTokenService.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/registration/token/ConfirmationTokenService.java @@ -6,24 +6,20 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.Optional; -// Class for working between controller and database @Service @AllArgsConstructor public class ConfirmationTokenService { private final ConfirmationTokenRepository confirmationTokenRepository; - // Save confirmationToken to database public void saveConfirmationToken(ConfirmationToken token) { confirmationTokenRepository.save(token); } - // Finds the token from the database public Optional<ConfirmationToken> getToken(String token) { return confirmationTokenRepository.findByToken(token); } - // Sets a token as confirmed public int setConfirmedAt(String token) { return confirmationTokenRepository.updateConfirmedAt( token, LocalDateTime.now()); diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/response/GeneralResponse.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/response/GeneralResponse.java index d6301cbd525a3a2b8192e3b59ea65e439fce30f5..ccaeabfbb7838f188fa0304a4e7b45bdf17def08 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/response/GeneralResponse.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/response/GeneralResponse.java @@ -7,7 +7,6 @@ import org.springframework.http.ResponseEntity; import java.util.HashMap; import java.util.Map; -// Custom response @AllArgsConstructor public class GeneralResponse implements IResponse { private final HttpStatus httpStatus; diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/response/IResponse.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/response/IResponse.java index 232c32ee1f3396c4969ca1b5922b8971866f1b30..3dbb94bf7ed975d5d4994cb5b7146231de4ba69f 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/response/IResponse.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/response/IResponse.java @@ -2,7 +2,6 @@ package com.joelhelkala.watcherServer.response; import org.springframework.http.ResponseEntity; -// Interface for custom responses public interface IResponse { ResponseEntity<Object> getResponse(); } diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/PasswordEncoder.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/PasswordEncoder.java index 245005085e2abace843797ad1e7ecfb7166d97e5..3092ec7d2233ff966138dc0cdf34aeaf02cc2b63 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/PasswordEncoder.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/PasswordEncoder.java @@ -4,7 +4,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -// Kinda like a passwordEncoder factory but it has just once encoder @Configuration public class PasswordEncoder { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/config/WebSecurityConfig.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/config/WebSecurityConfig.java index 91c526875c2492c4f2061ebd6cafeaad452a02b5..680b1bdad3bbab2ee4319b90c386d2b97b3272e8 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/config/WebSecurityConfig.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/config/WebSecurityConfig.java @@ -21,9 +21,6 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic import static org.springframework.http.HttpMethod.GET; -/* - Security configuration for Spring Boot security -*/ @Configuration @EnableWebSecurity @RequiredArgsConstructor public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @@ -46,9 +43,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { http.authorizeRequests().antMatchers("/api/v*/ping").permitAll(); http.authorizeRequests().antMatchers("/api/v*/registration/**").permitAll(); - // NodeData from nodes needs to be permitted since no authorization has been made yet - http.authorizeRequests().antMatchers("/api/v*/nodeData").permitAll(); - http.authorizeRequests().antMatchers("/api/v*/nodeData/**").permitAll(); // --------------------------- // GET requests to appuser endpoint should have ADMIN roles