Author: skygo
Date: Mon Apr 29 22:38:11 2013
New Revision: 1477395
URL: http://svn.apache.org/r1477395
Log:
Add a service and use ajax to build menus
Added:
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java
- copied, changed from r1476327,
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java
- copied, changed from r1476327,
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
Modified:
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js
Copied:
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java
(from r1476327,
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java)
URL:
http://svn.apache.org/viewvc/archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java?p2=archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java&p1=archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java&r1=1476327&r2=1477395&rev=1477395&view=diff
==============================================================================
---
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/CommonServices.java
(original)
+++
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PluginsService.java
Mon Apr 29 22:38:11 2013
@@ -23,50 +23,23 @@ import org.apache.archiva.redback.author
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
/**
- * contains some "free" services (i18n)
+ * contains some services for plugins
*
- * @author Olivier Lamy
- * @since 1.4-M3
+ * @author Eric Barboni
+ * @since 1.4-M4
*/
-@Path( "/commonServices/" )
-public interface CommonServices
+@Path( "/pluginsService/" )
+public interface PluginsService
{
- /**
- * will return properties available in
org/apache/archiva/i18n/default.properties
- * load default (en) then override with locale used so at least en are
returned if no
- * translation in the locale asked.
- */
- @Path( "getI18nResources" )
+ @Path( "getAdminPlugins" )
@GET
@Produces( { MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noRestriction = true )
- String getI18nResources( @QueryParam( "locale" ) String locale )
- throws ArchivaRestServiceException;
-
- /**
- * will return properties available in
org/apache/archiva/i18n/default.properties
- * load default (en) then override with locale used so at least en are
returned if no
- * translation in the locale asked.
- * This method will add redback resources too. note Archva wins
- */
- @Path( "getAllI18nResources" )
- @GET
- @Produces( { MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( noRestriction = true )
- String getAllI18nResources( @QueryParam( "locale" ) String locale )
- throws ArchivaRestServiceException;
-
-
- @Path( "validateCronExpression" )
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @RedbackAuthorization( noRestriction = true )
- Boolean validateCronExpression( @QueryParam( "cronExpression" ) String
cronExpression )
+ String getAdminPlugins( )
throws ArchivaRestServiceException;
}
Copied:
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java
(from r1476327,
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java)
URL:
http://svn.apache.org/viewvc/archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java?p2=archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java&p1=archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java&r1=1476327&r2=1477395&rev=1477395&view=diff
==============================================================================
---
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
(original)
+++
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java
Mon Apr 29 22:38:11 2013
@@ -18,188 +18,59 @@ package org.apache.archiva.rest.services
* under the License.
*/
-import org.apache.archiva.redback.components.scheduler.CronExpressionValidator;
-import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
-import org.apache.archiva.redback.rest.api.services.UtilServices;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
-import org.apache.archiva.rest.api.services.CommonServices;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
-import javax.annotation.PostConstruct;
import javax.inject.Inject;
-import javax.ws.rs.core.Response;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
+import org.apache.archiva.rest.api.services.PluginsService;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.io.Resource;
/**
- * @author Olivier Lamy
+ * @author Eric Barboni
*/
-@Service( "commonServices#rest" )
-public class DefaultCommonServices
- implements CommonServices
+@Service( "pluginsService#rest" )
+public class DefaultPluginsServices
+ implements PluginsService
{
- private static final String RESOURCE_NAME =
"org/apache/archiva/i18n/default";
-
- private Logger log = LoggerFactory.getLogger( getClass() );
-
+ private List<String> repositoryType = new ArrayList<String>();
+
@Inject
- private UtilServices utilServices;
-
- private Map<String, String> cachei18n = new ConcurrentHashMap<String,
String>();
-
- @Inject
- protected CronExpressionValidator cronExpressionValidator;
-
- @PostConstruct
- public void init()
- throws ArchivaRestServiceException
- {
-
- // preload i18n en and fr
- getAllI18nResources( "en" );
- getAllI18nResources( "fr" );
- }
-
- public String getI18nResources( String locale )
- throws ArchivaRestServiceException
- {
- Properties properties = new Properties();
-
- StringBuilder resourceName = new StringBuilder( RESOURCE_NAME );
- try
- {
-
- loadResource( properties, resourceName, locale );
-
- }
- catch ( IOException e )
- {
- log.warn( "skip error loading properties {}",
resourceName.toString() );
- }
-
- return fromProperties( properties );
- }
-
- private void loadResource( Properties properties, StringBuilder
resourceName, String locale )
- throws IOException
- {
- // load default
- loadResource( properties, new StringBuilder( resourceName ).append(
".properties" ).toString(), locale );
- // if locale override with locale content
- if ( StringUtils.isNotEmpty( locale ) )
- {
- loadResource( properties,
- new StringBuilder( resourceName ).append( "_" +
locale ).append( ".properties" ).toString(),
- locale );
- }
-
- }
-
- private String fromProperties( final Properties properties )
- {
- StringBuilder output = new StringBuilder();
-
- for ( Map.Entry<Object, Object> entry : properties.entrySet() )
- {
- output.append( (String) entry.getKey() ).append( '=' ).append(
(String) entry.getValue() );
- output.append( '\n' );
- }
-
- return output.toString();
- }
-
- private void loadResource( final Properties finalProperties, String
resourceName, String locale )
- throws IOException
+ public DefaultPluginsServices( ApplicationContext applicationContext )
{
- InputStream is = null;
- Properties properties = new Properties();
- try
- {
- is =
Thread.currentThread().getContextClassLoader().getResourceAsStream(
resourceName );
- if ( is != null )
+ Resource[] xmlResources;
+ try {
+ xmlResources = applicationContext.getResources(
"/**/repository/**/main.js" );
+ for (Resource rc : xmlResources)
{
- properties.load( is );
- finalProperties.putAll( properties );
+ String tmp = rc.getURL().toString();
+ tmp = tmp.substring( tmp.lastIndexOf("repository") + 11,
tmp.length() - 8 );
+ repositoryType.add( tmp );
}
- else
- {
- if ( !StringUtils.equalsIgnoreCase( locale, "en" ) )
- {
- log.info( "cannot load resource {}", resourceName );
- }
- }
- }
- finally
- {
- IOUtils.closeQuietly( is );
+ } catch (IOException ex) {
+
}
+
}
-
- public String getAllI18nResources( String locale )
+
+ @Override
+ public String getAdminPlugins()
throws ArchivaRestServiceException
{
-
- String cachedi18n = cachei18n.get( StringUtils.isEmpty( locale ) ?
"en" : StringUtils.lowerCase( locale ) );
- if ( cachedi18n != null )
- {
- return cachedi18n;
- }
-
- try
- {
-
- Properties all = utilServices.getI18nProperties( locale );
- StringBuilder resourceName = new StringBuilder( RESOURCE_NAME );
- loadResource( all, resourceName, locale );
-
- String i18n = fromProperties( all );
- cachei18n.put( StringUtils.isEmpty( locale ) ? "en" :
StringUtils.lowerCase( locale ), i18n );
- return i18n;
- }
- catch ( IOException e )
- {
- throw new ArchivaRestServiceException( e.getMessage(),
-
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
- }
- catch ( RedbackServiceException e )
- {
- throw new ArchivaRestServiceException( e.getMessage(),
e.getHttpErrorCode(), e );
- }
+ // rebuild
+ String baseRepo = "archiva/admin/repository/";
+ StringBuilder sb = new StringBuilder();
+ for (String repoType : repositoryType)
+ {
+ sb.append( baseRepo ).append( repoType ).append( "/main" ).append(
"|" );
+ }
+
+ return sb.substring( 0, sb.length() - 1);
+
}
- private void loadFromString( String propsStr, Properties properties )
- throws ArchivaRestServiceException
- {
- InputStream inputStream = null;
- try
- {
- inputStream = new ByteArrayInputStream( propsStr.getBytes() );
- properties.load( inputStream );
- }
- catch ( IOException e )
- {
- throw new ArchivaRestServiceException( e.getMessage(),
-
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
- }
- finally
- {
- IOUtils.closeQuietly( inputStream );
- }
- }
-
-
- public Boolean validateCronExpression( String cronExpression )
- throws ArchivaRestServiceException
- {
- return cronExpressionValidator.validate( cronExpression );
- }
}
Modified:
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
URL:
http://svn.apache.org/viewvc/archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml?rev=1477395&r1=1477394&r2=1477395&view=diff
==============================================================================
---
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
(original)
+++
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
Mon Apr 29 22:38:11 2013
@@ -68,6 +68,7 @@
<ref bean="searchService#rest"/>
<ref bean="commonServices#rest"/>
<ref bean="browseService#rest"/>
+ <ref bean="pluginsService#rest"/>
<ref bean="systemStatusService#rest"/>
<ref bean="reportRepositoriesService#rest" />
<ref bean="mergeRepositoriesService#rest"/>
Modified:
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js
URL:
http://svn.apache.org/viewvc/archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js?rev=1477395&r1=1477394&r2=1477395&view=diff
==============================================================================
---
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js
(original)
+++
archiva/branches/archiva-MRM-1756/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/main.js
Mon Apr 29 22:38:11 2013
@@ -226,15 +226,21 @@ function(jquery,ui,sammy,tmpl,i18n,jquer
this.administrationMenuItems = ko.observableArray([
{text: $.i18n.prop('menu.administration'), id: null} ]);
-
- var myrepplugins =
"archiva/admin/repository/legacy/main|archiva/admin/repository/maven2/main";
- $.each(myrepplugins.split("|"), function(key, value) {
- alert(value);
- require([value], function() {
+ var pluginsURL =
"restServices/archivaServices/pluginsService/getAdminPlugins";
+ $.ajax(pluginsURL, {
+ type: "GET",
+ dataType: 'text',
+ success: function(data) {
+ $.each(data.split("|"), function(key, value) {
+ require([value], function() {
showMenu(self.administrationMenuItems);
});
});
+ }
+ });
+ //var myrepplugins =
"archiva/admin/repository/legacy/main|archiva/admin/repository/maven2/main";
+
self.administrationMenuItems.push({ text :
$.i18n.prop('menu.network-proxies') , id:
"menu-network-proxies-list-a" , href: "#networkproxies" , redback:
"{permissions: ['archiva-manage-configuration']}", func:
function(){displayNetworkProxies()}});
self.administrationMenuItems.push({ text :
$.i18n.prop('menu.repository-scanning') , id:
"menu-repository-scanning-list-a" , href: "#scanningList" , redback:
"{permissions: ['archiva-manage-configuration']}", func:
function(){displayRepositoryScanning()}});
self.administrationMenuItems.push({ text :
$.i18n.prop('menu.runtime-configuration') , id:
"menu-runtime-configuration-list-a" , href: "#runtimeconfig" , redback:
"{permissions: ['archiva-manage-configuration']}", func:
function(){displayRuntimeConfiguration()}});