Java tutorial
/* * TaskAPIDemo.java 1.0 2014/7/11 * * Copyright (c) 2014-2030 Monmouth Technologies, Inc. * http://www.mt.com.tw * 10F-1 No. 306 Chung-Cheng 1st Road, Linya District, 802, Kaoshiung, Taiwan * All Rights Reserved. * * This software is the confidential and proprietary information of Monmouth * Technologies, Inc. You shall not disclose such Confidential Information and * shall use it only in accordance with the terms of the license agreement you * entered into with Monmouth Technologies. */ package tw.com.mt; import java.util.Calendar; import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.SystemConfiguration; import org.apache.commons.configuration.PropertiesConfiguration; import tw.com.mt.app.AppConstants; import tw.com.mt.util.TaskServiceClient; import com.ctu.tm.data.xsd.TaskBaseBean; /** * Demo all project related API functions. * * @version 1.0 2014/7/10 * @author ken * */ public class TaskAPIDemo { /** * The project key of the parent project. */ private int projObjKey; /** * The object key of the parent object, it could be a topic or a task. */ private int parentObjKey; /** * Property file name. */ private String propertyFile = "application.properties"; /** * Use this line to separate content when printing out information. */ private String seperateLine = "========================================"; /** * Default constructor. */ public TaskAPIDemo() { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); try { config.addConfiguration(new PropertiesConfiguration(propertyFile)); this.projObjKey = config.getInt("projObjKey"); this.parentObjKey = config.getInt("parentObjKey"); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private TaskBaseBean getTask(int taskObjKey) { TaskBaseBean task = TaskServiceClient.getTask(taskObjKey); return task; } /** * Get all tasks of the specified project. * * @return all projects in an Array */ private TaskBaseBean[] getAllTasksCreatedByUser100() { TaskBaseBean[] tasks = TaskServiceClient.findTasks(projObjKey, AppConstants.TASK_BIA_CREATED_BY, "100"); return tasks; } /** * Create a new project. */ private int createTask() { Calendar cal = Calendar.getInstance(); String taskName = "Task-" + cal.getTimeInMillis(); return TaskServiceClient.createTask(projObjKey, // projObjKey-key parentObjKey, // parentObjKey-?/key "?", // taskDesc-Memo?, 100, // taskOwnerKey-, Key , 0, // udaSet- 0, // sdaSet-??0?? "", // sda0-?? "", // sda1-?? "", // sda2-?? "", // sda3-?? "", // sda4-?? "", // sda5-?? "", // sda6-?? "", // sda7-?? "", // sda8-?? taskName, // sda9-?? "", // sda10-?? "", // sda11-?? "", // sda12-?? "", // sda13-?? "", // sda14-?? "", // sda15-?? "", // sda16-?? "", // sda17-?? "", // sda18-?? "", // sda19-?? "", // uda0-? "", // uda1-? "", // uda2-? "", // uda3-? "", // uda4-? "", // uda5-? "", // uda6-? "", // uda7-? "", // uda8-? "", // uda9-? "", // uda10-? "", // uda11-? "", // uda12-? "", // uda13-? "", // uda14-? "", // uda15-? "", // uda16-? "", // uda17-? "", // uda18-? "", // uda19-? "", // uda60-? "", // uda61-? "", // uda62-? "", // uda63-? "", // uda64-? "", // uda65-? "", // uda66-? "", // uda67-? "", // uda68-? "", // uda69-? "", // uda70-? "", // uda71-? "", // uda72-? "", // uda73-? "", // uda74-? "", // uda75-? "", // uda76-? "", // uda77-? "", // uda78-? "", // uda79-? "", // accessList-??,(userID,userID,userID) "", // userGroupAccessList-?, (ID,ID) "", // subTeamAccessList-??,(subTeamObjKey,subTeamObjKey) "N", // isMilestoneFlag- (Y/N) 999999, // seqNO-? "admin" // userID-ID ); } private void printMessage(String message) { System.out.println(""); System.out.println(seperateLine); System.out.println(message); System.out.println(seperateLine); System.out.println(""); } public static void main(String[] args) { TaskAPIDemo mytest = new TaskAPIDemo(); mytest.printMessage("Create a new task"); int taskObjKey = mytest.createTask(); if (taskObjKey > 0) { System.out.println(String.format("New Task Key : %d", taskObjKey)); } else { System.out.println(String.format("Error Code : %d", taskObjKey)); System.exit(0); } mytest.printMessage("Print out all tasks created by User 100 in project " + mytest.projObjKey); TaskBaseBean[] tasks = mytest.getAllTasksCreatedByUser100(); for (TaskBaseBean task : tasks) { System.out .println(String.format("Task Name: %s - Owner: %s", task.getTaskName(), task.getTaskOwnerID())); } mytest.printMessage("Get this newly created task"); TaskBaseBean task = mytest.getTask(taskObjKey); System.out.println(String.format("Task Name: %s - Owner: %s", task.getTaskName(), task.getTaskOwnerID())); } }