Search in sources :

Example 1 with ObservationDAO

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;
}
Also used : Plane(ca.nrc.cadc.caom2.Plane) Part(ca.nrc.cadc.caom2.Part) Observation(ca.nrc.cadc.caom2.Observation) ArrayList(java.util.ArrayList) Chunk(ca.nrc.cadc.caom2.Chunk) UUID(java.util.UUID) Artifact(ca.nrc.cadc.caom2.Artifact)

Example 2 with ObservationDAO

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);
}
Also used : ObservationURI(ca.nrc.cadc.caom2.ObservationURI) ObservationDAO(ca.nrc.cadc.caom2.persistence.ObservationDAO) ObservationState(ca.nrc.cadc.caom2.ObservationState) ResourceNotFoundException(ca.nrc.cadc.net.ResourceNotFoundException)

Example 3 with ObservationDAO

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);
}
Also used : ObservationURI(ca.nrc.cadc.caom2.ObservationURI) ObservationDAO(ca.nrc.cadc.caom2.persistence.ObservationDAO) Observation(ca.nrc.cadc.caom2.Observation) ObservationState(ca.nrc.cadc.caom2.ObservationState) URISyntaxException(java.net.URISyntaxException) ResourceNotFoundException(ca.nrc.cadc.net.ResourceNotFoundException) ObservationURI(ca.nrc.cadc.caom2.ObservationURI) URI(java.net.URI)

Example 4 with ObservationDAO

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);
    }
}
Also used : ObservationDAO(ca.nrc.cadc.caom2.persistence.ObservationDAO) RepoClient(ca.nrc.cadc.caom2.repo.client.RepoClient)

Example 5 with ObservationDAO

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);
}
Also used : ObservationURI(ca.nrc.cadc.caom2.ObservationURI) ObservationDAO(ca.nrc.cadc.caom2.persistence.ObservationDAO) Observation(ca.nrc.cadc.caom2.Observation) ObservationState(ca.nrc.cadc.caom2.ObservationState) ResourceAlreadyExistsException(ca.nrc.cadc.net.ResourceAlreadyExistsException)

Aggregations

ObservationDAO (ca.nrc.cadc.caom2.persistence.ObservationDAO)12 ObservationState (ca.nrc.cadc.caom2.ObservationState)4 RepoClient (ca.nrc.cadc.caom2.repo.client.RepoClient)4 ResourceNotFoundException (ca.nrc.cadc.net.ResourceNotFoundException)4 Observation (ca.nrc.cadc.caom2.Observation)3 ObservationURI (ca.nrc.cadc.caom2.ObservationURI)3 DeletedEntityDAO (ca.nrc.cadc.caom2.persistence.DeletedEntityDAO)2 URI (java.net.URI)2 Artifact (ca.nrc.cadc.caom2.Artifact)1 Chunk (ca.nrc.cadc.caom2.Chunk)1 ObservationResponse (ca.nrc.cadc.caom2.ObservationResponse)1 Part (ca.nrc.cadc.caom2.Part)1 Plane (ca.nrc.cadc.caom2.Plane)1 ObservationWriter (ca.nrc.cadc.caom2.xml.ObservationWriter)1 ByteCountOutputStream (ca.nrc.cadc.io.ByteCountOutputStream)1 ResourceAlreadyExistsException (ca.nrc.cadc.net.ResourceAlreadyExistsException)1 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1