[507] | 1 | /*
|
---|
| 2 | * To change this template, choose Tools | Templates
|
---|
| 3 | * and open the template in the editor.
|
---|
| 4 | */
|
---|
| 5 | package gov.hhs.fha.nhinc.common.propaccessor;
|
---|
| 6 |
|
---|
| 7 | import gov.hhs.fha.nhinc.nhinccomponentpropaccessor.NhincComponentPropAccessorPortType;
|
---|
| 8 |
|
---|
| 9 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertyResponseType;
|
---|
| 10 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertyRequestType;
|
---|
| 11 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertyBooleanResponseType;
|
---|
| 12 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertyBooleanRequestType;
|
---|
| 13 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertyNamesResponseType;
|
---|
| 14 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertyNamesRequestType;
|
---|
| 15 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertiesResponseType;
|
---|
| 16 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertiesRequestType;
|
---|
| 17 | import gov.hhs.fha.nhinc.common.propertyaccess.GetRefreshDurationResponseType;
|
---|
| 18 | import gov.hhs.fha.nhinc.common.propertyaccess.GetRefreshDurationRequestType;
|
---|
| 19 | import gov.hhs.fha.nhinc.common.propertyaccess.GetDurationBeforeNextRefreshResponseType;
|
---|
| 20 | import gov.hhs.fha.nhinc.common.propertyaccess.GetDurationBeforeNextRefreshRequestType;
|
---|
| 21 | import gov.hhs.fha.nhinc.common.propertyaccess.ForceRefreshResponseType;
|
---|
| 22 | import gov.hhs.fha.nhinc.common.propertyaccess.ForceRefreshRequestType;
|
---|
| 23 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertyFileLocationResponseType;
|
---|
| 24 | import gov.hhs.fha.nhinc.common.propertyaccess.GetPropertyFileLocationRequestType;
|
---|
| 25 | import gov.hhs.fha.nhinc.common.propertyaccess.DumpPropsToLogResponseType;
|
---|
| 26 | import gov.hhs.fha.nhinc.common.propertyaccess.DumpPropsToLogRequestType;
|
---|
| 27 | import gov.hhs.fha.nhinc.common.propertyaccess.WritePropertyFileResponseType;
|
---|
| 28 | import gov.hhs.fha.nhinc.common.propertyaccess.WritePropertyFileRequestType;
|
---|
| 29 | import gov.hhs.fha.nhinc.common.propertyaccess.DeletePropertyFileResponseType;
|
---|
| 30 | import gov.hhs.fha.nhinc.common.propertyaccess.DeletePropertyFileRequestType;
|
---|
| 31 |
|
---|
| 32 | import javax.ejb.Stateless;
|
---|
| 33 | import javax.jws.WebService;
|
---|
| 34 |
|
---|
| 35 | import org.apache.commons.logging.Log;
|
---|
| 36 | import org.apache.commons.logging.LogFactory;
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | *
|
---|
| 41 | * @author westbergl
|
---|
| 42 | */
|
---|
| 43 | @WebService(serviceName = "NhincComponentPropAccessor",
|
---|
| 44 | portName = "NhincComponentPropAccessorPort",
|
---|
| 45 | endpointInterface = "gov.hhs.fha.nhinc.nhinccomponentpropaccessor.NhincComponentPropAccessorPortType",
|
---|
| 46 | targetNamespace = "urn:gov:hhs:fha:nhinc:nhinccomponentpropaccessor",
|
---|
| 47 | wsdlLocation = "META-INF/wsdl/NhincComponentPropAccessor/NhincComponentPropAccessor.wsdl")
|
---|
| 48 | @Stateless
|
---|
| 49 | public class NhincComponentPropAccessor implements NhincComponentPropAccessorPortType
|
---|
| 50 | {
|
---|
| 51 |
|
---|
| 52 | private static Log log = LogFactory.getLog(NhincComponentPropAccessor.class);
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * This method returns the value of the given property that is located within the
|
---|
| 57 | * given property file. If the properties have been cached and the cache is
|
---|
| 58 | * still fresh, then it will return the value from the cache. If the properties
|
---|
| 59 | * are cached, but the cache is not fresh, then the cache will be updated with the
|
---|
| 60 | * current values in the properties file and then the property will be returned.
|
---|
| 61 | * If the properties for that file are not cached at all, the property will be
|
---|
| 62 | * retrieved from the properties file and returned.
|
---|
| 63 | *
|
---|
| 64 | * @param getPropertyRequest The input parameters - Property File and Property Name.
|
---|
| 65 | * @return The value for the property.
|
---|
| 66 | */
|
---|
| 67 | public GetPropertyResponseType getProperty(GetPropertyRequestType getPropertyRequest)
|
---|
| 68 | {
|
---|
| 69 | GetPropertyResponseType oOutput = null;
|
---|
| 70 |
|
---|
| 71 | try
|
---|
| 72 | {
|
---|
| 73 | oOutput = PropertyAccessHelper.getProperty(getPropertyRequest);
|
---|
| 74 | }
|
---|
| 75 | catch (Exception e)
|
---|
| 76 | {
|
---|
| 77 | String sMessage = "Failed to retrieve property. Exception: " + e.getMessage();
|
---|
| 78 | log.error(sMessage, e);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | return oOutput;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | /**
|
---|
| 85 | * This will return true if the property value is: T, t, or any case combination
|
---|
| 86 | * of "TRUE" and it will return false for all other values.
|
---|
| 87 | *
|
---|
| 88 | * @param getPropertyBooleanRequest The property file and property name.
|
---|
| 89 | * @return TRUE if the property is true and false if it is not.
|
---|
| 90 | */
|
---|
| 91 | public GetPropertyBooleanResponseType getPropertyBoolean(GetPropertyBooleanRequestType getPropertyBooleanRequest)
|
---|
| 92 | {
|
---|
| 93 | GetPropertyBooleanResponseType oOutput = null;
|
---|
| 94 |
|
---|
| 95 | try
|
---|
| 96 | {
|
---|
| 97 | oOutput = PropertyAccessHelper.getPropertyBoolean(getPropertyBooleanRequest);
|
---|
| 98 | }
|
---|
| 99 | catch (Exception e)
|
---|
| 100 | {
|
---|
| 101 | String sMessage = "Failed to retrieve boolean property. Exception: " + e.getMessage();
|
---|
| 102 | log.error(sMessage, e);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | return oOutput;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /**
|
---|
| 109 | * This method returns the set of keys in a property file.
|
---|
| 110 | *
|
---|
| 111 | * @param getPropertyNamesRequest The name of the property file.
|
---|
| 112 | * @return The list of property names in the property file.
|
---|
| 113 | */
|
---|
| 114 | public GetPropertyNamesResponseType getPropertyNames(GetPropertyNamesRequestType getPropertyNamesRequest)
|
---|
| 115 | {
|
---|
| 116 | GetPropertyNamesResponseType oOutput = null;
|
---|
| 117 |
|
---|
| 118 | try
|
---|
| 119 | {
|
---|
| 120 | oOutput = PropertyAccessHelper.getPropertyNames(getPropertyNamesRequest);
|
---|
| 121 | }
|
---|
| 122 | catch (Exception e)
|
---|
| 123 | {
|
---|
| 124 | String sMessage = "Failed to retrieve property names. Exception: " + e.getMessage();
|
---|
| 125 | log.error(sMessage, e);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | return oOutput;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /**
|
---|
| 132 | * This method returns the properties that are located within the given property
|
---|
| 133 | * file. If the properties have been cached and the cache is still fresh, then
|
---|
| 134 | * it will return the values from the cache. If the properties are cached, but
|
---|
| 135 | * the cache is not fresh, then the cache will be updated with the current values
|
---|
| 136 | * in the properties file and then the property values will be returned. If the
|
---|
| 137 | * properties for that file are not cached at all, the property will be retrieved
|
---|
| 138 | * from the properties file and returned.
|
---|
| 139 | *
|
---|
| 140 | * NOTE: THIS IS AN EXPENSIVE OPERATION. IT WILL CREATE A DEEP COPY OF THE
|
---|
| 141 | * PROPERTIES AND RETURN IT. THAT MEANS IT WILL CREATE AN EXACT REPLICA
|
---|
| 142 | * WITH ALL DATA. THIS IS A PROTECTION TO MAKE SURE THAT A PROPERTY
|
---|
| 143 | * IS NOT INADVERTANTLY CHANGED OUTSIDE OF THIS CLASS.
|
---|
| 144 | *
|
---|
| 145 | * @param getPropertiesRequest Name of the property file.
|
---|
| 146 | * @return Returns all of the properties and values in the property file.
|
---|
| 147 | */
|
---|
| 148 | public GetPropertiesResponseType getProperties(GetPropertiesRequestType getPropertiesRequest)
|
---|
| 149 | {
|
---|
| 150 | GetPropertiesResponseType oOutput = null;
|
---|
| 151 |
|
---|
| 152 | try
|
---|
| 153 | {
|
---|
| 154 | oOutput = PropertyAccessHelper.getProperties(getPropertiesRequest);
|
---|
| 155 | }
|
---|
| 156 | catch (Exception e)
|
---|
| 157 | {
|
---|
| 158 | String sMessage = "Failed to retrieve properties. Exception: " + e.getMessage();
|
---|
| 159 | log.error(sMessage, e);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | return oOutput;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /**
|
---|
| 166 | * This will return the in milliseconds the refresh duration on the property file.
|
---|
| 167 | * A setting of -1 means it never refreshes.
|
---|
| 168 | *
|
---|
| 169 | * @param getRefreshDurationRequest The name of the property file.
|
---|
| 170 | * @return the refresh duration for the property file.
|
---|
| 171 | */
|
---|
| 172 | public GetRefreshDurationResponseType getRefreshDuration(GetRefreshDurationRequestType getRefreshDurationRequest)
|
---|
| 173 | {
|
---|
| 174 | GetRefreshDurationResponseType oOutput = null;
|
---|
| 175 |
|
---|
| 176 | try
|
---|
| 177 | {
|
---|
| 178 | oOutput = PropertyAccessHelper.getRefreshDuration(getRefreshDurationRequest);
|
---|
| 179 | }
|
---|
| 180 | catch (Exception e)
|
---|
| 181 | {
|
---|
| 182 | String sMessage = "Failed to retrieve refresh duration. Exception: " + e.getMessage();
|
---|
| 183 | log.error(sMessage, e);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | return oOutput;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | /**
|
---|
| 190 | * This will return the duration in milliseconds before the next refresh of the
|
---|
| 191 | * properties file. A value of -1 indicates that no refresh will occur.
|
---|
| 192 | *
|
---|
| 193 | * @param getDurationBeforeNextRefreshRequest The name of the property file.
|
---|
| 194 | * @return The number of milliseconds before the next refresh will occur.
|
---|
| 195 | */
|
---|
| 196 | public GetDurationBeforeNextRefreshResponseType getDurationBeforeNextRefresh(GetDurationBeforeNextRefreshRequestType getDurationBeforeNextRefreshRequest)
|
---|
| 197 | {
|
---|
| 198 | GetDurationBeforeNextRefreshResponseType oOutput = null;
|
---|
| 199 |
|
---|
| 200 | try
|
---|
| 201 | {
|
---|
| 202 | oOutput = PropertyAccessHelper.getDurationBeforeNextRefresh(getDurationBeforeNextRefreshRequest);
|
---|
| 203 | }
|
---|
| 204 | catch (Exception e)
|
---|
| 205 | {
|
---|
| 206 | String sMessage = "Failed to retrieve duration before next refresh. Exception: " + e.getMessage();
|
---|
| 207 | log.error(sMessage, e);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | return oOutput;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /**
|
---|
| 214 | * If a property file has been cached, this will force a refresh of the property
|
---|
| 215 | * file. If a property file is not cached, then this operation will do nothing.
|
---|
| 216 | *
|
---|
| 217 | * @param forceRefreshRequest The name of the property file.
|
---|
| 218 | * @return true if the property file was refreshed.
|
---|
| 219 | */
|
---|
| 220 | public ForceRefreshResponseType forceRefresh(ForceRefreshRequestType forceRefreshRequest)
|
---|
| 221 | {
|
---|
| 222 | ForceRefreshResponseType oOutput = null;
|
---|
| 223 |
|
---|
| 224 | try
|
---|
| 225 | {
|
---|
| 226 | oOutput = PropertyAccessHelper.forceRefresh(forceRefreshRequest);
|
---|
| 227 | }
|
---|
| 228 | catch (Exception e)
|
---|
| 229 | {
|
---|
| 230 | String sMessage = "Failed to force refresh. Exception: " + e.getMessage();
|
---|
| 231 | log.error(sMessage, e);
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | return oOutput;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | /**
|
---|
| 238 | * This method will return the location of the property files. Essentially it
|
---|
| 239 | * will return the value in the NHINC_PROPERTIES_DIR environment variable.
|
---|
| 240 | *
|
---|
| 241 | * @param getPropertyFileLocationRequest Nothing important - just need this unique for document literal binding.
|
---|
| 242 | * @return The path and location of the property files.
|
---|
| 243 | */
|
---|
| 244 | public GetPropertyFileLocationResponseType getPropertyFileLocation(GetPropertyFileLocationRequestType getPropertyFileLocationRequest)
|
---|
| 245 | {
|
---|
| 246 | GetPropertyFileLocationResponseType oOutput = null;
|
---|
| 247 |
|
---|
| 248 | try
|
---|
| 249 | {
|
---|
| 250 | oOutput = PropertyAccessHelper.getPropertyFileLocation(getPropertyFileLocationRequest);
|
---|
| 251 | }
|
---|
| 252 | catch (Exception e)
|
---|
| 253 | {
|
---|
| 254 | String sMessage = "Failed to retrieve property file location. Exception: " + e.getMessage();
|
---|
| 255 | log.error(sMessage, e);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | return oOutput;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | /**
|
---|
| 262 | * This method dumps the properties and associated values for a properties file to
|
---|
| 263 | * the log file.
|
---|
| 264 | *
|
---|
| 265 | * @param dumpPropsToLogRequest the name of the property file.
|
---|
| 266 | * @return Nothing - it simply always returns true.
|
---|
| 267 | */
|
---|
| 268 | public DumpPropsToLogResponseType dumpPropsToLog(DumpPropsToLogRequestType dumpPropsToLogRequest)
|
---|
| 269 | {
|
---|
| 270 | DumpPropsToLogResponseType oOutput = null;
|
---|
| 271 |
|
---|
| 272 | try
|
---|
| 273 | {
|
---|
| 274 | oOutput = PropertyAccessHelper.dumpPropsToLog(dumpPropsToLogRequest);
|
---|
| 275 | }
|
---|
| 276 | catch (Exception e)
|
---|
| 277 | {
|
---|
| 278 | String sMessage = "Failed to dump property file to log. Exception: " + e.getMessage();
|
---|
| 279 | log.error(sMessage, e);
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | return oOutput;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | /**
|
---|
| 286 | * This method writes out the given properties as the specified properties file.
|
---|
| 287 | * Note: It does not merge information. It will completely overwrite the current
|
---|
| 288 | * file with the new properties information. If the file does not exist, it will
|
---|
| 289 | * create it. This writes the property file to the NHINC properties directory.
|
---|
| 290 | *
|
---|
| 291 | * WARNING: If a property file is currently cached in memory - the file will not be
|
---|
| 292 | * re-read until the next time the cache refreshes its property from the file based on
|
---|
| 293 | * the criteria that was put in place when the properties were last loaded from file.
|
---|
| 294 | * This is based on setting of the "CacheRefreshDuration" property in the property file.
|
---|
| 295 | *
|
---|
| 296 | * @param writePropertyFileRequest The name of the property file and the properties to write.
|
---|
| 297 | * @return True if this succeeds.
|
---|
| 298 | */
|
---|
| 299 | public WritePropertyFileResponseType writePropertyFile(WritePropertyFileRequestType writePropertyFileRequest)
|
---|
| 300 | {
|
---|
| 301 | WritePropertyFileResponseType oOutput = null;
|
---|
| 302 |
|
---|
| 303 | try
|
---|
| 304 | {
|
---|
| 305 | oOutput = PropertyAccessHelper.writePropertyFile(writePropertyFileRequest);
|
---|
| 306 | }
|
---|
| 307 | catch (Exception e)
|
---|
| 308 | {
|
---|
| 309 | String sMessage = "Failed to write property file. Exception: " + e.getMessage();
|
---|
| 310 | log.error(sMessage, e);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | return oOutput;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 | /**
|
---|
| 317 | * This method deletes the specified properties file.
|
---|
| 318 | * Note: It will completely delete the file from the NHINC properties directory.
|
---|
| 319 | *
|
---|
| 320 | * WARNING: If a property file is currently cached in memory - the file will not be
|
---|
| 321 | * removed from memory until the next time the cache refreshes its property from the file based on
|
---|
| 322 | * the criteria that was put in place when the properties were last loaded from file.
|
---|
| 323 | * This is based on setting of the "CacheRefreshDuration" property in the property file.
|
---|
| 324 | *
|
---|
| 325 | * @param deletePropertyFileRequest The name of the property file to be deleted without the ".properties" extension.
|
---|
| 326 | * @return True if this succeeds.
|
---|
| 327 | */
|
---|
| 328 | public DeletePropertyFileResponseType deletePropertyFile(DeletePropertyFileRequestType deletePropertyFileRequest)
|
---|
| 329 | {
|
---|
| 330 | DeletePropertyFileResponseType oOutput = null;
|
---|
| 331 |
|
---|
| 332 | try
|
---|
| 333 | {
|
---|
| 334 | oOutput = PropertyAccessHelper.deletePropertyFile(deletePropertyFileRequest);
|
---|
| 335 | }
|
---|
| 336 | catch (Exception e)
|
---|
| 337 | {
|
---|
| 338 | String sMessage = "Failed to delete property file. Exception: " + e.getMessage();
|
---|
| 339 | log.error(sMessage, e);
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | return oOutput;
|
---|
| 343 | }
|
---|
| 344 | }
|
---|