From 6bb368fb37325070f138175d630fc4322ca491bc Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@hostsharing.net>
Date: Wed, 23 Mar 2011 16:49:58 +0100
Subject: [PATCH] Paket und Admin-User in HSDB anlegen

---
 hsarback/src/de/hsadmin/mods/user/UnixUser.java     |    4 +++-
 hsarback/test/de/hsadmin/remote/PacTest.java        |    3 +--
 hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java |   17 +++++++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
index dcccd0c..ddd73df 100644
--- a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
+++ b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
@@ -11,7 +11,9 @@
 import de.hsadmin.core.model.AbstractEntity;
 import de.hsadmin.core.model.AbstractModuleImpl;
 import de.hsadmin.core.model.HSAdminException;
+import de.hsadmin.mods.cust.Contact;
 import de.hsadmin.mods.cust.Customer;
+import de.hsadmin.mods.user.UnixUser;
 
 public class PacModuleImpl extends AbstractModuleImpl {
 
@@ -77,6 +79,21 @@
 			pacComponents.add(pacComponent);
 		}
 		pac.setPacComponents(pacComponents);
+		Set<UnixUser> users = new HashSet<UnixUser>();
+		pac.setUnixUser(users);
+		UnixUser admin = new UnixUser();
+		Contact contact = customer.getContractualContact();
+		admin.setComment(contact.getFirstName() + " " + contact.getLastName());
+		admin.setHomedir("/home/pacs/" + pac.getName());
+		admin.setName(pac.getName());
+		admin.setShell("/bin/bash");
+		admin.setQuotaSoftlimit(0);
+		admin.setQuotaHardlimit(0);
+		admin.setPac(pac);
+		long nUID = 20000;
+		Long maxUid = (Long) em.createQuery("SELECT MAX(u.userId) FROM UnixUsers u").getSingleResult();
+		if (maxUid >= nUID) nUID = maxUid + 1;
+		admin.setUserId(nUID);
 		return super.add(newEntity);
 	}
 	
diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUser.java b/hsarback/src/de/hsadmin/mods/user/UnixUser.java
index 12763b8..57594db 100644
--- a/hsarback/src/de/hsadmin/mods/user/UnixUser.java
+++ b/hsarback/src/de/hsadmin/mods/user/UnixUser.java
@@ -156,7 +156,9 @@
 
 	public void setPac(Pac pac) {
 		this.pac = pac;
-		pac.getUnixUser().add(this);
+		if (pac.getUnixUser() != null) {
+			pac.getUnixUser().add(this);
+		}
 	}
 
 	public String getComment() {
diff --git a/hsarback/test/de/hsadmin/remote/PacTest.java b/hsarback/test/de/hsadmin/remote/PacTest.java
index 793c70d..3918277 100644
--- a/hsarback/test/de/hsadmin/remote/PacTest.java
+++ b/hsarback/test/de/hsadmin/remote/PacTest.java
@@ -75,10 +75,9 @@
 			assertNotNull(execute);
 			fail("exception expected");
 		} catch (XmlRpcException e) {
-//			System.out.println(e.getMessage());
+
 		}
 	}
-
 
 	@Test
 	public void testCreate() {

--
Gitblit v1.9.1