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 2012/10/24 15:56:00 UTC
svn commit: r1401690 - in
/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util:
ConnObjectUtil.java SchemaMappingUtil.java SchemaMappingWrapper.java
Author: ilgrosso
Date: Wed Oct 24 13:55:59 2012
New Revision: 1401690
URL: http://svn.apache.org/viewvc?rev=1401690&view=rev
Log:
Cleaning up and simple refactory (again)
Added:
incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingWrapper.java (with props)
Modified:
incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java
incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingUtil.java
Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java?rev=1401690&r1=1401689&r2=1401690&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ConnObjectUtil.java Wed Oct 24 13:55:59 2012
@@ -332,18 +332,22 @@ public class ConnObjectUtil {
return connObjectTO;
}
+ /**
+ * Query connected external resources for values to populated virtual attributes associated with the given owner.
+ *
+ * @param owner user or role
+ */
public void retrieveVirAttrValues(final AbstractAttributable owner) {
final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
final ConnInstanceLoader connInstanceLoader = context.getBean(ConnInstanceLoader.class);
- final Map<SchemaMappingUtil.SchemaMappingsWrapper, ConnectorObject> remoteObjects =
- new HashMap<SchemaMappingUtil.SchemaMappingsWrapper, ConnectorObject>();
+ final Map<SchemaMappingWrapper, ConnectorObject> remoteObjects =
+ new HashMap<SchemaMappingWrapper, ConnectorObject>();
for (ExternalResource resource : owner.getResources()) {
LOG.debug("Retrieve remote object from '{}'", resource.getName());
try {
- final SchemaMappingUtil.SchemaMappingsWrapper mappings = new SchemaMappingUtil.SchemaMappingsWrapper(
- resource.getMappings());
+ final SchemaMappingWrapper mappings = new SchemaMappingWrapper(resource.getMappings());
final String accountId = SchemaMappingUtil.getAccountIdValue(owner, mappings.getAccountIdMapping());
@@ -353,7 +357,7 @@ public class ConnObjectUtil {
// Retrieve attributes to get
final Set<String> extAttrNames = new HashSet<String>();
- for (Collection<SchemaMapping> virAttrMappings : mappings.getuVirMappings().values()) {
+ for (Set<SchemaMapping> virAttrMappings : mappings.getuVirMappings().values()) {
for (SchemaMapping virAttrMapping : virAttrMappings) {
extAttrNames.add(SchemaMappingUtil.getExtAttrName(virAttrMapping));
}
@@ -383,15 +387,14 @@ public class ConnObjectUtil {
for (AbstractVirAttr virAttr : owner.getVirtualAttributes()) {
LOG.debug("Provide value for virtual attribute '{}'", virAttr.getVirtualSchema().getName());
- for (SchemaMappingUtil.SchemaMappingsWrapper mappings : remoteObjects.keySet()) {
- Collection<SchemaMapping> virAttrMappings = mappings.getuVirMappings().get(
- virAttr.getVirtualSchema().getName());
+ for (Map.Entry<SchemaMappingWrapper, ConnectorObject> entry : remoteObjects.entrySet()) {
+ final Set<SchemaMapping> virAttrMappings = entry.getKey().getuVirMappings().
+ get(virAttr.getVirtualSchema().getName());
if (virAttrMappings != null) {
for (SchemaMapping virAttrMapping : virAttrMappings) {
- String extAttrName = SchemaMappingUtil.getExtAttrName(virAttrMapping);
- Attribute extAttr = remoteObjects.get(mappings).getAttributeByName(extAttrName);
-
+ final String extAttrName = SchemaMappingUtil.getExtAttrName(virAttrMapping);
+ final Attribute extAttr = entry.getValue().getAttributeByName(extAttrName);
if (extAttr != null && extAttr.getValue() != null && !extAttr.getValue().isEmpty()) {
for (Object obj : extAttr.getValue()) {
if (obj != null) {
Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingUtil.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingUtil.java?rev=1401690&r1=1401689&r2=1401690&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingUtil.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingUtil.java Wed Oct 24 13:55:59 2012
@@ -129,9 +129,10 @@ public class SchemaMappingUtil {
/**
* Get attribute values.
*
- * @param mapping mapping.
- * @param attributables list of attributables.
- * @param password password.
+ * @param mapping mapping
+ * @param attributables list of attributables
+ * @param password password
+ * @param schemaDAO schema DAO
* @return schema and attribute values.
*/
public static Map.Entry<AbstractSchema, List<AbstractAttrValue>> getIntValues(final SchemaMapping mapping,
@@ -240,6 +241,7 @@ public class SchemaMappingUtil {
public static List<String> getIntValueAsStrings(
final AbstractAttributable attributable, final SchemaMapping mapping) {
+
return getIntValueAsStrings(attributable, mapping, null);
}
@@ -347,8 +349,8 @@ public class SchemaMappingUtil {
/**
* Get first occurance of accountId mapping from a collection of mappings.
*
- * @param mappings collection of SchemaMapping.
- * @return AccountId mapping or null if no occurences found.
+ * @param mappings collection of SchemaMapping
+ * @return AccountId mapping or null if no occurences found
*/
public static SchemaMapping getAccountIdMapping(final Collection<SchemaMapping> mappings) {
for (SchemaMapping mapping : mappings) {
@@ -363,9 +365,9 @@ public class SchemaMappingUtil {
/**
* Get accountId internal value.
*
- * @param attributable attributable.
- * @param mappings collection of SchemaMapping.
- * @return accountId internal value.
+ * @param attributable attributable
+ * @param mappings collection of SchemaMapping
+ * @return accountId internal value
*/
public static String getAccountIdValue(final AbstractAttributable attributable,
final Collection<SchemaMapping> mappings) {
@@ -379,9 +381,9 @@ public class SchemaMappingUtil {
/**
* Get accountId internal value.
*
- * @param attributable attributable.
- * @param mappings accountId mapping.
- * @return accountId internal value.
+ * @param attributable attributable
+ * @param mapping accountId mapping
+ * @return accountId internal value
*/
public static String getAccountIdValue(final AbstractAttributable attributable, final SchemaMapping mapping) {
final List<String> values = getIntValueAsStrings(attributable, mapping);
@@ -389,160 +391,4 @@ public class SchemaMappingUtil {
? null
: values.get(0);
}
-
- public static class SchemaMappingsWrapper {
-
- SchemaMapping accountIdMapping = null;
-
- SchemaMapping passwordMapping = null;
-
- final Map<String, Collection<SchemaMapping>> uMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- final Map<String, Collection<SchemaMapping>> uVirMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- final Map<String, Collection<SchemaMapping>> uDerMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- final Map<String, Collection<SchemaMapping>> rMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- final Map<String, Collection<SchemaMapping>> rVirMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- final Map<String, Collection<SchemaMapping>> rDerMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- final Map<String, Collection<SchemaMapping>> mMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- final Map<String, Collection<SchemaMapping>> mVirMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- final Map<String, Collection<SchemaMapping>> mDerMappings = new HashMap<String, Collection<SchemaMapping>>();
-
- public SchemaMappingsWrapper(final Collection<SchemaMapping> mappings) {
- if (mappings == null) {
- return;
- }
-
- for (SchemaMapping mapping : mappings) {
- if (mapping.isAccountid() && accountIdMapping == null) {
-
- accountIdMapping = mapping;
-
- } else if (mapping.isPassword() && passwordMapping == null) {
-
- passwordMapping = mapping;
-
- } else {
- final String intAttrName = getIntAttrName(mapping);
-
- switch (mapping.getIntMappingType()) {
- case Password:
- if (passwordMapping == null) {
- passwordMapping = mapping;
- }
- break;
- case Username:
- case SyncopeUserId:
- case UserSchema:
- if (uMappings.get(intAttrName) == null) {
- uMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- uMappings.get(intAttrName).add(mapping);
- break;
- case RoleSchema:
- if (rMappings.get(intAttrName) == null) {
- rMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- rMappings.get(intAttrName).add(mapping);
- break;
- case MembershipSchema:
- if (mMappings.get(intAttrName) == null) {
- mMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- mMappings.get(intAttrName).add(mapping);
- break;
-
- case UserDerivedSchema:
- if (uDerMappings.get(intAttrName) == null) {
- uDerMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- uDerMappings.get(intAttrName).add(mapping);
- break;
- case RoleDerivedSchema:
- if (rDerMappings.get(intAttrName) == null) {
- rDerMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- rDerMappings.get(intAttrName).add(mapping);
- break;
- case MembershipDerivedSchema:
- if (mDerMappings.get(intAttrName) == null) {
- mDerMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- mDerMappings.get(intAttrName).add(mapping);
- break;
-
- case UserVirtualSchema:
- if (uVirMappings.get(intAttrName) == null) {
- uVirMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- uVirMappings.get(intAttrName).add(mapping);
- break;
- case RoleVirtualSchema:
- if (rVirMappings.get(intAttrName) == null) {
- rVirMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- rVirMappings.get(intAttrName).add(mapping);
- break;
- case MembershipVirtualSchema:
- if (mVirMappings.get(intAttrName) == null) {
- mVirMappings.put(intAttrName, new HashSet<SchemaMapping>());
- }
- mVirMappings.get(intAttrName).add(mapping);
- break;
- default:
- }
- }
- }
- }
-
- public SchemaMapping getAccountIdMapping() {
- return accountIdMapping;
- }
-
- public Map<String, Collection<SchemaMapping>> getmDerMappings() {
- return mDerMappings;
- }
-
- public Map<String, Collection<SchemaMapping>> getmMappings() {
- return mMappings;
- }
-
- public Map<String, Collection<SchemaMapping>> getmVirMappings() {
- return mVirMappings;
- }
-
- public SchemaMapping getPasswordMapping() {
- return passwordMapping;
- }
-
- public Map<String, Collection<SchemaMapping>> getrDerMappings() {
- return rDerMappings;
- }
-
- public Map<String, Collection<SchemaMapping>> getrMappings() {
- return rMappings;
- }
-
- public Map<String, Collection<SchemaMapping>> getrVirMappings() {
- return rVirMappings;
- }
-
- public Map<String, Collection<SchemaMapping>> getuDerMappings() {
- return uDerMappings;
- }
-
- public Map<String, Collection<SchemaMapping>> getuMappings() {
- return uMappings;
- }
-
- public Map<String, Collection<SchemaMapping>> getuVirMappings() {
- return uVirMappings;
- }
- }
}
Added: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingWrapper.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingWrapper.java?rev=1401690&view=auto
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingWrapper.java (added)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingWrapper.java Wed Oct 24 13:55:59 2012
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.util;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.syncope.core.persistence.beans.SchemaMapping;
+
+/**
+ *
+ * @author ilgrosso
+ */
+public class SchemaMappingWrapper {
+
+ private SchemaMapping accountIdMapping = null;
+
+ private SchemaMapping passwordMapping = null;
+
+ private final Map<String, Set<SchemaMapping>> uMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ private final Map<String, Set<SchemaMapping>> uVirMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ private final Map<String, Set<SchemaMapping>> uDerMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ private final Map<String, Set<SchemaMapping>> rMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ private final Map<String, Set<SchemaMapping>> rVirMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ private final Map<String, Set<SchemaMapping>> rDerMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ private final Map<String, Set<SchemaMapping>> mMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ private final Map<String, Set<SchemaMapping>> mVirMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ private final Map<String, Set<SchemaMapping>> mDerMappings = new HashMap<String, Set<SchemaMapping>>();
+
+ public SchemaMappingWrapper(final Set<SchemaMapping> mappings) {
+ if (mappings == null) {
+ return;
+ }
+ for (SchemaMapping mapping : mappings) {
+ if (mapping.isAccountid() && accountIdMapping == null) {
+ accountIdMapping = mapping;
+ } else if (mapping.isPassword() && passwordMapping == null) {
+ passwordMapping = mapping;
+ } else {
+ final String intAttrName = SchemaMappingUtil.getIntAttrName(mapping);
+ switch (mapping.getIntMappingType()) {
+ case Password:
+ if (passwordMapping == null) {
+ passwordMapping = mapping;
+ }
+ break;
+
+ case Username:
+ case SyncopeUserId:
+ case UserSchema:
+ if (uMappings.get(intAttrName) == null) {
+ uMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ uMappings.get(intAttrName).add(mapping);
+ break;
+
+ case RoleSchema:
+ if (rMappings.get(intAttrName) == null) {
+ rMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ rMappings.get(intAttrName).add(mapping);
+ break;
+
+ case MembershipSchema:
+ if (mMappings.get(intAttrName) == null) {
+ mMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ mMappings.get(intAttrName).add(mapping);
+ break;
+
+ case UserDerivedSchema:
+ if (uDerMappings.get(intAttrName) == null) {
+ uDerMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ uDerMappings.get(intAttrName).add(mapping);
+ break;
+
+ case RoleDerivedSchema:
+ if (rDerMappings.get(intAttrName) == null) {
+ rDerMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ rDerMappings.get(intAttrName).add(mapping);
+ break;
+
+ case MembershipDerivedSchema:
+ if (mDerMappings.get(intAttrName) == null) {
+ mDerMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ mDerMappings.get(intAttrName).add(mapping);
+ break;
+
+ case UserVirtualSchema:
+ if (uVirMappings.get(intAttrName) == null) {
+ uVirMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ uVirMappings.get(intAttrName).add(mapping);
+ break;
+
+ case RoleVirtualSchema:
+ if (rVirMappings.get(intAttrName) == null) {
+ rVirMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ rVirMappings.get(intAttrName).add(mapping);
+ break;
+
+ case MembershipVirtualSchema:
+ if (mVirMappings.get(intAttrName) == null) {
+ mVirMappings.put(intAttrName, new HashSet<SchemaMapping>());
+ }
+ mVirMappings.get(intAttrName).add(mapping);
+ break;
+
+ default:
+ }
+ }
+ }
+ }
+
+ public SchemaMapping getAccountIdMapping() {
+ return accountIdMapping;
+ }
+
+ public Map<String, Set<SchemaMapping>> getmDerMappings() {
+ return mDerMappings;
+ }
+
+ public Map<String, Set<SchemaMapping>> getmMappings() {
+ return mMappings;
+ }
+
+ public Map<String, Set<SchemaMapping>> getmVirMappings() {
+ return mVirMappings;
+ }
+
+ public SchemaMapping getPasswordMapping() {
+ return passwordMapping;
+ }
+
+ public Map<String, Set<SchemaMapping>> getrDerMappings() {
+ return rDerMappings;
+ }
+
+ public Map<String, Set<SchemaMapping>> getrMappings() {
+ return rMappings;
+ }
+
+ public Map<String, Set<SchemaMapping>> getrVirMappings() {
+ return rVirMappings;
+ }
+
+ public Map<String, Set<SchemaMapping>> getuDerMappings() {
+ return uDerMappings;
+ }
+
+ public Map<String, Set<SchemaMapping>> getuMappings() {
+ return uMappings;
+ }
+
+ public Map<String, Set<SchemaMapping>> getuVirMappings() {
+ return uVirMappings;
+ }
+}
Propchange: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingWrapper.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/SchemaMappingWrapper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain