diff --git a/src/main/java/com/application/DB/DB.java b/src/main/java/com/application/DB/DB.java index 02348eb6043a6d79fc78e08e166b14862aaf6181..b425377c0b0e6e5cf2c10ea6f77735fdd614e124 100644 --- a/src/main/java/com/application/DB/DB.java +++ b/src/main/java/com/application/DB/DB.java @@ -12,6 +12,8 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import static com.application.DB.Constants.*; + /** * This class is responsible for handling database related activities * @@ -77,7 +79,7 @@ public class DB { // we use to execute jobs on return BigQueryOptions.newBuilder(). setCredentials(getCredentials()). - setProjectId("sf-drying-optimization") + setProjectId(PROJECT_ID) .build().getService(); } @@ -279,7 +281,7 @@ public class DB { // Sqlstatement for ValÄsen(124) final String sqlStatement = "SELECT MAX(Name) as DryingSchedule, MAX(KilnName) as Kiln_name, DryingStarted, Max(CalculatedStop) as CalculatedStop\n" + - "FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches` \n" + + "FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches_v2` \n" + "WHERE KilnName = 5 \n" + "AND DATE(DryingStarted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" + "AND DATE(CalculatedStop) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" + @@ -309,19 +311,52 @@ public class DB { for (FieldValueList row : result.iterateAll()) { // Defining variables - String formatedInTidTork; - String formatedUtTidTork; + String formatedInTidTork = ""; + String formatedUtTidTork = ""; // Retrieving the data // DryingStarted: if(!row.get("DryingStarted").isNull()){ - long InTidTorkLong = row.get("DryingStarted").getTimestampValue()/1000; - // Formating the data from long to a string in the correct date format - formatedInTidTork = getDateFormat().format(InTidTorkLong); - } else { - formatedInTidTork = ""; + // Check if response is given in millis + if(row.get("DryingStarted").getValue() instanceof Integer) { + long InTidTorkLong = row.get("DryingStarted").getTimestampValue()/1000; + // Formating the data from long to a string in the correct date format + formatedInTidTork = getDateFormat().format(InTidTorkLong); + } + // Checks if response is given in a string date format + else if(row.get("DryingStarted").getValue() instanceof String) { + // stores the value + String value = (String) row.get("DryingStarted").getValue(); + // Splits the string based on 'T' + String[] splitValue = value.split("T"); + // Combines the values into a new format + formatedInTidTork = splitValue[0]+" "+splitValue[1]; + } } + // CalculatedStop: + // DryingCompleted: + if(!row.get("CalculatedStop").isNull()){ + // Check if response is given in millis + if(row.get("CalculatedStop").getValue() instanceof Integer) { + long utTidTorkLong = row.get("CalculatedStop").getTimestampValue()/1000; + // Formating the data from long to a string in the correct date format + formatedUtTidTork = getDateFormat().format(utTidTorkLong); + } + else if(row.get("CalculatedStop").getValue() instanceof String) { + // stores the value + String value = (String) row.get("CalculatedStop").getValue(); + // Splits the string based on 'T' + String[] splitValue = value.split("T"); + // Combines the values into a new format + formatedUtTidTork = splitValue[0]+" "+splitValue[1]; + } + } + + System.out.println(formatedInTidTork); + System.out.println(formatedUtTidTork+"\n"); + + /* // CalculatedStop: // DryingCompleted: if(!row.get("CalculatedStop").isNull()){ @@ -331,9 +366,10 @@ public class DB { } else { formatedUtTidTork = ""; } + */ // Checks if intidtork or outtidtork is empty, if so they are ignored and not added to the list - if (!formatedInTidTork.equals("") && !formatedUtTidTork.equals("")){ + if (!formatedInTidTork.isEmpty() && !formatedUtTidTork.isEmpty()){ // Adds the data to the dates map dates.put(formatedInTidTork,formatedUtTidTork); } diff --git a/target/classes/com/application/DB/DB.class b/target/classes/com/application/DB/DB.class index 47892ca45240c43c584a1352c2c3f57b0bec5022..30cd375022bc63510dd2aad4cd576d38dced7e46 100644 Binary files a/target/classes/com/application/DB/DB.class and b/target/classes/com/application/DB/DB.class differ