Merge "Issue #2761 add region level to localization" into development

Former-commit-id: 3782880dac [formerly 9011e1b31e] [formerly 6e59175ce4 [formerly 59789454912e36ed64eb18fa83561fb7325945e2]]
Former-commit-id: 6e59175ce4
Former-commit-id: b1e2788958
This commit is contained in:
Nate Jensen 2014-02-19 17:18:24 -06:00 committed by Gerrit Code Review
commit 9394879520
9 changed files with 404 additions and 16 deletions

View file

@ -64,6 +64,7 @@ import com.raytheon.uf.common.localization.msgs.ListUtilityResponse;
import com.raytheon.uf.common.localization.msgs.PrivilegedUtilityRequestMessage;
import com.raytheon.uf.common.localization.msgs.UtilityRequestMessage;
import com.raytheon.uf.common.localization.msgs.UtilityResponseMessage;
import com.raytheon.uf.common.localization.region.RegionLookup;
import com.raytheon.uf.common.localization.stream.LocalizationStreamGetRequest;
import com.raytheon.uf.common.localization.stream.LocalizationStreamPutRequest;
import com.raytheon.uf.common.status.IUFStatusHandler;
@ -95,6 +96,7 @@ import com.raytheon.uf.viz.core.requests.ThriftClient;
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* Aug 27, 2013 2295 bkowal The entire jms connection string is now
* provided by EDEX.
* Feb 06, 2014 2761 mnash Add region localization level
*
* </pre>
*
@ -160,12 +162,25 @@ public class LocalizationManager implements IPropertyChangeListener {
statusHandler.handle(Priority.CRITICAL,
"Error initializing localization store", e);
}
registerContextName(LocalizationLevel.USER, getCurrentUser());
registerContextName(LocalizationLevel.WORKSTATION, VizApp.getHostName());
registerContextName(LocalizationLevel.SITE, getCurrentSite());
registerContextName(LocalizationLevel.CONFIGURED, getCurrentSite());
registerContextName(LocalizationLevel.BASE, null);
/*
* look for current site, only do site/region/configured if current site
* is available
*/
String currentSite = getCurrentSite();
if (currentSite != null && currentSite.isEmpty() == false) {
registerContextName(LocalizationLevel.SITE, currentSite);
registerContextName(LocalizationLevel.CONFIGURED, currentSite);
String region = RegionLookup.getWfoRegion(getCurrentSite());
if (region != null) {
registerContextName(LocalizationLevel.REGION, region);
} else {
statusHandler.warn("Unable to find " + getCurrentSite()
+ " in regions.xml file.");
}
}
}
/**
@ -201,6 +216,14 @@ public class LocalizationManager implements IPropertyChangeListener {
this.currentSite = currentSite;
registerContextName(LocalizationLevel.SITE, this.currentSite);
registerContextName(LocalizationLevel.CONFIGURED, this.currentSite);
String region = RegionLookup.getWfoRegion(this.currentSite);
if (region != null) {
registerContextName(LocalizationLevel.REGION, region);
} else {
statusHandler.warn("Unable to find " + this.currentSite
+ " in regions.xml file");
contextMap.remove(LocalizationLevel.REGION);
}
if (!overrideSite) {
localizationStore.putValue(
LocalizationConstants.P_LOCALIZATION_SITE_NAME,

View file

@ -28,6 +28,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.ArrayUtils;
import com.raytheon.uf.common.localization.ILocalizationAdapter;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
@ -35,6 +37,9 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.LocalizationFile.ModifiableLocalizationFile;
import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException;
import com.raytheon.uf.common.localization.region.RegionLookup;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.core.props.EnvProperties;
import com.raytheon.uf.edex.core.props.PropertiesFactory;
@ -60,6 +65,7 @@ import com.raytheon.uf.edex.core.props.PropertiesFactory;
* Mar 14, 2013 1794 djohnson FileUtil.listFiles now returns List.
* Nov 03, 2013 2511 mnash Fix issue where if name occurs in path
* file won't be returned correctly
* Feb 13, 2014 mnash Add region level to localization
* </pre>
*
* @author jelkins
@ -68,6 +74,9 @@ import com.raytheon.uf.edex.core.props.PropertiesFactory;
public class EDEXLocalizationAdapter implements ILocalizationAdapter {
private static final IUFStatusHandler handler = UFStatus
.getHandler(EDEXLocalizationAdapter.class);
private final Map<LocalizationType, LocalizationContext[]> contexts;
/**
@ -90,10 +99,22 @@ public class EDEXLocalizationAdapter implements ILocalizationAdapter {
synchronized (this.contexts) {
LocalizationContext[] ctx = this.contexts.get(type);
if (ctx == null) {
ctx = new LocalizationContext[3];
ctx = new LocalizationContext[4];
ctx[0] = getContext(type, LocalizationLevel.SITE);
ctx[1] = getContext(type, LocalizationLevel.CONFIGURED);
ctx[2] = getContext(type, LocalizationLevel.BASE);
ctx[1] = getContext(type, LocalizationLevel.REGION);
ctx[2] = getContext(type, LocalizationLevel.CONFIGURED);
ctx[3] = getContext(type, LocalizationLevel.BASE);
if (RegionLookup.getWfoRegion(getSiteName()) == null) {
// remove REGION from the contexts array
List<LocalizationContext> c = new ArrayList<LocalizationContext>();
for (LocalizationContext con : ctx) {
if (con.getLocalizationLevel() != LocalizationLevel.REGION) {
c.add(con);
}
}
ctx = c.toArray(new LocalizationContext[0]);
}
this.contexts.put(type, ctx);
}
// return a copy for safety in case someone messes with references
@ -332,6 +353,13 @@ public class EDEXLocalizationAdapter implements ILocalizationAdapter {
|| level == LocalizationLevel.CONFIGURED) {
// fill in site name
contextName = getSiteName();
} else if (level == LocalizationLevel.REGION) {
contextName = RegionLookup.getWfoRegion(getSiteName());
if (contextName == null) {
handler.info("Unable to find " + getSiteName()
+ " in regions.xml file");
contextName = "none";
}
} else {
// EDEX has no concept of current user or personality
contextName = "none";
@ -376,8 +404,16 @@ public class EDEXLocalizationAdapter implements ILocalizationAdapter {
*/
@Override
public LocalizationLevel[] getAvailableLevels() {
return new LocalizationLevel[] { LocalizationLevel.BASE,
LocalizationLevel[] levels = new LocalizationLevel[] {
LocalizationLevel.BASE, LocalizationLevel.REGION,
LocalizationLevel.CONFIGURED, LocalizationLevel.SITE };
if (RegionLookup.getWfoRegion(getSiteName()) == null) {
levels = (LocalizationLevel[]) ArrayUtils.removeElement(levels,
LocalizationLevel.REGION);
}
return levels;
}
/*

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="resources/"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Localization Plug-in
Bundle-SymbolicName: com.raytheon.uf.common.localization
Bundle-Version: 1.12.1174.qualifier
Bundle-Version: 1.14.0
Bundle-Vendor: Raytheon
Require-Bundle: org.apache.commons.lang,
com.raytheon.uf.common.serialization,
@ -16,5 +16,8 @@ Export-Package: com.raytheon.uf.common.localization,
com.raytheon.uf.common.localization.exception,
com.raytheon.uf.common.localization.msgs,
com.raytheon.uf.common.localization.overrides,
com.raytheon.uf.common.localization.region,
com.raytheon.uf.common.localization.stream
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: resources/,
.

View file

@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
.,\
resources/

View file

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<regionSites>
<!-- Pacific Region PBP -->
<region regionId="PR">
<wfo>PBP</wfo>
<wfo>SAM</wfo>
<wfo>GUM</wfo>
<wfo>HNL</wfo>
</region>
<!-- Eastern Region VUY -->
<region regionId="ER">
<wfo>VUY</wfo>
<wfo>CAR</wfo>
<wfo>GYX</wfo>
<wfo>LWX</wfo>
<wfo>PHI</wfo>
<wfo>ALY</wfo>
<wfo>BGM</wfo>
<wfo>BUF</wfo>
<wfo>OKX</wfo>
<wfo>MHX</wfo>
<wfo>RAH</wfo>
<wfo>ILM</wfo>
<wfo>ILN</wfo>
<wfo>CLE</wfo>
<wfo>CTP</wfo>
<wfo>PBZ</wfo>
<wfo>CHS</wfo>
<wfo>CAE</wfo>
<wfo>GSP</wfo>
<wfo>BTV</wfo>
<wfo>RNK</wfo>
<wfo>AKQ</wfo>
<wfo>RLX</wfo>
</region>
<!-- Southern Region EHU -->
<region regionId="SR">
<wfo>EHU</wfo>
<wfo>BMX</wfo>
<wfo>HUN</wfo>
<wfo>MOB</wfo>
<wfo>LZK</wfo>
<wfo>JAX</wfo>
<wfo>EYW</wfo>
<wfo>MLB</wfo>
<wfo>MFL</wfo>
<wfo>TLH</wfo>
<wfo>TBW</wfo>
<wfo>FFC</wfo>
<wfo>LCH</wfo>
<wfo>LIX</wfo>
<wfo>SHV</wfo>
<wfo>JAN</wfo>
<wfo>ABQ</wfo>
<wfo>OUN</wfo>
<wfo>TSA</wfo>
<wfo>SJU</wfo>
<wfo>MRX</wfo>
<wfo>MEG</wfo>
<wfo>BNA</wfo>
<wfo>AMA</wfo>
<wfo>EWX</wfo>
<wfo>BRO</wfo>
<wfo>CRP</wfo>
<wfo>FWD</wfo>
<wfo>ELP</wfo>
<wfo>HGX</wfo>
<wfo>LUB</wfo>
<wfo>MAF</wfo>
<wfo>SJT</wfo>
</region>
<!-- Western Region VHW -->
<region regionId="WR">
<wfo>VHW</wfo>
<wfo>FGZ</wfo>
<wfo>PSR</wfo>
<wfo>TWC</wfo>
<wfo>EKA</wfo>
<wfo>LOX</wfo>
<wfo>STO</wfo>
<wfo>SGX</wfo>
<wfo>MTR</wfo>
<wfo>HNX</wfo>
<wfo>BOI</wfo>
<wfo>PIH</wfo>
<wfo>BYZ</wfo>
<wfo>GGW</wfo>
<wfo>TFX</wfo>
<wfo>MSO</wfo>
<wfo>LKN</wfo>
<wfo>VEF</wfo>
<wfo>REV</wfo>
<wfo>MFR</wfo>
<wfo>PDT</wfo>
<wfo>PQR</wfo>
<wfo>SLC</wfo>
<wfo>SEW</wfo>
<wfo>OTX</wfo>
</region>
<!-- Central region BCQ -->
<region regionId="CR">
<wfo>BCQ</wfo>
<wfo>DEN</wfo>
<wfo>GJT</wfo>
<wfo>PUB</wfo>
<wfo>ILX</wfo>
<wfo>LOT</wfo>
<wfo>IND</wfo>
<wfo>IWX</wfo>
<wfo>DMX</wfo>
<wfo>DVN</wfo>
<wfo>DDC</wfo>
<wfo>GLD</wfo>
<wfo>TOP</wfo>
<wfo>ICT</wfo>
<wfo>JKL</wfo>
<wfo>LMK</wfo>
<wfo>PAH</wfo>
<wfo>DTX</wfo>
<wfo>GRR</wfo>
<wfo>MQT</wfo>
<wfo>APX</wfo>
<wfo>DLH</wfo>
<wfo>MPX</wfo>
<wfo>EAX</wfo>
<wfo>SGF</wfo>
<wfo>LSX</wfo>
<wfo>GID</wfo>
<wfo>LBF</wfo>
<wfo>OAX</wfo>
<wfo>BIS</wfo>
<wfo>FGF</wfo>
<wfo>ABR</wfo>
<wfo>UNR</wfo>
<wfo>FSD</wfo>
<wfo>GRB</wfo>
<wfo>ARX</wfo>
<wfo>MKX</wfo>
<wfo>CYS</wfo>
<wfo>RIW</wfo>
</region>
<!-- Alaska Region VRH-->
<region regionId="AR">
<wfo>VRH</wfo>
<wfo>AFC</wfo>
<wfo>AFG</wfo>
<wfo>AJK</wfo>
</region>
</regionSites>

View file

@ -63,6 +63,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdap
* Apr 19, 2007 chammack Initial Creation.
* Jul 14, 2008 1250 jelkins EDEX LocalizationAdapter additions.
* Oct 01, 2013 2361 njensen Removed XML annotations and methods
* Feb 06, 2014 2761 mnash Add region localization level
*
* </pre>
*
@ -272,6 +273,8 @@ public class LocalizationContext implements Cloneable {
public static LocalizationLevel BASE = createLevel("BASE", 0, true);
public static LocalizationLevel REGION = createLevel("REGION", 150);
public static LocalizationLevel CONFIGURED = createLevel("CONFIGURED",
250, true);
@ -409,13 +412,6 @@ public class LocalizationContext implements Cloneable {
}
/** Defines localization function constants. */
public static enum LocalizationFunction {
UNKNOWN,
// --- Regular Functions ---------------------------------------------
BUNDLE, PLUGIN, COLORMAPS, CONFIG, PYTHON, SMARTINIT, GRID, SHAPEFILES, TEXTPRODUCTS
};
@DynamicSerializeElement
private LocalizationType localizationType;

View file

@ -0,0 +1,104 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.localization.region;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import com.raytheon.uf.common.localization.region.RegionSites.Region;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
/**
* Utility class for retrieving regions based on site information.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 30, 2014 mnash Initial creation
*
* </pre>
*
* @author mnash
* @version 1.0
*/
public class RegionLookup {
private static final IUFStatusHandler handler = UFStatus
.getHandler(RegionLookup.class);
private static Map<String, String> wfoToRegion;
/**
* Don't want/need to construct this class.
*/
private RegionLookup() {
}
/**
* Returns the region based on the site that is passed in.
*
* @param site
* @return
*/
public static synchronized String getWfoRegion(String site) {
if (wfoToRegion == null) {
RegionSites sites = parseFile();
if (sites != null) {
wfoToRegion = new HashMap<String, String>();
for (Region region : sites.getRegion()) {
for (String s : region.wfo) {
wfoToRegion.put(s, region.regionId);
}
}
} else {
wfoToRegion = new HashMap<String, String>();
}
}
return wfoToRegion.get(site);
}
/**
* Parses the regions.xml file that resides within the plugin
*
* @return
*/
private static RegionSites parseFile() {
InputStream stream = RegionLookup.class
.getResourceAsStream("/regions.xml");
JAXBManager manager = SingleTypeJAXBManager
.createWithoutException(RegionSites.class);
try {
return (RegionSites) manager.unmarshalFromInputStream(stream);
} catch (SerializationException e) {
handler.error("Unable to unmarshal regions.xml file", e);
}
return null;
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.localization.region;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* XML Description of a region and its corresponding wfos
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 31, 2014 mnash Initial creation
*
* </pre>
*
* @author mnash
* @version 1.0
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class RegionSites {
@XmlElement
private Region[] region;
/**
* @return the sites
*/
public Region[] getRegion() {
return region;
}
/**
* @param sites
* the sites to set
*/
public void setRegion(Region[] region) {
this.region = region;
}
public static class Region {
@XmlAttribute
public String regionId;
@XmlElement
public String[] wfo;
}
}