public class ToolUtils
extends Object
implements RemoteAccess
Modifier and Type | Field and Description |
---|---|
static String |
HTTPGWHOSTNAME |
static int |
MAJOR |
static int |
MINOR |
static Pattern |
NONALPHANUM |
static String |
RMIHOSTNAME |
static boolean |
SERVER |
static String |
WEBAPPNAME |
static String |
WTHOME |
Constructor and Description |
---|
ToolUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
_delete(String[] as)
server side part of delete()
|
static void |
_update(Persistable p) |
static void |
_update(WTCollection w)
server side part of update method.
|
static Group |
callTask(Hashtable formHash,
Group serverGroup,
String myTaskName)
short form of callTask
|
static Group |
callTask(Hashtable formHash,
Group serverGroup,
String myTaskName,
Hashtable params)
Prepare and invoke an InfoEngine Task.
|
static Hashtable |
callTask(Hashtable formHash,
Group serverGroup,
String myTaskName,
Hashtable params,
Boolean onlyDefault)
Prepare and invoke an InfoEngine Task.
|
static Group |
callTask(Persistable pbo,
String myTaskName)
workflow form of callTask
|
static Connection |
dbConnect()
connect to configured database and return connection object
|
static void |
delete(String[] as)
brute force remove obj with server side method.
|
static void |
deser(String[] argv)
deserialize an object from a file and dump it to stdout
|
static void |
deserex(String[] argv)
deserialize the base64 encoded text given in argv into an object and either print a stacktrace (if it's an exception) or dump it to stdout
typical use to get a stacktrace for the exception message in an I*E error group
|
static void |
deserLA(String[] argv)
deserialize an object from a file and dump it to stdout
|
static void |
dumpGroup(Group wt_group)
class to call dump of first element of group passed in.
|
static void |
dumpGroup(Group g,
int many)
class to dump a number of elements of group passed in.
|
static Map<String,Object> |
element2Hash(Element in)
make a hashtable from an Element
|
static String |
escapeXML(Object o)
escape xml (or html) special chars & > < " ' with their textual representation e.g.
|
static String |
extractMessage(Group g)
extract from a (typically @SERVER) group the innermost exception-message
|
static String |
extractMessage(Group g,
Logger logger1)
extract from a (typically @SERVER) group the innermost exception-message
|
static Object |
f2o(String f)
deserialize an object from a file.
|
static String |
fixEscapes(String a)
return string with occurences of %hh (hh being two hex digits) replaced with the character represented by hex value.
|
static void |
fixEscapes(String[] a)
call fixEscapes for all strings in an array.
|
static void |
fixEscapes(String a,
StringBuffer b)
replaces all occurrences of %hh (hh being two hex digits) with the character represented by hex value VR%3Awt.doc.WTDocument%3A423428 -> VR:wt.doc.WTDocument:423428
currently provides no way to escape the % except with %25 |
static Group |
fixObid(Group in)
make obid atts in group contain only the short obid for wt so we loop and change all values of atts named obid or masterReference
|
static Group |
fixObid(Group in,
String[] fixNames,
boolean complain)
make obid atts in group contain only the short obid for wt so we loop and change all values of atts in String[] fixNames
|
static void |
formatFloatToInt(Group g,
String[] cols)
try to reformat the value[s] into integers
|
static int[] |
getIntVersion(Class toCheck)
return an int array with major and minor version number
|
static String |
getOR(Object p)
return an obid for the object, of the obj is a Persistable and persisted gives normal OR:class:ida2a2 obid.
|
static String |
getOR(Persistable p)
return a Persistable's OR: obid
|
static String |
getRevString(Persistable perObj) |
static String |
getStackTrace(Throwable aThrowable) |
static String |
getVersion(Class toCheck)
return major.minor version assumes the class to inspect has two public ints called MAJOR and MINOR
|
static String |
getVR(Iterated p)
return an iterated's VR: obid
|
static String |
getWidths(Group in)
return a string that will set the width for a display webject for all cols of a group to the max num of chars contained in each col.
NOTE: as a sideeffect it checks and makes sure first element(=line) has all attributes occurring in elements 2..n, so display-table will work properly |
static Persistable |
getWTObject(Object o) |
static Persistable |
getWTObjectByNumber(String objNumber,
boolean getMaster) |
static WTUser |
getWTUserByName(String username) |
static WTUser |
getWTUserByName(String username,
boolean ignorecase) |
static WTUser |
getWTUserByName(String username,
boolean ignorecase,
boolean throwException) |
static WTUser |
getWTUserByName(String username,
boolean ignorecase,
boolean useLike,
boolean throwException)
get a wtuser obj by username.
|
static String |
group2csv(Group in,
String fdelim,
String rdelim,
boolean includeHeaders)
make csv data from group
|
static Map<String,Object>[] |
group2HashArray(Group in)
return a group as an array of Hashtables filled with first att values, including com.infoengine.object.type meta (e.g., wt.part.WTPart)
|
static Map<String,Object>[] |
group2HashArray(Group in,
boolean toLower)
return a group as an array of Hashtables filled with first att values, including com.infoengine.object.type meta (e.g., wt.part.WTPart)
|
static Group |
hash2Group(Hashtable h,
String groupName)
Make an infoengine group from a hash table.
|
static Group |
hash2Group(Hashtable h,
String groupName,
String key,
String value)
Make an infoengine group from a hash table, each key/value pair givng an element having a key and value att.
|
static Group |
hash2Group(Map h,
String groupName)
Make an infoengine group from a hash table.
|
static Group |
hash2ParamGroup(Hashtable h,
Hashtable f,
String groupName)
prepare a form group from 2 hashes, one gives "normal" atts, the other makes atts of the form param=name=value
|
static String |
innerMessage(Throwable e)
return the message of an exception, if nested exceptions exist return the innermost message.
|
static boolean |
isAlphaNumeric(String text) |
static boolean |
isRequiredVersion(Class toCheck,
int major,
int minor,
boolean throwEx)
return true if the required class has at least given major (and if major matches given minor version) assumes the class to inspect has two public ints called MAJOR and MINOR
|
static boolean |
isRoleMaster(String link,
int roleoff)
tell caller if a links roleA or roleB object is a Master.
|
static boolean |
isValUnique(Group g,
String col)
tell if a group's column contains the same value in all rows (e.g. verify all rows have the same value for att number)
|
static String |
jmxConn() |
static Workable |
latestVersionWrkObjFromObid(Object obid)
return the latest version of a persistable from an object (which via toString() must give an obid), return the working copy if the object is checked out.
|
static void |
logElement(Logger l,
Element e)
log a group's xml to the log4j logger.
|
static void |
logException(Logger l,
Throwable e)
log an exceptions stacktrace to the logger
|
static void |
logGroup(Logger l,
Group g)
log a group's xml to the log4j logger.
|
static void |
logGroup(Logger l,
Group g,
String reason)
log a group's xml to the log4j logger.
|
static Hashtable |
lookupFromGroup(Group in,
String key,
String value)
return a lookup hash made from two cols of a group
|
static void |
main(String[] args)
main to invoke setting of state or test isRoleMaster().
|
static void |
mergeSelectedAtts(Group in,
String key,
Group from,
String look,
String[] use)
merge the atts from one group into the rows of a receiving group, using a value from the receiving group as key into group from will throw exception if the lookup key value is not present in "from" group.
|
static void |
meta2att(Group in,
String meta,
String attName)
adds normal Att for requested meta data
|
static String |
ne(Object o,
Object... da) |
static String |
nn(Object o)
returns an empty string if passed null or an object's string representation
|
static String |
nn(Object o,
Object... da)
returns a default string from varargs array (uses first non-null value) if passed null or an object's string representation
|
static String |
nn(Object o,
String def)
returns a default string if passed null or an object's string representation
|
static Object |
nno(Object o)
returns an empty string if passed null or the object
|
static String |
nnx(Object s)
return nn with html escapes
|
static String |
nnx(Object s,
String d)
return nn with html escapes
|
static void |
o2f(Object o,
String s)
serialize an object to a file.
|
static String |
o2s(Object o)
serialize an object into a base64 string
|
static String |
objectInfo(Persistable obj) |
static Persistable |
objFromObid(Object obid)
return a persistable from an object (which via toString() must give an obid)
|
static String |
prettyPrint(boolean b) |
static String |
prettyPrint(byte b) |
static String |
prettyPrint(double b) |
static String |
prettyPrint(float b) |
static String |
prettyPrint(int b) |
static String |
prettyPrint(long b) |
static String |
prettyPrint(Object o)
simple override method for fullblown prettyPrint - returns a string of the obj's prettyprinted representation result will (intentionally) resemble perl's Data::Dumper output.
|
static String |
prettyPrint(Object o,
boolean wantNL)
simple override method for fullblown prettyPrint - returns a string of the obj's prettyprinted representation result will (intentionally) resemble perl's Data::Dumper output.
|
static String |
prettyPrint(Object o,
boolean wantNL,
boolean includeMeta)
simple override method for fullblown prettyPrint - returns a string of the obj's prettyprinted representation result will (intentionally) resemble perl's Data::Dumper output.
|
static String |
prettyPrint(Object o,
StringBuffer b,
String indent,
boolean wantNL)
print an object in a layout that allows to identify hases, vectors etc.
|
static String |
prettyPrint(Object o,
StringBuffer b,
String indent,
boolean wantNL,
boolean includeMeta)
print an object in a layout that allows to identify hases, vectors etc.
|
static String |
prettyPrint(short b) |
static Group |
readGroup(String s)
deserialize an infoengine group from a file.
|
static void |
removeAttNameTypePrefix(Group in,
String[] names)
removes the type prefix in an att's name (e.g., wt.part.WTPartUsageLink.quantity.unit -> quantity.unit)
|
static void |
removeAttNameTypePrefix(Group in,
String[] names,
String tail)
removes the type prefix in an att's name (e.g., wt.part.WTPartUsageLink.quantity.unit -> quantity.unit)
|
static boolean |
rmDashR(File fOrD)
recursively delete file or directory
|
static boolean |
rmDashR(String fOrD)
recursively delete file or directory
|
static void |
rotGroup(Group in)
rotate group -> cols get rows, new col headers are row0 row1 etc.
|
static Object |
s2o(String s)
deserialize an object from a base64 string
|
static void |
saveGroup(Group g,
String s)
serialize an infoengine group to a file.
|
static void |
setLC(String lcname,
RevisionControlled r)
reassign lifecycle of an obj.
|
static void |
setStates(String[] args)
set the state of obid[s] passed in; if args[0] is "-l" then args[1] has lifecycle to assign to objs
|
static String |
shortObid(Object longObid)
extract the short ([OV]R:class.name:seqnr) obid from a ufid
|
static String |
shortObid(Object longObid,
boolean throwException)
extract the short ([OV]R:class.name:seqnr) obid from a ufid
|
static String |
shortObid(String longObid)
Deprecated.
Method shortObid(String) is deprecated, replaced by shortObid(Object).
|
static String |
shortObid(String longObid,
boolean throwException)
Deprecated.
Method shortObid(String ,boolean) is deprecated, replaced by shortObid(Object, boolean).
|
static Group |
subGroup(Group g,
int skip,
int n)
return part of a group (for paging? )
|
static void |
trimAtt(Group in,
String attName)
walks a group's elements and trims whitespace from a given Att's value - IeDatum will be String afterwards.
|
static String |
unescapeXML(Object o)
escape xml (or html) special chars & > < " ' with their textual representation e.g.
|
static void |
update(Persistable p) |
static void |
update(WTCollection w)
calls server side update method on a given Persistable, bypassing checkin/checkout etc.
|
static Workable |
wrkObjFromObid(Object obid)
return a persistable from an object (which via toString() must give an obid), return the working copy if the object is checked out.
|
public static final int MAJOR
public static final int MINOR
public static final String RMIHOSTNAME
public static final String HTTPGWHOSTNAME
public static final String WEBAPPNAME
public static final String WTHOME
public static final boolean SERVER
public static final Pattern NONALPHANUM
public static void main(String[] args) throws Exception
args
- Exception
public static String getVersion(Class toCheck)
className
- public static int[] getIntVersion(Class toCheck)
toCheck
- public static boolean isRequiredVersion(Class toCheck, int major, int minor, boolean throwEx) throws RuntimeException
className
- major
- minor
- RuntimeException
public static Connection dbConnect() throws Exception
Exception
public static void setStates(String[] args) throws Exception
args
- Exception
public static void setLC(String lcname, RevisionControlled r) throws Exception
lcname
- the lifecycle name (to be resolved within r's container)r
- the obj to receive the new lcException
public static void rotGroup(Group in)
in
- group to rotatepublic static String getWidths(Group in)
in
- group to determine the widths forpublic static void dumpGroup(Group wt_group)
wt_group
- group to ask dump forpublic static void dumpGroup(Group g, int many)
g
- input group to dumpmany
- number of elements to dumppublic static Group fixObid(Group in) throws Exception
in
- group to make subst inException
public static Group fixObid(Group in, String[] fixNames, boolean complain) throws Exception
in
- group to make subst infixNames
- names of atts to fix.Exception
public static Group subGroup(Group g, int skip, int n)
g
- group with all recordsskip
- elements to skipn
- number of elements to returnpublic static String shortObid(String longObid) throws WTException
WTException
public static String shortObid(String longObid, boolean throwException) throws WTException
WTException
public static String shortObid(Object longObid) throws WTException
longObid
- Exception
WTException
public static String shortObid(Object longObid, boolean throwException) throws WTException
longObid
- throwException
- Exception
WTException
public static String group2csv(Group in, String fdelim, String rdelim, boolean includeHeaders)
in
- group to make data frompublic static Group hash2Group(Hashtable h, String groupName)
h
- input hash table with name/value pairsgroupName
- name to give to newly created grouppublic static Group hash2Group(Map h, String groupName)
h
- input hash table with name/value pairsgroupName
- name to give to newly created grouppublic static Group hash2Group(Hashtable h, String groupName, String key, String value)
h
- input hash table with key/value pairsgroupName
- name to give to newly created groupkey
- Attribute name for the key columnvalue
- Attribute name for the value columnpublic static void meta2att(Group in, String meta, String attName)
in
- meta
- attName
- public static void removeAttNameTypePrefix(Group in, String[] names) throws WTException
in
- Exception
- if an att creates a duplicate name.WTException
public static void removeAttNameTypePrefix(Group in, String[] names, String tail) throws WTException
in
- Exception
- if an att creates a duplicate name.WTException
public static Group callTask(Persistable pbo, String myTaskName) throws Exception
pbo
- obid of the workflows primaryBusinessObjectmyTaskName
- name of the TaskException
- if the task setup fails.public static Group callTask(Hashtable formHash, Group serverGroup, String myTaskName) throws Exception
formHash
- form data in a hashserverGroup
- if null we'll create one - else server data to pass onmyTaskName
- name of the TaskException
- if the task setup fails.public static Group callTask(Hashtable formHash, Group serverGroup, String myTaskName, Hashtable params) throws Exception
formHash
- form data in a hashserverGroup
- if null we'll create one - else server data to pass onmyTaskName
- name of the Taskparams
- hashtable to make form param=name=value entriesException
- if the task setup fails.public static Hashtable callTask(Hashtable formHash, Group serverGroup, String myTaskName, Hashtable params, Boolean onlyDefault) throws Exception
formHash
- form data in a hashserverGroup
- if null we'll create one - else server data to pass onmyTaskName
- name of the Taskparams
- hashtable to make form param=name=value entriesonlyDefault
- flag if we want all group_outsException
- if the task setup fails.public static String nn(Object o)
o
- public static Object nno(Object o)
o
- public static String nn(Object o, String def)
o
- obj. to testdef
- the default valuepublic static String nn(Object o, Object... da)
o
- obj. to testda
- array with potential default values, "" if empty or no non-null slot found.public static void update(WTCollection w) throws Exception
p
- Exception
public static void update(Persistable p) throws Exception
Exception
public static void _update(WTCollection w) throws Exception
p
- Exception
public static void _update(Persistable p) throws Exception
Exception
public static void trimAtt(Group in, String attName)
in
- attName
- public static void fixEscapes(String[] a)
a
- array with strings passed in.public static void fixEscapes(String a, StringBuffer b)
a
- String to make replacements tob
- StringBuffer for new data, gets truncated first.public static String fixEscapes(String a)
a
- public static Map<String,Object>[] group2HashArray(Group in)
in
- group to unloadpublic static Map<String,Object> element2Hash(Element in)
in
- Element to act uponpublic static Map<String,Object>[] group2HashArray(Group in, boolean toLower)
in
- group to unloadtoLower
- flag whether to lowercase att namespublic static Hashtable lookupFromGroup(Group in, String key, String value)
in
- group to unloadpublic static void saveGroup(Group g, String s) throws Exception
g
- the groups
- the filenameException
public static Group readGroup(String s) throws Exception
s
- the filenameException
public static String prettyPrint(byte b)
public static String prettyPrint(boolean b)
public static String prettyPrint(int b)
public static String prettyPrint(short b)
public static String prettyPrint(long b)
public static String prettyPrint(float b)
public static String prettyPrint(double b)
public static String prettyPrint(Object o)
o
- @return
- Stringpublic static String prettyPrint(Object o, boolean wantNL)
o
- wantNL
- @return
- Stringpublic static String prettyPrint(Object o, boolean wantNL, boolean includeMeta)
o
- wantNL
- @return
- Stringpublic static String prettyPrint(Object o, StringBuffer b, String indent, boolean wantNL)
o
- the objectb
- a stringbuffer to fillindent
- indentation to use for prettyprintend outputwantNL
- flag if lines are ended with \n or space@return
- Stringpublic static String prettyPrint(Object o, StringBuffer b, String indent, boolean wantNL, boolean includeMeta)
o
- the objectb
- a stringbuffer to fillindent
- indentation to use for prettyprintend outputwantNL
- flag if lines are ended with \n or spaceincludeMeta
- flag if IEobjects.toXML should containe meta infos@return
- Stringpublic static Group hash2ParamGroup(Hashtable h, Hashtable f, String groupName)
h
- f
- groupName
- public static void logGroup(Logger l, Group g, String reason)
l
- the loggerg
- the groupreason
- string to print in line before groups's xml appears@return
- voidpublic static void logGroup(Logger l, Group g)
l
- the loggerg
- the group@return
- voidpublic static void logElement(Logger l, Element e)
l
- the loggerg
- the group@return
- voidpublic static void mergeSelectedAtts(Group in, String key, Group from, String look, String[] use) throws IEException
in
- receiving groupkey
- col name of key into group fromfrom
- group to merge inlook
- colname for key lookupuse
- array of column names to merge into new group. possibly existing atts are first removed.IEException
- thrown for various error conditionspublic static boolean isValUnique(Group g, String col)
g
- the groupcol
- the column name@return
- booleanpublic static void formatFloatToInt(Group g, String[] cols)
g
- the group @param col array with col names @exceptionpublic static boolean isRoleMaster(String link, int roleoff) throws WTException
link
- string name of link class, e.g., wt.part.WTPartUsageLinkroleoff
- 0=roleA, 1=roleBWTException
public static String unescapeXML(Object o)
o
- the object to print (o.toString() or "" if null)public static String escapeXML(Object o)
o
- the object to print (o.toString() or "" if null)public static Persistable objFromObid(Object obid) throws WTException
obid
- WTException
public static Workable wrkObjFromObid(Object obid) throws WTException
obid
- WTException
public static Workable latestVersionWrkObjFromObid(Object obid) throws WTException
obid
- WTException
public static void deser(String[] argv) throws Exception
argv
- Exception
public static void deserLA(String[] argv) throws Exception
argv
- Exception
public static void deserex(String[] argv) throws Exception
argv
- Exception
public static void logException(Logger l, Throwable e)
l
- e
- Exception
public static String getVR(Iterated p)
p
- the persistable@return
- Stringpublic static String getOR(Persistable p)
p
- the persistable@return
- Stringpublic static String getOR(Object p)
p
- @return
- Stringpublic static boolean rmDashR(String fOrD)
fOrD
- the file or dir to remove@return
- booleanpublic static boolean rmDashR(File fOrD)
fOrD
- the file or dir to remove@return
- booleanpublic static void delete(String[] as) throws Exception
as
- [] string array with obid of objs to delete.Exception
public static void _delete(String[] as) throws Exception
as
- [] string array with obid of objs to delete.Exception
public static String extractMessage(Group g)
g
- @return
- String the message.public static String extractMessage(Group g, Logger logger1)
g
- @return
- String the message.public static String innerMessage(Throwable e)
e
- @return
- Stringpublic static Object s2o(String s) throws Exception
s
- the base64 stringException
public static String o2s(Object o) throws Exception
o
- the obj to serializeException
public static void o2f(Object o, String s) throws Exception
o
- the objectf
- the filenameException
public static Object f2o(String f) throws Exception
f
- the filenameException
public static String getRevString(Persistable perObj)
public static String objectInfo(Persistable obj)
public static String nnx(Object s)
object
- to stringify@return
- Stringpublic static String nnx(Object s, String d)
s
- object to stringifyd
- default if o null@return
- Stringpublic static WTUser getWTUserByName(String username) throws Exception
Exception
public static WTUser getWTUserByName(String username, boolean ignorecase) throws Exception
Exception
public static WTUser getWTUserByName(String username, boolean ignorecase, boolean throwException) throws Exception
Exception
public static WTUser getWTUserByName(String username, boolean ignorecase, boolean useLike, boolean throwException) throws Exception
username
- ignorecase
- throwException
- : if true throw exception if user is not found.Exception
public static Persistable getWTObjectByNumber(String objNumber, boolean getMaster) throws WTException, RemoteException, InvocationTargetException
WTException
RemoteException
InvocationTargetException
public static String jmxConn() throws Exception
Exception
public static String ne(Object o, Object... da)
public static String getStackTrace(Throwable aThrowable)
public static boolean isAlphaNumeric(String text)
public static Persistable getWTObject(Object o) throws Exception
Exception