-
Notifications
You must be signed in to change notification settings - Fork 59
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
Handlers #186
Merged
Merged
Handlers #186
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a287d6f
EDDGridFromErddap Sax Parser Test
ayushsingh01042003 5df1a8a
EDDTableFromFilesHandler and Test for EDDTableFromAsciiFiles
ayushsingh01042003 c9b237b
EDDGridAggregateExistingDimensionHandler
ayushsingh01042003 120b503
EDDGridCopyHandler
ayushsingh01042003 ec164d9
EDDGridFromEDDTableHandler
ayushsingh01042003 09221f0
EDDGridLon0360Handler
ayushsingh01042003 aca5ab5
Check for detecting multiple child datasetse
ayushsingh01042003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
WEB-INF/classes/gov/noaa/pfel/erddap/handlers/EDDGridAggregateExistingDimensionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package gov.noaa.pfel.erddap.handlers; | ||
|
||
import static gov.noaa.pfel.erddap.dataset.EDDGrid.DEFAULT_MATCH_AXIS_N_DIGITS; | ||
|
||
import com.cohort.array.StringArray; | ||
import com.cohort.util.String2; | ||
import gov.noaa.pfel.erddap.dataset.EDD; | ||
import gov.noaa.pfel.erddap.dataset.EDDGrid; | ||
import gov.noaa.pfel.erddap.dataset.EDDGridAggregateExistingDimension; | ||
import gov.noaa.pfel.erddap.util.EDStatic; | ||
import org.xml.sax.Attributes; | ||
import org.xml.sax.SAXException; | ||
|
||
public class EDDGridAggregateExistingDimensionHandler extends State { | ||
private StringBuilder content = new StringBuilder(); | ||
private State completeState; | ||
private String datasetID; | ||
private SaxParsingContext context; | ||
|
||
public EDDGridAggregateExistingDimensionHandler( | ||
SaxHandler saxHandler, String datasetID, State completeState, SaxParsingContext context) { | ||
super(saxHandler); | ||
this.completeState = completeState; | ||
this.datasetID = datasetID; | ||
this.context = context; | ||
} | ||
|
||
private EDDGrid firstChild = null; | ||
private StringArray tLocalSourceUrls = new StringArray(); | ||
private String tAccessibleTo = null; | ||
private String tGraphsAccessibleTo = null; | ||
private boolean tAccessibleViaWMS = true; | ||
private boolean tAccessibleViaFiles = EDStatic.defaultAccessibleViaFiles; | ||
private StringArray tOnChange = new StringArray(); | ||
private String tFgdcFile = null; | ||
private String tIso19115File = null; | ||
private int tMatchAxisNDigits = DEFAULT_MATCH_AXIS_N_DIGITS; | ||
private String tDefaultDataQuery = null; | ||
private String tDefaultGraphQuery = null; | ||
private int tnThreads = -1; // interpret invalid values (like -1) as EDStatic.nGridThreads | ||
private boolean tDimensionValuesInMemory = true; | ||
|
||
private String tSUServerType = null; | ||
private String tSURegex = null; | ||
private boolean tSURecursive = true; | ||
private String tSUPathRegex = ".*"; | ||
private String tSU = null; | ||
|
||
@Override | ||
public void startElement(String uri, String localName, String qName, Attributes attributes) | ||
throws SAXException { | ||
switch (localName) { | ||
case "dataset" -> { | ||
if (firstChild == null) { | ||
String tType = attributes.getValue("type"); | ||
if (tType == null || !tType.startsWith("EDDGrid")) { | ||
throw new RuntimeException( | ||
"Datasets.xml error: " | ||
+ "The dataset defined in an " | ||
+ "EDDGridAggregateExistingDimension must be a subclass of EDDGrid."); | ||
} | ||
|
||
String active = attributes.getValue("active"); | ||
String childDatasetID = attributes.getValue("datasetID"); | ||
State state = | ||
HandlerFactory.getHandlerFor( | ||
tType, childDatasetID, active, this, saxHandler, context); | ||
saxHandler.setState(state); | ||
} else { | ||
throw new RuntimeException( | ||
"Datasets.xml error: " | ||
+ "There can be only one <dataset> defined within an " | ||
+ "EDDGridAggregateExistingDimension <dataset>."); | ||
} | ||
} | ||
case "sourceUrls" -> { | ||
tSUServerType = attributes.getValue("serverType"); | ||
tSURegex = attributes.getValue("regex"); | ||
String tr = attributes.getValue("recursive"); | ||
tSUPathRegex = attributes.getValue("pathRegex"); | ||
tSURecursive = tr == null || String2.parseBoolean(tr); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void characters(char[] ch, int start, int length) throws SAXException { | ||
content.append(ch, start, length); | ||
} | ||
|
||
@Override | ||
public void endElement(String uri, String localName, String qName) throws Throwable { | ||
String contentStr = content.toString().trim(); | ||
|
||
switch (localName) { | ||
case "sourceUrl" -> tLocalSourceUrls.add(contentStr); | ||
case "sourceUrls" -> tSU = contentStr; | ||
case "matchAxisNDigits" -> | ||
tMatchAxisNDigits = String2.parseInt(contentStr, DEFAULT_MATCH_AXIS_N_DIGITS); | ||
case "ensureAxisValuesAreEqual" -> | ||
tMatchAxisNDigits = String2.parseBoolean(contentStr) ? 20 : 0; | ||
case "accessibleTo" -> tAccessibleTo = contentStr; | ||
case "graphsAccessibleTo" -> tGraphsAccessibleTo = contentStr; | ||
case "accessibleViaWMS" -> tAccessibleViaWMS = String2.parseBoolean(contentStr); | ||
case "accessibleViaFiles" -> tAccessibleViaFiles = String2.parseBoolean(contentStr); | ||
case "onChange" -> tOnChange.add(contentStr); | ||
case "fgdcFile" -> tFgdcFile = contentStr; | ||
case "iso19115File" -> tIso19115File = contentStr; | ||
case "defaultDataQuery" -> tDefaultDataQuery = contentStr; | ||
case "defaultGraphQuery" -> tDefaultGraphQuery = contentStr; | ||
case "nThreads" -> tnThreads = String2.parseInt(contentStr); | ||
case "dimensionValuesInMemory" -> tDimensionValuesInMemory = String2.parseBoolean(contentStr); | ||
case "dataset" -> { | ||
EDD dataset = | ||
new EDDGridAggregateExistingDimension( | ||
datasetID, | ||
tAccessibleTo, | ||
tGraphsAccessibleTo, | ||
tAccessibleViaWMS, | ||
tAccessibleViaFiles, | ||
tOnChange, | ||
tFgdcFile, | ||
tIso19115File, | ||
tDefaultDataQuery, | ||
tDefaultGraphQuery, | ||
firstChild, | ||
tLocalSourceUrls.toArray(), | ||
tSUServerType, | ||
tSURegex, | ||
tSURecursive, | ||
tSUPathRegex, | ||
tSU, | ||
tMatchAxisNDigits, | ||
tnThreads, | ||
tDimensionValuesInMemory); | ||
|
||
this.completeState.handleDataset(dataset); | ||
saxHandler.setState(this.completeState); | ||
} | ||
default -> String2.log("Unexpected end tag: " + localName); | ||
} | ||
content.setLength(0); | ||
} | ||
|
||
@Override | ||
public void handleDataset(EDD dataset) { | ||
firstChild = (EDDGrid) dataset; | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
WEB-INF/classes/gov/noaa/pfel/erddap/handlers/EDDGridCopyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package gov.noaa.pfel.erddap.handlers; | ||
|
||
import static gov.noaa.pfel.erddap.dataset.EDDGrid.DEFAULT_MATCH_AXIS_N_DIGITS; | ||
|
||
import com.cohort.array.StringArray; | ||
import com.cohort.util.SimpleException; | ||
import com.cohort.util.String2; | ||
import gov.noaa.pfel.erddap.dataset.EDD; | ||
import gov.noaa.pfel.erddap.dataset.EDDGrid; | ||
import gov.noaa.pfel.erddap.dataset.EDDGridCopy; | ||
import gov.noaa.pfel.erddap.util.EDStatic; | ||
import org.xml.sax.Attributes; | ||
import org.xml.sax.SAXException; | ||
|
||
public class EDDGridCopyHandler extends State { | ||
private StringBuilder content = new StringBuilder(); | ||
private State completeState; | ||
private String datasetID; | ||
private SaxParsingContext context; | ||
|
||
public EDDGridCopyHandler( | ||
SaxHandler saxHandler, String datasetID, State completeState, SaxParsingContext context) { | ||
super(saxHandler); | ||
this.completeState = completeState; | ||
this.datasetID = datasetID; | ||
this.context = context; | ||
} | ||
|
||
private EDDGrid tSourceEdd = null; | ||
private int tReloadEveryNMinutes = Integer.MAX_VALUE; | ||
private String tAccessibleTo = null; | ||
private String tGraphsAccessibleTo = null; | ||
private boolean tAccessibleViaWMS = true; | ||
private int tMatchAxisNDigits = DEFAULT_MATCH_AXIS_N_DIGITS; | ||
private StringArray tOnChange = new StringArray(); | ||
private String tFgdcFile = null; | ||
private String tIso19115File = null; | ||
private boolean checkSourceData = true; | ||
private boolean tFileTableInMemory = false; | ||
private String tDefaultDataQuery = null; | ||
private String tDefaultGraphQuery = null; | ||
private int tnThreads = -1; | ||
private boolean tAccessibleViaFiles = EDStatic.defaultAccessibleViaFiles; | ||
private boolean tDimensionValuesInMemory = true; | ||
private String tOnlySince = null; | ||
|
||
@Override | ||
public void startElement(String uri, String localName, String qName, Attributes attributes) | ||
throws SAXException { | ||
if (localName.equals("dataset")) { | ||
if (tSourceEdd != null) { | ||
throw new SimpleException("Cannot Have multiple Child datasets for" + datasetID); | ||
} | ||
String tType = attributes.getValue("type"); | ||
String active = attributes.getValue("active"); | ||
String childDatasetID = attributes.getValue("datasetID"); | ||
State state = | ||
HandlerFactory.getHandlerFor(tType, childDatasetID, active, this, saxHandler, context); | ||
saxHandler.setState(state); | ||
} | ||
} | ||
|
||
@Override | ||
public void characters(char[] ch, int start, int length) throws SAXException { | ||
content.append(ch, start, length); | ||
} | ||
|
||
@Override | ||
public void endElement(String uri, String localName, String qName) throws Throwable { | ||
String contentStr = content.toString().trim(); | ||
|
||
switch (localName) { | ||
case "accessibleTo" -> tAccessibleTo = contentStr; | ||
case "graphsAccessibleTo" -> tGraphsAccessibleTo = contentStr; | ||
case "accessibleViaWMS" -> tAccessibleViaWMS = String2.parseBoolean(contentStr); | ||
case "matchAxisNDigits" -> | ||
tMatchAxisNDigits = String2.parseInt(contentStr, DEFAULT_MATCH_AXIS_N_DIGITS); | ||
case "ensureAxisValuesAreEqual" -> | ||
tMatchAxisNDigits = String2.parseBoolean(contentStr) ? 20 : 0; // deprecated | ||
case "onChange" -> tOnChange.add(contentStr); | ||
case "fgdcFile" -> tFgdcFile = contentStr; | ||
case "iso19115File" -> tIso19115File = contentStr; | ||
case "reloadEveryNMinutes" -> tReloadEveryNMinutes = String2.parseInt(contentStr); | ||
case "checkSourceData" -> checkSourceData = String2.parseBoolean(contentStr); | ||
case "fileTableInMemory" -> tFileTableInMemory = String2.parseBoolean(contentStr); | ||
case "defaultDataQuery" -> tDefaultDataQuery = contentStr; | ||
case "defaultGraphQuery" -> tDefaultGraphQuery = contentStr; | ||
case "nThreads" -> tnThreads = String2.parseInt(contentStr); | ||
case "dimensionValuesInMemory" -> tDimensionValuesInMemory = String2.parseBoolean(contentStr); | ||
case "accessibleViaFiles" -> tAccessibleViaFiles = String2.parseBoolean(contentStr); | ||
case "onlySince" -> tOnlySince = contentStr; | ||
case "dataset" -> { | ||
EDD dataset = | ||
new EDDGridCopy( | ||
datasetID, | ||
tAccessibleTo, | ||
tGraphsAccessibleTo, | ||
tAccessibleViaWMS, | ||
tMatchAxisNDigits, | ||
tOnChange, | ||
tFgdcFile, | ||
tIso19115File, | ||
tDefaultDataQuery, | ||
tDefaultGraphQuery, | ||
tReloadEveryNMinutes, | ||
tSourceEdd, | ||
tFileTableInMemory, | ||
tAccessibleViaFiles, | ||
tOnlySince, | ||
tnThreads, | ||
tDimensionValuesInMemory); | ||
|
||
this.completeState.handleDataset(dataset); | ||
saxHandler.setState(this.completeState); | ||
} | ||
default -> String2.log("Unexpected end tag: " + localName); | ||
} | ||
content.setLength(0); | ||
} | ||
|
||
@Override | ||
public void handleDataset(EDD dataset) { | ||
tSourceEdd = (EDDGrid) dataset; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this throw an exception if it sees a second dataset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the old code specifies throwing an exception on getting a second child dataset,
https://github.com/ERDDAP/erddap/blob/main/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEDDTable.java#L113-L127
But I am guessing since the
tEDDTable
variable will update to the last child dataset which means there is no point in adding multiple, you are implying to add a check so that we only have one child dataset?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, add a check to make sure there's only one child dataset. Allowing multiple to be parsed could cause issues, and I think it's better to catch those early with explicit error messages.