Author: tolusha
Date: 2011-11-30 08:26:02 -0500 (Wed, 30 Nov 2011)
New Revision: 5248
Added:
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestGroupListener.java
Modified:
core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/GroupDAOImpl.java
core/trunk/exo.core.component.organization.jdbc/src/test/resources/conf/standalone/test-configuration-hibernate.xml
Log:
EXOJCR-1650: Organization Service - open session after preSave()
Modified:
core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/GroupDAOImpl.java
===================================================================
---
core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/GroupDAOImpl.java 2011-11-30
11:57:30 UTC (rev 5247)
+++
core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/GroupDAOImpl.java 2011-11-30
13:26:02 UTC (rev 5248)
@@ -114,12 +114,16 @@
*/
public void addChild(Group parent, Group child, boolean broadcast) throws Exception
{
- Session session = service_.openSession();
String groupId = "/" + child.getGroupName();
GroupImpl childImpl = (GroupImpl)child;
if (parent != null)
{
- Group parentGroup = (Group)session.get(GroupImpl.class, parent.getId());
+ Group parentGroup = findGroupById(parent.getId());
+ if (parentGroup == null)
+ {
+ throw new InvalidNameException("Can't add node to not existed parent
" + parent.getId());
+ }
+
groupId = parentGroup.getId() + "/" + child.getGroupName();
childImpl.setParentId(parentGroup.getId());
}
@@ -127,7 +131,8 @@
{
groupId = child.getId();
}
- Object o = session.get(GroupImpl.class, groupId);
+
+ Object o = findGroupById(groupId);
if (o != null)
{
Object[] args = {child.getGroupName()};
@@ -138,13 +143,14 @@
if (broadcast)
preSave(child, true);
+ Session session = service_.openSession();
session.save(childImpl);
session.flush();
if (broadcast)
postSave(child, true);
}
-
+
/**
* {@inheritDoc}
*/
Modified:
core/trunk/exo.core.component.organization.jdbc/src/test/resources/conf/standalone/test-configuration-hibernate.xml
===================================================================
---
core/trunk/exo.core.component.organization.jdbc/src/test/resources/conf/standalone/test-configuration-hibernate.xml 2011-11-30
11:57:30 UTC (rev 5247)
+++
core/trunk/exo.core.component.organization.jdbc/src/test/resources/conf/standalone/test-configuration-hibernate.xml 2011-11-30
13:26:02 UTC (rev 5248)
@@ -92,8 +92,15 @@
<type>org.exoplatform.services.organization.MembershipTypeEventListener</type>
<description>Membership type listerner for testing
purpose</description>
</component-plugin>
+ <component-plugin>
+ <name>init.service.listener</name>
+ <set-method>addListenerPlugin</set-method>
+
<type>org.exoplatform.services.tck.organization.TestGroupListener</type>
+ <description>this listener populate organization data for the first
launch</description>
+ </component-plugin>
</external-component-plugins>
+
<!-- org service initializer, copied from ECM portal.war -->
<external-component-plugins>
<target-component>org.exoplatform.services.organization.OrganizationService</target-component>
Added:
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestGroupListener.java
===================================================================
---
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestGroupListener.java
(rev 0)
+++
core/trunk/exo.core.component.organization.tests/src/main/java/org/exoplatform/services/tck/organization/TestGroupListener.java 2011-11-30
13:26:02 UTC (rev 5248)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.tck.organization;
+
+import org.exoplatform.container.StandaloneContainer;
+import org.exoplatform.container.component.RequestLifeCycle;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.GroupEventListener;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: TestListener.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class TestGroupListener extends GroupEventListener
+{
+
+ public void preSave(Group group, boolean isNew) throws Exception
+ {
+ RequestLifeCycle.begin(StandaloneContainer.getInstance());
+ RequestLifeCycle.end();
+ }
+}