HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2016-11-17 fca58de78a990566f93c7cb7b0be7957c6d102d4
perform pac-processor
1 files modified
38 ■■■■ changed files
hsarback/src/de/hsadmin/mods/pac/PacTasksServlet.java 38 ●●●● patch | view | raw | blame | history
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();