From 37612ad4f90067beb591cab6d5aa51954838f3f5 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 7 Dec 2012 15:04:08 +0000 Subject: [PATCH] fix bean mapping BeanReplicator does not replicate automatically object field git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1418347 13f79535-47bb-0310-9956-ffa450edef68 --- .../beans/ArchivaRuntimeConfiguration.java | 32 ++++++++++++++++++- .../admin/model/beans/LdapConfiguration.java | 29 +++++++++++++++++ ...faultArchivaRuntimeConfigurationAdmin.java | 7 ++++ .../main/webapp/js/archiva/general-admin.js | 29 ++++++++--------- 4 files changed, 81 insertions(+), 16 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ArchivaRuntimeConfiguration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ArchivaRuntimeConfiguration.java index 6883187ea..1b80c836a 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ArchivaRuntimeConfiguration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ArchivaRuntimeConfiguration.java @@ -20,14 +20,16 @@ package org.apache.archiva.admin.model.beans; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** * @author Olivier Lamy * @since 1.4-M4 */ -@XmlRootElement(name = "redbackRuntimeConfiguration") +@XmlRootElement( name = "redbackRuntimeConfiguration" ) public class ArchivaRuntimeConfiguration implements Serializable { @@ -42,6 +44,11 @@ public class ArchivaRuntimeConfiguration private Map configurationProperties; + /** + * field to ease json mapping wrapper on configurationProperties field + */ + private List configurationPropertiesEntries; + public ArchivaRuntimeConfiguration() { // no op @@ -91,6 +98,29 @@ public class ArchivaRuntimeConfiguration this.configurationProperties = configurationProperties; } + public List getConfigurationPropertiesEntries() + { + configurationPropertiesEntries = new ArrayList( getConfigurationProperties().size() ); + for ( Map.Entry entry : getConfigurationProperties().entrySet() ) + { + configurationPropertiesEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) ); + } + return configurationPropertiesEntries; + } + + public void setConfigurationPropertiesEntries( List configurationPropertiesEntries ) + { + this.configurationPropertiesEntries = configurationPropertiesEntries; + if ( configurationPropertiesEntries != null ) + { + this.configurationProperties = new HashMap( configurationPropertiesEntries.size() ); + for ( PropertyEntry propertyEntry : configurationPropertiesEntries ) + { + this.configurationProperties.put( propertyEntry.getKey(), propertyEntry.getValue() ); + } + } + } + @Override public String toString() { diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/LdapConfiguration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/LdapConfiguration.java index 107ba16c4..0db86bf30 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/LdapConfiguration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/LdapConfiguration.java @@ -19,7 +19,9 @@ package org.apache.archiva.admin.model.beans; */ import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -81,6 +83,11 @@ public class LdapConfiguration */ private Map extraProperties = new HashMap(); + /** + * field to ease json mapping wrapper on extraProperties field + */ + private List extraPropertiesEntries; + public LdapConfiguration() { // no op @@ -185,4 +192,26 @@ public class LdapConfiguration { this.bindAuthenticatorEnabled = bindAuthenticatorEnabled; } + + public List getExtraPropertiesEntries() + { + extraPropertiesEntries = new ArrayList( getExtraProperties().size() ); + for ( Map.Entry entry : getExtraProperties().entrySet() ) + { + extraPropertiesEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) ); + } + return extraPropertiesEntries; + } + + public void setExtraPropertiesEntries( List extraPropertiesEntries ) + { + this.extraPropertiesEntries = extraPropertiesEntries; + if ( extraPropertiesEntries != null ) + { + for ( PropertyEntry propertyEntry : extraPropertiesEntries ) + { + this.extraProperties.put( propertyEntry.getKey(), propertyEntry.getValue() ); + } + } + } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultArchivaRuntimeConfigurationAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultArchivaRuntimeConfigurationAdmin.java index fda2dcfed..7f2a1c1f5 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultArchivaRuntimeConfigurationAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultArchivaRuntimeConfigurationAdmin.java @@ -142,6 +142,13 @@ public class DefaultArchivaRuntimeConfigurationAdmin ArchivaRuntimeConfiguration archivaRuntimeConfiguration = new BeanReplicator().replicateBean( runtimeConfiguration, ArchivaRuntimeConfiguration.class ); + if ( runtimeConfiguration.getLdapConfiguration() != null ) + { + archivaRuntimeConfiguration.setLdapConfiguration( + new BeanReplicator().replicateBean( runtimeConfiguration.getLdapConfiguration(), + LdapConfiguration.class ) ); + } + if ( archivaRuntimeConfiguration.getLdapConfiguration() == null ) { // prevent NPE diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js index 77cc9282b..652c7e3fa 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js @@ -1151,28 +1151,28 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" } - ArchivaRuntimeConfiguration=function(userManagerImpl,archivaLdapConfiguration,migratedFromRedbackConfiguration,configurationProperties){ + ArchivaRuntimeConfiguration=function(userManagerImpl,ldapConfiguration,migratedFromRedbackConfiguration,configurationPropertiesEntries){ this.userManagerImpl=ko.observable(userManagerImpl); - this.archivaLdapConfiguration=ko.observable(archivaLdapConfiguration); + this.ldapConfiguration=ko.observable(ldapConfiguration); this.migratedFromRedbackConfiguration=ko.observable(migratedFromRedbackConfiguration); - this.configurationProperties=ko.observableArray(configurationProperties?configurationProperties:[]); + this.configurationPropertiesEntries=ko.observableArray(configurationPropertiesEntries?configurationPropertiesEntries:[]); } mapArchivaRuntimeConfiguration=function(data){ - var configurationProperties = data.configurationProperties == null ? []: $.each(data.configurationProperties,function(item){ + var configurationPropertiesEntries = data.configurationPropertiesEntries == null ? []: $.each(data.configurationPropertiesEntries,function(item){ return new Entry(item.key, item.value); }); - if (!$.isArray(configurationProperties)){ - configurationProperties=[]; + if (!$.isArray(configurationPropertiesEntries)){ + configurationPropertiesEntries=[]; } return new ArchivaRuntimeConfiguration(data.userManagerImpl,mapLdapConfiguration(data.ldapConfiguration),data.migratedFromRedbackConfiguration, - configurationProperties); + configurationPropertiesEntries); } LdapConfiguration=function(hostName,port,ssl,baseDn,contextFactory,bindDn,password,authenticationMethod, - extraProperties){ + extraPropertiesEntries){ //private String hostName; this.hostName=ko.observable(hostName); @@ -1197,20 +1197,19 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout" //private String authenticationMethod; this.authenticationMethod=ko.observable(authenticationMethod); - //private Map extraProperties = new HashMap(); - this.extraProperties=ko.observableArray(extraProperties); + this.extraPropertiesEntries=ko.observableArray(extraPropertiesEntries); } mapLdapConfiguration=function(data){ if(data){ - var extraProperties = data.extraProperties == null ? []: $.each(data.extraProperties,function(item){ + var extraPropertiesEntries = data.extraPropertiesEntries == null ? []: $.each(data.extraPropertiesEntries,function(item){ return new Entry(item.key, item.value); }); - if (!$.isArray(extraProperties)){ - extraProperties=[]; + if (!$.isArray(extraPropertiesEntries)){ + extraPropertiesEntries=[]; } - return new ArchivaLdapConfiguration(data.hostName,data.port,data.ssl,data.baseDn,data.contextFactory,data.bindDn,data.password, - data.authenticationMethod,extraProperties); + return new LdapConfiguration(data.hostName,data.port,data.ssl,data.baseDn,data.contextFactory,data.bindDn,data.password, + data.authenticationMethod,extraPropertiesEntries); } return null; }