mirror of https://github.com/apache/archiva.git
record license information in cassandra
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581637 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
663de30beb
commit
fa06b7b997
|
@ -47,6 +47,7 @@ public class License
|
||||||
|
|
||||||
public License()
|
public License()
|
||||||
{
|
{
|
||||||
|
// no op
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
|
|
|
@ -52,4 +52,6 @@ public interface CassandraArchivaManager
|
||||||
|
|
||||||
String getMailingListFamilyName();
|
String getMailingListFamilyName();
|
||||||
|
|
||||||
|
String getLicenseFamilyName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||||
import org.apache.archiva.metadata.model.CiManagement;
|
import org.apache.archiva.metadata.model.CiManagement;
|
||||||
import org.apache.archiva.metadata.model.FacetedMetadata;
|
import org.apache.archiva.metadata.model.FacetedMetadata;
|
||||||
import org.apache.archiva.metadata.model.IssueManagement;
|
import org.apache.archiva.metadata.model.IssueManagement;
|
||||||
|
import org.apache.archiva.metadata.model.License;
|
||||||
import org.apache.archiva.metadata.model.MailingList;
|
import org.apache.archiva.metadata.model.MailingList;
|
||||||
import org.apache.archiva.metadata.model.MetadataFacet;
|
import org.apache.archiva.metadata.model.MetadataFacet;
|
||||||
import org.apache.archiva.metadata.model.MetadataFacetFactory;
|
import org.apache.archiva.metadata.model.MetadataFacetFactory;
|
||||||
|
@ -105,6 +106,8 @@ public class CassandraMetadataRepository
|
||||||
|
|
||||||
private final ColumnFamilyTemplate<String, String> mailingListTemplate;
|
private final ColumnFamilyTemplate<String, String> mailingListTemplate;
|
||||||
|
|
||||||
|
private final ColumnFamilyTemplate<String, String> licenseTemplate;
|
||||||
|
|
||||||
public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
|
public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
|
||||||
ArchivaConfiguration configuration,
|
ArchivaConfiguration configuration,
|
||||||
CassandraArchivaManager cassandraArchivaManager )
|
CassandraArchivaManager cassandraArchivaManager )
|
||||||
|
@ -145,6 +148,12 @@ public class CassandraMetadataRepository
|
||||||
//
|
//
|
||||||
StringSerializer.get(), //
|
StringSerializer.get(), //
|
||||||
StringSerializer.get() );
|
StringSerializer.get() );
|
||||||
|
|
||||||
|
this.licenseTemplate = new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
|
||||||
|
cassandraArchivaManager.getLicenseFamilyName(),
|
||||||
|
//
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -898,6 +907,8 @@ public class CassandraMetadataRepository
|
||||||
recordMailingList( key, versionMetadata.getMailingLists() );
|
recordMailingList( key, versionMetadata.getMailingLists() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recordLicenses( key, versionMetadata.getLicenses() );
|
||||||
|
|
||||||
MutationResult mutationResult = mutator.execute();
|
MutationResult mutationResult = mutator.execute();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -955,12 +966,12 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( versionMetadata.getMailingLists() != null )
|
|
||||||
{
|
|
||||||
// update is a delete record
|
// update is a delete record
|
||||||
removeMailingList( key );
|
removeMailingList( key );
|
||||||
recordMailingList( key, versionMetadata.getMailingLists() );
|
recordMailingList( key, versionMetadata.getMailingLists() );
|
||||||
}
|
|
||||||
|
removeLicenses( key );
|
||||||
|
recordLicenses( key, versionMetadata.getLicenses() );
|
||||||
|
|
||||||
projectVersionMetadataModelTemplate.update( updater );
|
projectVersionMetadataModelTemplate.update( updater );
|
||||||
|
|
||||||
|
@ -1035,6 +1046,7 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
projectVersionMetadata.setMailingLists( getMailingLists( key ) );
|
projectVersionMetadata.setMailingLists( getMailingLists( key ) );
|
||||||
|
projectVersionMetadata.setLicenses( getLicenses( key ) );
|
||||||
// FIXME complete collections !!
|
// FIXME complete collections !!
|
||||||
// facets
|
// facets
|
||||||
|
|
||||||
|
@ -1161,7 +1173,7 @@ public class CassandraMetadataRepository
|
||||||
|
|
||||||
for ( String columnName : columnFamilyResult.getColumnNames() )
|
for ( String columnName : columnFamilyResult.getColumnNames() )
|
||||||
{
|
{
|
||||||
if (StringUtils.startsWith( columnName, "otherArchive." ))
|
if ( StringUtils.startsWith( columnName, "otherArchive." ) )
|
||||||
{
|
{
|
||||||
otherArchives.add( columnFamilyResult.getString( columnName ) );
|
otherArchives.add( columnFamilyResult.getString( columnName ) );
|
||||||
}
|
}
|
||||||
|
@ -1174,6 +1186,72 @@ public class CassandraMetadataRepository
|
||||||
return mailingLists;
|
return mailingLists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void recordLicenses( String projectVersionMetadataKey, List<License> licenses )
|
||||||
|
{
|
||||||
|
|
||||||
|
if ( licenses == null || licenses.isEmpty() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Mutator<String> licenseMutator = this.licenseTemplate.createMutator();
|
||||||
|
|
||||||
|
for ( License license : licenses )
|
||||||
|
{
|
||||||
|
// we don't care about the key as the real used one with the projectVersionMetadata
|
||||||
|
String keyLicense = UUID.randomUUID().toString();
|
||||||
|
String cfLicense = cassandraArchivaManager.getLicenseFamilyName();
|
||||||
|
|
||||||
|
addInsertion( licenseMutator, keyLicense, cfLicense, "projectVersionMetadataModel.key",
|
||||||
|
projectVersionMetadataKey );
|
||||||
|
|
||||||
|
addInsertion( licenseMutator, keyLicense, cfLicense, "license.name", license.getName() );
|
||||||
|
|
||||||
|
addInsertion( licenseMutator, keyLicense, cfLicense, "license.url", license.getUrl() );
|
||||||
|
|
||||||
|
}
|
||||||
|
licenseMutator.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeLicenses( String projectVersionMetadataKey )
|
||||||
|
{
|
||||||
|
StringSerializer ss = StringSerializer.get();
|
||||||
|
QueryResult<OrderedRows<String, String, String>> result =
|
||||||
|
HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
|
||||||
|
.setColumnFamily( cassandraArchivaManager.getLicenseFamilyName() ) //
|
||||||
|
.setColumnNames( "name" ) //
|
||||||
|
.setRowCount( Integer.MAX_VALUE ) //
|
||||||
|
.addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
|
||||||
|
.execute();
|
||||||
|
for ( Row<String, String, String> row : result.get() )
|
||||||
|
{
|
||||||
|
this.licenseTemplate.deleteRow( row.getKey() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<License> getLicenses( String projectVersionMetadataKey )
|
||||||
|
{
|
||||||
|
List<License> licenses = new ArrayList<License>();
|
||||||
|
|
||||||
|
StringSerializer ss = StringSerializer.get();
|
||||||
|
QueryResult<OrderedRows<String, String, String>> result =
|
||||||
|
HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
|
||||||
|
.setColumnFamily( cassandraArchivaManager.getLicenseFamilyName() ) //
|
||||||
|
.setColumnNames( "projectVersionMetadataModel.key" ) //
|
||||||
|
.setRowCount( Integer.MAX_VALUE ) //
|
||||||
|
.addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
for ( Row<String, String, String> row : result.get() )
|
||||||
|
{
|
||||||
|
ColumnFamilyResult<String, String> columnFamilyResult = this.licenseTemplate.queryColumns( row.getKey() );
|
||||||
|
|
||||||
|
licenses.add( new License( columnFamilyResult.getString( "license.name" ),
|
||||||
|
columnFamilyResult.getString( "license.url" ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return licenses;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
|
public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
|
||||||
ArtifactMetadata artifactMeta )
|
ArtifactMetadata artifactMeta )
|
||||||
|
|
|
@ -83,6 +83,8 @@ public class DefaultCassandraArchivaManager
|
||||||
|
|
||||||
private String mailingListFamilyName = "mailinglist";
|
private String mailingListFamilyName = "mailinglist";
|
||||||
|
|
||||||
|
private String licenseFamilyName = "license";
|
||||||
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initialize()
|
public void initialize()
|
||||||
|
@ -378,6 +380,24 @@ public class DefaultCassandraArchivaManager
|
||||||
projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
|
projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
|
||||||
mailingListCf.addColumnDefinition( projectVersionMetadataIdColumn );
|
mailingListCf.addColumnDefinition( projectVersionMetadataIdColumn );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// license table
|
||||||
|
{
|
||||||
|
final ColumnFamilyDefinition licenseCf =
|
||||||
|
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
|
||||||
|
getLicenseFamilyName(), //
|
||||||
|
ComparatorType.UTF8TYPE );
|
||||||
|
cfds.add( licenseCf );
|
||||||
|
|
||||||
|
// creating indexes for cql query
|
||||||
|
|
||||||
|
BasicColumnDefinition projectVersionMetadataIdColumn = new BasicColumnDefinition();
|
||||||
|
projectVersionMetadataIdColumn.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataId" ) );
|
||||||
|
projectVersionMetadataIdColumn.setIndexName( "projectVersionMetadataId" );
|
||||||
|
projectVersionMetadataIdColumn.setIndexType( ColumnIndexType.KEYS );
|
||||||
|
projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
|
||||||
|
licenseCf.addColumnDefinition( projectVersionMetadataIdColumn );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,4 +478,9 @@ public class DefaultCassandraArchivaManager
|
||||||
{
|
{
|
||||||
return mailingListFamilyName;
|
return mailingListFamilyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLicenseFamilyName()
|
||||||
|
{
|
||||||
|
return licenseFamilyName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,9 @@ public class CassandraMetadataRepositoryTest
|
||||||
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
||||||
cassandraArchivaManager.getMailingListFamilyName() );
|
cassandraArchivaManager.getMailingListFamilyName() );
|
||||||
|
|
||||||
|
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
||||||
|
cassandraArchivaManager.getLicenseFamilyName() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue