From fcfd86cf538d95c156135fba4a402360f8b70fe8 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 26 Sep 2011 16:02:23 +0000 Subject: [PATCH] [MRM-1519] api to configure webappconfiguration git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1175919 13f79535-47bb-0310-9956-ffa450edef68 --- .../model/admin/ArchivaAdministration.java | 7 ++ .../admin/model/beans/UiConfiguration.java | 79 +++++++++++++++++++ .../admin/DefaultArchivaAdministration.java | 45 ++++++++++- .../admin/ArchivaAdministrationTest.java | 34 +++++++- 4 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/UiConfiguration.java diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java index 32515ab2e..bfd271ef4 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; import org.apache.archiva.admin.model.beans.OrganisationInformation; +import org.apache.archiva.admin.model.beans.UiConfiguration; import java.util.List; @@ -90,4 +91,10 @@ public interface ArchivaAdministration void setOrganisationInformation( OrganisationInformation organisationInformation ) throws RepositoryAdminException; + UiConfiguration getUiConfiguration() + throws RepositoryAdminException; + + void updateUiConfiguration( UiConfiguration uiConfiguration ) + throws RepositoryAdminException; + } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/UiConfiguration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/UiConfiguration.java new file mode 100644 index 000000000..f9eba943d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/UiConfiguration.java @@ -0,0 +1,79 @@ +package org.apache.archiva.admin.model.beans; +/* + * 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. + */ + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +@XmlRootElement( name = "uiConfiguration" ) +public class UiConfiguration +{ + /** + * true if find artifacts should be enabled. + */ + private boolean showFindArtifacts = true; + + /** + * true if applet behavior for find artifacts should be enabled. + */ + private boolean appletFindEnabled = true; + + /** + * Field disableEasterEggs. + */ + private boolean disableEasterEggs = false; + + public UiConfiguration() + { + // noop + } + + public boolean isShowFindArtifacts() + { + return showFindArtifacts; + } + + public void setShowFindArtifacts( boolean showFindArtifacts ) + { + this.showFindArtifacts = showFindArtifacts; + } + + public boolean isAppletFindEnabled() + { + return appletFindEnabled; + } + + public void setAppletFindEnabled( boolean appletFindEnabled ) + { + this.appletFindEnabled = appletFindEnabled; + } + + public boolean isDisableEasterEggs() + { + return disableEasterEggs; + } + + public void setDisableEasterEggs( boolean disableEasterEggs ) + { + this.disableEasterEggs = disableEasterEggs; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java index 303ad3445..8cb88007f 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java @@ -25,10 +25,13 @@ import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; import org.apache.archiva.admin.model.beans.OrganisationInformation; +import org.apache.archiva.admin.model.beans.UiConfiguration; import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; import org.apache.archiva.audit.AuditEvent; -import org.apache.commons.lang.StringUtils; import org.apache.archiva.configuration.Configuration; +import org.apache.archiva.configuration.UserInterfaceOptions; +import org.apache.archiva.configuration.WebappConfiguration; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -146,8 +149,7 @@ public class DefaultArchivaAdministration throws RepositoryAdminException { Configuration configuration = getArchivaConfiguration().getConfiguration(); - org.apache.archiva.configuration.FileType fileType = - new org.apache.archiva.configuration.FileType(); + org.apache.archiva.configuration.FileType fileType = new org.apache.archiva.configuration.FileType(); fileType.setId( fileTypeId ); configuration.getRepositoryScanning().removeFileType( fileType ); saveConfiguration( configuration ); @@ -286,7 +288,42 @@ public class DefaultArchivaAdministration saveConfiguration( configuration ); } - //------------------------- + public UiConfiguration getUiConfiguration() + throws RepositoryAdminException + { + WebappConfiguration webappConfiguration = getArchivaConfiguration().getConfiguration().getWebapp(); + if ( webappConfiguration == null ) + { + return null; + } + UserInterfaceOptions userInterfaceOptions = webappConfiguration.getUi(); + if ( userInterfaceOptions == null ) + { + return null; + } + return new BeanReplicator().replicateBean( userInterfaceOptions, UiConfiguration.class ); + } + + public void updateUiConfiguration( UiConfiguration uiConfiguration ) + throws RepositoryAdminException + { + Configuration configuration = getArchivaConfiguration().getConfiguration(); + if ( uiConfiguration != null ) + { + + UserInterfaceOptions userInterfaceOptions = + new BeanReplicator().replicateBean( uiConfiguration, UserInterfaceOptions.class ); + configuration.getWebapp().setUi( userInterfaceOptions ); + } + else + { + configuration.getWebapp().setUi( null ); + } + saveConfiguration( configuration ); + + } + +//------------------------- // //------------------------- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java index 8eb414912..1a3e153fa 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.beans.FileType; import org.apache.archiva.admin.model.beans.LegacyArtifactPath; import org.apache.archiva.admin.model.beans.OrganisationInformation; +import org.apache.archiva.admin.model.beans.UiConfiguration; import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest; import org.apache.archiva.audit.AuditEvent; import org.junit.Test; @@ -170,17 +171,20 @@ public class ArchivaAdministrationTest } - + @Test public void organisationInfoUpdate() throws Exception { OrganisationInformation organisationInformation = archivaAdministration.getOrganisationInformation(); - assertNull( organisationInformation ); + assertNotNull( organisationInformation ); + assertNull( organisationInformation.getLogoLocation() ); + assertNull( organisationInformation.getName() ); + assertNull( organisationInformation.getUrl() ); organisationInformation = new OrganisationInformation(); organisationInformation.setLogoLocation( "http://foo.com/bar.png" ); organisationInformation.setName( "foo org" ); - organisationInformation.setUrl( "http:/foo.com" ); + organisationInformation.setUrl( "http://foo.com" ); archivaAdministration.setOrganisationInformation( organisationInformation ); @@ -191,4 +195,28 @@ public class ArchivaAdministrationTest assertEquals( "http://foo.com", organisationInformation.getUrl() ); } + + @Test + public void uiConfiguration() + throws Exception + { + UiConfiguration ui = archivaAdministration.getUiConfiguration(); + assertNotNull( ui ); + // assert default values + assertFalse( ui.isDisableEasterEggs() ); + assertTrue( ui.isAppletFindEnabled() ); + assertTrue( ui.isShowFindArtifacts() ); + + ui.setAppletFindEnabled( false ); + ui.setShowFindArtifacts( false ); + ui.setDisableEasterEggs( true ); + + archivaAdministration.updateUiConfiguration( ui ); + + ui = archivaAdministration.getUiConfiguration(); + + assertTrue( ui.isDisableEasterEggs() ); + assertFalse( ui.isAppletFindEnabled() ); + assertFalse( ui.isShowFindArtifacts() ); + } }