public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
ArtifactMetadata artifactMeta )
throws MetadataRepositoryException
{
Namespace namespace = getNamespace( repositoryId, namespaceId );
if ( namespace == null )
{
namespace = updateOrAddNamespace( repositoryId, namespaceId );
}
ProjectMetadata projectMetadata = new ProjectMetadata();
projectMetadata.setId( projectId );
projectMetadata.setNamespace( namespaceId );
updateProject( repositoryId, projectMetadata );
String key = new ArtifactMetadataModel.KeyBuilder().withNamespace( namespace ).withProject( projectId ).withId(
artifactMeta.getId() ).withProjectVersion( projectVersion ).build();
// exists?
boolean exists = this.artifactMetadataTemplate.isColumnsExist( key );
if ( exists )
{
// updater
ColumnFamilyUpdater<String, String> updater = this.artifactMetadataTemplate.createUpdater( key );
updater.setLong( "fileLastModified", artifactMeta.getFileLastModified().getTime() );
updater.setLong( "whenGathered", artifactMeta.getWhenGathered().getTime() );
updater.setLong( "size", artifactMeta.getSize() );
addUpdateStringValue( updater, "md5", artifactMeta.getMd5() );
addUpdateStringValue( updater, "sha1", artifactMeta.getSha1() );
addUpdateStringValue( updater, "version", artifactMeta.getVersion() );
this.artifactMetadataTemplate.update( updater );
}
else
{
String cf = this.cassandraArchivaManager.getArtifactMetadataFamilyName();
// create
this.artifactMetadataTemplate.createMutator() //
.addInsertion( key, cf, column( "id", artifactMeta.getId() ) )//
.addInsertion( key, cf, column( "repositoryName", repositoryId ) ) //
.addInsertion( key, cf, column( "namespaceId", namespaceId ) ) //
.addInsertion( key, cf, column( "project", artifactMeta.getProject() ) ) //
.addInsertion( key, cf, column( "projectVersion", projectVersion ) ) //
.addInsertion( key, cf, column( "version", artifactMeta.getVersion() ) ) //
.addInsertion( key, cf, column( "fileLastModified", artifactMeta.getFileLastModified().getTime() ) ) //
.addInsertion( key, cf, column( "size", artifactMeta.getSize() ) ) //
.addInsertion( key, cf, column( "md5", artifactMeta.getMd5() ) ) //
.addInsertion( key, cf, column( "sha1", artifactMeta.getSha1() ) ) //
.addInsertion( key, cf, column( "whenGathered", artifactMeta.getWhenGathered().getTime() ) )//
.execute();
}
key = new ProjectVersionMetadataModel.KeyBuilder() //
.withRepository( repositoryId ) //
.withNamespace( namespace ) //
.withProjectId( projectId ) //
.withProjectVersion( projectVersion ) //
.withId( artifactMeta.getId() ) //
.build();
QueryResult<OrderedRows<String, String, String>> result = HFactory //
.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) //
.setColumnNames( "version" ) //
.addEqualsExpression( "repositoryName", repositoryId ) //
.addEqualsExpression( "namespaceId", namespaceId ) //
.addEqualsExpression( "projectId", projectId ) //
.addEqualsExpression( "projectVersion", projectVersion ) //
.addEqualsExpression( "version", artifactMeta.getVersion() ) //
.execute();
exists = result.get().getCount() > 0;
if ( !exists )
{
String cf = this.cassandraArchivaManager.getProjectVersionMetadataFamilyName();
projectVersionMetadataTemplate.createMutator() //
.addInsertion( key, cf, column( "namespaceId", namespace.getName() ) ) //
.addInsertion( key, cf, column( "repositoryName", repositoryId ) ) //
.addInsertion( key, cf, column( "projectVersion", projectVersion ) ) //
.addInsertion( key, cf, column( "projectId", projectId ) ) //
.addInsertion( key, cf, column( "version", artifactMeta.getVersion() ) ) //
.execute();