Search in sources :

Example 1 with Artifact

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

the class ObservationDAO method updateEntity.

private void updateEntity(Plane entity, PlaneSkeleton s, Date now) {
    if (origin && s == null) {
        CaomUtil.assignID(entity, gen.generateID(entity.getID()));
    }
    if (origin && s != null) {
        Util.assignLastModified(entity, s.lastModified, "lastModified");
        Util.assignLastModified(entity, s.maxLastModified, "maxLastModified");
    }
    for (Artifact artifact : entity.getArtifacts()) {
        ArtifactSkeleton skel = null;
        if (s != null) {
            for (ArtifactSkeleton ss : s.artifacts) {
                if (artifact.getID().equals(ss.id)) {
                    skel = ss;
                }
            }
        }
        updateEntity(artifact, skel, now);
    }
    // new or changed
    // just in case
    digest.reset();
    Util.assignMetaChecksum(entity, entity.computeMetaChecksum(digest), "metaChecksum");
    Util.assignMetaChecksum(entity, entity.computeAccMetaChecksum(digest), "accMetaChecksum");
    boolean delta = false;
    if (s == null || s.metaChecksum == null) {
        delta = true;
    } else {
        delta = !entity.getMetaChecksum().equals(s.metaChecksum);
    }
    if (delta && (origin || entity.getLastModified() == null)) {
        Util.assignLastModified(entity, now, "lastModified");
    }
    boolean accDelta = false;
    if (s == null || s.accMetaChecksum == null) {
        accDelta = true;
    } else {
        accDelta = !entity.getAccMetaChecksum().equals(s.accMetaChecksum);
    }
    if (accDelta && (origin || entity.getMaxLastModified() == null)) {
        Util.assignLastModified(entity, now, "maxLastModified");
    }
}
Also used : ArtifactSkeleton(ca.nrc.cadc.caom2.persistence.skel.ArtifactSkeleton) Artifact(ca.nrc.cadc.caom2.Artifact)

Example 2 with Artifact

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

the class ObservationDAO method updateEntity.

private void updateEntity(Artifact entity, ArtifactSkeleton s, Date now) {
    if (origin && s == null) {
        CaomUtil.assignID(entity, gen.generateID(entity.getID()));
    }
    if (origin && s != null) {
        Util.assignLastModified(entity, s.lastModified, "lastModified");
        Util.assignLastModified(entity, s.maxLastModified, "maxLastModified");
    }
    for (Part part : entity.getParts()) {
        PartSkeleton skel = null;
        if (s != null) {
            for (PartSkeleton ss : s.parts) {
                if (part.getID().equals(ss.id)) {
                    skel = ss;
                }
            }
        }
        updateEntity(part, skel, now);
    }
    // new or changed
    // just in case
    digest.reset();
    Util.assignMetaChecksum(entity, entity.computeMetaChecksum(digest), "metaChecksum");
    Util.assignMetaChecksum(entity, entity.computeAccMetaChecksum(digest), "accMetaChecksum");
    boolean delta = false;
    if (s == null || s.metaChecksum == null) {
        delta = true;
    } else {
        delta = !entity.getMetaChecksum().equals(s.metaChecksum);
    }
    if (delta && (origin || entity.getLastModified() == null)) {
        Util.assignLastModified(entity, now, "lastModified");
    }
    boolean accDelta = false;
    if (s == null || s.accMetaChecksum == null) {
        accDelta = true;
    } else {
        accDelta = !entity.getAccMetaChecksum().equals(s.accMetaChecksum);
    }
    if (accDelta && (origin || entity.getMaxLastModified() == null)) {
        Util.assignLastModified(entity, now, "maxLastModified");
    }
}
Also used : Part(ca.nrc.cadc.caom2.Part) PartSkeleton(ca.nrc.cadc.caom2.persistence.skel.PartSkeleton)

Example 3 with Artifact

use of ca.nrc.cadc.caom2.Artifact 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 4 with Artifact

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

