diff options
6 files changed, 282 insertions, 2 deletions
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 @@ <dependencies> <dependency> <groupId>org.apache.archiva</groupId> - <artifactId>archiva-security</artifactId> + <artifactId>archiva-security-common</artifactId> + </dependency> <dependency> 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<String> 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() ); + } } |