Author: ilgrosso
Date: Thu Oct 9 09:48:42 2014
New Revision: 1630356
URL: http://svn.apache.org/r1630356
Log:
[SYNCOPE-562] Fixing ConfDAO implementation
Modified:
syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ConfDAOImpl.java
syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java
Modified:
syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ConfDAOImpl.java
URL:
http://svn.apache.org/viewvc/syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ConfDAOImpl.java?rev=1630356&r1=1630355&r2=1630356&view=diff
==============================================================================
---
syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ConfDAOImpl.java
(original)
+++
syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ConfDAOImpl.java
Thu Oct 9 09:48:42 2014
@@ -22,6 +22,7 @@ import org.apache.syncope.common.types.A
import org.apache.syncope.core.persistence.beans.conf.CAttr;
import org.apache.syncope.core.persistence.beans.conf.CSchema;
import org.apache.syncope.core.persistence.beans.conf.SyncopeConf;
+import org.apache.syncope.core.persistence.dao.AttrDAO;
import org.apache.syncope.core.persistence.dao.ConfDAO;
import org.apache.syncope.core.persistence.dao.SchemaDAO;
import org.apache.syncope.core.util.AttributableUtil;
@@ -35,6 +36,9 @@ public class ConfDAOImpl extends Abstrac
@Autowired
private SchemaDAO schemaDAO;
+ @Autowired
+ private AttrDAO attrDAO;
+
@Override
public SyncopeConf get() {
SyncopeConf instance = entityManager.find(SyncopeConf.class, 1L);
@@ -70,10 +74,19 @@ public class ConfDAOImpl extends Abstrac
@Override
public SyncopeConf save(final CAttr attr) {
- delete(attr.getSchema().getName());
-
SyncopeConf instance = get();
+
+ CAttr old = instance.getAttr(attr.getSchema().getName());
+ if (old != null && (!attr.getSchema().isUniqueConstraint()
+ ||
(!attr.getUniqueValue().getStringValue().equals(old.getUniqueValue().getStringValue()))))
{
+
+ instance.removeAttr(old);
+ attrDAO.delete(old.getId(), CAttr.class);
+ }
+
instance.addAttr(attr);
+ attr.setOwner(instance);
+
return entityManager.merge(instance);
}
Modified:
syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java
URL:
http://svn.apache.org/viewvc/syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java?rev=1630356&r1=1630355&r2=1630356&view=diff
==============================================================================
---
syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java
(original)
+++
syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java
Thu Oct 9 09:48:42 2014
@@ -48,9 +48,11 @@ import org.apache.syncope.core.persisten
import org.apache.syncope.core.persistence.beans.Notification;
import org.apache.syncope.core.persistence.beans.NotificationTask;
import org.apache.syncope.core.persistence.beans.conf.CAttr;
+import org.apache.syncope.core.persistence.beans.conf.CSchema;
import org.apache.syncope.core.persistence.dao.ConfDAO;
import org.apache.syncope.core.persistence.dao.EntitlementDAO;
import org.apache.syncope.core.persistence.dao.NotificationDAO;
+import org.apache.syncope.core.persistence.dao.SchemaDAO;
import org.apache.syncope.core.persistence.dao.TaskDAO;
import org.apache.syncope.core.rest.UserTestITCase;
import org.apache.syncope.core.rest.controller.RoleController;
@@ -121,6 +123,9 @@ public class NotificationTest {
private TaskDAO taskDAO;
@Autowired
+ private SchemaDAO schemaDAO;
+
+ @Autowired
private ConfDAO confDAO;
@Autowired
@@ -400,8 +405,8 @@ public class NotificationTest {
userController.create(userTO, true);
// 3. Set number of retries
- CAttr maxRetries = confDAO.find("notification.maxRetries", "5");
- maxRetries.getValues().clear();
+ CAttr maxRetries = new CAttr();
+ maxRetries.setSchema(schemaDAO.find("notification.maxRetries",
CSchema.class));
maxRetries.addValue("5",
AttributableUtil.getInstance(AttributableType.CONFIGURATION));
confDAO.save(maxRetries);
confDAO.flush();
@@ -429,8 +434,8 @@ public class NotificationTest {
startGreenMail();
// 8. reset number of retries
- maxRetries = confDAO.find("notification.maxRetries", "5");
- maxRetries.getValues().clear();
+ maxRetries = new CAttr();
+ maxRetries.setSchema(schemaDAO.find("notification.maxRetries",
CSchema.class));
maxRetries.addValue("0",
AttributableUtil.getInstance(AttributableType.CONFIGURATION));
confDAO.save(maxRetries);
confDAO.flush();