Skip to content
Snippets Groups Projects
Commit 403c918f authored by tpylak's avatar tpylak
Browse files

LMS-1180 YeastX: use the same date format for eicML/fiaML/quantML files. Fix unit tests.

SVN: 12774
parent c7cf1459
No related branches found
No related tags found
No related merge requests found
Showing
with 37 additions and 23 deletions
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<source>msSoft</source> <source>msSoft</source>
<valid>true</valid> <valid>true</valid>
<comment>no comment</comment> <comment>no comment</comment>
<registrationDate>2009-04-07 12:00:21</registrationDate> <registrationDate>04-Apr-1980 12:00:21</registrationDate>
<registrator>John Doe</registrator> <registrator>John Doe</registrator>
<concentration> <concentration>
<datasetParent>20090822211007858-23605</datasetParent> <datasetParent>20090822211007858-23605</datasetParent>
......
...@@ -33,6 +33,8 @@ public class DBUtils ...@@ -33,6 +33,8 @@ public class DBUtils
/** Current version of the database. */ /** Current version of the database. */
public static final String DATABASE_VERSION = "003"; public static final String DATABASE_VERSION = "003";
public static final String DATE_PATTERN = "dd-MMM-yyyy HH:mm:ss";
static static
{ {
QueryTool.getTypeMap().put(float[].class, new FloatArrayMapper()); QueryTool.getTypeMap().put(float[].class, new FloatArrayMapper());
......
...@@ -33,6 +33,7 @@ import org.xml.sax.helpers.DefaultHandler; ...@@ -33,6 +33,7 @@ import org.xml.sax.helpers.DefaultHandler;
import ch.systemsx.cisd.base.convert.NativeData; import ch.systemsx.cisd.base.convert.NativeData;
import ch.systemsx.cisd.base.convert.NativeData.ByteOrder; import ch.systemsx.cisd.base.convert.NativeData.ByteOrder;
import ch.systemsx.cisd.yeastx.db.DBUtils;
/** /**
* A file for parsing <code>eicML</code> files. * A file for parsing <code>eicML</code> files.
...@@ -56,18 +57,18 @@ public class EICMLParser extends DefaultHandler ...@@ -56,18 +57,18 @@ public class EICMLParser extends DefaultHandler
} }
private static final ThreadLocal<DateFormat> dateFormatHolder = new ThreadLocal<DateFormat>(); private static final ThreadLocal<DateFormat> dateFormatHolder = new ThreadLocal<DateFormat>();
public static DateFormat getDateFormat() public static DateFormat getDateFormat()
{ {
DateFormat dateFormat = dateFormatHolder.get(); DateFormat dateFormat = dateFormatHolder.get();
if (dateFormat == null) if (dateFormat == null)
{ {
dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); dateFormat = new SimpleDateFormat(DBUtils.DATE_PATTERN);
dateFormatHolder.set(dateFormat); dateFormatHolder.set(dateFormat);
} }
return dateFormat; return dateFormat;
} }
private StringBuilder buffer = new StringBuilder(); private StringBuilder buffer = new StringBuilder();
private EICMSRunDTO msRun; private EICMSRunDTO msRun;
......
...@@ -33,6 +33,7 @@ import org.xml.sax.helpers.DefaultHandler; ...@@ -33,6 +33,7 @@ import org.xml.sax.helpers.DefaultHandler;
import ch.systemsx.cisd.base.convert.NativeData; import ch.systemsx.cisd.base.convert.NativeData;
import ch.systemsx.cisd.base.convert.NativeData.ByteOrder; import ch.systemsx.cisd.base.convert.NativeData.ByteOrder;
import ch.systemsx.cisd.yeastx.db.DBUtils;
/** /**
* A file for parsing <code>eicML</code> files. * A file for parsing <code>eicML</code> files.
...@@ -42,7 +43,7 @@ import ch.systemsx.cisd.base.convert.NativeData.ByteOrder; ...@@ -42,7 +43,7 @@ import ch.systemsx.cisd.base.convert.NativeData.ByteOrder;
public class FIAMLParser extends DefaultHandler public class FIAMLParser extends DefaultHandler
{ {
private final static String FIA_RUN = "fiaRun"; private final static String FIA_RUN = "fiaRun";
/** A role that observes {@link FIAMSRunDTO}s. */ /** A role that observes {@link FIAMSRunDTO}s. */
public interface IMSRunObserver public interface IMSRunObserver
{ {
...@@ -56,7 +57,7 @@ public class FIAMLParser extends DefaultHandler ...@@ -56,7 +57,7 @@ public class FIAMLParser extends DefaultHandler
DateFormat dateFormat = dateFormatHolder.get(); DateFormat dateFormat = dateFormatHolder.get();
if (dateFormat == null) if (dateFormat == null)
{ {
dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); dateFormat = new SimpleDateFormat(DBUtils.DATE_PATTERN);
dateFormatHolder.set(dateFormat); dateFormatHolder.set(dateFormat);
} }
return dateFormat; return dateFormat;
...@@ -65,7 +66,7 @@ public class FIAMLParser extends DefaultHandler ...@@ -65,7 +66,7 @@ public class FIAMLParser extends DefaultHandler
private StringBuilder buffer = new StringBuilder(); private StringBuilder buffer = new StringBuilder();
private FIAMSRunDTO msRun; private FIAMSRunDTO msRun;
private FIAMSRunDataDTO fiaRunData; private FIAMSRunDataDTO fiaRunData;
private boolean parsingMsRun; private boolean parsingMsRun;
...@@ -138,13 +139,17 @@ public class FIAMLParser extends DefaultHandler ...@@ -138,13 +139,17 @@ public class FIAMLParser extends DefaultHandler
throw new SAXException("Illegal polarity: must be of length 1"); throw new SAXException("Illegal polarity: must be of length 1");
} }
msRun.setPolarity(value.charAt(0)); msRun.setPolarity(value.charAt(0));
} else if ("lowMz".equals(name)){ } else if ("lowMz".equals(name))
{
msRun.setLowMz(Float.parseFloat(value)); msRun.setLowMz(Float.parseFloat(value));
} else if ("highMz".equals(name)){ } else if ("highMz".equals(name))
{
msRun.setHighMz(Float.parseFloat(value)); msRun.setHighMz(Float.parseFloat(value));
} else if ("is".equals(name)){ } else if ("is".equals(name))
{
msRun.setInternalStandard(Float.parseFloat(value)); msRun.setInternalStandard(Float.parseFloat(value));
} else if ("od".equals(name)){ } else if ("od".equals(name))
{
msRun.setOd(Float.parseFloat(value)); msRun.setOd(Float.parseFloat(value));
} else if ("operator".equals(name)) } else if ("operator".equals(name))
{ {
......
...@@ -82,7 +82,6 @@ class QuantMLParser ...@@ -82,7 +82,6 @@ class QuantMLParser
private MSQuantificationsDTO doParseMSQuantifications(File dataSet) private MSQuantificationsDTO doParseMSQuantifications(File dataSet)
{ {
try try
{ {
Object object = unmarshaller.unmarshal(dataSet); Object object = unmarshaller.unmarshal(dataSet);
......
...@@ -21,12 +21,14 @@ import java.util.Date; ...@@ -21,12 +21,14 @@ import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter; import javax.xml.bind.annotation.adapters.XmlAdapter;
import ch.systemsx.cisd.yeastx.db.DBUtils;
/** /**
* @author Tomasz Pylak * @author Tomasz Pylak
*/ */
public class XmlDateAdapter extends XmlAdapter<String, Date> public class XmlDateAdapter extends XmlAdapter<String, Date>
{ {
static String PATTERN = "yyyy-MM-dd HH:mm:ss"; private static final String PATTERN = DBUtils.DATE_PATTERN;
@Override @Override
public String marshal(Date date) throws Exception public String marshal(Date date) throws Exception
......
...@@ -35,18 +35,23 @@ public abstract class AbstractDBTest ...@@ -35,18 +35,23 @@ public abstract class AbstractDBTest
static static
{ {
LogInitializer.init(); LogInitializer.init();
DBUtils.init(getDatabaseContext());
} }
protected DataSource datasource; protected DataSource datasource;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setUpClass() throws SQLException public void setUpClass() throws SQLException
{
datasource = getDatabaseContext().getDataSource();
}
private static DatabaseConfigurationContext getDatabaseContext()
{ {
final DatabaseConfigurationContext context = DBUtils.createDefaultDBContext(); final DatabaseConfigurationContext context = DBUtils.createDefaultDBContext();
context.setDatabaseKind("dbtest"); context.setDatabaseKind("dbtest");
context.setCreateFromScratch(true); context.setCreateFromScratch(true);
DBUtils.init(context); return context;
datasource = context.getDataSource();
} }
} }
...@@ -53,9 +53,9 @@ public class EICMLTest extends AbstractDBTest ...@@ -53,9 +53,9 @@ public class EICMLTest extends AbstractDBTest
public void testUploadEicML() throws SQLException public void testUploadEicML() throws SQLException
{ {
EICML2Database db = new EICML2Database(datasource); EICML2Database db = new EICML2Database(datasource);
db.uploadEicMLFile(new File("resource/examples/example.eicML"), db.uploadEicMLFile(new File("resource/examples/example.eicML"), new DMDataSetDTO(
new DMDataSetDTO("data set perm id", "sample perm id", "sample name", "data set perm id eicml", "sample perm id eicml", "sample name eicml",
"experiment perm id", "experiment name")); "experiment perm id eicml", "experiment name eicml"));
} }
private void checkChromatograms(int count, ChromatogramDTO chrom) private void checkChromatograms(int count, ChromatogramDTO chrom)
......
...@@ -60,7 +60,7 @@ public class FIAMLTest extends AbstractDBTest ...@@ -60,7 +60,7 @@ public class FIAMLTest extends AbstractDBTest
{ {
FIAML2Database fiaML2Database = new FIAML2Database(datasource); FIAML2Database fiaML2Database = new FIAML2Database(datasource);
fiaML2Database.uploadFiaMLFile(new File("resource/examples/example.fiaML"), fiaML2Database.uploadFiaMLFile(new File("resource/examples/example.fiaML"),
new DMDataSetDTO("data set perm id", "sample perm id", "sample name", new DMDataSetDTO("data set perm id fiaml", "sample perm id", "sample name",
"experiment perm id", "experiment name")); "experiment perm id", "experiment name"));
} }
......
...@@ -72,7 +72,7 @@ public class QuantMLParserTest extends AssertJUnit ...@@ -72,7 +72,7 @@ public class QuantMLParserTest extends AssertJUnit
assertTrue(quantification.isValid()); assertTrue(quantification.isValid());
assertEquals("no comment", quantification.getComment()); assertEquals("no comment", quantification.getComment());
assertEquals("John Doe", quantification.getRegistrator()); assertEquals("John Doe", quantification.getRegistrator());
Date expectedDate = new XmlDateAdapter().unmarshal("2009-04-07 12:00:21"); Date expectedDate = new XmlDateAdapter().unmarshal("04-Apr-1980 12:00:21");
assertEquals(expectedDate, quantification.getRegistrationDate()); assertEquals(expectedDate, quantification.getRegistrationDate());
assertEquals(1, quantification.getConcentrations().size()); assertEquals(1, quantification.getConcentrations().size());
......
...@@ -55,7 +55,7 @@ public class QuantMSDAOTest extends AbstractDBTest ...@@ -55,7 +55,7 @@ public class QuantMSDAOTest extends AbstractDBTest
{ {
QuantML2Database uploader = new QuantML2Database(datasource); QuantML2Database uploader = new QuantML2Database(datasource);
DMDataSetDTO dataSetDTO = DMDataSetDTO dataSetDTO =
new DMDataSetDTO("data set perm id", "sample perm id", "sample name", new DMDataSetDTO("data set perm id quant", "sample perm id quant", "sample name",
"experiment perm id", "experiment name"); "experiment perm id", "experiment name");
uploader.uploadQuantMLFile(new File("resource/examples/allFields.quantML"), dataSetDTO); uploader.uploadQuantMLFile(new File("resource/examples/allFields.quantML"), dataSetDTO);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment