Skip to content
Snippets Groups Projects
Commit f2fb22c6 authored by Bastiaan Verhoef's avatar Bastiaan Verhoef
Browse files

Bug1379:

Add support for store into otdb database
parent cb365bbf
Branches
Tags
No related merge requests found
Showing
with 760 additions and 400 deletions
......@@ -1202,6 +1202,8 @@ SAS/OTB/MoM-OTDB-adapter/doc/resources/inherit.gif -text
SAS/OTB/MoM-OTDB-adapter/examples/mom-otdb-adapter-keystore.jks -text
SAS/OTB/MoM-OTDB-adapter/examples/mom-otdb-adapter-trusted-keystore.jks -text
SAS/OTB/MoM-OTDB-adapter/examples/mom-otdb-adapter.cer -text
SAS/OTB/MoM-OTDB-adapter/examples/obs-50-active.xml -text
SAS/OTB/MoM-OTDB-adapter/examples/obs-50-specified.xml -text
SAS/OTB/MoM-OTDB-adapter/examples/obs.xml -text
SAS/OTB/MoM-OTDB-adapter/examples/observation.xml -text
SAS/OTB/MoM-OTDB-adapter/lib/astron-http-utils.jar -text
......
<?xml version="1.0" encoding="UTF-8"?>
<lofar:observation mom2Id="50"
xmlns:lofar="http://www.astron.nl/MoM2-Lofar"
xmlns:mom2="http://www.astron.nl/MoM2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.astron.nl/MoM2-Lofar C:/java/workspace/MoM-OTDB-adapter/schemas/LofarMoM2.xsd http://www.astron.nl/MoM2 C:/java/workspace/MoM-OTDB-adapter/schemas/MoM2.xsd ">
<currentStatus>
<mom2:activeStatus/>
</currentStatus>
<children/>
<observationAttributes>
<observationId>5005</observationId>
<clock/>
<startTime>2009-09-30T13:54:11</startTime>
<stations/>
</observationAttributes>
</lofar:observation>
<?xml version="1.0" encoding="UTF-8"?>
<lofar:observation mom2Id="50"
xmlns:lofar="http://www.astron.nl/MoM2-Lofar"
xmlns:mom2="http://www.astron.nl/MoM2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.astron.nl/MoM2-Lofar C:/java/workspace/MoM-OTDB-adapter/schemas/LofarMoM2.xsd http://www.astron.nl/MoM2 C:/java/workspace/MoM-OTDB-adapter/schemas/MoM2.xsd ">
<currentStatus>
<mom2:preparedStatus/>
</currentStatus>
<children>
<item index="0">
<lofar:measurement mom2Id="51" xsi:type="lofar:UVMeasurementType">
<measurementAttributes>
<ra>85.650575</ra>
<dec>49.852009</dec>
<equinox>J2000</equinox>
<duration>PT10M</duration>
<subbands>255,256,257</subbands>
</measurementAttributes>
</lofar:measurement>
</item>
<item index="1">
<lofar:measurement mom2Id="52" xsi:type="lofar:UVMeasurementType">
<measurementAttributes>
<ra>85.650575</ra>
<dec>49.852009</dec>
<equinox>J2000</equinox>
<duration>PT40M</duration>
<subbands>224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288</subbands>
</measurementAttributes>
</lofar:measurement>
</item>
<item index="2">
<lofar:measurement mom2Id="53" xsi:type="lofar:UVMeasurementType">
<measurementAttributes>
<ra>85.650575</ra>
<dec>49.852009</dec>
<equinox>J2000</equinox>
<duration>PT10M</duration>
<subbands>224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288</subbands>
</measurementAttributes>
</lofar:measurement>
</item>
</children>
<observationAttributes>
<observationId>5004</observationId>
<antenna>HBA Both</antenna>
<clock>
<channelWidth units="Hz">610.3515625</channelWidth>
<samplesPerSecond>155648</samplesPerSecond>
<subbandWidth units="Hz">156.25</subbandWidth>
<systemClock units="Hz">160</systemClock>
</clock>
<integrationInterval>4</integrationInterval>
<channelsPerSubband>256</channelsPerSubband>
<instrumentFilter>10-90 MHz</instrumentFilter>
<stations>
<station>
<name>CS302</name>
</station>
<station>
<name>CS303</name>
</station>
</stations>
</observationAttributes>
</lofar:observation>
<?xml version="1.0" encoding="UTF-8"?>
<lofar:observation mom2Id="27"
<lofar:observation mom2Id="50"
xmlns:lofar="http://www.astron.nl/MoM2-Lofar"
xmlns:mom2="http://www.astron.nl/MoM2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.astron.nl/MoM2-Lofar http://localhost:8080/mom2lofar/schemas/LofarMoM2.xsd http://www.astron.nl/MoM2 http://localhost:8080/mom2lofar/schemas/MoM2.xsd ">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>NGC 0628_obs</name>
<description>Tja, tja</description>
<statusHistory>
<item index="0">
<mom2ObjectStatus>
<name>Verhoef, Ir. Bastiaan</name>
<roles>Craft User, Reviewer, System Maintenance</roles>
<roles>Craft User, manager, Reviewer, System Maintenance</roles>
<user id="2"/>
<timeStamp>2009-09-22T12:35:34</timeStamp>
<timeStamp>2009-09-30T08:00:42</timeStamp>
<mom2:describedStatus/>
</mom2ObjectStatus>
</item>
<item index="1">
<mom2ObjectStatus>
<name>Verhoef, Ir. Bastiaan</name>
<roles>Craft User, Reviewer, System Maintenance</roles>
<roles>Craft User, manager, Reviewer, System Maintenance</roles>
<user id="2"/>
<timeStamp>2009-09-22T12:04:42</timeStamp>
<timeStamp>2009-09-30T08:00:10</timeStamp>
<mom2:openedStatus/>
</mom2ObjectStatus>
</item>
......@@ -30,25 +30,25 @@
</currentStatus>
<children>
<item index="0">
<lofar:measurement mom2Id="28" xsi:type="lofar:UVMeasurementType">
<lofar:measurement mom2Id="51" xsi:type="lofar:UVMeasurementType">
<name>Calibrator 1</name>
<description>asdfasd</description>
<statusHistory>
<item index="0">
<mom2ObjectStatus>
<name>Verhoef, Ir. Bastiaan</name>
<roles>Craft User, Reviewer, System Maintenance</roles>
<roles>Craft User, manager, Reviewer, System Maintenance</roles>
<user id="2"/>
<timeStamp>2009-09-22T12:35:34</timeStamp>
<timeStamp>2009-09-30T08:00:42</timeStamp>
<mom2:describedStatus/>
</mom2ObjectStatus>
</item>
<item index="1">
<mom2ObjectStatus>
<name>Verhoef, Ir. Bastiaan</name>
<roles>Craft User, Reviewer, System Maintenance</roles>
<roles>Craft User, manager, Reviewer, System Maintenance</roles>
<user id="2"/>
<timeStamp>2009-09-22T12:04:42</timeStamp>
<timeStamp>2009-09-30T08:00:10</timeStamp>
<mom2:openedStatus/>
</mom2ObjectStatus>
</item>
......@@ -65,35 +65,35 @@
<equinox>J2000</equinox>
<duration>PT10M</duration>
<subbandsSpecification>
<bandWidth>5000000</bandWidth>
<centralFrequency>50000000</centralFrequency>
<bandWidth units="kHz">100</bandWidth>
<centralFrequency units="MHz">40</centralFrequency>
<contiguous>false</contiguous>
<subbands>304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336</subbands>
<subbands>255,256,257</subbands>
</subbandsSpecification>
</specification>
</measurementAttributes>
</lofar:measurement>
</item>
<item index="1">
<lofar:measurement mom2Id="29" xsi:type="lofar:UVMeasurementType">
<lofar:measurement mom2Id="52" xsi:type="lofar:UVMeasurementType">
<name>Target 1</name>
<description>asdfasd</description>
<statusHistory>
<item index="0">
<mom2ObjectStatus>
<name>Verhoef, Ir. Bastiaan</name>
<roles>Craft User, Reviewer, System Maintenance</roles>
<roles>Craft User, manager, Reviewer, System Maintenance</roles>
<user id="2"/>
<timeStamp>2009-09-22T12:35:34</timeStamp>
<timeStamp>2009-09-30T08:00:42</timeStamp>
<mom2:describedStatus/>
</mom2ObjectStatus>
</item>
<item index="1">
<mom2ObjectStatus>
<name>Verhoef, Ir. Bastiaan</name>
<roles>Craft User, Reviewer, System Maintenance</roles>
<roles>Craft User, manager, Reviewer, System Maintenance</roles>
<user id="2"/>
<timeStamp>2009-09-22T12:04:42</timeStamp>
<timeStamp>2009-09-30T08:00:10</timeStamp>
<mom2:openedStatus/>
</mom2ObjectStatus>
</item>
......@@ -110,35 +110,35 @@
<equinox>J2000</equinox>
<duration>PT40M</duration>
<subbandsSpecification>
<bandWidth>5000000</bandWidth>
<centralFrequency>50000000</centralFrequency>
<bandWidth units="MHz">10</bandWidth>
<centralFrequency units="MHz">40</centralFrequency>
<contiguous>false</contiguous>
<subbands>304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336</subbands>
<subbands>224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288</subbands>
</subbandsSpecification>
</specification>
</measurementAttributes>
</lofar:measurement>
</item>
<item index="2">
<lofar:measurement mom2Id="30" xsi:type="lofar:UVMeasurementType">
<lofar:measurement mom2Id="53" xsi:type="lofar:UVMeasurementType">
<name>Calibrator 2</name>
<description>asdfasd</description>
<statusHistory>
<item index="0">
<mom2ObjectStatus>
<name>Verhoef, Ir. Bastiaan</name>
<roles>Craft User, Reviewer, System Maintenance</roles>
<roles>Craft User, manager, Reviewer, System Maintenance</roles>
<user id="2"/>
<timeStamp>2009-09-22T12:35:34</timeStamp>
<timeStamp>2009-09-30T08:00:42</timeStamp>
<mom2:describedStatus/>
</mom2ObjectStatus>
</item>
<item index="1">
<mom2ObjectStatus>
<name>Verhoef, Ir. Bastiaan</name>
<roles>Craft User, Reviewer, System Maintenance</roles>
<roles>Craft User, manager, Reviewer, System Maintenance</roles>
<user id="2"/>
<timeStamp>2009-09-22T12:04:42</timeStamp>
<timeStamp>2009-09-30T08:00:10</timeStamp>
<mom2:openedStatus/>
</mom2ObjectStatus>
</item>
......@@ -155,10 +155,10 @@
<equinox>J2000</equinox>
<duration>PT10M</duration>
<subbandsSpecification>
<bandWidth>5000000</bandWidth>
<centralFrequency>50000000</centralFrequency>
<bandWidth units="MHz">10</bandWidth>
<centralFrequency units="MHz">40</centralFrequency>
<contiguous>false</contiguous>
<subbands>304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336</subbands>
<subbands>224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288</subbands>
</subbandsSpecification>
</specification>
</measurementAttributes>
......@@ -168,9 +168,9 @@
<observationAttributes>
<specification>
<antenna>HBA Both</antenna>
<clock>160 MHz</clock>
<clock units="MHz">160</clock>
<instrument>Interferometer</instrument>
<instrumentFilter>10-80 MHz</instrumentFilter>
<instrumentFilter>10-90 MHz</instrumentFilter>
<integrationInterval>4</integrationInterval>
<stationSet>Custom</stationSet>
<stations>CS302,CS303</stations>
......
package nl.astron.lofar.odtb.mom2otdbadapter.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class Beam implements Serializable {
......@@ -17,12 +19,12 @@ public class Beam implements Serializable {
* Angle 1 (mom2 -> otdb)
* e.g. [6.123662, 5.233748, 1459568]
*/
private Double ra = null;
private List<Double> raList = new ArrayList<Double>();
/**
* Angle 2 (mom2 -> otdb)
* e.g. [1.026719, 0,711018, 0384089]
*/
private Double dec = null;
private List<Double> decList = new ArrayList<Double>();
/**
* Direction type (mom2 -> otdb)
......@@ -33,15 +35,15 @@ public class Beam implements Serializable {
/**
* duration
*/
private Integer duration;
private List<Integer> durations = new ArrayList<Integer>();
private Integer angleTime;
private List<Integer> angleTimes= new ArrayList<Integer>();
/**
* subbands that must be used (mom2 -> otdb)
* e.g. [1,3,5,7]
*/
private String subbands;
private List<String> subbands = new ArrayList<String>();
public Beam(LofarObservation observation){
this.parentObservation = observation;
......@@ -55,53 +57,53 @@ public class Beam implements Serializable {
this.mom2Id = mom2Id;
}
public Double getRa() {
return ra;
}
public void setRa(Double ra) {
this.ra = ra;
public String getEquinox() {
return equinox;
}
public Double getDec() {
return dec;
public void setEquinox(String equinox) {
this.equinox = equinox;
}
public void setDec(Double dec) {
this.dec = dec;
}
public String getEquinox() {
return equinox;
public List<Double> getRaList() {
return raList;
}
public void setEquinox(String equinox) {
this.equinox = equinox;
public void setRaList(List<Double> raList) {
this.raList = raList;
}
public Integer getDuration() {
return duration;
public List<Double> getDecList() {
return decList;
}
public void setDuration(Integer duration) {
this.duration = duration;
public void setDecList(List<Double> decList) {
this.decList = decList;
}
public List<Integer> getDurations() {
return durations;
}
public void setDurations(List<Integer> durations) {
this.durations = durations;
}
public Integer getAngleTime() {
return angleTime;
public List<Integer> getAngleTimes() {
return angleTimes;
}
public void setAngleTime(Integer angleTime) {
this.angleTime = angleTime;
public void setAngleTimes(List<Integer> angleTimes) {
this.angleTimes = angleTimes;
}
public String getSubbands() {
public List<String> getSubbands() {
return subbands;
}
public void setSubbands(String subbands) {
public void setSubbands(List<String> subbands) {
this.subbands = subbands;
}
......
......@@ -52,7 +52,7 @@ public class LofarObservation implements Serializable{
* Stations that belongs to the array configuration (mom2 -> otdb)
* e.g. [CS001,CS002]
*/
private String stations;
private List<String> stations = new ArrayList<String>();
private String antennaArray;
......@@ -140,11 +140,11 @@ public class LofarObservation implements Serializable{
public void setStationSet(String stationSet) {
this.stationSet = stationSet;
}
public String getStations() {
public List<String> getStations() {
return stations;
}
public void setStations(String stations) {
public void setStations(List<String> stations) {
this.stations = stations;
}
......
......@@ -13,6 +13,7 @@ import nl.astron.lofar.odtb.mom2otdbadapter.config.OTDBConfiguration;
import nl.astron.lofar.sas.otb.jotdb2.jConverterInterface;
import nl.astron.lofar.sas.otb.jotdb2.jOTDBinterface;
import nl.astron.lofar.sas.otb.jotdb2.jOTDBnode;
import nl.astron.lofar.sas.otb.jotdb2.jOTDBtree;
import nl.astron.lofar.sas.otb.jotdb2.jTreeMaintenanceInterface;
import nl.astron.lofar.sas.otb.jotdb2.jTreeState;
import nl.astron.util.AstronConverter;
......@@ -28,6 +29,58 @@ import org.apache.commons.logging.LogFactory;
*
*/
public class OTDBRepository implements Repository {
private static final String STRING_POINT = ".";
private static final String CHANNELS_PER_SUBBAND = "channelsPerSubband";
private static final String FILE_NAME_MASK = "MSNameMask";
private static final String INTEGRATION_STEPS = "integrationSteps";
private static final String IONPROC = "IONProc";
private static final String OLAP = "OLAP";
private static final String ONLINE_CONTROL = "OnlineControl";
private static final String OBSERVATION_CONTROL = "ObservationControl";
private static final String STATION_LIST = "stationList";
private static final String VIRTUAL_INSTRUMENT = "VirtualInstrument";
private static final String BEAM_MOM_ID = "momID";
private static final String SUBBAND_LIST = "subbandList";
private static final String DURATIONS = "durations";
private static final String ANGLE_TIMES = "angleTimes";
private static final String ANGLE2 = "angle2";
private static final String ANGLE1 = "angle1";
private static final String DIRECTION_TYPES = "directionTypes";
private static final String SAMPLE_CLOCK = "systemClock";
private static final String SUBBAND_WIDTH = "subbandWidth";
private static final String SAMPLES_PER_SECOND = "samplesPerSecond";
private static final String CHANNEL_WIDTH = "channelWidth";
private static final String BEAM = "Beam";
private static final String CLOCK_MODE = "clockMode";
private static final String BAND_FILTER = "bandFilter";
private static final String ANTENNA_SET = "antennaSet";
private static final String ANTENNA_ARRAY = "antennaArray";
private Log log = LogFactory.getLog(this.getClass());
private jOTDBinterface remoteOTDB = null;
......@@ -40,6 +93,8 @@ public class OTDBRepository implements Repository {
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
public static final String OTDB_DATE_TIME_FORMAT = "yyyy-MMM-dd HH:mm:ss";
private boolean connected = false;
private OTDBConfiguration config;
......@@ -78,33 +133,49 @@ public class OTDBRepository implements Repository {
public void store(LofarObservation lofarObservation) throws RepositoryException {
try {
init();
int treeId = tm.copyTemplateTree(config.getTemplateId());
Integer treeId = lofarObservation.getObservationId();
if (treeId == null) {
treeId = tm.copyTemplateTree(config.getTemplateId());
}
// int treeId = 6;
jOTDBnode observationNode = getObservationNode(treeId);
List<jOTDBnode> beams = new ArrayList<jOTDBnode>();
Vector<jOTDBnode> childs = getChilds(observationNode);
for (jOTDBnode node : childs) {
if ("antennaArray".equals(node.name)) {
if (ANTENNA_ARRAY.equals(node.name)) {
fillNode(node, lofarObservation.getAntennaArray());
} else if ("antennaSet".equals(node.name)) {
} else if (ANTENNA_SET.equals(node.name)) {
fillNode(node, lofarObservation.getAntennaSet());
} else if ("bandFilter".equals(node.name)) {
} else if (BAND_FILTER.equals(node.name)) {
fillNode(node, lofarObservation.getBandFilter());
} else if ("clockMode".equals(node.name)) {
} else if (CLOCK_MODE.equals(node.name)) {
fillNode(node, lofarObservation.getClockMode());
} else if ("Beam".equals(node.name)) {
} else if (BEAM.equals(node.name)) {
beams.add(node);
} else if ("VirtualInstrument".equals(node.name)) {
} else if (VIRTUAL_INSTRUMENT.equals(node.name)) {
jOTDBnode stationSetNode = getNode(node, "stationSet");
fillNode(stationSetNode, lofarObservation.getStationSet());
jOTDBnode stationsNode = getNode(node, "stationList");
jOTDBnode stationsNode = getNode(node, STATION_LIST);
fillNode(stationsNode, lofarObservation.getStations());
} else if (OBSERVATION_CONTROL.equals(node.name)) {
jOTDBnode onlineControlNode = getNode(node, ONLINE_CONTROL);
if (onlineControlNode != null) {
jOTDBnode olapNode = getNode(onlineControlNode, OLAP);
if (olapNode != null) {
jOTDBnode ionProcNode = getNode(olapNode, IONPROC);
if (ionProcNode != null) {
jOTDBnode integrationStepsNode = getNode(olapNode, INTEGRATION_STEPS);
fillNode(integrationStepsNode, lofarObservation.getIntegrationInterval().toString());
}
}
}
}
}
if (beams.size() > 0) {
for (int i = 1; i < beams.size(); i++) {
tm.deleteNode(beams.get(0));
tm.deleteNode(beams.get(i));
}
jOTDBnode aDefaultNode = beams.get(0);
......@@ -117,16 +188,20 @@ public class OTDBRepository implements Repository {
Vector<jOTDBnode> beamChilds = getChilds(beamNode);
// get all the params per child
for (jOTDBnode beamChild : beamChilds) {
if ("directionTypes".equals(beamChild.name)) {
if (DIRECTION_TYPES.equals(beamChild.name)) {
fillNode(beamChild, beam.getEquinox());
} else if ("angle1".equals(beamChild.name)) {
fillNode(beamChild, AstronConverter.toString(beam.getRa()));
} else if ("angle2".equals(beamChild.name)) {
fillNode(beamChild, AstronConverter.toString(beam.getDec()));
} else if ("angleTimes".equals(beamChild.name)) {
fillNode(beamChild, AstronConverter.toString(beam.getDuration()));
} else if ("subbandList".equals(beamChild.name)) {
} else if (ANGLE1.equals(beamChild.name)) {
fillNode(beamChild, beam.getRaList());
} else if (ANGLE2.equals(beamChild.name)) {
fillNode(beamChild, beam.getDecList());
} else if (ANGLE_TIMES.equals(beamChild.name)) {
fillNode(beamChild, beam.getAngleTimes());
} else if (DURATIONS.equals(beamChild.name)) {
fillNode(beamChild, beam.getDurations());
} else if (SUBBAND_LIST.equals(beamChild.name)) {
fillNode(beamChild, beam.getSubbands());
} else if (BEAM_MOM_ID.equals(beamChild.name)) {
fillNode(beamChild, beam.getMom2Id().toString());
}
saveNode(beamChild);
}
......@@ -146,6 +221,16 @@ public class OTDBRepository implements Repository {
}
}
@SuppressWarnings("unchecked")
private jOTDBnode getClockModeNode(int treeId, String clockMode) throws RemoteException {
jOTDBnode node = null;
Vector<jOTDBnode> childs = tm.getItemList(treeId, clockMode.substring(2));
if (childs.size() > 0) {
node = childs.get(0);
}
return node;
}
@SuppressWarnings("unchecked")
private Vector<jOTDBnode> getChilds(jOTDBnode node) throws RemoteException {
return tm.getItemList(node.treeID(), node.nodeID(), 1);
......@@ -155,7 +240,7 @@ public class OTDBRepository implements Repository {
@SuppressWarnings("unchecked")
private jOTDBnode getObservationNode(int treeId) throws RemoteException {
jOTDBnode node = null;
Vector<jOTDBnode> childs = tm.getItemList(treeId, "Observation");
Vector<jOTDBnode> childs = tm.getItemList(treeId, "%Observation");
if (childs.size() > 0) {
node = childs.get(0);
}
......@@ -178,6 +263,61 @@ public class OTDBRepository implements Repository {
}
}
private void fillNode(jOTDBnode node, List<?> values) throws RemoteException {
if (values != null && node != null) {
String value = "[";
for (int i = 0; i < values.size(); i++) {
if (i > 0) {
value += ",";
}
value += values.get(i);
}
value += "]";
node.limits = value;
saveNode(node);
}
}
private void fillDoubleList(jOTDBnode node, List<Double> values) throws RemoteException {
if (values != null && node != null) {
String value = node.limits.replaceAll("[\\]\\[ ]", "");
String[] array = value.split(",");
for (String arrayItem : array) {
Double doubleValue = AstronConverter.toDouble(arrayItem);
if (doubleValue != null) {
values.add(doubleValue);
}
}
}
}
private void fillStringList(jOTDBnode node, List<String> values) throws RemoteException {
if (values != null && node != null) {
String value = node.limits.replaceAll("[\\]\\[ ]", "");
String[] array = value.split(",");
for (String arrayItem : array) {
values.add(arrayItem);
}
}
}
private void fillIntegerList(jOTDBnode node, List<Integer> values) throws RemoteException {
if (values != null && node != null) {
String value = node.limits.replaceAll("[\\]\\[ ]", "");
String[] array = value.split(",");
for (String arrayItem : array) {
Integer intValue = AstronConverter.toInteger(arrayItem);
if (intValue != null) {
values.add(intValue);
}
}
}
}
/**
* Stores parameter in the tree by given parent node
*
......@@ -212,13 +352,14 @@ public class OTDBRepository implements Repository {
* @return node
* @throws RemoteException
*/
protected jOTDBnode getNode(jOTDBnode parentNode, String paramName) throws RemoteException {
@SuppressWarnings("unchecked")
private jOTDBnode getNode(jOTDBnode parentNode, String paramName) throws RemoteException {
jOTDBnode node = null;
/*
* if no parent node, do not retrieve something
*/
if (parentNode != null) {
Vector vector = tm.getItemList(parentNode.treeID(), paramName);
Vector<jOTDBnode> vector = tm.getItemList(parentNode.treeID(), paramName);
for (int i = 0; i < vector.size(); i++) {
node = (jOTDBnode) vector.get(i);
/*
......@@ -234,6 +375,23 @@ public class OTDBRepository implements Repository {
return node;
}
private String getValue(jOTDBnode parentNode, String paramName) throws RemoteException {
jOTDBnode node = getNode(parentNode, paramName);
if (node != null) {
return node.limits;
} else {
return null;
}
}
private String getValue(jOTDBnode node) throws RemoteException {
if (node != null) {
return node.limits;
} else {
return null;
}
}
/**
* Retrieve lates changes between start- en endtime
*
......@@ -244,42 +402,44 @@ public class OTDBRepository implements Repository {
* @return List of lofarObservation objects
* @throws RemoteException
*/
public List getLatestChanges(Date startDate, Date endDate) throws RepositoryException {
@SuppressWarnings("unchecked")
public List<LofarObservation> getLatestChanges(Date startDate, Date endDate) throws RepositoryException {
try {
init();
String startTime = AstronConverter.toDateString(startDate, DATE_TIME_FORMAT);
String endTime = AstronConverter.toDateString(endDate, DATE_TIME_FORMAT);
log.info("Retrieve latest changes between:" + startTime + " and " + endTime);
remoteOTDB.connect();
List result = new ArrayList();
Vector stateList = remoteOTDB.getStateList(0, false, startTime, endTime);
List<LofarObservation> result = new ArrayList<LofarObservation>();
Vector<jTreeState> stateList = remoteOTDB.getStateList(0, false, startTime, endTime);
for (int i = 0; i < stateList.size(); i++) {
jTreeState state = (jTreeState) stateList.get(i);
jOTDBtree treeInfo = remoteOTDB.getTreeInfo(state.treeID, false);
String status = converter.getTreeState(state.newState);
log.info("momId: " + state.momID + " status:" + status + " statusId:" + state.newState);
log.info("treeId: " + state.treeID + " momId: " + state.momID + " status:" + status + " statusId:"
+ state.newState);
if (state.momID > 0 && isStatusThatMustBeExported(status)) {
LofarObservation observation = new LofarObservation();
observation.setMom2Id(state.momID);
observation.setStatus(status);
// observation.setTimeStamp(state.timestamp);
jOTDBnode observationNode = tm.getTopNode(state.treeID);
jOTDBnode measurementsNode = getNode(observationNode, "measurementMom2Ids");
// observation.setMeasurementMom2Ids(measurementsNode.limits);
// if (status.equals("finished")){
// jOTDBnode viNode = getNode(observationNode, "VI1");
// jOTDBnode angle1 = getNode(viNode, "angle1");
// jOTDBnode angle2 = getNode(viNode, "angle2");
// jOTDBnode angleTimes = getNode(viNode, "angleTimes");
// observation.setAngle1(angle1.limits);
// observation.setAngle2(angle2.limits);
// observation.setAngleTimes(angleTimes.limits);
// jOTDBtree treeInfo =
// remoteOTDB.getTreeInfo(state.treeID,false);
// observation.setStartTime(treeInfo.starttime);
// observation.setEndTime(treeInfo.stoptime);
// }
result.add(observation);
LofarObservation lofarObservation = new LofarObservation();
lofarObservation.setMom2Id(state.momID);
lofarObservation.setObservationId(state.treeID);
lofarObservation.setStatus(status);
// it must be a template
if (treeInfo.originalTree == config.getTemplateId()) {
jOTDBnode observationNode = getObservationNode(state.treeID);
fillLofarObservation("", observationNode, lofarObservation);
} else {
jOTDBnode observationNode = getObservationNode(state.treeID);
String prefix = observationNode.name + STRING_POINT;
fillLofarObservation(prefix, observationNode, lofarObservation);
lofarObservation
.setStartTime(AstronConverter.toDate(treeInfo.starttime, OTDB_DATE_TIME_FORMAT));
lofarObservation.setEndTime(AstronConverter.toDate(treeInfo.stoptime, OTDB_DATE_TIME_FORMAT));
}
result.add(lofarObservation);
}
}
......@@ -292,6 +452,92 @@ public class OTDBRepository implements Repository {
throw new RepositoryException(e);
}
}
private void fillLofarObservation(String prefix, jOTDBnode observationNode, LofarObservation lofarObservation) throws RemoteException{
List<jOTDBnode> beams = new ArrayList<jOTDBnode>();
Vector<jOTDBnode> childs = getChilds(observationNode);
for (jOTDBnode node : childs) {
if (ANTENNA_ARRAY.equals(node.name)) {
lofarObservation.setAntennaArray(getValue(node));
} else if (ANTENNA_SET.equals(node.name)) {
lofarObservation.setAntennaSet(getValue(node));
} else if (BAND_FILTER.equals(node.name)) {
lofarObservation.setBandFilter(getValue(node));
} else if (CLOCK_MODE.equals(node.name)) {
String clockMode = getValue(node);
jOTDBnode clockNode = getClockModeNode(lofarObservation.getObservationId(), clockMode);
Vector<jOTDBnode> clockNodeChilds = getChilds(clockNode);
for (jOTDBnode clockNodeChild : clockNodeChilds) {
if (CHANNEL_WIDTH.equals(clockNodeChild.name)) {
lofarObservation.setChannelWidth(AstronConverter
.toDouble(getValue(clockNodeChild)));
} else if (SAMPLES_PER_SECOND.equals(clockNodeChild.name)) {
lofarObservation.setSamplesPerSecond(AstronConverter
.toInteger(getValue(clockNodeChild)));
} else if (SUBBAND_WIDTH.equals(clockNodeChild.name)) {
lofarObservation.setSubbandWidth(AstronConverter
.toDouble(getValue(clockNodeChild)));
} else if (SAMPLE_CLOCK.equals(clockNodeChild.name)) {
lofarObservation.setClockFrequency(AstronConverter
.toDouble(getValue(clockNodeChild)));
}
}
} else if (CHANNELS_PER_SUBBAND.equals(node.name)) {
lofarObservation.setChannelsPerSubband(AstronConverter.toInteger(getValue(node)));
} else if (FILE_NAME_MASK.equals(node.name)) {
lofarObservation.setFileNameMask((getValue(node)));
} else if (BEAM.equals(node.name)) {
beams.add(node);
} else if (VIRTUAL_INSTRUMENT.equals(node.name)) {
jOTDBnode stationsNode = getNode(node, STATION_LIST);
fillStringList(stationsNode, lofarObservation.getStations());
} else if (OBSERVATION_CONTROL.equals(node.name)) {
jOTDBnode onlineControlNode = getNode(node, ONLINE_CONTROL);
if (onlineControlNode != null) {
jOTDBnode olapNode = getNode(onlineControlNode, OLAP);
if (olapNode != null) {
jOTDBnode ionProcNode = getNode(olapNode, IONPROC);
if (ionProcNode != null) {
lofarObservation.setIntegrationInterval(AstronConverter.toDouble(getValue(
olapNode, INTEGRATION_STEPS)));
}
}
}
}
}
if (beams.size() > 0) {
// remove default beam
beams.remove(0);
for (jOTDBnode beamNode : beams) {
Beam beam = new Beam(lofarObservation);
Vector<jOTDBnode> beamChilds = getChilds(beamNode);
// get all the params per child
for (jOTDBnode beamChild : beamChilds) {
if (DIRECTION_TYPES.equals(beamChild.name)) {
beam.setEquinox(getValue(beamChild));
} else if (ANGLE1.equals(beamChild.name)) {
fillDoubleList(beamChild, beam.getRaList());
} else if (ANGLE2.equals(beamChild.name)) {
fillDoubleList(beamChild, beam.getDecList());
} else if (ANGLE_TIMES.equals(beamChild.name)) {
fillIntegerList(beamChild, beam.getAngleTimes());
} else if (DURATIONS.equals(beamChild.name)) {
fillIntegerList(beamChild, beam.getDurations());
} else if (SUBBAND_LIST.equals(beamChild.name)) {
fillStringList(beamChild, beam.getSubbands());
} else if (BEAM_MOM_ID.equals(beamChild.name)) {
beam.setMom2Id(AstronConverter.toInteger(getValue(beamChild)));
}
}
lofarObservation.getBeams().add(beam);
}
}
}
/**
* Checkes if observation with a status must be exported to MoM
......
......@@ -27,7 +27,7 @@ public class StubRepository implements Repository {
}else if (Mom2OtdbConverter.OTDB_FINISHED_STATUS.equals(observation.getStatus())){
int duration = 0;
for (Beam beam : observation.getBeams()) {
duration += beam.getDuration();
duration += beam.getDurations().get(0);
}
Date endTime = (Date) observation.getStartTime().clone();
endTime.setSeconds(duration);
......
......@@ -66,8 +66,8 @@ public class XMLParser {
}
int offSet = 0;
for (Beam beam: lofarObservation.getBeams()){
beam.setAngleTime(offSet);
offSet += beam.getDuration();
beam.getAngleTimes().add(offSet);
offSet += beam.getDurations().get(0);
}
return lofarObservation;
}
......@@ -93,6 +93,10 @@ public class XMLParser {
if (elements.containsKey(XMLConstants.CLOCK)) {
lofarObservation.setClockMode(Mom2OtdbConverter.getOTDBClockMode(getMHzFrequency(elements.get(XMLConstants.CLOCK))));
}
if (elements.containsKey(XMLConstants.INTEGRATION_INTERVAL)) {
lofarObservation.setIntegrationInterval(AstronConverter.toDouble(getValue(elements
.get(XMLConstants.INTEGRATION_INTERVAL))));
}
if (elements.containsKey(XMLConstants.INSTRUMENT_FILTER)) {
lofarObservation.setBandFilter(Mom2OtdbConverter.getOTDBBandFilter(getValue(elements
.get(XMLConstants.INSTRUMENT_FILTER)), lofarObservation.getAntennaArray()));
......@@ -101,9 +105,9 @@ public class XMLParser {
lofarObservation.setStationSet(getValue(elements.get(XMLConstants.STATION_SET)));
}
if (elements.containsKey(XMLConstants.STATIONS)) {
lofarObservation.setStations(getValue(elements.get(XMLConstants.STATIONS)));
if (lofarObservation.getStations() != null) {
lofarObservation.setStations("[" + lofarObservation.getStations() + "]");
String[] stations = getValue(elements.get(XMLConstants.STATIONS)).split(",");
for(String station: stations){
lofarObservation.getStations().add(station);
}
}
......@@ -241,16 +245,16 @@ public class XMLParser {
Element specification = (Element) specificationList.item(0);
Map<String, Element> elements = getElementMap(specification.getChildNodes());
if (elements.containsKey(XMLConstants.RA)) {
beam.setRa(AstronConverter.toDouble(getValue(elements.get(XMLConstants.RA))));
beam.getRaList().add(AstronConverter.toDouble(getValue(elements.get(XMLConstants.RA))));
}
if (elements.containsKey(XMLConstants.DEC)) {
beam.setDec(AstronConverter.toDouble(getValue(elements.get(XMLConstants.DEC))));
beam.getDecList().add(AstronConverter.toDouble(getValue(elements.get(XMLConstants.DEC))));
}
if (elements.containsKey(XMLConstants.EQUINOX)) {
beam.setEquinox(getValue(elements.get(XMLConstants.EQUINOX)));
}
if (elements.containsKey(XMLConstants.DURATION)) {
beam.setDuration(AstronConverter.convertXMLDurationToSeconds(getValue(elements
beam.getDurations().add(AstronConverter.convertXMLDurationToSeconds(getValue(elements
.get(XMLConstants.DURATION))));
}
if (elements.containsKey(XMLConstants.SUBBANDS_SPECIFICATION)) {
......@@ -258,7 +262,11 @@ public class XMLParser {
Map<String, Element> subbandsSpecificationsElements = getElementMap(subbandsSpecificationsElement
.getChildNodes());
if (subbandsSpecificationsElements.containsKey(XMLConstants.SUBBANDS)) {
beam.setSubbands("[" + getValue(subbandsSpecificationsElements.get(XMLConstants.SUBBANDS)) + "]");
String[] subbands = getValue(subbandsSpecificationsElements.get(XMLConstants.SUBBANDS)).split(",");
for(String subband: subbands){
beam.getSubbands().add(subband);
}
}
}
......
......@@ -26,6 +26,8 @@ import org.w3c.dom.Element;
*/
public class XMLGenerator {
private static final String STATION_NAME = "name";
private static final String MOM2_LOFAR_PREFIX = "lofar";
......@@ -96,7 +98,7 @@ public class XMLGenerator {
xmlBuilder.addTextElement(clockElement, "samplesPerSecond", observation.getSamplesPerSecond());
xmlBuilder.addFrequencyElement(clockElement, "subbandWidth", observation.getSubbandWidth());
xmlBuilder.addFrequencyElement(clockElement, "systemClock", observation.getClockFrequency());
xmlBuilder.addTextElement(observationAttributes, "integrationInterval", observation.getIntegrationInterval());
xmlBuilder.addTextElement(observationAttributes, XMLConstants.INTEGRATION_INTERVAL, observation.getIntegrationInterval());
xmlBuilder.addTextElement(observationAttributes, "channelsPerSubband", observation.getChannelsPerSubband());
xmlBuilder.addTextElement(observationAttributes, XMLConstants.INSTRUMENT_FILTER, Mom2OtdbConverter
.getMom2InstrumentFilter(observation.getBandFilter()));
......@@ -107,7 +109,7 @@ public class XMLGenerator {
if (observation.getStations() != null) {
Element stationsElement = xmlBuilder.addElement(observationAttributes, XMLConstants.STATIONS);
for (String station : Mom2OtdbConverter.getStringArray(observation.getStations())) {
for (String station : observation.getStations()) {
Element stationElement = xmlBuilder.addElement(stationsElement, XMLConstants.STATION);
xmlBuilder.addTextElement(stationElement, STATION_NAME, station);
}
......@@ -129,42 +131,47 @@ public class XMLGenerator {
xmlBuilder.addTypeAttributeToElement(measurementElement, XMLConstants.MOM2_LOFAR_NAMESPACE,
XMLConstants.UVMEASUREMENT_TYPE);
xmlBuilder.addAttributeToElement(measurementElement, XMLConstants.MOM2_ID, beam.getMom2Id().toString());
String[] subbands = Mom2OtdbConverter.getStringArray(beam.getSubbands());
if (Mom2OtdbConverter.OTDB_FINISHED_STATUS.equals(beam.getParentObservation().getStatus())) {
String fileMask = beam.getParentObservation().getFileNameMask();
fileMask = fileMask.substring(fileMask.lastIndexOf("/") + 1);
fileMask = fileMask.replaceAll("\\$\\{OBSERVATION\\}", beam.getParentObservation().getObservationId()
.toString());
fileMask = fileMask.replaceAll("\\$\\{BEAM\\}", index + "");
if (subbands.length > 0) {
if (beam.getSubbands().size() > 0) {
Element resultDataProducts = xmlBuilder.addElement(measurementElement, "resultDataProducts");
for (int i = 0; i < subbands.length; i++) {
for (int i = 0; i < beam.getSubbands().size(); i++) {
Element uvDataProduct = xmlBuilder.addIndexedElement(resultDataProducts, "uvDataProduct");
xmlBuilder.addTextElement(uvDataProduct, "name", fileMask.replaceAll("\\$\\{SUBBAND\\}", i + ""));
xmlBuilder.addTextElement(uvDataProduct, "fileFormat", Mom2OtdbConverter.getMom2DPFileType(fileMask));
xmlBuilder.addTextElement(uvDataProduct, "fileFormat", Mom2OtdbConverter
.getMom2DPFileType(fileMask));
xmlBuilder.addTextElement(uvDataProduct, "subband", i);
xmlBuilder.addTextElement(uvDataProduct, "stationSubband", subbands[i]);
xmlBuilder.addTextElement(uvDataProduct, "stationSubband", beam.getSubbands().get(i));
}
}
}
Element measurementAttributes = xmlBuilder.addElement(measurementElement, XMLConstants.MEASUREMENT_ATTRIBUTES);
xmlBuilder.addTextElement(measurementAttributes, XMLConstants.RA, beam.getRa());
xmlBuilder.addTextElement(measurementAttributes, XMLConstants.DEC, beam.getDec());
if (beam.getRaList().size() > 0 && beam.getDecList().size() > 0 && beam.getDurations().size() > 0
&& beam.getAngleTimes().size() > 0) {
xmlBuilder.addTextElement(measurementAttributes, XMLConstants.RA, beam.getRaList().get(0));
xmlBuilder.addTextElement(measurementAttributes, XMLConstants.DEC, beam.getDecList().get(0));
xmlBuilder.addTextElement(measurementAttributes, XMLConstants.EQUINOX, beam.getEquinox());
xmlBuilder.addDurationElement(measurementAttributes, XMLConstants.DURATION, beam.getDuration());
xmlBuilder.addDurationElement(measurementAttributes, XMLConstants.DURATION, beam.getDurations().get(0));
Date startTime = beam.getParentObservation().getStartTime();
if (startTime != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(startTime);
cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + beam.getAngleTime());
cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + beam.getAngleTimes().get(0));
xmlBuilder.addTextDateTimeElement(measurementAttributes, XMLConstants.START_TIME, cal.getTime());
if (beam.getParentObservation().getEndTime() != null) {
cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + beam.getDuration());
cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + beam.getDurations().get(0));
xmlBuilder.addTextDateTimeElement(measurementAttributes, XMLConstants.END_TIME, cal.getTime());
}
}
}
xmlBuilder.addTextElement(measurementAttributes, XMLConstants.SUBBANDS, Mom2OtdbConverter.getMom2Subbands(beam
.getSubbands()));
......@@ -190,4 +197,5 @@ public class XMLGenerator {
}
return result + XMLConstants.STATUS_SUFFIX;
}
}
package nl.astron.lofar.odtb.mom2otdbadapter.util;
import java.text.DecimalFormat;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Converts mom2 values to otdb values
*
......@@ -38,19 +37,21 @@ public class Mom2OtdbConverter {
private static final String CLOCK_MODE = "<<Clock";
private static final DecimalFormat CLOCK_FORMATTER = new DecimalFormat("000");
private static final Pattern INSTRUMENT_FILTER_PATTERN = Pattern.compile("(\\d+-\\d+)" + MHZ_SUFFIX);
public static String getOTDBClockMode(Double clock) {
return CLOCK_MODE + CLOCK_FORMATTER.format(clock);
}
public static String getOTDBAntennaArray(String antenna) {
return antenna.substring(0, 3).toUpperCase();
}
public static String getOTDBAntennaSet(String antenna) {
return antenna.toUpperCase().replace(' ', '_');
}
public static String getOTDBBandFilter(String instrumentFilter, String antennaArray) {
String result = antennaArray + "_";
Matcher filterMatcher = INSTRUMENT_FILTER_PATTERN.matcher(instrumentFilter);
......@@ -61,7 +62,9 @@ public class Mom2OtdbConverter {
/**
* Convert OTDB status from mom status
* @param status Mom2 status
*
* @param status
* Mom2 status
* @return OTDB status
*/
public static String getOTDBStatus(String status) {
......@@ -74,24 +77,39 @@ public class Mom2OtdbConverter {
}
public static String getMom2Antenna(String antennaSet) {
if (antennaSet != null) {
String result = antennaSet.replace('_', ' ');
int n = result.indexOf(' ');
n = n + 2;
result = result.substring(0, n) + result.substring(n, result.length()).toLowerCase();
return result;
}
return null;
}
public static String getMom2InstrumentFilter(String bandFilter) {
if (bandFilter != null) {
return bandFilter.substring(4).replace('_', '-') + MHZ_SUFFIX;
}
return null;
}
public static String[] getStringArray(String string) {
String temp = string.replaceAll("[\\]\\[ ]", "");
return temp.split(",");
}
public static String getMom2Subbands(String string){
return string.replaceAll("[\\]\\[]" , "");
public static String getMom2Subbands(List<String> subbands) {
String result = "";
for (int i = 0; i < subbands.size(); i++) {
if (i > 0) {
result += ",";
}
result += subbands.get(i);
}
return result;
}
public static String getMom2DPFileType(String fileMask) {
if (fileMask.endsWith(MS_EXTENSION)) {
return AIPS_CASA;
......
......@@ -13,6 +13,8 @@ public final class XMLConstants {
public static final String STATION_SET = "stationSet";
public static final String INTEGRATION_INTERVAL = "integrationInterval";
public static final String INSTRUMENT_FILTER = "instrumentFilter";
public static final String CLOCK = "clock";
......
......@@ -15,38 +15,42 @@ public class OTDBRepositoryTest {
OTDBConfiguration config =new OTDBConfiguration();
config.setRmiHost("lofar17");
config.setRmiPort(10500);
config.setTemplateId(5001);
repository = new OTDBRepository(config);
}
@Test
public void testStore() throws RepositoryException{
LofarObservation lofarObservation = new LofarObservation();
lofarObservation.setMom2Id(3);
lofarObservation.setStatus("being specified");
lofarObservation.setAntennaArray("HBA");
lofarObservation.setAntennaSet("HBA_TWO");
lofarObservation.setBandFilter("HBA_100_190");
lofarObservation.setClockMode("<<Clock200");
lofarObservation.setStationSet("Custom");
lofarObservation.setStations("[CS302, CS010]");
Beam beam = new Beam(lofarObservation);
beam.setRa(85.650575);
beam.setDec(49.852009);
beam.setEquinox("J2000");
beam.setDuration(423);
beam.setSubbands("[123,124]");
lofarObservation.getBeams().add(beam);
beam = new Beam(lofarObservation);
beam.setRa(85.650575);
beam.setDec(49.852009);
beam.setEquinox("J2000");
beam.setDuration(42);
beam.setSubbands("[1,2,3,4]");
lofarObservation.getBeams().add(beam);
repository.store(lofarObservation);
}
// @Test
// public void testStore() throws RepositoryException{
// LofarObservation lofarObservation = new LofarObservation();
// lofarObservation.setMom2Id(3);
// lofarObservation.setStatus("being specified");
// lofarObservation.setAntennaArray("HBA");
// lofarObservation.setAntennaSet("HBA_TWO");
// lofarObservation.setBandFilter("HBA_100_190");
// lofarObservation.setClockMode("<<Clock200");
// lofarObservation.setStationSet("Custom");
// lofarObservation.setStations("[CS302, CS010]");
// lofarObservation.setIntegrationInterval(3d);
// Beam beam = new Beam(lofarObservation);
// beam.setRa(85.650575);
// beam.setDec(49.852009);
// beam.setEquinox("J2000");
// beam.setAngleTime(0);
// beam.setDuration(423);
// beam.setSubbands("[123,124]");
// lofarObservation.getBeams().add(beam);
// beam = new Beam(lofarObservation);
// beam.setRa(85.650575);
// beam.setDec(49.852009);
// beam.setEquinox("J2000");
// beam.setAngleTime(423);
// beam.setDuration(42);
// beam.setSubbands("[1,2,3,4]");
// lofarObservation.getBeams().add(beam);
// repository.store(lofarObservation);
//
// }
@Test
public void testGetLatestChanges() throws RepositoryException {
......
......@@ -3,7 +3,9 @@ package nl.astron.lofar.odtb.mom2otdbadapter.mom2listener;
import java.io.File;
import java.io.FileInputStream;
import nl.astron.lofar.odtb.mom2otdbadapter.config.OTDBConfiguration;
import nl.astron.lofar.odtb.mom2otdbadapter.data.LofarObservation;
import nl.astron.lofar.odtb.mom2otdbadapter.data.OTDBRepository;
import nl.astron.util.XMLConverter;
import org.junit.Test;
......@@ -18,6 +20,12 @@ public class XMLParserTest {
InputSource inputSource = new InputSource(st);
Document document = XMLConverter.convertXMLToDocument(inputSource, null);
LofarObservation lofarObservation = XMLParser.getLofarObservation(document);
OTDBConfiguration config =new OTDBConfiguration();
config.setRmiHost("lofar17");
config.setRmiPort(10500);
config.setTemplateId(5001);
OTDBRepository repository = new OTDBRepository(config);
repository.store(lofarObservation);
System.out.println("YES");
}
......
......@@ -3,62 +3,43 @@ package nl.astron.lofar.odtb.mom2otdbadapter.otdblistener;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import nl.astron.lofar.odtb.mom2otdbadapter.config.Mom2Configuration;
import nl.astron.lofar.odtb.mom2otdbadapter.data.Beam;
import nl.astron.lofar.odtb.mom2otdbadapter.config.OTDBConfiguration;
import nl.astron.lofar.odtb.mom2otdbadapter.data.LofarObservation;
import nl.astron.util.AstronConverter;
import nl.astron.lofar.odtb.mom2otdbadapter.data.OTDBRepository;
import nl.astron.lofar.odtb.mom2otdbadapter.data.RepositoryException;
import org.junit.Test;
public class XMLGeneratorTest {
@Test
public void testGetObservationXml() throws IOException, ParserConfigurationException {
LofarObservation lofarObservation = new LofarObservation();
lofarObservation.setMom2Id(3);
lofarObservation.setAntennaSet("HBA_TWO");
lofarObservation.setBandFilter("HBA_110_190");
lofarObservation.setClockMode("<<Clock200");
lofarObservation.setStations("[CS302, CS010]");
lofarObservation.setStatus("finished");
lofarObservation.setObservationId(15);
lofarObservation.setStartTime(AstronConverter.toDate("2009/06/24 13:00 UTC"));
lofarObservation.setEndTime(AstronConverter.toDate("2009/06/24 13:30 UTC"));
lofarObservation.setClockFrequency(200000000d);
lofarObservation.setSubbandWidth(195312.5d);
lofarObservation.setChannelWidth(762.93945d);
lofarObservation.setChannelsPerSubband(256);
lofarObservation.setSamplesPerSecond(196608);
lofarObservation.setFileNameMask("/data/L${YEAR}_${MSNUMBER}/L${OBSERVATION}_B${BEAM}_SB${SUBBAND}.MS" );
Beam beam = new Beam(lofarObservation);
beam.setMom2Id(4);
beam.setRa(85.650575);
beam.setDec(49.852009);
beam.setEquinox("J2000");
beam.setDuration(4230);
beam.setSubbands("[123,124]");
lofarObservation.getBeams().add(beam);
beam = new Beam(lofarObservation);
beam.setMom2Id(5);
beam.setRa(85.650575);
beam.setDec(49.852009);
beam.setEquinox("J2000");
beam.setDuration(420);
beam.setSubbands("[1,2,3,4]");
lofarObservation.getBeams().add(beam);
Mom2Configuration config = new Mom2Configuration();
config.setMom2SchemasUrl("C:/java/workspace/MoM-OTDB-adapter/schemas/");
String xml = XMLGenerator.getObservationXml(lofarObservation, config);
File file = new File("examples/obs.xml");
public void testGetObservationXml() throws IOException, ParserConfigurationException, RepositoryException {
OTDBConfiguration config = new OTDBConfiguration();
config.setRmiHost("lofar17");
config.setRmiPort(10500);
config.setTemplateId(5001);
OTDBRepository repository = new OTDBRepository(config);
Date startDate = new Date();
startDate.setMonth(4);
Date endDate = new Date();
List<LofarObservation> lofarObservations = repository.getLatestChanges(startDate, endDate);
if (lofarObservations.size() > 0) {
LofarObservation lofarObservation = lofarObservations.get(0);
Mom2Configuration mom2Config = new Mom2Configuration();
mom2Config.setMom2SchemasUrl("C:/java/workspace/MoM-OTDB-adapter/schemas/");
String xml = XMLGenerator.getObservationXml(lofarObservation, mom2Config);
File file = new File("examples/obs-" + lofarObservation.getMom2Id() + "-" + lofarObservation.getStatus() + ".xml");
PrintWriter writer = new PrintWriter(file);
writer.print(xml);
writer.flush();
writer.close();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment