use of ca.nrc.cadc.caom2.persistence.ObservationDAO in project caom2db by opencadc.
the class ObservationExtractor method extractObservations.
// obsolete: this extracts list of observations but ObservationDAO no longer supports that in a single query
private List<Observation> extractObservations(ResultSet rs) throws SQLException {
int ncol = rs.getMetaData().getColumnCount();
log.debug("extractData: ncol=" + ncol);
List<Observation> ret = new ArrayList<Observation>();
Observation curObs = null;
Plane curPlane = null;
Artifact curArtifact = null;
Part curPart = null;
Chunk curChunk = null;
int row = 0;
while (rs.next()) {
row++;
int col = 1;
UUID obsID = obsMapper.getID(rs, row, col);
if (curObs == null || !curObs.getID().equals(obsID)) {
log.debug("mapping Observation at column " + col);
if (curObs != null) {
log.debug("END observation: " + curObs.getID());
}
curObs = obsMapper.mapRow(rs, row, col);
ret.add(curObs);
log.debug("START observation: " + curObs.getID());
}
// else: obs content repeated due to join -- ignore it
col += obsMapper.getColumnCount();
if (ncol > col) {
log.debug("mapping Plane at column " + col);
UUID planeID = planeMapper.getID(rs, row, col);
if (planeID != null) {
if (curPlane == null || !curPlane.getID().equals(planeID)) {
if (curPlane != null) {
log.debug("END plane: " + curPlane.getID());
}
curPlane = planeMapper.mapRow(rs, row, col);
curObs.getPlanes().add(curPlane);
log.debug("START plane: " + curPlane.getID());
}
// else: plane content repeated due to join -- ignore it
} else {
log.debug("observation: " + curObs.getID() + ": no planes");
curPlane = null;
}
col += planeMapper.getColumnCount();
}
if (curPlane != null && ncol > col) {
log.debug("mapping Artifact at column " + col);
UUID artifactID = artifactMapper.getID(rs, row, col);
if (artifactID != null) {
if (curArtifact == null || !curArtifact.getID().equals(artifactID)) {
if (curArtifact != null) {
log.debug("END artifact: " + curArtifact.getID());
}
curArtifact = artifactMapper.mapRow(rs, row, col);
curPlane.getArtifacts().add(curArtifact);
log.debug("START artifact: " + curArtifact.getID());
}
// else: artifact content repeated due to join -- ignore it
} else {
log.debug("plane: " + curPlane.getID() + ": no artifacts");
curArtifact = null;
}
col += artifactMapper.getColumnCount();
}
if (curArtifact != null && ncol > col) {
log.debug("mapping Part at column " + col);
UUID partID = partMapper.getID(rs, row, col);
if (partID != null) {
if (curPart == null || !curPart.getID().equals(partID)) {
if (curPart != null) {
log.debug("END part: " + curPart.getID());
}
curPart = partMapper.mapRow(rs, row, col);
curArtifact.getParts().add(curPart);
log.debug("START part: " + curPart.getID());
}
// else: artifact content repeated due to join -- ignore it
} else {
log.debug("artifact: " + curArtifact.getID() + ": no parts");
curPart = null;
}
col += partMapper.getColumnCount();
}
if (curPart != null && ncol > col) {
log.debug("mapping Chunk at column " + col);
UUID chunkID = chunkMapper.getID(rs, row, col);
if (chunkID != null) {
if (curChunk == null || !curChunk.getID().equals(chunkID)) {
if (curChunk != null) {
log.debug("END part: " + curChunk.getID());
}
curChunk = chunkMapper.mapRow(rs, row, col);
curPart.getChunks().add(curChunk);
log.debug("START chunk: " + curChunk.getID());
}
// else: artifact content repeated due to join -- ignore it
} else {
log.debug("part: " + curPart.getID() + ": no chunks");
curChunk = null;
}
col += chunkMapper.getColumnCount();
}
}
return ret;
}
use of ca.nrc.cadc.caom2.persistence.ObservationDAO 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);
}
use of ca.nrc.cadc.caom2.persistence.ObservationDAO in project caom2db by opencadc.
the class PostAction method doAction.
@Override
public void doAction() throws Exception {
ObservationURI uri = getURI();
log.debug("START: " + uri);
checkWritePermission();
Observation obs = getInputObservation();
if (!uri.equals(obs.getURI())) {
throw new IllegalArgumentException("invalid input: " + uri + " (path) must match : " + obs.getURI() + "(document)");
}
ObservationDAO dao = getDAO();
ObservationState s = dao.getState(obs.getID());
if (s == null) {
throw new ResourceNotFoundException("not found: " + uri);
}
validate(obs);
URI expectedMetaChecksum = null;
String condition = syncInput.getHeader("If-Match");
if (condition != null) {
condition = condition.trim();
try {
expectedMetaChecksum = new URI(condition);
} catch (URISyntaxException ex) {
throw new IllegalArgumentException("invalid If-Match value: " + condition, ex);
}
}
dao.put(obs, expectedMetaChecksum);
log.debug("DONE: " + uri);
}
use of ca.nrc.cadc.caom2.persistence.ObservationDAO in project caom2db by opencadc.
the class ObservationValidator method init.
private void init(int nthreads) throws IOException, ParseException, URISyntaxException {
if (src.getResourceType() == HarvestResource.SOURCE_DB && src.getDatabaseServer() != null) {
Map<String, Object> config1 = getConfigDAO(src);
this.srcObservationDAO = new ObservationDAO();
srcObservationDAO.setConfig(config1);
ready = true;
} else if (src.getResourceType() == HarvestResource.SOURCE_URI) {
this.srcObservationService = new RepoClient(src.getResourceID(), nthreads);
this.srcURI = src.getResourceID().toString();
} else if (src.getResourceType() == HarvestResource.SOURCE_CAP_URL) {
this.srcObservationService = new RepoClient(src.getCapabilitiesURL(), nthreads);
this.srcURI = src.getCapabilitiesURL().toString();
} else {
throw new IllegalStateException("BUG: unexpected HarvestResource resource type: " + src);
}
initProgressFile(src.getIdentifier());
// This is to capture the totals of each batch aggregate
runAggregate = new Aggregate();
if (srcObservationService != null) {
if (srcObservationService.isObsAvailable()) {
ready = true;
} else {
log.error("Not available obs endpoint in " + srcObservationService.toString());
}
}
// make sure wcslib can be loaded
try {
log.info("loading ca.nrc.cadc.wcs.WCSLib");
Class.forName("ca.nrc.cadc.wcs.WCSLib");
} catch (Throwable t) {
throw new RuntimeException("FATAL - failed to load WCSLib JNI binding", t);
}
}
use of ca.nrc.cadc.caom2.persistence.ObservationDAO in project caom2db by opencadc.
the class PutAction method doAction.
@Override
public void doAction() throws Exception {
ObservationURI uri = getURI();
log.debug("START: " + uri);
checkWritePermission();
Observation obs = getInputObservation();
if (!uri.equals(obs.getURI())) {
throw new IllegalArgumentException("invalid input: " + uri + " (path) must match : " + obs.getURI() + "(document)");
}
ObservationDAO dao = getDAO();
ObservationState s = dao.getState(obs.getID());
if (s != null) {
throw new ResourceAlreadyExistsException("already exists: " + uri);
}
validate(obs);
dao.put(obs);
log.debug("DONE: " + uri);
}
Aggregations