Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mesji/bacheloroppgave_2022
1 result
Show changes
Showing
with 1251 additions and 457 deletions
<component name="libraryTable">
<library name="Maven: io.opencensus:opencensus-contrib-http-util:0.31.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/io/opencensus/opencensus-contrib-http-util/0.31.0/opencensus-contrib-http-util-0.31.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/io/opencensus/opencensus-contrib-http-util/0.31.0/opencensus-contrib-http-util-0.31.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/io/opencensus/opencensus-contrib-http-util/0.31.0/opencensus-contrib-http-util-0.31.0-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: javax.annotation:javax.annotation-api:1.3.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.apache.httpcomponents:httpclient:4.5.13">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.apache.httpcomponents:httpcore:4.4.15">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore/4.4.15/httpcore-4.4.15.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore/4.4.15/httpcore-4.4.15-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore/4.4.15/httpcore-4.4.15-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.checkerframework:checker-compat-qual:2.5.5">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.checkerframework:checker-qual:3.21.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-qual/3.21.1/checker-qual-3.21.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-qual/3.21.1/checker-qual-3.21.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/checkerframework/checker-qual/3.21.1/checker-qual-3.21.1-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.threeten:threetenbp:1.5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/threeten/threetenbp/1.5.2/threetenbp-1.5.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/threeten/threetenbp/1.5.2/threetenbp-1.5.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/threeten/threetenbp/1.5.2/threetenbp-1.5.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Bachelor_application.iml" filepath="$PROJECT_DIR$/Bachelor_application.iml" />
</modules>
</component>
</project>
\ No newline at end of file
Index: .idea/.gitignore
===================================================================
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
--- a/.idea/.gitignore (revision bf612e45b76fce5444faaa257112a1e684497c29)
+++ /dev/null (revision bf612e45b76fce5444faaa257112a1e684497c29)
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
Index: .idea/vcs.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
--- /dev/null (date 1645110263019)
+++ b/.idea/vcs.xml (date 1645110263019)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="" vcs="Git" />
+ </component>
+</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
...@@ -52,5 +53,18 @@ ...@@ -52,5 +53,18 @@
<orderEntry type="library" name="Maven: com.google.cloud:google-cloud-storage:2.4.0" level="project" /> <orderEntry type="library" name="Maven: com.google.cloud:google-cloud-storage:2.4.0" level="project" />
<orderEntry type="library" name="Maven: com.google.apis:google-api-services-storage:v1-rev20211201-1.32.1" level="project" /> <orderEntry type="library" name="Maven: com.google.apis:google-api-services-storage:v1-rev20211201-1.32.1" level="project" />
<orderEntry type="library" name="Maven: com.google.auto.value:auto-value-annotations:1.9" level="project" /> <orderEntry type="library" name="Maven: com.google.auto.value:auto-value-annotations:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.10.14" level="project" />
<orderEntry type="library" name="Maven: org.jblas:jblas:1.2.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.13.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.2" level="project" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -29,6 +29,51 @@ ...@@ -29,6 +29,51 @@
<groupId>com.google.cloud</groupId> <groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId> <artifactId>google-cloud-storage</artifactId>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.14</version>
</dependency>
<dependency>
<groupId>org.jblas</groupId>
<artifactId>jblas</artifactId>
<version>1.2.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx</artifactId>
<version>11</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
......
package com.application.DB;
import com.application.GUI.Panes.LogoBar;
import com.application.GUI.PopUpWindows.NotificationPopUp;
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.TableResult;
import static com.application.DB.Constants.*;
import static com.application.DB.Settings.*;
import static com.application.GUI.PopUpWindows.LoginPopup.getPasswordTextField;
public class AccountHandler {
public static void getAccountInformation(String username, String password) throws Exception {
TableResult result = logIn(username,password);
if(result.getTotalRows() != 0) {
for (FieldValueList row : result.iterateAll()) {
if (row.get("Username").getValue().equals(username)) {
LogoBar.getLogin().setText(username);
setUserName(username);
if (!row.get("Phone_no").isNull()) {
setPhoneNo(row.get("Phone_no").getStringValue());
}
if (!row.get("First_name").isNull()) {
setFirstName(row.get("First_name").getStringValue());
}
if (!row.get("Last_name").isNull()) {
setLastName(row.get("Last_name").getStringValue());
}
if (!row.get("Admin").isNull()) {
setIsAdmin(row.get("Admin").getBooleanValue());
}
}
}
} else {
NotificationPopUp.displayNotificationWindow("Wrong username or password!");
getPasswordTextField().clear();
}
}
public static TableResult logIn(String username, String password) throws Exception {
// Sqlstatement
final String sqlStatement = "SELECT Username, Admin, Phone_no, First_name, Last_name " +
"FROM " + PROJECT_ID + "." + LOCATION_ID + "." + USERS_TABLE_NAME + " " +
"WHERE Username = " + '"' + username + '"' + " " +
"AND Password = " + '"' + password+ '"';
System.out.println(sqlStatement);
// Retrieves the results from the queryjob
return HelpingFunctions.createQueryJob(sqlStatement);
}
public static TableResult getAccount(String username) throws Exception {
// Sqlstatement
final String sqlStatement = "SELECT Username " +
"FROM " + PROJECT_ID + "." + LOCATION_ID + "." + USERS_TABLE_NAME + " " +
"WHERE Username = " + '"' + username + '"';
System.out.println(sqlStatement);
// Retrieves the results from the queryjob
return HelpingFunctions.createQueryJob(sqlStatement);
}
public static boolean addUser(String firstName, String lastName, String phoneNo, String username, String password, boolean isAdmin) throws Exception {
if(getAccount(username).getTotalRows() == 0) {
// Sqlstatement
final String sqlStatement =
"INSERT INTO " + PROJECT_ID + "." + LOCATION_ID + "." + USERS_TABLE_NAME + "(First_name, Last_name, Phone_no, Username, Password, Admin) " +
"VALUES(" + '"' + firstName + '"' + "," + '"' + lastName + '"' + "," + '"' + phoneNo + '"' + "," + '"' + username + '"' + "," + '"' + password + '"' + "," + isAdmin + ") ";
System.out.println(sqlStatement);
HelpingFunctions.createQueryJob(sqlStatement);
return true;
} else {
return false;
}
}
public static boolean deleteUser(String username) throws Exception {
if(getAccount(username).getTotalRows() != 0){
// Sqlstatement
final String sqlStatement = "DELETE FROM "+ PROJECT_ID + "." + LOCATION_ID + "." + USERS_TABLE_NAME +" WHERE Username = "+'"'+username+'"';
System.out.println(sqlStatement);
HelpingFunctions.createQueryJob(sqlStatement);
return true;
} else {
return false;
}
}
}
package com.application.DB;
public class Constants {
// Key name file for the database access
public static String KEY_FILE_NAME = "sf-drying-optimization-8a2e1b7ffc14.json";
// Time related constants
public static String START_TIME = "";
public static String STOP_TIME = "";
public static String CURRENT_DATE = "";
public static String TIME_LEFT = "";
// Boolean variable to tell if the drying process is finished
public static boolean IS_FINISHED = false;
// Boolean variable to tell if the data is finished loading
public static boolean LOADED_DATA = false;
// User inputs
public static String TREE_SPECIES = "";
public static String DIMENSIONS = "";
public static String SAWSET = "";
public static String MOISTURE_GOAL = "";
// Number of manual moisture checks
public static int NUMBER_OF_CHECKS = 1;
// Max number of input characters for sql injection prevention
public static int MAX_USER_INPUT_CHARACTERS = 10;
// Boolean constants to toggle default launch selected or not for checkboxes for showing graphs
public static boolean DEFAULT_IS_SELECTED_LIVE_DATA = true;
public static boolean DEFAULT_IS_SELECTED_REGRESSION = true;
public static boolean DEFAULT_IS_SELECTED_REGRESSION_SHADOW = false;
public static boolean DEFAULT_IS_SELECTED_PREVIOUS_DATA = true;
// Account constants
private static boolean isAdmin = false;
private static String firstName;
private static String lastName;
private static String userName;
private static String phoneNo;
public static String getUserName() { return userName;}
public static void setUserName(String userName) {
Constants.userName = userName;
}
public static String getPhoneNo() {
return phoneNo;
}
public static void setPhoneNo(String phoneNo) {
Constants.phoneNo = phoneNo;
}
public static boolean isIsAdmin() {
return isAdmin;
}
public static void setIsAdmin(boolean isAdmin) {
Constants.isAdmin = isAdmin;
}
public static String getFirstName() {
return firstName;
}
public static void setFirstName(String firstName) {
Constants.firstName = firstName;
}
public static String getLastName() {
return lastName;
}
public static void setLastName(String lastName) {
Constants.lastName = lastName;
}
}
This diff is collapsed.
package com.application.DB;
import com.application.GUI.PopUpWindows.NotificationPopUp;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.bigquery.*;
import io.opencensus.internal.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import static com.application.DB.Constants.KEY_FILE_NAME;
import static com.application.DB.Constants.MAX_USER_INPUT_CHARACTERS;
import static com.application.DB.Settings.*;
public class HelpingFunctions {
static Map<String,String> manMoist = new HashMap<>();
/**
* Creates a simple date format to use for converting millis in numbers to a usefull date format
*
* @return returns the date format
*/
static SimpleDateFormat getDateFormat() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat;
}
/**
* Retrieves the credentials file
*
* @return the credentials
* @throws Exception for potential errors
*/
private static GoogleCredentials getCredentials() throws Exception {
File credentialsPath = new File("./src/main/resources/com.application/"+KEY_FILE_NAME);
// Load credentials from JSON key file. If you can't set the GOOGLE_APPLICATION_CREDENTIALS
// environment variable, you can explicitly load the credentials file to construct the
// credentials.
GoogleCredentials credentials;
try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) {
credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
}
return credentials;
}
/**
* Creates a bigquery builder
*
* @return a builder
* @throws Exception returns potential error
*/
private static BigQuery getBuilder() throws Exception {
// Step 1: Initialize BigQuery service
// Here we set our project ID and get the `BigQuery` service object
// this is the interface to our BigQuery instance that
// we use to execute jobs on
return BigQueryOptions.newBuilder().
setCredentials(getCredentials()).
setProjectId(PROJECT_ID)
.build().getService();
}
/**
* Creates a job for the database
*
* @param queryConfig query configuration information
* @return a job
* @throws Exception returns potential error
*/
private static Job getJob(JobConfiguration queryConfig) throws Exception {
// Step 3: Run the job on BigQuery
// create a `Job` instance from the job configuration using the BigQuery service
// the job starts executing once the `create` method executes
Job queryJob = getBuilder().create(JobInfo.newBuilder(queryConfig).build());
queryJob = queryJob.waitFor();
// the waitFor method blocks until the job completes
// and returns `null` if the job doesn't exist anymore
if (queryJob == null) {
throw new Exception("job no longer exists");
}
// once the job is done, check if any error occured
if (queryJob.getStatus().getError() != null) {
throw new Exception(queryJob.getStatus().getError().toString());
}
return queryJob;
}
/**
* This function creates a query job that uses the query statement
* in order to retrieve information from the database
*
* @param sqlStatement input for the query statement
* @return returns the queryjob with the results
* @throws Exception Throws exception in case of error
*/
static TableResult createQueryJob(String sqlStatement) throws Exception {
// Creates a job configuration
Job queryJob = getJob(QueryJobConfiguration.newBuilder(sqlStatement).build());
// Retrieves the results from the queryjob
return queryJob.getQueryResults();
}
/**
* Stores data about manual measurements for moisture level in the lumber
*
* @return a list containing the outdate for the lumber and the corresponding diff value
*/
public static Map<String, String> getManMoist() {
return manMoist;
}
/**
* Function to iterate through all the Kwh values and storing them in a map
*
* @param data a map to store all the data
* @param baseline a baseline to base all the next values of to get a zero point
* @param result TableResult to iterate through
* @param kwhNameParameter Name of the Kwh name parameter in the database
* @param kwhTimestampNameParameter Name of the timestamp parameter in the database
*/
static void iterateKwhValues(Map<String, Number> data, int baseline, TableResult result, String kwhNameParameter, String kwhTimestampNameParameter) {
for (FieldValueList row : result.iterateAll()) {
// Sets the baseline in order to reset the kWh counter
if (baseline == 0) {
baseline = row.get("" + kwhNameParameter + "").getNumericValue().intValue();
}
// kWh value
int variantValue = row.get("" + kwhNameParameter + "").getNumericValue().intValue() - baseline; //-baseline
// Retrieving the wanted data
long timeStamp = row.get("" + kwhTimestampNameParameter + "").getTimestampValue() / 1000;
// Riktig format, men i string
String formatedTimeStamp = getDateFormat().format(timeStamp);
// Checks for negative values
if (variantValue > 0) {
// Adding the data to a list in order to sort through later
data.put(formatedTimeStamp, variantValue);
}
}
}
public static int getNoOfChambers(){
int valmeticsChamberIDS = 0;
int kwhChamberIDS = 0;
int noOfChambers = 0;
System.out.println("Constants.getSawmills().size(): "+ Settings.getSawmills().size());
for (HashMap.Entry<Integer, HashMap<String, HashMap<String, String>>> first : Settings.getSawmills().entrySet()) {
if (first.getKey() == 124) {
valmeticsChamberIDS = getValasenValmeticsChamberIDS().size();
kwhChamberIDS = getValasenKwhChamberIDS().size();
}
if (first.getKey() == 174) {
valmeticsChamberIDS = getArjangValmeticsChamberIDS().size();
kwhChamberIDS = getArjangKwhChamberIDS().size();
}
noOfChambers+= Math.min(valmeticsChamberIDS, kwhChamberIDS);
System.out.println("NO_OF_CHAMBERS: "+noOfChambers);
}
return noOfChambers;
}
public static boolean isLoadedData() {
return Constants.LOADED_DATA;
}
public static void setLoadedData(boolean loadedData) {
Constants.LOADED_DATA = loadedData;
}
public static boolean isValidInput (String input){
if(input.length() > Constants.MAX_USER_INPUT_CHARACTERS) {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
return true;
}
else if(input.contains("UNION")){
NotificationPopUp.displayNotificationWindow("Keyword: 'UNION' is not allowed");
return true;
}
else return false;
}
}
package com.application.DB;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
/**
* This class contains constants to be used related to database activities
*/
public final class Settings {
private Settings() {
// Empty constructor
}
// Number of wanted drying periods
public static int NUMBER_OF_PERIODS = 2;
// Number of seconds to wait before updating live data, in seconds
public static int NUMBER_OF_SECONDS_LIVE_DATA = 60;
// Confidence interval
public static final double CONFIDENCE_INTERVAL = 0.80;
// Current sawmill settings;
public static final String PROJECT_ID = "sf-drying-optimization";
public static final int LOCATION_ID = 124;
public static final String MAN_MOISTURE_TABLE = "int_dk_manMoisture";
public static final String KWH_TABLE_NAME = "int_sd_winccsensordata";
public static String USERS_TABLE_NAME = "users";
public static final String KWH_NAME_PARAMETER = "VariantValue";
public static final String KWH_TIMESTAMP_NAME_PARAMETER = "Timestamp";
public static final String KWH_VALUE_ID_NAME_PARAMETER = "ValueID";
public static final String KWH_VALUE_ID_VALUE_PARAMETER = "51"; // Which chamber is used
// Location Valasen(124)
// Project settings
public static final int VALASEN_LOCATION_ID = 124;
public static final String VALASEN_TABLE_NAME_VALMATICS = "int_dk_valmaticsdryingbatches_v2";
public static final String VALASEN_TABLE_NAME_KWH = "int_sd_winccsensordata";
// Parameters settings
// Valmatics
public static final String VALASEN_NAME_PARAMATERS = "Name";
public static final String VALASEN_START_DRYING_NAME = "DryingStarted";
public static final String VALASEN_STOP_DRYING_NAME = "CalculatedStop";
public static final String VALASEN_KILIN_NAME = "KilnName";
//public static int VALASEN_KILIN_ID = 5; // Kammer 5
//public static int VALASEN_KILIN_ID = 6; // Kammer 6
public static final int VALASEN_LIMIT = 1000;
public static final ArrayList<Integer> VALASEN_VALMETICS_CHAMBER_IDS = new ArrayList<>(Arrays.asList(5,6));
// Winccsensordata
public static final String VALASEN_KWH_NAME = "VariantValue";
public static final String VALASEN_TIMESTAMP_NAME = "Timestamp";
public static final String VALASEN_VALUE_ID_NAME = "ValueID";
//public static final int VALASEN_VALUE_ID = 51; // Kammer 5
//public static final int VALASEN_VALUE_ID = 56; // Kammer 6
public static final ArrayList<Integer> VALASEN_KWH_CHAMBER_IDS = new ArrayList<>(Arrays.asList(51,56));
// Location Arjang(174)
// Project settings
public static final int ARJANG_LOCATION_ID = 174;
public static final String ARJANG_TABLE_NAME_VALMATICS = "int_dk_valmaticsdryingbatches";
public static final String ARJANG_TABLE_NAME_KWH = "int_sd_swappconsensordata";
// Parameters settings
// Valmatics
public static final String ARJANG_NAME_PARAMATERS = "Name";
public static final String ARJANG_START_DRYING_NAME = "DryingStarted";
public static final String ARJANG_STOP_DRYING_NAME = "DryingCompleted";
public static final String ARJANG_KILIN_NAME = "KilinId";
//public static int ARJANG_KILIN_ID = 18;
//public static int ARJANG_KILIN_ID = 18554;
public static final int ARJANG_LIMIT = 1000;
public static final ArrayList<Integer> ARJANG_VALMETICS_CHAMBER_IDS = new ArrayList<>(Arrays.asList(17,18));
// Swappconsensordata
public static final String ARJANG_KWH_NAME = "RealValue";
public static final String ARJANG_TIMESTAMP_NAME = "Timestamp";
public static final String ARJANG_VALUE_ID_NAME = "ValueID";
//public static final int ARJANG_VALUE_ID = 19;
public static final ArrayList<Integer> ARJANG_KWH_CHAMBER_IDS = new ArrayList<>(Arrays.asList(19,19));
// Moisture Manual measurements
public static final String ARJANG_MANFUKTREG = "int_ds_manfuktreg";
public static final int ARJANG_NR_ADDED_DAYS = 2;
public static HashMap<Integer, HashMap<String, HashMap<String, String>>> getSawmills(){
HashMap<Integer, HashMap<String, HashMap<String, String>>> sawmillInfo = new HashMap<>();
sawmillInfo.put(VALASEN_LOCATION_ID, getValasenTables());
sawmillInfo.put(ARJANG_LOCATION_ID, getArjangTables());
return sawmillInfo;
}
// Valasen
private static HashMap<String, HashMap<String, String>> getValasenTables(){
HashMap<String, HashMap<String, String>> valasenTables = new HashMap<>();
valasenTables.put(getValasenTableNames().get("Valmetics"), getValasenValmeticsParameters());
valasenTables.put(getValasenTableNames().get("Kwh"), getValasenWinccsensordataParameters());
return valasenTables;
}
public static HashMap<String, String> getValasenTableNames(){
HashMap<String, String> valasenTables = new HashMap<>();
valasenTables.put("Valmetics", VALASEN_TABLE_NAME_VALMATICS);
valasenTables.put("Kwh", VALASEN_TABLE_NAME_KWH);
return valasenTables;
}
private static HashMap<String, String> getValasenValmeticsParameters(){
HashMap<String, String> valasenValmeticsParameters = new HashMap<>();
valasenValmeticsParameters.put("Name", VALASEN_NAME_PARAMATERS);
valasenValmeticsParameters.put("DryingStarted", VALASEN_START_DRYING_NAME);
valasenValmeticsParameters.put("DryingStopped", VALASEN_STOP_DRYING_NAME);
valasenValmeticsParameters.put("KilnName", VALASEN_KILIN_NAME);
//valasenValmeticsParameters.put("KilinID", String.valueOf(VALASEN_KILIN_ID));
valasenValmeticsParameters.put("Limit", String.valueOf(VALASEN_LIMIT));
return valasenValmeticsParameters;
}
public static ArrayList<Integer> getValasenValmeticsChamberIDS(){
return VALASEN_VALMETICS_CHAMBER_IDS;
}
private static HashMap<String, String> getValasenWinccsensordataParameters(){
HashMap<String, String> valasenWinccsensordataParameters = new HashMap<>();
valasenWinccsensordataParameters.put("KwhName", VALASEN_KWH_NAME);
valasenWinccsensordataParameters.put("Timestamp", VALASEN_TIMESTAMP_NAME);
valasenWinccsensordataParameters.put("ValueIDName", VALASEN_VALUE_ID_NAME);
//valasenWinccsensordataParameters.put("ValueID", String.valueOf(VALASEN_VALUE_ID));
//valasenWinccsensordataParameters.put("ValueID", String.valueOf(VALASEN_VALUE_ID));
return valasenWinccsensordataParameters;
}
public static ArrayList<Integer> getValasenKwhChamberIDS(){
return VALASEN_KWH_CHAMBER_IDS;
}
// Arjang
private static HashMap<String, HashMap<String, String>> getArjangTables(){
HashMap<String, HashMap<String, String>> arjangTables = new HashMap<>();
arjangTables.put(getArjangTableNames().get("Valmetics"), getArjangValmeticsParameters());
arjangTables.put(getArjangTableNames().get("Kwh"), getArjangWinccsensordataParameters());
return arjangTables;
}
public static HashMap<String, String> getArjangTableNames(){
HashMap<String, String> valasenTables = new HashMap<>();
valasenTables.put("Valmetics", ARJANG_TABLE_NAME_VALMATICS);
valasenTables.put("Kwh", ARJANG_TABLE_NAME_KWH);
return valasenTables;
}
private static HashMap<String, String> getArjangValmeticsParameters(){
HashMap<String, String> arjangValmeticsParameters = new HashMap<>();
arjangValmeticsParameters.put("Name", ARJANG_NAME_PARAMATERS);
arjangValmeticsParameters.put("DryingStarted", ARJANG_START_DRYING_NAME);
arjangValmeticsParameters.put("DryingStopped", ARJANG_STOP_DRYING_NAME);
arjangValmeticsParameters.put("KilnName", ARJANG_KILIN_NAME);
//arjangValmeticsParameters.put("KilinID", String.valueOf(ARJANG_KILIN_ID));
arjangValmeticsParameters.put("Limit", String.valueOf(ARJANG_LIMIT));
return arjangValmeticsParameters;
}
public static ArrayList<Integer> getArjangValmeticsChamberIDS(){
return ARJANG_VALMETICS_CHAMBER_IDS;
}
private static HashMap<String, String> getArjangWinccsensordataParameters(){
HashMap<String, String> arjangWinccsensordataParameters = new HashMap<>();
arjangWinccsensordataParameters.put("KwhName", ARJANG_KWH_NAME);
arjangWinccsensordataParameters.put("Timestamp", ARJANG_TIMESTAMP_NAME);
arjangWinccsensordataParameters.put("ValueIDName", ARJANG_VALUE_ID_NAME);
//arjangWinccsensordataParameters.put("ValueID", String.valueOf(ARJANG_VALUE_ID));
return arjangWinccsensordataParameters;
}
public static ArrayList<Integer> getArjangKwhChamberIDS(){
return ARJANG_KWH_CHAMBER_IDS;
}
}
package com.application.DB;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.bigquery.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class Sort {
private static GoogleCredentials getCredentials() throws Exception {
File credentialsPath = new File(".\\src\\main\\resources\\com.application\\sf-drying-optimization-1e234ad2b0f4.json");
// Load credentials from JSON key file. If you can't set the GOOGLE_APPLICATION_CREDENTIALS
// environment variable, you can explicitly load the credentials file to construct the
// credentials.
GoogleCredentials credentials;
try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) {
credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
}
return credentials;
}
// Step 1: Initialize BigQuery service
// Here we set our project ID and get the `BigQuery` service object
// this is the interface to our BigQuery instance that
// we use to execute jobs on
private static BigQuery getBuilder() throws Exception {
BigQuery bigquery = BigQueryOptions.newBuilder().
setCredentials(getCredentials()).
setProjectId("sf-drying-optimization")
.build().getService();
return bigquery;
}
public static void main(String[] args) throws Exception {
Sort.getFromExistingTable();
}
//getFromExistingTable sorts out treespecies, ex, width and height
//
public static void getFromExistingTable() throws Exception {
// Step 2: Prepare query job
// A "QueryJob" is a type of job that executes SQL queries
// we create a new job configuration from our SQL query and
final String GET_WORD_COUNT =
"SELECT Name, CalculatedStart, CalculatedStop FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches`" +
"WHERE Name Like \"%Gran%\" AND Name Like \"%3ex%\" AND NAME Like \"%47x150%\" AND DATE(CalculatedStart) " +
"BETWEEN \"2018-08-17\" AND \"2022-08-30\" ORDER BY DATE(CalculatedStart)";
QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder(GET_WORD_COUNT).build();
// Step 3: Run the job on BigQuery
// create a `Job` instance from the job configuration using the BigQuery service
// the job starts executing once the `create` method executes
Job queryJob = getBuilder().create(JobInfo.newBuilder(queryConfig).build());
queryJob = queryJob.waitFor();
// the waitFor method blocks until the job completes
// and returns `null` if the job doesn't exist anymore
if (queryJob == null) {
throw new Exception("job no longer exists");
}
// once the job is done, check if any error occured
if (queryJob.getStatus().getError() != null) {
throw new Exception(queryJob.getStatus().getError().toString());
}
// Step 4: Display results
// Print out a header line, and iterate through the
// query results to print each result in a new line
System.out.println("Name\tCalculatedStarted\tCalculatedStop");
TableResult result = queryJob.getQueryResults();
for (FieldValueList row : result.iterateAll()) {
// We can use the `get` method along with the column
// name to get the corresponding row entry
String name = row.get("Name").getStringValue();
String calculatedStart = row.get("CalculatedStart").getStringValue();
String calculatedStop = row.get("CalculatedStop").getStringValue();
System.out.printf("%s\t%s\t%s\n", name,calculatedStart, calculatedStop);
}
}
}