Class EntryTransforms
java.lang.Object
edu.wisc.ssec.mcidasv.servermanager.EntryTransforms
Useful methods for doing things like converting a
AddeServer
to a
RemoteAddeEntry
.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Function
<AddeServer, RemoteAddeEntry> private static final String
private static final int
private static final Matcher
No sense in rebuilding things that don't need to be rebuilt.private static final Pattern
Matches "host" declarations in a MCTABLE file.private static final org.slf4j.Logger
Logger object.private static final Matcher
No sense in rebuilding things that don't need to be rebuilt.private static final Pattern
Matches dataset routing information in a MCTABLE file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
static void
appendResolvFile
(String filename, Collection<LocalAddeEntry> entries) Writes aCollection
ofLocalAddeEntries
to a "RESOLV.SRV" file.asResolvEntries
(Collection<LocalAddeEntry> entries) static String
asResolvEntry
(LocalAddeEntry entry) Converts a givenLocalAddeEntry
into aString
that is suitable for including in a "RESOLV.SRV" file.convertAddeServerXml
(Element root, AddeEntry.EntrySource source) static Set
<RemoteAddeEntry> convertIdvServers
(List<AddeServer> idvServers) Converts givenidvServers
to aRemoteAddeEntries
.static Set
<AddeServer> convertMcvServers
(Collection<AddeEntry> entries) Converts givenAddeEntries
toAddeServers
.protected static Set
<RemoteAddeEntry> convertUserXml
(Element root) static Set
<RemoteAddeEntry> createEntriesFrom
(RemoteAddeEntry entry) static String
demungeFileMask
(String path) De-munges file mask strings.static String
Converts a givenAddeEntry.EntryType
to itsString
representation.protected static Set
<RemoteAddeEntry> extractMctableEntries
(String path, String username, String project) static Set
<AddeEntry.EntryType> findEntryTypes
(Collection<? extends AddeEntry> entries) private static List
<RemoteAddeEntry> mapDatasetsToName
(Map<String, String> datasetToHost, Map<String, String> hostToIp, String username, String project) This method is slightly confusing, sorry!mapIpToName
(Map<String, Set<String>> map) static String
mungeFileMask
(String mask) Munges a file maskString
into something "RESOLV.SRV" expects.static Set
<LocalAddeEntry> readResolvFile
(String filename) Reads a "RESOLV.SRV" file and converts the contents into aSet
ofLocalAddeEntries
.static LocalAddeEntry
readResolvLine
(String line) Converts aString
containing a "RESOLV.SRV" entry into aLocalAddeEntry
.static Set
<LocalAddeEntry> removeTemporaryEntriesFromResolvFile
(String filename, Collection<LocalAddeEntry> entries) static String
serverNameToStr
(LocalAddeEntry.ServerName serverName) Converts a givenLocalAddeEntry.ServerName
to itsString
representation.static LocalAddeEntry.AddeFormat
Attempts to convert aString
into a member ofLocalAddeEntry.AddeFormat
.static AddeEntry.EntrySource
Attempts to convert aString
to anAddeEntry.EntrySource
.static AddeEntry.EntryStatus
Attempts to convert aString
into anAddeEntry.EntryStatus
.static AddeEntry.EntryType
Attempts to convert aString
to aAddeEntry.EntryType
.static AddeEntry.EntryValidity
Attempts to convert aString
to anAddeEntry.EntryValidity
.static LocalAddeEntry.ServerName
Attempts to convert aString
to aLocalAddeEntry.ServerName
.private static void
writeResolvFile
(String filename, boolean append, Collection<LocalAddeEntry> entries) Writes aCollection
ofLocalAddeEntries
to a "RESOLV.SRV" file.static void
writeResolvFile
(String filename, Collection<LocalAddeEntry> entries) Writes aCollection
ofLocalAddeEntries
to a "RESOLV.SRV" file.
-
Field Details
-
logger
Logger object. -
routePattern
Matches dataset routing information in a MCTABLE file. -
hostPattern
Matches "host" declarations in a MCTABLE file. -
routeMatcher
No sense in rebuilding things that don't need to be rebuilt. -
hostMatcher
No sense in rebuilding things that don't need to be rebuilt. -
cygwinPrefix
- See Also:
-
cygwinPrefixLength
-
convertIdvServer
-
-
Constructor Details
-
EntryTransforms
private EntryTransforms()This is a utility class. Don't create it!
-
-
Method Details
-
findEntryTypes
-
convertIdvServers
Converts givenidvServers
to aRemoteAddeEntries
.- Parameters:
idvServers
- "IDV-style" ADDE servers to convert.- Returns:
Set
of remote ADDE entries that corresponds to the unique objects inidvServers
.
-
convertMcvServers
Converts givenAddeEntries
toAddeServers
.- Parameters:
entries
- "McIDAS-V style" ADDE entries to convert.- Returns:
Set
ofAddeServer
objects that corresponds to the ones found inentries
.
-
convertUserXml
- Parameters:
root
- "Root" of the XML to convert.- Returns:
Set
of remote ADDE entries described byroot
.
-
createEntriesFrom
-
convertAddeServerXml
- Parameters:
root
- XML to convert.source
- Used to "bulk set" the origin of whatever remote ADDE entries get created.- Returns:
Set
of remote ADDE entries contained withinroot
.
-
serverNameToStr
Converts a givenLocalAddeEntry.ServerName
to itsString
representation. Note that the resultingString
is lowercase.- Parameters:
serverName
- The server name to convert. Cannot benull
.- Returns:
serverName
converted to a lowercaseString
.- Throws:
NullPointerException
- ifserverName
isnull
.
-
strToServerName
Attempts to convert aString
to aLocalAddeEntry.ServerName
.- Parameters:
s
- Value whoseServerName
is wanted. Cannot benull
.- Returns:
- One of
ServerName
. If there was no "sensible" conversion, the method returnsLocalAddeEntry.ServerName.INVALID
. - Throws:
NullPointerException
- ifs
isnull
.
-
entryTypeToStr
Converts a givenAddeEntry.EntryType
to itsString
representation. Note that the resultingString
is lowercase.- Parameters:
type
- The type to convert. Cannot benull
.- Returns:
type
converted to a lowercaseString
.- Throws:
NullPointerException
- iftype
isnull
.
-
strToEntryType
Attempts to convert aString
to aAddeEntry.EntryType
.- Parameters:
s
- Value whoseEntryType
is wanted. Cannot benull
.- Returns:
- One of
EntryType
. If there was no "sensible" conversion, the method returnsAddeEntry.EntryType.UNKNOWN
. - Throws:
NullPointerException
- ifs
isnull
.
-
strToEntrySource
Attempts to convert aString
to anAddeEntry.EntrySource
.- Parameters:
s
-String
representation of anEntrySource
. Cannot benull
.- Returns:
- Uses
AddeEntry.EntrySource.valueOf(String)
to converts
to anEntrySource
and returns. If no conversion was possible, returnsAddeEntry.EntrySource.USER
. - Throws:
NullPointerException
- ifs
isnull
.
-
strToEntryValidity
Attempts to convert aString
to anAddeEntry.EntryValidity
.- Parameters:
s
-String
representation of anEntryValidity
. Cannot benull
.- Returns:
- Uses
AddeEntry.EntryValidity.valueOf(String)
to converts
to anEntryValidity
and returns. If no conversion was possible, returnsAddeEntry.EntryValidity.UNVERIFIED
. - Throws:
NullPointerException
- ifs
isnull
.
-
strToEntryStatus
Attempts to convert aString
into anAddeEntry.EntryStatus
.- Parameters:
s
-String
representation of anEntryStatus
. Cannot benull
.- Returns:
- Uses
AddeEntry.EntryStatus.valueOf(String)
to converts
into anEntryStatus
and returns. If no conversion was possible, returnsAddeEntry.EntryStatus.DISABLED
. - Throws:
NullPointerException
- ifs
isnull
.
-
strToAddeFormat
Attempts to convert aString
into a member ofLocalAddeEntry.AddeFormat
. This method does a little bit of magic with the incomingString
:- spaces are replaced with underscores
- dashes ("-") are removed
- Parameters:
s
-String
representation of anAddeFormat
. Cannot benull
.- Returns:
- Uses
LocalAddeEntry.AddeFormat.valueOf(String)
to convert the modifiedString
into anAddeFormat
and returns. If no conversion was possible, returnsLocalAddeEntry.AddeFormat.INVALID
. - Throws:
NullPointerException
- ifs
isnull
.
-
addeFormatToStr
-
extractMctableEntries
protected static Set<RemoteAddeEntry> extractMctableEntries(String path, String username, String project) -
mapDatasetsToName
private static List<RemoteAddeEntry> mapDatasetsToName(Map<String, String> datasetToHost, Map<String, String> hostToIp, String username, String project) This method is slightly confusing, sorry! Think of it kind of like a "SQL JOIN"...Basically create
RemoteAddeEntries
by using a hostname to determine which dataset belongs to which IP.- Parameters:
datasetToHost
-Map
of ADDE groups to host names.hostToIp
-Map
of host names to IP addresses.username
- ADDE username.project
- ADDE project number (as aString
).- Returns:
List
ofRemoteAddeEntry
instances. Each hostname will have a value fromdatasetToHost
and the accounting information is formed fromusername
andproject
.
-
mapIpToName
-
mapDatasetsToIp
-
readResolvFile
Reads a "RESOLV.SRV" file and converts the contents into aSet
ofLocalAddeEntries
.- Parameters:
filename
- Filename containing desired local ADDE entries. Cannot benull
.- Returns:
Set
of local ADDE entries contained withinfilename
.- Throws:
IOException
- if there was a problem reading fromfilename
.- See Also:
-
readResolvLine
Converts aString
containing a "RESOLV.SRV" entry into aLocalAddeEntry
.- Parameters:
line
- Line fromRESOLV.SRV
.- Returns:
LocalAddeEntry
that represents the givenline
fromRESOLV.SRV
.
-
writeResolvFile
public static void writeResolvFile(String filename, Collection<LocalAddeEntry> entries) throws IOException Writes aCollection
ofLocalAddeEntries
to a "RESOLV.SRV" file. This method discards the current contents offilename
!- Parameters:
filename
- Filename that will contain the local ADDE entries withinentries
. Cannot benull
.entries
-Set
of entries to be written tofilename
. Cannot benull
.- Throws:
IOException
- if there was a problem writing tofilename
.- See Also:
-
appendResolvFile
public static void appendResolvFile(String filename, Collection<LocalAddeEntry> entries) throws IOException Writes aCollection
ofLocalAddeEntries
to a "RESOLV.SRV" file. This method will append the contents ofentries
tofilename
.- Parameters:
filename
- Filename that will contain the local ADDE entries withinentries
. Cannot benull
.entries
-Collection
of entries to be written tofilename
. Cannot benull
.- Throws:
IOException
- if there was a problem writing tofilename
.- See Also:
-
writeResolvFile
private static void writeResolvFile(String filename, boolean append, Collection<LocalAddeEntry> entries) throws IOException Writes aCollection
ofLocalAddeEntries
to a "RESOLV.SRV" file.- Parameters:
filename
- Filename that will contain the local ADDE entries withinentries
. Cannot benull
.append
- Iftrue
, appendentries
tofilename
. Otherwise discards contents offilename
.entries
-Collection
of entries to be written tofilename
. Cannot benull
.- Throws:
IOException
- if there was a problem writing tofilename
.- See Also:
-
removeTemporaryEntriesFromResolvFile
public static Set<LocalAddeEntry> removeTemporaryEntriesFromResolvFile(String filename, Collection<LocalAddeEntry> entries) throws IOException - Throws:
IOException
-
demungeFileMask
De-munges file mask strings.This process is largely used to generate "Windows-friendly" masks.
- Parameters:
path
- File path to fix.- Returns:
path
with Windows fixes applied.- Throws:
NullPointerException
- ifpath
isnull
.
-
mungeFileMask
Munges a file maskString
into something "RESOLV.SRV" expects.Munging is only needed for Windows users--the process converts back slashes into forward slashes and prefixes with "/cygdrive/".
- Parameters:
mask
- File mask that may need to be fixed before storing inRESOLV.SRV
.- Returns:
- Path suitable for storing in
RESOLV.SRV
. - Throws:
NullPointerException
- ifmask
isnull
.
-
asResolvEntries
- Parameters:
entries
-Collection
of entries to convert. Should not benull
.- Returns:
entries
represented as strings.- See Also:
-
asResolvEntry
Converts a givenLocalAddeEntry
into aString
that is suitable for including in a "RESOLV.SRV" file. This method does not append a newline to the end of theString
.- Parameters:
entry
- TheLocalAddeEntry
to convert. Should not benull
.- Returns:
entry
as a "RESOLV.SRV" entry.
-