Ticket 701: Improve bdb.object.status supervisor query
authorAnders Henja <anders@henjab.se>
Mon, 19 Jun 2017 19:03:50 +0000 (21:03 +0200)
committerAnders Henja <anders@henjab.se>
Mon, 19 Jun 2017 19:03:50 +0000 (21:03 +0200)
itest/eu/baltrad/beast/system/BdbObjectStatusReporterITest.java
itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_seang_000001.h5 [new file with mode: 0644]
itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_sehud_000000.h5 [new file with mode: 0644]
itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_selek_000000.h5 [new file with mode: 0644]
src/eu/baltrad/beast/system/BdbObjectStatusReporter.java

index 3458c97..d827676 100644 (file)
@@ -49,6 +49,9 @@ public class BdbObjectStatusReporterITest {
     "fixtures/Z_SCAN_C_ESWI_20101016080000_seang_000000.h5",
     "fixtures/Z_SCAN_C_ESWI_20101016080500_seang_000000.h5",
     "fixtures/Z_SCAN_C_ESWI_20101016080500_searl_000000.h5",
+    "fixtures/Z_SCAN_C_ESWI_20101016080500_seang_000001.h5", // O1
+    "fixtures/Z_SCAN_C_ESWI_20101016080500_sehud_000000.h5", // O2
+    "fixtures/Z_SCAN_C_ESWI_20101016080500_selek_000000.h5", // O3  
     "fixtures/comp_20101016080000_swegmaps_2000.h5"
   };
   
@@ -75,6 +78,21 @@ public class BdbObjectStatusReporterITest {
     context.close();
   }
   
