/** * @param sessionId * @param objectType * @param object * @return */ public String doSave(String sessionId, String object) { Object obj = ObjectSerializer.xmlToObject(object); if (!(obj instanceof BaseObject)) { throw new RemoteException("Given object does not subclass " + BaseObject.class.getName()); } try { ((BaseObject) obj).save(); } catch (Exception e) { throw new RemoteException(e); } return ObjectSerializer.objectToXml(obj); }
/** * @param sessionId * @param entity * @param query * @return * @throws TorqueException */ public Vector doSearch(String sessionId, String entity, String query) { IReportSource obj = (IReportSource) ObjectSerializer.xmlToObject(entity); Vector results = new Vector(); try { List contentSources = obj.getContentSources(); String[] tmp, indeces; // determine all indeces to use for searching, one index per content source tmp = new String[contentSources.size()]; int count = 0; for (int i = 0; i < contentSources.size(); i++) { ContentSource source = (ContentSource) contentSources.get(i); String index = _indexDirectory + File.separator + source.getContentSourceId(); File testFile = new File(index); if (testFile.exists()) { tmp[i] = index; count++; } } indeces = new String[count]; System.arraycopy(tmp, 0, indeces, 0, count); List documents = QueryTask.search(indeces, query); for (Iterator it = documents.iterator(); it.hasNext(); ) { Document doc = (Document) it.next(); results.add(DocumentUtil.documentToXmlString(doc)); } } catch (Exception e) { logger.error(e); throw new RemoteException(e); } return results; }
/** * @param clientId * @param login * @param password * @return */ public String doLogin(/* long clientId,*/ String login, String password) { User user = UserPeer.doLogin(/* clientId, */ login, password); if (user != null) { return ObjectSerializer.objectToXml(user); } else { throw new RemoteException("Authentification failed. No such user."); } }
/** * @param sessionId * @param objectType * @param keys * @return */ public String retrieveByPks(String sessionId, String objectType, String keys) { Object resultObject = null; List keyObjects = (List) ObjectSerializer.xmlToObject(keys); try { Class peerClass = Class.forName(objectType + "Peer"); Method method = peerClass.getMethod("retrieveByPks", new Class[] {List.class}); resultObject = method.invoke(null, new Object[] {keyObjects}); } catch (Exception e) { throw new RemoteException(e); } if (resultObject != null) { return ObjectSerializer.objectToXml(resultObject); } return ""; }
/** * @param sessionId * @param objectType * @param criteria * @return */ public String doSelect(String sessionId, String objectType, String criteria) { Object resultObject = null; Criteria crit = (Criteria) ObjectSerializer.xmlToObject(criteria); try { Class peerClass = Class.forName(objectType + "Peer"); Method method = peerClass.getMethod("doSelect", new Class[] {Criteria.class}); resultObject = method.invoke(null, new Object[] {crit}); } catch (Exception e) { throw new RemoteException(e); } if (resultObject != null) { return ObjectSerializer.objectToXml(resultObject); } return ""; }
/** * @param sessionId * @param objectType * @param object */ public void doDelete(String sessionId, String object) { Object obj = ObjectSerializer.xmlToObject(object); try { String objClassName = obj.getClass().getName(); Class objClass = Class.forName(objClassName); Class peerClass = Class.forName(objClassName + "Peer"); Method method = peerClass.getMethod("doDelete", new Class[] {objClass}); method.invoke(null, new Object[] {obj}); } catch (Exception e) { throw new RemoteException(e); } }