Java tutorial
/* * DocAPIDemo.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.DocServiceClient; import tw.com.mt.util.TaskServiceClient; import com.ctu.tm.data.xsd.DocBaseBean; import com.ctu.tm.data.xsd.TaskBaseBean; /** * Demo all project related API functions. * * @version 1.0 2014/7/10 * @author ken * */ public class DocAPIDemo { /** * The project key of the parent project. */ private int projObjKey; /** * The object key of the parent object, it could be a task, topic or project. */ 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 DocAPIDemo() { 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 DocBaseBean getDoc(int docObjKey) { DocBaseBean doc = DocServiceClient.getDoc(docObjKey); return doc; } /** * Get all docs of the specified project. * * @return all docs in an Array */ private DocBaseBean[] getAllDocs() { DocBaseBean[] docs = DocServiceClient.loadDocsByRootObjKey(projObjKey); return docs; } /** * Create a new project. */ private int createDoc() { String summary = " "; String content = "??????" + "?"; return DocServiceClient.createDoc("admin", // userID- projObjKey, // rootObjKey-key100 parentObjKey, // parentObjKey-?key // rootObjKey? 0, // folderObjKey- 0, // processKey-?key AppConstants.DOC_TYPE_NOTES, // docType-? 0, // size-? summary, // docSummary-? content, // appLongData-?? "", // appShortData-? // //"N;application/msword;??;" "", // docContent-? "", // knowledgeType- "N", // isRequiredFlag-? "100", // serialNumber- true, // anyoneCanAccess-??? "", // accessList-??,(userID,userID,userID) "", // currVersion- "", // verifiedAt- 0, // confidentialityKey- 0, // stateKey-?key "", // docServerID-?ID "", // sda0-???2.4.3 "", // sda1-???2.4.3 "", // sda2-???2.4.3 "", // sda3-???2.4.3 "", // sda4-???2.4.3 "", // sda5-???2.4.3 "", // sda6-???2.4.3 "", // sda7-???2.4.3 "", // sda8-???2.4.3 "", // sda9-???2.4.3 "", // sda10-???2.4.3 "", // sda11-???2.4.3 "", // sda12-???2.4.3 "", // sda13-???2.4.3 "", // sda14-???2.4.3 "", // sda15-???2.4.3 "", // sda16-???2.4.3 "", // sda17-???2.4.3 "", // sda18-???2.4.3 "", // sda19-???2.4.3 "", // uda0-??2.3.2 "", // uda1-??2.3.2 "", // uda2-??2.3.2 "", // uda3-??2.3.2 "", // uda4-??2.3.2 "", // uda5-??2.3.2 "", // uda6-??2.3.2 "", // uda7-??2.3.2 "", // uda8-??2.3.2 "", // uda9-??2.3.2 "", // uda10-??2.3.2 "", // uda11-??2.3.2 "", // uda12-??2.3.2 "", // uda13-??2.3.2 "", // uda14-??2.3.2 "", // uda15-??2.3.2 "", // uda16-??2.3.2 "", // uda17-??2.3.2 "", // uda18-??2.3.2 "", // uda19-??2.3.2 "", // uda60-??2.3.2 "", // uda61-??2.3.2 "", // uda62-??2.3.2 "", // uda63-??2.3.2 "", // uda64-??2.3.2 "", // uda65-??2.3.2 "", // uda66-??2.3.2 "", // uda67-??2.3.2 "", // uda68-??2.3.2 "", // uda69-??2.3.2 "", // uda70-??2.3.2 "", // uda71-??2.3.2 "", // uda72-??2.3.2 "", // uda73-??2.3.2 "", // uda74-??2.3.2 "", // uda75-??2.3.2 "", // uda76-??2.3.2 "", // uda77-??2.3.2 "", // uda78-??2.3.2 "", // uda79-??2.3.2 "Y", // notificationFlag-?(Y/N) "ken@mt.com.tw", // mailTo- "ken@mt.com.tw", // extraEmailTo- "", // hiddenExtraEmailTo- "", // emailSubject- "", // emailContents- "tw" // language- ); } 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) { DocAPIDemo mytest = new DocAPIDemo(); mytest.printMessage("Create a new doc"); int docObjKey = mytest.createDoc(); if (docObjKey > 0) { System.out.println(String.format("New Doc Key : %d", docObjKey)); } else { System.out.println(String.format("Error Code : %d", docObjKey)); System.exit(0); } mytest.printMessage("Print out all docs of project " + mytest.projObjKey); DocBaseBean[] docs = mytest.getAllDocs(); for (DocBaseBean doc : docs) { System.out.println( String.format("Doc Summary: %s - Created By: %s", doc.getDocSummary(), doc.getCreatedByID())); } mytest.printMessage("Get this newly created doc"); DocBaseBean doc = mytest.getDoc(docObjKey); System.out.println( String.format("Doc Summary: %s - Created By: %s", doc.getDocSummary(), doc.getCreatedByID())); } }