Author: ilgrosso Date: Mon Feb 11 11:13:07 2013 New Revision: 1444739 URL: http://svn.apache.org/r1444739 Log: [SYNCOPE-215] Implement usage of AbstractVirSchema#isReadonly() + basci test
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/SchemaDataBinder.java syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java?rev=1444739&r1=1444738&r2=1444739&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java Mon Feb 11 11:13:07 2013 @@ -131,7 +131,7 @@ public abstract class AbstractAttributab } else if (schema.isReadonly()) { schema = null; - LOG.debug("Ignoring virtual or readonly schema {}", schemaName); + LOG.debug("Ignoring readonly schema {}", schemaName); } } @@ -157,6 +157,10 @@ public abstract class AbstractAttributab if (virtualSchema == null) { LOG.debug("Ignoring invalid virtual schema {}", virSchemaName); + } else if (virtualSchema.isReadonly()) { + virtualSchema = null; + + LOG.debug("Ignoring readonly virtual schema {}", virtualSchema); } } @@ -274,6 +278,7 @@ public abstract class AbstractAttributab } for (AbstractVirSchema virSchema : virSchemaDAO.findAll(attrUtil.virSchemaClass())) { if (attributable.getVirtualAttribute(virSchema.getName()) == null + && !virSchema.isReadonly() && evaluateMandatoryCondition(attrUtil, attributable, virSchema.getName(), attrUtil.virIntMappingType())) { @@ -294,11 +299,11 @@ public abstract class AbstractAttributab // 1. virtual attributes to be removed for (String vAttrToBeRemoved : vAttrsToBeRemoved) { - AbstractVirSchema virtualSchema = getVirtualSchema(vAttrToBeRemoved, attrUtil.virSchemaClass()); - if (virtualSchema != null) { - AbstractVirAttr virAttr = attributable.getVirtualAttribute(virtualSchema.getName()); + AbstractVirSchema virSchema = getVirtualSchema(vAttrToBeRemoved, attrUtil.virSchemaClass()); + if (virSchema != null) { + AbstractVirAttr virAttr = attributable.getVirtualAttribute(virSchema.getName()); if (virAttr == null) { - LOG.debug("No virtual attribute found for schema {}", virtualSchema.getName()); + LOG.debug("No virtual attribute found for schema {}", virSchema.getName()); } else { attributable.removeVirtualAttribute(virAttr); virAttrDAO.delete(virAttr); @@ -306,7 +311,7 @@ public abstract class AbstractAttributab for (ExternalResource resource : resourceDAO.findAll()) { for (AbstractMappingItem mapItem : attrUtil.getMappingItems(resource)) { - if (virtualSchema.getName().equals(mapItem.getIntAttrName()) + if (virSchema.getName().equals(mapItem.getIntAttrName()) && mapItem.getIntMappingType() == attrUtil.virIntMappingType() && attributable.getResources().contains(resource)) { @@ -731,7 +736,7 @@ public abstract class AbstractAttributab attributeTO = new AttributeTO(); attributeTO.setSchema(virtualAttribute.getVirtualSchema().getName()); attributeTO.setValues(virtualAttribute.getValues()); - attributeTO.setReadonly(false); + attributeTO.setReadonly(virtualAttribute.getVirtualSchema().isReadonly()); abstractAttributableTO.addVirtualAttribute(attributeTO); } Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/SchemaDataBinder.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/SchemaDataBinder.java?rev=1444739&r1=1444738&r2=1444739&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/SchemaDataBinder.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/SchemaDataBinder.java Mon Feb 11 11:13:07 2013 @@ -19,7 +19,6 @@ package org.apache.syncope.core.rest.data; import java.util.List; - import org.apache.syncope.common.to.SchemaTO; import org.apache.syncope.common.types.SyncopeClientExceptionType; import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException; @@ -45,7 +44,7 @@ public class SchemaDataBinder { */ private static final Logger LOG = LoggerFactory.getLogger(SchemaDataBinder.class); - private static final String[] IGNORE_SCHEMA_PROPERTIES = { "derivedSchemas", "attributes" }; + private static final String[] IGNORE_SCHEMA_PROPERTIES = {"derivedSchemas", "attributes"}; @Autowired private SchemaDAO schemaDAO; Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java?rev=1444739&r1=1444738&r2=1444739&view=diff ============================================================================== --- syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java (original) +++ syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java Mon Feb 11 11:13:07 2013 @@ -21,9 +21,9 @@ package org.apache.syncope.core.persiste import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.List; - import org.apache.syncope.common.types.AttributableType; import org.apache.syncope.core.persistence.beans.user.UVirSchema; import org.apache.syncope.core.util.AttributableUtil; @@ -53,12 +53,13 @@ public class VirSchemaTest extends Abstr public void save() { UVirSchema virtualAttributeSchema = new UVirSchema(); virtualAttributeSchema.setName("virtual"); + virtualAttributeSchema.setReadonly(true); virSchemaDAO.save(virtualAttributeSchema); UVirSchema actual = virSchemaDAO.find("virtual", UVirSchema.class); assertNotNull("expected save to work", actual); - assertEquals(virtualAttributeSchema, actual); + assertTrue(actual.isReadonly()); } @Test