[MRM-1490] REST services : organisation configuration methods

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1167473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-10 07:34:10 +00:00
parent 3c92bc1b40
commit 1f05224168
6 changed files with 282 additions and 2 deletions

View File

@ -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();
}
}

View File

@ -30,7 +30,8 @@
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-security</artifactId>
<artifactId>archiva-security-common</artifactId>
</dependency>
<dependency>

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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() );
}
}
}

View File

@ -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;
@ -74,4 +76,31 @@ public class ArchivaAdministrationServiceTest
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() );
}
}