java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml | 2
java/code/src/com/redhat/rhn/domain/channel/ChannelFamily.java | 7 -
java/code/src/com/redhat/rhn/domain/errata/impl/PublishedErrata.hbm.xml | 1
java/code/src/com/redhat/rhn/domain/org/OrgFactory.java | 10 -
java/code/src/com/redhat/rhn/domain/org/test/OrgFactoryTest.java | 69
++++++++++
java/code/src/com/redhat/rhn/manager/entitlement/EntitlementProcedure.java | 3
6 files changed, 82 insertions(+), 10 deletions(-)
New commits:
commit 285356391b0083a3a1fbee29107ac5567f0ff4b0
Author: Justin Sherrill <jsherril(a)redhat.com>
Date: Fri May 28 18:04:05 2010 -0400
fixes for org deletion and moving java code to use new org delete
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
b/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
index 7e187a1..9360561 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/System_queries.xml
@@ -405,7 +405,7 @@ ORDER BY UPPER(NVL(S.name, '(none)')), S.id
INFO.checkin AS LAST_CHECKIN
FROM rhnServer S, rhnServerInfo INFO
WHERE
- S.org_id = :org_id
+ S.org_id = :org_id and
S.id = INFO.server_id
</query>
</mode>
diff --git a/java/code/src/com/redhat/rhn/domain/channel/ChannelFamily.java
b/java/code/src/com/redhat/rhn/domain/channel/ChannelFamily.java
index 1f1ddfb..d564af9 100644
--- a/java/code/src/com/redhat/rhn/domain/channel/ChannelFamily.java
+++ b/java/code/src/com/redhat/rhn/domain/channel/ChannelFamily.java
@@ -206,8 +206,10 @@ public class ChannelFamily extends BaseDomainHelper {
*/
public Long getMaxMembers(Org orgIn) {
PrivateChannelFamily pcf = getChannelFamilyAllocationFor(orgIn);
+ if (pcf == null) {
+ return 0L;
+ }
return pcf.getMaxMembers();
-
}
/**
@@ -217,6 +219,9 @@ public class ChannelFamily extends BaseDomainHelper {
*/
public Long getCurrentMembers(Org orgIn) {
PrivateChannelFamily pcf = getChannelFamilyAllocationFor(orgIn);
+ if (pcf == null) {
+ return 0L;
+ }
return pcf.getCurrentMembers();
}
/**
diff --git a/java/code/src/com/redhat/rhn/domain/errata/impl/PublishedErrata.hbm.xml
b/java/code/src/com/redhat/rhn/domain/errata/impl/PublishedErrata.hbm.xml
index 6420dd2..26bd955 100644
--- a/java/code/src/com/redhat/rhn/domain/errata/impl/PublishedErrata.hbm.xml
+++ b/java/code/src/com/redhat/rhn/domain/errata/impl/PublishedErrata.hbm.xml
@@ -104,7 +104,6 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
and c.org = :org]]>
</query>
<query name="PublishedErrata.listIdsByOrg">
- <return-scalar type="long" column="id"/>
<![CDATA[
Select e.id as id
from com.redhat.rhn.domain.errata.impl.PublishedErrata as e
diff --git a/java/code/src/com/redhat/rhn/domain/org/OrgFactory.java
b/java/code/src/com/redhat/rhn/domain/org/OrgFactory.java
index 8149a1e..201bb86 100644
--- a/java/code/src/com/redhat/rhn/domain/org/OrgFactory.java
+++ b/java/code/src/com/redhat/rhn/domain/org/OrgFactory.java
@@ -23,6 +23,7 @@ import com.redhat.rhn.common.localization.LocalizationService;
import com.redhat.rhn.domain.channel.ChannelFamily;
import com.redhat.rhn.domain.role.RoleFactory;
import com.redhat.rhn.domain.server.ServerGroup;
+import com.redhat.rhn.manager.org.OrgProcedure;
import org.apache.log4j.Logger;
import org.hibernate.Session;
@@ -88,13 +89,8 @@ import java.util.Map;
*/
public static void deleteOrg(Long oid) {
// put in a sanity check here to make sure org exists
- //Org org = OrgFactory.lookupById(oid);
-
- Map in = new HashMap();
- in.put("org_id", oid);
- CallableMode m = ModeFactory.getCallableMode(
- "Org_queries", "delete_organization");
- m.execute(in, new HashMap());
+ Org org = OrgFactory.lookupById(oid);
+ OrgProcedure.getInstance().deleteOrg(org);
}
/**
diff --git a/java/code/src/com/redhat/rhn/domain/org/test/OrgFactoryTest.java
b/java/code/src/com/redhat/rhn/domain/org/test/OrgFactoryTest.java
index 15b2ffc..7b6acdf 100644
--- a/java/code/src/com/redhat/rhn/domain/org/test/OrgFactoryTest.java
+++ b/java/code/src/com/redhat/rhn/domain/org/test/OrgFactoryTest.java
@@ -19,7 +19,9 @@ import com.redhat.rhn.common.db.datasource.ModeFactory;
import com.redhat.rhn.common.db.datasource.WriteMode;
import com.redhat.rhn.domain.channel.Channel;
import com.redhat.rhn.domain.channel.ChannelFamily;
+import com.redhat.rhn.domain.channel.ChannelFamilyFactory;
import com.redhat.rhn.domain.channel.test.ChannelFactoryTest;
+import com.redhat.rhn.domain.errata.test.ErrataFactoryTest;
import com.redhat.rhn.domain.org.CustomDataKey;
import
com.redhat.rhn.domain.org.Org;
import com.redhat.rhn.domain.org.OrgEntitlementType;
@@ -30,18 +32,26 @@ import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.server.ServerConstants;
import com.redhat.rhn.domain.server.ServerGroup;
import com.redhat.rhn.domain.server.ServerGroupFactory;
+import com.redhat.rhn.domain.server.test.ServerFactoryTest;
import com.redhat.rhn.domain.server.test.ServerGroupTest;
import com.redhat.rhn.domain.token.ActivationKey;
import com.redhat.rhn.domain.token.Token;
import com.redhat.rhn.domain.token.TokenFactory;
import com.redhat.rhn.domain.token.test.ActivationKeyTest;
import com.redhat.rhn.domain.user.User;
+import com.redhat.rhn.domain.user.UserFactory;
+import com.redhat.rhn.manager.entitlement.EntitlementManager;
+import com.redhat.rhn.manager.org.UpdateOrgSoftwareEntitlementsCommand;
+import com.redhat.rhn.manager.org.UpdateOrgSystemEntitlementsCommand;
+import com.redhat.rhn.testing.ConfigTestUtils;
import com.redhat.rhn.testing.RhnBaseTestCase;
import com.redhat.rhn.testing.ServerGroupTestUtils;
import com.redhat.rhn.testing.ServerTestUtils;
import com.redhat.rhn.testing.TestUtils;
import com.redhat.rhn.testing.UserTestUtils;
+import org.apache.commons.lang.RandomStringUtils;
+
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -370,4 +380,63 @@ public class OrgFactoryTest extends RhnBaseTestCase {
assertTrue(totalOrgs.size() > 0);
}
+
+ private Long getMasterManagement() {
+ return EntitlementManager.getMaxEntitlements(EntitlementManager.MANAGEMENT,
+ OrgFactory.getSatelliteOrg());
+ }
+
+ private Long getMasterRhelServer() {
+ return ChannelFamilyFactory.lookupByLabel(
+ "rhel-server", null).getChannelFamilyAllocationFor(
+ OrgFactory.getSatelliteOrg()).getMaxMembers();
+ }
+
+ public void testDeleteOrg() throws Exception {
+ Long initialMgmnt = getMasterManagement();
+ assertTrue(initialMgmnt.longValue() > 0);
+ Long initialRhel = getMasterRhelServer();
+ assertTrue(initialRhel.longValue() > 0);
+ Long changeAmt = 10L;
+
+ OrgFactoryTest test = new OrgFactoryTest();
+ Org org = test.createTestOrg();
+ Long oid = org.getId();
+ User user = UserTestUtils.createUser(RandomStringUtils.randomAlphabetic(15),
oid);
+ user.addRole(RoleFactory.ORG_ADMIN);
+ UserFactory.save(user);
+
+
+
+ //clear to get the new entitlements below
+ OrgFactory.getSession().clear();
+
+ //Give it some system entitlements
+ UpdateOrgSystemEntitlementsCommand cmd1 = new
UpdateOrgSystemEntitlementsCommand(
+ EntitlementManager.MANAGEMENT, org, changeAmt);
+ cmd1.store();
+ assertEquals(initialMgmnt.longValue() - getMasterManagement().longValue(),
+ changeAmt.longValue());
+
+ //Give it some system entitlements
+ UpdateOrgSoftwareEntitlementsCommand cmd2
+ = new UpdateOrgSoftwareEntitlementsCommand("rhel-server", org,
changeAmt);
+ cmd2.store();
+ OrgFactory.getSession().clear();
+ assertEquals(initialRhel.longValue() - getMasterRhelServer().longValue(),
+ changeAmt.longValue());
+
+
+ ServerFactoryTest.createTestServer(org.getActiveOrgAdmins().get(0));
+ ErrataFactoryTest.createTestPublishedErrata(oid);
+ ConfigTestUtils.createConfigChannel(org);
+ org = null;
+ OrgFactory.deleteOrg(oid);
+ OrgFactory.getSession().clear();
+ assertNull(OrgFactory.lookupById(oid));
+
+ assertEquals(initialMgmnt, getMasterManagement());
+ assertEquals(initialRhel, getMasterRhelServer());
+ }
+
}
diff --git a/java/code/src/com/redhat/rhn/manager/entitlement/EntitlementProcedure.java
b/java/code/src/com/redhat/rhn/manager/entitlement/EntitlementProcedure.java
index dfafc51..8f23e7e 100644
--- a/java/code/src/com/redhat/rhn/manager/entitlement/EntitlementProcedure.java
+++ b/java/code/src/com/redhat/rhn/manager/entitlement/EntitlementProcedure.java
@@ -81,6 +81,9 @@ public class EntitlementProcedure {
List<PrivateChannelFamily> privChannels =
ChannelFamilyFactory.listPrivateChannelFamiles(org);
for (PrivateChannelFamily priv : privChannels) {
+ if (priv.getChannelFamily().getOrg() != null) {
+ continue;
+ }
PrivateChannelFamily masterFam =
priv.getChannelFamily().getChannelFamilyAllocationFor(masterOrg);
ChannelFactory.lockPrivateChannelFamily(priv);