Issue #3050 Fix SaveAsciiGridsHandler to get IFPServer instance based on site in the ParmID

Change-Id: Id2146e07f4e6103c9c96f2b09f0bae5980747052

Former-commit-id: 6f141288cae462aac8c1ea8c77dd7f88a33c382a
This commit is contained in:
Ron Anderson 2014-04-22 13:42:16 -05:00
parent 45059e722a
commit 859d709a03
2 changed files with 36 additions and 15 deletions

View file

@ -25,6 +25,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -34,6 +35,7 @@ import java.util.Scanner;
import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig;
import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager;
import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException;
import com.raytheon.edex.plugin.gfe.server.IFPServer;
import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory;
import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory.OriginType; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory.OriginType;
import com.raytheon.uf.common.dataplugin.gfe.RemapGrid; import com.raytheon.uf.common.dataplugin.gfe.RemapGrid;
@ -46,6 +48,7 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.TimeConstraints; import com.raytheon.uf.common.dataplugin.gfe.db.objects.TimeConstraints;
import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteKey; import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteKey;
import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException;
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DByte; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DByte;
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat;
import com.raytheon.uf.common.dataplugin.gfe.slice.DiscreteGridSlice; import com.raytheon.uf.common.dataplugin.gfe.slice.DiscreteGridSlice;
@ -72,6 +75,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Apr 13, 2011 #8393 dgilling Initial creation * Apr 13, 2011 #8393 dgilling Initial creation
* 02/19/13 #1637 randerso Added exception handling for Discrete and Weather * 02/19/13 #1637 randerso Added exception handling for Discrete and Weather
* 10/31/2013 #2508 randerso Change to use DiscreteGridSlice.getKeys() * 10/31/2013 #2508 randerso Change to use DiscreteGridSlice.getKeys()
* 04/22/2014 #3050 randerso Allow exceptions to propagate to caller from readASCIIGridData
* *
* </pre> * </pre>
* *
@ -353,12 +357,14 @@ public class ASCIIGrid {
} }
public String readASCIIGridData(File aGridData) public String readASCIIGridData(File aGridData)
throws FileNotFoundException { throws FileNotFoundException, GfeException, ParseException {
List<IGridSlice> gridSlices = new ArrayList<IGridSlice>(); List<IGridSlice> gridSlices = new ArrayList<IGridSlice>();
Scanner inputStream = new Scanner(aGridData, "US-ASCII");
while (true) { Scanner inputStream = null;
try { try {
inputStream = new Scanner(aGridData, "US-ASCII");
while (true) {
// read the ASCIIGRID keyword // read the ASCIIGRID keyword
// if we have an ASCIIGRID to read // if we have an ASCIIGRID to read
if (!inputStream.next().equals("ASCIIGRID")) { if (!inputStream.next().equals("ASCIIGRID")) {
@ -421,8 +427,12 @@ public class ASCIIGrid {
float yExtent = inputStream.nextFloat(); float yExtent = inputStream.nextFloat();
// make the GridLocation // make the GridLocation
IFPServerConfig config = IFPServerConfigManager IFPServer ifpServer = IFPServer.getActiveServer(dbSiteId);
.getServerConfig(dbSiteId); if (ifpServer == null) {
throw new GfeException("No active IFPServer for site: "
+ dbSiteId);
}
IFPServerConfig config = ifpServer.getConfig();
GridLocation baseGLoc = config.dbDomain(); GridLocation baseGLoc = config.dbDomain();
ProjectionData projData = config.getProjectionData(projId); ProjectionData projData = config.getProjectionData(projId);
GridLocation gLocation = new GridLocation(dbSiteId, projData, GridLocation gLocation = new GridLocation(dbSiteId, projData,
@ -600,14 +610,12 @@ public class ASCIIGrid {
if (!inputStream.hasNext()) { if (!inputStream.hasNext()) {
break; break;
} }
}
} catch (Exception e) { } finally {
statusHandler.handle(Priority.PROBLEM, if (inputStream != null) {
"Caught exception in readASCIIGridData()", e); inputStream.close();
break;
} }
} }
inputStream.close();
this.gridSlices = gridSlices; this.gridSlices = gridSlices;
return ""; return "";

View file

@ -61,6 +61,9 @@ import com.raytheon.uf.common.status.UFStatus;
* Apr 21, 2011 dgilling Initial creation * Apr 21, 2011 dgilling Initial creation
* Apr 23, 2013 1949 rjpeter Removed extra lock table look up * Apr 23, 2013 1949 rjpeter Removed extra lock table look up
* Jun 13, 2013 #2044 randerso Refactored to use IFPServer * Jun 13, 2013 #2044 randerso Refactored to use IFPServer
* Apr 21, 2014 #3050 randerso Get the IFPServer instance based on the
* site in the ParmID
*
* </pre> * </pre>
* *
* @author dgilling * @author dgilling
@ -83,9 +86,6 @@ public class SaveASCIIGridsHandler extends BaseGfeRequestHandler implements
@Override @Override
public ServerResponse<String> handleRequest(SaveASCIIGridsRequest request) public ServerResponse<String> handleRequest(SaveASCIIGridsRequest request)
throws Exception { throws Exception {
IFPServer ifpServer = getIfpServer(request);
GridParmManager gridParmMgr = ifpServer.getGridParmMgr();
LockManager lockMgr = ifpServer.getLockMgr();
ServerResponse<String> sr = new ServerResponse<String>(); ServerResponse<String> sr = new ServerResponse<String>();
@ -97,10 +97,23 @@ public class SaveASCIIGridsHandler extends BaseGfeRequestHandler implements
sr.addMessage(msg); sr.addMessage(msg);
} }
String prevSiteID = null;
int ngrids = agrid.getGridSlices().size(); int ngrids = agrid.getGridSlices().size();
for (int i = 0; i < ngrids; i++) { for (int i = 0; i < ngrids; i++) {
ParmID pid = agrid.getGridSlices().get(i).getGridInfo().getParmID(); ParmID pid = agrid.getGridSlices().get(i).getGridInfo().getParmID();
// get the server for this site
String siteID = pid.getDbId().getSiteId();
IFPServer ifpServer = IFPServer.getActiveServer(siteID);
if (ifpServer == null && !siteID.equals(prevSiteID)) {
sr.addMessage("No active IFPServer for site: " + siteID);
continue;
}
prevSiteID = siteID;
GridParmManager gridParmMgr = ifpServer.getGridParmMgr();
LockManager lockMgr = ifpServer.getLockMgr();
// get a list of available databases, see if the grid is part of an // get a list of available databases, see if the grid is part of an
// existing database. // existing database.
ServerResponse<List<DatabaseID>> srDbInv = gridParmMgr ServerResponse<List<DatabaseID>> srDbInv = gridParmMgr