mirror of https://github.com/apache/archiva.git
take care of null values
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1582119 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a80ae95cc8
commit
5a1a064f75
|
@ -92,6 +92,10 @@
|
||||||
<groupId>org.mortbay.jetty</groupId>
|
<groupId>org.mortbay.jetty</groupId>
|
||||||
<artifactId>jetty</artifactId>
|
<artifactId>jetty</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>servlet-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -882,55 +882,48 @@ public class CassandraMetadataRepository
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ColumnFamilyUpdater<String, String> updater = projectVersionMetadataTemplate.createUpdater( key );
|
ColumnFamilyUpdater<String, String> updater = projectVersionMetadataTemplate.createUpdater( key );
|
||||||
updater.setString( "projectId", projectId );
|
addUpdateStringValue( updater, "projectId", projectId );
|
||||||
updater.setString( "repositoryName", repositoryId );
|
addUpdateStringValue( updater, "repositoryName", repositoryId );
|
||||||
updater.setString( "namespaceId", namespaceId );
|
addUpdateStringValue( updater, "namespaceId", namespaceId );
|
||||||
updater.setString( "projectVersion", versionMetadata.getVersion() );
|
addUpdateStringValue( updater, "projectVersion", versionMetadata.getVersion() );
|
||||||
if ( StringUtils.isNotEmpty( versionMetadata.getDescription() ) )
|
addUpdateStringValue( updater, "description", versionMetadata.getDescription() );
|
||||||
{
|
|
||||||
updater.setString( "description", versionMetadata.getDescription() );
|
addUpdateStringValue( updater, "name", versionMetadata.getName() );
|
||||||
}
|
|
||||||
if ( StringUtils.isNotEmpty( versionMetadata.getName() ) )
|
|
||||||
{
|
|
||||||
updater.setString( "name", versionMetadata.getName() );
|
|
||||||
}
|
|
||||||
updater.setString( "incomplete", Boolean.toString( versionMetadata.isIncomplete() ) );
|
updater.setString( "incomplete", Boolean.toString( versionMetadata.isIncomplete() ) );
|
||||||
if ( StringUtils.isNotEmpty( versionMetadata.getUrl() ) )
|
addUpdateStringValue( updater, "url", versionMetadata.getUrl() );
|
||||||
{
|
|
||||||
updater.setString( "url", versionMetadata.getUrl() );
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
CiManagement ci = versionMetadata.getCiManagement();
|
CiManagement ci = versionMetadata.getCiManagement();
|
||||||
if ( ci != null )
|
if ( ci != null )
|
||||||
{
|
{
|
||||||
updater.setString( "ciManagement.system", ci.getSystem() );
|
addUpdateStringValue( updater, "ciManagement.system", ci.getSystem() );
|
||||||
updater.setString( "ciManagement.url", ci.getUrl() );
|
addUpdateStringValue( updater, "ciManagement.url", ci.getUrl() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
IssueManagement issueManagement = versionMetadata.getIssueManagement();
|
IssueManagement issueManagement = versionMetadata.getIssueManagement();
|
||||||
if ( issueManagement != null )
|
if ( issueManagement != null )
|
||||||
{
|
{
|
||||||
updater.setString( "issueManagement.system", issueManagement.getSystem() );
|
addUpdateStringValue( updater, "issueManagement.system", issueManagement.getSystem() );
|
||||||
updater.setString( "issueManagement.url", issueManagement.getUrl() );
|
addUpdateStringValue( updater, "issueManagement.url", issueManagement.getUrl() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Organization organization = versionMetadata.getOrganization();
|
Organization organization = versionMetadata.getOrganization();
|
||||||
if ( organization != null )
|
if ( organization != null )
|
||||||
{
|
{
|
||||||
updater.setString( "organization.name", organization.getName() );
|
addUpdateStringValue( updater, "organization.name", organization.getName() );
|
||||||
updater.setString( "organization.url", organization.getUrl() );
|
addUpdateStringValue( updater, "organization.url", organization.getUrl() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Scm scm = versionMetadata.getScm();
|
Scm scm = versionMetadata.getScm();
|
||||||
if ( scm != null )
|
if ( scm != null )
|
||||||
{
|
{
|
||||||
updater.setString( "scm.url", scm.getUrl() );
|
addUpdateStringValue( updater, "scm.url", scm.getUrl() );
|
||||||
updater.setString( "scm.connection", scm.getConnection() );
|
addUpdateStringValue( updater, "scm.connection", scm.getConnection() );
|
||||||
updater.setString( "scm.developerConnection", scm.getDeveloperConnection() );
|
addUpdateStringValue( updater, "scm.developerConnection", scm.getDeveloperConnection() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1363,9 +1356,9 @@ public class CassandraMetadataRepository
|
||||||
updater.setLong( "fileLastModified", artifactMeta.getFileLastModified().getTime() );
|
updater.setLong( "fileLastModified", artifactMeta.getFileLastModified().getTime() );
|
||||||
updater.setLong( "whenGathered", artifactMeta.getWhenGathered().getTime() );
|
updater.setLong( "whenGathered", artifactMeta.getWhenGathered().getTime() );
|
||||||
updater.setLong( "size", artifactMeta.getSize() );
|
updater.setLong( "size", artifactMeta.getSize() );
|
||||||
updater.setString( "md5", artifactMeta.getMd5() );
|
addUpdateStringValue(updater, "md5", artifactMeta.getMd5() );
|
||||||
updater.setString( "sha1", artifactMeta.getSha1() );
|
addUpdateStringValue(updater, "sha1", artifactMeta.getSha1() );
|
||||||
updater.setString( "version", artifactMeta.getVersion() );
|
addUpdateStringValue(updater, "version", artifactMeta.getVersion() );
|
||||||
this.artifactMetadataTemplate.update( updater );
|
this.artifactMetadataTemplate.update( updater );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1508,16 +1501,21 @@ public class CassandraMetadataRepository
|
||||||
{
|
{
|
||||||
String key = new MetadataFacetModel.KeyBuilder().withKey( entry.getKey() ).withArtifactMetadataModel(
|
String key = new MetadataFacetModel.KeyBuilder().withKey( entry.getKey() ).withArtifactMetadataModel(
|
||||||
artifactMetadataModel ).withFacetId( facetId ).withName( metadataFacet.getName() ).build();
|
artifactMetadataModel ).withFacetId( facetId ).withName( metadataFacet.getName() ).build();
|
||||||
metadataFacetTemplate.createMutator() //
|
Mutator<String> mutator = metadataFacetTemplate.createMutator() //
|
||||||
.addInsertion( key, cf, column( "repositoryName", artifactMetadataModel.getRepositoryId() ) ) //
|
.addInsertion( key, cf, column( "repositoryName", artifactMetadataModel.getRepositoryId() ) ) //
|
||||||
.addInsertion( key, cf, column( "namespaceId", artifactMetadataModel.getNamespace() ) ) //
|
.addInsertion( key, cf, column( "namespaceId", artifactMetadataModel.getNamespace() ) ) //
|
||||||
.addInsertion( key, cf, column( "projectId", artifactMetadataModel.getProject() ) ) //
|
.addInsertion( key, cf, column( "projectId", artifactMetadataModel.getProject() ) ) //
|
||||||
.addInsertion( key, cf, column( "projectVersion", artifactMetadataModel.getProjectVersion() ) ) //
|
.addInsertion( key, cf, column( "projectVersion", artifactMetadataModel.getProjectVersion() ) ) //
|
||||||
.addInsertion( key, cf, column( "facetId", facetId ) ) //
|
.addInsertion( key, cf, column( "facetId", facetId ) ) //
|
||||||
.addInsertion( key, cf, column( "key", entry.getKey() ) ) //
|
.addInsertion( key, cf, column( "key", entry.getKey() ) ) //
|
||||||
.addInsertion( key, cf, column( "value", entry.getValue() ) ) //
|
.addInsertion( key, cf, column( "value", entry.getValue() ) );
|
||||||
.addInsertion( key, cf, column( "name", metadataFacet.getName() ) ) //
|
|
||||||
.execute();
|
if ( metadataFacet.getName() != null )
|
||||||
|
{
|
||||||
|
mutator.addInsertion( key, cf, column( "name", metadataFacet.getName() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
mutator.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1608,8 +1606,8 @@ public class CassandraMetadataRepository
|
||||||
if ( exists )
|
if ( exists )
|
||||||
{
|
{
|
||||||
ColumnFamilyUpdater<String, String> updater = this.metadataFacetTemplate.createUpdater( key );
|
ColumnFamilyUpdater<String, String> updater = this.metadataFacetTemplate.createUpdater( key );
|
||||||
updater.setString( "facetId", metadataFacet.getFacetId() );
|
addUpdateStringValue(updater, "facetId", metadataFacet.getFacetId() );
|
||||||
updater.setString( "name", metadataFacet.getName() );
|
addUpdateStringValue(updater, "name", metadataFacet.getName() );
|
||||||
this.metadataFacetTemplate.update( updater );
|
this.metadataFacetTemplate.update( updater );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1645,7 +1643,7 @@ public class CassandraMetadataRepository
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ColumnFamilyUpdater<String, String> updater = this.metadataFacetTemplate.createUpdater( key );
|
ColumnFamilyUpdater<String, String> updater = this.metadataFacetTemplate.createUpdater( key );
|
||||||
updater.setString( "value", entry.getValue() );
|
addUpdateStringValue(updater, "value", entry.getValue() );
|
||||||
this.metadataFacetTemplate.update( updater );
|
this.metadataFacetTemplate.update( updater );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.archiva.metadata.repository.cassandra;
|
||||||
import me.prettyprint.cassandra.serializers.LongSerializer;
|
import me.prettyprint.cassandra.serializers.LongSerializer;
|
||||||
import me.prettyprint.cassandra.serializers.SerializerTypeInferer;
|
import me.prettyprint.cassandra.serializers.SerializerTypeInferer;
|
||||||
import me.prettyprint.cassandra.serializers.StringSerializer;
|
import me.prettyprint.cassandra.serializers.StringSerializer;
|
||||||
|
import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater;
|
||||||
import me.prettyprint.hector.api.Serializer;
|
import me.prettyprint.hector.api.Serializer;
|
||||||
import me.prettyprint.hector.api.beans.ColumnSlice;
|
import me.prettyprint.hector.api.beans.ColumnSlice;
|
||||||
import me.prettyprint.hector.api.beans.HColumn;
|
import me.prettyprint.hector.api.beans.HColumn;
|
||||||
|
@ -69,6 +70,7 @@ public class CassandraUtils
|
||||||
|
|
||||||
public static <A, B> HColumn<A, B> column( final A name, final B value )
|
public static <A, B> HColumn<A, B> column( final A name, final B value )
|
||||||
{
|
{
|
||||||
|
|
||||||
return HFactory.createColumn( name, //
|
return HFactory.createColumn( name, //
|
||||||
value, //
|
value, //
|
||||||
(Serializer<A>) SerializerTypeInferer.getSerializer( name ), //
|
(Serializer<A>) SerializerTypeInferer.getSerializer( name ), //
|
||||||
|
@ -130,6 +132,22 @@ public class CassandraUtils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* null check on the value to prevent {@link java.lang.IllegalArgumentException}
|
||||||
|
* @param updater
|
||||||
|
* @param columnName
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public static void addUpdateStringValue(ColumnFamilyUpdater<String,String> updater, String columnName, String value )
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updater.setString( columnName, value );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private CassandraUtils()
|
private CassandraUtils()
|
||||||
{
|
{
|
||||||
// no-op
|
// no-op
|
||||||
|
|
Loading…
Reference in New Issue