Author: bdaw
Date: 2008-09-19 07:37:32 -0400 (Fri, 19 Sep 2008)
New Revision: 93
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/NotYetImplementedException.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObject.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectAttribute.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectRelationship.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectRelationshipType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FeaturesDescriptionImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/HibernateIdentityStoreImpl.java
trunk/identity-impl/src/test/java/org/jboss/identity/
trunk/identity-impl/src/test/java/org/jboss/identity/impl/
trunk/identity-impl/src/test/java/org/jboss/identity/impl/SimpleIdentityObjectRelationshipTypeImpl.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/SimpleIdentityObjectTypeImpl.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/fedid/
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateIdentityStoreTestCase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateModelTestCase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateTestBase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/IdentityTypeEnum.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/RelationshipTypeEnum.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStoreContext.java
Removed:
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityAttribute.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectAttribute.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/fedid/
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/JPAModelTestCase.java
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java
trunk/identity-impl/pom.xml
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FileBasedIdentityStore.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleGroup.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/fedid/PseudonymGeneratorUnitTestCase.java
trunk/identity-impl/src/test/resources/META-INF/persistence.xml
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/FeaturesDescription.java
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java
trunk/parent/pom.xml
Log:
sync code
- simple implementation of Hibernate store
Deleted: trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityAttribute.java
===================================================================
---
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityAttribute.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityAttribute.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -1,32 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.jboss.identity.api;
-
-/**
- * An attribute of an identity
- * @author Anil.Saldhana(a)redhat.com
- * @since Jun 30, 2008
- */
-public interface IdentityAttribute
-{
-}
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java 2008-09-17
15:48:28 UTC (rev 92)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/IdentityType.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -48,12 +48,6 @@
String getName();
/**
- * <p>Return a list of attributes</p>
- * @return
- */
- List<IdentityAttribute> getAttributes();
-
- /**
* Validate configured Policies
* @throws org.jboss.identity.exception.PolicyValidationException
*/
Modified: trunk/identity-impl/pom.xml
===================================================================
--- trunk/identity-impl/pom.xml 2008-09-17 15:48:28 UTC (rev 92)
+++ trunk/identity-impl/pom.xml 2008-09-19 11:37:32 UTC (rev 93)
@@ -26,6 +26,8 @@
<
developerConnection>scm:svn:https://svn.jboss.org/jbossidentity/trunk&...
<
url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossidentity/trunk<...
</scm>
+
+
<dependencies>
<dependency>
<groupId>org.jboss.identity</groupId>
@@ -65,7 +67,7 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.2.GA</version>
- <scope>test</scope>
+ <!--<scope>test</scope>-->
</dependency>
<dependency>
<groupId>hsqldb</groupId>
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/NotYetImplementedException.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/NotYetImplementedException.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/NotYetImplementedException.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,50 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class NotYetImplementedException extends RuntimeException
+{
+ public NotYetImplementedException()
+ {
+ super();
+ }
+
+ public NotYetImplementedException(String message)
+ {
+ super(message);
+ }
+
+ public NotYetImplementedException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public NotYetImplementedException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Copied:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObject.java
(from rev 84,
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java)
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObject.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObject.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,205 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.model;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashMap;
+import java.util.Collections;
+
+import javax.persistence.Column;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.FetchType;
+import javax.persistence.UniqueConstraint;
+import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+
+import org.jboss.identity.exception.PolicyValidationException;
+import org.jboss.identity.model.core.IdentityObject;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@NamedQueries({
+ @NamedQuery(
+ name = "findIdentityObjectByNameAndType",
+ query = "select o from HibernateIdentityObject o where o.name like :name and
o.identityType.name like :typeName"
+ ),
+ @NamedQuery(
+ name = "findIdentityObjectsByType",
+ query = "select o from HibernateIdentityObject o where o.identityType.name
like :typeName"
+ ),
+ @NamedQuery(
+ name = "countIdentityObjectsByType",
+ query = "select count(o.id) from HibernateIdentityObject o where
o.identityType.name like :typeName"
+ )
+ })
+@Entity
+@Table(name = "identity_obj", uniqueConstraints =
{@UniqueConstraint(columnNames = {"NAME", "IDENTITY_TYPE"})})
+public class HibernateIdentityObject implements IdentityObject
+{
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(name = "NAME", nullable = false)
+ private String name;
+
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinColumn(name = "IDENTITY_TYPE", nullable = false)
+ private HibernateIdentityObjectType identityType;
+
+ @OneToMany(mappedBy = "fromIdentityObject")
+ private Set<HibernateIdentityObjectRelationship> fromRelationships = new
HashSet<HibernateIdentityObjectRelationship>();
+
+ @OneToMany(mappedBy = "toIdentityObject")
+ private Set<HibernateIdentityObjectRelationship> toRelationships = new
HashSet<HibernateIdentityObjectRelationship>();
+
+ @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
+ private Map<String, HibernateIdentityObjectAttribute> attributes = new
HashMap<String, HibernateIdentityObjectAttribute>();
+
+ public HibernateIdentityObject()
+ {
+ }
+
+ public HibernateIdentityObject(String name, HibernateIdentityObjectType identityType)
+ {
+ this.name = name;
+ this.identityType = identityType;
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public HibernateIdentityObjectType getIdentityType()
+ {
+ return identityType;
+ }
+
+ public void setIdentityType(HibernateIdentityObjectType identityType)
+ {
+ this.identityType = identityType;
+ }
+
+ public String getFQDN()
+ {
+ return null;
+ }
+
+ public Map<String, Set<String>> getAttributes()
+ {
+ Map<String, Set<String>> map = new HashMap<String,
Set<String>>();
+
+ for (HibernateIdentityObjectAttribute attribute : attributes.values())
+ {
+ map.put(attribute.getName(),
Collections.unmodifiableSet(attribute.getValues()));
+ }
+
+ return Collections.unmodifiableMap(map);
+ }
+
+ public void setAttribute(String name, Set<String> values)
+ {
+ attributes.put(name, new HibernateIdentityObjectAttribute(name, new
HashSet<String>(values)));
+ }
+
+ public void setAttributes(Map<String, Set<String>> values)
+ {
+ Map<String, HibernateIdentityObjectAttribute> newAttrs= new
HashMap<String, HibernateIdentityObjectAttribute>();
+
+ for (String name : values.keySet())
+ {
+
+ newAttrs.put(name, new HibernateIdentityObjectAttribute(name, new
HashSet<String>(values.get(name))));
+ }
+ attributes = newAttrs;
+ }
+
+ public void removeAttribute(String name)
+ {
+ attributes.remove(name);
+ }
+
+ public Set<HibernateIdentityObjectRelationship> getFromRelationships()
+ {
+ return fromRelationships;
+ }
+
+ public void setFromRelationships(Set<HibernateIdentityObjectRelationship>
fromRelationships)
+ {
+ this.fromRelationships = fromRelationships;
+ }
+
+ public void addFromRelationship(HibernateIdentityObjectRelationship fromRelationship)
+ {
+ fromRelationship.setFromIdentityObject(this);
+ fromRelationships.add(fromRelationship);
+ }
+
+ public Set<HibernateIdentityObjectRelationship> getToRelationships()
+ {
+ return toRelationships;
+ }
+
+ public void setToRelationships(Set<HibernateIdentityObjectRelationship>
toRelationships)
+ {
+ this.toRelationships = toRelationships;
+ }
+
+ public void addToRelationship(HibernateIdentityObjectRelationship toRelationship)
+ {
+ toRelationship.setToIdentityObject(this);
+ fromRelationships.add(toRelationship);
+ }
+
+ public void validatePolicy() throws PolicyValidationException
+ {
+
+ }
+}
Copied:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectAttribute.java
(from rev 84,
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectAttribute.java)
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectAttribute.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectAttribute.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,101 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.model;
+
+import org.hibernate.annotations.CollectionOfElements;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.OneToMany;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@Entity
+@Table(name = "identity_obj_attrs")
+public class HibernateIdentityObjectAttribute
+{
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String name;
+
+ @CollectionOfElements
+ private Set<String> values = new HashSet<String>();
+
+ public HibernateIdentityObjectAttribute()
+ {
+ }
+
+ public HibernateIdentityObjectAttribute(String name)
+ {
+ this.name = name;
+ }
+
+ public HibernateIdentityObjectAttribute(String name, Set<String> values)
+ {
+ this.name = name;
+ this.values = values;
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public Set<String> getValues()
+ {
+ return values;
+ }
+
+ public void setValues(Set<String> values)
+ {
+ this.values = values;
+ }
+
+ public void addValue(String val)
+ {
+ getValues().add(val);
+ }
+}
Copied:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectRelationship.java
(from rev 84,
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationship.java)
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectRelationship.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectRelationship.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,121 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.model;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.JoinColumn;
+import javax.persistence.UniqueConstraint;
+
+import org.jboss.identity.model.core.IdentityObjectRelationship;
+import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@NamedQueries({
+ @NamedQuery(
+ name = "findIdentityObjectRelationshipsByType",
+ query = "select r from HibernateIdentityObjectRelationship r where r.type.name
like :typeName"
+ )
+ })
+@Entity
+@Table(name="identity_relationships", uniqueConstraints =
{@UniqueConstraint(columnNames = {"TYPE", "FROM_IDENTITY",
"TO_IDENTITY"})})
+public class HibernateIdentityObjectRelationship implements IdentityObjectRelationship
+{
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @ManyToOne
+ @JoinColumn(nullable = false, name="TYPE")
+ private HibernateIdentityObjectRelationshipType type;
+
+ @ManyToOne
+ @JoinColumn(nullable = false, name="FROM_IDENTITY")
+ private HibernateIdentityObject fromIdentityObject;
+
+ @ManyToOne
+ @JoinColumn(nullable = false, name="TO_IDENTITY")
+ private HibernateIdentityObject toIdentityObject;
+
+ public HibernateIdentityObjectRelationship()
+ {
+ }
+
+ public HibernateIdentityObjectRelationship(HibernateIdentityObjectRelationshipType
type, HibernateIdentityObject fromIdentityObject, HibernateIdentityObject
toIdentityObject)
+ {
+ this.type = type;
+ this.fromIdentityObject = fromIdentityObject;
+ fromIdentityObject.getFromRelationships().add(this);
+ this.toIdentityObject = toIdentityObject;
+ toIdentityObject.getToRelationships().add(this);
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public IdentityObjectRelationshipType getType()
+ {
+ return type;
+ }
+
+ public void setType(HibernateIdentityObjectRelationshipType type)
+ {
+ this.type = type;
+ }
+
+ public HibernateIdentityObject getFromIdentityObject()
+ {
+ return fromIdentityObject;
+ }
+
+ public void setFromIdentityObject(HibernateIdentityObject fromIdentityObject)
+ {
+ this.fromIdentityObject = fromIdentityObject;
+ }
+
+ public HibernateIdentityObject getToIdentityObject()
+ {
+ return toIdentityObject;
+ }
+
+ public void setToIdentityObject(HibernateIdentityObject toIdentityObject)
+ {
+ this.toIdentityObject = toIdentityObject;
+ }
+}
Copied:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectRelationshipType.java
(from rev 84,
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java)
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectRelationshipType.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectRelationshipType.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,98 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+
+import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@NamedQueries({
+ @NamedQuery(
+ name = "findIdentityObjectRelationshipTypeByName",
+ query = "select t from HibernateIdentityObjectRelationshipType t where t.name
like :name"
+ )
+ })
+@Entity
+@Table(name = "identity_relationship_types")
+public class HibernateIdentityObjectRelationshipType implements
IdentityObjectRelationshipType
+{
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(nullable = false, unique = true)
+ private String name;
+
+ public HibernateIdentityObjectRelationshipType()
+ {
+ }
+
+ public HibernateIdentityObjectRelationshipType(String name)
+ {
+ this.name = name;
+ }
+
+
+ public HibernateIdentityObjectRelationshipType(IdentityObjectRelationshipType type)
+ {
+ if (type == null)
+ {
+ throw new IllegalArgumentException("type is null");
+ }
+ if (type.getName() != null)
+ {
+ this.name = type.getName();
+ }
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Copied:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectType.java
(from rev 84,
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java)
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectType.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/HibernateIdentityObjectType.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,102 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+
+import org.jboss.identity.model.core.IdentityObjectType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@NamedQueries({
+ @NamedQuery(
+ name = "findIdentityObjectTypeByName",
+ query = "select t from HibernateIdentityObjectType t where t.name like
:name"
+ )
+ })
+@Entity
+@Table(name = "identity_obj_types")
+public class HibernateIdentityObjectType implements IdentityObjectType
+{
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(nullable = false, unique = true)
+ private String name;
+
+
+ public HibernateIdentityObjectType()
+ {
+ }
+
+ public HibernateIdentityObjectType(String name)
+ {
+ this.name = name;
+ }
+
+ public HibernateIdentityObjectType(IdentityObjectType type)
+ {
+ if (type == null)
+ {
+ throw new IllegalArgumentException("type is null");
+ }
+ if (type.getName() != null)
+ {
+ this.name = type.getName();
+ }
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String toString()
+ {
+ return "IdentityObjectType[" + getName() + "]";
+ }
+}
Deleted:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -1,172 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.jboss.identity.impl.model;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.HashMap;
-
-import javax.persistence.Column;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-import javax.persistence.FetchType;
-import javax.persistence.UniqueConstraint;
-import javax.persistence.JoinColumn;
-
-import org.jboss.identity.exception.PolicyValidationException;
-import org.jboss.identity.model.core.IdentityObject;
-import org.hibernate.annotations.CollectionOfElements;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-@Entity
-@Table(name = "identity_obj", uniqueConstraints =
{@UniqueConstraint(columnNames = {"NAME", "IDENTITY_TYPE"})})
-public class JPAIdentityObject implements IdentityObject
-{
- @Id
- @GeneratedValue
- private Long id;
-
- @Column(name = "NAME", nullable = false)
- private String name;
-
- @ManyToOne
- @JoinColumn(name = "IDENTITY_TYPE")
- private JPAIdentityObjectType identityType;
-
- @OneToMany(mappedBy = "fromIdentityObject")
- private Set<JPAIdentityObjectRelationship> fromRelationships = new
HashSet<JPAIdentityObjectRelationship>();
-
- @OneToMany(mappedBy = "toIdentityObject")
- private Set<JPAIdentityObjectRelationship> toRelationships = new
HashSet<JPAIdentityObjectRelationship>();
-
- @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
- private Map<String, JPAIdentityObjectAttribute> attributes = new
HashMap<String, JPAIdentityObjectAttribute>();
-
- public JPAIdentityObject()
- {
- }
-
- public JPAIdentityObject(String name, JPAIdentityObjectType identityType)
- {
- this.name = name;
- this.identityType = identityType;
- }
-
- public Long getId()
- {
- return id;
- }
-
- public void setId(Long id)
- {
- this.id = id;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public JPAIdentityObjectType getIdentityType()
- {
- return identityType;
- }
-
- public void setIdentityType(JPAIdentityObjectType identityType)
- {
- this.identityType = identityType;
- }
-
- public String getFQDN()
- {
- return null;
- }
-
- public Map<String, Set<String>> getAttributes()
- {
- Map<String, Set<String>> map = new HashMap<String,
Set<String>>();
-
- for (JPAIdentityObjectAttribute attribute : attributes.values())
- {
- map.put(attribute.getName(), attribute.getValues());
- }
-
- return map;
- }
-
- public void addAttribute(String name, Set<String> values)
- {
- attributes.put(name, new JPAIdentityObjectAttribute(name, values));
- }
-
- public Set<JPAIdentityObjectRelationship> getFromRelationships()
- {
- return fromRelationships;
- }
-
- public void setFromRelationships(Set<JPAIdentityObjectRelationship>
fromRelationships)
- {
- this.fromRelationships = fromRelationships;
- }
-
- public void addFromRelationship(JPAIdentityObjectRelationship fromRelationship)
- {
- fromRelationship.setFromIdentityObject(this);
- fromRelationships.add(fromRelationship);
- }
-
- public Set<JPAIdentityObjectRelationship> getToRelationships()
- {
- return toRelationships;
- }
-
- public void setToRelationships(Set<JPAIdentityObjectRelationship>
toRelationships)
- {
- this.toRelationships = toRelationships;
- }
-
- public void addToRelationship(JPAIdentityObjectRelationship toRelationship)
- {
- toRelationship.setToIdentityObject(this);
- fromRelationships.add(toRelationship);
- }
-
- public void validatePolicy() throws PolicyValidationException
- {
-
- }
-}
Deleted:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectAttribute.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectAttribute.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectAttribute.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -1,101 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.jboss.identity.impl.model;
-
-import org.hibernate.annotations.CollectionOfElements;
-
-import javax.persistence.Entity;
-import javax.persistence.Table;
-import javax.persistence.OneToMany;
-import javax.persistence.Id;
-import javax.persistence.GeneratedValue;
-import java.util.Set;
-import java.util.HashSet;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-@Entity
-@Table(name = "identity_obj_attrs")
-public class JPAIdentityObjectAttribute
-{
- @Id
- @GeneratedValue
- private Long id;
-
- private String name;
-
- @CollectionOfElements
- private Set<String> values = new HashSet<String>();
-
- public JPAIdentityObjectAttribute()
- {
- }
-
- public JPAIdentityObjectAttribute(String name)
- {
- this.name = name;
- }
-
- public JPAIdentityObjectAttribute(String name, Set<String> values)
- {
- this.name = name;
- this.values = values;
- }
-
- public Long getId()
- {
- return id;
- }
-
- public void setId(Long id)
- {
- this.id = id;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public Set<String> getValues()
- {
- return values;
- }
-
- public void setValues(Set<String> values)
- {
- this.values = values;
- }
-
- public void addValue(String val)
- {
- getValues().add(val);
- }
-}
Deleted:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -1,77 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.jboss.identity.impl.model;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import org.jboss.identity.model.core.IdentityObjectRelationshipType;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-@Entity
-@Table(name = "identity_relationship_types")
-public class JPAIdentityObjectRelationshipType implements IdentityObjectRelationshipType
-{
-
- @Id
- @GeneratedValue
- private Long id;
-
- @Column(nullable = false, unique = true)
- private String name;
-
- public JPAIdentityObjectRelationshipType()
- {
- }
-
- public JPAIdentityObjectRelationshipType(String name)
- {
- this.name = name;
- }
-
- public Long getId()
- {
- return id;
- }
-
- public void setId(Long id)
- {
- this.id = id;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-}
Deleted:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -1,77 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.jboss.identity.impl.model;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import org.jboss.identity.model.core.IdentityObjectType;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-@Entity
-@Table(name = "identity_obj_types")
-public class JPAIdentityObjectType implements IdentityObjectType
-{
- @Id
- @GeneratedValue
- private Long id;
-
- @Column(nullable = false)
- private String name;
-
-
- public JPAIdentityObjectType()
- {
- }
-
- public JPAIdentityObjectType(String name)
- {
- this.name = name;
- }
-
- public Long getId()
- {
- return id;
- }
-
- public void setId(Long id)
- {
- this.id = id;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-}
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FeaturesDescriptionImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FeaturesDescriptionImpl.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FeaturesDescriptionImpl.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,80 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.store;
+
+import org.jboss.identity.spi.store.FeaturesDescription;
+import org.jboss.identity.spi.store.OperationType;
+import org.jboss.identity.spi.exception.IdentityTypeNotSupportedException;
+import org.jboss.identity.model.core.IdentityObjectType;
+import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+import org.jboss.identity.exception.IdentityException;
+
+import java.util.Set;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class FeaturesDescriptionImpl implements FeaturesDescription
+{
+ public Set<OperationType> getSupportedOperations(IdentityObjectType
identityObjectType) throws IdentityTypeNotSupportedException
+ {
+ return null;
+ }
+
+ public boolean isOperationSupported(OperationType operationType, IdentityObjectType
identityObjectType) throws IdentityTypeNotSupportedException
+ {
+ return true;
+ }
+
+ public Set<IdentityObjectType> getSupportedIdentityObjectTypes(OperationType
operationType)
+ {
+ return null;
+ }
+
+ public Set<IdentityObjectType> getSupportedIdentityObjectTypes()
+ {
+ return null;
+ }
+
+ public boolean isIdentityObjectTypeSupported(IdentityObjectType identityObjectType)
+ {
+ return true;
+ }
+
+ public boolean isRelationshipTypeSupported(IdentityObjectType fromType,
IdentityObjectType toType, IdentityObjectRelationshipType relationshipType) throws
IdentityException
+ {
+ return true;
+ }
+
+ public Set<IdentityObjectRelationshipType> getSupportedRelationshipTypes()
+ {
+ return null;
+ }
+
+ public Map<IdentityObjectRelationshipType, Map<IdentityObjectType,
IdentityObjectType>> getSupportedRelationshipTypeMappings()
+ {
+ return null;
+ }
+}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FileBasedIdentityStore.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FileBasedIdentityStore.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FileBasedIdentityStore.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -1,170 +1,170 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * 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.jboss.identity.impl.store;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.identity.exception.IdentityException;
-import org.jboss.identity.impl.types.SimpleIdentity;
-import org.jboss.identity.model.core.IdentityObject;
-import org.jboss.identity.model.core.IdentityObjectRelationshipType;
-import org.jboss.identity.model.core.IdentityObjectType;
-import org.jboss.identity.spi.store.FeaturesDescription;
-import org.jboss.identity.spi.store.IdentityStore;
-
-/**
- * File Based Identity Store
- * @author Anil.Saldhana(a)redhat.com
- * @since Aug 1, 2008
- */
-public class FileBasedIdentityStore implements IdentityStore
-{
- //TODO: Handle file semantics
-
- private List<IdentityObject> identities = new ArrayList<IdentityObject>();
-
- public void addAttributes(IdentityObject identity, Map<String, String[]>
attributes)
- throws IdentityException
- {
- }
-
- public void bootstrap() throws IOException
- {
- }
-
-
-
- public IdentityObject createIdentity(String name, IdentityObjectType type) throws
IdentityException
- {
- //Is there one already available?
- IdentityObject identity = this.findIdentity(name);
- if(identity == null)
- {
- identity = new SimpleIdentity(name);
- identities.add(identity);
- }
- return identity;
- }
-
- public <R extends IdentityObjectRelationshipType> void
createRelationship(IdentityObject fromIdentity,
- IdentityObject toIdentity,
- R relationshipType)
- throws IdentityException
- {
- }
-
- public <T extends IdentityObjectType> Collection<IdentityObject>
findIdentities(T identityType,
- int offset,
- int limit,
- String orderedByAttributeName, boolean ascending) throws IdentityException
- {
- return null;
- }
-
- public <T extends IdentityObjectType> Collection<IdentityObject>
findIdentities(T identityType,
- Map<String, String[]> attributes, int offset,
- int limit, String orderedByAttributeName, boolean ascending)
- throws IdentityException
- {
- return null;
- }
-
- public <T extends IdentityObjectType> Set<String>
getSupportedAttributeNames(T identityType) throws IdentityException
- {
- return null;
- }
-
- public IdentityObject findIdentity(String name, IdentityObjectType identityObjectType)
throws IdentityException
- {
- return null;
- }
-
- public IdentityObject findIdentity(Object id) throws IdentityException
- {
- return null;
- }
-
- public Map<String, String[]> getAttributes(IdentityObject identity)
- throws IdentityException
- {
- return null;
- }
-
- public String getId()
- {
- return null;
- }
-
-
- public <T extends IdentityObjectType> int getIdentitiesCount(T identityType)
throws IdentityException
- {
- return 0;
- }
-
- public <R extends IdentityObjectRelationshipType>
Collection<IdentityObject> findIdentities(IdentityObject identity, R
relationshipType, boolean parent, int offset, int limit, String orderedByAttributeName,
boolean ascending) throws IdentityException
- {
- return null;
- }
-
- public FeaturesDescription getSupportedFeatures()
- {
- return null;
- }
-
- public void removeAttributes(IdentityObject identity, Set<String> attributes)
- throws IdentityException
- {
- }
-
- public void removeIdentity(IdentityObject identity) throws IdentityException
- {
- }
-
- public <R extends IdentityObjectRelationshipType> void
removeRelationship(IdentityObject fromIdentity,
- IdentityObject toIdentity,
- R relationshipType)
- throws IdentityException
- {
- }
-
- public void removeRelationships(IdentityObject identity1, IdentityObject identity2)
- throws IdentityException
- {
- }
-
- public Set<IdentityObjectRelationshipType> resolveRelationships(IdentityObject
fromIdentity,
- IdentityObject toIdentity)
- throws IdentityException
- {
- return null;
- }
-
- public void updateAttributes(IdentityObject identity, Map<String, String[]>
attributes)
- throws IdentityException
- {
- }
-}
\ No newline at end of file
+///*
+// * JBoss, Home of Professional Open Source.
+// * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+// * as indicated by the @author tags. See the copyright.txt file in the
+// * distribution for a full listing of individual contributors.
+// *
+// * 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.jboss.identity.impl.store;
+//
+//import java.io.IOException;
+//import java.util.ArrayList;
+//import java.util.Collection;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.Set;
+//
+//import org.jboss.identity.exception.IdentityException;
+//import org.jboss.identity.impl.types.SimpleIdentity;
+//import org.jboss.identity.model.core.IdentityObject;
+//import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+//import org.jboss.identity.model.core.IdentityObjectType;
+//import org.jboss.identity.spi.store.FeaturesDescription;
+//import org.jboss.identity.spi.store.IdentityStore;
+//
+///**
+// * File Based Identity Store
+// * @author Anil.Saldhana(a)redhat.com
+// * @since Aug 1, 2008
+// */
+//public class FileBasedIdentityStore implements IdentityStore
+//{
+// //TODO: Handle file semantics
+//
+// private List<IdentityObject> identities = new
ArrayList<IdentityObject>();
+//
+// public void addAttributes(IdentityObject identity, Map<String,
Set<String>> attributes)
+// throws IdentityException
+// {
+// }
+//
+// public void bootstrap() throws IOException
+// {
+// }
+//
+//
+//
+// public IdentityObject createIdentityObject(String name, IdentityObjectType type)
throws IdentityException
+// {
+// //Is there one already available?
+// IdentityObject identity = this.findIdentityObject(name);
+// if(identity == null)
+// {
+// identity = new SimpleIdentity(name);
+// identities.add(identity);
+// }
+// return identity;
+// }
+//
+// public <R extends IdentityObjectRelationshipType> void
createRelationship(IdentityObject fromIdentity,
+// IdentityObject toIdentity,
+// IdentityObjectRelationshipType relationshipType)
+// throws IdentityException
+// {
+// }
+//
+// public <T extends IdentityObjectType> Collection<IdentityObject>
findIdentityObject(IdentityObjectType identityType,
+// int offset,
+// int limit,
+// boolean orderedByName, boolean ascending) throws IdentityException
+// {
+// return null;
+// }
+//
+// public <T extends IdentityObjectType> Collection<IdentityObject>
findIdentityObject(IdentityObjectType identityType,
+// Map<String, String[]> attributes, int offset,
+// int limit, boolean orderByName, boolean ascending)
+// throws IdentityException
+// {
+// return null;
+// }
+//
+// public <T extends IdentityObjectType> Set<String>
getSupportedAttributeNames(T identityType) throws IdentityException
+// {
+// return null;
+// }
+//
+// public IdentityObject findIdentityObject(String name, IdentityObjectType
identityObjectType) throws IdentityException
+// {
+// return null;
+// }
+//
+// public IdentityObject findIdentityObject(Object id) throws IdentityException
+// {
+// return null;
+// }
+//
+// public Map<String, Set<String>> getAttributes(IdentityObject identity)
+// throws IdentityException
+// {
+// return null;
+// }
+//
+// public String getId()
+// {
+// return null;
+// }
+//
+//
+// public <T extends IdentityObjectType> int getIdentityObjectsCount(T
identityType) throws IdentityException
+// {
+// return 0;
+// }
+//
+// public <R extends IdentityObjectRelationshipType>
Collection<IdentityObject> findIdentityObject(IdentityObject identity, R
relationshipType, boolean parent, int offset, int limit, boolean orderByName, boolean
ascending) throws IdentityException
+// {
+// return null;
+// }
+//
+// public FeaturesDescription getSupportedFeatures()
+// {
+// return null;
+// }
+//
+// public void removeAttributes(IdentityObject identity, Set<String> attributes)
+// throws IdentityException
+// {
+// }
+//
+// public void removeIdentityObject(IdentityObject identity) throws IdentityException
+// {
+// }
+//
+// public <R extends IdentityObjectRelationshipType> void
removeRelationship(IdentityObject fromIdentity,
+// IdentityObject toIdentity,
+// IdentityObjectRelationshipType relationshipType)
+// throws IdentityException
+// {
+// }
+//
+// public void removeRelationships(IdentityObject identity1, IdentityObject identity2)
+// throws IdentityException
+// {
+// }
+//
+// public Set<IdentityObjectRelationshipType> resolveRelationships(IdentityObject
fromIdentity,
+// IdentityObject toIdentity)
+// throws IdentityException
+// {
+// return null;
+// }
+//
+// public void updateAttributes(IdentityObject identity, Map<String,
Set<String>> attributes)
+// throws IdentityException
+// {
+// }
+//}
\ No newline at end of file
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/HibernateIdentityStoreImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/HibernateIdentityStoreImpl.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/HibernateIdentityStoreImpl.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,585 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.store;
+
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.FeaturesDescription;
+import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+import org.jboss.identity.model.core.IdentityObject;
+import org.jboss.identity.model.core.IdentityObjectType;
+import org.jboss.identity.exception.IdentityException;
+import org.jboss.identity.impl.model.HibernateIdentityObject;
+import org.jboss.identity.impl.model.HibernateIdentityObjectType;
+import org.jboss.identity.impl.model.HibernateIdentityObjectRelationshipType;
+import org.jboss.identity.impl.model.HibernateIdentityObjectRelationship;
+import org.jboss.identity.impl.NotYetImplementedException;
+import org.hibernate.ejb.HibernateEntityManager;
+
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import java.util.Set;
+import java.util.Collection;
+import java.util.Map;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
+import java.util.HashSet;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class HibernateIdentityStoreImpl implements IdentityStore
+{
+ private final String QUERY_RELATIONSHIP_BY_FROM_TO =
+ "select r from HibernateIdentityObjectRelationship r where
r.fromIdentityObject like :fromIO and " +
+ "r.toIdentityObject like :toIO";
+
+ private final String QUERY_RELATIONSHIP_BY_FROM_TO_TYPE =
+ "select r from HibernateIdentityObjectRelationship r where
r.fromIdentityObject like :fromIO and " +
+ "r.toIdentityObject like :toIO and r.type.name like :typeName";
+
+ private final String QUERY_RELATIONSHIP_BY_IDENTITIES =
+ "select r from HibernateIdentityObjectRelationship r where " +
+ "(r.fromIdentityObject like :IO1 and r.toIdentityObject like :IO2) or
" +
+ "(r.fromIdentityObject like :IO2 and r.toIdentityObject like :IO1)";
+
+ private String id;
+
+ private FeaturesDescription supportedFeatures;
+
+ public HibernateIdentityStoreImpl()
+ {
+ // For now just dummy impl
+ //TODO: initialize with configuration
+ supportedFeatures = new FeaturesDescriptionImpl();
+ }
+
+ public void start()
+ {
+ //TODO: populate store with configured identity types if needed (and configured)
+
+
+ }
+
+ public void stop()
+ {
+
+ }
+
+
+
+ public void bootstrap() throws IOException
+ {
+ //TODO: NYI
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+ }
+
+ public FeaturesDescription getSupportedFeatures()
+ {
+ return supportedFeatures;
+ }
+
+ public IdentityObject createIdentityObject(String name, IdentityObjectType
identityObjectType) throws IdentityException
+ {
+
+ if (name == null)
+ {
+ throw new IllegalArgumentException("IdentityObject name is null");
+ }
+
+ checkIOType(identityObjectType);
+
+ // Check if object with a given name and type is not present already
+
+
+ List results =
getEntityManager().createNamedQuery("findIdentityObjectByNameAndType")
+ .setParameter("name", name)
+ .setParameter("typeName",
identityObjectType.getName()).getResultList();
+
+ if (results.size() != 0)
+ {
+ throw new IdentityException("IdentityObject already present in this
IdentityStore");
+ }
+
+
+
+ HibernateIdentityObjectType hibernateType =
getHibernateIdentityObjectType(identityObjectType);
+
+ HibernateIdentityObject io = new HibernateIdentityObject(name, hibernateType);
+
+ try
+ {
+ getEntityManager().persist(io);
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot persist new IdentityObject" + io,
e);
+ }
+
+
+ return io;
+ }
+
+ public void removeIdentityObject(IdentityObject identity) throws IdentityException
+ {
+ checkIOInstance(identity);
+
+ //TODO: handle cleanup of present relationships
+
+ try
+ {
+ HibernateIdentityObject hibernateObject = getHibernateIdentityObject(identity);
+ getEntityManager().remove(hibernateObject);
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot remove IdentityObject" + identity,
e);
+ }
+ }
+
+ public <T extends IdentityObjectType> int getIdentityObjectsCount(T
identityType) throws IdentityException
+ {
+ checkIOType(identityType);
+
+ HibernateIdentityObjectType jpaType =
getHibernateIdentityObjectType(identityType);
+
+ int count;
+ try
+ {
+ count = ((Number)getEntityManager()
+ .createNamedQuery("countIdentityObjectsByType")
+ .setParameter("typeName", jpaType.getName())
+ .getSingleResult()).intValue();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot count stored IdentityObjects with type:
" + identityType.getName(), e);
+ }
+
+ return count;
+ }
+
+ public IdentityObject findIdentityObject(String name, IdentityObjectType type) throws
IdentityException
+ {
+
+ if (name == null)
+ {
+ throw new IllegalArgumentException("IdentityObject name is null");
+ }
+
+ checkIOType(type);
+
+ HibernateIdentityObjectType hibernateType = getHibernateIdentityObjectType(type);
+
+ HibernateIdentityObject hibernateObject = null;
+
+ try
+ {
+ hibernateObject =
(HibernateIdentityObject)getEntityManager().createNamedQuery("findIdentityObjectByNameAndType")
+ .setParameter("name", name)
+ .setParameter("typeName", hibernateType.getName())
+ .getSingleResult();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot find IdentityObject with name
'" + name + "' and type '" + type.getName() +
"'", e);
+ }
+
+ return hibernateObject;
+ }
+
+ public IdentityObject findIdentityObject(Object id) throws IdentityException
+ {
+ if (id == null)
+ {
+ throw new IllegalArgumentException("id is null");
+ }
+
+ HibernateIdentityObject hibernateObject = null;
+
+ try
+ {
+ hibernateObject =
(HibernateIdentityObject)getEntityManager().find(HibernateIdentityObject.class, id);
+ }
+ catch(Exception e)
+ {
+ throw new IdentityException("Cannot find IdentityObject with id: " +
id, e);
+ }
+
+ return hibernateObject;
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityObjectType
identityType, int offset, int limit, boolean orderedByName, boolean ascending) throws
IdentityException
+ {
+ checkIOType(identityType);
+
+ HibernateIdentityObjectType hibernateType =
getHibernateIdentityObjectType(identityType);
+
+ List<IdentityObject> results = new LinkedList<IdentityObject>();
+
+ try
+ {
+ //TODO:OrderBy
+ Query q =
getEntityManager().createNamedQuery("findIdentityObjectsByType")
+ .setParameter("typeName", hibernateType.getName())
+ .setFirstResult(offset);
+
+ if (limit > 0)
+ {
+ q.setMaxResults(limit);
+ }
+
+ results = (List<IdentityObject>)q.getResultList();
+
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot find IdentityObjects with type
'" + identityType.getName() + "'", e);
+ }
+
+ return results;
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityObjectType
identityType, Map<String, String[]> attributes, int offset, int limit, boolean
orderByName, boolean ascending) throws IdentityException
+ {
+ //TODO: NYI
+ throw new NotYetImplementedException();
+ }
+
+ public Collection<IdentityObject> findIdentityObject(IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent, int offset, int limit,
boolean orderByName, boolean ascending) throws IdentityException
+ {
+ //TODO: NYI
+ throw new NotYetImplementedException();
+ }
+
+ public void createRelationship(IdentityObject fromIdentity, IdentityObject toIdentity,
IdentityObjectRelationshipType relationshipType) throws IdentityException
+ {
+ //TODO: NYI
+ //throw new NotYetImplementedException();
+
+ if (relationshipType == null)
+ {
+ throw new IllegalArgumentException("RelationshipType is null");
+ }
+
+ checkIOInstance(fromIdentity);
+ checkIOInstance(toIdentity);
+
+ HibernateIdentityObject fromIO = getHibernateIdentityObject(fromIdentity);
+ HibernateIdentityObject toIO = getHibernateIdentityObject(toIdentity);
+ HibernateIdentityObjectRelationshipType type =
getHibernateIdentityObjectRelationshipType(relationshipType);
+
+ getSupportedFeatures().isRelationshipTypeSupported(fromIO.getIdentityType(),
toIO.getIdentityType(), relationshipType);
+
+
+ org.hibernate.Query query =
getEntityManager().getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO_TYPE)
+ .setParameter("fromIO", fromIO)
+ .setParameter("toIO", toIO)
+ .setParameter("typeName", type.getName());
+
+ List results = query.list();
+
+ if (results.size() != 0)
+ {
+ throw new IdentityException("Relationship already present");
+ }
+
+ HibernateIdentityObjectRelationship relationship = new
HibernateIdentityObjectRelationship(type, fromIO, toIO);
+ getEntityManager().persist(relationship);
+
+ }
+
+ public void removeRelationship(IdentityObject fromIdentity, IdentityObject toIdentity,
IdentityObjectRelationshipType relationshipType) throws IdentityException
+ {
+
+ if (relationshipType == null)
+ {
+ throw new IllegalArgumentException("RelationshipType is null");
+ }
+
+ checkIOInstance(fromIdentity);
+ checkIOInstance(toIdentity);
+
+ HibernateIdentityObject fromIO = getHibernateIdentityObject(fromIdentity);
+ HibernateIdentityObject toIO = getHibernateIdentityObject(toIdentity);
+ HibernateIdentityObjectRelationshipType type =
getHibernateIdentityObjectRelationshipType(relationshipType);
+
+ getSupportedFeatures().isRelationshipTypeSupported(fromIO.getIdentityType(),
toIO.getIdentityType(), relationshipType);
+
+
+ org.hibernate.Query query =
getEntityManager().getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO_TYPE)
+ .setParameter("fromIO", fromIO)
+ .setParameter("toIO", toIO)
+ .setParameter("typeName", type.getName());
+
+ List results = query.list();
+
+ if (results == null)
+ {
+ throw new IdentityException("Relationship already present");
+ }
+
+ HibernateIdentityObjectRelationship relationship =
(HibernateIdentityObjectRelationship)results.iterator().next();
+
+ fromIO.getFromRelationships().remove(relationship);
+ toIO.getToRelationships().remove(relationship);
+ getEntityManager().remove(relationship);
+
+ }
+
+ public void removeRelationships(IdentityObject identity1, IdentityObject identity2)
throws IdentityException
+ {
+ checkIOInstance(identity1);
+ checkIOInstance(identity2);
+
+ HibernateIdentityObject hio1 = getHibernateIdentityObject(identity1);
+ HibernateIdentityObject hio2 = getHibernateIdentityObject(identity2);
+
+ org.hibernate.Query query =
getEntityManager().getSession().createQuery(QUERY_RELATIONSHIP_BY_IDENTITIES)
+ .setParameter("IO1", hio1)
+ .setParameter("IO2", hio2);
+
+ List results = query.list();
+
+ for (Iterator iterator = results.iterator(); iterator.hasNext();)
+ {
+ HibernateIdentityObjectRelationship relationship =
(HibernateIdentityObjectRelationship) iterator.next();
+
relationship.getFromIdentityObject().getFromRelationships().remove(relationship);
+ relationship.getToIdentityObject().getToRelationships().remove(relationship);
+ getEntityManager().remove(relationship);
+ }
+ }
+
+ public Set<IdentityObjectRelationshipType> resolveRelationships(IdentityObject
fromIdentity, IdentityObject toIdentity) throws IdentityException
+ {
+ checkIOInstance(fromIdentity);
+ checkIOInstance(toIdentity);
+
+ HibernateIdentityObject hio1 = getHibernateIdentityObject(fromIdentity);
+ HibernateIdentityObject hio2 = getHibernateIdentityObject(toIdentity);
+
+ org.hibernate.Query query =
getEntityManager().getSession().createQuery(QUERY_RELATIONSHIP_BY_FROM_TO)
+ .setParameter("fromIO", hio1)
+ .setParameter("toIO", hio2);
+
+ List<HibernateIdentityObjectRelationship> results = query.list();
+
+ Set<IdentityObjectRelationshipType> types = new
HashSet<IdentityObjectRelationshipType>();
+
+ for (Iterator<HibernateIdentityObjectRelationship> iterator =
results.iterator(); iterator.hasNext();)
+ {
+ HibernateIdentityObjectRelationship relationship = iterator.next();
+ types.add(relationship.getType());
+ }
+ return types;
+ }
+
+ // Attribute store
+
+ public <T extends IdentityObjectType> Set<String>
getSupportedAttributeNames(T identityType) throws IdentityException
+ {
+ //TODO: NYI
+ return null;
+ }
+
+ public Map<String, Set<String>> getAttributes(IdentityObject identity)
throws IdentityException
+ {
+
+ checkIOInstance(identity);
+
+ HibernateIdentityObject hibernateObject = getHibernateIdentityObject(identity);
+
+ return hibernateObject.getAttributes();
+
+ }
+
+ public void updateAttributes(IdentityObject identity, Map<String,
Set<String>> attributes) throws IdentityException
+ {
+
+ checkIOInstance(identity);
+
+ if (attributes == null)
+ {
+ throw new IllegalArgumentException("attributes are null");
+ }
+
+ HibernateIdentityObject hibernateObject = getHibernateIdentityObject(identity);
+
+ hibernateObject.setAttributes(attributes);
+
+ }
+
+ public void addAttributes(IdentityObject identity, Map<String,
Set<String>> attributes) throws IdentityException
+ {
+
+ checkIOInstance(identity);
+
+ if (attributes == null)
+ {
+ throw new IllegalArgumentException("attributes are null");
+ }
+
+ HibernateIdentityObject hibernateObject = getHibernateIdentityObject(identity);
+
+ for (String name : attributes.keySet())
+ {
+ hibernateObject.setAttribute(name, attributes.get(name));
+ }
+ }
+
+ public void removeAttributes(IdentityObject identity, Set<String> attributes)
throws IdentityException
+ {
+
+ checkIOInstance(identity);
+
+ if (attributes == null)
+ {
+ throw new IllegalArgumentException("attributes are null");
+ }
+
+ HibernateIdentityObject hibernateObject = getHibernateIdentityObject(identity);
+
+ for (String attr : attributes)
+ {
+ hibernateObject.removeAttribute(attr);
+ }
+ }
+
+ // Internal
+
+ public void addIdentityObjectType(IdentityObjectType type) throws IdentityException
+ {
+ HibernateIdentityObjectType hibernateType = new HibernateIdentityObjectType(type);
+ getEntityManager().persist(hibernateType);
+ }
+
+
+ public void addIdentityObjectRelationshipType(IdentityObjectRelationshipType type)
throws IdentityException
+ {
+ HibernateIdentityObjectRelationshipType hibernateType = new
HibernateIdentityObjectRelationshipType(type);
+ getEntityManager().persist(hibernateType);
+ }
+
+
+ protected HibernateEntityManager getEntityManager()
+ {
+ return null;
+ }
+
+ private void checkIOInstance(IdentityObject io)
+ {
+ if (io == null)
+ {
+ throw new IllegalArgumentException("IdentityObject is null");
+ }
+
+ if (!(io instanceof HibernateIdentityObject))
+ {
+ throw new IllegalArgumentException("IdentityObject type not supported by
this " +
+ "IdentityStore implementation: " + io.getClass().getName());
+ }
+ }
+
+ private void checkIOType(IdentityObjectType iot) throws IdentityException
+ {
+ if (iot == null)
+ {
+ throw new IllegalArgumentException("IdentityObjectType is null");
+ }
+
+ if (!getSupportedFeatures().isIdentityObjectTypeSupported(iot))
+ {
+ throw new IdentityException("IdentityType not supported by this
IdentityStore implementation: " + iot);
+ }
+ }
+
+ private HibernateIdentityObjectType getHibernateIdentityObjectType(IdentityObjectType
type) throws IdentityException
+ {
+
+ HibernateIdentityObjectType hibernateType = null;
+
+ try
+ {
+ hibernateType =
(HibernateIdentityObjectType)getEntityManager().createNamedQuery("findIdentityObjectTypeByName")
+ .setParameter("name", type.getName())
+ .getSingleResult() ;
+ }
+ catch (NoResultException e)
+ {
+ throw new IdentityException("IdentityObjectType[ " + type.getName() +
"] not present in the store.");
+ }
+
+ return hibernateType;
+ }
+
+ private HibernateIdentityObject getHibernateIdentityObject(IdentityObject io) throws
IdentityException
+ {
+
+ HibernateIdentityObject hibernateObject = null;
+
+ try
+ {
+ hibernateObject =
(HibernateIdentityObject)getEntityManager().createNamedQuery("findIdentityObjectByNameAndType")
+ .setParameter("name", io.getName())
+ .setParameter("typeName", io.getIdentityType().getName())
+ .getSingleResult();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("IdentityObject[ " + io.getName() + "
| " + io.getIdentityType().getName() + "] not present in the store.");
+ }
+
+ return hibernateObject;
+ }
+
+ private HibernateIdentityObjectRelationshipType
getHibernateIdentityObjectRelationshipType(IdentityObjectRelationshipType iot) throws
IdentityException
+ {
+
+ HibernateIdentityObjectRelationshipType relationshipType = null;
+
+ try
+ {
+ relationshipType =
(HibernateIdentityObjectRelationshipType)getEntityManager().createNamedQuery("findIdentityObjectRelationshipTypeByName")
+ .setParameter("name", iot.getName())
+ .getSingleResult();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("IdentityObjectRelationshipType[ " +
iot.getName() + "] not present in the store.");
+ }
+
+ return relationshipType;
+ }
+
+}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleGroup.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleGroup.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleGroup.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -25,7 +25,6 @@
import org.jboss.identity.api.Group;
import org.jboss.identity.api.GroupType;
-import org.jboss.identity.api.IdentityAttribute;
import org.jboss.identity.exception.PolicyValidationException;
/**
@@ -52,11 +51,6 @@
return name;
}
- public List<IdentityAttribute> getAttributes()
- {
- return null;
- }
-
public void validatePolicy() throws PolicyValidationException
{
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/SimpleIdentityObjectRelationshipTypeImpl.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/SimpleIdentityObjectRelationshipTypeImpl.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/SimpleIdentityObjectRelationshipTypeImpl.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,44 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl;
+
+import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleIdentityObjectRelationshipTypeImpl implements
IdentityObjectRelationshipType
+{
+ private String name;
+
+ public SimpleIdentityObjectRelationshipTypeImpl(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/SimpleIdentityObjectTypeImpl.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/SimpleIdentityObjectTypeImpl.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/SimpleIdentityObjectTypeImpl.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,44 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl;
+
+import org.jboss.identity.model.core.IdentityObjectType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class SimpleIdentityObjectTypeImpl implements IdentityObjectType
+{
+ String name;
+
+ public SimpleIdentityObjectTypeImpl(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
Copied: trunk/identity-impl/src/test/java/org/jboss/identity/impl/fedid (from rev 84,
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/fedid)
Modified:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/fedid/PseudonymGeneratorUnitTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/fedid/PseudonymGeneratorUnitTestCase.java 2008-09-11
22:01:24 UTC (rev 84)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/fedid/PseudonymGeneratorUnitTestCase.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*/
-package org.jboss.test.identity.impl.test.fedid;
+package org.jboss.identity.impl.fedid;
import org.jboss.identity.impl.fedid.UUIDPseudonymGenerator;
import org.jboss.identity.spi.fedid.PseudonymGenerator;
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateIdentityStoreTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateIdentityStoreTestCase.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateIdentityStoreTestCase.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,311 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.store;
+
+import org.jboss.identity.model.core.IdentityObject;
+import org.hibernate.ejb.HibernateEntityManager;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class HibernateIdentityStoreTestCase extends HibernateTestBase
+{
+
+ protected HibernateIdentityStoreImpl store;
+
+ public HibernateIdentityStoreTestCase(String testName)
+ {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ store = new HibernateIdentityStoreImpl(){
+ protected HibernateEntityManager getEntityManager()
+ {
+ return em;
+ }
+ };
+
+ populateIdentityTypes();
+ populateRelationshipTypes();
+
+ }
+
+ private void populateRelationshipTypes() throws Exception
+ {
+
+ em.getTransaction().begin();
+
+ RelationshipTypeEnum types[] = RelationshipTypeEnum.values();
+
+ for (int i = 0; i < types.length; i++)
+ {
+ RelationshipTypeEnum type = types[i];
+ store.addIdentityObjectRelationshipType(type);
+ }
+
+ em.getTransaction().commit();
+
+ }
+
+ private void populateIdentityTypes() throws Exception
+ {
+ em.getTransaction().begin();
+
+ IdentityTypeEnum types[] = IdentityTypeEnum.values();
+
+ for (int i = 0; i < types.length; i++)
+ {
+ IdentityTypeEnum type = types[i];
+ store.addIdentityObjectType(type);
+ }
+
+ em.getTransaction().commit();
+ }
+
+ public void testStorePersistence() throws Exception{
+
+ em.getTransaction().begin();
+
+ IdentityObject user1 = store.createIdentityObject("Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 = store.createIdentityObject("Eva",
IdentityTypeEnum.USER);
+
+ IdentityObject group1 = store.createIdentityObject("Devision1",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group2 = store.createIdentityObject("Devision2",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group3 = store.createIdentityObject("Devision3",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group4 = store.createIdentityObject("Devision4",
IdentityTypeEnum.ORGANIZATION);
+
+ em.flush();
+
+ assertEquals(0, store.getIdentityObjectsCount(IdentityTypeEnum.ROLE));
+ assertEquals(2, store.getIdentityObjectsCount(IdentityTypeEnum.USER));
+ assertEquals(4, store.getIdentityObjectsCount(IdentityTypeEnum.ORGANIZATION));
+
+ em.flush();
+
+ store.removeIdentityObject(user1);
+ store.removeIdentityObject(group1);
+ store.removeIdentityObject(group2);
+
+ assertEquals(1, store.getIdentityObjectsCount(IdentityTypeEnum.USER));
+ assertEquals(2, store.getIdentityObjectsCount(IdentityTypeEnum.ORGANIZATION));
+
+ store.removeIdentityObject(user2);
+ store.removeIdentityObject(group3);
+ store.removeIdentityObject(group4);
+
+ assertEquals(0, store.getIdentityObjectsCount(IdentityTypeEnum.USER));
+ assertEquals(0, store.getIdentityObjectsCount(IdentityTypeEnum.ORGANIZATION));
+
+ em.getTransaction().commit();
+
+ }
+
+ public void testFindMethods() throws Exception{
+
+ em.getTransaction().begin();
+
+ IdentityObject user1 = store.createIdentityObject("Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 = store.createIdentityObject("Eva",
IdentityTypeEnum.USER);
+
+ IdentityObject group1 = store.createIdentityObject("Devision1",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group2 = store.createIdentityObject("Devision2",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group3 = store.createIdentityObject("Devision3",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group4 = store.createIdentityObject("Devision4",
IdentityTypeEnum.ORGANIZATION);
+
+ em.flush();
+
+ IdentityObject xx = store.findIdentityObject("Adam",
IdentityTypeEnum.USER);
+ assertEquals(xx.getId(), user1.getId());
+
+ xx = store.findIdentityObject(user2.getId());
+ assertEquals(xx.getId(), user2.getId());
+
+ Collection results = store.findIdentityObject(IdentityTypeEnum.USER, 0, 0, true,
true);
+ assertEquals(2, results.size());
+
+ results = store.findIdentityObject(IdentityTypeEnum.ORGANIZATION, 0, 0, true,
true);
+ assertEquals(4, results.size());
+
+ results = store.findIdentityObject(IdentityTypeEnum.ROLE, 0, 0, true, true);
+ assertEquals(0, results.size());
+
+
+ em.getTransaction().commit();
+
+ }
+
+ public void testAttributes() throws Exception{
+
+ em.getTransaction().begin();
+
+ IdentityObject user1 = store.createIdentityObject("Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 = store.createIdentityObject("Eva",
IdentityTypeEnum.USER);
+
+ em.flush();
+
+ Map<String, Set<String>> attrs = new HashMap<String,
Set<String>>();
+ HashSet<String> vals = new HashSet<String>();
+ vals.add("val1");
+ vals.add("val2");
+ vals.add("val3");
+
+ attrs.put("key1", vals);
+
+ vals = new HashSet<String>();
+ vals.add("val1");
+ vals.add("val2");
+ vals.add("val3");
+ vals.add("val4");
+ attrs.put("key2", vals);
+
+ store.addAttributes(user1, attrs);
+
+ em.flush();
+
+ Map<String, Set<String>> persistedAttrs = store.getAttributes(user1);
+
+ assertEquals(2, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key1"));
+ assertEquals(3, persistedAttrs.get("key1").size());
+
+ assertTrue(persistedAttrs.containsKey("key2"));
+ assertEquals(4, persistedAttrs.get("key2").size());
+
+ em.flush();
+
+ attrs = new HashMap<String, Set<String>>();
+ vals = new HashSet<String>();
+ vals.add("val1");
+ attrs.put("key3", vals);
+
+ store.addAttributes(user1, attrs);
+
+ em.flush();
+
+ persistedAttrs = store.getAttributes(user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key1"));
+ assertEquals(3, persistedAttrs.get("key1").size());
+
+ assertTrue(persistedAttrs.containsKey("key2"));
+ assertEquals(4, persistedAttrs.get("key2").size());
+
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(1, persistedAttrs.get("key3").size());
+
+ em.flush();
+
+ store.updateAttributes(user1, attrs);
+
+ em.flush();
+
+ persistedAttrs = store.getAttributes(user1);
+
+ assertEquals(1, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("key3"));
+ assertEquals(1, persistedAttrs.get("key3").size());
+
+ em.flush();
+
+ Set<String> names = new HashSet<String>();
+ names.add("key3");
+ store.removeAttributes(user1, names);
+
+ em.flush();
+
+ persistedAttrs = store.getAttributes(user1);
+
+ assertEquals(0, persistedAttrs.keySet().size());
+
+
+ em.getTransaction().commit();
+
+ }
+
+ public void testRelationships() throws Exception{
+
+ em.getTransaction().begin();
+
+ IdentityObject user1 = store.createIdentityObject("Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 = store.createIdentityObject("Eva",
IdentityTypeEnum.USER);
+
+ IdentityObject group1 = store.createIdentityObject("Devision1",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group2 = store.createIdentityObject("Devision2",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group3 = store.createIdentityObject("Devision3",
IdentityTypeEnum.ORGANIZATION);
+ IdentityObject group4 = store.createIdentityObject("Devision4",
IdentityTypeEnum.ORGANIZATION);
+
+ em.flush();
+
+ store.createRelationship(group1, user1, RelationshipTypeEnum.MEMBER);
+ store.createRelationship(group2, user1, RelationshipTypeEnum.MEMBER);
+
+ em.flush();
+
+ assertEquals(1, store.resolveRelationships(group1, user1).size());
+ assertEquals(0, store.resolveRelationships(user1, group1).size());
+ assertEquals(1, store.resolveRelationships(group2, user1).size());
+ assertEquals(0, store.resolveRelationships(user1, group2).size());
+
+ store.removeRelationship(group2, user1, RelationshipTypeEnum.MEMBER);
+
+ em.flush();
+
+ assertEquals(1, store.resolveRelationships(group1, user1).size());
+ assertEquals(0, store.resolveRelationships(user1, group1).size());
+ assertEquals(0, store.resolveRelationships(group2, user1).size());
+ assertEquals(0, store.resolveRelationships(user1, group2).size());
+
+ store.removeRelationships(user1, group1);
+
+ assertEquals(0, store.resolveRelationships(group1, user1).size());
+ assertEquals(0, store.resolveRelationships(user1, group1).size());
+ assertEquals(0, store.resolveRelationships(group2, user1).size());
+ assertEquals(0, store.resolveRelationships(user1, group2).size());
+
+
+ em.getTransaction().commit();
+
+ }
+
+
+
+
+
+
+}
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateModelTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateModelTestCase.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateModelTestCase.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,277 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.store;
+
+import java.util.Set;
+import java.util.HashSet;
+
+import javax.persistence.Query;
+
+import org.jboss.identity.impl.model.HibernateIdentityObject;
+import org.jboss.identity.impl.model.HibernateIdentityObjectRelationship;
+import org.jboss.identity.impl.model.HibernateIdentityObjectRelationshipType;
+import org.jboss.identity.impl.model.HibernateIdentityObjectType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class HibernateModelTestCase extends HibernateTestBase
+{
+ public HibernateModelTestCase(String testName)
+ {
+ super(testName);
+ }
+
+ public void testPersistence() {
+
+ em.getTransaction().begin();
+
+
+ //
+
+ HibernateIdentityObjectType iot = new HibernateIdentityObjectType();
+ iot.setName("User");
+
+ em.persist(iot);
+ assertTrue(em.contains(iot));
+
+
+ HibernateIdentityObject io = new HibernateIdentityObject();
+ io.setName("John Kowalski");
+ io.setIdentityType(iot);
+
+ em.persist(io);
+ assertTrue(em.contains(io));
+
+ em.remove(io);
+ assertFalse(em.contains(io));
+
+ //
+
+
+
+ //
+
+ HibernateIdentityObjectRelationshipType iort = new
HibernateIdentityObjectRelationshipType();
+ iort.setName("Member");
+
+ em.persist(iort);
+ assertTrue(em.contains(iort));
+
+ //
+
+// JPAIdentityObjectRelationship ior = new JPAIdentityObjectRelationship();
+// ior.setType(iort);
+//
+// em.persist(ior);
+// assertTrue(em.contains(ior));
+
+// em.remove(ior);
+// assertFalse(em.contains(ior));
+
+ //
+
+ assertTrue(em.contains(iort));
+
+ em.remove(iort);
+ assertFalse(em.contains(iort));
+
+ em.getTransaction().commit();
+
+
+ }
+
+ public void testRelationships()
+ {
+
+ em.getTransaction().begin();
+
+ HibernateIdentityObjectType groupType = new
HibernateIdentityObjectType("Group");
+ em.persist(groupType);
+ HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
+ em.persist(userType);
+
+ HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType);
+ em.persist(user1);
+ HibernateIdentityObject user2 = new HibernateIdentityObject("user2",
userType);
+ em.persist(user2);
+ HibernateIdentityObject user3 = new HibernateIdentityObject("user3",
userType);
+ em.persist(user3);
+
+ HibernateIdentityObject group1 = new HibernateIdentityObject("group1",
groupType);
+ em.persist(group1);
+ HibernateIdentityObject group2 = new HibernateIdentityObject("group2",
groupType);
+ em.persist(group2);
+ HibernateIdentityObject group3 = new HibernateIdentityObject("group3",
groupType);
+ em.persist(group3);
+
+ HibernateIdentityObjectRelationshipType memberType = new
HibernateIdentityObjectRelationshipType("member");
+ em.persist(memberType);
+
+ HibernateIdentityObjectRelationship relationship = new
HibernateIdentityObjectRelationship(memberType, group1, user1);
+ em.persist(relationship);
+ relationship = new HibernateIdentityObjectRelationship(memberType, group1, user2);
+ em.persist(relationship);
+ relationship = new HibernateIdentityObjectRelationship(memberType, group2, user3);
+ em.persist(relationship);
+ relationship = new HibernateIdentityObjectRelationship(memberType, group2,
group1);
+ em.persist(relationship);
+
+ em.getTransaction().commit();
+
+ //
+
+ em.getTransaction().begin();
+
+ Query ioQuery = em.createQuery("select o from HibernateIdentityObject o where
o.name like :name");
+
+ group1 = (HibernateIdentityObject)ioQuery.setParameter("name",
"group1").getSingleResult();
+ assertEquals(2, group1.getFromRelationships().size());
+ assertEquals(1, group1.getToRelationships().size());
+ group2 = (HibernateIdentityObject)ioQuery.setParameter("name",
"group2").getSingleResult();
+ assertEquals(2, group2.getFromRelationships().size());
+ assertEquals(0, group2.getToRelationships().size());
+
+ user3 = (HibernateIdentityObject)ioQuery.setParameter("name",
"user3").getSingleResult();
+ assertEquals(1, user3.getToRelationships().size());
+ assertEquals(0, user3.getFromRelationships().size());
+ assertEquals("group2",
user3.getToRelationships().iterator().next().getFromIdentityObject().getName());
+ em.getTransaction().commit();
+
+ }
+
+ public void testNameTypeConstraint() throws Exception
+ {
+
+ em.getTransaction().begin();
+
+ HibernateIdentityObjectType groupType = new
HibernateIdentityObjectType("Group");
+ em.persist(groupType);
+ HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
+ em.persist(userType);
+
+ HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType);
+ em.persist(user1);
+ HibernateIdentityObject user2 = new HibernateIdentityObject("user2",
userType);
+ em.persist(user2);
+
+ em.getTransaction().commit();
+ em.getTransaction().begin();
+
+ try
+ {
+
+ HibernateIdentityObject user3 = new HibernateIdentityObject("user2",
userType);
+ em.persist(user3);
+
+ // Should fail
+ fail();
+ }
+ catch (Exception e)
+ {
+ //expected
+ em.getTransaction().rollback();
+ }
+
+
+ em.getTransaction().begin();
+
+
+ HibernateIdentityObject user4 = new HibernateIdentityObject("group1",
userType);
+ em.persist(user4);
+
+
+ HibernateIdentityObject group1 = new HibernateIdentityObject("group1",
groupType);
+ em.persist(group1);
+ HibernateIdentityObject group2 = new HibernateIdentityObject("group2",
groupType);
+ em.persist(group2);
+
+ em.flush();
+
+ try
+ {
+
+ HibernateIdentityObject group3 = new HibernateIdentityObject("group2",
groupType);
+ em.persist(group3);
+
+ // Should fail
+ fail();
+ }
+ catch (Exception e)
+ {
+ //expected
+ em.getTransaction().rollback();
+ }
+
+ em.getTransaction().begin();
+
+ HibernateIdentityObject group4 = new HibernateIdentityObject("user1",
groupType);
+ em.persist(group4);
+
+ em.getTransaction().commit();
+
+
+
+
+
+ }
+
+
+ public void testAttributes() throws Exception
+ {
+
+ em.getTransaction().begin();
+
+ HibernateIdentityObjectType userType = new
HibernateIdentityObjectType("User");
+ em.persist(userType);
+ HibernateIdentityObject user1 = new HibernateIdentityObject("user1",
userType);
+ em.persist(user1);
+
+ Set<String> values1 = new HashSet<String>();
+ values1.add("Val1");
+ values1.add("Val2");
+ values1.add("Val3");
+
+
+ user1.setAttribute("simple1", values1);
+ user1.setAttribute("simple2", values1);
+
+
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+
+
+ user1 = em.find(HibernateIdentityObject.class, user1.getId());
+ assertEquals(2, user1.getAttributes().entrySet().size() );
+ assertNotNull(user1.getAttributes().get("simple1"));
+ assertEquals(3, user1.getAttributes().get("simple1").size());
+
+
+ em.getTransaction().commit();
+
+
+ }
+
+}
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateTestBase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateTestBase.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/HibernateTestBase.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,99 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.store;
+
+import junit.framework.TestCase;
+
+import javax.persistence.Persistence;
+import java.util.logging.Logger;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import org.hibernate.ejb.HibernateEntityManager;
+import org.hibernate.ejb.HibernateEntityManagerFactory;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public abstract class HibernateTestBase extends TestCase
+{
+ private static Logger logger =
Logger.getLogger(HibernateModelTestCase.class.getName());
+
+ private HibernateEntityManagerFactory emFactory;
+
+ protected HibernateEntityManager em;
+
+ private Connection connection;
+
+
+ public HibernateTestBase(String testName) {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ try {
+ logger.info("Starting in-memory HSQL database for unit tests");
+ Class.forName("org.hsqldb.jdbcDriver");
+ connection =
DriverManager.getConnection("jdbc:hsqldb:mem:unit-testing-jpa", "sa",
"");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Exception during HSQL database startup.");
+ }
+ try
+ {
+ logger.info("Building JPA EntityManager for unit tests");
+ emFactory =
(HibernateEntityManagerFactory)Persistence.createEntityManagerFactory("jboss-identity-model");
+ em = (HibernateEntityManager)emFactory.createEntityManager();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Exception during JPA EntityManager instanciation.");
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ logger.info("Shuting down Hibernate JPA layer.");
+ if (em != null)
+ {
+ em.close();
+ }
+ if (emFactory != null)
+ {
+ emFactory.close();
+ }
+ logger.info("Stopping in-memory HSQL database.");
+ try
+ {
+ connection.createStatement().execute("SHUTDOWN");
+ }
+ catch (Exception ex) {}
+ }
+}
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/IdentityTypeEnum.java
===================================================================
--- trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/IdentityTypeEnum.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/IdentityTypeEnum.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,45 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.store;
+
+import org.jboss.identity.model.core.IdentityObjectType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public enum IdentityTypeEnum implements IdentityObjectType
+{
+ IDENTITY,
+ USER,
+ ROLE,
+ GROUP,
+ GROUP_ADMINISTRATION,
+ ORGANIZATION,
+ COMMUNITY;
+
+ public String getName()
+ {
+ return this.name();
+ }
+}
\ No newline at end of file
Added:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/RelationshipTypeEnum.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/RelationshipTypeEnum.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/RelationshipTypeEnum.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,40 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.impl.store;
+
+import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public enum RelationshipTypeEnum implements IdentityObjectRelationshipType
+{
+ MEMBER;
+
+ public String getName()
+ {
+ return this.name();
+ }
+}
Deleted:
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/JPAModelTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/JPAModelTestCase.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/JPAModelTestCase.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -1,368 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.jboss.test.identity.impl.test.portal;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.util.logging.Logger;
-import java.util.Set;
-import java.util.HashSet;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.persistence.Query;
-
-import junit.framework.TestCase;
-
-import org.jboss.identity.impl.model.JPAIdentityObject;
-import org.jboss.identity.impl.model.JPAIdentityObjectRelationship;
-import org.jboss.identity.impl.model.JPAIdentityObjectRelationshipType;
-import org.jboss.identity.impl.model.JPAIdentityObjectType;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
- * @version : 0.1 $
- */
-public class JPAModelTestCase extends TestCase
-{
- private static Logger logger = Logger.getLogger(JPAModelTestCase.class.getName());
-
- private EntityManagerFactory emFactory;
-
- private EntityManager em;
-
- private Connection connection;
-
- public JPAModelTestCase(String testName) {
- super(testName);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- try {
- logger.info("Starting in-memory HSQL database for unit tests");
- Class.forName("org.hsqldb.jdbcDriver");
- connection =
DriverManager.getConnection("jdbc:hsqldb:mem:unit-testing-jpa", "sa",
"");
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- fail("Exception during HSQL database startup.");
- }
- try
- {
- logger.info("Building JPA EntityManager for unit tests");
- emFactory =
Persistence.createEntityManagerFactory("jboss-identity-model");
- em = emFactory.createEntityManager();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- fail("Exception during JPA EntityManager instanciation.");
- }
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- logger.info("Shuting down Hibernate JPA layer.");
- if (em != null)
- {
- em.close();
- }
- if (emFactory != null)
- {
- emFactory.close();
- }
- logger.info("Stopping in-memory HSQL database.");
- try
- {
- connection.createStatement().execute("SHUTDOWN");
- }
- catch (Exception ex) {}
- }
-
- public void testPersistence() {
- try
- {
-
- em.getTransaction().begin();
-
- //
-
- JPAIdentityObject io = new JPAIdentityObject();
- io.setName("John Kowalski");
-
- em.persist(io);
- assertTrue(em.contains(io));
-
- em.remove(io);
- assertFalse(em.contains(io));
-
- //
-
- JPAIdentityObjectType iot = new JPAIdentityObjectType();
- iot.setName("User");
-
- em.persist(iot);
- assertTrue(em.contains(iot));
-
- em.remove(iot);
- assertFalse(em.contains(iot));
-
- //
-
- JPAIdentityObjectRelationshipType iort = new
JPAIdentityObjectRelationshipType();
- iort.setName("Member");
-
- em.persist(iort);
- assertTrue(em.contains(iort));
-
- //
-
- JPAIdentityObjectRelationship ior = new JPAIdentityObjectRelationship();
- ior.setType(iort);
-
- em.persist(ior);
- assertTrue(em.contains(ior));
-
- em.remove(ior);
- assertFalse(em.contains(ior));
-
- //
-
- assertTrue(em.contains(iort));
-
- em.remove(iort);
- assertFalse(em.contains(iort));
-
- em.getTransaction().commit();
-
- }
- catch (Exception ex)
- {
- em.getTransaction().rollback();
- ex.printStackTrace();
- fail("Exception during testPersistence");
- }
- }
-
- public void testRelationships()
- {
- try
- {
- em.getTransaction().begin();
-
- JPAIdentityObjectType groupType = new JPAIdentityObjectType("Group");
- em.persist(groupType);
- JPAIdentityObjectType userType = new JPAIdentityObjectType("User");
- em.persist(userType);
-
- JPAIdentityObject user1 = new JPAIdentityObject("user1", userType);
- em.persist(user1);
- JPAIdentityObject user2 = new JPAIdentityObject("user2", userType);
- em.persist(user2);
- JPAIdentityObject user3 = new JPAIdentityObject("user3", userType);
- em.persist(user3);
-
- JPAIdentityObject group1 = new JPAIdentityObject("group1",
groupType);
- em.persist(group1);
- JPAIdentityObject group2 = new JPAIdentityObject("group2",
groupType);
- em.persist(group2);
- JPAIdentityObject group3 = new JPAIdentityObject("group3",
groupType);
- em.persist(group3);
-
- JPAIdentityObjectRelationshipType memberType = new
JPAIdentityObjectRelationshipType("member");
- em.persist(memberType);
-
- JPAIdentityObjectRelationship relationship = new
JPAIdentityObjectRelationship(memberType, group1, user1);
- em.persist(relationship);
- relationship = new JPAIdentityObjectRelationship(memberType, group1, user2);
- em.persist(relationship);
- relationship = new JPAIdentityObjectRelationship(memberType, group2, user3);
- em.persist(relationship);
- relationship = new JPAIdentityObjectRelationship(memberType, group2, group1);
- em.persist(relationship);
-
- em.getTransaction().commit();
-
- //
-
- em.getTransaction().begin();
-
- Query ioQuery = em.createQuery("select o from JPAIdentityObject o where
o.name like :name");
-
- group1 = (JPAIdentityObject)ioQuery.setParameter("name",
"group1").getSingleResult();
- assertEquals(2, group1.getFromRelationships().size());
- assertEquals(1, group1.getToRelationships().size());
- group2 = (JPAIdentityObject)ioQuery.setParameter("name",
"group2").getSingleResult();
- assertEquals(2, group2.getFromRelationships().size());
- assertEquals(0, group2.getToRelationships().size());
-
- user3 = (JPAIdentityObject)ioQuery.setParameter("name",
"user3").getSingleResult();
- assertEquals(1, user3.getToRelationships().size());
- assertEquals(0, user3.getFromRelationships().size());
- assertEquals("group2",
user3.getToRelationships().iterator().next().getFromIdentityObject().getName());
- em.getTransaction().commit();
- }
- catch (Exception ex)
- {
- em.getTransaction().rollback();
- ex.printStackTrace();
- fail("Exception during testPersistence");
- }
- }
-
- public void testNameTypeConstraint() throws Exception
- {
-
- try
- {
- em.getTransaction().begin();
-
- JPAIdentityObjectType groupType = new JPAIdentityObjectType("Group");
- em.persist(groupType);
- JPAIdentityObjectType userType = new JPAIdentityObjectType("User");
- em.persist(userType);
-
- JPAIdentityObject user1 = new JPAIdentityObject("user1", userType);
- em.persist(user1);
- JPAIdentityObject user2 = new JPAIdentityObject("user2", userType);
- em.persist(user2);
-
- em.flush();
-
- try
- {
-
- JPAIdentityObject user3 = new JPAIdentityObject("user2",
userType);
- em.persist(user3);
-
- //em.getTransaction().commit();
-
- // Should fail
- fail();
- }
- catch (Exception e)
- {
- //expected
- em.getTransaction().rollback();
- }
-
-
- em.getTransaction().begin();
-
-
- JPAIdentityObject user4 = new JPAIdentityObject("group1", userType);
- em.persist(user4);
-
-
- JPAIdentityObject group1 = new JPAIdentityObject("group1",
groupType);
- em.persist(group1);
- JPAIdentityObject group2 = new JPAIdentityObject("group2",
groupType);
- em.persist(group2);
-
- em.flush();
-
- try
- {
-
- JPAIdentityObject group3 = new JPAIdentityObject("group2",
groupType);
- em.persist(group3);
-
- // Should fail
- fail();
- }
- catch (Exception e)
- {
- //expected
- em.getTransaction().rollback();
- }
-
- em.getTransaction().begin();
-
- JPAIdentityObject group4 = new JPAIdentityObject("user1", groupType);
- em.persist(group4);
-
- em.getTransaction().commit();
-
-
-
- }
- catch (Exception ex)
- {
- em.getTransaction().rollback();
- ex.printStackTrace();
- fail("Exception during testPersistence");
- }
-
- }
-
-
- public void testAttributes() throws Exception
- {
-
- try
- {
- em.getTransaction().begin();
-
- JPAIdentityObjectType userType = new JPAIdentityObjectType("User");
- em.persist(userType);
- JPAIdentityObject user1 = new JPAIdentityObject("user1", userType);
- em.persist(user1);
-
- Set<String> values1 = new HashSet<String>();
- values1.add("Val1");
- values1.add("Val2");
- values1.add("Val3");
-
-
- user1.addAttribute("simple1", values1);
- user1.addAttribute("simple2", values1);
-
-
- em.getTransaction().commit();
-
- em.getTransaction().begin();
-
-
- user1 = em.find(JPAIdentityObject.class, user1.getId());
- assertEquals(2, user1.getAttributes().entrySet().size() );
- assertNotNull(user1.getAttributes().get("simple1"));
- assertEquals(3, user1.getAttributes().get("simple1").size());
-
-
- em.getTransaction().commit();
- }
- catch (Exception ex)
- {
- em.getTransaction().rollback();
- ex.printStackTrace();
- fail("Exception during testPersistence");
- }
-
- }
-
-}
Modified: trunk/identity-impl/src/test/resources/META-INF/persistence.xml
===================================================================
--- trunk/identity-impl/src/test/resources/META-INF/persistence.xml 2008-09-17 15:48:28
UTC (rev 92)
+++ trunk/identity-impl/src/test/resources/META-INF/persistence.xml 2008-09-19 11:37:32
UTC (rev 93)
@@ -9,11 +9,11 @@
<provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>org.jboss.identity.impl.model.JPAIdentityObject</class>
-
<class>org.jboss.identity.impl.model.JPAIdentityObjectAttribute</class>
- <class>org.jboss.identity.impl.model.JPAIdentityObjectType</class>
-
<class>org.jboss.identity.impl.model.JPAIdentityObjectRelationship</class>
-
<class>org.jboss.identity.impl.model.JPAIdentityObjectRelationshipType</class>
+ <class>org.jboss.identity.impl.model.HibernateIdentityObject</class>
+
<class>org.jboss.identity.impl.model.HibernateIdentityObjectAttribute</class>
+
<class>org.jboss.identity.impl.model.HibernateIdentityObjectType</class>
+
<class>org.jboss.identity.impl.model.HibernateIdentityObjectRelationship</class>
+
<class>org.jboss.identity.impl.model.HibernateIdentityObjectRelationshipType</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
Modified:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/AttributeStore.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -54,7 +54,7 @@
* @return
* @throws IdentityException
*/
- Map<String, String[]> getAttributes(IdentityObject identity) throws
IdentityException;
+ Map<String, Set<String>> getAttributes(IdentityObject identity) throws
IdentityException;
/**
* Update attributes with new values - previous values will be overwritten
@@ -62,7 +62,7 @@
* @param attributes
* @throws IdentityException
*/
- void updateAttributes(IdentityObject identity, Map<String, String[]>
attributes)
+ void updateAttributes(IdentityObject identity, Map<String, Set<String>>
attributes)
throws IdentityException;
/**
@@ -73,7 +73,7 @@
* @param attributes
* @throws IdentityException
*/
- void addAttributes(IdentityObject identity, Map<String, String[]> attributes)
+ void addAttributes(IdentityObject identity, Map<String, Set<String>>
attributes)
throws IdentityException;
/**
Modified:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/FeaturesDescription.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/FeaturesDescription.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/FeaturesDescription.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -61,18 +61,18 @@
* @return set of identity types that can be processed with a given operation
* @throws org.jboss.identity.exception.IdentityException
*/
- public Set<IdentityObjectType> getSupportedIdentities(OperationType
operationType);
+ public Set<IdentityObjectType> getSupportedIdentityObjectTypes(OperationType
operationType);
/**
* @return set of identity types that can be persisted
*/
- Set<IdentityObjectType> getSupportedIdentities();
+ Set<IdentityObjectType> getSupportedIdentityObjectTypes();
/**
* @param identityObjectType
* @return boolean describing if given identity type can be persisted or retrieved
using this identity store
*/
- boolean isIdentitySupported(IdentityObjectType identityObjectType);
+ boolean isIdentityObjectTypeSupported(IdentityObjectType identityObjectType);
/**
* @param fromType
@@ -81,7 +81,7 @@
* @return true is given relationship can be persisted or retrieved
* @throws org.jboss.identity.exception.IdentityException
*/
- boolean isRelationshipSupported(IdentityObjectType fromType, IdentityObjectType
toType,
+ boolean isRelationshipTypeSupported(IdentityObjectType fromType, IdentityObjectType
toType,
IdentityObjectRelationshipType relationshipType)
throws IdentityException;
Modified:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java 2008-09-17
15:48:28 UTC (rev 92)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStore.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -67,7 +67,7 @@
* @return
* @throws IdentityException
*/
- IdentityObject createIdentity(String name, IdentityObjectType identityObjectType)
throws IdentityException;
+ IdentityObject createIdentityObject(String name, IdentityObjectType
identityObjectType) throws IdentityException;
/**
* Remove given identity
@@ -75,14 +75,14 @@
* @param identity
* @throws IdentityException
*/
- void removeIdentity(IdentityObject identity) throws IdentityException;
+ void removeIdentityObject(IdentityObject identity) throws IdentityException;
/**
* @param identityType
* @return a number of stored identities with a given type
* @throws IdentityException
*/
- <T extends IdentityObjectType> int getIdentitiesCount(T identityType)
+ <T extends IdentityObjectType> int getIdentityObjectsCount(T identityType)
throws IdentityException;
/**
@@ -93,7 +93,7 @@
* @return
* @throws IdentityException
*/
- IdentityObject findIdentity(String name, IdentityObjectType identityObjectType) throws
IdentityException;
+ IdentityObject findIdentityObject(String name, IdentityObjectType identityObjectType)
throws IdentityException;
/**
* Find identity with a given id
@@ -102,7 +102,7 @@
* @return
* @throws IdentityException
*/
- IdentityObject findIdentity(Object id) throws IdentityException;
+ IdentityObject findIdentityObject(Object id) throws IdentityException;
/**
* Find identities with a given type paginated and ordered.
@@ -113,14 +113,12 @@
* @param identityType
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
- * @param ascending default true
- * @return
- * @throws IdentityException
+ * @param orderByName
+ *@param ascending default true @return @throws IdentityException
*/
- <T extends IdentityObjectType> Collection<IdentityObject> findIdentities(T
identityType,
+ Collection<IdentityObject> findIdentityObject(IdentityObjectType identityType,
int offset, int limit,
- String orderedByAttributeName,
+ boolean orderByName,
boolean ascending) throws IdentityException;
/**
@@ -132,15 +130,14 @@
* @param attributes
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
- * @param ascending default true
- * @return
+ * @param orderByName
+ *@param ascending default true @return
* @throws IdentityException
*/
- <T extends IdentityObjectType> Collection<IdentityObject> findIdentities(T
identityType,
+ Collection<IdentityObject> findIdentityObject(IdentityObjectType identityType,
Map<String, String[]> attributes,
int offset, int limit,
- String orderedByAttributeName, boolean ascending)
throws IdentityException;
+ boolean orderByName, boolean ascending) throws
IdentityException;
/**
* Find identites that have relationship with given identity. Relationships are
directional (from parent to child).
@@ -150,20 +147,19 @@
*
* @param identity
* @param relationshipType
- * @param parent defines if given identity is parent or child side in the
+ * @param parent defines if given identity is parent or child side in the
* relationship - default is true (parent)
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
- * @param ascending default true
- * @return
+ * @param orderByName
+ *@param ascending default true @return
* @throws IdentityException
*/
- <R extends IdentityObjectRelationshipType>Collection<IdentityObject>
findIdentities(IdentityObject identity,
- R relationshipType,
+ Collection<IdentityObject> findIdentityObject(IdentityObject identity,
+ IdentityObjectRelationshipType relationshipType,
boolean parent,
int offset, int limit,
- String orderedByAttributeName,
+ boolean orderByName,
boolean ascending) throws IdentityException;
@@ -176,9 +172,9 @@
* @param relationshipType
* @throws IdentityException
*/
- <R extends IdentityObjectRelationshipType> void
createRelationship(IdentityObject fromIdentity,
+ void createRelationship(IdentityObject fromIdentity,
IdentityObject toIdentity,
- R relationshipType) throws IdentityException;
+ IdentityObjectRelationshipType relationshipType) throws IdentityException;
/**
* Remove relationship between identities. Relationships can be directional so
@@ -189,9 +185,9 @@
* @param relationshipType
* @throws IdentityException
*/
- <R extends IdentityObjectRelationshipType> void
removeRelationship(IdentityObject fromIdentity,
+ void removeRelationship(IdentityObject fromIdentity,
IdentityObject toIdentity,
- R relationshipType) throws IdentityException;
+ IdentityObjectRelationshipType relationshipType) throws IdentityException;
/**
* Remove all relationships between identities. Direction of relationships doesn't
Added:
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStoreContext.java
===================================================================
---
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStoreContext.java
(rev 0)
+++
trunk/identity-spi/src/main/java/org/jboss/identity/spi/store/IdentityStoreContext.java 2008-09-19
11:37:32 UTC (rev 93)
@@ -0,0 +1,31 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.jboss.identity.spi.store;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface IdentityStoreContext
+{
+}
Modified: trunk/parent/pom.xml
===================================================================
--- trunk/parent/pom.xml 2008-09-17 15:48:28 UTC (rev 92)
+++ trunk/parent/pom.xml 2008-09-19 11:37:32 UTC (rev 93)
@@ -43,7 +43,7 @@
<configuration>
<printSummary>true</printSummary>
<disableXmlReport>false</disableXmlReport>
- <testFailureIgnore>true</testFailureIgnore>
+ <testFailureIgnore>false</testFailureIgnore>
<includes>
<include>**/**TestCase.java</include>
</includes>