use of ca.nrc.cadc.caom2.ObservationURI in project caom2db by opencadc.
the class ObservationDAO method getStateImpl.
private ObservationState getStateImpl(ObservationURI uri, UUID id) {
checkInit();
if (uri == null && id == null) {
throw new IllegalArgumentException("args cannot be null");
}
log.debug("GET: " + uri + " | " + id);
long t = System.currentTimeMillis();
try {
String sql = null;
if (uri != null) {
sql = gen.getSelectSQL(uri, 1, false);
} else {
sql = gen.getSelectSQL(id, 1, false);
}
log.debug("GET: " + sql);
JdbcTemplate jdbc = new JdbcTemplate(dataSource);
// ObservationSkeleton skel = (ObservationSkeleton) jdbc.query(sql, new ObservationSkeletonExtractor());
Observation obs = (Observation) jdbc.query(sql, gen.getObservationExtractor());
if (obs != null) {
ObservationState ret = new ObservationState(obs.getURI());
ret.id = obs.getID();
ret.accMetaChecksum = obs.getAccMetaChecksum();
ret.maxLastModified = obs.getMaxLastModified();
// ret.maxLastModified = skel.maxLastModified;
return ret;
}
return null;
} finally {
long dt = System.currentTimeMillis() - t;
log.debug("GET: " + uri + " | " + id + " " + dt + "ms");
}
}
use of ca.nrc.cadc.caom2.ObservationURI in project caom2db by opencadc.
the class SQLGeneratorTest method testSelectObservationSQL.
@Test
public void testSelectObservationSQL() {
try {
ObservationURI uri = new ObservationURI("FOO", "NoSuchObservation");
for (int i = 1; i <= 5; i++) {
String sql = gen.getSelectSQL(uri, i, false);
Assert.assertNotNull(sql);
log.debug("SQL [" + sql.length() + "] " + sql);
for (int t = 0; t < i; t++) Assert.assertTrue(tables[t], sql.contains(tables[t]));
for (int t = i; t < 5; t++) Assert.assertFalse(tables[t], sql.contains(tables[t]));
}
} catch (Exception unexpected) {
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
use of ca.nrc.cadc.caom2.ObservationURI in project caom2db by opencadc.
the class ArtifactValidator method getLogicalMetadata.
private TreeSet<ArtifactMetadata> getLogicalMetadata() throws Exception {
TreeSet<ArtifactMetadata> result = new TreeSet<>(ArtifactMetadata.getComparator());
if (StringUtil.hasText(source)) {
// use database <server.database.schema>
// HarvestSkipURI table is not supported in 'diff' mode, i.e. reportOnly = true
this.supportSkipURITable = !reportOnly;
long t1 = System.currentTimeMillis();
List<ObservationState> states = observationDAO.getObservationList(collection, null, null, null);
long t2 = System.currentTimeMillis();
long dt = t2 - t1;
log.info("get-state-list: size=" + states.size() + " in " + dt + " ms");
int depth = 3;
ListIterator<ObservationState> iter = states.listIterator();
t1 = System.currentTimeMillis();
while (iter.hasNext()) {
ObservationState s = iter.next();
// GC
iter.remove();
ObservationResponse resp = observationDAO.getObservationResponse(s, depth);
if (resp == null) {
log.error("Null response from Observation DAO, ObservationURI: " + s.getURI().toString() + ", depth: " + depth);
} else if (resp.observation == null) {
log.error("Observation is null, ObservationURI: " + s.getURI().toString() + ", depth: " + depth);
} else {
for (Plane plane : resp.observation.getPlanes()) {
for (Artifact artifact : plane.getArtifacts()) {
String observationID = s.getURI().getObservationID();
result.add(getMetadata(observationID, artifact, plane.dataRelease, plane.metaRelease));
}
}
}
}
log.info("Finished logical metadata query in " + (System.currentTimeMillis() - t1) + " ms");
} else {
this.supportSkipURITable = false;
if (caomTapResourceID != null) {
// source is a TAP resource ID
AuthMethod authMethod = AuthenticationUtil.getAuthMethodFromCredentials(AuthenticationUtil.getCurrentSubject());
TapClient tapClient = new TapClient(caomTapResourceID);
try {
this.caomTapURL = tapClient.getSyncURL(authMethod);
} catch (ResourceNotFoundException ex) {
if (ex.getMessage().contains("with password")) {
throw new ResourceNotFoundException("TAP service for " + caomTapResourceID + " does not support password authentication.", ex);
}
}
}
// source is a TAP service URL or a TAP resource ID
String adql = "select distinct(a.uri), a.contentChecksum, a.contentLength, a.contentType, o.observationID, " + "a.productType, a.releaseType, p.dataRelease, p.metaRelease " + "from caom2.Artifact a " + "join caom2.Plane p on a.planeID = p.planeID " + "join caom2.Observation o on p.obsID = o.obsID " + "where o.collection='" + collection + "'";
log.debug("logical query: " + adql);
long start = System.currentTimeMillis();
result = query(caomTapURL, adql);
log.info("Finished caom2 query in " + (System.currentTimeMillis() - start) + " ms");
}
return result;
}
use of ca.nrc.cadc.caom2.ObservationURI in project caom2db by opencadc.
the class GetActionTest method testDoIt.
@Test
public void testDoIt() throws Exception {
// test the doIt method when it returns 2 observations
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
GetAction getAction = new TestGetAction(mockDao);
TestSyncOutput out = new TestSyncOutput();
getAction.setSyncOutput(out);
reset(mockDao);
expect(mockRequest.getMethod()).andReturn("GET");
expect(mockRequest.getServletPath()).andReturn("/obs").atLeastOnce();
expect(mockRequest.getPathInfo()).andReturn("TEST").atLeastOnce();
// build the list of observations for the mock dao to return
List<ObservationState> obsList = new ArrayList<ObservationState>();
DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
ObservationState os1 = new ObservationState(new ObservationURI("TEST", "1234"));
os1.maxLastModified = df.parse("2010-10-10T10:10:10.10");
os1.accMetaChecksum = URI.create("md5:5b71d023d4729575d550536dce8439e6");
obsList.add(os1);
ObservationState os2 = new ObservationState(new ObservationURI("TEST", "6789"));
os2.maxLastModified = df.parse("2011-11-11T11:11:11.111");
os2.accMetaChecksum = URI.create("md5:aedbcf5e27a17fc2daa5a0e0d7840009");
obsList.add(os2);
Enumeration<String> params = Collections.emptyEnumeration();
expect(mockRequest.getParameterNames()).andReturn(params);
// since no maxRec argument given, expect the default one
expect(mockDao.getObservationList("TEST", null, null, RepoAction.MAX_LIST_SIZE, true)).andReturn(obsList);
replay(mockDao, mockRequest);
getAction.setSyncInput(new SyncInput(mockRequest, getAction.getInlineContentHandler()));
getAction.run();
String expected = "TEST" + "\t" + "1234" + "\t" + df.format(os1.maxLastModified) + "\t" + os1.accMetaChecksum.toString() + "\n" + "TEST" + "\t" + "6789" + "\t" + df.format(os2.maxLastModified) + "\t" + os2.accMetaChecksum.toString() + "\n";
String content = out.getContent();
log.debug("\n--list content start--\n" + content + "\n--list content end--");
Assert.assertEquals(expected, content);
// repeat test when start, end, maxRec and ascendingOrder specified
getAction = new TestGetAction(mockDao);
reset(mockDao);
reset(mockRequest);
// get a new OutSync
out = new TestSyncOutput();
getAction.setSyncOutput(out);
// build the list of observations for the mock dao to return
expect(mockRequest.getMethod()).andReturn("GET");
expect(mockRequest.getPathInfo()).andReturn("/TEST");
List<String> keys = new ArrayList<String>();
keys.add("MAXREC");
keys.add("Start");
keys.add("end");
params = Collections.enumeration(keys);
String startDate = "2010-10-10T10:10:10.1";
String endDate = "2011-11-11T11:11:11.111";
expect(mockRequest.getParameterNames()).andReturn(params);
expect(mockRequest.getParameterValues("MAXREC")).andReturn(new String[] { "3" });
expect(mockRequest.getParameterValues("Start")).andReturn(new String[] { startDate });
expect(mockRequest.getParameterValues("end")).andReturn(new String[] { endDate });
// all arguments given
expect(mockDao.getObservationList("TEST", df.parse(startDate), df.parse(endDate), 3, true)).andReturn(obsList);
replay(mockDao, mockRequest);
getAction.setSyncInput(new SyncInput(mockRequest, getAction.getInlineContentHandler()));
getAction.run();
Assert.assertEquals(expected, out.getContent());
log.info("Finished testDoIt.");
}
use of ca.nrc.cadc.caom2.ObservationURI in project caom2db by opencadc.
the class DeleteAction method doAction.
@Override
public void doAction() throws Exception {
ObservationURI uri = getURI();
log.debug("START: " + uri);
checkWritePermission();
ObservationDAO dao = getDAO();
ObservationState s = dao.getState(uri);
if (s == null) {
throw new ResourceNotFoundException("not found: " + uri);
}
dao.delete(s.getID());
log.debug("DONE: " + uri);
}
Aggregations