You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2012/03/05 15:29:32 UTC
svn commit: r1297069 - in
/incubator/syncope/trunk/core/src/main/java/org/syncope/core:
propagation/ConnectorFacadeProxy.java
rest/controller/ConnInstanceController.java
rest/data/ConnInstanceDataBinder.java
Author: fmartelli
Date: Mon Mar 5 14:29:31 2012
New Revision: 1297069
URL: http://svn.apache.org/viewvc?rev=1297069&view=rev
Log:
Connector configuration properties setting used to fail with character property type
Modified:
incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ConnInstanceController.java
incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java?rev=1297069&r1=1297068&r2=1297069&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/propagation/ConnectorFacadeProxy.java Mon Mar 5 14:29:31 2012
@@ -127,8 +127,7 @@ public class ConnectorFacadeProxy {
// get the specified connector.
ConnectorInfo info;
try {
- info = connBundleManager.getConnectorManager().
- findConnectorInfo(key);
+ info = connBundleManager.getConnectorManager().findConnectorInfo(key);
if (info == null) {
throw new NotFoundException("Connector Info for key " + key);
}
@@ -144,8 +143,7 @@ public class ConnectorFacadeProxy {
}
// retrieve the ConfigurationProperties.
- ConfigurationProperties properties =
- apiConfig.getConfigurationProperties();
+ final ConfigurationProperties properties = apiConfig.getConfigurationProperties();
if (properties == null) {
throw new NotFoundException("Configuration properties");
@@ -154,99 +152,24 @@ public class ConnectorFacadeProxy {
// Print out what the properties are (not necessary)
if (LOG.isDebugEnabled()) {
for (String propName : properties.getPropertyNames()) {
- LOG.debug("\nProperty Name: "
- + properties.getProperty(propName).getName()
- + "\nProperty Type: "
- + properties.getProperty(propName).getType());
+ LOG.debug("\nProperty Name: {}\nProperty Type: {}",
+ properties.getProperty(propName).getName(),
+ properties.getProperty(propName).getType());
}
}
// Set all of the ConfigurationProperties needed by the connector.
- Class propertySchemaClass;
- Object propertyValue;
for (ConnConfProperty property : connInstance.getConfiguration()) {
- if (property.getValues() != null
- && !property.getValues().isEmpty()) {
- try {
- propertySchemaClass = ClassUtils.forName(
- property.getSchema().getType(),
- ClassUtils.getDefaultClassLoader());
-
- if (GuardedString.class.equals(propertySchemaClass)) {
- propertyValue = new GuardedString(
- ((String) property.getValues().iterator().next()).toCharArray());
- } else if (GuardedByteArray.class.equals(
- propertySchemaClass)) {
-
- propertyValue = new GuardedByteArray(
- (byte[]) property.getValues().iterator().next());
- } else if (Character.class.equals(propertySchemaClass)
- || char.class.equals(propertySchemaClass)) {
-
- propertyValue =
- (Character) property.getValues().iterator().next();
- } else if (Integer.class.equals(propertySchemaClass)
- || int.class.equals(propertySchemaClass)) {
-
- propertyValue =
- Integer.parseInt(
- property.getValues().iterator().next().toString());
-
- } else if (Long.class.equals(propertySchemaClass)
- || long.class.equals(propertySchemaClass)) {
-
- propertyValue =
- Long.parseLong(
- property.getValues().iterator().next().toString());
-
- } else if (Float.class.equals(propertySchemaClass)
- || float.class.equals(propertySchemaClass)) {
-
- propertyValue =
- Float.parseFloat(
- property.getValues().iterator().next().toString());
-
- } else if (Double.class.equals(propertySchemaClass)
- || double.class.equals(propertySchemaClass)) {
-
- propertyValue =
- Double.parseDouble(
- property.getValues().iterator().next().toString());
-
- } else if (Boolean.class.equals(propertySchemaClass)
- || boolean.class.equals(propertySchemaClass)) {
-
- propertyValue =
- Boolean.parseBoolean(
- property.getValues().iterator().next().toString());
-
- } else if (URI.class.equals(propertySchemaClass)) {
- propertyValue = URI.create(
- (String) property.getValues().iterator().next());
- } else if (File.class.equals(propertySchemaClass)) {
- propertyValue = new File(
- (String) property.getValues().iterator().next());
- } else if (String[].class.equals(propertySchemaClass)) {
- propertyValue =
- ((List<String>) property.getValues()).toArray(
- new String[]{});
- } else {
- propertyValue =
- (String) property.getValues().iterator().next();
- }
-
- properties.setPropertyValue(
- property.getSchema().getName(), propertyValue);
- } catch (Throwable t) {
- LOG.error("Invalid ConnConfProperty specified: {}",
- property, t);
- }
+ final Object propertyValue = getPropertyValue(property);
+ if (propertyValue != null) {
+ properties.setPropertyValue(property.getSchema().getName(), propertyValue);
}
}
// Use the ConnectorFacadeFactory's newInstance() method to get
// a new connector.
connector = ConnectorFacadeFactory.getInstance().newInstance(apiConfig);
+
if (connector == null) {
throw new NotFoundException("Connector");
}
@@ -665,4 +588,47 @@ public class ConnectorFacadeProxy {
return oob.build();
}
+
+ private Object getPropertyValue(final ConnConfProperty property) {
+ Object value = null;
+
+ final List<Object> values = property.getValues();
+
+ if (values != null && !values.isEmpty()) {
+ try {
+ final Class propertySchemaClass =
+ ClassUtils.forName(property.getSchema().getType(), ClassUtils.getDefaultClassLoader());
+
+ if (GuardedString.class.equals(propertySchemaClass)) {
+ value = new GuardedString((values.get(0).toString()).toCharArray());
+ } else if (GuardedByteArray.class.equals(propertySchemaClass)) {
+ value = new GuardedByteArray((byte[]) values.get(0));
+ } else if (Character.class.equals(propertySchemaClass) || char.class.equals(propertySchemaClass)) {
+ value = StringUtils.hasText((String) values.get(0)) ? values.get(0).toString().charAt(0) : null;
+ } else if (Integer.class.equals(propertySchemaClass) || int.class.equals(propertySchemaClass)) {
+ value = Integer.parseInt(values.get(0).toString());
+ } else if (Long.class.equals(propertySchemaClass) || long.class.equals(propertySchemaClass)) {
+ value = Long.parseLong(values.get(0).toString());
+ } else if (Float.class.equals(propertySchemaClass) || float.class.equals(propertySchemaClass)) {
+ value = Float.parseFloat(values.get(0).toString());
+ } else if (Double.class.equals(propertySchemaClass) || double.class.equals(propertySchemaClass)) {
+ value = Double.parseDouble(values.get(0).toString());
+ } else if (Boolean.class.equals(propertySchemaClass) || boolean.class.equals(propertySchemaClass)) {
+ value = Boolean.parseBoolean(values.get(0).toString());
+ } else if (URI.class.equals(propertySchemaClass)) {
+ value = URI.create(values.get(0).toString());
+ } else if (File.class.equals(propertySchemaClass)) {
+ value = new File(values.get(0).toString());
+ } else if (String[].class.equals(propertySchemaClass)) {
+ value = values.toArray(new String[]{});
+ } else {
+ value = values.get(0).toString();
+ }
+ } catch (Throwable t) {
+ LOG.error("Invalid ConnConfProperty specified: {}", property, t);
+ }
+ }
+
+ return value;
+ }
}
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ConnInstanceController.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ConnInstanceController.java?rev=1297069&r1=1297068&r2=1297069&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ConnInstanceController.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/controller/ConnInstanceController.java Mon Mar 5 14:29:31 2012
@@ -227,8 +227,7 @@ public class ConnInstanceController exte
}
@PreAuthorize("hasRole('CONNECTOR_READ')")
- @RequestMapping(method = RequestMethod.GET,
- value = "/bundle/list")
+ @RequestMapping(method = RequestMethod.GET, value = "/bundle/list")
@Transactional(readOnly = true)
public List<ConnBundleTO> getBundles(
@RequestParam(value = "lang", required = false) final String lang)
@@ -240,8 +239,7 @@ public class ConnInstanceController exte
CurrentLocale.set(new Locale(lang));
}
- ConnectorInfoManager manager =
- bundleManager.getConnectorManager();
+ ConnectorInfoManager manager = bundleManager.getConnectorManager();
List<ConnectorInfo> bundles = manager.getConnectorInfos();
@@ -261,18 +259,14 @@ public class ConnInstanceController exte
if (bundles != null) {
for (ConnectorInfo bundle : bundles) {
connectorBundleTO = new ConnBundleTO();
- connectorBundleTO.setDisplayName(
- bundle.getConnectorDisplayName());
+ connectorBundleTO.setDisplayName(bundle.getConnectorDisplayName());
key = bundle.getConnectorKey();
LOG.debug("\nBundle name: {}"
+ "\nBundle version: {}"
+ "\nBundle class: {}",
- new Object[]{
- key.getBundleName(),
- key.getBundleVersion(),
- key.getConnectorName()});
+ new Object[]{key.getBundleName(), key.getBundleVersion(), key.getConnectorName()});
connectorBundleTO.setBundleName(key.getBundleName());
connectorBundleTO.setConnectorName(key.getConnectorName());
@@ -289,30 +283,24 @@ public class ConnInstanceController exte
configurationProperty = properties.getProperty(propName);
// set name
- connConfPropSchema.setName(
- configurationProperty.getName());
+ connConfPropSchema.setName(configurationProperty.getName());
// set display name
- connConfPropSchema.setDisplayName(
- configurationProperty.getDisplayName(propName));
+ connConfPropSchema.setDisplayName(configurationProperty.getDisplayName(propName));
// set help message
- connConfPropSchema.setHelpMessage(
- configurationProperty.getHelpMessage(propName));
+ connConfPropSchema.setHelpMessage(configurationProperty.getHelpMessage(propName));
// set if mandatory
- connConfPropSchema.setRequired(
- configurationProperty.isRequired());
+ connConfPropSchema.setRequired(configurationProperty.isRequired());
// set type
- connConfPropSchema.setType(
- configurationProperty.getType().getName());
+ connConfPropSchema.setType(configurationProperty.getType().getName());
connectorBundleTO.addProperty(connConfPropSchema);
}
- LOG.debug("Bundle properties: {}",
- connectorBundleTO.getProperties());
+ LOG.debug("Bundle properties: {}", connectorBundleTO.getProperties());
connectorBundleTOs.add(connectorBundleTO);
}
@@ -397,8 +385,7 @@ public class ConnInstanceController exte
}
/**
- * Merge connector configuration properties avoiding repetition but giving
- * priority to primary set.
+ * Merge connector configuration properties avoiding repetition but giving priority to primary set.
*
* @param primary primary set.
* @param secondary secondary set.
Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java?rev=1297069&r1=1297068&r2=1297069&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/ConnInstanceDataBinder.java Mon Mar 5 14:29:31 2012
@@ -156,8 +156,7 @@ public class ConnInstanceDataBinder {
throws NotFoundException {
ConnInstanceTO connInstanceTO = new ConnInstanceTO();
- connInstanceTO.setId(connInstance.getId() != null
- ? connInstance.getId().longValue() : 0L);
+ connInstanceTO.setId(connInstance.getId() != null ? connInstance.getId().longValue() : 0L);
// retrieve the ConfigurationProperties.
ConfigurationProperties properties =
@@ -166,37 +165,29 @@ public class ConnInstanceDataBinder {
connInstance.getVersion(),
connInstance.getConnectorName());
- BeanUtils.copyProperties(
- connInstance, connInstanceTO, IGNORE_PROPERTIES);
+ BeanUtils.copyProperties(connInstance, connInstanceTO, IGNORE_PROPERTIES);
ConnConfPropSchema connConfPropSchema;
ConfigurationProperty configurationProperty;
- Map<String, ConnConfProperty> connInstanceToConfMap =
- connInstanceTO.getConfigurationMap();
+ Map<String, ConnConfProperty> connInstanceToConfMap = connInstanceTO.getConfigurationMap();
for (String propName : properties.getPropertyNames()) {
configurationProperty = properties.getProperty(propName);
if (!connInstanceToConfMap.containsKey(propName)) {
connConfPropSchema = new ConnConfPropSchema();
- connConfPropSchema.setName(
- configurationProperty.getName());
- connConfPropSchema.setDisplayName(
- configurationProperty.getDisplayName(propName));
- connConfPropSchema.setHelpMessage(
- configurationProperty.getHelpMessage(propName));
- connConfPropSchema.setRequired(
- configurationProperty.isRequired());
- connConfPropSchema.setType(
- configurationProperty.getType().getName());
+ connConfPropSchema.setName(configurationProperty.getName());
+ connConfPropSchema.setDisplayName(configurationProperty.getDisplayName(propName));
+ connConfPropSchema.setHelpMessage(configurationProperty.getHelpMessage(propName));
+ connConfPropSchema.setRequired(configurationProperty.isRequired());
+ connConfPropSchema.setType(configurationProperty.getType().getName());
ConnConfProperty property = new ConnConfProperty();
property.setSchema(connConfPropSchema);
connInstanceTO.addConfiguration(property);
} else {
connInstanceToConfMap.get(propName).getSchema().
- setDisplayName(
- configurationProperty.getDisplayName(propName));
+ setDisplayName(configurationProperty.getDisplayName(propName));
}
}
return connInstanceTO;