Search in sources :

Example 1 with DerivedObservation

use of ca.nrc.cadc.caom2.DerivedObservation in project caom2db by opencadc.

the class AbstractObservationDAOTest method testUpdateDerivedToSimple.

@Test
public void testUpdateDerivedToSimple() {
    try {
        DerivedObservation comp = new DerivedObservation("FOO", "bar", new Algorithm("baz"));
        comp.getMembers().add(new ObservationURI(URI.create("caom:FOO/part")));
        log.debug("put: comp");
        dao.put(comp);
        log.debug("put: comp DONE");
        String sql = "SELECT count(*) from " + dao.gen.getTable(ObservationMember.class) + " WHERE parentID = " + dao.gen.literal(comp.getID());
        JdbcTemplate jdbc = new JdbcTemplate(dao.dataSource);
        if (dao.gen.persistOptimisations) {
            int compMembers = jdbc.queryForObject(sql, new IntRowMapper());
            log.info("composite members: " + compMembers);
            Assert.assertEquals("one compMember", 1, compMembers);
        }
        // this is so we can detect incorrect timestamp round trips
        // caused by assigning something other than what was stored
        Thread.sleep(2 * TIME_TOLERANCE);
        log.debug("get: comp");
        Observation c = dao.get(comp.getURI());
        log.debug("get: comp DONE");
        Assert.assertNotNull("found", c);
        Assert.assertEquals("composite", DerivedObservation.class, c.getClass());
        testEqual(comp, c);
        log.info("verified: " + c);
        Observation simp = new SimpleObservation("FOO", "bar");
        Util.assignID(simp, comp.getID());
        log.debug("put: simp");
        dao.put(simp);
        log.debug("put: simp DONE");
        log.debug("get: simp");
        Observation s = dao.get(simp.getURI());
        log.debug("get: comp DONE");
        Assert.assertNotNull("found", s);
        Assert.assertEquals("simple", simp.getClass(), s.getClass());
        testEqual(simp, s);
        log.info("verified: " + s);
        log.info("update: " + comp.getID() + " == " + simp.getID());
        Assert.assertEquals("single UUID -- put was an update", comp.getID(), simp.getID());
        if (dao.gen.persistOptimisations) {
            int simpMembers = jdbc.queryForObject(sql, new IntRowMapper());
            log.info("simple members: " + simpMembers);
            Assert.assertEquals("no simpMembers", 0, simpMembers);
        }
        dao.delete(simp.getURI());
        Observation deleted = dao.get(simp.getURI());
        Assert.assertNull("deleted", deleted);
    } catch (Exception unexpected) {
        log.error("unexpected exception", unexpected);
        if (txnManager.isOpen())
            try {
                txnManager.rollbackTransaction();
            } catch (Throwable t) {
                log.error("failed to rollback transaction", t);
            }
        Assert.fail("unexpected exception: " + unexpected);
    }
}
Also used : DerivedObservation(ca.nrc.cadc.caom2.DerivedObservation) ObservationURI(ca.nrc.cadc.caom2.ObservationURI) IntRowMapper(ca.nrc.cadc.db.IntRowMapper) SimpleObservation(ca.nrc.cadc.caom2.SimpleObservation) DerivedObservation(ca.nrc.cadc.caom2.DerivedObservation) Observation(ca.nrc.cadc.caom2.Observation) DeletedObservation(ca.nrc.cadc.caom2.DeletedObservation) SimpleObservation(ca.nrc.cadc.caom2.SimpleObservation) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Algorithm(ca.nrc.cadc.caom2.Algorithm) Point(ca.nrc.cadc.caom2.types.Point) SQLException(java.sql.SQLException) PreconditionFailedException(ca.nrc.cadc.net.PreconditionFailedException) Test(org.junit.Test)

Example 2 with DerivedObservation

use of ca.nrc.cadc.caom2.DerivedObservation in project caom2db by opencadc.

the class AbstractObservationDAOTest method getTestObservation.