+  long getMinuteOffsetFromNow(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second) {
+    GregorianCalendar c = new GregorianCalendar();
+    c.setTimeZone(TimeZone.getTimeZone("UTC"));
+    c.set(Calendar.YEAR, year);
+    c.set(Calendar.MONTH, month);
+    c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+    c.set(Calendar.HOUR_OF_DAY, hourOfDay);
+    c.set(Calendar.MINUTE, minute);
+    c.set(Calendar.SECOND, second);
+    
+    GregorianCalendar now = new GregorianCalendar();
+
+    return ((now.getTimeInMillis() - c.getTimeInMillis()) / (60 * 1000));
+  }
+  
   @Test
   public void testGetStatus_searl() {
     GregorianCalendar c = new GregorianCalendar();
@@ -110,6 +128,152 @@ public class BdbObjectStatusReporterITest {
   }
 
   @Test
+  public void testGetStatus_OptionalAttribute_elangle_0_5() {
+    long minute = getMinuteOffsetFromNow(2010,9,16,8,0,0) + 2;
+    
+    Map<String,Object> values = new HashMap<String, Object>();
+    values.put("objects", "SCAN");
+    values.put("sources", "seang");
+    values.put("minutes", minute);
+    values.put("where/elangle", "0.5");
+    
+    // Verify that we can find the specified elangle
+    Set<SystemStatus> result = classUnderTest.getStatus(values);
+    Assert.assertEquals(1, result.size());
+    Assert.assertTrue(result.contains(SystemStatus.OK));
+  }
+
+  @Test
+  public void testGetStatus_OptionalAttribute_elangle_1_5() {
+    long minute = getMinuteOffsetFromNow(2010,9,16,8,0,0) + 2;
+    
+    Map<String,Object> values = new HashMap<String, Object>();
+    values.put("objects", "SCAN");
+    values.put("sources", "seang");
+    values.put("minutes", minute);
+    values.put("where/elangle", "1.5");
+    
+    // Verify that we can find the specified elangle
+    Set<SystemStatus> result = classUnderTest.getStatus(values);
+    Assert.assertEquals(1, result.size());
+    Assert.assertTrue(result.contains(SystemStatus.OK));
+  }
+
+  @Test
+  public void testGetStatus_OptionalAttribute_elangle_2_0_doesntexist() {
+    long minute = getMinuteOffsetFromNow(2010,9,16,8,0,0) + 2;
+    
+    Map<String,Object> values = new HashMap<String, Object>();
+    values.put("objects", "SCAN");
+    values.put("sources", "seang");
+    values.put("minutes", minute);
+    values.put("where/elangle", "1.0");
+    
+    // Verify that we can find the specified elangle
+    Set<SystemStatus> result = classUnderTest.getStatus(values);
+    Assert.assertEquals(1, result.size());
+    Assert.assertTrue(result.contains(SystemStatus.COMMUNICATION_PROBLEM));
+  }
+
+  @Test
+  public void testGetStatus_OptionalAttribute_malfunc_True() {
+    long minute = getMinuteOffsetFromNow(2010,9,16,8,5,0) + 2;
+    
+    Map<String,Object> values = new HashMap<String, Object>();
+    values.put("objects", "SCAN");
+    values.put("sources", "sehud");
+    values.put("minutes", minute);
+    values.put("how/malfunc", "True");
+    
+    // Verify
+    Set<SystemStatus> result = classUnderTest.getStatus(values);
+    Assert.assertEquals(1, result.size());
+    Assert.assertTrue(result.contains(SystemStatus.OK));
+    
+    // And just ensure that we dont find anything with malfunc = False
+    values.put("how/malfunc", "False");
+    result = classUnderTest.getStatus(values);
+    Assert.assertTrue(result.contains(SystemStatus.COMMUNICATION_PROBLEM));
+  }
+
+  @Test
+  public void testGetStatus_OptionalAttribute_malfunc_False() {
+    long minute = getMinuteOffsetFromNow(2010,9,16,8,5,0) + 2;
+    
+    Map<String,Object> values = new HashMap<String, Object>();
+    values.put("objects", "SCAN");
+    values.put("sources", "selek");
+    values.put("minutes", minute);
+    values.put("how/malfunc", "False");
+    
+    // Verify
+    Set<SystemStatus> result = classUnderTest.getStatus(values);
+    Assert.assertEquals(1, result.size());
+    Assert.assertTrue(result.contains(SystemStatus.OK));
+
+    // And just ensure that we dont find anything with malfunc = True
+    values.put("how/malfunc", "True");
+    result = classUnderTest.getStatus(values);
+    Assert.assertTrue(result.contains(SystemStatus.COMMUNICATION_PROBLEM));
+  }
+
+  @Test
+  public void testGetStatus_OptionalAttribute_mixed() {
+    long minute = getMinuteOffsetFromNow(2010,9,16,8,5,0) + 2;
+    
+    Map<String,Object> values = new HashMap<String, Object>();
+    values.put("objects", "SCAN");
+    values.put("sources", "selek");
+    values.put("minutes", minute);
+    values.put("where/a1gate", "0");
+    values.put("where/nrays", "420");
+    values.put("where/rstart", "0");
+    
+    // Verify
+    Set<SystemStatus> result = classUnderTest.getStatus(values);
+    Assert.assertEquals(1, result.size());
+    Assert.assertTrue(result.contains(SystemStatus.OK));
+
+    // And just ensure that we dont find anything other values
+    values.put("where/a1gate", "1");
+    result = classUnderTest.getStatus(values);
+    Assert.assertTrue(result.contains(SystemStatus.COMMUNICATION_PROBLEM));
+
+    // And just ensure that we dont find anything other values
+    values.put("where/a1gate", "0");
+    values.put("where/nrays", "421");
+    result = classUnderTest.getStatus(values);
+    Assert.assertTrue(result.contains(SystemStatus.COMMUNICATION_PROBLEM));
+
+    // And just ensure that we dont find anything other values
+    values.put("where/nrays", "420");
+    values.put("where/rstart", "10");
+    result = classUnderTest.getStatus(values);
+    Assert.assertTrue(result.contains(SystemStatus.COMMUNICATION_PROBLEM));
+
+    // And now test that we can reset it back again to get a hit
+    values.put("where/rstart", "0");
+    result = classUnderTest.getStatus(values);
+    Assert.assertTrue(result.contains(SystemStatus.OK));
+  }
+
+  @Test
+  public void testGetStatus_OptionalAttribute_mixed_2() {
+    long minute = getMinuteOffsetFromNow(2010,9,16,8,5,0) + 2;
+    
+    Map<String,Object> values = new HashMap<String, Object>();
+    values.put("objects", "SCAN");
+    values.put("sources", "selek,searl");
+    values.put("minutes", minute);
+    values.put("how/system", "ERIC");
+    
+    // Verify
+    Set<SystemStatus> result = classUnderTest.getStatus(values);
+    Assert.assertEquals(1, result.size());
+    Assert.assertTrue(result.contains(SystemStatus.OK));
+  }
+  
+  @Test
   public void testGetStatus_pvol_searl() {
     GregorianCalendar c = new GregorianCalendar();
 
diff --git a/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_seang_000001.h5 b/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_seang_000001.h5
new file mode 100644 (file)
index 0000000..4209144
Binary files /dev/null and b/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_seang_000001.h5 differ
diff --git a/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_sehud_000000.h5 b/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_sehud_000000.h5
new file mode 100644 (file)
index 0000000..f9f99dd
Binary files /dev/null and b/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_sehud_000000.h5 differ
diff --git a/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_selek_000000.h5 b/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_selek_000000.h5
new file mode 100644 (file)
index 0000000..21b9625
Binary files /dev/null and b/itest/eu/baltrad/beast/system/fixtures/Z_SCAN_C_ESWI_20101016080500_selek_000000.h5 differ
index cc79ce7..7a8f7ac 100644 (file)
@@ -64,6 +64,9 @@ public class BdbObjectStatusReporter implements ISystemStatusReporter{
     SUPPORTED_ATTRIBUTES.add("objects");
     SUPPORTED_ATTRIBUTES.add("sources");
     SUPPORTED_ATTRIBUTES.add("areas");
+    SUPPORTED_ATTRIBUTES.add("what/*");
+    SUPPORTED_ATTRIBUTES.add("where/*");
+    SUPPORTED_ATTRIBUTES.add("how/*");
   }
   
   /**
@@ -172,6 +175,15 @@ public class BdbObjectStatusReporter implements ISystemStatusReporter{
       qfilter.add(xpr.or(prodfilter));
     }
     
+    // Handle optional attributes
+    for (String k : values.keySet()) {
+      String lowerCaseK = k.toLowerCase();
+      if (lowerCaseK.startsWith("what/") || lowerCaseK.startsWith("where/") || lowerCaseK.startsWith("how/")) {
+        //List<Expression> filters = new ArrayList<Expression>();
+        qfilter.add(xpr.eq(xpr.attribute(lowerCaseK), xpr.literal((String)values.get(k))));
+      }
+    }
+    
     return xpr.and(qfilter);
   }