Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recalculate Bounding Boxes #200

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@ public String getParamValue(){
* @param calculationMode
* @return true if recalculation succeeded, false otherwise.
*/
private boolean recalculateBBox(StoreType type, String xmlElementName, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){
private boolean recalculateBBox(StoreType type, GSResourceEncoder renc, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){

String baseUrl = restURL + "/rest/workspaces/" + workspace + "/" +
type.getType().toLowerCase() +"s/" + storeName + "/" +
Expand All @@ -3283,8 +3283,12 @@ private boolean recalculateBBox(StoreType type, String xmlElementName, String wo
// GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace);

// String body = wsenc.toString();
String body = "<" + xmlElementName +"><name>" + layerName + "</name>" +
"<enabled>" + enabled + "</enabled></" + xmlElementName + ">";
// String body = "<" + xmlElementName +"><name>" + layerName + "</name>" +
// "<enabled>" + enabled + "</enabled></" + xmlElementName + ">";
renc.remove(GSResourceEncoder.KEYWORDS);
renc.remove(GSResourceEncoder.METADATA);
renc.remove(GSResourceEncoder.METADATALINKS);
String body = renc.toString();
Copy link
Author

@cschroedl-gov cschroedl-gov Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: never mind! After adding a method to XmlElement to recursively delete empty children, I was able to use the GS*Encoder classes instead of building the xml with Strings.

When I switched to using GSEncoder classes, I noted that several extra elements were added to the resulting XML documents. These extra empty elements could overwrite existing keywords, metadata, and metadatalinks. While I can remove a hard-coded list of extra elements now, the same kind of problem can occur in the future if new fields are added to the encoders without updating this class. I opted to revert to simple String construction instead of GSEncoder classes to ensure that this functionality would continue to be stable in the future.

String sendResult = HTTPUtils.putXml(sUrl, body, gsuser, gspass);
boolean success = sendResult != null;
return success;
Expand All @@ -3299,7 +3303,11 @@ private boolean recalculateBBox(StoreType type, String xmlElementName, String wo
* @return true if successful, false otherwise
*/
public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){
return recalculateBBox(StoreType.DATASTORES, "featureType", workspace, storeName, layerName, calculationMode, enabled);
GSFeatureTypeEncoder fenc = new GSFeatureTypeEncoder();
fenc.remove(GSFeatureTypeEncoder.ATTRIBUTES);
fenc.setName(layerName);
fenc.setEnabled(enabled);
return recalculateBBox(StoreType.DATASTORES, fenc, workspace, storeName, layerName, calculationMode);
}

/**
Expand All @@ -3311,6 +3319,10 @@ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, St
* @return true if successful, false otherwise
*/
public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){
return recalculateBBox(StoreType.COVERAGESTORES, "coverage", workspace, storeName, layerName, calculationMode, enabled);
GSCoverageEncoder cenc = new GSCoverageEncoder();
cenc.remove(GSCoverageEncoder.SUPPORTED_FORMATS);
cenc.setName(layerName);
cenc.setEnabled(enabled);
return recalculateBBox(StoreType.COVERAGESTORES, cenc, workspace, storeName, layerName, calculationMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class GSCoverageEncoder extends GSResourceEncoder {
public final static String NATIVECOVERAGENAME = "nativeCoverageName";

private final static String NATIVE_FORMAT="nativeFormat";
private final static String SUPPORTED_FORMATS="supportedFormats";
public final static String SUPPORTED_FORMATS="supportedFormats";

private final static String REQUEST_SRS="requestSRS";
private final static String RESPONSE_SRS="responseSRS";
Expand Down