void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
throws RepositoryAdminException;
+
+ RepositoryScanning getRepositoryScanning()
+ throws RepositoryAdminException;
+
+ void updateRepositoryScanning( RepositoryScanning repositoryScanning, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ FileType getFileType( String fileTypeId )
+ throws RepositoryAdminException;
+
+ void addFileType( FileType fileType, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ void removeFileType( String fileTypeId, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ void addInvalidContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ void removeInvalidContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
}
import org.apache.archiva.admin.AuditInformation;
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.audit.AuditEvent;
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
}
return legacyArtifactPaths;
+
}
public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
org.apache.maven.archiva.configuration.LegacyArtifactPath.class ) );
saveConfiguration( configuration );
+ triggerAuditEvent( "", "", AuditEvent.ADD_LEGACY_PATH, auditInformation );
}
public void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
configuration.removeLegacyArtifactPath( legacyArtifactPath );
saveConfiguration( configuration );
+ triggerAuditEvent( "", "", AuditEvent.REMOVE_LEGACY_PATH, auditInformation );
+ }
+
+ public void updateRepositoryScanning( RepositoryScanning repositoryScanning, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+ configuration.setRepositoryScanning(
+ new BeanReplicator().replicateBean( repositoryScanning, RepositoryScanningConfiguration.class ) );
+
+ saveConfiguration( configuration );
+ }
+
+ public RepositoryScanning getRepositoryScanning()
+ throws RepositoryAdminException
+ {
+ return new BeanReplicator().replicateBean( getArchivaConfiguration().getConfiguration().getRepositoryScanning(),
+ RepositoryScanning.class );
+ }
+
+ public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+ org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
+ if ( fileType == null )
+ {
+ return;
+ }
+ fileType.addPattern( pattern );
+
+ saveConfiguration( configuration );
+ }
+
+ public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+ org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
+ if ( fileType == null )
+ {
+ return;
+ }
+ fileType.removePattern( pattern );
+
+ saveConfiguration( configuration );
+ }
+
+ public FileType getFileType( String fileTypeId )
+ throws RepositoryAdminException
+ {
+ org.apache.maven.archiva.configuration.FileType fileType =
+ getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
+ if ( fileType == null )
+ {
+ return null;
+ }
+ return new BeanReplicator().replicateBean( fileType, FileType.class );
+ }
+
+ public void addFileType( FileType fileType, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ if ( getFileTypeById( fileType.getId(), configuration ) != null )
+ {
+ throw new RepositoryAdminException(
+ "impossible to FileType with id " + fileType.getId() + " already exists" );
+ }
+
+ configuration.getRepositoryScanning().addFileType(
+ new BeanReplicator().replicateBean( fileType, org.apache.maven.archiva.configuration.FileType.class ) );
+ saveConfiguration( configuration );
+ }
+
+ public void removeFileType( String fileTypeId, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ org.apache.maven.archiva.configuration.FileType fileType =
+ new org.apache.maven.archiva.configuration.FileType();
+ fileType.setId( fileTypeId );
+ configuration.getRepositoryScanning().removeFileType( fileType );
+ saveConfiguration( configuration );
+ }
+
+ public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
+ saveConfiguration( configuration );
+ triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
+ }
+
+ public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
+ saveConfiguration( configuration );
+ triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
+ }
+
+ public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
+ saveConfiguration( configuration );
+ triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
+ }
+
+ public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
+ saveConfiguration( configuration );
+ triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
+ }
+
+//-------------------------
+ //
+ //-------------------------
+
+ private org.apache.maven.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
+ {
+ for ( org.apache.maven.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
+ {
+ if ( StringUtils.equals( id, fileType.getId() ) )
+ {
+ return fileType;
+ }
+ }
+ return null;
}
}
*/
import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.junit.Test;
import javax.inject.Inject;
+import java.util.Arrays;
/**
* @author Olivier Lamy
@Test
- public void getAll()
+ public void getAllLegacyPaths()
throws Exception
{
assertNotNull( archivaAdministration.getLegacyArtifactPaths() );
log.info( "all legacy paths {}", archivaAdministration.getLegacyArtifactPaths() );
}
- public void addAndDelete()
+ public void addAndDeleteLegacyPath()
throws Exception
{
int initialSize = archivaAdministration.getLegacyArtifactPaths().size();
archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
assertEquals( initialSize, archivaAdministration.getLegacyArtifactPaths().size() );
}
+
+ @Test
+ public void addAndUpdateAndDeleteFileType()
+ throws RepositoryAdminException
+ {
+ int initialSize = archivaAdministration.getRepositoryScanning().getFileTypes().size();
+
+ FileType fileType = new FileType();
+ fileType.setId( "foo" );
+ fileType.setPatterns( Arrays.asList( "bar", "toto" ) );
+
+ archivaAdministration.addFileType( fileType, getFakeAuditInformation() );
+
+ assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
+
+ archivaAdministration.addFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
+
+ assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
+
+ assertEquals( 3, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
+
+ assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
+ assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
+ assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
+
+ archivaAdministration.removeFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
+
+ assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
+
+ assertEquals( 2, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
+
+ assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
+ assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
+ assertFalse( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
+
+ archivaAdministration.removeFileType( "foo", getFakeAuditInformation() );
+
+ assertEquals( initialSize, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
+ assertNull( archivaAdministration.getFileType( "foo" ) );
+ }
}
return saveConfiguration();
}
+ public String removeFiletypePattern()
+ {
+ log.info( "Remove File Type Pattern [" + getFileTypeId() + ":" + getPattern() + "]" );
+
+ if ( !isValidFiletypeCommand() )
+ {
+ return INPUT;
+ }
+
+ FileType filetype = findFileType( getFileTypeId() );
+ if ( filetype == null )
+ {
+ addActionError( "Pattern not removed, unable to find filetype " + getFileTypeId() );
+ return INPUT;
+ }
+
+ filetype.removePattern( getPattern() );
+
+ triggerAuditEvent( AuditEvent.REMOVE_PATTERN + " " + pattern );
+
+ return saveConfiguration();
+ }
+
public String getFileTypeId()
{
return fileTypeId;
CollectionUtils.forAllDo( reposcanning.getFileTypes(), filetypeToMapClosure );
fileTypeMap = filetypeToMapClosure.getMap();
- AddAdminRepoConsumerClosure addAdminRepoConsumer;
-
- addAdminRepoConsumer = new AddAdminRepoConsumerClosure( reposcanning.getKnownContentConsumers() );
+ AddAdminRepoConsumerClosure addAdminRepoConsumer =
+ new AddAdminRepoConsumerClosure( reposcanning.getKnownContentConsumers() );
CollectionUtils.forAllDo( repoconsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
this.knownContentConsumers = addAdminRepoConsumer.getList();
Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
Collections.sort( fileTypeIds );
}
- public String removeFiletypePattern()
- {
- log.info( "Remove File Type Pattern [" + getFileTypeId() + ":" + getPattern() + "]" );
-
- if ( !isValidFiletypeCommand() )
- {
- return INPUT;
- }
-
- FileType filetype = findFileType( getFileTypeId() );
- if ( filetype == null )
- {
- addActionError( "Pattern not removed, unable to find filetype " + getFileTypeId() );
- return INPUT;
- }
-
- filetype.removePattern( getPattern() );
-
- triggerAuditEvent( AuditEvent.REMOVE_PATTERN + " " + pattern );
-
- return saveConfiguration();
- }
-
public void setFileTypeId( String fileTypeId )
{
this.fileTypeId = fileTypeId;