import org.apache.archiva.admin.model.beans.NetworkConfiguration;
import org.apache.archiva.admin.model.beans.OrganisationInformation;
import org.apache.archiva.admin.model.beans.UiConfiguration;
+import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
List<String> getKnownContentConsumers()
throws ArchivaRestServiceException;
+ @Path( "getKnownContentAdminRepositoryConsumers" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+ @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ /**
+ * @since 1.4-M3
+ */
+ List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
+ throws ArchivaRestServiceException;
+
+ @Path( "getInvalidContentAdminRepositoryConsumers" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+ @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ /**
+ * @since 1.4-M3
+ */
+ List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
+ throws ArchivaRestServiceException;
+
@Path( "getInvalidContentConsumers" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
import org.apache.archiva.admin.model.beans.UiConfiguration;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
+import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
+import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
+import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
@Named( value = "managedRepositoryContent#legacy" )
private ManagedRepositoryContent repositoryContent;
+ @Inject
+ private RepositoryContentConsumers repoConsumerUtil;
+
public List<LegacyArtifactPath> getLegacyArtifactPaths()
throws ArchivaRestServiceException
{
throw new ArchivaRestServiceException( e.getMessage() );
}
}
+
+ public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
+ throws ArchivaRestServiceException
+ {
+ try
+ {
+ AddAdminRepoConsumerClosure addAdminRepoConsumer =
+ new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
+ CollectionUtils.forAllDo( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
+ List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
+ Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
+ return knownContentConsumers;
+ }
+ catch ( RepositoryAdminException e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage() );
+ }
+ }
+
+ public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
+ throws ArchivaRestServiceException
+ {
+ try
+ {
+ AddAdminRepoConsumerClosure addAdminRepoConsumer =
+ new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
+ CollectionUtils.forAllDo( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
+ List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
+ Collections.sort( invalidContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
+ return invalidContentConsumers;
+ }
+ catch ( RepositoryAdminException e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage() );
+ }
+ }
}
--- /dev/null
+package org.apache.archiva.rest.services.utils;
+
+/*
+ * 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 org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
+import org.apache.commons.collections.Closure;
+import org.apache.archiva.consumers.RepositoryContentConsumer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * AddAdminRepoConsumerClosure
+ *
+ * @version $Id$
+ */
+public class AddAdminRepoConsumerClosure
+ implements Closure
+{
+ private List<AdminRepositoryConsumer> list = new ArrayList<AdminRepositoryConsumer>();
+
+ private List<String> selectedIds;
+
+ public AddAdminRepoConsumerClosure( List<String> selectedIds )
+ {
+ this.selectedIds = selectedIds;
+ }
+
+ public void execute( Object input )
+ {
+ if ( input instanceof RepositoryContentConsumer )
+ {
+ RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
+
+ boolean enabled = this.selectedIds.contains( consumer.getId() );
+ AdminRepositoryConsumer adminconsumer = new AdminRepositoryConsumer();
+ adminconsumer.setEnabled( enabled );
+ adminconsumer.setId( consumer.getId() );
+ adminconsumer.setDescription( consumer.getDescription() );
+
+ list.add( adminconsumer );
+ }
+ }
+
+ public List<AdminRepositoryConsumer> getList()
+ {
+ return list;
+ }
+}
--- /dev/null
+package org.apache.archiva.rest.services.utils;
+
+/*
+ * 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 org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
+
+import java.util.Comparator;
+
+/**
+ * AdminRepositoryConsumerComparator
+ *
+ * @version $Id$
+ */
+public class AdminRepositoryConsumerComparator
+ implements Comparator<AdminRepositoryConsumer>
+{
+ private static AdminRepositoryConsumerComparator INSTANCE = new AdminRepositoryConsumerComparator();
+
+ public static AdminRepositoryConsumerComparator getInstance()
+ {
+ return INSTANCE;
+ }
+
+ public int compare( AdminRepositoryConsumer o1, AdminRepositoryConsumer o2 )
+ {
+ if ( o1 == null && o2 == null )
+ {
+ return 0;
+ }
+
+ if ( o1 == null && o2 != null )
+ {
+ return 1;
+ }
+
+ if ( o1 != null && o2 == null )
+ {
+ return -1;
+ }
+
+ String id1 = o1.getId();
+ String id2 = o2.getId();
+ return id1.compareToIgnoreCase( id2 );
+ }
+}
import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
import org.apache.archiva.admin.model.beans.OrganisationInformation;
import org.apache.archiva.admin.model.beans.UiConfiguration;
+import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import java.util.Arrays;
+import java.util.List;
/**
* @author Olivier Lamy
assertFalse( ui.isAppletFindEnabled() );
assertFalse( ui.isShowFindArtifacts() );
}
+
+ @Test
+ public void getKnownContentAdminRepositoryConsumer()
+ throws Exception
+ {
+ List<AdminRepositoryConsumer> consumers =
+ getArchivaAdministrationService().getKnownContentAdminRepositoryConsumers();
+ assertFalse( consumers.isEmpty() );
+ }
+
+ @Test
+ public void getInvalidContentAdminRepositoryConsumer()
+ throws Exception
+ {
+ List<AdminRepositoryConsumer> consumers =
+ getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
+ assertFalse( consumers.isEmpty() );
+ assertAllDisabled( consumers );
+
+ getArchivaAdministrationService().addInvalidContentConsumer( "foo" );
+
+ consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
+ assertFalse( consumers.isEmpty() );
+ assertAllEnabled( consumers );
+
+
+ getArchivaAdministrationService().removeInvalidContentConsumer( "foo" );
+
+ consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
+
+ assertAllDisabled( consumers );
+
+ assertFalse( consumers.isEmpty() );
+ }
+
+ private void assertAllEnabled( List<AdminRepositoryConsumer> consumers )
+ {
+ for ( AdminRepositoryConsumer consumer : consumers )
+ {
+ assertTrue( consumer.isEnabled() );
+ }
+ }
+
+ private void assertAllDisabled( List<AdminRepositoryConsumer> consumers )
+ {
+ for ( AdminRepositoryConsumer consumer : consumers )
+ {
+ assertFalse( consumer.isEnabled() );
+ }
+ }
}
--- /dev/null
+package org.apache.archiva.rest.services.utils;
+/*
+ * 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 org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.consumers.ConsumerException;
+import org.apache.archiva.consumers.ConsumerMonitor;
+import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service( "InvalidRepositoryContentConsumer#mock" )
+public class MockInvalidRepositoryContentConsumer
+ implements InvalidRepositoryContentConsumer
+{
+ public String getId()
+ {
+ return "foo";
+ }
+
+ public String getDescription()
+ {
+ return "the foo";
+ }
+
+ public boolean isPermanent()
+ {
+ return false;
+ }
+
+ public void addConsumerMonitor( ConsumerMonitor monitor )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeConsumerMonitor( ConsumerMonitor monitor )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<String> getIncludes()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<String> getExcludes()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void beginScan( ManagedRepository repository, Date whenGathered )
+ throws ConsumerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
+ throws ConsumerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void processFile( String path )
+ throws ConsumerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void processFile( String path, boolean executeOnEntireRepo )
+ throws Exception
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void completeScan()
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void completeScan( boolean executeOnEntireRepo )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isProcessUnmodified()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
+++ /dev/null
-package org.apache.archiva.web.action.admin.scanning;
-
-/*
- * 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 org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
-import org.apache.commons.collections.Closure;
-import org.apache.archiva.consumers.RepositoryContentConsumer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * AddAdminRepoConsumerClosure
- *
- * @version $Id$
- */
-public class AddAdminRepoConsumerClosure
- implements Closure
-{
- private List<AdminRepositoryConsumer> list = new ArrayList<AdminRepositoryConsumer>();
-
- private List<String> selectedIds;
-
- public AddAdminRepoConsumerClosure( List<String> selectedIds )
- {
- this.selectedIds = selectedIds;
- }
-
- public void execute( Object input )
- {
- if ( input instanceof RepositoryContentConsumer )
- {
- RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
-
- boolean enabled = this.selectedIds.contains( consumer.getId() );
- AdminRepositoryConsumer adminconsumer = new AdminRepositoryConsumer();
- adminconsumer.setEnabled( enabled );
- adminconsumer.setId( consumer.getId() );
- adminconsumer.setDescription( consumer.getDescription() );
-
- list.add( adminconsumer );
- }
- }
-
- public List<AdminRepositoryConsumer> getList()
- {
- return list;
- }
-}
+++ /dev/null
-package org.apache.archiva.web.action.admin.scanning;
-
-/*
- * 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 org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
-
-import java.util.Comparator;
-
-/**
- * AdminRepositoryConsumerComparator
- *
- * @version $Id$
- */
-public class AdminRepositoryConsumerComparator
- implements Comparator<AdminRepositoryConsumer>
-{
- private static AdminRepositoryConsumerComparator INSTANCE = new AdminRepositoryConsumerComparator();
-
- public static AdminRepositoryConsumerComparator getInstance()
- {
- return INSTANCE;
- }
-
- public int compare( AdminRepositoryConsumer o1, AdminRepositoryConsumer o2 )
- {
- if ( o1 == null && o2 == null )
- {
- return 0;
- }
-
- if ( o1 == null && o2 != null )
- {
- return 1;
- }
-
- if ( o1 != null && o2 == null )
- {
- return -1;
- }
-
- String id1 = o1.getId();
- String id2 = o2.getId();
- return id1.compareToIgnoreCase( id2 );
- }
-}
import org.apache.archiva.audit.Auditable;
import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
+import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
+import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;