Re: OGOJOGI: job.getHistory()
Christoph Guse <[email protected]>
| Newsgroups | gmane.comp.cms.opengroupware.xmlrpc.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi murphee, thanks for your help. I decided to code a version with a new HistoryObject. You can find the changed and the new classes in the attachment. Have a nice weekend Christoph murphee (Werner Schuster) wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Christoph Guse wrote: > | I tried to use job.getHistory() in the job class. I extended XmlRpcJob > | so the remote method jobs.getHistory() is called. I get values from the > | OGo-Server: > > How did you do this? I mean, how does your call look like? > > > | Unfortunately I'm not able to put the methodResponse in an object like > | History, because I don't fully understand how OGOJOGI put the XML > result > | in an object. > > Well... if you do something like > caller.invoke(....) > ~ (where "caller" is an object of type XmlRpcCaller) you'll get back a > Map (or a Hashtable), holding the result from OG.o (the XmlRpc Struct > type is put into a Map/Hashtable). > JOGI uses a XmlRpcBaseDocument (or something like that) as an aid for > this, ie. classes like Person, ... (which map to an OG.o document, which > are returned as XmlRpc structs) are derived from XmlRpcBasedocument. > > Depends on what you want to do, you could simply have your Job > getHistory() return a List of ... I don't know, Maps that hold the Job > information. This is a solution if the History information is read only, > and you don't want to allow the users to modify the contents. > A cleaner way would be to create a History object that hides the > internals and provided methods to access the information. > > murphee > - -- > Werner Schuster (murphee) > Student of SoftwareEngineering and KnowledgeManagement > Maintainer of the OGO-JOGI Project @ http://ogo-jogi.sourceforge.net/ > Blog @ http://jroller.com/page/murphee > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.4 (MingW32) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFCX+FOgLjXNIXpN6MRAsW7AKCBHsgmqRXQs0eKeJH6WfP2Gz2qLACdGJSt > RYf6riTFKFLzRrHCnDPlOCI= > =R2r/ > -----END PGP SIGNATURE----- -- **************************************** Christoph Guse LöhstraÃe 34 41747 Viersen Tel. 0 21 62 / 50 24 066 Mobil 01 72 / 160 74 84 VoIP 0 12 12 / 39 64 48 831 ****************************************
HistoryObject.java
(text/x-java, 1.5 KB)
/* OGO-JOGI Project Java Interface for OpenGroupware.org Copyright (C) 2003 Andreas Rath (teddius) [email protected] Copyright (C) 2003 Werner Schuster (murphee) [email protected] This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Created on 15.04.2005 */ package org.opengroupware.jogi.ogo; /** Holds an History Object of a job * * * @author Christoph Guse [email protected] * * * */ public interface HistoryObject { public String getNameComment() throws OgoException; public String getJobId() throws OgoException; public String getObjectVersion() throws OgoException; public String getActorId() throws OgoException; public String getAction() throws OgoException; public String getActionDate() throws OgoException; public String getNameId() throws OgoException; public String getJobStatus() throws OgoException; }
XmlRpcHistoryObject.java
(text/x-java, 3 KB)
/* OGO-JOGI Project Java Interface for OpenGroupware.org Copyright (C) 2005 Christoph Guse [email protected] This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Created on 15.04.2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package org.opengroupware.jogi.connect.xmlrpc; import java.util.Hashtable; import java.util.Map; import org.opengroupware.jogi.ogo.HistoryObject; import org.opengroupware.jogi.ogo.OgoException; public class XmlRpcHistoryObject extends XmlRpcBaseDocument implements HistoryObject{ private static final String KEY_NAME_COMMENT = "comment"; private static final String KEY_JOB_ID = "jobId"; private static final String KEY_OBJECT_VERSION = "objectVersion"; private static final String KEY_ACTOR_ID = "actorId"; private static final String KEY_ACTION = "action"; private static final String KEY_ACTION_DATE = "actionDate"; private static final String KEY_NAME_ID = "id"; private static final String KEY_JOB_STATUS = "jobStatus"; protected boolean checkNewContent(Map new_content) { if (new_content.get(KEY_JOB_ID) != null) { return true; } return false; } public XmlRpcHistoryObject(Hashtable table) throws OgoException{ super(); content_ = new Hashtable(); content_.put(KEY_NAME_COMMENT, table.get(KEY_NAME_COMMENT)); content_.put(KEY_JOB_ID, table.get(KEY_JOB_ID)); content_.put(KEY_OBJECT_VERSION, table.get(KEY_OBJECT_VERSION)); content_.put(KEY_ACTOR_ID, table.get(KEY_ACTOR_ID)); content_.put(KEY_ACTION, table.get(KEY_ACTION)); content_.put(KEY_ACTION_DATE, table.get(KEY_ACTION_DATE)); content_.put(KEY_NAME_ID, table.get(KEY_NAME_ID)); content_.put(KEY_JOB_STATUS, table.get(KEY_JOB_STATUS)); } public String getNameComment(){ return (String) content_.get(KEY_NAME_COMMENT); } public String getJobId(){ return (String) content_.get(KEY_JOB_ID); } public String getObjectVersion(){ return (String) content_.get(KEY_OBJECT_VERSION); } public String getActorId(){ return (String) content_.get(KEY_ACTOR_ID); } public String getAction(){ return (String) content_.get(KEY_ACTION); } public String getActionDate(){ return (String) content_.get(KEY_ACTION_DATE); } public String getNameId(){ return (String) content_.get(KEY_NAME_ID); } public String getJobStatus(){ return (String) content_.get(KEY_JOB_STATUS); } }
XmlRpcJob.java
(text/x-java, 14.9 KB)
/* OGO-JOGI Project Java Interface for OpenGroupware.org Copyright (C) 2003 Andreas Rath (teddius) [email protected] Copyright (C) 2003 Werner Schuster (murphee) [email protected] This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Created on Aug 4, 2003 * */ package org.opengroupware.jogi.connect.xmlrpc; import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Vector; import org.opengroupware.jogi.ogo.Account; import org.opengroupware.jogi.ogo.HistoryObject; import org.opengroupware.jogi.ogo.Job; import org.opengroupware.jogi.ogo.OpenGroupWare; import org.opengroupware.jogi.ogo.OgoException; import org.opengroupware.jogi.ogo.ConnectionException; import org.opengroupware.jogi.ogo.Person; /** * @author Werner Schuster (murphee) * @author Andreas Rath (teddius) */ public class XmlRpcJob extends XmlRpcBaseDocument implements Job { // check if this is OK, or if the thing is case sensitive // the thing is case sensitive! (teddius) public static final String KEY_ID = "id"; public static final String KEY_CATEGORY = "category"; public static final String KEY_START_DATE = "startDate"; public static final String KEY_END_DATE = "endDate"; public static final String KEY_STATUS = "status"; public static final String KEY_PRIORITY = "priority"; public static final String KEY_NAME = "name"; public static final String KEY_IS_TEAM_JOB = "isTeamJob"; public static final String KEY_KEYWORDS = "keywords"; public static final String KEY_EXECUTOR = "executor"; public static final String KEY_CREATOR = "creator"; public static final String OGO_CALL_JOB_MARK_DONE = "jobs.markDone"; public static final String OGO_CALL_JOB_ARCHIVE_JOB = "jobs.archiveJob"; public static final String OGO_CALL_JOB_ACCEPT_JOB = "jobs.acceptJob"; public static final String OGO_CALL_JOB_ANNOTATE_JOB = "jobs.annotateJob"; public static final String OGO_CALL_JOB_REJECT_JOB = "jobs.rejectJob"; public static final String OGO_CALL_JOB_REACTIVATE_JOB = "jobs.reactivateJob"; public static final String OGO_CALL_JOB_UPDATE_JOB = "jobs.updateJob"; public static final String OGO_CALL_JOB_GET_HISTORY = "jobs.getHistory"; protected XmlRpcCaller caller_; protected OpenGroupWare ogo_; public XmlRpcJob(Date startDate, Date endDate, String name) throws OgoException, ConnectionException{ super(); content_ = new Hashtable(); put(KEY_START_DATE, startDate); put(KEY_END_DATE, endDate); put(KEY_NAME, name); } protected XmlRpcJob(Date startDate, Date endDate, String name, XmlRpcCaller caller, OpenGroupWare ogo) throws OgoException, ConnectionException { super(); content_ = new Hashtable(); caller_ = caller; ogo_ = ogo; put(KEY_START_DATE, startDate); put(KEY_END_DATE, endDate); put(KEY_NAME, name); } protected XmlRpcJob(Date startDate, Date endDate, String name, String keywords, String priority, XmlRpcCaller caller, OpenGroupWare ogo) throws OgoException, ConnectionException { super(); content_ = new Hashtable(); caller_ = caller; ogo_ = ogo; put(KEY_START_DATE, startDate); put(KEY_END_DATE, endDate); put(KEY_NAME, name); put(KEY_PRIORITY, priority); put(KEY_KEYWORDS, keywords); } protected XmlRpcJob(XmlRpcCaller caller, Map content, OpenGroupWare ogo) throws OgoException, ConnectionException { super(); if (checkNewContent(content)) { caller_ = caller; content_ = new Hashtable(content); id_ = content_.get(KEY_ID).toString(); ogo_ = ogo; } else { throw new IllegalArgumentException("Missing contents in the document map."); } } /** * Utility method that is called from the markDone, acceptJobs, etc methods; * @return */ private boolean changeJobProperty(String functionName) throws OgoException, ConnectionException { List params = new Vector(); params.add(id_); Object retVal = caller_.invoke(functionName, params); if (retVal instanceof Boolean) { return ((Boolean) retVal).booleanValue(); } else { return false; } } protected boolean changeJobProperty(String functionName, String comment) throws OgoException, ConnectionException { List params = new Vector(); params.add(id_); params.add(comment); Object retVal = caller_.invoke(functionName, params); if (retVal instanceof Boolean) { return ((Boolean) retVal).booleanValue(); } else { return false; } } // TODO: add the versions with Comments! public boolean markDone() throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_MARK_DONE); } public boolean archiveJob() throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_ARCHIVE_JOB); } public boolean acceptJob() throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_ACCEPT_JOB); } public boolean rejectJob() throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_REJECT_JOB); } public boolean reactivateJob() throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_REACTIVATE_JOB); } public boolean reactivateJob(String comment) throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_REACTIVATE_JOB, comment); } public boolean markDone(String comment) throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_MARK_DONE, comment); } public boolean archiveJob(String comment) throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_ARCHIVE_JOB, comment); } public boolean acceptJob(String comment) throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_ACCEPT_JOB, comment); } public boolean annotateJob(String comment) throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_ANNOTATE_JOB, comment); } public boolean rejectJob(String comment) throws OgoException, ConnectionException { return changeJobProperty(OGO_CALL_JOB_REJECT_JOB, comment); } // added by Christoph Guse // doesn't work public void updateJob(Person person) throws OgoException, ConnectionException{ List param = new Vector(); param.add(((XmlRpcPerson) person).getContent()); param.add(((XmlRpcJob) this).getContent()); Object obj = caller_.invoke(OGO_CALL_JOB_UPDATE_JOB, param); } // TODO: find out how JobHistory looks like; // completed by Christoph Guse public Iterator getHistory() throws OgoException, ConnectionException{ // parameters for caller List param = new Vector(); param.add(content_.get(KEY_ID)); // execute caller Object result = caller_.invoke(OGO_CALL_JOB_GET_HISTORY, param); Vector history = new Vector(); ArrayList ret = new ArrayList(); if(result instanceof List){ Vector r = (Vector) result; Enumeration enum = r.elements(); while(enum.hasMoreElements()){ Hashtable elem = (Hashtable) enum.nextElement(); HistoryObject obj = new XmlRpcHistoryObject(elem); ret.add(obj); } } return ret.iterator(); } public void setStartDate(Date start_date) throws OgoException, ConnectionException { if (start_date != null) { put(KEY_START_DATE, start_date); } else { throw new NullPointerException("StartDate parameter must not be null."); } } public Date getStartDate() throws OgoException, ConnectionException { Object tempDate = content_.get(KEY_START_DATE); if ((tempDate != null) && (tempDate instanceof Date)) { return (Date) tempDate; } // TODO: return null or throw exception? return null; } public void setEndDate(Date end_date) throws OgoException, ConnectionException { if (end_date != null) { put(KEY_END_DATE, end_date); } else { throw new NullPointerException("EndDate parameter must not be null."); } } public Date getEndDate() throws OgoException, ConnectionException { Object tempDate = content_.get(KEY_END_DATE); if ((tempDate != null) && (tempDate instanceof Date)) { return (Date) tempDate; } // TODO: return null or throw exception? return null; } protected void setAccountMap(String key, String id, String login) throws OgoException, ConnectionException { // TODO: Hack? Should an Account be used?? Map map = new Hashtable(); map.put(XmlRpcAccount.KEY_ID, id); map.put(XmlRpcAccount.KEY_LOGIN, login); put(key, map); } protected String getAccountId(String key) throws OgoException, ConnectionException { Object temp = content_.get(key); if (temp instanceof Map) { Object retVal = ((Map) temp).get(XmlRpcAccount.KEY_ID); System.out.println("\nACCOUNT_ID: " + retVal); if (retVal != null) { return retVal.toString(); } else { // TODO: throw exception ? return null; } } else { // TODO: throw exception ? return null; } } public void setExecutor(Account account) throws OgoException, ConnectionException { if ((account != null) && (account.getId() != null) && (account.getLogin() != null)) { setAccountMap(KEY_EXECUTOR, account.getId(), account.getLogin()); } else { throw new IllegalArgumentException("Illegal arguments for setExecutor Method. "); } } public Account getExecutor() throws OgoException, ConnectionException { return ogo_.getAccountManager().getById(getAccountId(KEY_EXECUTOR)); } public void setCreator(Account account) throws OgoException, ConnectionException { if ((account != null) && (account.getId() != null) && (account.getLogin() != null)) { setAccountMap(KEY_CREATOR, account.getId(), account.getLogin()); } else { throw new IllegalArgumentException("Illegal arguments for setCreator Method. "); } } public Account getCreator() throws OgoException, ConnectionException { return ogo_.getAccountManager().getById(getAccountId(KEY_CREATOR)); } public void setName(String name) throws OgoException, ConnectionException { if (name != null) { put(KEY_NAME, name); } else { throw new NullPointerException("Nameparameter must not be null."); } } public String getName() throws OgoException, ConnectionException { return getString(KEY_NAME); } public void setPriority(int priority) throws OgoException, ConnectionException { put(KEY_PRIORITY, new Integer(priority)); } public int getPriority() throws OgoException, ConnectionException { Object temp = (Integer) content_.get(KEY_PRIORITY); if ((temp != null) && (temp instanceof Integer)) { return ((Integer) temp).intValue(); } else { // TODO: Exception or default Value??? return 0; } } public void setKeywords(String key_words) throws OgoException, ConnectionException { if (key_words != null) { put(KEY_KEYWORDS, key_words); } else { throw new NullPointerException("Keyword parameter must not be null."); } } public String getKeywords() throws OgoException, ConnectionException { return getString(KEY_KEYWORDS); } public void setStatus(String status) throws OgoException, ConnectionException { if (status != null) { put(KEY_STATUS, status); } else { throw new NullPointerException("Status parameter must not be null."); } } public String getStatus() throws OgoException, ConnectionException { return getString(KEY_STATUS); } public boolean isTeamJob() throws OgoException, ConnectionException { Object temp = content_.get(KEY_IS_TEAM_JOB); if (temp instanceof Boolean) { return ((Boolean) temp).booleanValue(); } return false; } public void setIsTeamJob(boolean bool) throws OgoException, ConnectionException { put(KEY_IS_TEAM_JOB, new Boolean(bool)); } public void setCategory(String cat) throws OgoException, ConnectionException { put(KEY_CATEGORY, cat); } public String getCategory() throws OgoException, ConnectionException { return getString(KEY_CATEGORY); } protected boolean checkNewContent(Map new_content) { if (new_content.get(KEY_ID) != null) { return true; } return false; } public String getId() throws OgoException, ConnectionException { Object obj = content_.get(KEY_ID); if (obj instanceof String) { return (String) obj; } return null; } }