]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1490] REST services : organisation configuration methods
authorOlivier Lamy <olamy@apache.org>
Sat, 10 Sep 2011 07:34:10 +0000 (07:34 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 10 Sep 2011 07:34:10 +0000 (07:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1167473 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/OrganisationInformation.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/OrganisationInformation.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.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 (file)
index 0000000..77bd06d
--- /dev/null
@@ -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();
+    }
+}
index 005a95101feed3612b1ec822d9bdb5ec44ce29f0..79d833ea1351595b8aec0179d6cd2305b1cc2353 100644 (file)
@@ -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 (file)
index 0000000..648823c
--- /dev/null
@@ -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();
+    }
+}
index 81912a8a7d67c425d4ae653fdf4c981b820948fc..19f9c7f790043380a59a7483a23a0c17fb4c445e 100644 (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;
 }
+
index 89ffb59b08ae764f267ddab1cfe26a620089362e..522779395012babaec763c01db8f9033c641ebb7 100644 (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() );
+        }
+    }
 }
index 32bc95e01ef83303f64bedc3940f24ed769c89cf..c6656fc317f4696d71b5b501b23e96a8f692e257 100644 (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;
@@ -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() );
+    }
 }