[Spacewalk-devel] Patch (2/2) to add API support for Listing Server Notes

Michael Stahnke mastahnke at gmail.com
Wed Jun 25 23:09:50 EDT 2008


Here's the second bit.

rom 7a6a0c2431041936ee1000a933da2c42cdd94b0d Mon Sep 17 00:00:00 2001
From: stahnma <stahnma at fedoraproject.org>
Date: Wed, 25 Jun 2008 21:41:21 -0500
Subject: [PATCH] Adding Notes List API call

---
 .../redhat/rhn/domain/server/ServerFactory.java    |   10 ++++++++
 .../xmlrpc/serializer/SerializerRegistry.java      |    1 +
 .../rhn/frontend/xmlrpc/system/SystemHandler.java  |   25 ++++++++++++++++++++
 3 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/java/code/src/com/redhat/rhn/domain/server/ServerFactory.java
b/java/code/src/com/redhat/rhn/domain/server/ServerFactory.java
index 9432670..7b603dd 100644
--- a/java/code/src/com/redhat/rhn/domain/server/ServerFactory.java
+++ b/java/code/src/com/redhat/rhn/domain/server/ServerFactory.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;

 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
@@ -33,6 +34,7 @@ import com.redhat.rhn.common.db.datasource.ModeFactory;
 import com.redhat.rhn.common.db.datasource.SelectMode;
 import com.redhat.rhn.common.hibernate.HibernateFactory;
 import com.redhat.rhn.common.validator.ValidatorError;
+import com.redhat.rhn.domain.action.server.ServerAction;
 import com.redhat.rhn.domain.org.CustomDataKey;
 import com.redhat.rhn.domain.org.Org;
 import com.redhat.rhn.domain.rhnpackage.PackageEvrFactory;
@@ -520,5 +522,13 @@ public class ServerFactory extends HibernateFactory {
         return snaps;
     }

+
+    public static void deleteActions(Set<ServerAction> actions) {
+
+       for (ServerAction action : actions) {
+               ServerFactory.getSession().delete(action);
+       }
+    }
+
 }

diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/SerializerRegistry.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/SerializerRegistry.java
index a56e6e9..e290c35 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/SerializerRegistry.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/SerializerRegistry.java
@@ -83,6 +83,7 @@ public class SerializerRegistry {
         SERIALIZER_CLASSES.add(KickstartScriptSerializer.class);
         SERIALIZER_CLASSES.add(ServerSnapshotSerializer.class);
         SERIALIZER_CLASSES.add(PackageNevraSerializer.class);
+        SERIALIZER_CLASSES.add(NoteSerializer.class);
     }

     /**
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
index 70e29ff..3c389de 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
@@ -69,6 +69,7 @@ import com.redhat.rhn.domain.server.Dmi;
 import com.redhat.rhn.domain.server.InstalledPackage;
 import com.redhat.rhn.domain.server.Location;
 import com.redhat.rhn.domain.server.ManagedServerGroup;
+import com.redhat.rhn.domain.server.Note;
 import com.redhat.rhn.domain.server.Server;
 import com.redhat.rhn.domain.server.ServerFactory;
 import com.redhat.rhn.domain.server.ServerGroupFactory;
@@ -2066,6 +2067,30 @@ public class SystemHandler extends BaseHandler {
     }

     /**
+     * Lists all of the notes that are associated with a system.
+     *   If no notes are found it should return an empty set.
+     * @param sessionKey the session key
+     * @param sid the system id
+     * @return Array of Note objects associated with the given system
+     *
+     * @xmlrpc.doc Provides a list of notes associated with a system.
+     * @xmlrpc.param #param("string", "sessionKey")
+     * @xmlrpc.param #param("int", "serverId")
+     * @xmlrpc.returntype
+     *  #array()
+     *      $NoteSerializer
+     *  #array_end()
+     */
+    public Set<Note> listNotes(String sessionKey , Integer sid)
+    {
+        User loggedInUser = getLoggedInUser(sessionKey);
+        Server server = SystemManager.lookupByIdAndUser(new
Long(sid.longValue()),
+            loggedInUser);
+        return server.getNotes();
+    }
+
+
+    /**
      * Lists all of the packages that are installed on a system that
also belong
      *  to a particular channel.  NOTE: when the arch for an
installed package is
      *  unavailable we do not take it into concern, meaning that it
is arch unaware.
--
1.5.5.1




More information about the Spacewalk-devel mailing list