Package com.redwood.scheduler.api.tool
Class ToolConnectionImpl
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- com.redwood.scheduler.tool.util.StandaloneAbstractCallXmlHandler
-
- com.redwood.scheduler.tool.messages.CallHandler
-
- com.redwood.scheduler.api.tool.ToolConnectionImpl
-
- All Implemented Interfaces:
ToolConnection,ContentHandler,DTDHandler,EntityResolver,ErrorHandler
public final class ToolConnectionImpl extends com.redwood.scheduler.tool.messages.CallHandler implements ToolConnection
-
-
Field Summary
-
Fields inherited from class com.redwood.scheduler.tool.messages.CallHandler
authenticated, errorMessage, eventId, returnCode, systemId
-
Fields inherited from interface com.redwood.scheduler.api.tool.ToolConnection
CAR_MAP_KEY_JOB_ID, JAR_MAP_KEY_JOB_ID
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ToolResultSetexecuteQuery(String query, Map<String,String> options, Map<String,Object> parameters)Execute a query and return the result as a ToolResultSet.StringexecuteQueryString(String query, Map<String,String> options, Map<String,Object> parameters)Execute a query and return the result as a String.LongexecuteScript(String newScript, OutputHandler newStdout, OutputHandler newStderr)Execute RedwoodScript.Stringget(String newObjectType, String newBusinessKey, boolean search)REST HTTP GETStringget(String newObjectType, String newBusinessKey, boolean search, String propertiesSet, Set<String> includeProperties, Set<String> excludeProperties)REST HTTP GETFileget(String newObjectType, String newKey, String filename, String filepath, boolean search)REST HTTP GETStringgetJobFile(String newUniqueId, String newDestination, String defaultName)REST HTTP GET JOBFILE Get the jobfile identified by the given uniqueId, and store it in the given directoryStringgetLibraries(String filePath)REST HTTP GET API Libraries for local buildsStringgetRestCapabilitiesXML()Retrieve the WADL file for the REST servlet.FilegetScripts(Set<String> items, String filename, String filepath, boolean includeLibraries)REST HTTP POSTStringgetVersion()REST HTTP GET VersionvoidimportCar(File f, String importRuleSet, OutputStreamOutputHandler newStdout, StringBuilderOutputHandler newStderr)import car filevoidimportCar(File f, String importRuleSet, String targetPartition, OutputStreamOutputHandler newStdout, StringBuilderOutputHandler newStderr)import car fileStringlist(String newObjectType, String newFilter, String newSearch, boolean newStylesheet)REST HTTP LISTStringlist(String newObjectType, String newFilter, String newSearch, String newCheck, boolean newStylesheet)REST HTTP LISTvoidlogin(String newPassword)Stringput(File carFile, boolean async)REST HTTP PUT CARStringput(String xml, boolean async)REST HTTP PUT XML fileLongraiseEvent(String newEventName, String newRaiseComment)Raise an eventStringscriptsList()REST HTTP GET SCRIPTS-LIST This method returns all objects that have editable Redwood Script (JobDefinition, Trigger, ExtensionPoint etc.) either as a source, or via related objects like actions.protected voidstderr(com.redwood.scheduler.tool.messages.Console newConsole)protected voidstdout(com.redwood.scheduler.tool.messages.Console newConsole)protected StringtoRequest(com.redwood.scheduler.tool.messages.CallBase call)protected StringtoRequest(List<com.redwood.scheduler.tool.messages.CallBase> calls)Map<String,BigDecimal>uploadCAR(File carFile, String importRuleSet)Upload a CAR file to the server.Map<String,BigDecimal>uploadCAR(File carFile, String importRuleSet, String targetPartition, Map<String,String> ruleSetParameters)Upload a CAR file to the server.Map<String,BigDecimal>uploadJAR(File jarFile, String libraryName)Upload a JAR file to the server.-
Methods inherited from class com.redwood.scheduler.tool.messages.CallHandler
createCall, handle, handle, handle, handle, handle, handle
-
Methods inherited from class com.redwood.scheduler.tool.util.StandaloneAbstractCallXmlHandler
characters, endElement, getCalls, getMessageIds, startElement
-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
-
-
-
Method Detail
-
login
public void login(String newPassword) throws ToolException, LoginException
- Throws:
ToolExceptionLoginException
-
importCar
public void importCar(File f, String importRuleSet, OutputStreamOutputHandler newStdout, StringBuilderOutputHandler newStderr) throws ToolException, IOException
Description copied from interface:ToolConnectionimport car file- Specified by:
importCarin interfaceToolConnection- Parameters:
f- is the car fileimportRuleSet- is import rule setnewStdout- the handler for stderr.newStderr- the handler for stdout.- Throws:
ToolException- if an exception occurs.IOException- if an IO exception occurs
-
importCar
public void importCar(File f, String importRuleSet, String targetPartition, OutputStreamOutputHandler newStdout, StringBuilderOutputHandler newStderr) throws ToolException, IOException
Description copied from interface:ToolConnectionimport car file- Specified by:
importCarin interfaceToolConnection- Parameters:
f- is the car fileimportRuleSet- is import rule settargetPartition- is import rule setnewStdout- the handler for stderr.newStderr- the handler for stdout.- Throws:
ToolException- if an exception occurs.IOException- if an IO exception occurs
-
executeScript
public Long executeScript(String newScript, OutputHandler newStdout, OutputHandler newStderr) throws ToolException
Description copied from interface:ToolConnectionExecute RedwoodScript.- Specified by:
executeScriptin interfaceToolConnection- Parameters:
newScript- the code to execute (NOT a filename).newStdout- the handler for stderr.newStderr- the handler for stdout.- Returns:
- the return code (may be null).
- Throws:
ToolException- if an exception occurs.
-
raiseEvent
public Long raiseEvent(String newEventName, String newRaiseComment) throws ToolException, EventRaiseException
Description copied from interface:ToolConnectionRaise an event- Specified by:
raiseEventin interfaceToolConnection- Parameters:
newEventName- the name of the event to raise.newRaiseComment- the raise comment, may be null.- Returns:
- the event id.
- Throws:
ToolException- if an exception occurs.EventRaiseException- if the event cannot be raised.
-
stderr
protected void stderr(com.redwood.scheduler.tool.messages.Console newConsole) throws IOException- Specified by:
stderrin classcom.redwood.scheduler.tool.messages.CallHandler- Throws:
IOException
-
stdout
protected void stdout(com.redwood.scheduler.tool.messages.Console newConsole) throws IOException- Specified by:
stdoutin classcom.redwood.scheduler.tool.messages.CallHandler- Throws:
IOException
-
toRequest
protected String toRequest(com.redwood.scheduler.tool.messages.CallBase call)
-
executeQueryString
public String executeQueryString(String query, Map<String,String> options, Map<String,Object> parameters) throws ToolException, QueryException
Description copied from interface:ToolConnectionExecute a query and return the result as a String.- Specified by:
executeQueryStringin interfaceToolConnection- Parameters:
query- the query to executeoptions- options for output (see the documentation for set option value). SeeToolConnection.executeQuery(String, Map, Map)parameters- parameters to query (see the documentation for bind parameter type value). SeeToolConnection.executeQuery(String, Map, Map)- Returns:
- a string representation of the query results.
- Throws:
ToolException- if an exception occursQueryException- if the query caused an error
-
executeQuery
public ToolResultSet executeQuery(String query, Map<String,String> options, Map<String,Object> parameters) throws ToolException, QueryException
Description copied from interface:ToolConnectionExecute a query and return the result as a ToolResultSet.- Specified by:
executeQueryin interfaceToolConnection- Parameters:
query- the query to executeoptions- options for output (see the documentation for set option value).parameters- parameters to query (see the documentation for bind parameter type value). Accepted Java parameter types:- String - for String parameters
- Long - for Integer parameters (the majority of numeric values, including UniqueId)
- BigDecimal - for Numbers (mainly in/out values of job parameters)
- Calendar - for DateTimeZone
import com.redwood.scheduler.api.tool.*; public class Main { public static void main(String [] args) throws Exception { ToolConnection con = ToolConnectionFactory.createConnection(args[0], 60000); ToolResultSet rs = con.executeQuery("select JobDefinition.Name, JobDefinition.UniqueId from JobDefinition", null, null); while (rs.next()) { System.out.println(rs.getString(1) + " = " + rs.getString(2)); } } }- Returns:
- a string representation of the query results.
- Throws:
ToolException- if an exception occursQueryException- if the query caused an error
-
uploadCAR
public Map<String,BigDecimal> uploadCAR(File carFile, String importRuleSet) throws IOException, ToolException
Description copied from interface:ToolConnectionUpload a CAR file to the server.- Specified by:
uploadCARin interfaceToolConnection- Parameters:
carFile- the car file to upload, required.importRuleSet- the import rule set to use, may be null.- Returns:
- a Map containing results from the server. The map will contain the job id of the submitted job, if the server supports it. The result will never be null, but may be an empty map
- Throws:
IOException- if an IO exception occursToolException- if an exception occurs
-
uploadCAR
public Map<String,BigDecimal> uploadCAR(File carFile, String importRuleSet, String targetPartition, Map<String,String> ruleSetParameters) throws IOException, ToolException
Description copied from interface:ToolConnectionUpload a CAR file to the server.- Specified by:
uploadCARin interfaceToolConnection- Parameters:
carFile- the car file to upload, required.importRuleSet- the import rule set to use, may be null.targetPartition- the target partition, may be null.ruleSetParameters- the ruleSet parameters, may be null.- Returns:
- a Map containing results from the server. The map will contain the job id of the submitted job, if the server supports it. The result will never be null, but may be an empty map
- Throws:
IOException- if an IO exception occursToolException- if an exception occurs
-
uploadJAR
public Map<String,BigDecimal> uploadJAR(File jarFile, String libraryName) throws IOException, ToolException
Description copied from interface:ToolConnectionUpload a JAR file to the server.- Specified by:
uploadJARin interfaceToolConnection- Parameters:
jarFile- the jar file to upload, required.libraryName- the library to upload it to, required.- Returns:
- a Map containing results from the server. The map will contain the job id of the submitted job, if the server supports it. The result will never be null, but may be an empty map
- Throws:
IOException- if an IO exception occursToolException- if an exception occurs
-
put
public String put(String xml, boolean async) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP PUT XML file- Specified by:
putin interfaceToolConnection- Parameters:
xml- The XML object to send to the serverasync- (Optional) async=true - do the request asynchronously- Returns:
- the REST Response
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
put
public String put(File carFile, boolean async) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP PUT CAR- Specified by:
putin interfaceToolConnection- Parameters:
carFile- the CAR file to send to the serverasync- (Optional) async=true - do the request asynchronously- Returns:
- the REST Response
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
get
public String get(String newObjectType, String newBusinessKey, boolean search) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP GET- Specified by:
getin interfaceToolConnection- Parameters:
newObjectType- the object type to get from the REST server.newBusinessKey- the key of the object to get from the REST serversearch- if search is true then businessKey is a search pattern to match one or more objects- Returns:
- the XML representation of the object
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
get
public String get(String newObjectType, String newBusinessKey, boolean search, String propertiesSet, Set<String> includeProperties, Set<String> excludeProperties) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP GET- Specified by:
getin interfaceToolConnection- Parameters:
newObjectType- the object type to get from the REST server.newBusinessKey- the key of the object to get from the REST serversearch- if search is true then businessKey is a search pattern to match one or more objectspropertiesSet- is the name of the properties set to include in the returned XMLincludeProperties- are the properties to include on top of the given propertiesSetexcludeProperties- are the properties to elide from the given propertiesSet- Returns:
- the XML representation of the object
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
get
public File get(String newObjectType, String newKey, String filename, String filepath, boolean search) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP GET- Specified by:
getin interfaceToolConnection- Parameters:
newObjectType- the object type to get from the REST server.newKey- the key of the object to get from the REST serverfilename- the name of the file to be returned (optional)filepath- the path to store the file when it is downloadedsearch- if search is true then businessKey is a search pattern to match one or more objects- Returns:
- the CAR file representation of the object
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
list
public String list(String newObjectType, String newFilter, String newSearch, boolean newStylesheet) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP LIST- Specified by:
listin interfaceToolConnection- Parameters:
newObjectType- is the list of objects requestednewFilter- is the name of the query filter to apply when queryingnewSearch- is the search to use (on SearchName)newStylesheet- is to indicate if a stylesheet should be used to render the result. The stylesheet used the Document under path doc:/Redwood/REST/Custom_StyleSheet.xml, if that is not set, the default stylesheet doc:/Redwood/REST/Custom_StyleSheet.xml is used- Returns:
- the list of objects
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
list
public String list(String newObjectType, String newFilter, String newSearch, String newCheck, boolean newStylesheet) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP LIST- Specified by:
listin interfaceToolConnection- Parameters:
newObjectType- is the list of objects requestednewFilter- is the name of the query filter to apply when queryingnewSearch- is the search to use (on SearchName)newCheck- is the name of the action that will be used to check if the object should be returned. This name will be passed into canPerform() and if it return false, it is not returned in the result. If null is passed in, the default "export" will be used, so only exportable objects will be returned. If the value "none" is passed in, no check will be performed.newStylesheet- is to indicate if a stylesheet should be used to render the result. The stylesheet used the Document under path doc:/Redwood/REST/Custom_StyleSheet.xml, if that is not set, the default stylesheet doc:/Redwood/REST/Custom_StyleSheet.xml is used- Returns:
- the list of objects
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
getLibraries
public String getLibraries(String filePath) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP GET API Libraries for local builds- Specified by:
getLibrariesin interfaceToolConnection- Parameters:
filePath- the directory to store the libraries- Returns:
- the version of the server libraries
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
getVersion
public String getVersion() throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP GET Version- Specified by:
getVersionin interfaceToolConnection- Returns:
- the BUILD ID of the server
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
getJobFile
public String getJobFile(String newUniqueId, String newDestination, String defaultName) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP GET JOBFILE Get the jobfile identified by the given uniqueId, and store it in the given directory- Specified by:
getJobFilein interfaceToolConnection- Parameters:
newUniqueId- is the uniqueId of the jobfile that must be retrievednewDestination- is the folder where the file will be written todefaultName- is the name that will be given to the file if the server does not provide with a name.- Returns:
- the name of the file
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
getRestCapabilitiesXML
public String getRestCapabilitiesXML() throws ToolException, IOException
Description copied from interface:ToolConnectionRetrieve the WADL file for the REST servlet. When this returns null, none was found (earlier version), and will not throw an exception, even though the server returned an error code.- Specified by:
getRestCapabilitiesXMLin interfaceToolConnection- Returns:
- the WADL file if one exists
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
scriptsList
public String scriptsList() throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP GET SCRIPTS-LIST This method returns all objects that have editable Redwood Script (JobDefinition, Trigger, ExtensionPoint etc.) either as a source, or via related objects like actions.- Specified by:
scriptsListin interfaceToolConnection- Returns:
- the objects that have editable Redwood Script
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
getScripts
public File getScripts(Set<String> items, String filename, String filepath, boolean includeLibraries) throws ToolException, IOException
Description copied from interface:ToolConnectionREST HTTP POST- Specified by:
getScriptsin interfaceToolConnection- Parameters:
items- is the list of items to fetch from the serverfilename- the name of the file to be returned (optional)filepath- the path to store the file when it is downloadedincludeLibraries- if true, it will also include the libraries that are referenced by the objects being requested.- Returns:
- the CAR file representation of the object
- Throws:
ToolException- if an exception occursIOException- if an IO exception occurs
-
-