use of ca.nrc.cadc.caom2.Algorithm in project caom2db by opencadc.
the class ObservationValidator method validateChecksum.
private void validateChecksum(Observation o) throws MismatchedChecksumException {
if (o.getAccMetaChecksum() == null) {
// no check
return;
}
try {
URI calculatedChecksum = o.computeAccMetaChecksum(MessageDigest.getInstance("MD5"));
log.debug("validateChecksum: " + o.getURI() + " -- " + o.getAccMetaChecksum() + " vs " + calculatedChecksum);
if (!calculatedChecksum.equals(o.getAccMetaChecksum())) {
throw new MismatchedChecksumException(o.getURI() + " -- caom2 " + o.getAccMetaChecksum() + " vs calculated " + calculatedChecksum);
}
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("MD5 digest algorithm not available");
}
}
use of ca.nrc.cadc.caom2.Algorithm in project bgpcep by opendaylight.
the class SrNodeAttributesParser method parseSrAlgorithms.
public static SrAlgorithm parseSrAlgorithms(final ByteBuf buffer) {
final SrAlgorithmBuilder builder = new SrAlgorithmBuilder();
final var algs = ImmutableSet.<Algorithm>builder();
while (buffer.isReadable()) {
algs.add(Algorithm.forValue(buffer.readUnsignedByte()));
}
builder.setAlgorithms(algs.build());
return builder.build();
}
use of ca.nrc.cadc.caom2.Algorithm 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);
}
}
use of ca.nrc.cadc.caom2.Algorithm 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;
}
use of ca.nrc.cadc.caom2.Algorithm in project caom2db by opencadc.
the class ObservationHarvester method validateChecksum.
private void validateChecksum(Observation o) throws MismatchedChecksumException {
if (o.getAccMetaChecksum() == null) {
// no check
return;
}
try {
URI calculatedChecksum = o.computeAccMetaChecksum(MessageDigest.getInstance("MD5"));
log.debug("validateChecksum: " + o.getURI() + " -- " + o.getAccMetaChecksum() + " vs " + calculatedChecksum);
if (!calculatedChecksum.equals(o.getAccMetaChecksum())) {
throw new MismatchedChecksumException("Observation.accMetaChecksum mismatch");
}
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("MD5 digest algorithm not available");
}
}
Aggregations