private Observation getTestObservation(boolean full, int depth, boolean comp, boolean sci) throws Exception {
    Observation o;
    if (comp) {
        DerivedObservation obs = new DerivedObservation("TEST", "SimpleBar", new Algorithm("doit"));
        if (full) {
            obs.getMembers().add(new ObservationURI("TEST", "simple1"));
            obs.getMembers().add(new ObservationURI("TEST", "simple2"));
            obs.getMembers().add(new ObservationURI("TEST", "simple3"));
        }
        o = obs;
    } else
        o = new SimpleObservation("TEST", "SimpleBar");
    if (full) {
        o.metaProducer = URI.create("test:observation/roundrip-1.0");
        if (sci)
            o.intent = ObservationIntentType.SCIENCE;
        else {
            o.intent = ObservationIntentType.CALIBRATION;
            o.type = "flat";
        }
        o.sequenceNumber = new Integer(123);
        o.metaRelease = TEST_DATE;
        o.proposal = new Proposal("MyFirstProposal");
        o.proposal.getKeywords().addAll(TEST_KEYWORDS);
        o.proposal.pi = "little old me";
        o.proposal.title = "My Little Pony";
        o.proposal.project = "Project 51";
        o.target = new Target("Pony 51");
        o.target.targetID = URI.create("naif:1701");
        o.target.type = TargetType.OBJECT;
        o.target.getKeywords().addAll(TEST_KEYWORDS);
        o.target.standard = Boolean.TRUE;
        o.target.redshift = new Double(0.0);
        o.target.moving = Boolean.FALSE;
        o.targetPosition = new TargetPosition("FK5", new Point(1.0, 2.0));
        if (sci)
            o.targetPosition.equinox = 2000.0;
        o.requirements = new Requirements(Status.FAIL);
        o.telescope = new Telescope("BothEyes");
        o.telescope.getKeywords().addAll(TEST_KEYWORDS);
        o.telescope.geoLocationX = 100.0;
        o.telescope.geoLocationY = 200.0;
        o.telescope.geoLocationZ = 300.0;
        o.instrument = new Instrument("test-instrument");
        o.instrument.getKeywords().addAll(TEST_KEYWORDS);
        o.environment = new Environment();
        o.environment.seeing = 0.08;
        o.environment.photometric = Boolean.TRUE;
        o.getMetaReadGroups().add(URI.create("ivo://example.net/gms?GroupA"));
        o.getMetaReadGroups().add(URI.create("ivo://example.net/gms?GroupB"));
    }
    if (depth == 1)
        return o;
    o.getPlanes().add(getTestPlane(full, "thing1", depth, true));
    o.getPlanes().add(getTestPlane(full, "thing2", depth, false));
    Assert.assertEquals(2, o.getPlanes().size());
    return o;
}
Also used : ObservationURI(ca.nrc.cadc.caom2.ObservationURI) Telescope(ca.nrc.cadc.caom2.Telescope) Point(ca.nrc.cadc.caom2.types.Point) Algorithm(ca.nrc.cadc.caom2.Algorithm) TargetPosition(ca.nrc.cadc.caom2.TargetPosition) Requirements(ca.nrc.cadc.caom2.Requirements) DerivedObservation(ca.nrc.cadc.caom2.DerivedObservation) Target(ca.nrc.cadc.caom2.Target) SimpleObservation(ca.nrc.cadc.caom2.SimpleObservation) DerivedObservation(ca.nrc.cadc.caom2.DerivedObservation) Observation(ca.nrc.cadc.caom2.Observation) DeletedObservation(ca.nrc.cadc.caom2.DeletedObservation) SimpleObservation(ca.nrc.cadc.caom2.SimpleObservation) Instrument(ca.nrc.cadc.caom2.Instrument) Environment(ca.nrc.cadc.caom2.Environment) Proposal(ca.nrc.cadc.caom2.Proposal)

Aggregations

Algorithm (ca.nrc.cadc.caom2.Algorithm)2 DeletedObservation (ca.nrc.cadc.caom2.DeletedObservation)2 DerivedObservation (ca.nrc.cadc.caom2.DerivedObservation)2 Observation (ca.nrc.cadc.caom2.Observation)2 ObservationURI (ca.nrc.cadc.caom2.ObservationURI)2 SimpleObservation (ca.nrc.cadc.caom2.SimpleObservation)2 Point (ca.nrc.cadc.caom2.types.Point)2 Environment (ca.nrc.cadc.caom2.Environment)1 Instrument (ca.nrc.cadc.caom2.Instrument)1 Proposal (ca.nrc.cadc.caom2.Proposal)1 Requirements (ca.nrc.cadc.caom2.Requirements)1 Target (ca.nrc.cadc.caom2.Target)1 TargetPosition (ca.nrc.cadc.caom2.TargetPosition)1 Telescope (ca.nrc.cadc.caom2.Telescope)1 IntRowMapper (ca.nrc.cadc.db.IntRowMapper)1 PreconditionFailedException (ca.nrc.cadc.net.PreconditionFailedException)1 SQLException (java.sql.SQLException)1 Test (org.junit.Test)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1