diff --git a/.gitattributes b/.gitattributes index 302479b28b341a0ea8e424c753e31db38ff89c0b..7817f74ff24b61d2ded4d73558ad6d48fd70f312 100644 --- a/.gitattributes +++ b/.gitattributes @@ -739,6 +739,11 @@ MAC/_System/lofar30.journal -text svneol=native#application/octet-stream MAC/_System/lofar30.sysconf -text svneol=native#application/octet-stream MAC/bootstrap -text svneol=native#application/octet-stream MAC/lofarconf.in -text svneol=native#application/octet-stream +SAS/OTB/MoM-OTDB-adapter/.cvsignore -text +SAS/OTB/MoM-OTDB-adapter/lib/astron-http-utils.jar -text +SAS/OTB/MoM-OTDB-adapter/lib/astron-utils.jar -text +SAS/OTB/MoM-OTDB-adapter/lib/commons-httpclient-3.0-rc4.jar -text +SAS/OTB/MoM-OTDB-adapter/lib/commons-validator.jar -text SAS/OTB/jOTDB/src/jOTDB/jOTDBinterface.jar -text svneol=unset#unset SAS/OTB/jOTDB/src/jOTDB/jOTDBserver.jar -text svneol=unset#unset SDP/SPP/DSP[!!-~]BUILDER/myfilterbank.mdl -text diff --git a/.gitignore b/.gitignore index 698285e7550ce3d25b08c2736c86aca917b651fe..719bbe1b0ecdd5f598aea473295a87487f179c04 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ MAC/Navigator/panels/nav_fw/test.pnl +SAS/OTB/MoM-OTDB-adapter/bin diff --git a/SAS/OTB/MoM-OTDB-adapter/.classpath b/SAS/OTB/MoM-OTDB-adapter/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ff55ad5e90b03e62b0dbc5ffcd3513f6da0026dc --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/.classpath @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="lib" path="C:/jotdb.jar"/> + <classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/> + <classpathentry kind="lib" path="lib/commons-logging.jar"/> + <classpathentry kind="lib" path="lib/xercesImpl.jar"/> + <classpathentry kind="lib" path="lib/xml-apis.jar"/> + <classpathentry sourcepath="/AstronHttpUtils" kind="lib" path="lib/astron-http-utils.jar"/> + <classpathentry kind="lib" path="lib/commons-httpclient-3.0-rc4.jar"/> + <classpathentry kind="lib" path="lib/astron-utils.jar"/> + <classpathentry kind="lib" path="lib/commons-validator.jar"/> + <classpathentry sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip" kind="var" path="JUNIT_HOME/junit.jar"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/SAS/OTB/MoM-OTDB-adapter/.cvsignore b/SAS/OTB/MoM-OTDB-adapter/.cvsignore new file mode 100644 index 0000000000000000000000000000000000000000..ba077a4031add5b3a04384f8b9cfc414efbf47dd --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/SAS/OTB/MoM-OTDB-adapter/.project b/SAS/OTB/MoM-OTDB-adapter/.project new file mode 100644 index 0000000000000000000000000000000000000000..2de9036249ee0196b1f628dc8123c7951d4d7e8f --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>MoM-OTDB-adapter</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/SAS/OTB/MoM-OTDB-adapter/META-INF/MANIFEST.MF b/SAS/OTB/MoM-OTDB-adapter/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..44b6c52f8e9f76930e598484949011ee97f02f6c --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Ant-Version: Apache Ant 1.5.4 +Main-class: nl.astron.mom2.lofar.odtb.Mom2OTDBAdapter diff --git a/SAS/OTB/MoM-OTDB-adapter/build/build.xml b/SAS/OTB/MoM-OTDB-adapter/build/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..30dd72b7e45e26605ae0fc1ec7d126fd02f0f435 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/build/build.xml @@ -0,0 +1,41 @@ +<?xml version = '1.0' encoding = 'windows-1252'?> + +<project name="Scotty" default="Main Build" basedir="."> + + <property name="projectDir" value=".."/> + <property name="src" value="${projectDir}"/> + <property name="lib" value="${projectDir}/lib"/> + <property name="bin" value="${projectDir}/bin"/> + <property name="jarFile" value="${bin}/mom-otdb-adapter.jar"/> + + + <!-- setup classpath to include jars --> + <path id="classpath"> + <fileset dir="${lib}"> + <include name="*.jar"/> + </fileset> + </path> + + <target name="Main Build" depends="compile,jar"></target> + + <target name="init"> + <delete dir="${bin}"/> + <mkdir dir="${bin}"/> + </target> + + + <target name="compile" depends="init"> + <javac srcdir="${src}" destdir="${bin}" debug="off" > + + <!-- tell the compiler to use my classpath (with the xerces jars) --> + <classpath refid="classpath" /> + + </javac> + </target> + + <target name="jar" depends="compile"> + <jar destfile="${jarFile}" basedir="${bin}" + manifest="${projectDir}/META-INF/MANIFEST.MF"/> + </target> + +</project> diff --git a/SAS/OTB/MoM-OTDB-adapter/lib/astron-http-utils.jar b/SAS/OTB/MoM-OTDB-adapter/lib/astron-http-utils.jar new file mode 100644 index 0000000000000000000000000000000000000000..08d1d413790820159585c705b3c069935fab0c6f Binary files /dev/null and b/SAS/OTB/MoM-OTDB-adapter/lib/astron-http-utils.jar differ diff --git a/SAS/OTB/MoM-OTDB-adapter/lib/astron-utils.jar b/SAS/OTB/MoM-OTDB-adapter/lib/astron-utils.jar new file mode 100644 index 0000000000000000000000000000000000000000..727f03d4a6b72a1cd09ea27254bc9fd53b58e080 Binary files /dev/null and b/SAS/OTB/MoM-OTDB-adapter/lib/astron-utils.jar differ diff --git a/SAS/OTB/MoM-OTDB-adapter/lib/commons-httpclient-3.0-rc4.jar b/SAS/OTB/MoM-OTDB-adapter/lib/commons-httpclient-3.0-rc4.jar new file mode 100644 index 0000000000000000000000000000000000000000..9a6881b7d75b4f9295e98336653ee17b6da16d9c Binary files /dev/null and b/SAS/OTB/MoM-OTDB-adapter/lib/commons-httpclient-3.0-rc4.jar differ diff --git a/SAS/OTB/MoM-OTDB-adapter/lib/commons-validator.jar b/SAS/OTB/MoM-OTDB-adapter/lib/commons-validator.jar new file mode 100644 index 0000000000000000000000000000000000000000..e3f9aafb23276e66846343e4f388a2566123e2c5 Binary files /dev/null and b/SAS/OTB/MoM-OTDB-adapter/lib/commons-validator.jar differ diff --git a/SAS/OTB/MoM-OTDB-adapter/src/log4j.properties b/SAS/OTB/MoM-OTDB-adapter/src/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..5041c3ba624233fb573752324c3d0b0443152d8b --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/log4j.properties @@ -0,0 +1,22 @@ +# +# Configures Log4j as the Tomcat system logger +# +log4j.rootLogger=INFO, CONSOLE + +# +# Configuration for standard output ("catalina.out"). +# +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p %c:%L - %m\n + + +# +# Application logging options +# +log4j.logger.nl.astron.lofar=DEBUG, CONSOLE + + + + + diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/MomOtdbAdapter.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/MomOtdbAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..2616ec2af53111ef806243735683087d5fefa2fa --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/MomOtdbAdapter.java @@ -0,0 +1,25 @@ +package nl.astron.lofar.odtb.mom2otdbadapter; + +import nl.astron.lofar.odtb.mom2otdbadapter.mom2listener.Server; +import nl.astron.lofar.odtb.mom2otdbadapter.otdblistener.OTDBListener; +import nl.astron.lofar.odtb.mom2otdbadapter.otdblistener.OTDBQueueProcessor; +import nl.astron.lofar.odtb.mom2otdbadapter.otdblistener.Queue; + + +public class MomOtdbAdapter { + + /** + * @param args + */ + public static void main(String[] args) { +/* Queue queue = new Queue(); + OTDBQueueProcessor otdbQueueProcessor = new OTDBQueueProcessor(queue); + otdbQueueProcessor.start(); + OTDBListener otdbListener = new OTDBListener(queue,5000); + otdbListener.start();*/ + + Server server = new Server(); + server.start(); + } + +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/data/LofarObservation.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/data/LofarObservation.java new file mode 100644 index 0000000000000000000000000000000000000000..d4085b25bece8d70274441dab67a3b79f75d1cfc --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/data/LofarObservation.java @@ -0,0 +1,167 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.data; + +import java.io.Serializable; + + +public class LofarObservation implements Serializable{ + /* + * for both input and output + */ + protected String mom2Id = null; + protected String status = null; + protected String measurementMom2Ids = null; + protected String angleTimes = null; + /* + * only for input + */ + protected String subbands = null; + protected String backend = null; + protected String arrayConfiguration = null; + protected String stations = null; + protected String srgConfiguration = null; + protected Integer samplingFrequency = null; + protected String bandSelection = null; + protected String angle1 = null; + protected String angle2 = null; + + protected String directionType = null; + protected int requestedDuration = 0; + + /* + * only for output + */ + protected String startTime = null; + protected String endTime = null; + + + public String getMom2Id() { + return mom2Id; + } + public void setMom2Id(String mom2Id) { + this.mom2Id = mom2Id; + } + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + + public String getSubbands() { + return subbands; + } + + public void setSubbands(String subbands) { + this.subbands = subbands; + } + + public String getArrayConfiguration() { + return arrayConfiguration; + } + + public void setArrayConfiguration(String arrayConfgiuration) { + this.arrayConfiguration = arrayConfgiuration; + } + + public String getBackend() { + return backend; + } + + public void setBackend(String backend) { + this.backend = backend; + } + + public String getBandSelection() { + return bandSelection; + } + + public void setBandSelection(String bandSelection) { + this.bandSelection = bandSelection; + } + + + + + + + public Integer getSamplingFrequency() { + return samplingFrequency; + } + + public void setSamplingFrequency(Integer samplingFrequency) { + this.samplingFrequency = samplingFrequency; + } + + public String getSrgConfiguration() { + return srgConfiguration; + } + + public void setSrgConfiguration(String srgConfiguration) { + this.srgConfiguration = srgConfiguration; + } + + public String getAngleTimes() { + return angleTimes; + } + + public void setAngleTimes(String angeTimes) { + this.angleTimes = angeTimes; + } + + public String getAngle1() { + return angle1; + } + + public void setAngle1(String angle1) { + this.angle1 = angle1; + } + + public String getAngle2() { + return angle2; + } + + public void setAngle2(String angle2) { + this.angle2 = angle2; + } + + public String getDirectionType() { + return directionType; + } + + public void setDirectionType(String directionType) { + this.directionType = directionType; + } + + public String getStations() { + return stations; + } + + public void setStations(String stations) { + this.stations = stations; + } + public int getRequestedDuration() { + return requestedDuration; + } + public void setRequestedDuration(int requestedDuration) { + this.requestedDuration = requestedDuration; + } + public String getEndTime() { + return endTime; + } + public void setEndTime(String endTime) { + this.endTime = endTime; + } + public String getMeasurementMom2Ids() { + return measurementMom2Ids; + } + public void setMeasurementMom2Ids(String measurementMom2Ids) { + this.measurementMom2Ids = measurementMom2Ids; + } + public String getStartTime() { + return startTime; + } + public void setStartTime(String startTime) { + this.startTime = startTime; + } + +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/data/OTDBRepository.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/data/OTDBRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..25f7bb9eba96fc700b31cb99fa9fe240da4c26bb --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/data/OTDBRepository.java @@ -0,0 +1,22 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.data; + + + +public class OTDBRepository { + + public void story(LofarObservation lofarObservation){ + + } + + public LofarObservation getLatestChanges(String date){ + LofarObservation observation = new LofarObservation(); + observation.setMom2Id("15"); + observation.setAngleTimes("[+0,+30,+60]"); + observation.setStatus("specified"); + observation.setMeasurementMom2Ids("[16,17,18]"); + observation.setStartTime("16-12-2005 12:00:00"); + observation.setEndTime("16-12-2005 13:00:00"); + return observation; + } + +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/Mom2OtdbConverter.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/Mom2OtdbConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..270eff924b567a6c1fdaa50ef2e5b20374b7ee8c --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/Mom2OtdbConverter.java @@ -0,0 +1,178 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.mom2listener; + +import nl.astron.wsrt.util.WsrtConverter; +import nl.astron.wsrt.util.WsrtValidator; + +public class Mom2OtdbConverter { + private static final double MAX_BANDWIDTH = 32000000; + private static final int TOTAL_SUBBANDS = 512; + public static String getOTDBSubbands(Integer samplingFrequency, Integer numberOfBands, + String subbandPlacement, Integer startFrequency, Integer spacing) { + if (samplingFrequency == null + || numberOfBands == null + || WsrtValidator.isBlankOrNull(subbandPlacement) + || startFrequency == null + || spacing == null){ + return null; + } + String subbandPlacementLowerCase = subbandPlacement.toLowerCase(); + /* + * if subband placement is special, no calculation can be made + */ + if (subbandPlacementLowerCase.equals("special")){ + return null; + } + /* + * if contiguous or scattered, calculate subbands + */ + else if(subbandPlacementLowerCase.equals("contiguous") || + subbandPlacementLowerCase.equals("scattered")){ + double samplingFreq = samplingFrequency.doubleValue(); + double startFreq = startFrequency.doubleValue(); + int nBands = numberOfBands.intValue(); + int spac = 0; + if (subbandPlacementLowerCase.equals("scattered")){ + spac = spacing.intValue(); + } + /* + * calculate subband width + */ + double subbandWidth = samplingFreq /(2*TOTAL_SUBBANDS); + /* + * calculate firstband + */ + double firstBand = startFreq/subbandWidth; + firstBand = Math.floor(firstBand); + + /* + * calculate max number of bands + */ + double maxBands = MAX_BANDWIDTH/subbandWidth; + maxBands = Math.floor(maxBands); + /* + * check if bands exceeds max number of bands + */ + if (nBands > maxBands){ + nBands = (int) maxBands; + } + int currentSubband = (int) firstBand; + String result ="[" ; + for (int i = 0; i < nBands && currentSubband < TOTAL_SUBBANDS;i++){ + result+=currentSubband; + if (i < nBands-1 && currentSubband < TOTAL_SUBBANDS-(1 + spac)){ + result += ","; + } + currentSubband = currentSubband + spac + 1; + } + result += "]"; + return result; + + + } + return null; + } + public static String getOTDBBandSelection(String filter){ + + /* + * check if filter is not null + */ + + if (!WsrtValidator.isBlankOrNull(filter)) { + /* + * filter looks like 10-70 (160 MHz sampling rate) split it into: + * '10-70 ' '160 MHz sampling rate)' + */ + String[] splitted = filter.split("\\("); + /* + * get '10-70' + */ + String band = splitted[0].trim(); + /* + * split it into + * '10' '70' + */ + String[] frequencies = band.split("[- ]"); + /* + * get '10' + */ + String startFrequency = frequencies[0]; + String endFrequency = frequencies[1]; + int startFreq = 0; + int endFreq = 0; + if (WsrtValidator.isPositiveInt(startFrequency)){ + + startFreq = WsrtConverter.toInt(WsrtConverter.toInteger(startFrequency)); + } + if (WsrtValidator.isPositiveInt(endFrequency)){ + + endFreq = WsrtConverter.toInt(WsrtConverter.toInteger(endFrequency)); + } + if (startFreq >= 10 && endFreq <= 90){ + return "LB_10_90"; + }else if (startFreq >= 110 && endFreq <= 190){ + return "HB_110_190"; + }else if (startFreq >= 210 && endFreq <= 250){ + return "HB_210_250"; + }else if (startFreq >= 170 && endFreq <= 230){ + return "HB_170_230"; + } + + + } + return null; + } + + public static Integer getOTDBSamplingFrequency(String filter) { + /* + * check if filter is not null + */ + + if (!WsrtValidator.isBlankOrNull(filter)) { + /* + * filter looks like 10-70 (160 MHz sampling rate) split it into: + * '10-70 ' '160 MHz sampling rate)' + */ + String[] splitted = filter.split("\\("); + /* + * get '160 MHz sampling rate)' + */ + String samplingRate = splitted[1].trim(); + /* + * split it by ' ' result is '160' 'MHz' 'sampling' 'rate)' + */ + splitted = samplingRate.split(" "); + /* + * get '160' + */ + String samplingFrequency = splitted[0]; + /* + * if it is a positive int + */ + if (WsrtValidator.isPositiveInt(samplingFrequency)) { + /* + * convert it to an integer + */ + int number = WsrtConverter.toInteger(samplingFrequency) + .intValue(); + /* + * convert it from MHz to Hz + */ + return new Integer(number * 1000000); + } + } + return null; + } + public static Integer getOTDBFrequency(String frequency){ + Double freq = WsrtConverter.toDouble(frequency); + return new Integer((int)freq.doubleValue()*1000000); + } + public static String getOTDBStatus(String status){ + if (status.equals("described")){ + return "being specified"; + }else if (status.equals("specified")){ + return "approved"; + } + return null; + } + +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/ProcessConnection.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/ProcessConnection.java new file mode 100644 index 0000000000000000000000000000000000000000..d2cbf8df3b365f4e8c23bca911a34a950e86cf00 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/ProcessConnection.java @@ -0,0 +1,84 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.mom2listener; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.StringReader; +import java.net.Socket; + + +import nl.astron.lofar.odtb.mom2otdbadapter.data.LofarObservation; +import nl.astron.lofar.odtb.mom2otdbadapter.data.OTDBRepository; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.xerces.parsers.DOMParser; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + + + +public class ProcessConnection extends Thread { + private Log log = LogFactory.getLog(this.getClass()); + private Socket client; + + // Constructor + ProcessConnection(Socket client) { + this.client = client; + + } + + public void run() { + log.info("Process client connection"); + String line = null; + BufferedReader in = null; + PrintWriter out = null; + try { + in = new BufferedReader(new InputStreamReader(client + .getInputStream())); + out = new PrintWriter(client.getOutputStream(), true); + StringBuffer stringBuffer = new StringBuffer(); + while ((line = in.readLine()) != null) { + + log.info(line); + stringBuffer.append(line); + + + } + out.write(processInput(stringBuffer.toString())); + in.close(); + out.close(); + client.close(); + } catch (IOException e) { + log.error("Read failed"); + } + } + protected String processInput(String input){ + try { + Document document = convertStringToDocument(input); + XMLParser xmlParser = new XMLParser(); + LofarObservation lofarObservation = xmlParser.getLofarObservation(document); + OTDBRepository repository = new OTDBRepository(); + repository.story(lofarObservation); + return "succeed"; + }catch (Exception e){ + log.error("Exception throwed: " + e.getMessage(), e); + } + return "failed"; + } + + protected Document convertStringToDocument(String myXML) throws Exception { + // read an xml string into a domtree + Document document; + DOMParser itsParser = new DOMParser(); + + StringReader reader = new StringReader(myXML); + InputSource source = new InputSource(reader); + itsParser.parse(source); + + // get document + document = itsParser.getDocument(); + return document; + } +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/Server.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/Server.java new file mode 100644 index 0000000000000000000000000000000000000000..8b22b8851b348350728f17c4d8959a63509f7cc9 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/Server.java @@ -0,0 +1,32 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.mom2listener; + +import java.io.IOException; +import java.net.ServerSocket; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class Server { + private Log log = LogFactory.getLog(this.getClass()); + + public void start() { + ServerSocket server = null; + try { + log.info("Starting server on port 4444"); + server = new ServerSocket(4444); + } catch (IOException e) { + log.fatal("Could not listen on port 4444", e); + } + while (true) { + ProcessConnection w; + try { + // server.accept returns a client connection + w = new ProcessConnection(server.accept()); + w.start(); + } catch (IOException e) { + log.error("Accept failed: 4444", e); + } + } + } + +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/XMLParser.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/XMLParser.java new file mode 100644 index 0000000000000000000000000000000000000000..8b3540684d29c4b17e6e6f85d621896d9c39159b --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/mom2listener/XMLParser.java @@ -0,0 +1,378 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.mom2listener; + +import nl.astron.lofar.odtb.mom2otdbadapter.data.LofarObservation; +import nl.astron.wsrt.util.WsrtConverter; +import nl.astron.wsrt.util.WsrtValidator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +public class XMLParser { + private Log log = LogFactory.getLog(this.getClass()); + + private static final String PREFIX = "lofar"; + + private static final String MOM2_ID = "mom2Id"; + + private static final String OBSERVATION = "observation"; + + private static final String CURRENT_STATUS = "currentStatus"; + + private static final String DESCRIBED_STATUS = "describedStatus"; + + private static final String SPECIFIED_STATUS = "specifiedStatus"; + + private static final String OBSERVATION_ATTRIBUTES = "observationAttributes"; + + private static final String ARRAY_CONFIGURATION = "arrayConfiguration"; + + private static final String DEFAULT_ARRAY_CONFIGURATION = "default"; + + private static final String DETAILED_ARRAY_CONFIGURATION = "detailed"; + + private static final String STATION = "station"; + + private static final String SRG_CONFIGURATION = "srgConfiguration"; + + private static final String BAND_FILTER = "bandFilter"; + + private static final String SUBBAND_PLACEMENT = "subbandPlacement"; + + private static final String NUMBER_OF_BANDS = "numberOfBands"; + + private static final String START_FREQUENCY = "startFrequency"; + + private static final String SPACING = "spacing"; + + private static final String BACKEND = "backend"; + + private static final String CHILDREN = "children"; + + private static final String ITEM = "item"; + + private static final String MEASUREMENT = "measurement"; + + private static final String MEASUREMENT_ATTRIBUTES = "measurementAttributes"; + + private static final String RA = "ra"; + + private static final String DEC = "dec"; + + private static final String DIRECTION_TYPE = "coordinateRef"; + + private static final String REQUESTED_DURATION = "requestedDuration"; + + public LofarObservation getLofarObservation(Document document) { + LofarObservation lofarObservation = new LofarObservation(); + + /* + * search for project + */ + Node element = document.getDocumentElement(); + if (equal(element, withPrefix(OBSERVATION))) { + lofarObservation.setMom2Id(getAttribute(element.getAttributes(), + MOM2_ID)); + for (int i = 0; i < element.getChildNodes().getLength(); i++) { + Node nodeChild = element.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equal(nodeChild, CURRENT_STATUS)) { + parseCurrentStatus(nodeChild, lofarObservation); + } else if (equal(nodeChild, + withPrefix(OBSERVATION_ATTRIBUTES))) { + parseObservationAttributes(nodeChild, lofarObservation); + } else if (equal(nodeChild, CHILDREN)) { + parseChildren(nodeChild, lofarObservation); + } + } + } + if (lofarObservation.getAngle1() != null) { + lofarObservation.setAngle1(lofarObservation.getAngle1() + "]"); + } + if (lofarObservation.getAngle2() != null) { + lofarObservation.setAngle2(lofarObservation.getAngle2() + "]"); + } + if (lofarObservation.getAngleTimes() != null) { + lofarObservation.setAngleTimes(lofarObservation.getAngleTimes() + + "]"); + } + } + return lofarObservation; + } + + protected void parseObservationAttributes(Node node, + LofarObservation lofarObservation) { + String filter = null; + String subbandPlacement = null; + Integer numberOfBands = null; + Integer startFrequency = null; + Integer spacing = null; + + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node nodeChild = node.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equal(nodeChild, ARRAY_CONFIGURATION)) { + parseArrayConfiguration(nodeChild,lofarObservation); + } else if (equal(nodeChild, SRG_CONFIGURATION)) { + lofarObservation.setSrgConfiguration(getValue(nodeChild)); + } else if (equal(nodeChild, BAND_FILTER)) { + filter = getValue(nodeChild); + } else if (equal(nodeChild, SUBBAND_PLACEMENT)) { + subbandPlacement = getValue(nodeChild); + } else if (equal(nodeChild, NUMBER_OF_BANDS)) { + numberOfBands = WsrtConverter + .toInteger(getValue(nodeChild)); + } else if (equal(nodeChild, START_FREQUENCY)) { + startFrequency = Mom2OtdbConverter + .getOTDBFrequency(getValue(nodeChild)); + } else if (equal(nodeChild, SPACING)) { + spacing = WsrtConverter.toInteger(getValue(nodeChild)); + } else if (equal(nodeChild, BACKEND)) { + lofarObservation.setBackend(getValue(nodeChild)); + } + } + } + lofarObservation.setBandSelection(Mom2OtdbConverter + .getOTDBBandSelection(filter)); + lofarObservation.setSamplingFrequency(Mom2OtdbConverter + .getOTDBSamplingFrequency(filter)); + lofarObservation.setSubbands(Mom2OtdbConverter.getOTDBSubbands( + lofarObservation.getSamplingFrequency(), numberOfBands, + subbandPlacement, startFrequency, spacing)); + } + + protected void parseArrayConfiguration(Node node, + LofarObservation lofarObservation) { + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node nodeChild = node.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equal(nodeChild, DEFAULT_ARRAY_CONFIGURATION)) { + lofarObservation + .setArrayConfiguration(DEFAULT_ARRAY_CONFIGURATION); + lofarObservation.setStations(getValue(nodeChild)); + } else if (equal(nodeChild, DETAILED_ARRAY_CONFIGURATION)) { + lofarObservation + .setArrayConfiguration(DETAILED_ARRAY_CONFIGURATION); + parseStations(nodeChild, lofarObservation); + } + } + } + } + + protected void parseStations(Node node, LofarObservation lofarObservation) { + String stations = null; + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node nodeChild = node.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equal(nodeChild, STATION)) { + if (stations == null) { + stations = "[" + getValue(nodeChild); + } else { + stations = stations + "," + getValue(nodeChild); + } + } + } + } + if (stations != null) { + stations += "]"; + lofarObservation.setStations(stations); + } + + } + + protected void parseCurrentStatus(Node node, + LofarObservation lofarObservation) { + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node nodeChild = node.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equalIgnorePrefix(nodeChild, DESCRIBED_STATUS)) { + lofarObservation.setStatus(formatStatus(DESCRIBED_STATUS)); + } else if (equalIgnorePrefix(nodeChild, SPECIFIED_STATUS)) { + lofarObservation.setStatus(formatStatus(SPECIFIED_STATUS)); + } + } + } + } + + protected void parseChildren(Node node, LofarObservation lofarObservation) { + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node nodeChild = node.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equalIgnorePrefix(nodeChild, ITEM)) { + parseItem(nodeChild, lofarObservation); + } + } + } + } + + protected void parseItem(Node node, LofarObservation lofarObservation) { + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node nodeChild = node.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equalIgnorePrefix(nodeChild, MEASUREMENT)) { + parseMeasurement(nodeChild, lofarObservation); + } + } + } + } + + protected void parseMeasurement(Node node, LofarObservation lofarObservation) { + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node nodeChild = node.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equalIgnorePrefix(nodeChild, + MEASUREMENT_ATTRIBUTES)) { + parseMeasurementAttributes(nodeChild, lofarObservation); + } + } + } + } + + protected void parseMeasurementAttributes(Node node, + LofarObservation lofarObservation) { + for (int i = 0; i < node.getChildNodes().getLength(); i++) { + Node nodeChild = node.getChildNodes().item(i); + /* + * if child is an element + */ + if (WsrtValidator.implementsInterface(Element.class, nodeChild + .getClass())) { + + if (equalIgnorePrefix(nodeChild, RA)) { + if (lofarObservation.getAngle1() == null) { + lofarObservation.setAngle1("[" + getValue(nodeChild)); + } else { + lofarObservation.setAngle1(lofarObservation.getAngle1() + "," + getValue(nodeChild)); + } + } else if (equalIgnorePrefix(nodeChild, DEC)) { + if (lofarObservation.getAngle2() == null) { + lofarObservation.setAngle2("[" + getValue(nodeChild)); + } else { + lofarObservation.setAngle2(lofarObservation.getAngle2()+ "," + getValue(nodeChild)); + } + } else if (equalIgnorePrefix(nodeChild, DIRECTION_TYPE)) { + if (lofarObservation.getDirectionType() == null) { + lofarObservation.setDirectionType(getValue(nodeChild)); + } + } else if (equalIgnorePrefix(nodeChild, REQUESTED_DURATION)) { + + if (lofarObservation.getAngleTimes() == null) { + lofarObservation.setAngleTimes("[+" + + lofarObservation.getRequestedDuration()); + } else { + lofarObservation.setAngleTimes(lofarObservation.getAngleTimes() + ",+" + + lofarObservation.getRequestedDuration()); + } + Integer seconds = getSeconds(getValue(nodeChild)); + lofarObservation.setRequestedDuration(lofarObservation + .getRequestedDuration() + + seconds.intValue()); + } + } + } + } + + protected String getAttribute(NamedNodeMap map, String name) { + Node node = map.getNamedItem(name); + return node.getNodeValue(); + } + + protected String withPrefix(String string) { + + return PREFIX + ":" + string; + } + + /** + * The getValue method returns the value of an node + * + * @param node + * @return + */ + protected String getValue(Node node) { + String value = null; + if (node.getFirstChild() != null) { + value = node.getFirstChild().getNodeValue(); + if (log.isDebugEnabled()) { + log.debug("Node: " + node.getNodeName() + " value: " + value); + } + } + return value; + } + + protected Integer getSeconds(String string) { + String[] splitted = string.split("T"); + splitted = splitted[splitted.length - 1].split("H"); + splitted = splitted[splitted.length - 1].split("M"); + String seconds = splitted[splitted.length - 1]; + if (seconds.endsWith("S")) { + seconds = seconds.substring(0, seconds.length() - 1); + int sec = WsrtConverter.toDouble(seconds).intValue(); + return new Integer(sec); + } + return null; + } + + /** + * The equal method compares if an node has the given name + * + * @param node + * @param nodeName + * @return + */ + protected boolean equal(Node node, String nodeName) { + return node.getNodeName().equals(nodeName); + } + + protected boolean equalIgnorePrefix(Node node, String nodeName) { + String[] nodeSplit = node.getNodeName().split(":"); + String withoutPrefix = nodeSplit[nodeSplit.length - 1]; + return withoutPrefix.equals(nodeName); + } + + protected String formatStatus(String status) { + return status.replaceAll("Status", ""); + } +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/OTDBListener.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/OTDBListener.java new file mode 100644 index 0000000000000000000000000000000000000000..737024789af1e0fcc3a430623ca181fafd841b97 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/OTDBListener.java @@ -0,0 +1,34 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.otdblistener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class OTDBListener extends Thread { + private Log log = LogFactory.getLog(this.getClass()); + + private int seconds = 100; + + private Queue queue = null; + + /* + * seconds to wait + */ + public OTDBListener(Queue queue, int seconds) { + this.seconds = seconds; + this.queue = queue; + } + + public void run() { + while (true) { + try { + log.debug("Add new task"); + Task task = new Task(); + task.setXml("Test xml"); + queue.add(task); + log.debug("Going to sleep"); + Thread.sleep(seconds); + } catch (InterruptedException e) { + } + } + } +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/OTDBQueueProcessor.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/OTDBQueueProcessor.java new file mode 100644 index 0000000000000000000000000000000000000000..0f8e5b4bc9ce83f7907ceaaa3edea6025f2c7d34 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/OTDBQueueProcessor.java @@ -0,0 +1,76 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.otdblistener; + +import java.io.IOException; + +import nl.astron.util.http.AstronHttpClient; +import nl.astron.util.http.exception.AstronHttpException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class OTDBQueueProcessor extends Thread { + private static final int SLEEP_MILLISECONDS = 5000; + + private Log log = LogFactory.getLog(this.getClass()); + + private AstronHttpClient httpClient = null; + + private Queue queue = null; + + /* + * seconds to wait + */ + public OTDBQueueProcessor(Queue queue) { + this.queue = queue; + } + + public void run() { + try { + httpClient = new AstronHttpClient("http", "localhost", 8080, + "/wsrtauth"); + httpClient.login("bastiaan", "bastiaan"); + while (true) { + Task task = queue.get(); + log.debug("Process task: " + task.getXml()); + processTask(task); + + } + } catch (AstronHttpException ahe) { + log.error("AstronHttpException:" + ahe.getMessage(), ahe); + + } + + } + + protected void processTask(Task task) { + boolean succeed = false; + while (!succeed) { + try { + + String result = httpClient.getResponseAsString("http", 8080, + "/mom2", + "/interface/importXML.do?command=IMPORTXML&xmlcontent=" + + "test"); + //ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(result); + //String string = new String(result); + log.info(result); + + succeed = true; + } catch (AstronHttpException ahe) { + log.error("AstronHttpException:" + ahe.getMessage(), ahe); + sleep(); + } catch (IOException ahe) { + log.error("IOException:" + ahe.getMessage(), ahe); + sleep(); + } + } + } + + protected void sleep() { + try { + log.debug("Wait some seconds"); + Thread.sleep(SLEEP_MILLISECONDS); + } catch (InterruptedException e) { + } + } +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/Queue.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/Queue.java new file mode 100644 index 0000000000000000000000000000000000000000..291278cfee6717f57ca9d1ab3c4c3e18b6dd6ca3 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/Queue.java @@ -0,0 +1,34 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.otdblistener; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class Queue { + private Log log = LogFactory.getLog(this.getClass()); + private List tasks = new ArrayList(); + + public synchronized Task get() { + while (tasks.size()==0) { + log.info("Waiting for tasks...."); + try { + wait(); + } catch (InterruptedException e) { + } + } + + Task task = (Task) tasks.get(0); + tasks.remove(0); + log.info("Processing task...., one task removed. Number of tasks:" + tasks.size()); + notifyAll(); + return task; + } + + public synchronized void add(Task task) { + tasks.add(task); + log.info("Task added. Number of tasks:" + tasks.size()); + notifyAll(); + } +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/Task.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/Task.java new file mode 100644 index 0000000000000000000000000000000000000000..78553c8e85bb9975ad9983feabf23e0edaa0580f --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/Task.java @@ -0,0 +1,13 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.otdblistener; + +public class Task { + protected String xml = null; + + public String getXml() { + return xml; + } + + public void setXml(String xml) { + this.xml = xml; + } +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/XMLGenerator.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/XMLGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..75decc1ae50c265250a03fed5d5ed65aac5fa81f --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/otdblistener/XMLGenerator.java @@ -0,0 +1,27 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.otdblistener; + +import javax.xml.parsers.ParserConfigurationException; + +import nl.astron.lofar.odtb.mom2otdbadapter.data.LofarObservation; +import nl.astron.wsrt.util.XMLBuilder; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class XMLGenerator { + public static final String MOM2_LOFAR_NAMESPACE = "http://www.astron.nl/MoM2-Lofar"; + + private XMLBuilder xmlBuilder = null; + + public Document getObservationXml(LofarObservation observation) throws ParserConfigurationException{ + xmlBuilder = new XMLBuilder(); + xmlBuilder.addNamespace("lofar", MOM2_LOFAR_NAMESPACE, + "http://proposal.astron.nl/schemas/LofarProposal.xsd"); + Element element = xmlBuilder.addRootElement(MOM2_LOFAR_NAMESPACE, + "observation"); + xmlBuilder.addAttributeToElement(element,"mom2Id",observation.getMom2Id().toString()); + return xmlBuilder.getDocument(); + + + } +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/AllTests.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/AllTests.java new file mode 100644 index 0000000000000000000000000000000000000000..3368a7d29dd3c4902715da116fd091ac684c00f8 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/AllTests.java @@ -0,0 +1,17 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.test; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for nl.astron.lofar.odtb.mom2otdbadapter.test"); + //$JUnit-BEGIN$ + suite.addTestSuite(TestMom2OtdbConverter.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/TestClient.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/TestClient.java new file mode 100644 index 0000000000000000000000000000000000000000..a0af00c961ad679b9bcc0530c689e02eeac97ba6 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/TestClient.java @@ -0,0 +1,42 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.Socket; +import java.net.UnknownHostException; + +public class TestClient { + public void listenSocket(){ +// Create socket connection + try{ + Socket socket = new Socket("localhost", 4444); + File file = new File("r:\\observation.xml"); + FileInputStream input = new FileInputStream(file); + int byteInt = -1; + while ((byteInt = input.read()) != -1){ + socket.getOutputStream().write(byteInt); + + } + socket.getOutputStream().flush(); + socket.getOutputStream().close(); + socket.close(); + } catch (UnknownHostException e) { + System.out.println("Unknown host: localhost"); + System.exit(1); + } catch (IOException e) { + System.out.println("No I/O"); + System.exit(1); + } + } + /** + * @param args + */ + public static void main(String[] args) { + TestClient testClient = new TestClient(); + testClient.listenSocket(); + // TODO Auto-generated method stub + + } + +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/TestMom2OtdbConverter.java b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/TestMom2OtdbConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..d35ebb017b25417a8ad5863b0967a7545a1d273d --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/TestMom2OtdbConverter.java @@ -0,0 +1,108 @@ +package nl.astron.lofar.odtb.mom2otdbadapter.test; + +import junit.framework.TestCase; +import nl.astron.lofar.odtb.mom2otdbadapter.mom2listener.Mom2OtdbConverter; + +public class TestMom2OtdbConverter extends TestCase { + + public TestMom2OtdbConverter(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /* + * Test method for + * 'nl.astron.lofar.odtb.mom2otdbadapter.mom2listener.Mom2OtdbConverter.getOTDBSubbands(String, + * String, String, String, String)' + */ + public void testGetOTDBContiguousSubbands() { + String subbands = Mom2OtdbConverter.getOTDBSubbands(new Integer( + 160000000), new Integer(50), "Contiguous", + new Integer(79000000), new Integer(0)); + assertEquals("[505,506,507,508,509,510,511]", subbands); + } + + public void testGetOTDBScatteredSubbands() { + String subbands = Mom2OtdbConverter.getOTDBSubbands(new Integer( + 160000000), new Integer(50), "Scattered", + new Integer(79000000), new Integer(1)); + assertEquals("[505,507,509,511]", subbands); + } + + public void testGetOTDBMaxSubbands() { + String subbands = Mom2OtdbConverter.getOTDBSubbands(new Integer( + 160000000), new Integer(500), "Scattered", + new Integer(1000000), new Integer(1)); + assertEquals("[6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38," + + "40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72," + + "74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104," + + "106,108,110,112,114,116,118,120,122,124,126,128,130," + + "132,134,136,138,140,142,144,146,148,150,152,154,156," + + "158,160,162,164,166,168,170,172,174,176,178,180,182," + + "184,186,188,190,192,194,196,198,200,202,204,206,208," + + "210,212,214,216,218,220,222,224,226,228,230,232,234," + + "236,238,240,242,244,246,248,250,252,254,256,258,260," + + "262,264,266,268,270,272,274,276,278,280,282,284,286," + + "288,290,292,294,296,298,300,302,304,306,308,310,312," + + "314,316,318,320,322,324,326,328,330,332,334,336,338," + + "340,342,344,346,348,350,352,354,356,358,360,362,364," + + "366,368,370,372,374,376,378,380,382,384,386,388,390," + + "392,394,396,398,400,402,404,406,408,410,412]", subbands); + } + + /* + * Test method for + * 'nl.astron.lofar.odtb.mom2otdbadapter.mom2listener.Mom2OtdbConverter.getOTDBBandSelection(String)' + */ + public void testGetOTDBBandSelection() { + String bandSelection = Mom2OtdbConverter + .getOTDBBandSelection("10-70 MHz (160 MHz samplingrate)"); + assertEquals("LB_10_90", bandSelection); + bandSelection = Mom2OtdbConverter + .getOTDBBandSelection("10-80 MHz (200 MHz samplingrate)"); + assertEquals("LB_10_90", bandSelection); + bandSelection = Mom2OtdbConverter + .getOTDBBandSelection("110-130 MHz (160 MHz samplingrate)"); + assertEquals("HB_110_190", bandSelection); + bandSelection = Mom2OtdbConverter + .getOTDBBandSelection("110-190 MHz (200 MHz samplingrate)"); + assertEquals("HB_110_190", bandSelection); + bandSelection = Mom2OtdbConverter + .getOTDBBandSelection("170-230 MHz (160 MHz samplingrate)"); + assertEquals("HB_170_230", bandSelection); + bandSelection = Mom2OtdbConverter + .getOTDBBandSelection("210-230 MHz (160 MHz samplingrate)"); + assertEquals("HB_210_250", bandSelection); + bandSelection = Mom2OtdbConverter + .getOTDBBandSelection("210-250 MHz (200 MHz samplingrate)"); + assertEquals("HB_210_250", bandSelection); + } + + public void testGetOTDBSamplingFrequency() { + Integer lowBand = Mom2OtdbConverter + .getOTDBSamplingFrequency("10-80 (200 MHz sampling rate)"); + assertEquals(new Integer(200000000), lowBand); + lowBand = Mom2OtdbConverter + .getOTDBSamplingFrequency("10-70 (160 MHz sampling rate)"); + assertEquals(new Integer(160000000), lowBand); + } + + public void testGetOTDBFrequency() { + Integer frequency = Mom2OtdbConverter.getOTDBFrequency("10.0"); + assertEquals(new Integer(10000000), frequency); + } + + public void testGetOTDBStatus() { + String status = Mom2OtdbConverter.getOTDBStatus("described"); + assertEquals("being specified", status); + status = Mom2OtdbConverter.getOTDBStatus("specified"); + assertEquals("approved", status); + } +} diff --git a/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/project.xml b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..e21396ef730c426b583220d5b5546cfa64aa5134 --- /dev/null +++ b/SAS/OTB/MoM-OTDB-adapter/src/nl/astron/lofar/odtb/mom2otdbadapter/test/project.xml @@ -0,0 +1,255 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lofar:project xmlns:lofar="http://www.astron.nl/MoM2-Lofar" + xmlns:mom2="http://www.astron.nl/MoM2" + xmlns:user="http://www.astron.nl/useradmin" + xmlns:persistent="http://www.astron.nl/PersistentObjects" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.astron.nl/MoM2-Lofar http://wop17.nfra.nl/twiki/pub/Tools/Schemas/LofarMoM2.xsd http://www.astron.nl/MoM2 http://wop17.nfra.nl/twiki/pub/Tools/Schemas/MoM2.xsd http://www.astron.nl/useradmin http://proposal.astron.nl/schemas/UserAdmin.xsd http://www.astron.nl/PersistentObjects http://proposal.astron.nl/schemas/PersistentObjects.xsd " + mom2Id="0" xsi:type="lofar:LofarProjectType" id="0"> + <name>name</name> + <description>description</description> + <currentStatus> + <mom2:openedStatus /> + </currentStatus> + <generalRemarks> + <item> + <mom2:generalRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp>2001-12-31T12:00:00</timeStamp> + </mom2:generalRemark> + </item> + </generalRemarks> + <inspectionReports> + <item> + <mom2:inspectionReport> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp>2001-12-31T12:00:00</timeStamp> + </mom2:inspectionReport> + </item> + </inspectionReports> + <specificationRemarks> + <item> + <mom2:specificationRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp>2001-12-31T12:00:00</timeStamp> + </mom2:specificationRemark> + </item> + </specificationRemarks> + <schedulingRemarks> + <item> + <mom2:schedulingRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp>2001-12-31T12:00:00</timeStamp> + </mom2:schedulingRemark> + </item> + </schedulingRemarks> + <usedDataProducts> + <item> + <lofar:proposalDocument> + <name>name</name> + <uri>uri</uri> + <type>PROPOSAL</type> + <released>false</released> + </lofar:proposalDocument> + </item> + </usedDataProducts> + <children> + <item> + <lofar:collection> + <name>name</name> + <description>description</description> + <currentStatus> + <mom2:openedStatus /> + </currentStatus> + <!-- <children/> --> + </lofar:collection> + </item> + <item> + <lofar:observation> + <name>name</name> + <description>description</description> + <currentStatus> + <mom2:openedStatus /> + </currentStatus> + <generalRemarks> + <item> + <mom2:generalRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp>2001-12-31T12:00:00</timeStamp> + </mom2:generalRemark> + </item> + </generalRemarks> + <inspectionReports> + <item> + <mom2:inspectionReport> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp>2001-12-31T12:00:00</timeStamp> + </mom2:inspectionReport> + </item> + </inspectionReports> + <specificationRemarks> + <item> + <mom2:specificationRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp>2001-12-31T12:00:00</timeStamp> + </mom2:specificationRemark> + </item> + </specificationRemarks> + <schedulingRemarks> + <item> + <mom2:schedulingRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp>2001-12-31T12:00:00</timeStamp> + </mom2:schedulingRemark> + </item> + </schedulingRemarks> + <resultDataProducts> + <item> + <lofar:dataset> + <name>name</name> + <uri>uri</uri> + <type>LOFARDATA</type> + <released>false</released> + </lofar:dataset> + </item> + </resultDataProducts> + <lofar:observationAttributes> + <arrayConfiguration>Central core</arrayConfiguration> + <srgConfiguration>Station</srgConfiguration> + <bandFilter>10-70 MHz (160 MHz samplingrate)</bandFilter> + <subbandPlacement>Scattered</subbandPlacement> + <numberOfBands>10</numberOfBands> + <startFrequency>10.0</startFrequency> + <spacing>0</spacing> + <backend>Demo correlator</backend> + </lofar:observationAttributes> + <children> + <item> + <lofar:measurement> + <name>name</name> + <description>description</description> + <currentStatus> + <mom2:openedStatus /> + </currentStatus> + <generalRemarks> + <item> + <mom2:generalRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp> + 2001-12-31T12:00:00 + </timeStamp> + </mom2:generalRemark> + </item> + </generalRemarks> + <inspectionReports> + <item> + <mom2:inspectionReport> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp> + 2001-12-31T12:00:00 + </timeStamp> + </mom2:inspectionReport> + </item> + </inspectionReports> + <specificationRemarks> + <item> + <mom2:specificationRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp> + 2001-12-31T12:00:00 + </timeStamp> + </mom2:specificationRemark> + </item> + </specificationRemarks> + <schedulingRemarks> + <item> + <mom2:schedulingRemark> + <user id="0" /> + <name>name</name> + <roles>roles</roles> + <text>text</text> + <timeStamp> + 2001-12-31T12:00:00 + </timeStamp> + </mom2:schedulingRemark> + </item> + </schedulingRemarks> + <resultDataProducts> + <item index="0"> + <lofar:dataset> + <name>name</name> + <uri>uri</uri> + <type>LOFARDATA</type> + <released>false</released> + </lofar:dataset> + </item> + </resultDataProducts> + <lofar:measurementAttributes> + <fieldName>fieldName</fieldName> + <ra>0.0</ra> + <dec>0.0</dec> + <coordinateRef>J2000</coordinateRef> + <requestedDuration> + P1D + </requestedDuration> + <startTime> + 2001-12-31T12:00:00 + </startTime> + <endTime>2001-12-31T12:00:00</endTime> + <timeRef>LST</timeRef> + </lofar:measurementAttributes> + </lofar:measurement> + </item> + </children> + </lofar:observation> + </item> + </children> + <proposalId>proposalId</proposalId> + <members> + <item> + <registeredMember> + <roles> + <mom2:pi /> + </roles> + <user id="0" /> + </registeredMember> + </item> + </members> + <lofar:allocation> + <mom2:observingTime>10000</mom2:observingTime> + </lofar:allocation> + <releaseDate>2010-01-01</releaseDate> +</lofar:project>