the class ObservationSkeletonExtractor method extractData.

@Override
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
    ObservationSkeleton ret = null;
    PlaneSkeleton curPlane = null;
    ArtifactSkeleton curArtifact = null;
    PartSkeleton curPart = null;
    ChunkSkeleton curChunk = null;
    int ncol = rs.getMetaData().getColumnCount();
    while (rs.next()) {
        if (ret == null) {
            ret = new ObservationSkeleton();
        }
        Date d;
        Date md;
        UUID id;
        URI cs;
        URI acs;
        int col = 1;
        if (ret.id == null) {
            d = Util.getDate(rs, col++, utcCalendar);
            md = Util.getDate(rs, col++, utcCalendar);
            cs = Util.getURI(rs, col++);
            acs = Util.getURI(rs, col++);
            id = Util.getUUID(rs, col++);
            ret.id = id;
            ret.lastModified = d;
            ret.maxLastModified = md;
            ret.metaChecksum = cs;
            ret.accMetaChecksum = acs;
        } else {
            // skip
            col += 5;
        }
        if (ncol > col) {
            // plane
            d = Util.getDate(rs, col++, utcCalendar);
            md = Util.getDate(rs, col++, utcCalendar);
            cs = Util.getURI(rs, col++);
            acs = Util.getURI(rs, col++);
            id = Util.getUUID(rs, col++);
            if (id != null) {
                if (curPlane == null || !curPlane.id.equals(id)) {
                    curPlane = new PlaneSkeleton();
                    curPlane.id = id;
                    curPlane.lastModified = d;
                    curPlane.maxLastModified = md;
                    curPlane.metaChecksum = cs;
                    curPlane.accMetaChecksum = acs;
                    log.debug("add: " + curPlane + " to " + ret);
                    ret.planes.add(curPlane);
                }
                if (ncol > col) {
                    // artifact
                    d = Util.getDate(rs, col++, utcCalendar);
                    md = Util.getDate(rs, col++, utcCalendar);
                    cs = Util.getURI(rs, col++);
                    acs = Util.getURI(rs, col++);
                    id = Util.getUUID(rs, col++);
                    if (id != null) {
                        if (curArtifact == null || !curArtifact.id.equals(id)) {
                            curArtifact = new ArtifactSkeleton();
                            curArtifact.id = id;
                            curArtifact.lastModified = d;
                            curArtifact.maxLastModified = md;
                            curArtifact.metaChecksum = cs;
                            curArtifact.accMetaChecksum = acs;
                            log.debug("add: " + curArtifact + " to " + curPlane);
                            curPlane.artifacts.add(curArtifact);
                        }
                        if (ncol > col) {
                            // part
                            d = Util.getDate(rs, col++, utcCalendar);
                            md = Util.getDate(rs, col++, utcCalendar);
                            cs = Util.getURI(rs, col++);
                            acs = Util.getURI(rs, col++);
                            id = Util.getUUID(rs, col++);
                            if (id != null) {
                                if (curPart == null || !curPart.id.equals(id)) {
                                    curPart = new PartSkeleton();
                                    curPart.id = id;
                                    curPart.lastModified = d;
                                    curPart.maxLastModified = md;
                                    curPart.metaChecksum = cs;
                                    curPart.accMetaChecksum = acs;
                                    log.debug("add: " + curPart + " to " + curArtifact);
                                    curArtifact.parts.add(curPart);
                                }
                                if (ncol > col) {
                                    // chunk
                                    d = Util.getDate(rs, col++, utcCalendar);
                                    md = Util.getDate(rs, col++, utcCalendar);
                                    cs = Util.getURI(rs, col++);
                                    acs = Util.getURI(rs, col++);
                                    id = Util.getUUID(rs, col++);
                                    if (id != null) {
                                        curChunk = new ChunkSkeleton();
                                        curChunk.id = id;
                                        curChunk.lastModified = d;
                                        curChunk.maxLastModified = md;
                                        curChunk.metaChecksum = cs;
                                        curChunk.accMetaChecksum = acs;
                                        log.debug("add: " + curChunk + " to " + curPart);
                                        curPart.chunks.add(curChunk);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return ret;
}
Also used : ChunkSkeleton(ca.nrc.cadc.caom2.persistence.skel.ChunkSkeleton) ArtifactSkeleton(ca.nrc.cadc.caom2.persistence.skel.ArtifactSkeleton) ObservationSkeleton(ca.nrc.cadc.caom2.persistence.skel.ObservationSkeleton) PlaneSkeleton(ca.nrc.cadc.caom2.persistence.skel.PlaneSkeleton) PartSkeleton(ca.nrc.cadc.caom2.persistence.skel.PartSkeleton) UUID(java.util.UUID) URI(java.net.URI) Date(java.util.Date)

Example 5 with Artifact

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

the class PlaneDAO method put.

@Override
public void put(Skeleton cur, Plane p, LinkedList<CaomEntity> parents, JdbcTemplate jdbc) {
    if (p == null) {
        throw new IllegalArgumentException("arg cannot be null");
    }
    log.debug("PUT: " + p.getID());
    long t = System.currentTimeMillis();
    try {
        // delete obsolete children
        List<Pair<Artifact>> pairs = new ArrayList<Pair<Artifact>>();
        if (cur != null) {
            PlaneSkeleton cs = (PlaneSkeleton) cur;
            // delete the skeletons that are not in p.getArtifacts()
            for (ArtifactSkeleton as : cs.artifacts) {
                Artifact a = Util.findArtifact(p.getArtifacts(), as.id);
                if (a == null) {
                    log.debug("put caused delete artifact: " + a);
                    artifactDAO.delete(as, jdbc);
                }
            }
            // pair up planes and skeletons for insert/update
            for (Artifact a : p.getArtifacts()) {
                ArtifactSkeleton as = Util.findArtifactSkel(cs.artifacts, a.getID());
                // null ok
                pairs.add(new Pair<Artifact>(as, a));
            }
        } else {
            for (Artifact a : p.getArtifacts()) {
                pairs.add(new Pair<Artifact>(null, a));
            }
        }
        super.put(cur, p, parents, jdbc);
        parents.push(p);
        for (Pair<Artifact> a : pairs) {
            artifactDAO.put(a.cur, a.val, parents, jdbc);
        }
        parents.pop();
    } finally {
        long dt = System.currentTimeMillis() - t;
        log.debug("PUT: " + p.getID() + " " + dt + "ms");
    }
}
Also used : ArtifactSkeleton(ca.nrc.cadc.caom2.persistence.skel.ArtifactSkeleton) ArrayList(java.util.ArrayList) PlaneSkeleton(ca.nrc.cadc.caom2.persistence.skel.PlaneSkeleton) Artifact(ca.nrc.cadc.caom2.Artifact)

Aggregations

Artifact (ca.nrc.cadc.caom2.Artifact)35 Plane (ca.nrc.cadc.caom2.Plane)30 Observation (ca.nrc.cadc.caom2.Observation)17 Part (ca.nrc.cadc.caom2.Part)16 SimpleObservation (ca.nrc.cadc.caom2.SimpleObservation)16 Test (org.junit.Test)14 Date (java.util.Date)13 Chunk (ca.nrc.cadc.caom2.Chunk)12 Artifact (org.eclipse.bpmn2.Artifact)12 ArrayList (java.util.ArrayList)11 URI (java.net.URI)10 SubProcess (org.eclipse.bpmn2.SubProcess)10 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)9 Process (org.eclipse.bpmn2.Process)9 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)8 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)8 Association (org.eclipse.bpmn2.Association)7 FlowElement (org.eclipse.bpmn2.FlowElement)7 ArtifactMetadata (ca.nrc.cadc.caom2.artifact.ArtifactMetadata)6 HarvestSkipURI (ca.nrc.cadc.caom2.harvester.state.HarvestSkipURI)5