From 8dd1c7ed6c6d05e296befdacad83ac006887c10b Mon Sep 17 00:00:00 2001
From: Dimitar Misev <misev@rasdaman.com>
Date: Wed, 16 Jan 2013 19:20:46 +0100
Subject: [PATCH] Fix handling of simultaneous requests in petascope (ticket
133)
---
.../main/java/petascope/core/DbMetadataSource.java | 43 +++++---------------
.../src/main/java/petascope/core/Metadata.java | 9 ++++
.../src/main/java/petascope/util/WcsUtil.java | 7 ++++
.../wcs2/extensions/GmlFormatExtension.java | 16 --------
.../wcs2/handlers/DescribeCoverageHandler.java | 11 -----
5 files changed, 26 insertions(+), 60 deletions(-)
diff --git a/applications/petascope/src/main/java/petascope/core/DbMetadataSource.java b/applications/petascope/src/main/java/petascope/core/DbMetadataSource.java
index db8f7a0..e115e0e 100644
a
|
b
|
public class DbMetadataSource implements IMetadataSource {
|
451 | 451 | ensureConnection(); |
452 | 452 | s = conn.createStatement(); |
453 | 453 | |
454 | | ResultSet r = s.executeQuery("SELECT id, type, nullDefault, interpolationTypeDefault, nullResistanceDefault FROM PS_Coverage WHERE name = '" + coverageName + "'"); |
| 454 | ResultSet r = null; |
| 455 | r = s.executeQuery("SELECT id, type, nullDefault, interpolationTypeDefault, nullResistanceDefault FROM PS_Coverage WHERE name = '" + coverageName + "'"); |
455 | 456 | |
456 | 457 | if (!r.next()) { |
457 | 458 | throw new PetascopeException(ExceptionCode.InvalidRequest, |
… |
… |
public class DbMetadataSource implements IMetadataSource {
|
630 | 631 | } else if (twoDCoverage) { |
631 | 632 | log.warn(" Bounding box missing for 2-D coverage '" + coverageName + "'..."); |
632 | 633 | } |
| 634 | |
| 635 | r = s.executeQuery("SELECT metadata FROM ps_metadata WHERE coverage in " |
| 636 | + "(SELECT id FROM ps_coverage WHERE name = '" + coverage + "')"); |
| 637 | String metadata = ""; |
| 638 | if (r.next()) { |
| 639 | metadata = r.getString("metadata"); |
| 640 | } |
633 | 641 | |
634 | 642 | /* Done with SQL statements */ |
635 | 643 | s.close(); |
… |
… |
public class DbMetadataSource implements IMetadataSource {
|
639 | 647 | new InterpolationMethod(interpolationTypeDefault, nullResistanceDefault), |
640 | 648 | coverageName, coverageType, domain, bbox, title, abstr, keywords); |
641 | 649 | meta.setCoverageId(coverage); |
| 650 | meta.setMetadata(metadata); |
642 | 651 | log.trace("Caching coverage metadata."); |
643 | 652 | cache.put(coverageName, meta); |
644 | 653 | return meta; |
… |
… |
public class DbMetadataSource implements IMetadataSource {
|
1054 | 1063 | } |
1055 | 1064 | } |
1056 | 1065 | |
1057 | | /** |
1058 | | * Given the CoverageID; returns image metadata |
1059 | | * @param coverageId |
1060 | | * @return textual metadata |
1061 | | * @throws PetascopeException |
1062 | | */ |
1063 | | public String getImageMetadata(String coverageId) throws PetascopeException { |
1064 | | Statement s = null; |
1065 | | try { |
1066 | | ensureConnection(); |
1067 | | s = conn.createStatement(); |
1068 | | ResultSet r = s.executeQuery("SELECT metadata FROM ps_metadata WHERE coverage in " |
1069 | | + "(SELECT id FROM ps_coverage WHERE name = '" + coverageId + "')"); |
1070 | | if (r.next()) { |
1071 | | return r.getString("metadata"); |
1072 | | } else { |
1073 | | return ""; |
1074 | | } |
1075 | | } catch (SQLException sqle) { |
1076 | | throw new PetascopeException(ExceptionCode.ResourceError, |
1077 | | "Error retrieving metadata for coverage " + coverageId, sqle); |
1078 | | } finally { |
1079 | | if (s != null) { |
1080 | | try { |
1081 | | s.close(); |
1082 | | } catch (SQLException f) { |
1083 | | } |
1084 | | } |
1085 | | close(); |
1086 | | } |
1087 | | } |
1088 | | |
1089 | 1066 | /** Insert metadata for a new coverage. |
1090 | 1067 | * |
1091 | 1068 | * @param meta Metadata object, container of information |
diff --git a/applications/petascope/src/main/java/petascope/core/Metadata.java b/applications/petascope/src/main/java/petascope/core/Metadata.java
index 49581ff..fb78bd0 100644
a
|
b
|
public class Metadata implements Cloneable {
|
63 | 63 | private Bbox bbox = null; |
64 | 64 | private CellDomainElement cellX, cellY, cellT; |
65 | 65 | private DomainElement domX, domY, domT; |
| 66 | private String metadata; |
66 | 67 | |
67 | 68 | public Metadata(List<CellDomainElement> cellDomain, List<RangeElement> range, |
68 | 69 | Set<String> nullSet, String nullDefault, Set<InterpolationMethod> interpolationSet, |
… |
… |
public class Metadata implements Cloneable {
|
683 | 684 | BigInteger big = cellT.getHi().subtract(cellT.getLo()); |
684 | 685 | return big.longValue(); |
685 | 686 | } |
| 687 | |
| 688 | public String getMetadata() { |
| 689 | return metadata; |
| 690 | } |
| 691 | |
| 692 | public void setMetadata(String metadata) { |
| 693 | this.metadata = metadata; |
| 694 | } |
686 | 695 | } |
diff --git a/applications/petascope/src/main/java/petascope/util/WcsUtil.java b/applications/petascope/src/main/java/petascope/util/WcsUtil.java
index a9a65a3..623f0b6 100644
a
|
b
|
public class WcsUtil {
|
183 | 183 | Pair.of("\\{code\\}", range.getUomCode())); |
184 | 184 | } |
185 | 185 | |
| 186 | String metadata = m.getMetadata().getMetadata(); |
| 187 | if (metadata == null) { |
| 188 | metadata = "<gmlcov:metadata>" + metadata + "</gmlcov:metadata>"; |
| 189 | } else { |
| 190 | metadata = ""; |
| 191 | } |
186 | 192 | String ret = Templates.getTemplate(template, |
187 | 193 | Pair.of("\\{coverageId\\}", m.getCoverageId()), |
188 | 194 | Pair.of("\\{coverageType\\}", m.getCoverageType()), |
… |
… |
public class WcsUtil {
|
199 | 205 | Pair.of("\\{srsName\\}", getSrsName(m)), |
200 | 206 | Pair.of("\\{lowerCorner\\}", getLowerCorner(m)), |
201 | 207 | Pair.of("\\{upperCorner\\}", getUpperCorner(m)), |
| 208 | Pair.of("\\{metadata\\}", metadata), |
202 | 209 | Pair.of("\\{additions\\}", getAdditions(m))); |
203 | 210 | |
204 | 211 | if (replaceBounds) { |
diff --git a/applications/petascope/src/main/java/petascope/wcs2/extensions/GmlFormatExtension.java b/applications/petascope/src/main/java/petascope/wcs2/extensions/GmlFormatExtension.java
index a0ae976..980bad7 100644
a
|
b
|
public class GmlFormatExtension extends AbstractFormatExtension {
|
72 | 72 | //Handle the range subset feature |
73 | 73 | RangeSubsettingExtension rsubExt = (RangeSubsettingExtension) ExtensionsRegistry.getExtension(ExtensionsRegistry.RANGE_SUBSETTING_IDENTIFIER); |
74 | 74 | rsubExt.handle(request, m); |
75 | | String metadata = ""; |
76 | | try { |
77 | | metadata = meta.getImageMetadata(request.getCoverageId()); |
78 | | } catch (PetascopeException p) { |
79 | | throw new WCSException(ExceptionCode.ResourceError, p); |
80 | | } |
81 | 75 | |
82 | 76 | if (m.getCoverageType().equals(GetCoverageRequest.MULTIPOINT_COVERAGE)) { |
83 | 77 | Response r = handleMultiPoint(request, request.getCoverageId(), meta, m); |
84 | 78 | String xml = r.getXml(); |
85 | | if (!metadata.isEmpty()) { |
86 | | xml = xml.replace("{metadata}", "<gmlcov:metadata>" + metadata + "</gmlcov:metadata>"); |
87 | | } else { |
88 | | xml = xml.replace("{metadata}", ""); |
89 | | } |
90 | 79 | return new Response(r.getData(), xml, r.getMimeType()); |
91 | 80 | } |
92 | 81 | |
93 | 82 | setBounds(request, m, meta); |
94 | 83 | String gml = WcsUtil.getGML(m, Templates.GRID_COVERAGE, true); |
95 | 84 | gml = addCoverageData(gml, request, meta, m); |
96 | | if (!metadata.isEmpty()) { |
97 | | gml = gml.replace("{metadata}", "<gmlcov:metadata>" + metadata + "</gmlcov:metadata>"); |
98 | | } else { |
99 | | gml = gml.replace("{metadata}", ""); |
100 | | } |
101 | 85 | return new Response(gml); |
102 | 86 | } |
103 | 87 | |
diff --git a/applications/petascope/src/main/java/petascope/wcs2/handlers/DescribeCoverageHandler.java b/applications/petascope/src/main/java/petascope/wcs2/handlers/DescribeCoverageHandler.java
index 10aff65..cc80b77 100644
a
|
b
|
public class DescribeCoverageHandler extends AbstractRequestHandler<DescribeCove
|
80 | 80 | if (exc != null) { |
81 | 81 | continue; |
82 | 82 | } |
83 | | String metadata = ""; |
84 | | try { |
85 | | metadata = meta.getImageMetadata(coverageId); |
86 | | } catch (PetascopeException p) { |
87 | | throw new WCSException(ExceptionCode.ResourceError, p); |
88 | | } |
89 | | if (!metadata.isEmpty()) { |
90 | | descr = descr.replace("{metadata}", "<gmlcov:metadata>" + metadata + "</gmlcov:metadata>"); |
91 | | } else { |
92 | | descr = descr.replace("{metadata}", ""); |
93 | | } |
94 | 83 | try { |
95 | 84 | root.appendChild(XMLUtil.buildDocument(null, descr).getRootElement().copy()); |
96 | 85 | } catch (Exception ex) { |