java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml |
9
java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java |
27 ++
java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java |
98 ++++++++++
java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java |
39 +++
4 files changed, 173 insertions(+)
New commits:
commit 130e2cea44de094d0c2b1fd919630090e56ef508
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Thu Sep 1 15:37:17 2011 +0200
734799 - New API: configchannel.getFileRevision
New API call to get a particular config file revision.
The call accepts following arguments:
* config channel label (string)
* config file path (string)
* config file revision (integer)
In case of success, the call returns config revision (hash with
complete information), traceback otherwise.
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
index 8e3e116..695fcfb 100644
---
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
+++
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
@@ -161,6 +161,41 @@ public class ConfigChannelHandler extends BaseHandler {
}
/**
+ * Get revision for specified config file
+ * @param sessionKey User's session key.
+ * @param configChannelLabel Config channel label.
+ * @param filePath The configuration file path.
+ * @param revision The configuration file revision.
+ * @return Revisions of the configuration file, errors out otherwise.
+ *
+ * @xmlrpc.doc Get revision of the specified config file
+ * @xmlrpc.param #session_key()
+ * @xmlrpc.param #param_desc("string", "configChannelLabel",
+ * "label of config channel to lookup on")
+ * @xmlrpc.param #param_desc("string", "filePath", "config
file path to examine")
+ * @xmlrpc.param #param_desc("int", "revision", "config file
revision to examine")
+ * @xmlrpc.returntype
+ * $ConfigRevisionSerializer
+ */
+ public ConfigRevision getFileRevision(String sessionKey, String configChannelLabel,
+ String filePath, Integer revision) {
+ User loggedInUser = getLoggedInUser(sessionKey);
+ XmlRpcConfigChannelHelper configHelper =
XmlRpcConfigChannelHelper.getInstance();
+ ConfigChannel cc = configHelper.lookupGlobal(loggedInUser, configChannelLabel);
+ ConfigurationManager cm = ConfigurationManager.getInstance();
+ ConfigFile cf = cm.lookupConfigFile(loggedInUser, cc.getId(), filePath);
+
+ if (cf == null) {
+ throw new FaultException(1022, "InvalidConfigFileException",
+ "Could not find configuration file with filePath=: " +
filePath);
+ }
+
+ ConfigRevision cr = cm.lookupConfigRevisionByRevId(loggedInUser, cf,
+ revision.longValue());
+ return cr;
+ }
+
+ /**
* Return a struct of config channel details.
* @param sessionKey User's session key.
* @param configChannelLabel Config channel label.
commit 5067a62c15a29f47da377ca03c7587f3f9f918fe
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Thu Sep 1 13:53:43 2011 +0200
734799 - New API: configchannel.getFileRevisions
New API call to list available config file revisions.
The call accepts following arguments:
* config channel label (string)
* config file path (string)
In case of success, the call returns list of config revisions
(hash with complete information), traceback otherwise.
diff --git a/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml
b/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml
index c4fe45d..ac7fecb 100644
--- a/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml
+++ b/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml
@@ -38,4 +38,8 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
where cr.revision = :rev and
cr.configFile = :cf]]>
</query>
+ <query name="ConfigRevision.findByConfigFile">
+ <![CDATA[from com.redhat.rhn.domain.config.ConfigRevision as cr
+ where cr.configFile = :cf]]>
+ </query>
</hibernate-mapping>
diff --git a/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java
b/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java
index b0e2465..a7122be 100644
--- a/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java
+++ b/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java
@@ -423,6 +423,18 @@ public class ConfigurationFactory extends HibernateFactory {
}
/**
+ * Finds configuration revisions for a given configuration file
+ * @param cf The ConfigFile to look for.
+ * @return List of configuration revisions for given configuration file.
+ */
+ public static List lookupConfigRevisions(ConfigFile cf) {
+ Session session = HibernateFactory.getSession();
+ Query q = session.getNamedQuery("ConfigRevision.findByConfigFile");
+ q.setEntity("cf", cf);
+ return (List<ConfigRevision>) q.list();
+ }
+
+ /**
* Finds a ConfigInfo from the database with a given id.
* @param id The identifier for the ConfigInfo
* @return The sought for ConfigInfo or null if not found.
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
index f6e7047..8e3e116 100644
---
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
+++
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
@@ -124,6 +124,43 @@ public class ConfigChannelHandler extends BaseHandler {
}
/**
+ * Get list of revisions for specified config file
+ * @param sessionKey User's session key.
+ * @param configChannelLabel Config channel label.
+ * @param filePath The configuration file path.
+ * @return List of revisions of the configuration file, errors out otherwise.
+ *
+ * @xmlrpc.doc Get list of revisions for specified config file
+ * @xmlrpc.param #session_key()
+ * @xmlrpc.param #param_desc("string", "channelLabel",
+ * "label of config channel to lookup on")
+ * @xmlrpc.param
+ * #param_desc("string", "config file path to examine")
+ * @xmlrpc.returntype
+ * #array()
+ * $ConfigRevisionSerializer
+ * #array_end()
+ */
+ public List getFileRevisions(String sessionKey, String configChannelLabel,
+ String filePath) {
+ User loggedInUser = getLoggedInUser(sessionKey);
+ XmlRpcConfigChannelHelper configHelper =
XmlRpcConfigChannelHelper.getInstance();
+ ConfigChannel cc = configHelper.lookupGlobal(loggedInUser, configChannelLabel);
+ ConfigurationManager cm = ConfigurationManager.getInstance();
+ ConfigFile cf = cm.lookupConfigFile(loggedInUser, cc.getId(), filePath);
+
+ if (cf == null) {
+ throw new FaultException(1022, "InvalidConfigFileException",
+ "Could not find configuration file with filePath=: " +
filePath);
+ }
+
+ ArrayList<ConfigRevision> revisions =
+ (ArrayList<ConfigRevision>) cm.lookupConfigRevisions(cf);
+
+ return revisions;
+ }
+
+ /**
* Return a struct of config channel details.
* @param sessionKey User's session key.
* @param configChannelLabel Config channel label.
diff --git a/java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java
b/java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java
index a36c0fb..8fcf22a 100644
--- a/java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java
+++ b/java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java
@@ -1914,6 +1914,15 @@ public class ConfigurationManager extends BaseManager {
}
/**
+ * For a given configuration file, return list of config revisions
+ * @param cf ConfigFile to lookup the revision for.
+ * @return List of config file revisions.
+ */
+ public List lookupConfigRevisions(ConfigFile cf) {
+ return ConfigurationFactory.lookupConfigRevisions(cf);
+ }
+
+ /**
* @param uid The user id
* @param ccid The config channel id
* @return whether the user with the given id can view the
commit 66852a112809b10e110186f5e604369cb42992f6
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Wed Aug 31 16:08:54 2011 +0200
734799 - New API: configchannel.deleteFileRevisions
New API call to delete arbitrary config file revision (if permissions permit).
The call accepts following arguments:
* config channel label (string)
* config file path (string)
* list of config file revisions to delete (list of integers)
The call returns 1 in case of success, traceback otherwise.
diff --git a/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml
b/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml
index 685ee3c..c4fe45d 100644
--- a/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml
+++ b/java/code/src/com/redhat/rhn/domain/config/ConfigRevision.hbm.xml
@@ -33,4 +33,9 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
column="config_file_type_id"
cascade="none" />
</class>
+ <query name="ConfigRevision.findByRevisionAndConfigFile">
+ <![CDATA[from com.redhat.rhn.domain.config.ConfigRevision as cr
+ where cr.revision = :rev and
+ cr.configFile = :cf]]>
+ </query>
</hibernate-mapping>
diff --git a/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java
b/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java
index 149f53c..b0e2465 100644
--- a/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java
+++ b/java/code/src/com/redhat/rhn/domain/config/ConfigurationFactory.java
@@ -407,6 +407,21 @@ public class ConfigurationFactory extends HibernateFactory {
return a;
}
+
+ /**
+ * Finds a ConfigRevision for a given ConfigFile and given revision id
+ * @param ConfigFile The ConfigFile to look for.
+ * @param rev_id The ConfigFile revision to look for.
+ * @return ConfigRevision The sought for ConfigRevision.
+ */
+ public static ConfigRevision lookupConfigRevisionByRevId(ConfigFile cf, Long rev_id)
{
+ Session session = HibernateFactory.getSession();
+ Query q =
session.getNamedQuery("ConfigRevision.findByRevisionAndConfigFile");
+ q.setLong("rev", rev_id.longValue());
+ q.setEntity("cf", cf);
+ return (ConfigRevision) q.uniqueResult();
+ }
+
/**
* Finds a ConfigInfo from the database with a given id.
* @param id The identifier for the ConfigInfo
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
index c68ac14..f6e7047 100644
---
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
+++
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/configchannel/ConfigChannelHandler.java
@@ -98,6 +98,32 @@ public class ConfigChannelHandler extends BaseHandler {
}
/**
+ * Delete specified revisions of a given configuration file
+ * @param sessionKey User's session key.
+ * @param configChannelLabel Config channel label.
+ * @param filePath The configuration file path.
+ * @param revisions List of configuration file revisions to delete.
+ * @return 1 if deletion succeeds, errors out otherwise.
+ */
+ public int deleteFileRevisions(String sessionKey, String configChannelLabel,
+ String filePath, List<Integer> revisions) {
+ User loggedInUser = getLoggedInUser(sessionKey);
+
+ XmlRpcConfigChannelHelper configHelper =
XmlRpcConfigChannelHelper.getInstance();
+ ConfigChannel cc = configHelper.lookupGlobal(loggedInUser, configChannelLabel);
+ ConfigurationManager cm = ConfigurationManager.getInstance();
+ ConfigFile cf = cm.lookupConfigFile(loggedInUser, cc.getId(), filePath);
+
+ for (Integer rev_id : revisions) {
+ ConfigRevision cr = cm.lookupConfigRevisionByRevId(loggedInUser, cf,
+ rev_id.longValue());
+ cm.deleteConfigRevision(loggedInUser, cr);
+ }
+
+ return 1;
+ }
+
+ /**
* Return a struct of config channel details.
* @param sessionKey User's session key.
* @param configChannelLabel Config channel label.
diff --git a/java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java
b/java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java
index 0bd5853..a36c0fb 100644
--- a/java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java
+++ b/java/code/src/com/redhat/rhn/manager/configuration/ConfigurationManager.java
@@ -1884,6 +1884,36 @@ public class ConfigurationManager extends BaseManager {
}
/**
+ * For a given configuration file, looks up a config revision id
+ * @param user The user requesting to lookup a config revision.
+ * @param cf The ConfigFile that the revision applies to
+ * @param rev_id The ConfigFile revision id.
+ * @return The sought for config revision.
+ */
+ public ConfigRevision lookupConfigRevisionByRevId(User user, ConfigFile cf,
+ Long rev_id) {
+ ConfigRevision cr = ConfigurationFactory.lookupConfigRevisionByRevId(cf,
rev_id);
+
+ if (cr == null) {
+ throw new LookupException("Could not find config revision with revision
id="
+ + rev_id);
+ }
+
+ if (!accessToRevision(user.getId(), cr.getId())) {
+ LocalizationService ls = LocalizationService.getInstance();
+ LookupException e =
+ new LookupException("Could not find config revision with revision
id="
+ + rev_id);
+ e.setLocalizedTitle(ls.getMessage("lookup.configrev.title"));
+ e.setLocalizedReason1(ls.getMessage("lookup.configrev.reason1"));
+ e.setLocalizedReason2(ls.getMessage("lookup.configrev.reason2"));
+ throw e;
+ }
+
+ return cr;
+ }
+
+ /**
* @param uid The user id
* @param ccid The config channel id
* @return whether the user with the given id can view the