Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Please comment this code so I can understand it...

Would someone comment this code so I can understand it?
import org.muos.management.managementSupport.Attribute;
import org.muos.management.managementSupport.Lab;
import org.muos.management.managementSupport.ManagementSupport;
import org.muos.management.managementSupport.ManagementSupportException;
import org.muos.management.managementSupport.ManagementSupportFactory;
import org.muos.management.managementSupport.RequirementVerificationID;
import org.muos.management.managementSupport.Tree;


public class SampleCode {

      /**
       * @param args
       */
      public static void main(String[] args) {
            String serviceLocation = "http://localhost:8080/axis2/services/TEService";
            ManagementSupport supporter = null;
            try {
                  supporter = ManagementSupportFactory.getManagementSupport(serviceLocation);
            } catch (ManagementSupportException e) {
                  //If can not initialize the TEServiceStub, do something here
                  e.printStackTrace();
            }

            if(supporter == null) {
                  return;
            }

            /*
             * Sample of deleteLab,
             */
            try {
                  supporter.deleteLab(123L);
                  //delete success
            } catch (ManagementSupportException e) {
                  //delete fail
                  e.printStackTrace();
            }

            /*
             * GetLabAttribute()
             */
            try {
                  String attribute = supporter.getLabAttribute(123L, "lab_attribute_name");
                  //Successfully get the attribute
                  System.out.println(attribute);
            } catch (ManagementSupportException e) {
                  //Fail
                  e.printStackTrace();
            }

            try {
                  String attribute = supporter.getLabChangeAttribute(1234L, "attribute_name");
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] labIds = supporter.getLabChanges();
                  for(long id : labIds) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getLabChangesByLab(123L); //LabId
                  for(long id : ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getLabChangesByNode(1234L);//NodeId
                  for(long id :ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getLabs();
                  for(long id : ids)  {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getNodeAttribute(1234L, "attribute_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getNodeChildren(1234L);
                  for(long id : ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getProjectAttribute(1234L, "attriubte_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getProjects();
                  for(long id : ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getRequirementVerificationAttribute("requirementId", 123L, "attibute_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  RequirementVerificationID[]  ids = supporter.getRequirementVerifications(1243L);
                  for(RequirementVerificationID id : ids) {
                        System.out.println(id.getRequirementId());
                        System.out.println(id.getTestLogId());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] nodeIds = supporter.getRootNodes(1244L);
                  for(long id : nodeIds) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getSessionAttribute(134L, "attribute_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] sessionIds = supporter.getSessions();
                  for(long id : sessionIds) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String xml = supporter.getSTDTree();
                  System.out.println(xml);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  String value = supporter.getTestLogAttribute(1234L, "attribute_name");
                  System.out.println(value);
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] testlogIds = supporter.getTestLogs();
                  for(long id : testlogIds) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  long[] ids = supporter.getTestLogsByNode(1345L);
                  for(long id : ids) {
                        System.out.println(id);
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Lab lab = new Lab();
            lab.setDescription("This is a lab");
            lab.setId(4564L);
            lab.setLocation("Where the lab is");
            lab.setOwner("who the owner is");
            try {
                  Attribute[] attributes = supporter.saveLab(lab);
                  for(Attribute attr : attributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Attribute[] labChangeAttributes = new Attribute[2];
            Attribute attr1 = new Attribute();
            attr1.setName("attributeName");
            attr1.setValue("attributeValue");
            Attribute attr2 = new Attribute();
            attr2.setName("attributeName");
            attr2.setValue("attributeValue");
            labChangeAttributes[0] = attr1;
            labChangeAttributes[1] = attr2;
            try {
                  Attribute[] returnedAttributes = supporter.saveLabChange("test log UID", labChangeAttributes);
                  for(Attribute attr : returnedAttributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Attribute[] requirementVerificationAttributes = new Attribute[2];
            attr1 = new Attribute();
            attr1.setName("attributeName");
            attr1.setValue("attributeValue");
            attr2 = new Attribute();
            attr2.setName("attributeName");
            attr2.setValue("attributeValue");
            labChangeAttributes[0] = attr1;
            labChangeAttributes[1] = attr2;
            try {
                  Attribute[] returnedAttributes = supporter.saveRequirementVerification("RequirementId", "testLogUID", requirementVerificationAttributes);
                  for(Attribute attr : returnedAttributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Attribute[] sessionAttibutes = new Attribute[2];
            attr1 = new Attribute();
            attr1.setName("attributeName");
            attr1.setValue("attributeValue");
            attr2 = new Attribute();
            attr2.setName("attributeName");
            attr2.setValue("attributeValue");
            labChangeAttributes[0] = attr1;
            labChangeAttributes[1] = attr2;
            try {
                  Attribute[] returnedAttributes = supporter.saveSession(123L, "sessionUID", sessionAttibutes);
                  for(Attribute attr : returnedAttributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            Attribute[] testLogSession = new Attribute[2];
            attr1 = new Attribute();
            attr1.setName("attributeName");
            attr1.setValue("attributeValue");
            attr2 = new Attribute();
            attr2.setName("attributeName");
            attr2.setValue("attributeValue");
            labChangeAttributes[0] = attr1;
            labChangeAttributes[1] = attr2;
            try {
                  Attribute[] returnedAttributes = supporter.saveTestLog("sessionUID", "testLogUID", testLogSession);
                  for(Attribute attr : returnedAttributes) {
                        System.out.println("name :" + attr.getName() + " ; value = " + attr.getValue());
                  }
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

            try {
                  Tree tree = supporter.populateTree(1234L);
                  System.out.println(tree.getNode().getNodeId());
                  for(Attribute att : tree.getNode().getAttributes()) {
                        System.out.println(att.getName());
                        System.out.println(att.getValue());
                  }
                  System.out.println("has children : "  + tree.getChildren().size());
            } catch (ManagementSupportException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
      }

}
0
yankeebushsoftware
Asked:
yankeebushsoftware
1 Solution
 
_iskywalker_Commented:
first we must know what is the
org.muos.management.managementSupport
since most of functions are from it and the rest is documented.
0
 
reach2piyushCommented:
//Looks like you got a web service with the following address
String serviceLocation = "http://localhost:8080/axis2/services/TEService";

//ManagementSupportFactory class looks like a utility class to connect to that Web Service ^ returns you a stub to call methods on that Web service
supporter = ManagementSupportFactory.getManagementSupport(serviceLocation);

// The following piece of code  along with all other subsequent similar code demonstrate/test a business method call to the above mentioned web-service,
Each call is enclosed in a separate try-catch loop, this will ensure that the program will continue even if any of the calls fails.  
/*
* Sample of deleteLab,
*/
try {
supporter.deleteLab(123L);
//delete success
} catch (ManagementSupportException e) {
//delete fail
e.printStackTrace();
}
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now