diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f66acd1 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.gitignore b/.gitignore index 72beb40..4d310d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # Ignore patterns *~ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..d6fbe59 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + splints-fork_splints + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/lib/java/commons-codec-1.10.jar b/lib/java/commons-codec-1.10.jar new file mode 100644 index 0000000..1d7417c Binary files /dev/null and b/lib/java/commons-codec-1.10.jar differ diff --git a/lib/java/commons-logging-1.2.jar b/lib/java/commons-logging-1.2.jar new file mode 100644 index 0000000..93a3b9f Binary files /dev/null and b/lib/java/commons-logging-1.2.jar differ diff --git a/lib/java/fluent-hc-4.5.5.jar b/lib/java/fluent-hc-4.5.5.jar new file mode 100644 index 0000000..f1495c7 Binary files /dev/null and b/lib/java/fluent-hc-4.5.5.jar differ diff --git a/lib/java/httpclient-4.5.5.jar b/lib/java/httpclient-4.5.5.jar new file mode 100644 index 0000000..7796b0e Binary files /dev/null and b/lib/java/httpclient-4.5.5.jar differ diff --git a/lib/java/httpclient-cache-4.5.5.jar b/lib/java/httpclient-cache-4.5.5.jar new file mode 100644 index 0000000..264dc1c Binary files /dev/null and b/lib/java/httpclient-cache-4.5.5.jar differ diff --git a/lib/java/httpclient-win-4.5.5.jar b/lib/java/httpclient-win-4.5.5.jar new file mode 100644 index 0000000..25574c9 Binary files /dev/null and b/lib/java/httpclient-win-4.5.5.jar differ diff --git a/lib/java/httpcore-4.4.9.jar b/lib/java/httpcore-4.4.9.jar new file mode 100644 index 0000000..e2d3cbf Binary files /dev/null and b/lib/java/httpcore-4.4.9.jar differ diff --git a/lib/java/httpmime-4.5.5.jar b/lib/java/httpmime-4.5.5.jar new file mode 100644 index 0000000..4d3ee66 Binary files /dev/null and b/lib/java/httpmime-4.5.5.jar differ diff --git a/lib/java/javax.json-1.0.jar b/lib/java/javax.json-1.0.jar new file mode 100755 index 0000000..11f8cef Binary files /dev/null and b/lib/java/javax.json-1.0.jar differ diff --git a/lib/java/jna-4.4.0.jar b/lib/java/jna-4.4.0.jar new file mode 100644 index 0000000..521bd92 Binary files /dev/null and b/lib/java/jna-4.4.0.jar differ diff --git a/lib/java/jna-platform-4.4.0.jar b/lib/java/jna-platform-4.4.0.jar new file mode 100644 index 0000000..ce54d8f Binary files /dev/null and b/lib/java/jna-platform-4.4.0.jar differ diff --git a/lib/json.jar b/lib/json.jar new file mode 100644 index 0000000..40a325d Binary files /dev/null and b/lib/json.jar differ diff --git a/src/java/bitbucket/BitbucketIssuesClient.java b/src/java/bitbucket/BitbucketIssuesClient.java new file mode 100644 index 0000000..e86031d --- /dev/null +++ b/src/java/bitbucket/BitbucketIssuesClient.java @@ -0,0 +1,77 @@ +package bitbucket; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + +import org.json.*; + +/** + * + * @author Ziad Yarbouh from soen487-team08 + * + */ +public class BitbucketIssuesClient { + + private static String urlprefix = "https://api.bitbucket.org/1.0/repositories/soen487-w18-08/json-parser-issue-number/issues/"; + + /** + * Get Issue Details given IssueNumber + * + * @param issueNumber + * @throws Exception + */ + public static void getIssueDetails(int issueNumber) throws Exception { + String inumber = Integer.toString(issueNumber); + JSONObject json; + + try { + URL base = new URL(urlprefix); + URL url = new URL(base, inumber); + json = new JSONObject(getText(url)); + // System.out.println(response); + + String[] names = JSONObject.getNames(json); + + for (String str : names) { + if (!str.equals("reported_by")) { + System.out.println(str + ":" + json.get(str)); + } + } + + } catch (MalformedURLException e) { + System.err.println("ERROR: " + e.getMessage()); + } + } + + /** + * Get Text given URL + * + * @param url + * @return response + */ + public static String getText(URL url) { + StringBuilder response = new StringBuilder(); + + try { + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + + while ((inputLine = in.readLine()) != null) + response.append(inputLine); + + in.close(); + + } catch (IOException e) { + System.err.println(e.getMessage()); + } + + return response.toString(); + } + +} diff --git a/src/java/fp/v11/CreateIssue.java b/src/java/fp/v11/CreateIssue.java deleted file mode 100644 index 02aba14..0000000 --- a/src/java/fp/v11/CreateIssue.java +++ /dev/null @@ -1,200 +0,0 @@ -package fp.v11; - -import javax.xml.soap.*; - -public class CreateIssue -{ - - public static void main( String[] args ) - { - - try - { - /* - // Comment this out for NO proxy. - java.util.Properties props = System.getProperties(); - props.put( "http.proxyHost", "localhost" ); - props.put( "http.proxyPort", "8888" ); - */ - - - // Setup SOAP message. - SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); - SOAPConnection connection = scf.createConnection(); - MessageFactory msgFactory = MessageFactory.newInstance(); - SOAPMessage msg = msgFactory.createMessage(); - - SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); - env.addNamespaceDeclaration( "xsi", "http://www.w3.org/1999/XMLSchema-instance" ); - env.addNamespaceDeclaration( "xsd", "http://www.w3.org/1999/XMLSchema" ); - env.addNamespaceDeclaration( "namesp2", "http://xml.apache.org/xml-soap" ); - env.addNamespaceDeclaration( "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/" ); - - - // Compose SOAP body. - SOAPBody body = env.getBody(); - SOAPElement invoke = body.addChildElement( env.createName("MRWebServices__createIssue", "namesp1","MRWebServices") ); - - - SOAPElement arg1 = invoke.addChildElement( env.createName("user") ); - arg1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg1.addTextNode("YOUR_AGENT_USERNAME"); - - SOAPElement arg2 = invoke.addChildElement( env.createName("password") ); - arg2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg2.addTextNode("YOUR_AGENT_PASSWORD"); - - SOAPElement arg3 = invoke.addChildElement( env.createName("extrainfo") ); - arg3.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - - SOAPElement arg4 = invoke.addChildElement( env.createName("args") ); - arg4.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" ); - - SOAPElement arg4_1 = arg4.addChildElement( env.createName("priorityNumber") ); - arg4_1.addAttribute( env.createName("type","xsi",""), "xsd:int" ); - arg4_1.addTextNode("5"); - - SOAPElement arg4_2 = arg4.addChildElement( env.createName("status") ); - arg4_2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_2.addTextNode("Open"); - - SOAPElement arg4_4 = arg4.addChildElement( env.createName("description") ); - arg4_4.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_4.addTextNode("Place issue description here. From Java code."); - - - SOAPElement arg4_5 = arg4.addChildElement( env.createName("Assignees") ); - arg4_5.addAttribute( env.createName("type","xsi",""), "SOAP-ENC:Array" ); - arg4_5.addAttribute( env.createName("arrayType","SOAP-ENC",""), "xsd:string[2]" ); - - SOAPElement arg4_5_1 = arg4_5.addChildElement( env.createName("item") ); - arg4_5_1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_5_1.addTextNode("[YOUR_QUEUE_ASSIGNEE]"); - - //SOAPElement arg4_5_2 = arg4_5.addChildElement( env.createName("item") ); - //arg4_5_2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - //arg4_5_2.addTextNode("user2"); - - - SOAPElement arg4_3 = arg4.addChildElement( env.createName("abfields") ); - arg4_3.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" ); - - /* - SOAPElement arg4_3_1 = arg4_3.addChildElement( env.createName("Custom__bAB__bField__bOne") ); - arg4_3_1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_3_1.addTextNode("Value of Custom AB Field One"); - - SOAPElement arg4_3_2 = arg4_3.addChildElement( env.createName("Last__bName") ); - arg4_3_2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_3_2.addTextNode("Doe"); - - SOAPElement arg4_3_3 = arg4_3.addChildElement( env.createName("First__bName") ); - arg4_3_3.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_3_3.addTextNode("John"); - */ - - SOAPElement arg4_3_4 = arg4_3.addChildElement( env.createName("Email__bAddress") ); - arg4_3_4.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_3_4.addTextNode("USER@EMAIL"); - - - /* - SOAPElement arg4_6 = arg4.addChildElement( env.createName("projfields") ); - arg4_6.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" ); - - SOAPElement arg4_6_1 = arg4_6.addChildElement( env.createName("Custom__bField__bOne") ); - arg4_6_1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_6_1.addTextNode("Value of Custom Field One"); - - SOAPElement arg4_6_2 = arg4_6.addChildElement( env.createName("Custom__bField__bTwo") ); - arg4_6_2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_6_2.addTextNode("Value of Custom Field Two"); - */ - - SOAPElement arg4_7 = arg4.addChildElement( env.createName("projectID") ); - arg4_7.addAttribute( env.createName("type","xsi",""), "xsd:int" ); - arg4_7.addTextNode("PROJECT_ID"); - - SOAPElement arg4_8 = arg4.addChildElement( env.createName("title") ); - arg4_8.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_8.addTextNode("Test Issue Java - Splints"); - - - msg.saveChanges(); - - //System.out.println("Request Message ----------\n"); - //msg.writeTo( System.out ); - - // Make SOAP call - SOAPMessage reply = connection.call( msg, "https://localhost/MRcgi/MRWebServices.pl" ); - - - connection.close(); - - //System.out.println("Reply Message ----------\n"); - //reply.writeTo( System.out ); - - // Get result - SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody(); - - // Check for error - if( replybody.hasFault() ) - { - throw new Exception( replybody.getFault().getFaultString() ); - - } - - - - // Iterate through the result body, extracting information - java.util.Iterator it = replybody.getChildElements(); - while( it.hasNext() ) - { - Object obj = it.next(); - - if( obj instanceof SOAPElement ) - { - SOAPElement ele = (SOAPElement)obj; - String s = ele.getElementName().getLocalName(); - - if( s.equals("MRWebServices__createIssueResponse") ) - { - java.util.Iterator it2 = ele.getChildElements(); - - while( it2.hasNext() ) - { - Object obj2 = it2.next(); - if( obj2 instanceof SOAPElement ) - { - SOAPElement ele2 = (SOAPElement)obj2; - String s2 = ele2.getElementName().getLocalName(); - if( s2.equals("return") ) - { - java.util.Iterator it3 = ele2.getChildElements(); - - while( it3.hasNext() ) - { - Object obj3 = it3.next(); - - if( obj3 instanceof Text ) - { - Text txt = (Text)obj3; - System.out.println( "Issue " + txt.getValue() + " has been created." ); - } - } - } - } - } - } - } - } - } - catch( Exception ex ) - { - ex.printStackTrace(); - } - - System.out.println("Done"); - } - -} diff --git a/src/java/fp/v11/EditIssue.java b/src/java/fp/v11/EditIssue.java deleted file mode 100644 index d176384..0000000 --- a/src/java/fp/v11/EditIssue.java +++ /dev/null @@ -1,120 +0,0 @@ -package fp.v11; - -import javax.xml.soap.*; - -public class EditIssue -{ - - public static void main( String[] args ) - { - - try - { - /* - // Comment this out for NO proxy. - java.util.Properties props = System.getProperties(); - //props.put( "http.proxyHost", "localhost" ); - //props.put( "http.proxyPort", "8888" ); - */ - - // Setup SOAP message. - SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); - SOAPConnection connection = scf.createConnection(); - MessageFactory msgFactory = MessageFactory.newInstance(); - SOAPMessage msg = msgFactory.createMessage(); - - SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); - env.addNamespaceDeclaration( "xsi", "http://www.w3.org/1999/XMLSchema-instance" ); - env.addNamespaceDeclaration( "xsd", "http://www.w3.org/1999/XMLSchema" ); - env.addNamespaceDeclaration( "namesp2", "http://xml.apache.org/xml-soap" ); - env.addNamespaceDeclaration( "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/" ); - - - // Compose SOAP body. - SOAPBody body = env.getBody(); - SOAPElement invoke = body.addChildElement( env.createName("MRWebServices__editIssue", "namesp1","MRWebServices") ); - - SOAPElement arg1 = invoke.addChildElement( env.createName("user") ); - arg1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg1.addTextNode("YOUR_AGENT_USERNAME"); - - SOAPElement arg2 = invoke.addChildElement( env.createName("password") ); - arg2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg2.addTextNode("YOUR_AGENT_PASSWORD"); - - SOAPElement arg3 = invoke.addChildElement( env.createName("extrainfo") ); - arg3.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - - SOAPElement arg4 = invoke.addChildElement( env.createName("args") ); - arg4.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" ); - - SOAPElement arg4_3 = arg4.addChildElement( env.createName("projectID") ); - arg4_3.addAttribute( env.createName("type","xsi",""), "xsd:int" ); - arg4_3.addTextNode("PROJECT_ID"); - - SOAPElement arg4_4 = arg4.addChildElement( env.createName("mrID") ); - arg4_4.addAttribute( env.createName("type","xsi",""), "xsd:int" ); - arg4_4.addTextNode("TICKET_NUMBER"); - - SOAPElement arg4_5 = arg4.addChildElement( env.createName("title") ); - arg4_5.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_5.addTextNode("Test Issue Java - Splints"); - - SOAPElement arg4_6 = arg4.addChildElement( env.createName("description") ); - arg4_6.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_6.addTextNode("Place issue description here. From Java code. End test."); - - /* - SOAPElement arg4_1 = arg4.addChildElement( env.createName("abfields") ); - arg4_1.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" ); - - SOAPElement arg4_1_1 = arg4_1.addChildElement( env.createName("Custom__bAB__bField__bOne") ); - arg4_1_1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_1_1.addTextNode("NEW VALUE FOR Custom AB Field One"); - */ - - /* - SOAPElement arg4_2 = arg4.addChildElement( env.createName("projfields") ); - arg4_2.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" ); - - SOAPElement arg4_2_1 = arg4_2.addChildElement( env.createName("Custom__bField__bTwo") ); - arg4_2_1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); - arg4_2_1.addTextNode("NEW VALUE FOR Custom Field Two"); - */ - - - - msg.saveChanges(); - - //System.out.println("Request Message ----------\n"); - //msg.writeTo( System.out ); - - // Make SOAP call - SOAPMessage reply = connection.call( msg, "https://localhost/MRcgi/MRWebServices.pl" ); - - - connection.close(); - - //System.out.println("Reply Message ----------\n"); - //reply.writeTo( System.out ); - - // Get result - SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody(); - - // Check for error - if( replybody.hasFault() ) - { - throw new Exception( replybody.getFault().getFaultString() ); - } - - System.out.println( "done." ); - - } - catch( Exception ex ) - { - ex.printStackTrace(); - - } - } - -} diff --git a/src/java/fp/v11/Splints.java b/src/java/fp/v11/Splints.java new file mode 100644 index 0000000..c62dbb5 --- /dev/null +++ b/src/java/fp/v11/Splints.java @@ -0,0 +1,17 @@ +package fp.v11; + +public class Splints { + + + public static void main(String args[]) + { + try + { + System.out.println("Hello."); + } + catch(Exception e) + { + System.err.println("ERROR: " + e.getMessage()); + } + } +} diff --git a/src/java/fp/v11/splints/Config.java b/src/java/fp/v11/splints/Config.java new file mode 100644 index 0000000..3db1393 --- /dev/null +++ b/src/java/fp/v11/splints/Config.java @@ -0,0 +1,15 @@ +package fp.v11.splints; + +/** + * Soap and proxy parameters + * @author soen487-w18-team03 + */ +public class Config { + + public static final String SOAP_AGENT_USERNAME = "YOUR_AGENT_USERNAME"; + public static final String SOAP_AGENT_PASSWORD = "YOUR_AGENT_PASSWORD"; + public static final String BASE_URL = "https://localhost"; + public static final String PROXY_HOST = "localhost"; + public static final String PROXY_PORT = "8888"; + +} diff --git a/src/java/fp/v11/splints/Constants.java b/src/java/fp/v11/splints/Constants.java new file mode 100644 index 0000000..35ea864 --- /dev/null +++ b/src/java/fp/v11/splints/Constants.java @@ -0,0 +1,32 @@ +package fp.v11.splints; + +/** + * + * @author Vincent Fugnitto from soen487-w18-team08 + * + */ +public class Constants { + + /* Fields */ + + static final String WORKSPACE = "projectID"; + static final String ISSUE = "mrID"; + static final String ISSUE_SUBJECT = "title"; + static final String ISSUE_STATUS = "status"; + static final String CONTACT_FIRST_NAME = "First__bName"; + static final String CONTACT_LAST_NAME = "Last__bName"; + static final String CONTACT_EMAIL = "Email__bAddress"; + static final String SUBMITTER = "submitter"; + static final String ASSIGNEES = "assignees"; + static final String PRIORITY_NUMBER = "priorityNumber"; + static final String DESCRIPTION = "description"; + + /* Custom Fields */ + + static final String IMPACT = "Impact"; + static final String URGENCY = "Urgency"; + static final String CONTACT_METHOD = "Contact__bMethod"; + static final String TICKET_TYPE = "Type__bof_bTicket"; + static final String SERVICE_CATGORY = "Service__bCategory"; + static final String SERVICE_NAME = "Service__bName"; +} diff --git a/src/java/fp/v11/splints/FootPrints11.java b/src/java/fp/v11/splints/FootPrints11.java new file mode 100644 index 0000000..ef1fc5e --- /dev/null +++ b/src/java/fp/v11/splints/FootPrints11.java @@ -0,0 +1,620 @@ +package fp.v11.splints; + +import java.util.Collection; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPBody; +import javax.xml.soap.SOAPConnection; +import javax.xml.soap.SOAPConnectionFactory; +import javax.xml.soap.SOAPElement; +import javax.xml.soap.SOAPEnvelope; +import javax.xml.soap.SOAPMessage; +import javax.xml.soap.Text; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * + * @author soen487-w18-team03 + * @author Vincent Fugnitto from soen487-w18-team08 + */ +public class FootPrints11 implements ISplints { + + @Override + public String createIssue() { + String priorityNumber = "5"; + String status = "Open"; + String description = "Place issue description here. From Java code."; + String assignee = "[YOUR_QUEUE_ASSIGNEE]"; + String emailBAddress = "USER@EMAIL"; + String projectId = "PROJECT_ID"; + String title = "Test Issue Java - Splints"; + + //Optional Parameters + String customFieldOne = "Value of Custom Field One"; + String customFieldTwo = "Value of Custom Field Two"; + String item = "user2"; + String customABFieldOne = "Value of Custom AB Field One"; + String firstBName = "John"; + String lastBName = "Doe"; + + String ticketNumber = "0"; + try { + /* + // Comment this out for NO proxy. + java.util.Properties props = System.getProperties(); + props.put( "http.proxyHost", Config.PROXY_HOST ); + props.put( "http.proxyPort", Config.PROXY_PORT ); + */ + + // Setup SOAP message. + SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); + SOAPConnection connection = scf.createConnection(); + MessageFactory msgFactory = MessageFactory.newInstance(); + SOAPMessage msg = msgFactory.createMessage(); + + SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); + env.addNamespaceDeclaration("xsi", "http://www.w3.org/1999/XMLSchema-instance"); + env.addNamespaceDeclaration("xsd", "http://www.w3.org/1999/XMLSchema"); + env.addNamespaceDeclaration("namesp2", "http://xml.apache.org/xml-soap"); + env.addNamespaceDeclaration("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"); + + // Compose SOAP body. + SOAPBody body = env.getBody(); + SOAPElement invoke = body + .addChildElement(env.createName("MRWebServices__createIssue", "namesp1", "MRWebServices")); + + SOAPElement arg1 = invoke.addChildElement(env.createName("user")); + arg1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg1.addTextNode(Config.SOAP_AGENT_USERNAME); + + SOAPElement arg2 = invoke.addChildElement(env.createName("password")); + arg2.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg2.addTextNode(Config.SOAP_AGENT_USERNAME); + + SOAPElement arg3 = invoke.addChildElement(env.createName("extrainfo")); + arg3.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + + SOAPElement arg4 = invoke.addChildElement(env.createName("args")); + arg4.addAttribute(env.createName("type", "xsi", ""), "namesp2:SOAPStruct"); + + SOAPElement arg4_1 = arg4.addChildElement(env.createName("priorityNumber")); + arg4_1.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4_1.addTextNode(priorityNumber); + + SOAPElement arg4_2 = arg4.addChildElement(env.createName("status")); + arg4_2.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_2.addTextNode(status); + + SOAPElement arg4_4 = arg4.addChildElement(env.createName("description")); + arg4_4.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_4.addTextNode(description); + + SOAPElement arg4_5 = arg4.addChildElement(env.createName("Assignees")); + arg4_5.addAttribute(env.createName("type", "xsi", ""), "SOAP-ENC:Array"); + arg4_5.addAttribute(env.createName("arrayType", "SOAP-ENC", ""), "xsd:string[2]"); + + SOAPElement arg4_5_1 = arg4_5.addChildElement(env.createName("item")); + arg4_5_1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_5_1.addTextNode(assignee); + + //SOAPElement arg4_5_2 = arg4_5.addChildElement( env.createName("item") ); + //arg4_5_2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); + //arg4_5_2.addTextNode(item); + SOAPElement arg4_3 = arg4.addChildElement(env.createName("abfields")); + arg4_3.addAttribute(env.createName("type", "xsi", ""), "namesp2:SOAPStruct"); + + /* + SOAPElement arg4_3_1 = arg4_3.addChildElement( env.createName("Custom__bAB__bField__bOne") ); + arg4_3_1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); + arg4_3_1.addTextNode(customABFieldOne); + + SOAPElement arg4_3_2 = arg4_3.addChildElement( env.createName("Last__bName") ); + arg4_3_2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); + arg4_3_2.addTextNode(lastBName); + + SOAPElement arg4_3_3 = arg4_3.addChildElement( env.createName("First__bName") ); + arg4_3_3.addAttribute( env.createName("type","xsi",""), "xsd:string" ); + arg4_3_3.addTextNode(firstBName); + */ + SOAPElement arg4_3_4 = arg4_3.addChildElement(env.createName("Email__bAddress")); + arg4_3_4.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_3_4.addTextNode(emailBAddress); + + /* + SOAPElement arg4_6 = arg4.addChildElement( env.createName("projfields") ); + arg4_6.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" ); + + SOAPElement arg4_6_1 = arg4_6.addChildElement( env.createName("Custom__bField__bOne") ); + arg4_6_1.addAttribute( env.createName("type","xsi",""), "xsd:string" ); + arg4_6_1.addTextNode(customFieldOne); + + SOAPElement arg4_6_2 = arg4_6.addChildElement( env.createName("Custom__bField__bTwo") ); + arg4_6_2.addAttribute( env.createName("type","xsi",""), "xsd:string" ); + arg4_6_2.addTextNode(customFieldTwo); + */ + SOAPElement arg4_7 = arg4.addChildElement(env.createName("projectID")); + arg4_7.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4_7.addTextNode(projectId); + + SOAPElement arg4_8 = arg4.addChildElement(env.createName("title")); + arg4_8.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_8.addTextNode(title); + + msg.saveChanges(); + + //System.out.println("Request Message ----------\n"); + //msg.writeTo( System.out ); + // Make SOAP call + SOAPMessage reply = connection.call(msg, Config.BASE_URL + "/MRcgi/MRWebServices.pl"); + + connection.close(); + + //System.out.println("Reply Message ----------\n"); + //reply.writeTo( System.out ); + // Get result + SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody(); + + // Check for error + if (replybody.hasFault()) { + throw new Exception(replybody.getFault().getFaultString()); + + } + + // Iterate through the result body, extracting information + java.util.Iterator it = replybody.getChildElements(); + while (it.hasNext()) { + Object obj = it.next(); + + if (obj instanceof SOAPElement) { + SOAPElement ele = (SOAPElement) obj; + String s = ele.getElementName().getLocalName(); + + if (s.equals("MRWebServices__createIssueResponse")) { + java.util.Iterator it2 = ele.getChildElements(); + + while (it2.hasNext()) { + Object obj2 = it2.next(); + if (obj2 instanceof SOAPElement) { + SOAPElement ele2 = (SOAPElement) obj2; + String s2 = ele2.getElementName().getLocalName(); + if (s2.equals("return")) { + java.util.Iterator it3 = ele2.getChildElements(); + + while (it3.hasNext()) { + Object obj3 = it3.next(); + + if (obj3 instanceof Text) { + Text txt = (Text) obj3; + ticketNumber = txt.getValue(); + System.out.println("Issue " + ticketNumber + " has been created."); + } + } + } + } + } + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + System.out.println("Done"); + return ticketNumber; + } + + @Override + public NodeList getIssueDetails() { + String projectId = "PROJECT_ID"; + String ticketNumber = "TICKET_NUMBER"; + NodeList result = null; + + try { + /* + // Comment this out for NO proxy. + java.util.Properties props = System.getProperties(); + props.put( "http.proxyHost", Config.PROXY_HOST ); + props.put( "http.proxyPort", Config.PROXY_PORT ); + */ + + // Setup SOAP message. + SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); + SOAPConnection connection = scf.createConnection(); + MessageFactory msgFactory = MessageFactory.newInstance(); + SOAPMessage msg = msgFactory.createMessage(); + + SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); + env.addNamespaceDeclaration("xsi", "http://www.w3.org/1999/XMLSchema-instance"); + env.addNamespaceDeclaration("xsd", "http://www.w3.org/1999/XMLSchema"); + env.addNamespaceDeclaration("namesp2", "http://xml.apache.org/xml-soap"); + env.addNamespaceDeclaration("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"); + + // Compose SOAP body. + SOAPBody body = env.getBody(); + SOAPElement invoke = body + .addChildElement(env.createName("MRWebServices__getIssueDetails", "namesp1", "MRWebServices")); + + SOAPElement arg1 = invoke.addChildElement(env.createName("user")); + arg1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg1.addTextNode(Config.SOAP_AGENT_USERNAME); + + SOAPElement arg2 = invoke.addChildElement(env.createName("password")); + arg2.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg2.addTextNode(Config.SOAP_AGENT_PASSWORD); + + SOAPElement arg3 = invoke.addChildElement(env.createName("extrainfo")); + arg3.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + + SOAPElement arg4 = invoke.addChildElement(env.createName("projectID")); + arg4.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4.addTextNode(projectId); + + SOAPElement arg5 = invoke.addChildElement(env.createName("mrid")); + arg5.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg5.addTextNode(ticketNumber); + + msg.saveChanges(); + + //System.out.println("Request Message ----------\n"); + //msg.writeTo( System.out ); + // Make SOAP call + SOAPMessage reply = connection.call(msg, Config.BASE_URL + "/MRcgi/MRWebServices.pl"); + + connection.close(); + + //System.out.println("Reply Message ----------\n"); + //reply.writeTo( System.out ); + // Get result + SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody(); + + // Check for error + if (replybody.hasFault()) { + throw new Exception(replybody.getFault().getFaultString()); + + } + DumpSOAPElement(replybody, 0); + result = replybody.getChildNodes(); + + } catch (Exception ex) { + + ex.printStackTrace(); + + } + + System.out.println("Done"); + return result; + } + + @Override + public NodeList linkIssues() { + String linkType = "LINK_TYPE"; + String projectId1 = "PROJECT_ID1"; + String ticketNumber1 = "TICKET_NUMBER1"; + String projectId2 = "PROJECT_ID2"; + String ticketNumber2 = "TICKET_NUMBER2"; + NodeList result = null; + + try { + /* + // Comment this out for NO proxy. + java.util.Properties props = System.getProperties(); + props.put( "http.proxyHost", Config.PROXY_HOST ); + props.put( "http.proxyPort", Config.PROXY_PORT ); + */ + + // Setup SOAP message. + SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); + SOAPConnection connection = scf.createConnection(); + MessageFactory msgFactory = MessageFactory.newInstance(); + SOAPMessage msg = msgFactory.createMessage(); + + SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); + env.addNamespaceDeclaration("xsi", "http://www.w3.org/1999/XMLSchema-instance"); + env.addNamespaceDeclaration("xsd", "http://www.w3.org/1999/XMLSchema"); + env.addNamespaceDeclaration("namesp2", "http://xml.apache.org/xml-soap"); + env.addNamespaceDeclaration("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"); + + // Compose SOAP body. + SOAPBody body = env.getBody(); + SOAPElement invoke = body + .addChildElement(env.createName("MRWebServices__linkIssues", "namesp1", "MRWebServices")); + + SOAPElement arg1 = invoke.addChildElement(env.createName("user")); + arg1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg1.addTextNode(Config.SOAP_AGENT_USERNAME); + + SOAPElement arg2 = invoke.addChildElement(env.createName("password")); + arg2.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg2.addTextNode(Config.SOAP_AGENT_PASSWORD); + + SOAPElement arg3 = invoke.addChildElement(env.createName("extrainfo")); + arg3.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + + SOAPElement arg4 = invoke.addChildElement(env.createName("args")); + arg4.addAttribute(env.createName("type", "xsi", ""), "namesp2:SOAPStruct"); + + SOAPElement arg4_1 = arg4.addChildElement(env.createName("linkType")); + arg4_1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_1.addTextNode(linkType); + + SOAPElement arg4_2 = arg4.addChildElement(env.createName("issue1")); + arg4_2.addAttribute(env.createName("type", "xsi", ""), "namesp2:SOAPStruct"); + + SOAPElement arg4_2_1 = arg4_2.addChildElement(env.createName("projectID")); + arg4_2_1.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4_2_1.addTextNode(projectId1); + + SOAPElement arg4_2_2 = arg4_2.addChildElement(env.createName("mrID")); + arg4_2_2.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4_2_2.addTextNode(ticketNumber1); + + SOAPElement arg4_3 = arg4.addChildElement(env.createName("issue2")); + arg4_3.addAttribute(env.createName("type", "xsi", ""), "namesp2:SOAPStruct"); + + SOAPElement arg4_3_1 = arg4_3.addChildElement(env.createName("projectID")); + arg4_3_1.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4_3_1.addTextNode(projectId2); + + SOAPElement arg4_3_2 = arg4_3.addChildElement(env.createName("mrID")); + arg4_3_2.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4_3_2.addTextNode(ticketNumber2); + + msg.saveChanges(); + + //System.out.println("Request Message ----------\n"); + //msg.writeTo( System.out ); + // Make SOAP call + SOAPMessage reply = connection.call(msg, Config.BASE_URL + "/MRcgi/MRWebServices.pl"); + + connection.close(); + + //System.out.println("Reply Message ----------\n"); + //reply.writeTo( System.out ); + // Get result + SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody(); + result = replybody.getChildNodes(); + // Check for error + if (replybody.hasFault()) { + throw new Exception(replybody.getFault().getFaultString()); + + } + + if (replybody.getValue() != null) { + System.out.println(String.format("Link %s %s:$s -> %s:%s is successful.\n", linkType, ticketNumber1, + projectId1, ticketNumber2, projectId2)); + } else { + System.out.println(String.format("Link %s %s:$s -> %s:%s failed.\n", linkType, ticketNumber1, + projectId1, ticketNumber2, projectId2)); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + return result; + } + + /** + * Prints soap element names + */ + private void DumpSOAPElement(SOAPElement el, int indent) throws Exception { + java.util.Iterator it = el.getChildElements(); + + while (it.hasNext()) { + String indstr = GetIndent(indent); + Object obj = it.next(); + + if (obj instanceof SOAPElement) { + SOAPElement ele = (SOAPElement) obj; + System.out.println(indstr + "-----------------------------"); + System.out.println(indstr + ele.getElementName().getLocalName()); + System.out.println(indstr + "-----------------------------"); + DumpSOAPElement(ele, indent + 4); + + } else if (obj instanceof Text) { + Text txt = (Text) obj; + System.out.println(indstr + txt.getValue() + "\n"); + + } + } + } + + + /** + * Gets indent for printing + */ + private String GetIndent(int num) { + String s = ""; + + for (int i = 0; i < num; i++) { + s = s + " "; + } + + return s; + } + + + /* (non-Javadoc) + * @see fp.v11.splints.ISplints#editIssue() + */ + @Override + public void editIssue() { + + try { + java.util.Properties props = System.getProperties(); + props.put("http.proxyHost", "localhost"); + props.put("http.proxyPort", "8888"); + + // Setup SOAP message. + SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); + SOAPConnection connection = scf.createConnection(); + MessageFactory msgFactory = MessageFactory.newInstance(); + SOAPMessage msg = msgFactory.createMessage(); + SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); + env.addNamespaceDeclaration("xsi", "http://www.w3.org/1999/XMLSchema-instance"); + env.addNamespaceDeclaration("xsd", "http://www.w3.org/1999/XMLSchema"); + env.addNamespaceDeclaration("namesp2", "http://xml.apache.org/xml-soap"); + env.addNamespaceDeclaration("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"); + + // Compose SOAP body. + SOAPBody body = env.getBody(); + SOAPElement invoke = body + .addChildElement(env.createName("MRWebServices__editIssue", "namesp1", "MRWebServices")); + + SOAPElement arg1 = invoke.addChildElement(env.createName("user")); + arg1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg1.addTextNode("WebServices"); + + SOAPElement arg2 = invoke.addChildElement(env.createName("password")); + arg2.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg2.addTextNode("fakepassword"); + + SOAPElement arg3 = invoke.addChildElement(env.createName("extrainfo")); + arg3.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + + SOAPElement arg4 = invoke.addChildElement(env.createName("args")); + arg4.addAttribute(env.createName("type", "xsi", ""), "namesp2:SOAPStruct"); + + SOAPElement arg4_1 = arg4.addChildElement(env.createName("abfields")); + arg4_1.addAttribute(env.createName("type", "xsi", ""), "namesp2:SOAPStruct"); + + SOAPElement arg4_1_1 = arg4_1.addChildElement(env.createName("Custom__bAB__bField__bOne")); + arg4_1_1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_1_1.addTextNode("NEW VALUE FOR Custom AB Field One"); + + SOAPElement arg4_2 = arg4.addChildElement(env.createName("projfields")); + arg4_2.addAttribute(env.createName("type", "xsi", ""), "namesp2:SOAPStruct"); + + SOAPElement arg4_2_1 = arg4_2.addChildElement(env.createName("Custom__bField__bTwo")); + arg4_2_1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_2_1.addTextNode("NEW VALUE FOR Custom Field Two"); + + SOAPElement arg4_3 = arg4.addChildElement(env.createName("title")); + arg4_3.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4_3.addTextNode("NEW title is here."); + + SOAPElement arg4_4 = arg4.addChildElement(env.createName("projectID")); + arg4_4.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4_4.addTextNode("78"); + + SOAPElement arg4_5 = arg4.addChildElement(env.createName("mrID")); + arg4_5.addAttribute(env.createName("type", "xsi", ""), "xsd:int"); + arg4_5.addTextNode("40"); + + msg.saveChanges(); + + // Make SOAP call + SOAPMessage reply = connection.call(msg, "http://fakeserver/MRcgi/MRWebServices.pl"); + connection.close(); + + // Get result + SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody(); + + // Check for error + if (replybody.hasFault()) { + throw new Exception(replybody.getFault().getFaultString()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /* (non-Javadoc) + * @see fp.v11.splints.ISplints#getIndent(int) + */ + @Override + public String getIndent(int num) { + String s = ""; + for (int i = 0; i < num; i++) { + s = s + " "; + } + return s; + } + + /* (non-Javadoc) + * @see fp.v11.splints.ISplints#dumpSOAPElement(javax.xml.soap.SOAPElement, int) + */ + @Override + public void dumpSOAPElement(SOAPElement el, int indent) throws Exception { + java.util.Iterator it = el.getChildElements(); + while (it.hasNext()) { + String indstr = getIndent(indent); + Object obj = it.next(); + + if (obj instanceof SOAPElement) { + SOAPElement ele = (SOAPElement) obj; + System.out.println(indstr + "-----------------------------"); + System.out.println(indstr + ele.getElementName().getLocalName()); + System.out.println(indstr + "-----------------------------"); + dumpSOAPElement(ele, indent + 4); + } + + else if (obj instanceof Text) { + Text txt = (Text) obj; + System.out.println(indstr + txt.getValue() + "\n"); + } + } + } + + /* (non-Javadoc) + * @see fp.v11.splints.ISplints#queryIssues() + */ + @Override + public void queryIssues() { + try { + // Comment this out for NO proxy. + java.util.Properties props = System.getProperties(); + props.put("http.proxyHost", "localhost"); + props.put("http.proxyPort", "8888"); + + // Setup SOAP message. + SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); + SOAPConnection connection = scf.createConnection(); + MessageFactory msgFactory = MessageFactory.newInstance(); + SOAPMessage msg = msgFactory.createMessage(); + + SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); + env.addNamespaceDeclaration("xsi", "http://www.w3.org/1999/XMLSchema-instance"); + env.addNamespaceDeclaration("xsd", "http://www.w3.org/1999/XMLSchema"); + env.addNamespaceDeclaration("namesp2", "http://xml.apache.org/xml-soap"); + env.addNamespaceDeclaration("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/"); + + // Compose SOAP body. + SOAPBody body = env.getBody(); + SOAPElement invoke = body + .addChildElement(env.createName("MRWebServices__search", "namesp1", "MRWebServices")); + + SOAPElement arg1 = invoke.addChildElement(env.createName("user")); + arg1.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg1.addTextNode("WebServices"); + + SOAPElement arg2 = invoke.addChildElement(env.createName("password")); + arg2.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg2.addTextNode("root"); + + SOAPElement arg3 = invoke.addChildElement(env.createName("extrainfo")); + arg3.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + + SOAPElement arg4 = invoke.addChildElement(env.createName("query")); + arg4.addAttribute(env.createName("type", "xsi", ""), "xsd:string"); + arg4.addTextNode("select mrID, mrTITLE from MASTER78 WHERE mrTITLE LIKE '%of%'"); + + msg.saveChanges(); + // System.out.println("Request Message ----------\n"); + // msg.writeTo( System.out ); + // Make SOAP call + SOAPMessage reply = connection.call(msg, "http://virgo/MRcgi/MRWebServices.pl"); + connection.close(); + // System.out.println("Reply Message ----------\n"); + // reply.writeTo( System.out ); + // Get result + SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody(); + // Check for error + if (replybody.hasFault()) { + throw new Exception(replybody.getFault().getFaultString()); + } + dumpSOAPElement(replybody, 0); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/src/java/fp/v11/splints/HardcodedCredentialsProvider.java b/src/java/fp/v11/splints/HardcodedCredentialsProvider.java new file mode 100644 index 0000000..1bb8527 --- /dev/null +++ b/src/java/fp/v11/splints/HardcodedCredentialsProvider.java @@ -0,0 +1,29 @@ +package fp.v11.splints; + +/** + * HardcodedCredentialsProvider provides getters for + * hard-coded user credentials + * (USERNAME, PASSWORD) + * + * @author soen487-w18-team08 + * + */ +public class HardcodedCredentialsProvider { + + /** + * Get Hard Coded User + * @return "hardcodeduser" + */ + public String getUsername() { + return "hardcodeduser"; + } + + /** + * Get Hard Coded Password + * @return "hardcodedpass" + */ + public String getPassword() { + return "hardcodedpass"; + } + +} diff --git a/src/java/fp/v11/splints/ISplints.java b/src/java/fp/v11/splints/ISplints.java new file mode 100644 index 0000000..d4844e2 --- /dev/null +++ b/src/java/fp/v11/splints/ISplints.java @@ -0,0 +1,58 @@ +package fp.v11.splints; + +import javax.xml.soap.SOAPElement; +import org.w3c.dom.NodeList; + +/** + * ISplints Interface + * Interface for interacting with Splints + * + * @author soen487-w18-team03 + * @author Vincent Fugnitto from soen487-team08 + */ +public interface ISplints { + + /** + * Creates an issue + * @return Ticket Number + */ + public String createIssue(); + + /** + * Gets issue details + * + */ + public NodeList getIssueDetails(); + + /** + * Links two issues + * + */ + public NodeList linkIssues(); + + /** + * Edit Issue + */ + void editIssue(); + + /** + * Get Indent + * @param num + * @return indent + */ + String getIndent(int num); + + /** + * Dump SOAP Element + * @param el + * @param indent + * @throws Exception + */ + void dumpSOAPElement(SOAPElement el, int indent) throws Exception; + + /** + * Query Issues + */ + void queryIssues(); +} + diff --git a/src/java/fp/v11/splints/PromptCredentialsProvider.java b/src/java/fp/v11/splints/PromptCredentialsProvider.java new file mode 100644 index 0000000..1f70eee --- /dev/null +++ b/src/java/fp/v11/splints/PromptCredentialsProvider.java @@ -0,0 +1,63 @@ +package fp.v11.splints; + +import java.io.Console; +import java.io.IOError; +import java.util.Scanner; + +/** + * PromptCredentialsProvider asks for username and password instead of + * hard-coding them. A primitive implementation. + * @author soen487-w18-team03 + */ +public class PromptCredentialsProvider { + + private final Console console; + private final Scanner scanner; + public static final String USERNAME_INPUT_TEXT = "Your username: "; + public static final String PASSWORD_INPUT_TEXT = "Your password: "; + + public PromptCredentialsProvider() { + this.scanner = new Scanner(System.in); + this.console = System.console(); + } + + /** + * Prompts user for username + * @return String + */ + public String getUsername() { + String username = null; + if (console != null) { + try { + username = String.valueOf(console.readLine(USERNAME_INPUT_TEXT)); + } catch (IOError error) { + error.printStackTrace(); + } + + } else { + System.out.println(USERNAME_INPUT_TEXT); + username = scanner.nextLine(); + } + return username; + } + + /** + * Prompts user for password + * @return String + */ + public String getPassword() { + String password = null; + if (console != null) { + try { + password = String.valueOf(console.readPassword(PASSWORD_INPUT_TEXT)); + } catch (IOError error) { + error.printStackTrace(); + } + + } else { + System.out.println(PASSWORD_INPUT_TEXT); + password = scanner.nextLine(); + } + return password; + } +} diff --git a/src/java/fp/v11/splints.java b/src/java/fp/v11/splints/splints.java similarity index 89% rename from src/java/fp/v11/splints.java rename to src/java/fp/v11/splints/splints.java index af9bb28..d6b1538 100644 --- a/src/java/fp/v11/splints.java +++ b/src/java/fp/v11/splints/splints.java @@ -1,4 +1,4 @@ -package fp.v11; +package fp.v11.splints; public class splints { diff --git a/src/java/fp/v12/FootPrints12.java b/src/java/fp/v12/FootPrints12.java new file mode 100644 index 0000000..6e9774e --- /dev/null +++ b/src/java/fp/v12/FootPrints12.java @@ -0,0 +1,113 @@ +package fp.v12; + +public class FootPrints12 implements FootPrints12Interface { + + + @Override + public void createItem() { + //To implement + } + + @Override + public int getItemId() { + //To implement + return 0; + } + + @Override + public void editItem() { + //To implement + } + + @Override + public void linkItems() { + //To implement + } + + @Override + public void createTicket() { + //To implement + } + + @Override + public void createTicketAndLinkAssets() { + //To implement + } + + @Override + public String getTicketDetails() { + //To implement + return null; + } + + @Override + public void editTicket() { + //To implement + } + + @Override + public void linkTickets() { + //To implement + } + + @Override + public void createContact() { + //To implement + } + + @Override + public void createOrEditContact() { + //To implement + } + + @Override + public String getContactAssociatedTickets() { + //To implement + return null; + } + + @Override + public void editContact() { + //To implement + } + + @Override + public void createCI() { + //To implement + } + + @Override + public void editCI() { + //To implement + } + + @Override + public void listContainerDefinitions() { + //To implement + } + + @Override + public void listItemDefinitions() { + //To implement + } + + @Override + public void listFieldDefinitions() { + //To implement + } + + @Override + public void listQuickTemplates() { + //To implement + } + + @Override + public void listSearches() { + //To implement + } + + @Override + public void runSearch() { + //To implement + } +} diff --git a/src/java/fp/v12/FootPrints12Interface.java b/src/java/fp/v12/FootPrints12Interface.java new file mode 100644 index 0000000..486675c --- /dev/null +++ b/src/java/fp/v12/FootPrints12Interface.java @@ -0,0 +1,74 @@ +package fp.v12; + +/** + * Describes the services offered by + * FootPrint version 12 + */ +public interface FootPrints12Interface { + + /** + * ITEM OPERATIONS + */ + void createItem(); + + int getItemId(); + + void editItem(); + + void linkItems(); + + /** + * TICKET OPERATIONS + */ + + void createTicket(); + + void createTicketAndLinkAssets(); + + String getTicketDetails(); + + void editTicket(); + + void linkTickets(); + + /** + * CONTACT OPERATIONS + */ + void createContact(); + + void createOrEditContact(); + + String getContactAssociatedTickets(); + + void editContact(); + + /** + * CI OPERATIONS + */ + void createCI(); + + void editCI(); + + /** + * LIST OPERATIONS + */ + + void listContainerDefinitions(); + + void listItemDefinitions(); + + void listFieldDefinitions(); + + void listQuickTemplates(); + + void listSearches(); + + /** + * SEARCH OPERATION + */ + + void runSearch(); + + + +} diff --git a/src/java/github/GitHub.java b/src/java/github/GitHub.java new file mode 100644 index 0000000..e188d90 --- /dev/null +++ b/src/java/github/GitHub.java @@ -0,0 +1,85 @@ + /** + * Simple JSON reader parser client (GET) for GitHub + * Usage: https://bitbucket.org/soen487-w18-03/soen487-w18-team03/issues/8/github-json-parser + */ + +package github; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import javax.json.*; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.JsonString; + + +public class GitHub { + + // To be merged with Constant file + static final String api = "https://api.github.com/repos/"; + static final String workspace = "NAG-DevOps/splints/"; + static final int issue = 1; + String issue_subject = ""; + String issue_status = ""; + String submitter = ""; + String assignees = ""; + String priority_number = ""; + String description = ""; + + public static void main(String args[]) { + getIssueDetails(issue); + } + + public static void getIssueDetails(int piIssueNumber) { + try { + URL base = new URL(api); + URL url = new URL(base, workspace + "issues/" + piIssueNumber); + String response = sendGet(url); + System.out.println(response); + JsonObject object = getJsonObject(response); + JsonString title = (JsonString) object.get("title"); + System.out.println("Issue title : "+title.getString()); + } catch (MalformedURLException e) { + System.err.println("ERROR: " + e.getMessage()); + } + } + + /** + * This method convert JSon String into JSon Object + * @param response + */ + public static JsonObject getJsonObject(String response) { + JsonObject object; + try (JsonReader jsonReader = Json.createReader(new StringReader(response))) { + object = jsonReader.readObject(); + } + return object; + } + + /** + * This method should later be merged into an utility package containing all HTTP requests + * This method send a HTTP GET request to the given URL + * @param url + */ + public static String sendGet(URL url) { + StringBuilder result = new StringBuilder(); + try { + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String line; + while ((line = rd.readLine()) != null) { + result.append(line); + } + } catch (IOException e) { + System.out.println(e.getMessage()); + } + return result.toString(); + } + +} diff --git a/src/java/rt/RTEditTicket.java b/src/java/rt/RTEditTicket.java new file mode 100644 index 0000000..6308296 --- /dev/null +++ b/src/java/rt/RTEditTicket.java @@ -0,0 +1,94 @@ +package rt; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * Edit Ticket Utility for RT + * + * @author Kenneth Serrano and Vincent Fugnitto from soen487-team08 + * + */ +public class RTEditTicket { + + private static final String USER_AGENT = "Mozilla/5.0"; + private static final String HOSTNAME = "localhost"; + + /** + * Test Runner for Edit Ticket + * + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + String username = "user"; + String password = "pwd"; + String content = "test"; + int ticketId = 1; + editTicket(HOSTNAME, username, password, ticketId, content); + } + + /** + * Edit RT Ticket + * + * @param username + * @param password + * @param ticketId + * @param content + */ + public static void editTicket(String host, String username, String password, int ticketId, String content) { + String url = "http://" + host + "/REST/1.0/ticket/" + ticketId + "/edit?user=" + username + "&pass=" + password + ""; + String postData = "AdminCc: userX\nText: This is a REST test edit ticket\n"; + try { + sendPost(url, postData); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Send Post HTTP Request + * + * @param url + * @param params + * @return + * @throws Exception + */ + private static void sendPost(String url, String params) throws Exception { + + // open URL connection + URL obj = new URL(url); + HttpURLConnection con = (HttpURLConnection) obj.openConnection(); + + // add request header + con.setRequestMethod("POST"); + con.setRequestProperty("User-Agent", USER_AGENT); + con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); + con.setDoOutput(true); + + // add content + DataOutputStream w = new DataOutputStream(con.getOutputStream()); + w.writeBytes(params); + w.flush(); + w.close(); + + // get response code + int responseCode = con.getResponseCode(); + System.out.println("Response Code: " + responseCode); + + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + // print result + System.out.println(response.toString()); + } +} diff --git a/src/java/rt/RtCreateIssue.java b/src/java/rt/RtCreateIssue.java new file mode 100644 index 0000000..93c8eb7 --- /dev/null +++ b/src/java/rt/RtCreateIssue.java @@ -0,0 +1,90 @@ +package rt; + +import java.io.IOException; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; + +public class RtCreateIssue { + + // Constants will be retrieved/merged from the Config/Constants file further into the project + static final String HOSTNAME = ""; // Required RT Rest host name from server + static final String BASE_URI = "http://"+HOSTNAME+"/REST/1.0"; + + public static void main(String[] args) throws Exception { + + String url = BASE_URI +"/ticket/new?user=username&pass=password"; + + // POST request with the given URI + HttpPost httppost = sendPost(url); + + // Execute and get the response + HttpEntity resEntity = getResponse(httppost); + + // Obtain the content details from response + getResponseDetails(resEntity); + + } + /** + * This method sends a HTTP POST request to the given url + * @param url + */ + public static HttpPost sendPost(String url){ + + HttpPost httppost = new HttpPost(url); + // Request parameters and other properties + try { + StringBody content = new StringBody("Subject: Test\nQueue: General",ContentType.TEXT_PLAIN); // Content variable with key value pairs + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.addPart("content", content); + httppost.setEntity(builder.build()); + System.out.println("Request: " + httppost.getRequestLine()+"\n"); + } + catch (Exception e){ + System.out.println(e.getMessage()); + } + return httppost; + + } + /** + * This method retrieves the response from the HTTP POST request + * @param httppost + */ + public static HttpEntity getResponse(HttpPost httppost){ + + HttpClient httpclient = HttpClientBuilder.create().build(); + HttpEntity responseEntity = null; + HttpResponse response = null; + + try { + response = httpclient.execute(httppost); + responseEntity = response.getEntity(); + } + catch(IOException e) { + System.out.println(e.getMessage()); + } + // Checking the status of the response + if (response !=null){ + System.out.println(response.getStatusLine()+"\n"); + } + return responseEntity; + + } + /** + * This method outputs the content details of the response + * @param responseEntity + */ + public static void getResponseDetails(HttpEntity responseEntity){ + + if (responseEntity != null) { + System.out.println(responseEntity.getContentType()+"\nContent-Length: "+responseEntity.getContentLength()); + } + } +} diff --git a/tools/ci/java-compile.sh b/tools/ci/java-compile.sh new file mode 100755 index 0000000..251f384 --- /dev/null +++ b/tools/ci/java-compile.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +javaCommand="$(javac -version)" +if [[ "$javaCommand" == *"command not found"* ]]; then + echo "You do not have the java compiler installed on your machine" +else + echo "You can compile" + cd ../../src/java + find -name "*.java" > sources.txt + javac @sources.txt +fi