Re: ogojogi->job->set
Christoph Guse <[email protected]>
| Newsgroups | gmane.comp.cms.opengroupware.xmlrpc.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Helge, unfortunately I can't try out your code. In my OGo installation there is no method jobs.updateJob. This method is in my xml-rpc documentation, but when I use the unixtool xmlrpc_call the method jobs.updateJob is not listet. I think I will install OGo ShapeShifter 8. When I'm lucky the method is in there. By the way: I found an error in XmlRpcAccountManager.getById(). The correct parameter is String, not int. The corrected version is attached. Greets Christoph Werner Schuster (murphee) wrote: > Christoph Guse wrote: > >> Hi Helge, >> >> at a first glance I can't find the section in which JOGI calls the >> function "jobs.update". In my OGo XML-RPC documentation there is a >> function "updateJob" in the packet jobs. My idea is now to change >> JOGI so it calls "jobs.updateJob". Am I'm wrong? Where can I find >> "jobs.update"? I'm searching but can't find it. > > > It's in the org.opengroupware.jogi.connect.xmlrpc.XmlRpcJobManager > class, defined as JOB_MANAGER_JOB_UPDATE, which > is used in the > public void update(Observable o, Object arg) > method in the same class. > > I looked at the code, and you could something like this (in the update > method): > List param = new Vector(); > // New Code start: > XmlRpcPerson pers = > (XmlRpcPerson)job.getCreator().getPerson(); > param.add(new Hashtable(pers.getContent())); > // New Code end > param.add(jobDoc); > > The jobs.updateJob function needs full Person object... but I'm not > sure which Person they want. I assume > it's the creator, but it might also be the Executor (in that case, > adapt code in the first new line with > (XmlRpcPerson)job.getCreator().getPerson(); > ). > > I haven't tested this code, so I don't know if this really works. If > you get this working, I'd appreciate it if you could send me the > working code (a patch or diff, or just the code you updated), so I > could incorporate these changes into the JOGI CVS HEAD. > > murphee -- **************************************** Christoph Guse Zimmer 33510 HubertusstraÃe 149 41239 Mönchengladbach Tel. 0 21 66 / 14 52 59 Mobil 01 72 / 160 74 84 ****************************************
XmlRpcAccountManager.java
(text/plain, 13.8 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.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Observable; import java.util.Observer; import org.opengroupware.jogi.ogo.Account; import org.opengroupware.jogi.ogo.AccountManager; import org.opengroupware.jogi.ogo.FetchSpecification; import org.opengroupware.jogi.ogo.OpenGroupWare; import org.opengroupware.jogi.ogo.OgoException; import org.opengroupware.jogi.ogo.ConnectionException; import org.opengroupware.jogi.ogo.UpdateException; /** * @author Werner Schuster (murphee) Andreas Rath (teddius) */ public class XmlRpcAccountManager implements AccountManager, Observer { public static final String OGO_CALL_ACCOUNT_UPDATE = "account.update"; public static final String OGO_CALL_ACCOUNT_DELETE = "account.delete"; public static final String OGO_CALL_ACCOUNT_INSERT = "account.insert"; public static final String OGO_CALL_ACCOUNT_GET_LOGIN_ACCOUNT = "account.getLoginAccount"; public static final String OGO_CALL_ACCOUNT_GET_BY_LOGIN = "account.getByLogin"; public static final String OGO_CALL_ACCOUNT_DELETE_BY_LOGIN = "account.deleteByLogin"; public static final String OGO_CALL_ACCOUNT_DELETE_BY_NUMBER = "account.deleteByNumber"; public static final String OGO_CALL_ACCOUNT_PASSWORD_FOR_LOGIN = "account.passwordForLogin"; public static final String OGO_CALL_ACCOUNT_FETCH = "account.fetch"; public static final String OGO_CALL_ACCOUNT_FETCH_IDS = "account.fetchIds"; public static final String OGO_CALL_ACCOUNT_GET_BY_ID = "account.getById"; public static final String OGO_CALL_ACCOUNT_GET_BY_NUMBER = "account.getByNumber"; XmlRpcCaller caller_; /** * This stores all the accounts that have ever been loaded or generated. * The key used to store them is their id, as this should be unique (hopefully...). * This is vitally important, to ensure that only one instance of an specific Account * exists. Otherwise, any fetch* method would/could return new instances of Accounts * that might already have instance here, which would lead to inconsistancies (eg. * one instance representing an older state of a new one) as well as it would be * impossible to check for equality using the "==" operator. */ protected Map cached_accounts_; protected OpenGroupWare openGroupware_; public XmlRpcAccountManager(XmlRpcCaller caller, OpenGroupWare ogo) { cached_accounts_ = new HashMap(); caller_ = caller; openGroupware_ = ogo; } public XmlRpcAccountManager(XmlRpcCaller caller) { cached_accounts_ = new HashMap(); caller_ = caller; } public Account getByNumber(String account_number) throws OgoException, ConnectionException { // TODO: find out what his "number" is supposed to mean! Object obj = caller_.invoke(OGO_CALL_ACCOUNT_GET_BY_NUMBER, account_number); if (obj instanceof Map) { return receiveAccount(obj); } return null; } public Iterator fetchIds(FetchSpecification spec) throws OgoException, ConnectionException { List params = new ArrayList(); params.add(new XmlRpcFetchSpecification(spec).getContent()); Object accTemp = caller_.invoke(OGO_CALL_ACCOUNT_FETCH_IDS, params); if (accTemp instanceof List) { return ((List) accTemp).iterator(); } return null; } /** * This method returns the Account associated by this <code>id</code>. * For example if you want to receive the Account with the OpengroupWare * <code>id</code> <pre>skyrix://skyrix.com/sx_skyrix/122282</pre> * you must supply the numeric part as argument to the method call. * In the example above the correct argument to receive the account * would be <code>122282</code> * * @param id The numeric Part of the OpengroupWare <code>id</code>. * @return An {@link org.opengroupware.jogi.ogo.Account Account} Object * for this <code>id</code> */ public Account getById(String id) throws OgoException, ConnectionException { // List param = new Vector(); // param.add(Id); // return receiveAccount(caller_.invoke(OGO_CALL_ACCOUNT_GET_BY_ID, param)); Object obj; try { // int int_ = Integer.parseInt(id); //obj = caller_.invoke(OGO_CALL_ACCOUNT_GET_BY_ID, int_); // account.getById takes String parameter, not int obj = caller_.invoke(OGO_CALL_ACCOUNT_GET_BY_ID,id); } catch (OgoException e) { /** * NOTE: check if "account.getById" only accepts an Integer Value? * if so, I have to parse the "skyrix//.../234232" for the * Integer value at the end -> id */ obj = caller_.invoke(OGO_CALL_ACCOUNT_GET_BY_ID, id); /** NOTE: for id like "skyrix://balabla/23232" */ } if (obj instanceof Map) { return receiveAccount(obj); } return null; } /** * Deletes an account by a number. Because a number is unique in the * OpenGroupware database deleting by number is safe. */ public void deleteByNumber(String number) throws OgoException, ConnectionException { List param = new ArrayList(); param.add(number); caller_.invoke(OGO_CALL_ACCOUNT_DELETE_BY_NUMBER, param); } public void deleteByLogin(String login) throws OgoException, ConnectionException { List param = new ArrayList(); param.add(login); boolean isDeleted = true; Object result = caller_.invoke(OGO_CALL_ACCOUNT_DELETE_BY_LOGIN, param); if(result instanceof Boolean){ isDeleted = ((Boolean)result).booleanValue(); } // update local cache for (Iterator iter = cached_accounts_.keySet().iterator(); iter.hasNext();) { Account currAccount = (Account) cached_accounts_.get(iter.next()); if (currAccount.getLogin().equals(login)) { cached_accounts_.remove(currAccount.getId()); // TODO: invalidate the existing Account instances??? // the XmlRpc... classes could have an "deleted" flag that they check // before any action; } } } // Comment copied from interface public void delete(Account account) throws OgoException, ConnectionException { cached_accounts_.remove(account.getId()); deleteByLogin(account.getLogin()); } // Comment copied from interface public String passwordForLogin(String login) throws OgoException, ConnectionException { /** * Password returned by the call from Opengroupware is returned in * standard unix crypt. */ List param = new ArrayList(); param.add(login); Object result = caller_.invoke(OGO_CALL_ACCOUNT_PASSWORD_FOR_LOGIN, param); if(result instanceof String){ return (String)result; } else { return null; } } /* (non-Javadoc) * @see jogi.ogo.AccountManager#getTeamsForLogin(java.lang.String) */ public List getTeamsForLogin(String login) throws OgoException, ConnectionException { // TODO Auto-generated method stub return null; } /* (non-Javadoc) * @see jogi.ogo.AccountManager#getByLogin(java.lang.String) */ public Account getByLogin(String login) throws OgoException, ConnectionException { List param = new ArrayList(); param.add(login); Object accTemp = caller_.invoke(OGO_CALL_ACCOUNT_GET_BY_LOGIN, param); return receiveAccount(accTemp); } /* (non-Javadoc) * @see jogi.ogo.AccountManager#fetch(java.lang.String) */ public Iterator fetch(FetchSpecification spec) throws OgoException, ConnectionException { List params = new ArrayList(); //new XmlRpcFetchSpecification(spec).getContent() Map arg1 = new Hashtable(); arg1.put(XmlRpcFetchSpecification.KEY_QUALIFIER, spec.getQualifier()); params.add(arg1); Object accTemp = caller_.invoke(OGO_CALL_ACCOUNT_FETCH, params); if (accTemp instanceof List) { // receive each Account List retVal = new ArrayList(); for (Iterator iter = ((List) accTemp).iterator(); iter.hasNext();) { Object tempAccount = receiveAccount(iter.next()); if (tempAccount != null) { retVal.add(tempAccount); } else { // TODO: if one of the returned Accounts is invalid... what to do? // throw an exception or just ignore it and return the rest??? } } // end for return retVal.iterator(); } // end if List return Collections.EMPTY_LIST.iterator(); } /* (non-Javadoc) * @see jogi.ogo.AccountManager#insert(java.lang.String, java.lang.String, java.lang.String) */ public Account insert(String login) throws OgoException, ConnectionException { Map paramStruct = new HashMap(); paramStruct.put(XmlRpcAccount.KEY_LOGIN, login); List params = new ArrayList(); params.add(paramStruct); Object retVal = caller_.invoke(OGO_CALL_ACCOUNT_INSERT, params); if (retVal instanceof Map) { // TODO: put this in an own method, for all methods that // have to create Accounts! return createNewAccount((Map) retVal); } else { // TODO: throw an exception! } return null; } /* (non-Javadoc) * @see jogi.ogo.AccountManager#commitUpdate() */ public void commitUpdate() throws OgoException, ConnectionException { // TODO Auto-generated method stub } /* (non-Javadoc) * @see jogi.ogo.AccountManager#getAllTemplateUserLogins() */ public List getAllTemplateUserLogins() throws OgoException, ConnectionException { // TODO Auto-generated method stub return null; } public Account getLoginAccount() throws OgoException, ConnectionException { Object accTemp = caller_.invoke(OGO_CALL_ACCOUNT_GET_LOGIN_ACCOUNT, new ArrayList()); return receiveAccount(accTemp); } /** * This takes the return value of an XML-RPC call, and if that is an Account * it either updates the cached version of it or creates a new one. * * @param accTemp The object returned by an XML-RPC call. * @return An updated copy of an XmlRpcAccount. */ protected XmlRpcAccount receiveAccount(Object accTemp) throws OgoException, ConnectionException { XmlRpcAccount retVal = getCachedAccount(accTemp); if (retVal != null) { // if retVal != null, then accTemp is a Map in any case; ((XmlRpcAccount) retVal).setContent((Map) accTemp); return (XmlRpcAccount) retVal; } else { if (accTemp instanceof Map) { return createNewAccount((Map) accTemp); } } // default return null; } /** * This method takes the return value of an XML-RPC call and looks up * the object which represents this <code>id</code> in the cache. If the * object exists in the cache the cached Object will be returned. If * the object is not in the cache <code>null</code> will be returned. * * @param obj The result of an XML-RPC Call. * @return An instance of an * {@link org.opengroupware.jogi.connect.xmlrpc.XmlRpcAccount XmlRpcAccount} * object or <code>null</code> if no object exists in the cache. */ protected XmlRpcAccount getCachedAccount(Object obj) { if (obj instanceof Map) { Map accMap = (Map) obj; Object tempLoginObj = accMap.get(XmlRpcAccount.KEY_ID); if (tempLoginObj != null) { String tempLogin = tempLoginObj.toString(); return (XmlRpcAccount) cached_accounts_.get(tempLogin); } } else { return null; } return null; } /** * Creates a new {@link org.opengroupware.jogi.connect.xmlrpc.XmlRpcAccount * XmlRpcAccount } from a {@link java.util.Map Map}. * * @param content The {@link java.util.Map Map} containing the data from * which a new {@link org.opengroupware.jogi.connect.xmlrpc.XmlRpcAccount XmlRpcAccount} * should be created. * @return A newly created {@link org.opengroupware.jogi.connect.xmlrpc.XmlRpcAccount * XmlRpcAccount} * with its values initalized from the {@link java.util.Map Map}. */ protected XmlRpcAccount createNewAccount(Map content) throws OgoException, ConnectionException { XmlRpcAccount tempAccount = new XmlRpcAccount(caller_, content, openGroupware_); cached_accounts_.put(tempAccount.getId(), tempAccount); // NOTE: this is important!!! tempAccount.addObserver(this); return tempAccount; } /** * Updates an object and synchronizes it with the OpengroupWare server * * @param o An observable. * @param arg The object which should be updated. */ public void update(Observable o, Object arg) { if (arg instanceof XmlRpcAccount) { XmlRpcAccount acc = (XmlRpcAccount) arg; Hashtable accDoc = new Hashtable(acc.getContent()); // TODO: walk the Map and make sure that all the contents // are of types that can be directly mapped to the XML-RPC // aequivalents! List param = new ArrayList(); param.add(accDoc); try { caller_.invoke(OGO_CALL_ACCOUNT_UPDATE, param); } catch (OgoException e){ throw new UpdateException(e); } catch (ConnectionException e){ throw new UpdateException(e); } } } }