Author: bdaw
Date: 2009-11-12 08:37:28 -0500 (Thu, 12 Nov 2009)
New Revision: 929
Modified:
idm/trunk/example/simple/src/test/java/org/jboss/identity/idm/example/DBTestCase.java
idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/SimpleAttribute.java
idm/trunk/idm-hibernate/src/main/java/org/jboss/identity/idm/impl/model/hibernate/HibernateIdentityObjectAttribute.java
idm/trunk/idm-hibernate/src/main/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreImpl.java
idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java
Log:
- fix updateAttributes() to add not present attributes istead of only update values of
present ones
Modified:
idm/trunk/example/simple/src/test/java/org/jboss/identity/idm/example/DBTestCase.java
===================================================================
---
idm/trunk/example/simple/src/test/java/org/jboss/identity/idm/example/DBTestCase.java 2009-11-11
22:47:31 UTC (rev 928)
+++
idm/trunk/example/simple/src/test/java/org/jboss/identity/idm/example/DBTestCase.java 2009-11-12
13:37:28 UTC (rev 929)
@@ -128,11 +128,13 @@
random.nextBytes(picture);
identitySession.getAttributesManager().addAttributes(johnDoe, new Attribute[] {new
SimpleAttribute("picture", new byte[][]{picture})});
+ identitySession.getAttributesManager().addAttributes(johnDoe, new Attribute[] {new
SimpleAttribute("emplyer", new String[]{"ACME1",
"ACME2"})});
+ identitySession.getAttributesManager().addAttributes(johnDoe, new Attribute[] {new
SimpleAttribute("hobby", new String[]{"BASE Jumping"})});
// Assert picture
Map<String, Attribute> attributes =
identitySession.getAttributesManager().getAttributes(johnDoe);
- assertEquals(1, attributes.keySet().size());
+ assertEquals(3, attributes.keySet().size());
assertTrue(Arrays.equals((byte[])attributes.get("picture").getValue(),
picture));
Modified:
idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/SimpleAttribute.java
===================================================================
---
idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/SimpleAttribute.java 2009-11-11
22:47:31 UTC (rev 928)
+++
idm/trunk/idm-core/src/main/java/org/jboss/identity/idm/impl/api/SimpleAttribute.java 2009-11-12
13:37:28 UTC (rev 929)
@@ -58,7 +58,11 @@
public SimpleAttribute(String name, Object value)
{
this.name = name;
- this.values.add(value);
+ if (value != null)
+ {
+ this.values.add(value);
+ }
+
}
public SimpleAttribute(Attribute attribute)
Modified:
idm/trunk/idm-hibernate/src/main/java/org/jboss/identity/idm/impl/model/hibernate/HibernateIdentityObjectAttribute.java
===================================================================
---
idm/trunk/idm-hibernate/src/main/java/org/jboss/identity/idm/impl/model/hibernate/HibernateIdentityObjectAttribute.java 2009-11-11
22:47:31 UTC (rev 928)
+++
idm/trunk/idm-hibernate/src/main/java/org/jboss/identity/idm/impl/model/hibernate/HibernateIdentityObjectAttribute.java 2009-11-12
13:37:28 UTC (rev 929)
@@ -36,9 +36,9 @@
public class HibernateIdentityObjectAttribute implements IdentityObjectAttribute
{
- public static final String TYPE_TEXT = "TEXT";
+ public static final String TYPE_TEXT = "text";
- public static final String TYPE_BINARY = "BINARY";
+ public static final String TYPE_BINARY = "binary";
private Long id;
@@ -101,6 +101,10 @@
public void setType(String newType)
{
+ if (!newType.equals(TYPE_TEXT) && !newType.equals(TYPE_BINARY))
+ {
+ throw new IllegalArgumentException("Type has not supported value." +
" Name=" + name + "; type=" + type);
+ }
this.type = newType;
}
@@ -119,7 +123,7 @@
return Collections.unmodifiableSet(textValues);
}
- public void setTextValues(Set<String> textValues)
+ public void setTextValues(Collection<String> textValues)
{
this.textValues.clear();
this.textValues.addAll(textValues);
@@ -149,7 +153,7 @@
}
else
{
- throw new IllegalStateException("Type has not supported value");
+ throw new IllegalStateException("Type has not supported value." +
" Name=" + name + "; type=" + type);
}
}
@@ -159,7 +163,7 @@
{
if (!(value instanceof String))
{
- throw new IllegalArgumentException("String value expected with a set
type");
+ throw new IllegalArgumentException("String value expected with a set
type." + " Name=" + name + "; type=" + type);
}
addTextValue((String)value);
}
@@ -167,14 +171,14 @@
{
if (!(value instanceof byte[]))
{
- throw new IllegalArgumentException("byte[] value expected with a set
type");
+ throw new IllegalArgumentException("byte[] value expected with a set
type." + " Name=" + name + "; type=" + type);
}
setBinaryValue((byte[])value);
}
else
{
- throw new IllegalStateException("Type has not supported value or has not
been set");
+ throw new IllegalStateException("Type has not supported value or has not
been set." + " Name=" + name + "; type=" + type);
}
}
@@ -192,7 +196,7 @@
}
else
{
- throw new IllegalStateException("Type has not supported value");
+ throw new IllegalStateException("Type has not supported value." +
" Name=" + name + "; type=" + type);
}
}
@@ -212,7 +216,7 @@
}
else
{
- throw new IllegalStateException("Type has not supported value");
+ throw new IllegalStateException("Type has not supported value." +
" Name=" + name + "; type=" + type);
}
}
}
Modified:
idm/trunk/idm-hibernate/src/main/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreImpl.java
===================================================================
---
idm/trunk/idm-hibernate/src/main/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreImpl.java 2009-11-11
22:47:31 UTC (rev 928)
+++
idm/trunk/idm-hibernate/src/main/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreImpl.java 2009-11-12
13:37:28 UTC (rev 929)
@@ -1658,8 +1658,6 @@
throw new IllegalArgumentException("attributes are null");
}
- //TODO: check if attribute values time is same as MD type
-
Map<String, IdentityObjectAttribute> mappedAttributes = new
HashMap<String, IdentityObjectAttribute>();
Map<String, IdentityObjectAttributeMetaData> mdMap =
attributesMetaData.get(identity.getIdentityType().getName());
@@ -1750,10 +1748,13 @@
// Default to text
String type = amd != null ? amd.getType() :
IdentityObjectAttributeMetaData.TEXT_TYPE;
+ boolean present = false;
+
for (HibernateIdentityObjectAttribute storeAttribute :
hibernateObject.getAttributes())
{
if (storeAttribute.getName().equals(name))
{
+ present = true;
if
(storeAttribute.getType().equals(HibernateIdentityObjectAttribute.TYPE_TEXT))
{
if (!type.equals(IdentityObjectAttributeMetaData.TEXT_TYPE))
@@ -1779,9 +1780,6 @@
throw new IdentityException("Wrong attribute mapping. Attribute
persisted as binary is mapped with: "
+ type + ". Attribute name: " + name);
}
-
-
-
storeAttribute.setBinaryValue((byte[])attribute.getValue());
}
else
@@ -1791,6 +1789,21 @@
break;
}
}
+
+ if (!present && attribute.getValues() != null &&
attribute.getValues().size() > 0)
+ {
+ HibernateIdentityObjectAttribute newAttribute = new
HibernateIdentityObjectAttribute(hibernateObject, name, type);
+ if (type.equals(HibernateIdentityObjectAttribute.TYPE_TEXT))
+ {
+ newAttribute.setTextValues(attribute.getValues());
+ }
+ else if (type.equals(HibernateIdentityObjectAttribute.TYPE_BINARY))
+ {
+ newAttribute.setBinaryValue((byte[])attribute.getValue());
+ }
+ hibernateObject.addAttribute(newAttribute);
+ }
+
}
}
@@ -1951,7 +1964,7 @@
values.add(value.toString());
}
hibernateAttribute = new HibernateIdentityObjectAttribute(hibernateObject,
name, HibernateIdentityObjectAttribute.TYPE_TEXT);
- hibernateAttribute.setTextValues(values);;
+ hibernateAttribute.setTextValues(values);
}
else if (type.equals(IdentityObjectAttributeMetaData.BINARY_TYPE))
{
Modified:
idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java
===================================================================
---
idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java 2009-11-11
22:47:31 UTC (rev 928)
+++
idm/trunk/idm-testsuite/src/test/java/org/jboss/identity/idm/impl/store/hibernate/HibernateIdentityStoreTestCase.java 2009-11-12
13:37:28 UTC (rev 929)
@@ -323,13 +323,27 @@
flush();
+ attrs = new IdentityObjectAttribute[]{
+ new SimpleAttribute("key4", new String[]{"val2"})
+ };
+
+ store.updateAttributes(ctx, user1, attrs);
+
+ flush();
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(4, persistedAttrs.keySet().size());
+ assertEquals("val2",
persistedAttrs.get("key4").getValue().toString());
+
+
store.removeAttributes(ctx, user1, new String[] {"key3"});
flush();
persistedAttrs = store.getAttributes(ctx, user1);
- assertEquals(2, persistedAttrs.keySet().size());
+ assertEquals(3, persistedAttrs.keySet().size());
commit();