You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2013/10/10 16:38:00 UTC
svn commit: r1531003 [7/9] - in /syncope/trunk: ./
common/src/main/java/org/apache/syncope/common/
common/src/main/java/org/apache/syncope/common/mod/
common/src/main/java/org/apache/syncope/common/to/
common/src/main/java/org/apache/syncope/common/uti...
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=1531003&r1=1531002&r2=1531003&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 Thu Oct 10 14:37:56 2013
@@ -46,10 +46,31 @@ import org.apache.syncope.core.persisten
import org.apache.syncope.core.persistence.beans.AbstractDerAttr;
import org.apache.syncope.core.persistence.beans.AbstractDerSchema;
import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
+import org.apache.syncope.core.persistence.beans.AbstractNormalSchema;
import org.apache.syncope.core.persistence.beans.AbstractSchema;
import org.apache.syncope.core.persistence.beans.AbstractVirAttr;
import org.apache.syncope.core.persistence.beans.AbstractVirSchema;
import org.apache.syncope.core.persistence.beans.ExternalResource;
+import org.apache.syncope.core.persistence.beans.membership.MAttr;
+import org.apache.syncope.core.persistence.beans.membership.MAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.MDerAttr;
+import org.apache.syncope.core.persistence.beans.membership.MDerAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.MVirAttr;
+import org.apache.syncope.core.persistence.beans.membership.MVirAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.Membership;
+import org.apache.syncope.core.persistence.beans.role.RAttr;
+import org.apache.syncope.core.persistence.beans.role.RAttrTemplate;
+import org.apache.syncope.core.persistence.beans.role.RDerAttr;
+import org.apache.syncope.core.persistence.beans.role.RDerAttrTemplate;
+import org.apache.syncope.core.persistence.beans.role.RVirAttr;
+import org.apache.syncope.core.persistence.beans.role.RVirAttrTemplate;
+import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
+import org.apache.syncope.core.persistence.beans.user.UAttr;
+import org.apache.syncope.core.persistence.beans.user.UDerAttr;
+import org.apache.syncope.core.persistence.beans.user.UDerSchema;
+import org.apache.syncope.core.persistence.beans.user.USchema;
+import org.apache.syncope.core.persistence.beans.user.UVirAttr;
+import org.apache.syncope.core.persistence.beans.user.UVirSchema;
import org.apache.syncope.core.persistence.dao.AttrDAO;
import org.apache.syncope.core.persistence.dao.AttrValueDAO;
import org.apache.syncope.core.persistence.dao.ConfDAO;
@@ -120,7 +141,22 @@ public abstract class AbstractAttributab
@Autowired
private JexlUtil jexlUtil;
- private <T extends AbstractSchema> T getSchema(final String schemaName, final Class<T> reference) {
+ @SuppressWarnings("unchecked")
+ protected <T extends AbstractSchema> T getSchema(final String schemaName, final Class<T> reference) {
+ T result = null;
+
+ if (AbstractNormalSchema.class.isAssignableFrom(reference)) {
+ result = (T) getNormalSchema(schemaName, (Class<? extends AbstractNormalSchema>) reference);
+ } else if (AbstractDerSchema.class.isAssignableFrom(reference)) {
+ result = (T) getDerSchema(schemaName, (Class<? extends AbstractDerSchema>) reference);
+ } else if (AbstractVirSchema.class.isAssignableFrom(reference)) {
+ result = (T) getVirSchema(schemaName, (Class<? extends AbstractVirSchema>) reference);
+ }
+
+ return result;
+ }
+
+ private <T extends AbstractNormalSchema> T getNormalSchema(final String schemaName, final Class<T> reference) {
T schema = null;
if (StringUtils.isNotBlank(schemaName)) {
schema = schemaDAO.find(schemaName, reference);
@@ -139,7 +175,7 @@ public abstract class AbstractAttributab
return schema;
}
- private <T extends AbstractDerSchema> T getDerivedSchema(final String derSchemaName, final Class<T> reference) {
+ private <T extends AbstractDerSchema> T getDerSchema(final String derSchemaName, final Class<T> reference) {
T derivedSchema = null;
if (StringUtils.isNotBlank(derSchemaName)) {
derivedSchema = derSchemaDAO.find(derSchemaName, reference);
@@ -151,7 +187,7 @@ public abstract class AbstractAttributab
return derivedSchema;
}
- private <T extends AbstractVirSchema> T getVirtualSchema(final String virSchemaName, final Class<T> reference) {
+ private <T extends AbstractVirSchema> T getVirSchema(final String virSchemaName, final Class<T> reference) {
T virtualSchema = null;
if (StringUtils.isNotBlank(virSchemaName)) {
virtualSchema = virSchemaDAO.find(virSchemaName, reference);
@@ -178,11 +214,10 @@ public abstract class AbstractAttributab
}
protected void fillAttribute(final List<String> values, final AttributableUtil attributableUtil,
- final AbstractSchema schema, final AbstractAttr attribute, final SyncopeClientException invalidValues) {
+ final AbstractNormalSchema schema, final AbstractAttr attr, final SyncopeClientException invalidValues) {
- // if the schema is multivalue, all values are considered for
- // addition, otherwise only the fist one - if provided - is
- // considered
+ // if schema is multivalue, all values are considered for addition;
+ // otherwise only the fist one - if provided - is considered
List<String> valuesProvided = schema.isMultivalue()
? values
: (values.isEmpty()
@@ -194,7 +229,7 @@ public abstract class AbstractAttributab
LOG.debug("Null value for {}, ignoring", schema.getName());
} else {
try {
- attribute.addValue(value, attributableUtil);
+ attr.addValue(value, attributableUtil);
} catch (ValidationException e) {
LOG.error("Invalid value for attribute " + schema.getName() + ": " + value, e);
@@ -209,9 +244,9 @@ public abstract class AbstractAttributab
final AbstractAttributable attributable) {
JexlContext jexlContext = new MapContext();
- jexlUtil.addAttrsToContext(attributable.getAttributes(), jexlContext);
- jexlUtil.addDerAttrsToContext(attributable.getDerivedAttributes(), attributable.getAttributes(), jexlContext);
- jexlUtil.addVirAttrsToContext(attributable.getVirtualAttributes(), jexlContext);
+ jexlUtil.addAttrsToContext(attributable.getAttrs(), jexlContext);
+ jexlUtil.addDerAttrsToContext(attributable.getDerAttrs(), attributable.getAttrs(), jexlContext);
+ jexlUtil.addVirAttrsToContext(attributable.getVirAttrs(), jexlContext);
return Boolean.parseBoolean(jexlUtil.evaluate(mandatoryCondition, jexlContext));
}
@@ -255,8 +290,23 @@ public abstract class AbstractAttributab
LOG.debug("Check mandatory constraint among resources {}", attributable.getResources());
// Check if there is some mandatory schema defined for which no value has been provided
- for (AbstractSchema schema : schemaDAO.findAll(attrUtil.schemaClass())) {
- if (attributable.getAttribute(schema.getName()) == null
+ List<? extends AbstractNormalSchema> normalSchemas;
+ switch (attrUtil.getType()) {
+ case ROLE:
+ normalSchemas = ((SyncopeRole) attributable).getAttrTemplateSchemas(RAttrTemplate.class);
+ break;
+
+ case MEMBERSHIP:
+ normalSchemas = ((Membership) attributable).getSyncopeRole().
+ getAttrTemplateSchemas(MAttrTemplate.class);
+ break;
+
+ case USER:
+ default:
+ normalSchemas = schemaDAO.findAll(attrUtil.schemaClass());
+ }
+ for (AbstractNormalSchema schema : normalSchemas) {
+ if (attributable.getAttr(schema.getName()) == null
&& !schema.isReadonly()
&& (evaluateMandatoryCondition(schema.getMandatoryCondition(), attributable)
|| evaluateMandatoryCondition(attrUtil, attributable, schema.getName(),
@@ -267,8 +317,24 @@ public abstract class AbstractAttributab
reqValMissing.addElement(schema.getName());
}
}
- for (AbstractDerSchema derSchema : derSchemaDAO.findAll(attrUtil.derSchemaClass())) {
- if (attributable.getDerivedAttribute(derSchema.getName()) == null
+
+ List<? extends AbstractDerSchema> derSchemas;
+ switch (attrUtil.getType()) {
+ case ROLE:
+ derSchemas = ((SyncopeRole) attributable).getAttrTemplateSchemas(RDerAttrTemplate.class);
+ break;
+
+ case MEMBERSHIP:
+ derSchemas = ((Membership) attributable).getSyncopeRole().
+ getAttrTemplateSchemas(MDerAttrTemplate.class);
+ break;
+
+ case USER:
+ default:
+ derSchemas = derSchemaDAO.findAll(attrUtil.derSchemaClass());
+ }
+ for (AbstractDerSchema derSchema : derSchemas) {
+ if (attributable.getDerAttr(derSchema.getName()) == null
&& evaluateMandatoryCondition(attrUtil, attributable, derSchema.getName(),
attrUtil.derIntMappingType())) {
@@ -277,8 +343,24 @@ public abstract class AbstractAttributab
reqValMissing.addElement(derSchema.getName());
}
}
- for (AbstractVirSchema virSchema : virSchemaDAO.findAll(attrUtil.virSchemaClass())) {
- if (attributable.getVirtualAttribute(virSchema.getName()) == null
+
+ List<? extends AbstractVirSchema> virSchemas;
+ switch (attrUtil.getType()) {
+ case ROLE:
+ virSchemas = ((SyncopeRole) attributable).getAttrTemplateSchemas(RVirAttrTemplate.class);
+ break;
+
+ case MEMBERSHIP:
+ virSchemas = ((Membership) attributable).getSyncopeRole().
+ getAttrTemplateSchemas(MVirAttrTemplate.class);
+ break;
+
+ case USER:
+ default:
+ virSchemas = virSchemaDAO.findAll(attrUtil.virSchemaClass());
+ }
+ for (AbstractVirSchema virSchema : virSchemas) {
+ if (attributable.getVirAttr(virSchema.getName()) == null
&& !virSchema.isReadonly()
&& evaluateMandatoryCondition(attrUtil, attributable, virSchema.getName(),
attrUtil.virIntMappingType())) {
@@ -292,6 +374,67 @@ public abstract class AbstractAttributab
return reqValMissing;
}
+ private void setAttrSchema(final AbstractAttributable attributable,
+ final AbstractAttr attr, final AbstractNormalSchema schema) {
+
+ if (attr instanceof UAttr) {
+ ((UAttr) attr).setSchema((USchema) schema);
+ } else if (attr instanceof RAttr) {
+ RAttrTemplate template = ((SyncopeRole) attributable).
+ getAttrTemplate(RAttrTemplate.class, schema.getName());
+ if (template != null) {
+ ((RAttr) attr).setTemplate(template);
+ }
+ } else if (attr instanceof MAttr) {
+ MAttrTemplate template = ((Membership) attributable).getSyncopeRole().
+ getAttrTemplate(MAttrTemplate.class, schema.getName());
+ if (template != null) {
+ ((MAttr) attr).setTemplate(template);
+ }
+ }
+ }
+
+ private void setDerAttrSchema(final AbstractAttributable attributable,
+ final AbstractDerAttr derAttr, final AbstractDerSchema derSchema) {
+
+ if (derAttr instanceof UDerAttr) {
+ ((UDerAttr) derAttr).setSchema((UDerSchema) derSchema);
+ } else if (derAttr instanceof RDerAttr) {
+ RDerAttrTemplate template = ((SyncopeRole) attributable).
+ getAttrTemplate(RDerAttrTemplate.class, derSchema.getName());
+ if (template != null) {
+ ((RDerAttr) derAttr).setTemplate(template);
+ }
+ } else if (derAttr instanceof MDerAttr) {
+ MDerAttrTemplate template = ((Membership) attributable).getSyncopeRole().
+ getAttrTemplate(MDerAttrTemplate.class, derSchema.getName());
+ if (template != null) {
+ ((MDerAttr) derAttr).setTemplate(template);
+ }
+ }
+ }
+
+ private void setVirAttrSchema(final AbstractAttributable attributable,
+ final AbstractVirAttr virAttr, final AbstractVirSchema virSchema) {
+
+ if (virAttr instanceof UVirAttr) {
+ ((UVirAttr) virAttr).setSchema((UVirSchema) virSchema);
+ } else if (virAttr instanceof RVirAttr) {
+ RVirAttrTemplate template = ((SyncopeRole) attributable).
+ getAttrTemplate(RVirAttrTemplate.class, virSchema.getName());
+ if (template != null) {
+ ((RVirAttr) virAttr).setTemplate(template);
+ }
+ } else if (virAttr instanceof MVirAttr) {
+ MVirAttrTemplate template =
+ ((Membership) attributable).getSyncopeRole().
+ getAttrTemplate(MVirAttrTemplate.class, virSchema.getName());
+ if (template != null) {
+ ((MVirAttr) virAttr).setTemplate(template);
+ }
+ }
+ }
+
public PropagationByResource fillVirtual(final AbstractAttributable attributable,
final Set<String> vAttrsToBeRemoved, final Set<AttributeMod> vAttrsToBeUpdated,
final AttributableUtil attrUtil) {
@@ -300,13 +443,13 @@ public abstract class AbstractAttributab
// 1. virtual attributes to be removed
for (String vAttrToBeRemoved : vAttrsToBeRemoved) {
- AbstractVirSchema virSchema = getVirtualSchema(vAttrToBeRemoved, attrUtil.virSchemaClass());
+ AbstractVirSchema virSchema = getVirSchema(vAttrToBeRemoved, attrUtil.virSchemaClass());
if (virSchema != null) {
- AbstractVirAttr virAttr = attributable.getVirtualAttribute(virSchema.getName());
+ AbstractVirAttr virAttr = attributable.getVirAttr(virSchema.getName());
if (virAttr == null) {
LOG.debug("No virtual attribute found for schema {}", virSchema.getName());
} else {
- attributable.removeVirtualAttribute(virAttr);
+ attributable.removeVirAttr(virAttr);
virAttrDAO.delete(virAttr);
}
@@ -332,8 +475,22 @@ public abstract class AbstractAttributab
// 2. virtual attributes to be updated
for (AttributeMod vAttrToBeUpdated : vAttrsToBeUpdated) {
- AbstractVirSchema virSchema = getVirtualSchema(vAttrToBeUpdated.getSchema(), attrUtil.virSchemaClass());
+ AbstractVirSchema virSchema = getVirSchema(vAttrToBeUpdated.getSchema(), attrUtil.virSchemaClass());
+ AbstractVirAttr virAttr = null;
if (virSchema != null) {
+ virAttr = attributable.getVirAttr(virSchema.getName());
+ if (virAttr == null) {
+ virAttr = attrUtil.newVirAttr();
+ setVirAttrSchema(attributable, virAttr, virSchema);
+ if (virAttr.getSchema() == null) {
+ LOG.debug("Ignoring {} because no valid schema or template was found", vAttrToBeUpdated);
+ } else {
+ attributable.addVirAttr(virAttr);
+ }
+ }
+ }
+
+ if (virSchema != null && virAttr != null && virAttr.getSchema() != null) {
for (ExternalResource resource : resourceDAO.findAll()) {
for (AbstractMappingItem mapItem : attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION)) {
if (virSchema.getName().equals(mapItem.getIntAttrName())
@@ -345,13 +502,6 @@ public abstract class AbstractAttributab
}
}
- AbstractVirAttr virAttr = attributable.getVirtualAttribute(virSchema.getName());
- if (virAttr == null) {
- virAttr = attrUtil.newVirAttr();
- virAttr.setVirtualSchema(virSchema);
- attributable.addVirtualAttribute(virAttr);
- }
-
final List<String> values = new ArrayList<String>(virAttr.getValues());
values.removeAll(vAttrToBeUpdated.getValuesToBeRemoved());
values.addAll(vAttrToBeUpdated.getValuesToBeAdded());
@@ -377,7 +527,7 @@ public abstract class AbstractAttributab
SyncopeClientException invalidValues = new SyncopeClientException(SyncopeClientExceptionType.InvalidValues);
// 1. resources to be removed
- for (String resourceToBeRemoved : attributableMod.getResourcesToBeRemoved()) {
+ for (String resourceToBeRemoved : attributableMod.getResourcesToRemove()) {
ExternalResource resource = getResource(resourceToBeRemoved);
if (resource != null) {
propByRes.add(ResourceOperation.DELETE, resource.getName());
@@ -388,7 +538,7 @@ public abstract class AbstractAttributab
LOG.debug("Resources to be removed:\n{}", propByRes);
// 2. resources to be added
- for (String resourceToBeAdded : attributableMod.getResourcesToBeAdded()) {
+ for (String resourceToBeAdded : attributableMod.getResourcesToAdd()) {
ExternalResource resource = getResource(resourceToBeAdded);
if (resource != null) {
propByRes.add(ResourceOperation.CREATE, resource.getName());
@@ -399,25 +549,25 @@ public abstract class AbstractAttributab
LOG.debug("Resources to be added:\n{}", propByRes);
// 3. attributes to be removed
- for (String attributeToBeRemoved : attributableMod.getAttributesToBeRemoved()) {
- AbstractSchema schema = getSchema(attributeToBeRemoved, attrUtil.schemaClass());
+ for (String attributeToBeRemoved : attributableMod.getAttrsToRemove()) {
+ AbstractNormalSchema schema = getNormalSchema(attributeToBeRemoved, attrUtil.schemaClass());
if (schema != null) {
- AbstractAttr attribute = attributable.getAttribute(schema.getName());
- if (attribute == null) {
+ AbstractAttr attr = attributable.getAttr(schema.getName());
+ if (attr == null) {
LOG.debug("No attribute found for schema {}", schema);
} else {
String newValue = null;
- for (AttributeMod mod : attributableMod.getAttributesToBeUpdated()) {
+ for (AttributeMod mod : attributableMod.getAttrsToUpdate()) {
if (schema.getName().equals(mod.getSchema())) {
newValue = mod.getValuesToBeAdded().get(0);
}
}
if (!schema.isUniqueConstraint()
- || (!attribute.getUniqueValue().getStringValue().equals(newValue))) {
+ || (!attr.getUniqueValue().getStringValue().equals(newValue))) {
- attributable.removeAttribute(attribute);
- attrDAO.delete(attribute.getId(), attrUtil.attrClass());
+ attributable.removeAttr(attr);
+ attrDAO.delete(attr.getId(), attrUtil.attrClass());
}
}
@@ -429,11 +579,11 @@ public abstract class AbstractAttributab
propByRes.add(ResourceOperation.UPDATE, resource.getName());
- if (mapItem.isAccountid() && attribute != null
- && !attribute.getValuesAsStrings().isEmpty()) {
+ if (mapItem.isAccountid() && attr != null
+ && !attr.getValuesAsStrings().isEmpty()) {
propByRes.addOldAccountId(resource.getName(),
- attribute.getValuesAsStrings().iterator().next());
+ attr.getValuesAsStrings().iterator().next());
}
}
}
@@ -444,9 +594,24 @@ public abstract class AbstractAttributab
LOG.debug("Attributes to be removed:\n{}", propByRes);
// 4. attributes to be updated
- for (AttributeMod attributeMod : attributableMod.getAttributesToBeUpdated()) {
- AbstractSchema schema = getSchema(attributeMod.getSchema(), attrUtil.schemaClass());
+ for (AttributeMod attributeMod : attributableMod.getAttrsToUpdate()) {
+ AbstractNormalSchema schema = getNormalSchema(attributeMod.getSchema(), attrUtil.schemaClass());
+ AbstractAttr attr = null;
if (schema != null) {
+ attr = attributable.getAttr(schema.getName());
+ if (attr == null) {
+ attr = attrUtil.newAttr();
+ setAttrSchema(attributable, attr, schema);
+ if (attr.getSchema() == null) {
+ LOG.debug("Ignoring {} because no valid schema or template was found", attributeMod);
+ } else {
+ attr.setOwner(attributable);
+ attributable.addAttr(attr);
+ }
+ }
+ }
+
+ if (schema != null && attr != null && attr.getSchema() != null) {
for (ExternalResource resource : resourceDAO.findAll()) {
for (AbstractMappingItem mapItem : attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION)) {
if (schema.getName().equals(mapItem.getIntAttrName())
@@ -458,26 +623,18 @@ public abstract class AbstractAttributab
}
}
- AbstractAttr attribute = attributable.getAttribute(schema.getName());
- if (attribute == null) {
- attribute = attrUtil.newAttr();
- attribute.setSchema(schema);
- attribute.setOwner(attributable);
-
- attributable.addAttribute(attribute);
- }
// 1.1 remove values
Set<Long> valuesToBeRemoved = new HashSet<Long>();
for (String valueToBeRemoved : attributeMod.getValuesToBeRemoved()) {
- if (attribute.getSchema().isUniqueConstraint()) {
- if (attribute.getUniqueValue() != null
- && valueToBeRemoved.equals(attribute.getUniqueValue().getValueAsString())) {
+ if (attr.getSchema().isUniqueConstraint()) {
+ if (attr.getUniqueValue() != null
+ && valueToBeRemoved.equals(attr.getUniqueValue().getValueAsString())) {
- valuesToBeRemoved.add(attribute.getUniqueValue().getId());
+ valuesToBeRemoved.add(attr.getUniqueValue().getId());
}
} else {
- for (AbstractAttrValue mav : attribute.getValues()) {
+ for (AbstractAttrValue mav : attr.getValues()) {
if (valueToBeRemoved.equals(mav.getValueAsString())) {
valuesToBeRemoved.add(mav.getId());
}
@@ -491,15 +648,15 @@ public abstract class AbstractAttributab
// 1.2 add values
List<String> valuesToBeAdded = attributeMod.getValuesToBeAdded();
if (valuesToBeAdded != null && !valuesToBeAdded.isEmpty()
- && (!schema.isUniqueConstraint() || attribute.getUniqueValue() == null
- || !valuesToBeAdded.iterator().next().equals(attribute.getUniqueValue().getValueAsString()))) {
+ && (!schema.isUniqueConstraint() || attr.getUniqueValue() == null
+ || !valuesToBeAdded.iterator().next().equals(attr.getUniqueValue().getValueAsString()))) {
- fillAttribute(attributeMod.getValuesToBeAdded(), attrUtil, schema, attribute, invalidValues);
+ fillAttribute(attributeMod.getValuesToBeAdded(), attrUtil, schema, attr, invalidValues);
}
// if no values are in, the attribute can be safely removed
- if (attribute.getValuesAsStrings().isEmpty()) {
- attrDAO.delete(attribute);
+ if (attr.getValuesAsStrings().isEmpty()) {
+ attrDAO.delete(attr);
}
}
}
@@ -511,10 +668,10 @@ public abstract class AbstractAttributab
LOG.debug("Attributes to be updated:\n{}", propByRes);
// 5. derived attributes to be removed
- for (String derAttrToBeRemoved : attributableMod.getDerivedAttributesToBeRemoved()) {
- AbstractDerSchema derSchema = getDerivedSchema(derAttrToBeRemoved, attrUtil.derSchemaClass());
+ for (String derAttrToBeRemoved : attributableMod.getDerAttrsToRemove()) {
+ AbstractDerSchema derSchema = getDerSchema(derAttrToBeRemoved, attrUtil.derSchemaClass());
if (derSchema != null) {
- AbstractDerAttr derAttr = attributable.getDerivedAttribute(derSchema.getName());
+ AbstractDerAttr derAttr = attributable.getDerAttr(derSchema.getName());
if (derAttr == null) {
LOG.debug("No derived attribute found for schema {}", derSchema.getName());
} else {
@@ -530,10 +687,10 @@ public abstract class AbstractAttributab
propByRes.add(ResourceOperation.UPDATE, resource.getName());
if (mapItem.isAccountid() && derAttr != null
- && !derAttr.getValue(attributable.getAttributes()).isEmpty()) {
+ && !derAttr.getValue(attributable.getAttrs()).isEmpty()) {
propByRes.addOldAccountId(resource.getName(),
- derAttr.getValue(attributable.getAttributes()));
+ derAttr.getValue(attributable.getAttrs()));
}
}
}
@@ -544,8 +701,8 @@ public abstract class AbstractAttributab
LOG.debug("Derived attributes to be removed:\n{}", propByRes);
// 6. derived attributes to be added
- for (String derAttrToBeAdded : attributableMod.getDerivedAttributesToBeAdded()) {
- AbstractDerSchema derSchema = getDerivedSchema(derAttrToBeAdded, attrUtil.derSchemaClass());
+ for (String derAttrToBeAdded : attributableMod.getDerAttrsToAdd()) {
+ AbstractDerSchema derSchema = getDerSchema(derAttrToBeAdded, attrUtil.derSchemaClass());
if (derSchema != null) {
for (ExternalResource resource : resourceDAO.findAll()) {
for (AbstractMappingItem mapItem : attrUtil.getMappingItems(resource, MappingPurpose.PROPAGATION)) {
@@ -559,9 +716,13 @@ public abstract class AbstractAttributab
}
AbstractDerAttr derAttr = attrUtil.newDerAttr();
- derAttr.setDerivedSchema(derSchema);
- derAttr.setOwner(attributable);
- attributable.addDerivedAttribute(derAttr);
+ setDerAttrSchema(attributable, derAttr, derSchema);
+ if (derAttr.getSchema() == null) {
+ LOG.debug("Ignoring {} because no valid schema or template was found", derAttrToBeAdded);
+ } else {
+ derAttr.setOwner(attributable);
+ attributable.addDerAttr(derAttr);
+ }
}
}
@@ -569,8 +730,8 @@ public abstract class AbstractAttributab
// 7. virtual attributes: for users and roles this is delegated to PropagationManager
if (AttributableType.USER != attrUtil.getType() && AttributableType.ROLE != attrUtil.getType()) {
- fillVirtual(attributable, attributableMod.getVirtualAttributesToBeRemoved(),
- attributableMod.getVirtualAttributesToBeUpdated(), attrUtil);
+ fillVirtual(attributable, attributableMod.getVirAttrsToRemove(),
+ attributableMod.getVirAttrsToUpdate(), attrUtil);
}
// Finally, check if mandatory values are missing
@@ -598,15 +759,19 @@ public abstract class AbstractAttributab
final AttributableUtil attrUtil) {
for (AttributeTO attributeTO : vAttrs) {
- AbstractVirAttr virAttr = attributable.getVirtualAttribute(attributeTO.getSchema());
+ AbstractVirAttr virAttr = attributable.getVirAttr(attributeTO.getSchema());
if (virAttr == null) {
- AbstractVirSchema virSchema = getVirtualSchema(attributeTO.getSchema(), attrUtil.virSchemaClass());
+ AbstractVirSchema virSchema = getVirSchema(attributeTO.getSchema(), attrUtil.virSchemaClass());
if (virSchema != null) {
virAttr = attrUtil.newVirAttr();
- virAttr.setVirtualSchema(virSchema);
- virAttr.setOwner(attributable);
- attributable.addVirtualAttribute(virAttr);
- virAttr.setValues(attributeTO.getValues());
+ setVirAttrSchema(attributable, virAttr, virSchema);
+ if (virAttr.getSchema() == null) {
+ LOG.debug("Ignoring {} because no valid schema or template was found", attributeTO);
+ } else {
+ virAttr.setOwner(attributable);
+ attributable.addVirAttr(virAttr);
+ virAttr.setValues(attributeTO.getValues());
+ }
}
} else {
virAttr.setValues(attributeTO.getValues());
@@ -620,27 +785,26 @@ public abstract class AbstractAttributab
// 1. attributes
SyncopeClientException invalidValues = new SyncopeClientException(SyncopeClientExceptionType.InvalidValues);
- AbstractSchema schema;
- AbstractAttr attribute;
-
// Only consider attributeTO with values
- for (AttributeTO attributeTO : attributableTO.getAttributes()) {
+ for (AttributeTO attributeTO : attributableTO.getAttrs()) {
if (attributeTO.getValues() != null && !attributeTO.getValues().isEmpty()) {
-
- schema = getSchema(attributeTO.getSchema(), attributableUtil.schemaClass());
+ AbstractNormalSchema schema = getNormalSchema(attributeTO.getSchema(), attributableUtil.schemaClass());
if (schema != null) {
- attribute = attributable.getAttribute(schema.getName());
- if (attribute == null) {
- attribute = attributableUtil.newAttr();
- attribute.setSchema(schema);
+ AbstractAttr attr = attributable.getAttr(schema.getName());
+ if (attr == null) {
+ attr = attributableUtil.newAttr();
+ setAttrSchema(attributable, attr, schema);
}
+ if (attr.getSchema() == null) {
+ LOG.debug("Ignoring {} because no valid schema or template was found", attributeTO);
+ } else {
+ fillAttribute(attributeTO.getValues(), attributableUtil, schema, attr, invalidValues);
- fillAttribute(attributeTO.getValues(), attributableUtil, schema, attribute, invalidValues);
-
- if (!attribute.getValuesAsStrings().isEmpty()) {
- attributable.addAttribute(attribute);
- attribute.setOwner(attributable);
+ if (!attr.getValuesAsStrings().isEmpty()) {
+ attributable.addAttr(attr);
+ attr.setOwner(attributable);
+ }
}
}
}
@@ -651,17 +815,18 @@ public abstract class AbstractAttributab
}
// 2. derived attributes
- AbstractDerSchema derivedSchema;
- AbstractDerAttr derivedAttribute;
- for (AttributeTO attributeTO : attributableTO.getDerivedAttributes()) {
-
- derivedSchema = getDerivedSchema(attributeTO.getSchema(), attributableUtil.derSchemaClass());
-
- if (derivedSchema != null) {
- derivedAttribute = attributableUtil.newDerAttr();
- derivedAttribute.setDerivedSchema(derivedSchema);
- derivedAttribute.setOwner(attributable);
- attributable.addDerivedAttribute(derivedAttribute);
+ for (AttributeTO attributeTO : attributableTO.getDerAttrs()) {
+ AbstractDerSchema derSchema = getDerSchema(attributeTO.getSchema(), attributableUtil.derSchemaClass());
+
+ if (derSchema != null) {
+ AbstractDerAttr derAttr = attributableUtil.newDerAttr();
+ setDerAttrSchema(attributable, derAttr, derSchema);
+ if (derAttr.getSchema() == null) {
+ LOG.debug("Ignoring {} because no valid schema or template was found", attributeTO);
+ } else {
+ derAttr.setOwner(attributable);
+ attributable.addDerAttr(derAttr);
+ }
}
}
@@ -669,24 +834,27 @@ public abstract class AbstractAttributab
if (AttributableType.USER == attributableUtil.getType()
|| AttributableType.ROLE == attributableUtil.getType()) {
- for (AttributeTO vattrTO : attributableTO.getVirtualAttributes()) {
- AbstractVirSchema uVirSchema = getVirtualSchema(vattrTO.getSchema(), attributableUtil.virSchemaClass());
+ for (AttributeTO vattrTO : attributableTO.getVirAttrs()) {
+ AbstractVirSchema virSchema = getVirSchema(vattrTO.getSchema(), attributableUtil.virSchemaClass());
- if (uVirSchema != null) {
- AbstractVirAttr vattr = attributableUtil.newVirAttr();
- vattr.setVirtualSchema(uVirSchema);
- vattr.setOwner(attributable);
- attributable.addVirtualAttribute(vattr);
+ if (virSchema != null) {
+ AbstractVirAttr virAttr = attributableUtil.newVirAttr();
+ setVirAttrSchema(attributable, virAttr, virSchema);
+ if (virAttr.getSchema() == null) {
+ LOG.debug("Ignoring {} because no valid schema or template was found", vattrTO);
+ } else {
+ virAttr.setOwner(attributable);
+ attributable.addVirAttr(virAttr);
+ }
}
}
}
- fillVirtual(attributable, attributableTO.getVirtualAttributes(), attributableUtil);
+ fillVirtual(attributable, attributableTO.getVirAttrs(), attributableUtil);
// 4. resources
- ExternalResource resource;
for (String resourceName : attributableTO.getResources()) {
- resource = getResource(resourceName);
+ ExternalResource resource = getResource(resourceName);
if (resource != null) {
attributable.addResource(resource);
@@ -698,49 +866,48 @@ public abstract class AbstractAttributab
scce.addException(requiredValuesMissing);
}
- // Throw composite exception if there is at least one element set
- // in the composing exceptions
+ // Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
}
- protected void fillTO(final AbstractAttributableTO abstractAttributableTO,
- final Collection<? extends AbstractAttr> attributes,
- final Collection<? extends AbstractDerAttr> derivedAttributes,
- final Collection<? extends AbstractVirAttr> virtualAttributes,
+ protected void fillTO(final AbstractAttributableTO attributableTO,
+ final Collection<? extends AbstractAttr> attrs,
+ final Collection<? extends AbstractDerAttr> derAttrs,
+ final Collection<? extends AbstractVirAttr> virAttrs,
final Collection<ExternalResource> resources) {
AttributeTO attributeTO;
- for (AbstractAttr attribute : attributes) {
+ for (AbstractAttr attr : attrs) {
attributeTO = new AttributeTO();
- attributeTO.setSchema(attribute.getSchema().getName());
- attributeTO.getValues().addAll(attribute.getValuesAsStrings());
- attributeTO.setReadonly(attribute.getSchema().isReadonly());
+ attributeTO.setSchema(attr.getSchema().getName());
+ attributeTO.getValues().addAll(attr.getValuesAsStrings());
+ attributeTO.setReadonly(attr.getSchema().isReadonly());
- abstractAttributableTO.getAttributes().add(attributeTO);
+ attributableTO.getAttrs().add(attributeTO);
}
- for (AbstractDerAttr derivedAttribute : derivedAttributes) {
+ for (AbstractDerAttr derAttr : derAttrs) {
attributeTO = new AttributeTO();
- attributeTO.setSchema(derivedAttribute.getDerivedSchema().getName());
- attributeTO.getValues().add(derivedAttribute.getValue(attributes));
+ attributeTO.setSchema(derAttr.getSchema().getName());
+ attributeTO.getValues().add(derAttr.getValue(attrs));
attributeTO.setReadonly(true);
- abstractAttributableTO.getDerivedAttributes().add(attributeTO);
+ attributableTO.getDerAttrs().add(attributeTO);
}
- for (AbstractVirAttr virtualAttribute : virtualAttributes) {
+ for (AbstractVirAttr virAttr : virAttrs) {
attributeTO = new AttributeTO();
- attributeTO.setSchema(virtualAttribute.getVirtualSchema().getName());
- attributeTO.getValues().addAll(virtualAttribute.getValues());
- attributeTO.setReadonly(virtualAttribute.getVirtualSchema().isReadonly());
+ attributeTO.setSchema(virAttr.getSchema().getName());
+ attributeTO.getValues().addAll(virAttr.getValues());
+ attributeTO.setReadonly(virAttr.getSchema().isReadonly());
- abstractAttributableTO.getVirtualAttributes().add(attributeTO);
+ attributableTO.getVirAttrs().add(attributeTO);
}
for (ExternalResource resource : resources) {
- abstractAttributableTO.getResources().add(resource.getName());
+ attributableTO.getResources().add(resource.getName());
}
}
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java Thu Oct 10 14:37:56 2013
@@ -18,9 +18,6 @@
*/
package org.apache.syncope.core.rest.data;
-import static org.apache.syncope.common.types.PolicyType.GLOBAL_ACCOUNT;
-import static org.apache.syncope.common.types.PolicyType.GLOBAL_PASSWORD;
-import static org.apache.syncope.common.types.PolicyType.GLOBAL_SYNC;
import org.apache.syncope.common.to.AccountPolicyTO;
import org.apache.syncope.common.to.PasswordPolicyTO;
import org.apache.syncope.common.to.AbstractPolicyTO;
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java Thu Oct 10 14:37:56 2013
@@ -31,14 +31,28 @@ import org.apache.syncope.common.types.S
import org.apache.syncope.common.validation.SyncopeClientCompositeException;
import org.apache.syncope.common.validation.SyncopeClientException;
import org.apache.syncope.core.connid.ConnObjectUtil;
+import org.apache.syncope.core.persistence.beans.AbstractAttrTemplate;
+import org.apache.syncope.core.persistence.beans.AbstractSchema;
import org.apache.syncope.core.persistence.beans.AccountPolicy;
import org.apache.syncope.core.persistence.beans.Entitlement;
import org.apache.syncope.core.persistence.beans.ExternalResource;
import org.apache.syncope.core.persistence.beans.PasswordPolicy;
+import org.apache.syncope.core.persistence.beans.membership.MAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.MDerAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.MDerSchema;
+import org.apache.syncope.core.persistence.beans.membership.MSchema;
+import org.apache.syncope.core.persistence.beans.membership.MVirAttrTemplate;
+import org.apache.syncope.core.persistence.beans.membership.MVirSchema;
import org.apache.syncope.core.persistence.beans.membership.Membership;
import org.apache.syncope.core.persistence.beans.role.RAttr;
+import org.apache.syncope.core.persistence.beans.role.RAttrTemplate;
import org.apache.syncope.core.persistence.beans.role.RDerAttr;
+import org.apache.syncope.core.persistence.beans.role.RDerAttrTemplate;
+import org.apache.syncope.core.persistence.beans.role.RDerSchema;
+import org.apache.syncope.core.persistence.beans.role.RSchema;
import org.apache.syncope.core.persistence.beans.role.RVirAttr;
+import org.apache.syncope.core.persistence.beans.role.RVirAttrTemplate;
+import org.apache.syncope.core.persistence.beans.role.RVirSchema;
import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
import org.apache.syncope.core.persistence.dao.EntitlementDAO;
@@ -104,12 +118,43 @@ public class RoleDataBinder extends Abst
return result;
}
+ private <T extends AbstractAttrTemplate<K>, K extends AbstractSchema> void setAttrTemplates(
+ final SyncopeRole role, final List<String> schemaNames,
+ final Class<T> templateClass, final Class<K> schemaClass) {
+
+ List<T> toRemove = new ArrayList<T>();
+ for (T template : role.getAttrTemplates(templateClass)) {
+ if (!schemaNames.contains(template.getSchema().getName())) {
+ toRemove.add(template);
+ }
+ }
+ role.getAttrTemplates(templateClass).removeAll(toRemove);
+
+ for (String schemaName : schemaNames) {
+ if (role.getAttrTemplate(templateClass, schemaName) == null) {
+ K schema = getSchema(schemaName, schemaClass);
+ if (schema != null) {
+ try {
+ T template = templateClass.newInstance();
+ template.setSchema(schema);
+ template.setOwner(role);
+ role.getAttrTemplates(templateClass).add(template);
+ } catch (Exception e) {
+ LOG.error("Could not create template for {}", templateClass, e);
+ }
+ }
+ }
+ }
+ }
+
public SyncopeRole create(final SyncopeRole role, final RoleTO roleTO) {
role.setInheritOwner(roleTO.isInheritOwner());
- role.setInheritAttributes(roleTO.isInheritAttributes());
- role.setInheritDerivedAttributes(roleTO.isInheritDerivedAttributes());
- role.setInheritVirtualAttributes(roleTO.isInheritVirtualAttributes());
+ role.setInheritAttrs(roleTO.isInheritAttrs());
+ role.setInheritDerAttrs(roleTO.isInheritDerAttrs());
+ role.setInheritVirAttrs(roleTO.isInheritVirAttrs());
+
+ role.setInheritTemplates(roleTO.isInheritTemplates());
role.setInheritPasswordPolicy(roleTO.isInheritPasswordPolicy());
role.setInheritAccountPolicy(roleTO.isInheritAccountPolicy());
@@ -147,13 +192,20 @@ public class RoleDataBinder extends Abst
invalidRoles.addElement(roleTO.getName());
}
+ // attribute templates
+ setAttrTemplates(role, roleTO.getRAttrTemplates(), RAttrTemplate.class, RSchema.class);
+ setAttrTemplates(role, roleTO.getRDerAttrTemplates(), RDerAttrTemplate.class, RDerSchema.class);
+ setAttrTemplates(role, roleTO.getRVirAttrTemplates(), RVirAttrTemplate.class, RVirSchema.class);
+ setAttrTemplates(role, roleTO.getMAttrTemplates(), MAttrTemplate.class, MSchema.class);
+ setAttrTemplates(role, roleTO.getMDerAttrTemplates(), MDerAttrTemplate.class, MDerSchema.class);
+ setAttrTemplates(role, roleTO.getMVirAttrTemplates(), MVirAttrTemplate.class, MVirSchema.class);
+
// attributes, derived attributes, virtual attributes and resources
fill(role, roleTO, AttributableUtil.getInstance(AttributableType.ROLE), scce);
// entitlements
- Entitlement entitlement;
for (String entitlementName : roleTO.getEntitlements()) {
- entitlement = entitlementDAO.find(entitlementName);
+ Entitlement entitlement = entitlementDAO.find(entitlementName);
if (entitlement == null) {
LOG.warn("Ignoring invalid entitlement {}", entitlementName);
} else {
@@ -224,14 +276,18 @@ public class RoleDataBinder extends Abst
role.setInheritOwner(roleMod.getInheritOwner());
}
- if (roleMod.getInheritAttributes() != null) {
- role.setInheritAttributes(roleMod.getInheritAttributes());
+ if (roleMod.getInheritTemplates() != null) {
+ role.setInheritTemplates(roleMod.getInheritTemplates());
}
- if (roleMod.getInheritDerivedAttributes() != null) {
- role.setInheritDerivedAttributes(roleMod.getInheritDerivedAttributes());
+
+ if (roleMod.getInheritAttrs() != null) {
+ role.setInheritAttrs(roleMod.getInheritAttrs());
+ }
+ if (roleMod.getInheritDerAttrs() != null) {
+ role.setInheritDerAttrs(roleMod.getInheritDerAttrs());
}
- if (roleMod.getInheritVirtualAttributes() != null) {
- role.setInheritVirtualAttributes(roleMod.getInheritVirtualAttributes());
+ if (roleMod.getInheritVirAttrs() != null) {
+ role.setInheritVirAttrs(roleMod.getInheritVirAttrs());
}
if (roleMod.getInheritPasswordPolicy() != null) {
@@ -254,6 +310,26 @@ public class RoleDataBinder extends Abst
}
}
+ // attribute templates
+ if (roleMod.isModRAttrTemplates()) {
+ setAttrTemplates(role, roleMod.getRAttrTemplates(), RAttrTemplate.class, RSchema.class);
+ }
+ if (roleMod.isModRDerAttrTemplates()) {
+ setAttrTemplates(role, roleMod.getRDerAttrTemplates(), RDerAttrTemplate.class, RDerSchema.class);
+ }
+ if (roleMod.isModRVirAttrTemplates()) {
+ setAttrTemplates(role, roleMod.getRVirAttrTemplates(), RVirAttrTemplate.class, RVirSchema.class);
+ }
+ if (roleMod.isModMAttrTemplates()) {
+ setAttrTemplates(role, roleMod.getMAttrTemplates(), MAttrTemplate.class, MSchema.class);
+ }
+ if (roleMod.isModMDerAttrTemplates()) {
+ setAttrTemplates(role, roleMod.getMDerAttrTemplates(), MDerAttrTemplate.class, MDerSchema.class);
+ }
+ if (roleMod.isModMVirAttrTemplates()) {
+ setAttrTemplates(role, roleMod.getMVirAttrTemplates(), MVirAttrTemplate.class, MVirSchema.class);
+ }
+
// policies
if (roleMod.getPasswordPolicy() != null) {
role.setPasswordPolicy(roleMod.getPasswordPolicy().getId() == null
@@ -302,9 +378,11 @@ public class RoleDataBinder extends Abst
roleTO.setInheritOwner(role.isInheritOwner());
- roleTO.setInheritAttributes(role.isInheritAttributes());
- roleTO.setInheritDerivedAttributes(role.isInheritDerivedAttributes());
- roleTO.setInheritVirtualAttributes(role.isInheritVirtualAttributes());
+ roleTO.setInheritTemplates(role.isInheritTemplates());
+
+ roleTO.setInheritAttrs(role.isInheritAttrs());
+ roleTO.setInheritDerAttrs(role.isInheritDerAttrs());
+ roleTO.setInheritVirAttrs(role.isInheritVirAttrs());
roleTO.setInheritPasswordPolicy(role.isInheritPasswordPolicy());
roleTO.setInheritAccountPolicy(role.isInheritAccountPolicy());
@@ -323,14 +401,14 @@ public class RoleDataBinder extends Abst
// -------------------------
// Retrieve all [derived/virtual] attributes (inherited and not)
// -------------------------
- final List<RAttr> allAttributes = role.findInheritedAttributes();
- allAttributes.addAll((List<RAttr>) role.getAttributes());
+ final List<RAttr> allAttributes = role.findInheritedAttrs();
+ allAttributes.addAll((List<RAttr>) role.getAttrs());
- final List<RDerAttr> allDerAttributes = role.findInheritedDerivedAttributes();
- allDerAttributes.addAll((List<RDerAttr>) role.getDerivedAttributes());
+ final List<RDerAttr> allDerAttributes = role.findInheritedDerAttrs();
+ allDerAttributes.addAll((List<RDerAttr>) role.getDerAttrs());
- final List<RVirAttr> allVirAttributes = role.findInheritedVirtualAttributes();
- allVirAttributes.addAll((List<RVirAttr>) role.getVirtualAttributes());
+ final List<RVirAttr> allVirAttributes = role.findInheritedVirAttrs();
+ allVirAttributes.addAll((List<RVirAttr>) role.getVirAttrs());
// -------------------------
fillTO(roleTO, allAttributes, allDerAttributes, allVirAttributes, role.getResources());
@@ -339,6 +417,25 @@ public class RoleDataBinder extends Abst
roleTO.getEntitlements().add(entitlement.getName());
}
+ for (RAttrTemplate template : role.findInheritedTemplates(RAttrTemplate.class)) {
+ roleTO.getRAttrTemplates().add(template.getSchema().getName());
+ }
+ for (RDerAttrTemplate template : role.findInheritedTemplates(RDerAttrTemplate.class)) {
+ roleTO.getRDerAttrTemplates().add(template.getSchema().getName());
+ }
+ for (RVirAttrTemplate template : role.findInheritedTemplates(RVirAttrTemplate.class)) {
+ roleTO.getRVirAttrTemplates().add(template.getSchema().getName());
+ }
+ for (MAttrTemplate template : role.findInheritedTemplates(MAttrTemplate.class)) {
+ roleTO.getMAttrTemplates().add(template.getSchema().getName());
+ }
+ for (MDerAttrTemplate template : role.findInheritedTemplates(MDerAttrTemplate.class)) {
+ roleTO.getMDerAttrTemplates().add(template.getSchema().getName());
+ }
+ for (MVirAttrTemplate template : role.findInheritedTemplates(MVirAttrTemplate.class)) {
+ roleTO.getMVirAttrTemplates().add(template.getSchema().getName());
+ }
+
roleTO.setPasswordPolicy(role.getPasswordPolicy() == null
? null
: role.getPasswordPolicy().getId());
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=1531003&r1=1531002&r2=1531003&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 Thu Oct 10 14:37:56 2013
@@ -30,7 +30,7 @@ import org.apache.syncope.common.validat
import org.apache.syncope.common.validation.SyncopeClientException;
import org.apache.syncope.core.persistence.beans.AbstractAttr;
import org.apache.syncope.core.persistence.beans.AbstractDerSchema;
-import org.apache.syncope.core.persistence.beans.AbstractSchema;
+import org.apache.syncope.core.persistence.beans.AbstractNormalSchema;
import org.apache.syncope.core.persistence.beans.AbstractVirSchema;
import org.apache.syncope.core.persistence.dao.SchemaDAO;
import org.apache.syncope.core.util.AttributableUtil;
@@ -48,7 +48,7 @@ public class SchemaDataBinder {
private JexlUtil jexlUtil;
// --------------- NORMAL -----------------
- private <T extends AbstractSchema> void fill(final T schema, final SchemaTO schemaTO) {
+ private <T extends AbstractNormalSchema> void fill(final T schema, final SchemaTO schemaTO) {
if (!jexlUtil.isExpressionValid(schemaTO.getMandatoryCondition())) {
SyncopeClientCompositeException scce =
new SyncopeClientCompositeException(Response.Status.BAD_REQUEST.getStatusCode());
@@ -64,17 +64,17 @@ public class SchemaDataBinder {
BeanUtils.copyProperties(schemaTO, schema);
}
- public <T extends AbstractSchema> void create(final SchemaTO schemaTO, final T schema) {
+ public <T extends AbstractNormalSchema> void create(final SchemaTO schemaTO, final T schema) {
fill(schema, schemaTO);
}
- public <T extends AbstractSchema> void update(final SchemaTO schemaTO, final T schema,
+ public <T extends AbstractNormalSchema> void update(final SchemaTO schemaTO, final T schema,
final AttributableUtil attributableUtil) {
SyncopeClientCompositeException scce =
new SyncopeClientCompositeException(Response.Status.BAD_REQUEST.getStatusCode());
- List<AbstractAttr> attrs = schemaDAO.getAttributes(schema, attributableUtil.attrClass());
+ List<AbstractAttr> attrs = schemaDAO.findAttrs(schema, attributableUtil.attrClass());
if (!attrs.isEmpty()) {
if (schema.getType() != schemaTO.getType()) {
SyncopeClientException e = new SyncopeClientException(SyncopeClientExceptionType.valueOf("Invalid"
@@ -99,7 +99,7 @@ public class SchemaDataBinder {
fill(schema, schemaTO);
}
- public <T extends AbstractSchema> SchemaTO getSchemaTO(final T schema, final AttributableUtil attributableUtil) {
+ public <T extends AbstractNormalSchema> SchemaTO getSchemaTO(final T schema, final AttributableUtil attributableUtil) {
SchemaTO schemaTO = new SchemaTO();
BeanUtils.copyProperties(schema, schemaTO);
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/TaskDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/TaskDataBinder.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/TaskDataBinder.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/TaskDataBinder.java Thu Oct 10 14:37:56 2013
@@ -82,12 +82,12 @@ public class TaskDataBinder {
private JexlUtil jexlUtil;
private void checkJexl(final AbstractAttributableTO attributableTO, final SyncopeClientException sce) {
- for (AttributeTO attrTO : attributableTO.getAttributes()) {
+ for (AttributeTO attrTO : attributableTO.getAttrs()) {
if (!attrTO.getValues().isEmpty() && !jexlUtil.isExpressionValid(attrTO.getValues().get(0))) {
sce.addElement("Invalid JEXL: " + attrTO.getValues().get(0));
}
}
- for (AttributeTO attrTO : attributableTO.getVirtualAttributes()) {
+ for (AttributeTO attrTO : attributableTO.getVirAttrs()) {
if (!attrTO.getValues().isEmpty() && !jexlUtil.isExpressionValid(attrTO.getValues().get(0))) {
sce.addElement("Invalid JEXL: " + attrTO.getValues().get(0));
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java Thu Oct 10 14:37:56 2013
@@ -66,7 +66,7 @@ import org.springframework.transaction.a
public class UserDataBinder extends AbstractAttributableDataBinder {
private static final String[] IGNORE_USER_PROPERTIES = {
- "memberships", "attributes", "derivedAttributes", "virtualAttributes", "resources"};
+ "memberships", "attrs", "derAttrs", "virAttrs", "resources"};
@Autowired
private ConnObjectUtil connObjectUtil;
@@ -272,7 +272,7 @@ public class UserDataBinder extends Abst
// store the role ids of membership required to be added
Set<Long> membershipToBeAddedRoleIds = new HashSet<Long>();
- for (MembershipMod membToBeAdded : userMod.getMembershipsToBeAdded()) {
+ for (MembershipMod membToBeAdded : userMod.getMembershipsToAdd()) {
membershipToBeAddedRoleIds.add(membToBeAdded.getRole());
}
@@ -280,7 +280,7 @@ public class UserDataBinder extends Abst
final Set<String> toBeProvisioned = new HashSet<String>();
// memberships to be removed
- for (Long membershipId : userMod.getMembershipsToBeRemoved()) {
+ for (Long membershipId : userMod.getMembershipsToRemove()) {
LOG.debug("Membership to be removed: {}", membershipId);
Membership membership = membershipDAO.find(membershipId);
@@ -299,8 +299,8 @@ public class UserDataBinder extends Abst
membership = user.getMembership(membership.getSyncopeRole().getId());
if (membershipToBeAddedRoleIds.contains(membership.getSyncopeRole().getId())) {
- Set<Long> attributeIds = new HashSet<Long>(membership.getAttributes().size());
- for (AbstractAttr attribute : membership.getAttributes()) {
+ Set<Long> attributeIds = new HashSet<Long>(membership.getAttrs().size());
+ for (AbstractAttr attribute : membership.getAttrs()) {
attributeIds.add(attribute.getId());
}
for (Long attributeId : attributeIds) {
@@ -309,7 +309,7 @@ public class UserDataBinder extends Abst
attributeIds.clear();
// remove derived attributes
- for (AbstractDerAttr derAttr : membership.getDerivedAttributes()) {
+ for (AbstractDerAttr derAttr : membership.getDerAttrs()) {
attributeIds.add(derAttr.getId());
}
@@ -319,7 +319,7 @@ public class UserDataBinder extends Abst
attributeIds.clear();
// remove virtual attributes
- for (AbstractVirAttr virAttr : membership.getVirtualAttributes()) {
+ for (AbstractVirAttr virAttr : membership.getVirAttrs()) {
attributeIds.add(virAttr.getId());
}
for (Long virAttrId : attributeIds) {
@@ -335,7 +335,7 @@ public class UserDataBinder extends Abst
}
// memberships to be added
- for (MembershipMod membershipMod : userMod.getMembershipsToBeAdded()) {
+ for (MembershipMod membershipMod : userMod.getMembershipsToAdd()) {
LOG.debug("Membership to be added: role({})", membershipMod.getRole());
SyncopeRole role = roleDAO.find(membershipMod.getRole());
@@ -381,8 +381,7 @@ public class UserDataBinder extends Abst
connObjectUtil.retrieveVirAttrValues(user, AttributableUtil.getInstance(AttributableType.USER));
- fillTO(userTO, user.getAttributes(), user.getDerivedAttributes(), user.getVirtualAttributes(),
- user.getResources());
+ fillTO(userTO, user.getAttrs(), user.getDerAttrs(), user.getVirAttrs(), user.getResources());
MembershipTO membershipTO;
for (Membership membership : user.getMemberships()) {
@@ -398,8 +397,9 @@ public class UserDataBinder extends Abst
membershipTO.setRoleId(membership.getSyncopeRole().getId());
membershipTO.setRoleName(membership.getSyncopeRole().getName());
- fillTO(membershipTO, membership.getAttributes(), membership.getDerivedAttributes(), membership.
- getVirtualAttributes(), membership.getResources());
+ fillTO(membershipTO,
+ membership.getAttrs(), membership.getDerAttrs(), membership.getVirAttrs(),
+ membership.getResources());
userTO.getMemberships().add(membershipTO);
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java Thu Oct 10 14:37:56 2013
@@ -152,7 +152,7 @@ public class LDAPMembershipSyncActions e
MembershipMod membershipMod = new MembershipMod();
membershipMod.setRole(roleTO.getId());
- userMod.getMembershipsToBeAdded().add(membershipMod);
+ userMod.getMembershipsToAdd().add(membershipMod);
}
return userMod;
@@ -201,8 +201,8 @@ public class LDAPMembershipSyncActions e
WorkflowResult<Map.Entry<Long, Boolean>> updated = uwfAdapter.update(userMod);
List<PropagationTask> tasks = propagationManager.getUserUpdateTaskIds(updated,
- userMod.getPassword(), userMod.getVirtualAttributesToBeRemoved(),
- userMod.getVirtualAttributesToBeUpdated(),
+ userMod.getPassword(), userMod.getVirAttrsToRemove(),
+ userMod.getVirAttrsToUpdate(),
Collections.singleton(resourceName));
taskExecutor.execute(tasks);
@@ -242,7 +242,7 @@ public class LDAPMembershipSyncActions e
for (Map.Entry<Long, Long> member : membersBeforeRoleUpdate.entrySet()) {
UserMod userMod = new UserMod();
userMod.setId(member.getKey());
- userMod.getMembershipsToBeRemoved().add(member.getValue());
+ userMod.getMembershipsToRemove().add(member.getValue());
userUpdate(userMod, resource.getName());
}
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java Thu Oct 10 14:37:56 2013
@@ -48,7 +48,7 @@ import org.apache.syncope.core.notificat
import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
import org.apache.syncope.core.persistence.beans.AbstractAttributable;
import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
-import org.apache.syncope.core.persistence.beans.AbstractSchema;
+import org.apache.syncope.core.persistence.beans.AbstractNormalSchema;
import org.apache.syncope.core.persistence.beans.PropagationTask;
import org.apache.syncope.core.persistence.beans.SyncPolicy;
import org.apache.syncope.core.persistence.beans.SyncTask;
@@ -276,7 +276,7 @@ public class SyncopeSyncResultHandler im
case RoleSchema:
final AbstractAttrValue value = attrUtil.newAttrValue();
- AbstractSchema schema = schemaDAO.find(accountIdItem.getIntAttrName(), attrUtil.schemaClass());
+ AbstractNormalSchema schema = schemaDAO.find(accountIdItem.getIntAttrName(), attrUtil.schemaClass());
if (schema == null) {
value.setStringValue(uid);
} else {
@@ -534,7 +534,7 @@ public class SyncopeSyncResultHandler im
uwfAdapter.create((UserTO) subjectTO, true, enabled);
List<PropagationTask> tasks = propagationManager.getUserCreateTaskIds(created,
- ((UserTO) subjectTO).getPassword(), subjectTO.getVirtualAttributes(),
+ ((UserTO) subjectTO).getPassword(), subjectTO.getVirAttrs(),
Collections.singleton(syncTask.getResource().getName()));
taskExecutor.execute(tasks);
@@ -548,7 +548,7 @@ public class SyncopeSyncResultHandler im
}
if (AttributableType.ROLE == attrUtil.getType()) {
WorkflowResult<Long> created = rwfAdapter.create((RoleTO) subjectTO);
- AttributeTO roleOwner = subjectTO.getAttributeMap().get(StringUtils.EMPTY);
+ AttributeTO roleOwner = subjectTO.getAttrMap().get(StringUtils.EMPTY);
if (roleOwner != null) {
roleOwnerMap.put(created.getResult(), roleOwner.getValues().iterator().next());
}
@@ -556,7 +556,7 @@ public class SyncopeSyncResultHandler im
EntitlementUtil.extendAuthContext(created.getResult());
List<PropagationTask> tasks = propagationManager.getRoleCreateTaskIds(created,
- subjectTO.getVirtualAttributes(), Collections.singleton(syncTask.getResource().getName()));
+ subjectTO.getVirAttrs(), Collections.singleton(syncTask.getResource().getName()));
taskExecutor.execute(tasks);
@@ -632,8 +632,8 @@ public class SyncopeSyncResultHandler im
List<PropagationTask> tasks = propagationManager.getUserUpdateTaskIds(updated,
userMod.getPassword(),
- userMod.getVirtualAttributesToBeRemoved(),
- userMod.getVirtualAttributesToBeUpdated(),
+ userMod.getVirAttrsToRemove(),
+ userMod.getVirAttrsToUpdate(),
Collections.singleton(syncTask.getResource().getName()));
taskExecutor.execute(tasks);
@@ -662,7 +662,7 @@ public class SyncopeSyncResultHandler im
WorkflowResult<Long> updated = rwfAdapter.update(roleMod);
String roleOwner = null;
- for (AttributeMod attrMod : roleMod.getAttributesToBeUpdated()) {
+ for (AttributeMod attrMod : roleMod.getAttrsToUpdate()) {
if (attrMod.getSchema().isEmpty()) {
roleOwner = attrMod.getValuesToBeAdded().iterator().next();
}
@@ -672,8 +672,8 @@ public class SyncopeSyncResultHandler im
}
List<PropagationTask> tasks = propagationManager.getRoleUpdateTaskIds(updated,
- roleMod.getVirtualAttributesToBeRemoved(),
- roleMod.getVirtualAttributesToBeUpdated(),
+ roleMod.getVirAttrsToRemove(),
+ roleMod.getVirAttrsToUpdate(),
Collections.singleton(syncTask.getResource().getName()));
taskExecutor.execute(tasks);
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/AttributableUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/AttributableUtil.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/AttributableUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/AttributableUtil.java Thu Oct 10 14:37:56 2013
@@ -31,32 +31,39 @@ import org.apache.syncope.common.types.I
import org.apache.syncope.common.types.MappingPurpose;
import org.apache.syncope.common.types.SyncPolicySpec;
import org.apache.syncope.core.persistence.beans.AbstractAttr;
+import org.apache.syncope.core.persistence.beans.AbstractAttrTemplate;
import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
import org.apache.syncope.core.persistence.beans.AbstractAttributable;
import org.apache.syncope.core.persistence.beans.AbstractDerAttr;
import org.apache.syncope.core.persistence.beans.AbstractDerSchema;
import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
-import org.apache.syncope.core.persistence.beans.AbstractSchema;
+import org.apache.syncope.core.persistence.beans.AbstractNormalSchema;
import org.apache.syncope.core.persistence.beans.AbstractVirAttr;
import org.apache.syncope.core.persistence.beans.AbstractVirSchema;
import org.apache.syncope.core.persistence.beans.ExternalResource;
import org.apache.syncope.core.persistence.beans.membership.MAttr;
+import org.apache.syncope.core.persistence.beans.membership.MAttrTemplate;
import org.apache.syncope.core.persistence.beans.membership.MAttrUniqueValue;
import org.apache.syncope.core.persistence.beans.membership.MAttrValue;
import org.apache.syncope.core.persistence.beans.membership.MDerAttr;
+import org.apache.syncope.core.persistence.beans.membership.MDerAttrTemplate;
import org.apache.syncope.core.persistence.beans.membership.MDerSchema;
import org.apache.syncope.core.persistence.beans.membership.MSchema;
import org.apache.syncope.core.persistence.beans.membership.MVirAttr;
+import org.apache.syncope.core.persistence.beans.membership.MVirAttrTemplate;
import org.apache.syncope.core.persistence.beans.membership.MVirSchema;
import org.apache.syncope.core.persistence.beans.membership.Membership;
import org.apache.syncope.core.persistence.beans.role.RAttr;
+import org.apache.syncope.core.persistence.beans.role.RAttrTemplate;
import org.apache.syncope.core.persistence.beans.role.RAttrUniqueValue;
import org.apache.syncope.core.persistence.beans.role.RAttrValue;
import org.apache.syncope.core.persistence.beans.role.RDerAttr;
+import org.apache.syncope.core.persistence.beans.role.RDerAttrTemplate;
import org.apache.syncope.core.persistence.beans.role.RDerSchema;
import org.apache.syncope.core.persistence.beans.role.RMappingItem;
import org.apache.syncope.core.persistence.beans.role.RSchema;
import org.apache.syncope.core.persistence.beans.role.RVirAttr;
+import org.apache.syncope.core.persistence.beans.role.RVirAttrTemplate;
import org.apache.syncope.core.persistence.beans.role.RVirSchema;
import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
@@ -322,7 +329,7 @@ public final class AttributableUtil {
return result;
}
- public <T extends AbstractSchema> Class<T> schemaClass() {
+ public <T extends AbstractNormalSchema> Class<T> schemaClass() {
Class result = null;
switch (type) {
@@ -340,7 +347,7 @@ public final class AttributableUtil {
return result;
}
- public <T extends AbstractSchema> T newSchema() {
+ public <T extends AbstractNormalSchema> T newSchema() {
T result = null;
switch (type) {
@@ -414,6 +421,24 @@ public final class AttributableUtil {
return result;
}
+ @SuppressWarnings("rawtypes")
+ public <T extends AbstractAttrTemplate> Class<T> attrTemplateClass() {
+ Class result = null;
+
+ switch (type) {
+ case USER:
+ break;
+ case ROLE:
+ result = RAttrTemplate.class;
+ break;
+ case MEMBERSHIP:
+ result = MAttrTemplate.class;
+ break;
+ }
+
+ return result;
+ }
+
public <T extends AbstractAttr> Class<T> attrClass() {
Class result = null;
@@ -450,6 +475,24 @@ public final class AttributableUtil {
return result;
}
+ @SuppressWarnings("rawtypes")
+ public <T extends AbstractAttrTemplate> Class<T> derAttrTemplateClass() {
+ Class result = null;
+
+ switch (type) {
+ case USER:
+ break;
+ case ROLE:
+ result = RDerAttrTemplate.class;
+ break;
+ case MEMBERSHIP:
+ result = MDerAttrTemplate.class;
+ break;
+ }
+
+ return result;
+ }
+
public <T extends AbstractDerAttr> Class<T> derAttrClass() {
Class result = null;
@@ -468,6 +511,24 @@ public final class AttributableUtil {
return result;
}
+ @SuppressWarnings("rawtypes")
+ public <T extends AbstractAttrTemplate> Class<T> virAttrTemplateClass() {
+ Class result = null;
+
+ switch (type) {
+ case USER:
+ break;
+ case ROLE:
+ result = RVirAttrTemplate.class;
+ break;
+ case MEMBERSHIP:
+ result = MVirAttrTemplate.class;
+ break;
+ }
+
+ return result;
+ }
+
public <T extends AbstractVirAttr> Class<T> virAttrClass() {
Class result = null;
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/EntitlementUtil.java Thu Oct 10 14:37:56 2013
@@ -23,6 +23,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
+import org.apache.syncope.common.SyncopeConstants;
import org.apache.syncope.core.persistence.beans.Entitlement;
import org.slf4j.Logger;
@@ -44,7 +45,8 @@ public final class EntitlementUtil {
private static final Logger LOG = LoggerFactory.getLogger(EntitlementUtil.class);
public static String getAuthenticatedUsername() {
- return SecurityContextHolder.getContext().getAuthentication().getName();
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ return authentication == null ? SyncopeConstants.ANONYMOUS_USER : authentication.getName();
}
public static Set<String> getOwnedEntitlementNames() {
@@ -108,7 +110,7 @@ public final class EntitlementUtil {
/**
* Extend the current authentication context to include the given role.
- *
+ *
* @param roleId role id
*/
public static void extendAuthContext(final Long roleId) {
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/JexlUtil.java Thu Oct 10 14:37:56 2013
@@ -137,22 +137,24 @@ public class JexlUtil {
return context;
}
- public JexlContext addAttrsToContext(final Collection<? extends AbstractAttr> attributes,
+ public JexlContext addAttrsToContext(final Collection<? extends AbstractAttr> attrs,
final JexlContext jexlContext) {
JexlContext context = jexlContext == null
? new MapContext()
: jexlContext;
- for (AbstractAttr attr : attributes) {
- List<String> attributeValues = attr.getValuesAsStrings();
- String expressionValue = attributeValues.isEmpty()
- ? ""
- : attributeValues.get(0);
+ for (AbstractAttr attr : attrs) {
+ if (attr.getSchema() != null) {
+ List<String> attrValues = attr.getValuesAsStrings();
+ String expressionValue = attrValues.isEmpty()
+ ? ""
+ : attrValues.get(0);
- LOG.debug("Add attribute {} with value {}", attr.getSchema().getName(), expressionValue);
+ LOG.debug("Add attribute {} with value {}", attr.getSchema().getName(), expressionValue);
- context.set(attr.getSchema().getName(), expressionValue);
+ context.set(attr.getSchema().getName(), expressionValue);
+ }
}
return context;
@@ -166,14 +168,16 @@ public class JexlUtil {
: jexlContext;
for (AbstractDerAttr derAttr : derAttrs) {
- String expressionValue = derAttr.getValue(attrs);
- if (expressionValue == null) {
- expressionValue = "";
- }
+ if (derAttr.getSchema() != null) {
+ String expressionValue = derAttr.getValue(attrs);
+ if (expressionValue == null) {
+ expressionValue = "";
+ }
- LOG.debug("Add derived attribute {} with value {}", derAttr.getDerivedSchema().getName(), expressionValue);
+ LOG.debug("Add derived attribute {} with value {}", derAttr.getSchema().getName(), expressionValue);
- context.set(derAttr.getDerivedSchema().getName(), expressionValue);
+ context.set(derAttr.getSchema().getName(), expressionValue);
+ }
}
return context;
@@ -187,14 +191,16 @@ public class JexlUtil {
: jexlContext;
for (AbstractVirAttr virAttr : virAttrs) {
- List<String> attributeValues = virAttr.getValues();
- String expressionValue = attributeValues.isEmpty()
- ? ""
- : attributeValues.get(0);
+ if (virAttr.getSchema() != null) {
+ List<String> attrValues = virAttr.getValues();
+ String expressionValue = attrValues.isEmpty()
+ ? ""
+ : attrValues.get(0);
- LOG.debug("Add virtual attribute {} with value {}", virAttr.getVirtualSchema().getName(), expressionValue);
+ LOG.debug("Add virtual attribute {} with value {}", virAttr.getSchema().getName(), expressionValue);
- context.set(virAttr.getVirtualSchema().getName(), expressionValue);
+ context.set(virAttr.getSchema().getName(), expressionValue);
+ }
}
return context;
@@ -205,7 +211,7 @@ public class JexlUtil {
addFieldsToContext(attributableTO, context);
- for (AttributeTO attr : attributableTO.getAttributes()) {
+ for (AttributeTO attr : attributableTO.getAttrs()) {
List<String> values = attr.getValues();
String expressionValue = values.isEmpty()
? ""
@@ -215,7 +221,7 @@ public class JexlUtil {
context.set(attr.getSchema(), expressionValue);
}
- for (AttributeTO derAttr : attributableTO.getDerivedAttributes()) {
+ for (AttributeTO derAttr : attributableTO.getDerAttrs()) {
List<String> values = derAttr.getValues();
String expressionValue = values.isEmpty()
? ""
@@ -225,7 +231,7 @@ public class JexlUtil {
context.set(derAttr.getSchema(), expressionValue);
}
- for (AttributeTO virAttr : attributableTO.getVirtualAttributes()) {
+ for (AttributeTO virAttr : attributableTO.getVirAttrs()) {
List<String> values = virAttr.getValues();
String expressionValue = values.isEmpty()
? ""
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java?rev=1531003&r1=1531002&r2=1531003&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java Thu Oct 10 14:37:56 2013
@@ -38,7 +38,7 @@ import org.apache.syncope.core.persisten
import org.apache.syncope.core.persistence.beans.AbstractAttributable;
import org.apache.syncope.core.persistence.beans.AbstractDerAttr;
import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
-import org.apache.syncope.core.persistence.beans.AbstractSchema;
+import org.apache.syncope.core.persistence.beans.AbstractNormalSchema;
import org.apache.syncope.core.persistence.beans.AbstractVirAttr;
import org.apache.syncope.core.persistence.beans.ExternalResource;
import org.apache.syncope.core.persistence.beans.membership.MDerSchema;
@@ -162,7 +162,7 @@ public final class MappingUtil {
final List<AbstractAttrValue> values = MappingUtil.getIntValues(resource, mapItem, attributables,
vAttrsToBeRemoved, vAttrsToBeUpdated);
- AbstractSchema schema = null;
+ AbstractNormalSchema schema = null;
AttributeSchemaType schemaType;
switch (mapItem.getIntMappingType()) {
case UserSchema:
@@ -271,8 +271,8 @@ public final class MappingUtil {
final JexlContext jexlContext = new MapContext();
jexlUtil.addFieldsToContext(subject, jexlContext);
- jexlUtil.addAttrsToContext(subject.getAttributes(), jexlContext);
- jexlUtil.addDerAttrsToContext(subject.getDerivedAttributes(), subject.getAttributes(), jexlContext);
+ jexlUtil.addAttrsToContext(subject.getAttrs(), jexlContext);
+ jexlUtil.addDerAttrsToContext(subject.getDerAttrs(), subject.getAttrs(), jexlContext);
evalAccountLink = jexlUtil.evaluate(attrUtil.getAccountLink(resource), jexlContext);
}
@@ -331,7 +331,7 @@ public final class MappingUtil {
case RoleSchema:
case MembershipSchema:
for (AbstractAttributable attributable : attributables) {
- final AbstractAttr attr = attributable.getAttribute(mappingItem.getIntAttrName());
+ final AbstractAttr attr = attributable.getAttr(mappingItem.getIntAttrName());
if (attr != null) {
if (attr.getUniqueValue() != null) {
values.add(attr.getUniqueValue());
@@ -353,7 +353,7 @@ public final class MappingUtil {
case RoleVirtualSchema:
case MembershipVirtualSchema:
for (AbstractAttributable attributable : attributables) {
- AbstractVirAttr virAttr = attributable.getVirtualAttribute(mappingItem.getIntAttrName());
+ AbstractVirAttr virAttr = attributable.getVirAttr(mappingItem.getIntAttrName());
if (virAttr != null) {
if (virAttr.getValues() != null) {
for (String value : virAttr.getValues()) {
@@ -387,11 +387,11 @@ public final class MappingUtil {
case RoleDerivedSchema:
case MembershipDerivedSchema:
for (AbstractAttributable attributable : attributables) {
- AbstractDerAttr derAttr = attributable.getDerivedAttribute(mappingItem.getIntAttrName());
+ AbstractDerAttr derAttr = attributable.getDerAttr(mappingItem.getIntAttrName());
if (derAttr != null) {
attrValue = (attributable instanceof SyncopeRole)
? new RAttrValue() : new UAttrValue();
- attrValue.setStringValue(derAttr.getValue(attributable.getAttributes()));
+ attrValue.setStringValue(derAttr.getValue(attributable.getAttrs()));
values.add(attrValue);
}