aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib
diff options
context:
space:
mode:
authorGerwin Gsenger <g.gsenger@datentechnik-innovation.at>2015-01-30 11:11:40 +0100
committerGerwin Gsenger <g.gsenger@datentechnik-innovation.at>2015-01-30 11:23:42 +0100
commit4b8f2b481636ef71146d382f386f9c297da7a64b (patch)
tree01ea16dd62c3012c5f15a9494ea367b5eacd9bab /id/server/idserverlib
parentfca585327afd4fd3dc0b5f1146cbb5d8648c3a41 (diff)
downloadmoa-id-spss-4b8f2b481636ef71146d382f386f9c297da7a64b.tar.gz
moa-id-spss-4b8f2b481636ef71146d382f386f9c297da7a64b.tar.bz2
moa-id-spss-4b8f2b481636ef71146d382f386f9c297da7a64b.zip
implement DAO methods, add exeptions to ProcessInstanceStoreDAO interface
Diffstat (limited to 'id/server/idserverlib')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java3
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAO.java35
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java91
3 files changed, 95 insertions, 34 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
index a67badf49..0dfd2236f 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
@@ -110,10 +110,10 @@ import at.gv.egovernment.moa.id.config.auth.data.ProtocolAllowed;
import at.gv.egovernment.moa.id.config.legacy.BuildFromLegacyConfig;
import at.gv.egovernment.moa.id.config.stork.STORKConfig;
import at.gv.egovernment.moa.id.data.IssuerAndSerial;
+import at.gv.egovernment.moa.id.process.dao.ProcessInstanceStore;
import at.gv.egovernment.moa.id.protocols.pvp2x.config.MOADefaultBootstrap;
import at.gv.egovernment.moa.logging.Logger;
import at.gv.egovernment.moa.util.MiscUtil;
-import at.gv.util.config.EgovUtilConfiguration;
import at.gv.util.config.EgovUtilPropertiesConfiguration;
/**
@@ -344,6 +344,7 @@ public class AuthConfigurationProvider extends ConfigurationProvider {
config.addAnnotatedClass(OldSSOSessionIDStore.class);
config.addAnnotatedClass(ExceptionStore.class);
config.addAnnotatedClass(InterfederationSessionStore.class);
+ config.addAnnotatedClass(ProcessInstanceStore.class);
config.addProperties(moaSessionProp);
MOASessionDBUtils.initHibernate(config, moaSessionProp);
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAO.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAO.java
index 57489c33e..0aa6f80cd 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAO.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAO.java
@@ -2,6 +2,7 @@ package at.gv.egovernment.moa.id.process.dao;
import java.util.List;
+import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
import at.gv.egovernment.moa.id.process.ProcessInstance;
public interface ProcessInstanceStoreDAO {
@@ -12,18 +13,23 @@ public interface ProcessInstanceStoreDAO {
*
* @param pIStore
* the {@link ProcessInstanceStore} to persist.
+ * @throws MOADatabaseException
+ * is thrown if a problem occurs while accessing the database.
*/
- void save(ProcessInstanceStore pIStore);
+ void save(ProcessInstanceStore pIStore) throws MOADatabaseException;
/**
- * Loads a {@link ProcessInstanceStore}, defined by
- * {@code processInstanceID} from the database.
+ * Returns a {@link ProcessInstanceStore}, defined by
+ * {@code processInstanceID} from the database, or {@code null} if the
+ * object could not be found.
*
* @param processInstanceID
* the id of the {@code ProcessInstanceStore} to retrieve.
- * @return a ProcessInstanceStore.
+ * @return a ProcessInstanceStore, or {@code null}.
+ * @throws MOADatabaseException
+ * is thrown if a problem occurs while accessing the database.
*/
- ProcessInstanceStore load(String processInstanceId);
+ ProcessInstanceStore load(String processInstanceId) throws MOADatabaseException;
/**
* Deletes the {@link ProcessInstance} corresponding with the
@@ -31,26 +37,19 @@ public interface ProcessInstanceStoreDAO {
*
* @param processInstanceID
* the id of the {@code ProcessInstance} to be deleted.
+ * @throws MOADatabaseException
+ * is thrown if a problem occurs while accessing the database.
*/
- void remove(String processInstanceId);
+ void remove(String processInstanceId) throws MOADatabaseException;
/**
* Returns all {@link ProcessInstanceStore} objects stored in the database.
* The returned list may be empty, but never {@code null}.
*
* @return a list of {@link ProcessInstanceStore} (never {@code null}).
+ * @throws MOADatabaseException
+ * is thrown if a problem occurs while accessing the database.
*/
- List<ProcessInstanceStore> getAllProcessInstanceStores();
-
- /**
- * Returns the specific {@link ProcessInstanceStore} object corresponding to
- * the given {@code processInstanceId}, or {@code null} if the object could
- * not be found.
- *
- * @param processInstanceId
- * the processInstanceId to search.
- * @return the ProcessInstanceStore for the given id, or {@code null}.
- */
- ProcessInstanceStore getProcessInstance(String processInstanceId);
+ List<ProcessInstanceStore> getAllProcessInstanceStores() throws MOADatabaseException;
}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java
index cde34acd1..f5fb71145 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java
@@ -1,10 +1,18 @@
package at.gv.egovernment.moa.id.process.dao;
+import java.util.Collections;
import java.util.List;
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils;
+import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
+
/**
* Database backed implementation of the {@link ProcessInstanceStoreDAO}
* interface.
@@ -20,32 +28,85 @@ public class ProcessInstanceStoreDAOImpl implements ProcessInstanceStoreDAO {
}
@Override
- public void save(ProcessInstanceStore pIStore) {
- // TODO Auto-generated method stub
+ public void save(ProcessInstanceStore pIStore) throws MOADatabaseException {
+ try {
+ MOASessionDBUtils.saveOrUpdate(pIStore);
+ log.debug("Store process instance with='{}' in the database.", pIStore.getProcessInstanceId());
+ } catch (MOADatabaseException e) {
+ log.warn("ProcessInstanceStore could not be persisted to the database.");
+ throw e;
+ }
}
@Override
- public ProcessInstanceStore load(String processInstanceID) {
- // TODO Auto-generated method stub
- return null;
- }
+ public ProcessInstanceStore load(String processInstanceId) throws MOADatabaseException {
- @Override
- public void remove(String processInstanceId) {
- // TODO Auto-generated method stub
+ log.debug("Retrieve the ProcessInstanceStore for id='{}' from the database.", processInstanceId);
+ Session session = MOASessionDBUtils.getCurrentSession();
+ ProcessInstanceStore result = null;
+ Transaction tx = null;
+ try {
+ synchronized (session) {
+ tx = session.beginTransaction();
+ // select all where processInstanceId equals processInstanceId
+ Criteria criteria = session.createCriteria(ProcessInstanceStore.class);
+ criteria.add(Restrictions.eq("processInstanceId", processInstanceId));
+ result = (ProcessInstanceStore) criteria.uniqueResult();
+ tx.commit();
+ }
+ } catch (Exception e) {
+ log.error("There are multiple persisted processes with the same process instance id '{}'",
+ processInstanceId);
+ if (tx != null) {
+ tx.rollback();
+ }
+ throw e;
+ } finally {
+ MOASessionDBUtils.closeSession();
+ }
+ return result;
}
@Override
- public List<ProcessInstanceStore> getAllProcessInstanceStores() {
- // TODO Auto-generated method stub
- return null;
+ public void remove(String processInstanceId) throws MOADatabaseException {
+
+ log.debug("Delete the ProcessInstanceStore for id='{}' from the database.", processInstanceId);
+
+ ProcessInstanceStore toBeDeleted = load(processInstanceId);
+ boolean result = MOASessionDBUtils.delete(toBeDeleted);
+ if (result == false) {
+ log.warn("Could not delete the ProcessInstanceStore with process instance id '{}'", processInstanceId);
+ throw new MOADatabaseException("Could not delete the ProcessInstanceStore with process instance id '"
+ + processInstanceId + "'.");
+ }
}
+ @SuppressWarnings("unchecked")
@Override
- public ProcessInstanceStore getProcessInstance(String processInstanceId) {
- // TODO Auto-generated method stub
- return null;
+ public List<ProcessInstanceStore> getAllProcessInstanceStores() throws MOADatabaseException {
+ log.debug("Retrieve a list with all ProcessInstanceStores from the database.");
+ Session session = MOASessionDBUtils.getCurrentSession();
+
+ List<ProcessInstanceStore> result = Collections.emptyList();
+ Transaction tx = null;
+ try {
+ synchronized (session) {
+ tx = session.beginTransaction();
+ // select all
+ result = session.createCriteria(ProcessInstanceStore.class).list();
+ tx.commit();
+ }
+ } catch (Exception e) {
+ log.error("A problem occured while retrieving all stored ProcessInstanceStores.");
+ if (tx != null) {
+ tx.rollback();
+ }
+ throw e;
+ } finally {
+ MOASessionDBUtils.closeSession();
+ }
+ return result;
}
}