Issue #3592 Fixed several localization issue in GFE

Change-Id: I2e65649d490372b5c1738f07c79b5ed15885f8c7

Former-commit-id: 6471f81a7f [formerly 57a3542038] [formerly 52e5636261] [formerly 6471f81a7f [formerly 57a3542038] [formerly 52e5636261] [formerly b91141ef7b [formerly 52e5636261 [formerly a5ef55df33009948fec139e7729dd53ae4251667]]]]
Former-commit-id: b91141ef7b
Former-commit-id: 2ff7cdc2b7 [formerly 99e223ba91] [formerly dd2d3a8470cb3ae49ca6cea84cfcaed0474acfe1 [formerly c23122797d]]
Former-commit-id: 9c8b38cb807e8fc53e55d3f54f170833cfebdb61 [formerly be55fa4984]
Former-commit-id: 6cb8a0602a
This commit is contained in:
Ron Anderson 2014-09-09 11:04:25 -05:00
parent 558702d535
commit ad9d944b4c
11 changed files with 405 additions and 218 deletions

View file

@ -100,6 +100,7 @@ import com.raytheon.viz.gfe.textformatter.TextProductManager;
* 09/05/2013 2307 dgilling Use better PythonScript constructor.
* 09/16/2013 2033 dgilling Remove unused IToolController.
* 12/09/2013 2367 dgilling Instantiate ProcedureJobPool here.
* 09/09/2014 3592 randerso Added call to SampleSetManager.dispose()
*
* </pre>
*
@ -290,6 +291,7 @@ public class DataManager {
* {@link DataManagerFactory#dispose(Object)}
*/
void dispose() {
sampleSetManager.dispose();
selectTimeRangeManager.dispose();
refManager.dispose();
parmManager.dispose();

View file

@ -25,7 +25,6 @@ import java.util.List;
import java.util.Map;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.gfe.GFEException;
import com.raytheon.viz.gfe.core.msgs.ISampleSetChangedListener;
import com.raytheon.viz.gfe.edittool.GridID;
@ -39,7 +38,8 @@ import com.vividsolutions.jts.geom.Coordinate;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 30, 2008 chammack Initial creation
* Apr 9, 2009 1288 rjpeter Added add/remove method for sample set listener
* Apr 09, 2009 1288 rjpeter Added add/remove method for sample set listener
* Sep 09, 2014 3592 randerso Added dispose method, removed networkNotification method
* </pre>
*
* @author chammack
@ -52,6 +52,11 @@ public interface ISampleSetManager {
public static final float DEFAULT_THRESHOLD = 0.0f;
/**
* Dispose the SampleSetManager
*/
public void dispose();
/**
* Returns the set of sample points for the named sample set. If the sample
* set is not known, an empty list will be returned.
@ -196,15 +201,6 @@ public interface ISampleSetManager {
*/
public boolean deleteSampleSet(final SampleId sampleId);
/**
* Input network sample notification from NetworkMgr indicating that the
* sample set inventory has changed or the contents of a sample set has
* changed.
*/
public void networkNotification(final SampleId[] anInventory,
final SampleId[] additions, final SampleId[] deletions,
final SampleId[] changes) throws VizException;
/**
* @return the loadedSet
*/

View file

@ -36,6 +36,7 @@ import com.raytheon.viz.gfe.core.internal.SampleSetManager;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 25, 2011 njensen Initial creation
* Sep 09, 2014 #3592 randerso Removed unused DataManager parameter to SampleSetManager constructor
*
* </pre>
*
@ -60,7 +61,7 @@ public class SampleSetMgrInitJob extends Job {
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
dataMgr.sampleSetManager = new SampleSetManager(dataMgr);
dataMgr.sampleSetManager = new SampleSetManager();
dataMgr.getInitStatus().setSampleSetMgrDone(true);
return Status.OK_STATUS;

View file

@ -143,6 +143,7 @@ import com.raytheon.viz.gfe.types.MutableInteger;
* 04/02/2014 #2969 randerso Fix error when Toop parm is unloaded.
* 05/01/2014 #3105 dgilling Ensure mutable db gets into availableServerDatabases
* if it has to be created during ParmManager construction.
* 09/08/2104 #3592 randerso Changed to use new pm listStaticFiles()
* </pre>
*
* @author chammack
@ -3099,11 +3100,10 @@ public class ParmManager implements IParmManager, IMessageClient {
private List<VCModule> initVirtualCalcParmDefinitions() {
// retrieve the inventory from the ifpServer
IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationFile[] modules = pathMgr
.listFiles(
pathMgr.getLocalSearchHierarchy(LocalizationType.COMMON_STATIC),
FileUtil.join("gfe", "vcmodule"),
new String[] { "py" }, false, true);
LocalizationFile[] modules = pathMgr.listStaticFiles(
LocalizationType.COMMON_STATIC,
FileUtil.join("gfe", "vcmodule"), new String[] { "py" }, false,
true);
List<VCModule> definitions = new ArrayList<VCModule>(modules.length);
for (LocalizationFile mod : modules) {
@ -3112,6 +3112,7 @@ public class ParmManager implements IParmManager, IMessageClient {
File textData = mod.getFile(true);
// create the VCModule
statusHandler.debug("Loading VCModule: " + mod);
VCModule m = new VCModule(dataManager, this, textData);
if (!m.isValid()) {
statusHandler.handle(Priority.PROBLEM,

View file

@ -109,6 +109,7 @@ import com.vividsolutions.jts.geom.Envelope;
* 06/21/2013 14983 ryu Added method for synchronous evaluation of query.
* 08/06/2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles()
* 09/30/2013 2361 njensen Use JAXBManager for XML
* 09/08/2104 #3592 randerso Changed to use new pm listStaticFiles()
*
* </pre>
*
@ -231,9 +232,8 @@ public class ReferenceSetManager implements IReferenceSetManager,
// load the complete list of edit areas
List<ReferenceID> refIDs = new ArrayList<ReferenceID>();
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext[] ctx = pm
.getLocalSearchHierarchy(LocalizationType.COMMON_STATIC);
LocalizationFile[] contents = pm.listFiles(ctx, EDIT_AREAS_DIR,
LocalizationFile[] contents = pm.listStaticFiles(
LocalizationType.COMMON_STATIC, EDIT_AREAS_DIR,
new String[] { ".xml" }, false, true);
if (contents != null) {
for (LocalizationFile lf : contents) {
@ -245,7 +245,8 @@ public class ReferenceSetManager implements IReferenceSetManager,
}
// load the edit area group lists
LocalizationFile[] groupFiles = pm.listFiles(ctx, EDIT_AREA_GROUPS_DIR,
LocalizationFile[] groupFiles = pm.listStaticFiles(
LocalizationType.COMMON_STATIC, EDIT_AREA_GROUPS_DIR,
new String[] { ".txt" }, false, true);
if (groupFiles != null) {
for (LocalizationFile lf : groupFiles) {
@ -779,8 +780,8 @@ public class ReferenceSetManager implements IReferenceSetManager,
if (lf != null) {
try {
refData = ReferenceData.getJAXBManager()
.unmarshalFromXmlFile(lf.getFile().getPath());
refData = ReferenceData.getJAXBManager().unmarshalFromXmlFile(
lf.getFile().getPath());
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error reading xml file "
@ -921,7 +922,7 @@ public class ReferenceSetManager implements IReferenceSetManager,
LocalizationFile lf = pm.getLocalizationFile(ctx,
FileUtil.join(EDIT_AREAS_DIR, refID.getName() + ".xml"));
if (lf != null
if ((lf != null)
&& (!withVerification || AccessMgr.verifyDelete(lf.getName(),
LocalizationType.COMMON_STATIC, false))) {
try {
@ -1124,7 +1125,7 @@ public class ReferenceSetManager implements IReferenceSetManager,
if (pointyTaper) {
for (i = ll.x; i <= ur.x; i++) {
for (j = ll.y; j <= ur.y; j++) {
grid.set(i, j, grid.get(i, j) * taperFactor / maxDist);
grid.set(i, j, (grid.get(i, j) * taperFactor) / maxDist);
}
}
}
@ -1192,7 +1193,7 @@ public class ReferenceSetManager implements IReferenceSetManager,
int y = j;
while ((x >= 0) && (y >= 0) && (x < dim.x) && (y < dim.y)
&& bitGrid.getAsBoolean(x, y)) {
vdist = vdist + Math.sqrt(v.x * v.x + v.y * v.y);
vdist = vdist + Math.sqrt((v.x * v.x) + (v.y * v.y));
x = x + v.x;
y = y + v.y;
}
@ -1200,11 +1201,12 @@ public class ReferenceSetManager implements IReferenceSetManager,
y = j;
while ((x >= 0) && (y >= 0) && (x < dim.x) && (y < dim.y)
&& bitGrid.getAsBoolean(x, y)) {
avdist = avdist + Math.sqrt(av.x * av.x + av.y * av.y);
avdist = avdist
+ Math.sqrt((av.x * av.x) + (av.y * av.y));
x = x + av.x;
y = y + av.y;
}
if (vdist + avdist == 0) {
if ((vdist + avdist) == 0) {
grid.set(i, j, 0.0f);
} else {
grid.set(i, j, (float) (vdist / (vdist + avdist)));
@ -1352,7 +1354,7 @@ public class ReferenceSetManager implements IReferenceSetManager,
/**
* @param ref
* @param mode2
* @param mode
*/
private void setRefSet(ReferenceData ref, RefSetMode mode) {
mode = determineMode(mode);
@ -1383,7 +1385,7 @@ public class ReferenceSetManager implements IReferenceSetManager,
}
/**
* @param mode2
* @param mode
* @return
*/
private RefSetMode determineMode(RefSetMode mode) {
@ -1666,7 +1668,7 @@ public class ReferenceSetManager implements IReferenceSetManager,
LocalizationFile lf = PathManagerFactory.getPathManager()
.getStaticLocalizationFile(filePath);
if (lf != null && lf.exists()) {
if ((lf != null) && lf.exists()) {
changes.add(refId);
} else {
deletions.add(refId);
@ -1718,7 +1720,7 @@ public class ReferenceSetManager implements IReferenceSetManager,
.getFileName());
// if it exists, load it
if (lf != null && lf.exists()) {
if ((lf != null) && lf.exists()) {
loadGroup(lf);
}
checkGroupConsistency();
@ -1824,7 +1826,7 @@ public class ReferenceSetManager implements IReferenceSetManager,
Date spedTime = dataManager.getSpatialDisplayManager()
.getSpatialEditorTime();
if (spedTime != null && msg.getTimeRange().contains(spedTime)) {
if ((spedTime != null) && msg.getTimeRange().contains(spedTime)) {
evaluateActiveRefSet(listener);
}
}

View file

@ -22,6 +22,7 @@ package com.raytheon.viz.gfe.core.internal;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -33,6 +34,8 @@ import org.geotools.referencing.GeodeticCalculator;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleData;
import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.uf.common.localization.FileUpdatedMessage;
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
@ -47,10 +50,8 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.util.FileUtil;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.gfe.Activator;
import com.raytheon.viz.gfe.GFEException;
import com.raytheon.viz.gfe.core.DataManager;
import com.raytheon.viz.gfe.core.ISampleSetManager;
import com.raytheon.viz.gfe.core.msgs.ISampleSetChangedListener;
import com.raytheon.viz.gfe.edittool.GridID;
@ -68,13 +69,15 @@ import com.vividsolutions.jts.geom.Coordinate;
* Apr 9, 2009 1288 rjpeter Added ISampleSetChangedListener handling.
* Aug 6, 2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles()
* Sep 30, 2013 2361 njensen Use JAXBManager for XML
* Sep 08, 2104 #3592 randerso Changed to use new pm listStaticFiles()
* </pre>
*
* @author rbell
* @version 1.0
*/
public class SampleSetManager implements ISampleSetManager {
public class SampleSetManager implements ISampleSetManager,
ILocalizationFileObserver {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(SampleSetManager.class);
@ -91,19 +94,20 @@ public class SampleSetManager implements ISampleSetManager {
private Map<String, List<Coordinate>> markerLocations;
private final DataManager dataManager;
private final Set<ISampleSetChangedListener> sampleSetChangedListeners;
private boolean showLatLon;
private IPathManager pathManager;
private LocalizationFile sampleSetDir;
/**
* Default constructor.
*
* Gets the initial sample inventory.
*/
public SampleSetManager(DataManager dataManager) {
this.dataManager = dataManager;
public SampleSetManager() {
this.loadedSet = new SampleId();
this.inventory = new HashSet<SampleId>();
@ -114,17 +118,23 @@ public class SampleSetManager implements ISampleSetManager {
this.sampleSetChangedListeners = new HashSet<ISampleSetChangedListener>();
IPathManager pm = PathManagerFactory.getPathManager();
this.pathManager = PathManagerFactory.getPathManager();
LocalizationFile[] files = pm.listFiles(
pm.getLocalSearchHierarchy(LocalizationType.COMMON_STATIC),
SAMPLE_SETS_DIR, new String[] { ".xml" }, true, true);
this.sampleSetDir = pathManager.getLocalizationFile(pathManager
.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.BASE), SAMPLE_SETS_DIR);
// initialize the inventory
LocalizationFile[] files = pathManager.listStaticFiles(
LocalizationType.COMMON_STATIC, SAMPLE_SETS_DIR,
new String[] { ".xml" }, true, true);
for (LocalizationFile file : files) {
String fn = LocalizationUtil.extractName(file.getName()).replace(
".xml", "");
this.inventory.add(new SampleId(fn));
}
this.sampleSetDir.addFileUpdatedObserver(this);
// load default sample points
String[] sampleSets = Activator.getDefault().getPreferenceStore()
@ -133,24 +143,22 @@ public class SampleSetManager implements ISampleSetManager {
for (String id : sampleSets) {
SampleId sid = new SampleId(id);
if (this.inventory.contains(sid)) {
try {
loadSampleSet(sid, SampleSetLoadMode.ADD);
} catch (GFEException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
loadSampleSet(sid, SampleSetLoadMode.ADD);
}
}
}
// get initial marker points
try {
getMarkerPoints();
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to get initial sampleset marker points", e);
}
getMarkerPoints();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#dispose()
*/
@Override
public void dispose() {
this.sampleSetDir.removeFileUpdatedObserver(this);
}
/*
@ -160,8 +168,8 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#sampleSetLocations(java.lang
* .String)
*/
public List<Coordinate> sampleSetLocations(final String setName)
throws GFEException {
@Override
public List<Coordinate> sampleSetLocations(final String setName) {
// verify set in inventory
boolean found = false;
for (SampleId thisId : this.inventory) {
@ -172,9 +180,10 @@ public class SampleSetManager implements ISampleSetManager {
}
if (!found) {
throw new GFEException(
"Attempt to get locations for unknown sample set ["
statusHandler
.error("Attempt to get locations for unknown sample set ["
+ setName + "]");
return Collections.emptyList();
}
String fileName = FileUtil.join(SAMPLE_SETS_DIR, setName + ".xml");
@ -187,9 +196,9 @@ public class SampleSetManager implements ISampleSetManager {
f = file.getFile(true);
} catch (LocalizationException e) {
if (f == null) {
throw new GFEException(
"An error occurred retrieving SampleSet: " + fileName,
e);
statusHandler.error("An error occurred retrieving SampleSet: "
+ fileName, e);
return Collections.emptyList();
}
}
@ -198,7 +207,8 @@ public class SampleSetManager implements ISampleSetManager {
sampleData = SampleData.getJAXBManager().unmarshalFromXmlFile(
f.getAbsolutePath());
} catch (Exception e) {
throw new GFEException("Unable to load sampledata: " + f, e);
statusHandler.error("Unable to load sampledata: " + f, e);
return Collections.emptyList();
}
return sampleData.getPoints();
@ -212,8 +222,9 @@ public class SampleSetManager implements ISampleSetManager {
* .edex.plugin.gfe.sample.SampleId,
* com.raytheon.viz.gfe.core.internal.SampleSetManager.SampleSetLoadMode)
*/
@Override
public void loadSampleSet(final SampleId sampleId,
SampleSetLoadMode loadMode) throws GFEException {
SampleSetLoadMode loadMode) {
File f = PathManagerFactory.getPathManager().getStaticFile(
FileUtil.join(SAMPLE_SETS_DIR, sampleId.getName() + ".xml"));
@ -221,8 +232,9 @@ public class SampleSetManager implements ISampleSetManager {
try {
sampleData = SampleData.getJAXBManager().unmarshalFromXmlFile(
f.getPath());
sampleData.setSampleId(sampleId);
} catch (Exception e) {
throw new GFEException("Unable to load sampledata: " + f);
statusHandler.error("Unable to load sampledata: " + f);
}
// set the loadedSet flag appropriately
@ -247,6 +259,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#clearSamples()
*/
@Override
public void clearSamples() {
mergeSamples(new ArrayList<Coordinate>(), SampleSetLoadMode.REPLACE);
this.loadedSet = new SampleId(); // no loaded set
@ -260,6 +273,7 @@ public class SampleSetManager implements ISampleSetManager {
* @seecom.raytheon.viz.gfe.core.ISampleSetManager#addAnchoredSample(com.
* vividsolutions.jts.geom.Coordinate)
*/
@Override
public void addAnchoredSample(final Coordinate sampleLocation) {
mergeSamples(Arrays.asList(sampleLocation), SampleSetLoadMode.ADD);
this.loadedSet = new SampleId(); // no longer a loaded set
@ -274,6 +288,7 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#removeAnchoredSample(com.
* vividsolutions.jts.geom.Coordinate)
*/
@Override
public void removeAnchoredSample(final Coordinate sampleLocation) {
removeAnchoredSample(sampleLocation,
ISampleSetManager.DEFAULT_THRESHOLD);
@ -286,6 +301,7 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#removeAnchoredSample(com.
* vividsolutions.jts.geom.Coordinate, float)
*/
@Override
public void removeAnchoredSample(final Coordinate sampleLocation,
float threshold) {
mergeSamples(Arrays.asList(sampleLocation), SampleSetLoadMode.REMOVE,
@ -301,6 +317,7 @@ public class SampleSetManager implements ISampleSetManager {
* @seecom.raytheon.viz.gfe.core.ISampleSetManager#addAnchoredMarker(com.
* vividsolutions.jts.geom.Coordinate)
*/
@Override
public void addAnchoredMarker(final Coordinate location, final GridID gid) {
String set = activeMarkerSet(gid);
List<Coordinate> locations = markerLocations.get(set);
@ -319,6 +336,7 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#removeAnchoredMarker(com.
* vividsolutions.jts.geom.Coordinate)
*/
@Override
public void removeAnchoredMarker(final Coordinate location, final GridID gid) {
removeAnchoredMarker(location, gid, ISampleSetManager.DEFAULT_THRESHOLD);
}
@ -330,6 +348,7 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#removeAnchoredMarker(com.
* vividsolutions.jts.geom.Coordinate, float)
*/
@Override
public void removeAnchoredMarker(final Coordinate location,
final GridID gid, float threshold) {
boolean found = false;
@ -361,6 +380,7 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#anchoredMarkerAtLocation(
* com.vividsolutions.jts.geom.Coordinate, float)
*/
@Override
public boolean anchoredMarkerAtLocation(final Coordinate location,
final GridID gid, float threshold) {
String set = activeMarkerSet(gid);
@ -388,6 +408,7 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#saveSampleSet(com.vividsolutions
* .jts.geom.Coordinate[], com.raytheon.edex.plugin.gfe.sample.SampleId)
*/
@Override
public boolean saveSampleSet(final List<Coordinate> sampleLocations,
final SampleId sampleId) {
@ -413,13 +434,6 @@ public class SampleSetManager implements ISampleSetManager {
e);
}
this.inventory.add(sampleId);
// // send a notification to interested users
// networkNotification(notification.inventory(),
// notification.additions(),
// notification.deletions(), notification.changes());
return true;
}
@ -430,6 +444,7 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#saveActiveSampleSet(com.raytheon
* .edex.plugin.gfe.sample.SampleId)
*/
@Override
public boolean saveActiveSampleSet(final SampleId sampleId) {
this.loadedSet = sampleId;
return saveSampleSet(this.locations, sampleId);
@ -442,6 +457,7 @@ public class SampleSetManager implements ISampleSetManager {
* com.raytheon.viz.gfe.core.ISampleSetManager#deleteSampleSet(com.raytheon
* .edex.plugin.gfe.sample.SampleId)
*/
@Override
public boolean deleteSampleSet(final SampleId sampleId) {
LocalizationFile file = PathManagerFactory.getPathManager()
.getStaticLocalizationFile(
@ -458,7 +474,6 @@ public class SampleSetManager implements ISampleSetManager {
try {
file.delete();
this.inventory.remove(sampleId);
} catch (LocalizationOpFailedException e) {
statusHandler.handle(Priority.PROBLEM,
"Error deleting from localization server", e);
@ -471,69 +486,55 @@ public class SampleSetManager implements ISampleSetManager {
* (non-Javadoc)
*
* @see
* com.raytheon.viz.gfe.core.ISampleSetManager#networkNotification(com.raytheon
* .edex.plugin.gfe.sample.SampleId[],
* com.raytheon.edex.plugin.gfe.sample.SampleId[],
* com.raytheon.edex.plugin.gfe.sample.SampleId[],
* com.raytheon.edex.plugin.gfe.sample.SampleId[])
* com.raytheon.uf.common.localization.ILocalizationFileObserver#fileUpdated
* (com.raytheon.uf.common.localization.FileUpdatedMessage)
*/
public void networkNotification(final SampleId[] anInventory,
final SampleId[] additions, final SampleId[] deletions,
final SampleId[] changes) throws VizException {
@Override
public void fileUpdated(FileUpdatedMessage message) {
// logDebug << "NetworkNotification newInv=" << anInventory
// << " add=" << additions << " del=" << deletions << " chg="
// << changes << std::endl;
// logDebug << "OldInventory=" << anInventory << std::endl;
// logDebug << "Active loaded set=" << _loadedSet << std::endl;
String name = LocalizationUtil.extractName(message.getFileName())
.replace(".xml", "");
SampleId id = new SampleId(name);
// store the new inventory
this.inventory = new HashSet<SampleId>(Arrays.asList(anInventory));
switch (message.getChangeType()) {
case ADDED:
case UPDATED:
this.inventory.add(id);
// loaded sample set changed?, check by name field for a match
for (SampleId changesId : changes) {
if (changesId.getName().equals(this.loadedSet.getName())) {
// logDebug << "LoadedSampleSet changed " << _loadedSet <<
// std::endl;
loadSampleSet(changesId, SampleSetLoadMode.REPLACE);
// loaded sample set "added", may simply be a rename
if (id.getName().equals(this.loadedSet.getName())) {
loadSampleSet(id, SampleSetLoadMode.REPLACE);
}
if (changesId.getName().equals(SampleSetManager.MARKER_NAME)) {
// logDebug << "MarkerSet changed " << changesId << std::endl;
if (id.getName().equals(SampleSetManager.MARKER_NAME)) {
getMarkerPoints();
}
}
break;
// loaded sample set deleted?
for (SampleId deletionsId : deletions) {
if (deletionsId.getName().equals(this.loadedSet.getName())) {
// logDebug << "LoadedSampleSet deleted " << _loadedSet
// << ' ' << deletionsId << std::endl;
this.loadedSet = new SampleId();
case DELETED:
LocalizationFile[] files = pathManager.listStaticFiles(
LocalizationType.COMMON_STATIC, message.getFileName(),
new String[] { ".xml" }, false, true);
if (id.getName().equals(this.loadedSet.getName())) {
if (files.length > 0) {
loadSampleSet(id, SampleSetLoadMode.REPLACE);
} else {
this.inventory.remove(id);
this.loadedSet = new SampleId();
}
}
if (deletionsId.getName().equals(SampleSetManager.MARKER_NAME)) {
// logDebug << "MarkerSet deleted " << deletionsId << std::endl;
if (id.getName().equals(SampleSetManager.MARKER_NAME)) {
getMarkerPoints();
}
break;
default:
statusHandler.error("Unexpected FileChangeType received: "
+ message.getChangeType().name());
break;
}
// loaded sample set "added", may simply be a rename
for (SampleId additionsId : additions) {
if (additionsId.getName().equals(this.loadedSet.getName())) {
// logDebug << "LoadedSampleSet added " << _loadedSet
// << " " << additionsId << std::endl;
loadSampleSet(additionsId, SampleSetLoadMode.REPLACE);
}
if (additionsId.getName().equals(SampleSetManager.MARKER_NAME)) {
// logDebug << "MarkerSet added " << additionsId << std::endl;
getMarkerPoints();
}
}
// inventory changed?
if ((additions.length > 0) || (deletions.length > 0)
|| (changes.length > 0)) {
}
// logDebug << "Active set is now: " << _loadedSet << std::endl;
fireSampleSetChangedListeners();
}
@ -603,7 +604,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* Gets the set of points, sends out notification of changes.
*/
private void getMarkerPoints() throws VizException {
private void getMarkerPoints() {
// ensure it is in the inventory
this.markerLocations.clear();
@ -621,6 +622,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#getLoadedSet()
*/
@Override
public SampleId getLoadedSet() {
return this.loadedSet;
}
@ -630,6 +632,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#getInventory()
*/
@Override
public SampleId[] getInventory() {
return this.inventory.toArray(new SampleId[this.inventory.size()]);
}
@ -639,6 +642,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#getInventoryAsList()
*/
@Override
public ArrayList<SampleId> getInventoryAsList() {
ArrayList<SampleId> ids = new ArrayList<SampleId>();
for (SampleId id : this.inventory) {
@ -652,6 +656,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#getInventoryAsStrings()
*/
@Override
public String[] getInventoryAsStrings() {
String[] retVal = new String[this.inventory.size()];
int i = 0;
@ -663,6 +668,7 @@ public class SampleSetManager implements ISampleSetManager {
return retVal;
}
@Override
public String activeMarkerSet(GridID gid) {
// get office type from GridID
String ot = gid.getParm().getOfficeType();
@ -678,6 +684,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#getLocations()
*/
@Override
public List<Coordinate> getLocations() {
return new ArrayList<Coordinate>(this.locations);
}
@ -687,6 +694,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#getMarkerLocations()
*/
@Override
public Map<String, List<Coordinate>> getMarkerLocations() {
return this.markerLocations;
}
@ -696,6 +704,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#isShowLatLon()
*/
@Override
public boolean isShowLatLon() {
return showLatLon;
}
@ -705,6 +714,7 @@ public class SampleSetManager implements ISampleSetManager {
*
* @see com.raytheon.viz.gfe.core.ISampleSetManager#setShowLatLon(boolean)
*/
@Override
public void setShowLatLon(boolean showLatLon) {
this.showLatLon = showLatLon;
fireSampleSetChangedListeners();

View file

@ -22,15 +22,15 @@ package com.raytheon.viz.gfe.core.internal;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import com.raytheon.uf.common.dataplugin.gfe.time.SelectTimeRange;
import com.raytheon.uf.common.dataplugin.gfe.time.SelectTimeRange.Mode;
@ -62,6 +62,7 @@ import com.raytheon.viz.gfe.core.msgs.SelectTimeRangesChangedMsg;
* Dec 3, 2009 #3135 randerso Initial creation
* Aug 1, 2012 #965 dgilling Change location of SelectTimeRange.
* Aug 6, 2013 #1561 njensen Use pm.listFiles() instead of pm.listStaticFiles()
* Sep 8, 2104 #3592 randerso Changed to use new pm listStaticFiles()
*
* </pre>
*
@ -78,23 +79,17 @@ public class SelectTimeRangeManager implements ISelectTimeRangeManager,
private static final String FILE_EXT = ".SELECTTR";
private static final IPathManager pathManager = PathManagerFactory
.getPathManager();
private static final TimeZone ZULU = TimeZone.getTimeZone("GMT");
protected DataManager dataManager;
private IPathManager pathManager;
private TimeZone timeZone;
private String[] inventory;
private Map<String, SelectTimeRange> rangeMap;
private LocalizationFile selectTRDir;
public SelectTimeRangeManager(DataManager dataManager) {
this.dataManager = dataManager;
// Find the referenced time zone
timeZone = TimeZone.getTimeZone("GMT");
try {
@ -105,13 +100,13 @@ public class SelectTimeRangeManager implements ISelectTimeRangeManager,
"Unable to retrieve GFE time zone, using GMT", e);
}
IPathManager pathMgr = PathManagerFactory.getPathManager();
selectTRDir = pathMgr.getLocalizationFile(pathMgr.getContext(
this.pathManager = PathManagerFactory.getPathManager();
selectTRDir = pathManager.getLocalizationFile(pathManager.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE),
FILE_PATH);
selectTRDir.addFileUpdatedObserver(this);
fileUpdated(null);
loadInventory();
}
@Override
@ -123,15 +118,17 @@ public class SelectTimeRangeManager implements ISelectTimeRangeManager,
@Override
public String[] inventory() {
String[] inventory = this.rangeMap.keySet().toArray(
new String[this.rangeMap.size()]);
return inventory;
}
private SelectTimeRange loadTimeRange(LocalizationFile lf) {
File file = lf.getFile();
String rangeName = rangeNameFromFileName(lf.getName());
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
in = new BufferedReader(new InputStreamReader(lf.openInputStream()));
String[] s = in.readLine().split("\\s+");
int start = Integer.parseInt(s[0]);
int end = Integer.parseInt(s[1]);
@ -140,21 +137,22 @@ public class SelectTimeRangeManager implements ISelectTimeRangeManager,
mode = Mode.values()[Integer.parseInt(s[2])];
}
SelectTimeRange range = new SelectTimeRange(FileUtil.unmangle(file
.getName().replace(FILE_EXT, "")), start, end, mode, lf
.getContext().getLocalizationLevel(),
SelectTimeRange range = new SelectTimeRange(rangeName, start, end,
mode, lf.getContext().getLocalizationLevel(),
(mode.equals(Mode.ZULU) ? ZULU : timeZone));
return range;
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error reading SELECTTR file " + file.getAbsolutePath(), e);
"Error reading SELECTTR file "
+ lf.getFile().getAbsolutePath(), e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM,
"Error closing file " + file.getAbsolutePath(), e);
"Error closing file "
+ lf.getFile().getAbsolutePath(), e);
}
}
}
@ -173,22 +171,26 @@ public class SelectTimeRangeManager implements ISelectTimeRangeManager,
LocalizationLevel.USER), FileUtil.join(FILE_PATH,
FileUtil.mangle(name) + FILE_EXT));
File file = lf.getFile();
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(file));
out = new BufferedWriter(new OutputStreamWriter(
lf.openOutputStream()));
out.write(String.format("%d %d %d", start, end, mode.ordinal()));
out.close();
out = null;
lf.save();
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error writing SELECTTR file " + file.getAbsolutePath(), e);
"Error writing SELECTTR file "
+ lf.getFile().getAbsolutePath(), e);
} finally {
try {
out.close();
if (out != null) {
out.close();
}
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM, "Error closing file "
+ file.getAbsolutePath(), e);
+ lf.getFile().getAbsolutePath(), e);
}
}
}
@ -210,9 +212,48 @@ public class SelectTimeRangeManager implements ISelectTimeRangeManager,
@Override
public void fileUpdated(FileUpdatedMessage message) {
LocalizationFile[] files = pathManager.listFiles(pathManager
.getLocalSearchHierarchy(LocalizationType.COMMON_STATIC),
FILE_PATH, new String[] { FILE_EXT }, false, true);
SelectTimeRange range;
switch (message.getChangeType()) {
case ADDED:
case UPDATED:
LocalizationFile lf = pathManager.getLocalizationFile(
message.getContext(), message.getFileName());
range = loadTimeRange(lf);
if (range != null) {
this.rangeMap.put(range.getName(), range);
}
break;
case DELETED:
LocalizationFile[] files = pathManager.listStaticFiles(
LocalizationType.COMMON_STATIC, message.getFileName(),
new String[] { FILE_EXT }, false, true);
if (files.length > 0) {
range = loadTimeRange(files[0]); // should only be one
if (range != null) {
this.rangeMap.put(range.getName(), range);
}
} else {
String rangeName = rangeNameFromFileName(message.getFileName());
this.rangeMap.remove(rangeName);
}
break;
default:
statusHandler.error("Unexpected FileChangeType received: "
+ message.getChangeType().name());
break;
}
new SelectTimeRangesChangedMsg().send();
}
private void loadInventory() {
LocalizationFile[] files = pathManager.listStaticFiles(
LocalizationType.COMMON_STATIC, FILE_PATH,
new String[] { FILE_EXT }, false, true);
List<SelectTimeRange> ranges = new ArrayList<SelectTimeRange>(
files.length);
@ -224,19 +265,22 @@ public class SelectTimeRangeManager implements ISelectTimeRangeManager,
}
Collections.sort(ranges);
String[] inv = new String[ranges.size()];
Map<String, SelectTimeRange> map = new HashMap<String, SelectTimeRange>();
int i = 0;
Map<String, SelectTimeRange> map = new TreeMap<String, SelectTimeRange>();
for (SelectTimeRange range : ranges) {
inv[i++] = range.getName();
map.put(range.getName(), range);
}
synchronized (this) {
this.inventory = inv;
this.rangeMap = map;
}
new SelectTimeRangesChangedMsg().send();
}
private String rangeNameFromFileName(String fileName) {
File file = new File(fileName);
String rangeName = FileUtil.unmangle(file.getName().replace(FILE_EXT,
""));
return rangeName;
}
}

View file

@ -72,6 +72,8 @@ import com.raytheon.viz.gfe.textformatter.CombinationsFileUtil.ComboData.Entry;
* Sep 30, 2013 2361 njensen Use JAXBManager for XML
* Feb 05, 2014 #2591 randerso Forced retrieval of combinations file
* Implemented retry on error
* Sep 08, 2104 #3592 randerso Changed to use only list site level files as all
* combo files are saved to the site level
*
* </pre>
*
@ -138,8 +140,8 @@ public class CombinationsFileUtil {
public static LocalizationFile[] getSavedCombos() {
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationFile[] combos = pm.listFiles(
pm.getLocalSearchHierarchy(LocalizationType.CAVE_STATIC),
LocalizationFile[] combos = pm.listFiles(pm.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.SITE),
SAVED_COMBO_DIR, new String[] { ".xml" }, false, true);
return combos;
@ -222,8 +224,9 @@ public class CombinationsFileUtil {
IPathManager pm = PathManagerFactory.getPathManager();
// retrieve combinations file if it's changed
LocalizationFile lf = pm.getStaticLocalizationFile(FileUtil.join(
COMBO_DIR_PATH, comboName + ".py"));
LocalizationFile lf = pm.getStaticLocalizationFile(
LocalizationType.CAVE_STATIC,
FileUtil.join(COMBO_DIR_PATH, comboName + ".py"));
File pyFile = null;
if (lf != null) {
try {
@ -234,7 +237,7 @@ public class CombinationsFileUtil {
}
}
if (pyFile == null || !pyFile.exists()) {
if ((pyFile == null) || !pyFile.exists()) {
return Collections.emptyList();
}
@ -250,24 +253,24 @@ public class CombinationsFileUtil {
map.put("comboName", comboName);
PythonScript python = null;
for (int retryCount = 0; retryCount < MAX_TRIES; retryCount++) {
try {
try {
python = new PythonScript(scriptPath,
PyUtil.buildJepIncludePath(
GfePyIncludeUtil.getCombinationsIncludePath(),
GfePyIncludeUtil.getCommonPythonIncludePath()),
CombinationsFileUtil.class.getClassLoader());
GfePyIncludeUtil.getCombinationsIncludePath(),
GfePyIncludeUtil.getCommonPythonIncludePath()),
CombinationsFileUtil.class.getClassLoader());
Object com = python.execute("getCombinations", map);
combos = (List<List<String>>) com;
Object com = python.execute("getCombinations", map);
combos = (List<List<String>>) com;
// if successfully retrieved break out of the loop
break;
} catch (JepException e) {
} catch (JepException e) {
// remove the .pyo file
new File(pyFile.getAbsolutePath() + "o").delete();
// if not last try, log and try again
if (retryCount < MAX_TRIES - 1) {
if (retryCount < (MAX_TRIES - 1)) {
// log but don't pop up
statusHandler.handle(Priority.EVENTB,
"Error loading combinations file: " + comboName
@ -275,15 +278,15 @@ public class CombinationsFileUtil {
}
// else throw exception
else {
throw new GfeException("Error loading combinations file: "
+ comboName, e);
throw new GfeException("Error loading combinations file: "
+ comboName, e);
}
} finally {
if (python != null) {
python.dispose();
}
} finally {
if (python != null) {
python.dispose();
}
}
}
return combos;
}

View file

@ -49,6 +49,7 @@ import com.raytheon.uf.common.util.FileUtil;
* Jul 24, 2012 dgilling Initial creation
* Aug 07, 2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles()
* Sep 30, 2013 2361 njensen Use JAXBManager for XML
* Sep 08, 2104 3592 randerso Changed to use new pm listStaticFiles()
*
* </pre>
*
@ -81,9 +82,9 @@ public class ReferenceMgr {
public ServerResponse<List<ReferenceID>> getInventory() {
List<ReferenceID> refIDs = new ArrayList<ReferenceID>();
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationFile[] contents = pm.listFiles(
pm.getLocalSearchHierarchy(LocalizationType.COMMON_STATIC),
EDIT_AREAS_DIR, new String[] { ".xml" }, false, true);
LocalizationFile[] contents = pm.listStaticFiles(
LocalizationType.COMMON_STATIC, EDIT_AREAS_DIR,
new String[] { ".xml" }, false, true);
if (contents != null) {
for (LocalizationFile lf : contents) {
String s = LocalizationUtil.extractName(lf.getName());
@ -116,7 +117,8 @@ public class ReferenceMgr {
// process each ReferenceID requested
for (ReferenceID id : ids) {
String path = FileUtil.join(EDIT_AREAS_DIR, id.getName() + ".xml");
LocalizationFile lf = pathMgr.getStaticLocalizationFile(path);
LocalizationFile lf = pathMgr.getStaticLocalizationFile(
LocalizationType.COMMON_STATIC, path);
// does it exist?
if (lf == null) {
@ -129,8 +131,8 @@ public class ReferenceMgr {
// open and read the file
ReferenceData refData = null;
try {
refData = ReferenceData.getJAXBManager()
.unmarshalFromXmlFile(lf.getFile().getPath());
refData = ReferenceData.getJAXBManager().unmarshalFromXmlFile(
lf.getFile().getPath());
} catch (Exception e) {
sr.addMessage("Unable to read reference data [" + id + "]");
data = Collections.emptyList();

View file

@ -41,6 +41,10 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 02/12/2008 chammack Initial Creation.
* Sep 08, 2014 3592 randerso Added single type listStaticFiles,
* getStaticLocalizationFile, and getStaticFile APIs
* Improved JavaDoc for all listStaticFiles,
* getStaticLocalizationFile, and getStaticFile APIs.
*
* </pre>
*
@ -49,13 +53,16 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
*/
public interface IPathManager {
/**
* Directory separator used by Localization
*/
public static final String SEPARATOR = "/";
/**
*
* Checks the localization hierarchy for a static file
*
* First searches user, then site and finally base to find the file.
* Finds the specified file in any applicable LocalizationType. Note: If the
* same file exists in multiple localization levels, only the lowest level
* version of the file will be returned.
*
* Returns null if file is not found.
*
@ -63,13 +70,30 @@ public interface IPathManager {
* the name of the file to search for
* @return a pointer to the location on the filesystem
*/
public abstract File getStaticFile(String name);
public File getStaticFile(String name);
/**
*
* Checks the localization hierarchy for a static file
* Finds the specified file in the specified LocalizationType. Note: If the
* same file exists in multiple localization levels, only the lowest level
* version of the file will be returned.
*
* First searches user, then site and finally base to find the file.
* Returns null if file is not found.
*
* @param type
* LocalizationType of file to be found
*
* @param name
* the name of the file to search for
* @return a pointer to the location on the filesystem
*/
public File getStaticFile(LocalizationType type, String name);
/**
*
* Finds the specified file in any applicable LocalizationType. Note: If the
* same file exists in multiple localization levels, only the lowest level
* version of the file will be returned.
*
* Returns null if file is not found.
*
@ -77,7 +101,25 @@ public interface IPathManager {
* the name of the file to search for
* @return the file and the context it was found in
*/
public abstract LocalizationFile getStaticLocalizationFile(String name);
public LocalizationFile getStaticLocalizationFile(String name);
/**
*
* Finds the specified file in the specified LocalizationType. Note: If the
* same file exists in multiple localization levels, only the lowest level
* version of the file will be returned.
*
* Returns null if file is not found.
*
* @param type
* LocalizationType of file to be found
*
* @param name
* the name of the file to search for
* @return the file and the context it was found in
*/
public LocalizationFile getStaticLocalizationFile(LocalizationType type,
String name);
/**
*
@ -89,7 +131,7 @@ public interface IPathManager {
* the filename to search
* @return an absolute pointer on the filesystem to the file
*/
public abstract File getFile(LocalizationContext context, String name);
public File getFile(LocalizationContext context, String name);
/**
*
@ -101,8 +143,8 @@ public interface IPathManager {
* the filename to search
* @return an absolute pointer on the filesystem to the file
*/
public abstract LocalizationFile getLocalizationFile(
LocalizationContext context, String name);
public LocalizationFile getLocalizationFile(LocalizationContext context,
String name);
/**
* Returns a map containing a LocalizationFile for each LocalizationLevel
@ -114,11 +156,13 @@ public interface IPathManager {
* the localization file name
* @return map of LocalizationLevel to LocalizationFile
*/
public abstract Map<LocalizationLevel, LocalizationFile> getTieredLocalizationFile(
public Map<LocalizationLevel, LocalizationFile> getTieredLocalizationFile(
LocalizationType type, String name);
/**
* Lists files in the directory
* Lists all files in the localization hierarchy for the specified directory
* Note: If the same file exists in multiple localization levels, all
* versions of the file will be returned in the array.
*
* @param context
* the localization context to use
@ -134,12 +178,14 @@ public interface IPathManager {
* directories
* @return the files on the filesystem in the directory
*/
public abstract LocalizationFile[] listFiles(LocalizationContext context,
public LocalizationFile[] listFiles(LocalizationContext context,
String name, String[] extensions, boolean recursive,
boolean filesOnly);
/**
* Lists files in the directory
* Lists all files in the localization hierarchy for the specified directory
* Note: If the same file exists in multiple localization levels, all
* versions of the file will be returned in the array.
*
* @param contexts
* the localization contexts to search
@ -156,9 +202,9 @@ public interface IPathManager {
* @return the files on the filesystem in the directory or null in case of
* error
*/
public abstract LocalizationFile[] listFiles(
LocalizationContext[] contexts, String name, String[] extensions,
boolean recursive, boolean filesOnly);
public LocalizationFile[] listFiles(LocalizationContext[] contexts,
String name, String[] extensions, boolean recursive,
boolean filesOnly);
/**
* Lists all files in all localization contexts in a particular directory.
@ -177,8 +223,32 @@ public interface IPathManager {
* directories
* @return a list of files
*/
public abstract LocalizationFile[] listStaticFiles(String name,
String[] extensions, boolean recursive, boolean filesOnly);
public LocalizationFile[] listStaticFiles(String name, String[] extensions,
boolean recursive, boolean filesOnly);
/**
* Lists all files in the specified LocalizationType in a particular
* directory. Note: If the same file exists in multiple localization levels,
* only the lowest level version of the file will be returned in the array.
*
* @param type
* the localization type to use
*
* @param name
* the directory to look in
* @param extensions
* a list of file extensions to look for, or null if no filter
* @param recursive
* true for recursive directory listing, false for a single level
* listing
* @param filesOnly
* true if only files are listed, false to list both files and
* directories
* @return a list of files
*/
public LocalizationFile[] listStaticFiles(LocalizationType type,
String name, String[] extensions, boolean recursive,
boolean filesOnly);
/**
* Returns a localization context for the given type and level for the
@ -188,7 +258,7 @@ public interface IPathManager {
* @param level
* @return the localization context
*/
public abstract LocalizationContext getContext(LocalizationType type,
public LocalizationContext getContext(LocalizationType type,
LocalizationLevel level);
/**
@ -198,8 +268,8 @@ public interface IPathManager {
* @param siteId
* @return the site localization context
*/
public abstract LocalizationContext getContextForSite(
LocalizationType type, String siteId);
public LocalizationContext getContextForSite(LocalizationType type,
String siteId);
/**
* Return the localization contexts that should be searched given a
@ -209,16 +279,16 @@ public interface IPathManager {
* the type
* @return the localization contexts
*/
public abstract LocalizationContext[] getLocalSearchHierarchy(
public LocalizationContext[] getLocalSearchHierarchy(
LocalizationContext.LocalizationType type);
/**
* Get the available context strings for the given level
*
* @param level
* @return
* @return the available contexts
*/
public abstract String[] getContextList(LocalizationLevel level);
public String[] getContextList(LocalizationLevel level);
/**
* Returns the available levels to be used, sorted from lowest search level
@ -226,5 +296,5 @@ public interface IPathManager {
*
* @return Available sorted levels
*/
public abstract LocalizationLevel[] getAvailableLevels();
public LocalizationLevel[] getAvailableLevels();
}

View file

@ -55,6 +55,8 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* ------------ ---------- ----------- --------------------------
* 02/12/2008 chammack Initial Creation.
* Oct 23, 2012 1322 djohnson Allow test code in the same package to clear fileCache.
* Sep 08, 2014 3592 randerso Added single type listStaticFiles,
* getStaticLocalizationFile, and getStaticFile APIs
*
* </pre>
*
@ -63,8 +65,8 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
*/
public class PathManager implements IPathManager {
private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(PathManager.class, "Localization");
private static final IUFStatusHandler statusHandler = UFStatus.getHandler(
PathManager.class, "Localization");
// @VisibleForTesting
static final Map<LocalizationFileKey, LocalizationFile> fileCache = new ConcurrentHashMap<LocalizationFileKey, LocalizationFile>();
@ -93,6 +95,33 @@ public class PathManager implements IPathManager {
return file;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.common.localization.IPathManager#getStaticFile(com.raytheon
* .uf.common.localization.LocalizationContext.LocalizationType,
* java.lang.String)
*/
@Override
public File getStaticFile(LocalizationType type, String name) {
LocalizationFile locFile = getStaticLocalizationFile(type, name);
File file = null;
if (locFile != null) {
file = locFile.getFile();
}
return file;
}
@Override
public LocalizationFile getStaticLocalizationFile(LocalizationType type,
String name) {
Validate.notNull(name, "Path name must not be null");
return this.getStaticLocalizationFile(new LocalizationType[] { type },
name);
}
/*
* (non-Javadoc)
*
@ -103,11 +132,16 @@ public class PathManager implements IPathManager {
@Override
public LocalizationFile getStaticLocalizationFile(String name) {
Validate.notNull(name, "Path name must not be null");
LocalizationType[] types = this.adapter.getStaticContexts();
return this.getStaticLocalizationFile(types, name);
}
private LocalizationFile getStaticLocalizationFile(
LocalizationType[] types, String name) {
Validate.notNull(name, "Path name must not be null");
name = name.replace(File.separator, IPathManager.SEPARATOR);
// Iterate through the types
LocalizationType[] types = this.adapter.getStaticContexts();
List<LocalizationContext> contexts = new ArrayList<LocalizationContext>();
for (LocalizationType type : types) {
// Iterate through the hierarchy
@ -122,7 +156,7 @@ public class PathManager implements IPathManager {
name);
for (LocalizationFile file : files) {
if (file != null && file.exists()) {
if ((file != null) && file.exists()) {
// First file found in hierarchy is used
return file;
}
@ -156,7 +190,7 @@ public class PathManager implements IPathManager {
LocalizationFile[] files = getLocalizationFile(contexts, name);
for (LocalizationFile lf : files) {
if (lf != null && lf.exists()) {
if ((lf != null) && lf.exists()) {
map.put(lf.getContext().getLocalizationLevel(), lf);
}
}
@ -259,7 +293,7 @@ public class PathManager implements IPathManager {
LocalizationFileKey key = new LocalizationFileKey(response.fileName,
response.context);
LocalizationFile lf = fileCache.get(key);
if (lf != null && lf.isNull() == false) {
if ((lf != null) && (lf.isNull() == false)) {
// Ensure latest data for file, will only be null if no File can be
// returned for path/context.
lf.update(response);
@ -361,6 +395,21 @@ public class PathManager implements IPathManager {
return false;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.common.localization.IPathManager#listFiles(java.lang.
* String , java.lang.String[])
*/
@Override
public LocalizationFile[] listStaticFiles(LocalizationType type,
String name, String[] filter, boolean recursive, boolean filesOnly) {
return this.listStaticFiles(new LocalizationType[] { type }, name,
filter, recursive, filesOnly);
}
/*
* (non-Javadoc)
*
@ -375,6 +424,13 @@ public class PathManager implements IPathManager {
// Iterate through the types
LocalizationType[] types = this.adapter.getStaticContexts();
return this.listStaticFiles(types, name, filter, recursive, filesOnly);
}
private LocalizationFile[] listStaticFiles(LocalizationType[] types,
String name, String[] filter, boolean recursive, boolean filesOnly) {
Validate.notNull(name, "Path name must not be null");
List<LocalizationContext> contexts = new ArrayList<LocalizationContext>();
for (LocalizationType type : types) {
// Iterate through the hierarchy
@ -512,7 +568,7 @@ public class PathManager implements IPathManager {
ListResponseEntry lre = entry.getValue();
SerializableKey key = entry.getKey();
LocalizationFile file = new LocalizationFile();
if (lre.getContext() != null && lre.getFileName() != null) {
if ((lre.getContext() != null) && (lre.getFileName() != null)) {
file = new LocalizationFile(pm.adapter, lre.getContext(),
pm.adapter.getPath(lre.getContext(),
lre.getFileName()), lre.getDate(),