From 1f05224168a754378929640cd7f2a067f702c226 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 10 Sep 2011 07:34:10 +0000 Subject: [PATCH] [MRM-1490] REST services : organisation configuration methods git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1167473 13f79535-47bb-0310-9956-ffa450edef68 --- .../admin/OrganisationInformation.java | 95 ++++++++++++++++++ .../archiva-rest/archiva-rest-api/pom.xml | 3 +- .../api/model/OrganisationInformation.java | 98 +++++++++++++++++++ .../ArchivaAdministrationService.java | 16 +++ .../DefaultArchivaAdministrationService.java | 41 ++++++++ .../ArchivaAdministrationServiceTest.java | 31 +++++- 6 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/OrganisationInformation.java create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/OrganisationInformation.java diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/OrganisationInformation.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/OrganisationInformation.java new file mode 100644 index 000000000..77bd06d0d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/OrganisationInformation.java @@ -0,0 +1,95 @@ +package org.apache.archiva.admin.repository.admin; +/* + * 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. + */ + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public class OrganisationInformation +{ + /** + * name of the organisation. + */ + private String name; + + /** + * name of the organisation. + */ + private String url; + + /** + * name of the organisation. + */ + private String logoLocation; + + public OrganisationInformation() + { + // no op + } + + public OrganisationInformation( String name, String url, String logoLocation ) + { + this.name = name; + this.url = url; + this.logoLocation = logoLocation; + } + + public String getName() + { + return name; + } + + public void setName( String name ) + { + this.name = name; + } + + public String getUrl() + { + return url; + } + + public void setUrl( String url ) + { + this.url = url; + } + + public String getLogoLocation() + { + return logoLocation; + } + + public void setLogoLocation( String logoLocation ) + { + this.logoLocation = logoLocation; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "OrganisationInformation" ); + sb.append( "{name='" ).append( name ).append( '\'' ); + sb.append( ", url='" ).append( url ).append( '\'' ); + sb.append( ", logoLocation='" ).append( logoLocation ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml index 005a95101..79d833ea1 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml @@ -30,7 +30,8 @@ org.apache.archiva - archiva-security + archiva-security-common + diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/OrganisationInformation.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/OrganisationInformation.java new file mode 100644 index 000000000..648823c8d --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/OrganisationInformation.java @@ -0,0 +1,98 @@ +package org.apache.archiva.rest.api.model; +/* + * 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 = "organisationInformation" ) +public class OrganisationInformation +{ + /** + * name of the organisation. + */ + private String name; + + /** + * name of the organisation. + */ + private String url; + + /** + * name of the organisation. + */ + private String logoLocation; + + public OrganisationInformation() + { + // no op + } + + public OrganisationInformation( String name, String url, String logoLocation ) + { + this.name = name; + this.url = url; + this.logoLocation = logoLocation; + } + + public String getName() + { + return name; + } + + public void setName( String name ) + { + this.name = name; + } + + public String getUrl() + { + return url; + } + + public void setUrl( String url ) + { + this.url = url; + } + + public String getLogoLocation() + { + return logoLocation; + } + + public void setLogoLocation( String logoLocation ) + { + this.logoLocation = logoLocation; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "OrganisationInformation" ); + sb.append( "{name='" ).append( name ).append( '\'' ); + sb.append( ", url='" ).append( url ).append( '\'' ); + sb.append( ", logoLocation='" ).append( logoLocation ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java index 81912a8a7..19f9c7f79 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java @@ -20,6 +20,7 @@ package org.apache.archiva.rest.api.services; import org.apache.archiva.rest.api.model.FileType; import org.apache.archiva.rest.api.model.LegacyArtifactPath; +import org.apache.archiva.rest.api.model.OrganisationInformation; import org.apache.archiva.security.common.ArchivaRoleConstants; import org.codehaus.plexus.redback.authorization.RedbackAuthorization; @@ -160,4 +161,19 @@ public interface ArchivaAdministrationService @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) List getInvalidContentConsumers() throws ArchivaRestServiceException; + + @Path( "getOrganisationInformation" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + OrganisationInformation getOrganisationInformation() + throws ArchivaRestServiceException; + + @Path( "setOrganisationInformation" ) + @POST + @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + void setOrganisationInformation( OrganisationInformation organisationInformation ) + throws ArchivaRestServiceException; } + diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java index 89ffb59b0..522779395 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.repository.RepositoryAdminException; import org.apache.archiva.admin.repository.admin.ArchivaAdministration; import org.apache.archiva.rest.api.model.FileType; import org.apache.archiva.rest.api.model.LegacyArtifactPath; +import org.apache.archiva.rest.api.model.OrganisationInformation; import org.apache.archiva.rest.api.services.ArchivaAdministrationService; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.springframework.stereotype.Service; @@ -300,4 +301,44 @@ public class DefaultArchivaAdministrationService throw new ArchivaRestServiceException( e.getMessage() ); } } + + public OrganisationInformation getOrganisationInformation() + throws ArchivaRestServiceException + { + try + { + org.apache.archiva.admin.repository.admin.OrganisationInformation organisationInformation = + archivaAdministration.getOrganisationInformation(); + + return organisationInformation == null + ? null + : new BeanReplicator().replicateBean( organisationInformation, OrganisationInformation.class ); + } + catch ( RepositoryAdminException e ) + { + throw new ArchivaRestServiceException( e.getMessage() ); + } + } + + public void setOrganisationInformation( OrganisationInformation organisationInformation ) + throws ArchivaRestServiceException + { + try + { + if ( organisationInformation == null ) + { + archivaAdministration.setOrganisationInformation( null ); + } + else + { + archivaAdministration.setOrganisationInformation( + new BeanReplicator().replicateBean( organisationInformation, + org.apache.archiva.admin.repository.admin.OrganisationInformation.class ) ); + } + } + catch ( RepositoryAdminException e ) + { + throw new ArchivaRestServiceException( e.getMessage() ); + } + } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java index 32bc95e01..c6656fc31 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java @@ -20,6 +20,8 @@ package org.apache.archiva.rest.services; import org.apache.archiva.rest.api.model.FileType; import org.apache.archiva.rest.api.model.LegacyArtifactPath; +import org.apache.archiva.rest.api.model.OrganisationInformation; +import org.apache.commons.lang.StringUtils; import org.junit.Test; import java.util.Arrays; @@ -70,8 +72,35 @@ public class ArchivaAdministrationServiceTest getArchivaAdministrationService().removeFileType( "footwo" ); - assertEquals( initialSize , getArchivaAdministrationService().getFileTypes().size() ); + assertEquals( initialSize, getArchivaAdministrationService().getFileTypes().size() ); assertNull( getArchivaAdministrationService().getFileType( "footwo" ) ); } + + @Test + public void organisationInformationUpdate() + throws Exception + { + OrganisationInformation organisationInformation = + getArchivaAdministrationService().getOrganisationInformation(); + + // rest return an empty bean + assertNotNull( organisationInformation ); + assertTrue( StringUtils.isBlank( organisationInformation.getLogoLocation() ) ); + assertTrue( StringUtils.isBlank( organisationInformation.getName() ) ); + assertTrue( StringUtils.isBlank( organisationInformation.getUrl() ) ); + + organisationInformation = new OrganisationInformation(); + organisationInformation.setLogoLocation( "http://foo.com/bar.png" ); + organisationInformation.setName( "foo org" ); + organisationInformation.setUrl( "http://foo.com" ); + + getArchivaAdministrationService().setOrganisationInformation( organisationInformation ); + + organisationInformation = getArchivaAdministrationService().getOrganisationInformation(); + assertNotNull( organisationInformation ); + assertEquals( "http://foo.com/bar.png", organisationInformation.getLogoLocation() ); + assertEquals( "foo org", organisationInformation.getName() ); + assertEquals( "http://foo.com", organisationInformation.getUrl() ); + } } -- 2.39.5