From fca58de78a990566f93c7cb7b0be7957c6d102d4 Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@jalin.de>
Date: Thu, 17 Nov 2016 13:24:43 +0100
Subject: [PATCH] perform pac-processor

---
 hsarback/src/de/hsadmin/mods/pac/PacTasksServlet.java |   38 +++++++++++++++++++++++++++++---------
 1 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/hsarback/src/de/hsadmin/mods/pac/PacTasksServlet.java b/hsarback/src/de/hsadmin/mods/pac/PacTasksServlet.java
index ecc9771..050371b 100644
--- a/hsarback/src/de/hsadmin/mods/pac/PacTasksServlet.java
+++ b/hsarback/src/de/hsadmin/mods/pac/PacTasksServlet.java
@@ -17,6 +17,8 @@
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -24,6 +26,8 @@
 
 import de.hsadmin.core.model.TechnicalException;
 import de.hsadmin.core.model.Transaction;
+import de.hsadmin.core.qserv.Processor;
+import de.hsadmin.core.qserv.QueueTask;
 import de.hsadmin.core.util.Config;
 
 public class PacTasksServlet extends HttpServlet 
@@ -106,17 +110,33 @@
 		messageCount++;
 		try {
 			final TextMessage txtMessage = (TextMessage) jmsMessage;
-			System.out.println(txtMessage.getText());
-//			transaction = new Transaction("pactasks");
-//			transaction.beginTransaction();
-//			EntityManager em = transaction.getEntityManager();
-//			em.clear();
-//			em.persist(persistentQT);
-//			em.flush();
-//			transaction.commitTransaction();
+			final String message = txtMessage.getText();
+			System.out.println(message);
+			final String[] parts = message.split(":");
+			transaction = new Transaction("pactasks");
+			transaction.beginTransaction();
+			final EntityManager em = transaction.getEntityManager();
+			final Query qPac = em.createQuery("SELECT p FROM Pacs p WHERE p.name = :name");
+			qPac.setParameter("name", parts[1]);
+			final Pac pac = (Pac) qPac.getSingleResult();
+			final PacProcessorFactory factory = new PacProcessorFactory();
+			Processor proc = null;
+			if ("pac.add".equals(parts[0])) {
+				proc = factory.createCreateProcessor(em, pac);
+			}
+			if ("pac.update".equals(parts[0])) {
+				proc = factory.createUpdateProcessor(em, pac);
+			}
+			if ("pac.delete".equals(parts[0])) {
+				proc = factory.createDeleteProcessor(em, pac);
+			}
+			transaction.enqueue(pac.getHiveName(), new QueueTask(pac.owningUser(em), parts[0] + ":" + parts[1], message, proc));
+			em.clear();
+			em.flush();
+			transaction.commitTransaction();
 		} catch (Exception e) {
 			errorCount++;
-//			if (transaction != null) transaction.rollbackTransaction();
+			if (transaction != null) transaction.rollbackTransaction();
 			throw new TechnicalException(e);
 		} finally {
 			if (transaction != null) transaction.close();

--
Gitblit v1.9.0-SNAPSHOT