1 package org.apache.archiva.metadata.repository.cassandra;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import me.prettyprint.cassandra.model.CqlQuery;
23 import me.prettyprint.cassandra.model.CqlRows;
24 import me.prettyprint.cassandra.serializers.LongSerializer;
25 import me.prettyprint.cassandra.serializers.StringSerializer;
26 import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate;
27 import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater;
28 import me.prettyprint.cassandra.service.template.ThriftColumnFamilyTemplate;
29 import me.prettyprint.hector.api.Keyspace;
30 import me.prettyprint.hector.api.beans.ColumnSlice;
31 import me.prettyprint.hector.api.beans.OrderedRows;
32 import me.prettyprint.hector.api.beans.Row;
33 import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
34 import me.prettyprint.hector.api.factory.HFactory;
35 import me.prettyprint.hector.api.mutation.MutationResult;
36 import me.prettyprint.hector.api.query.QueryResult;
37 import org.apache.archiva.configuration.ArchivaConfiguration;
38 import org.apache.archiva.metadata.model.ArtifactMetadata;
39 import org.apache.archiva.metadata.model.FacetedMetadata;
40 import org.apache.archiva.metadata.model.MetadataFacet;
41 import org.apache.archiva.metadata.model.MetadataFacetFactory;
42 import org.apache.archiva.metadata.model.ProjectMetadata;
43 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
44 import org.apache.archiva.metadata.model.ProjectVersionReference;
45 import org.apache.archiva.metadata.repository.MetadataRepository;
46 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
47 import org.apache.archiva.metadata.repository.MetadataResolutionException;
48 import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel;
49 import org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel;
50 import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
51 import org.apache.archiva.metadata.repository.cassandra.model.Project;
52 import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel;
53 import org.apache.archiva.metadata.repository.cassandra.model.Repository;
54 import org.apache.commons.lang.StringUtils;
55 import org.modelmapper.ModelMapper;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
59 import javax.persistence.PersistenceException;
60 import java.util.ArrayList;
61 import java.util.Collection;
62 import java.util.Collections;
63 import java.util.Date;
64 import java.util.HashMap;
65 import java.util.HashSet;
66 import java.util.List;
70 import static org.apache.archiva.metadata.repository.cassandra.CassandraUtils.column;
73 * @author Olivier Lamy
76 public class CassandraMetadataRepository
77 implements MetadataRepository
80 private Logger logger = LoggerFactory.getLogger( getClass() );
82 private ArchivaConfiguration configuration;
84 private final Map<String, MetadataFacetFactory> metadataFacetFactories;
86 private final CassandraArchivaManager cassandraArchivaManager;
88 private final ColumnFamilyTemplate<String, String> projectVersionMetadataModelTemplate;
90 private final ColumnFamilyTemplate<String, String> projectTemplate;
92 private final ColumnFamilyTemplate<String, String> artifactMetadataTemplate;
94 private final ColumnFamilyTemplate<String, String> metadataFacetTemplate;
96 public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
97 ArchivaConfiguration configuration,
98 CassandraArchivaManager cassandraArchivaManager )
100 this.metadataFacetFactories = metadataFacetFactories;
101 this.configuration = configuration;
102 this.cassandraArchivaManager = cassandraArchivaManager;
104 this.projectVersionMetadataModelTemplate =
105 new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
106 cassandraArchivaManager.getProjectVersionMetadataModelFamilyName(),
107 StringSerializer.get(), //
108 StringSerializer.get() );
110 this.projectTemplate = new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
111 cassandraArchivaManager.getProjectFamilyName(),
113 StringSerializer.get(), //
114 StringSerializer.get() );
116 this.artifactMetadataTemplate =
117 new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
118 cassandraArchivaManager.getArtifactMetadataModelFamilyName(),
120 StringSerializer.get(), //
121 StringSerializer.get() );
123 this.metadataFacetTemplate =
124 new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
125 cassandraArchivaManager.getMetadataFacetModelFamilyName(),
127 StringSerializer.get(), //
128 StringSerializer.get() );
133 * if the repository doesn't exist it will be created
135 * @param repositoryId
138 public Repository getOrCreateRepository( String repositoryId )
139 throws MetadataRepositoryException
141 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
142 QueryResult<OrderedRows<String, String, String>> result = HFactory //
143 .createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(),
144 StringSerializer.get() ) //
145 .setColumnFamily( cassandraArchivaManager.getRepositoryFamilyName() ) //
146 .setColumnNames( "repositoryName" ) //
147 .addEqualsExpression( "repositoryName", repositoryId ) //
150 if ( result.get().getCount() < 1 )
152 // we need to create the repository
153 Repository repository = new Repository( repositoryId );
157 MutationResult mutationResult = HFactory.createMutator( keyspace, StringSerializer.get() ) //
158 .addInsertion( repositoryId, //
159 cassandraArchivaManager.getRepositoryFamilyName(), //
160 CassandraUtils.column( "repositoryName", repository.getName() ) ) //
164 catch ( HInvalidRequestException e )
166 logger.error( e.getMessage(), e );
167 throw new MetadataRepositoryException( e.getMessage(), e );
172 return new Repository(
173 result.get().getList().get( 0 ).getColumnSlice().getColumnByName( "repositoryName" ).getValue() );
177 protected Repository getRepository( String repositoryId )
178 throws MetadataRepositoryException
180 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
181 QueryResult<OrderedRows<String, String, String>> result = HFactory //
182 .createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(),
183 StringSerializer.get() ) //
184 .setColumnFamily( cassandraArchivaManager.getRepositoryFamilyName() ) //
185 .setColumnNames( "repositoryName" ) //
186 .addEqualsExpression( "repositoryName", repositoryId ) //
188 return ( result.get().getCount() > 0 ) ? new Repository( repositoryId ) : null;
192 public void updateNamespace( String repositoryId, String namespaceId )
193 throws MetadataRepositoryException
195 updateOrAddNamespace( repositoryId, namespaceId );
198 public Namespace updateOrAddNamespace( String repositoryId, String namespaceId )
199 throws MetadataRepositoryException
203 Repository repository = getOrCreateRepository( repositoryId );
205 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
208 new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build();
210 Namespace namespace = getNamespace( repositoryId, namespaceId );
211 if ( namespace == null )
213 namespace = new Namespace( namespaceId, repository );
214 HFactory.createMutator( keyspace, StringSerializer.get() )
216 .addInsertion( key, //
217 cassandraArchivaManager.getNamespaceFamilyName(), //
218 CassandraUtils.column( "name", namespace.getName() ) ) //
219 .addInsertion( key, //
220 cassandraArchivaManager.getNamespaceFamilyName(), //
221 CassandraUtils.column( "repositoryName", repository.getName() ) ) //
227 catch ( HInvalidRequestException e )
229 logger.error( e.getMessage(), e );
230 throw new MetadataRepositoryException( e.getMessage(), e );
234 protected Namespace getNamespace( String repositoryId, String namespaceId )
236 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
237 QueryResult<OrderedRows<String, String, String>> result = HFactory //
238 .createRangeSlicesQuery( keyspace, //
239 StringSerializer.get(), //
240 StringSerializer.get(), //
241 StringSerializer.get() ) //
242 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
243 .setColumnNames( "repositoryName", "name" ) //
244 .addEqualsExpression( "repositoryName", repositoryId ) //
245 .addEqualsExpression( "name", namespaceId ) //
247 if ( result.get().getCount() > 0 )
249 ColumnSlice<String, String> columnSlice = result.get().getList().get( 0 ).getColumnSlice();
250 return new Namespace( columnSlice.getColumnByName( "name" ).getValue(), //
251 new Repository( columnSlice.getColumnByName( "repositoryName" ).getValue() ) );
259 public void removeNamespace( String repositoryId, String namespaceId )
260 throws MetadataRepositoryException
265 new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build();
267 MutationResult result =
268 HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
269 .addDeletion( key, cassandraArchivaManager.getNamespaceFamilyName() ) //
274 catch ( HInvalidRequestException e )
276 logger.error( e.getMessage(), e );
277 throw new MetadataRepositoryException( e.getMessage(), e );
283 public void removeRepository( final String repositoryId )
284 throws MetadataRepositoryException
287 // FIXME remove all datas attached to the repositoryId
289 // retrieve and delete all namespace with this repositoryId
291 // TODO use cql queries to delete all
292 List<String> namespacesKey = new ArrayList<String>();
294 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
295 QueryResult<OrderedRows<String, String, String>> result = HFactory //
296 .createRangeSlicesQuery( keyspace, //
297 StringSerializer.get(), //
298 StringSerializer.get(), //
299 StringSerializer.get() ) //
300 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
301 .setColumnNames( "repositoryName", "name" ) //
302 .addEqualsExpression( "repositoryName", repositoryId ) //
305 for ( Row<String, String, String> row : result.get().getList() )
307 namespacesKey.add( row.getKey() );
310 HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
311 .addDeletion( namespacesKey, cassandraArchivaManager.getNamespaceFamilyName() ) //
314 //delete repositoryId
315 HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
316 .addDeletion( repositoryId, cassandraArchivaManager.getRepositoryFamilyName() ) //
320 final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
322 // remove data related to the repository
323 this.getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
326 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
328 if ( artifactMetadataModel != null )
330 if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId ) )
332 artifactMetadataModels.add( artifactMetadataModel );
339 getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
341 final List<Namespace> namespaces = new ArrayList<Namespace>();
343 getNamespaceEntityManager().visitAll( new Function<Namespace, Boolean>()
346 public Boolean apply( Namespace namespace )
348 if ( namespace != null )
350 if ( StringUtils.equals( namespace.getRepository().getId(), repositoryId ) )
352 namespaces.add( namespace );
359 getNamespaceEntityManager().remove( namespaces );
361 final List<Project> projects = new ArrayList<Project>();
362 getProjectEntityManager().visitAll( new Function<Project, Boolean>()
365 public Boolean apply( Project project )
367 if ( project != null )
369 if ( StringUtils.equals( project.getNamespace().getRepository().getId(), repositoryId ) )
371 projects.add( project );
378 getProjectEntityManager().remove( projects );
380 // TODO cleanup or not
381 //final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>( );
382 //getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
384 final List<ProjectVersionMetadataModel> projectVersionMetadataModels =
385 new ArrayList<ProjectVersionMetadataModel>();
387 getProjectVersionMetadataModelEntityManager().visitAll( new Function<ProjectVersionMetadataModel, Boolean>()
390 public Boolean apply( ProjectVersionMetadataModel projectVersionMetadataModel )
392 if ( projectVersionMetadataModel != null )
394 if ( StringUtils.equals( projectVersionMetadataModel.getNamespace().getRepository().getId(),
397 projectVersionMetadataModels.add( projectVersionMetadataModel );
404 getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
406 Repository repository = getRepositoryEntityManager().get( repositoryId );
407 if ( repository != null )
409 getRepositoryEntityManager().remove( repository );
416 public Collection<String> getRepositories()
417 throws MetadataRepositoryException
421 logger.debug( "getRepositories" );
423 final QueryResult<OrderedRows<String, String, String>> cResult = //
424 HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), //
425 StringSerializer.get(), //
426 StringSerializer.get(), //
427 StringSerializer.get() ) //
428 .setColumnFamily( cassandraArchivaManager.getRepositoryFamilyName() ) //
429 .setColumnNames( "repositoryName" ) //
430 .setRange( null, null, false, Integer.MAX_VALUE ) //
433 List<String> repoIds = new ArrayList<String>( cResult.get().getCount() );
435 for ( Row<String, String, String> row : cResult.get() )
437 repoIds.add( row.getColumnSlice().getColumnByName( "repositoryName" ).getValue() );
442 catch ( PersistenceException e )
444 throw new MetadataRepositoryException( e.getMessage(), e );
451 public Collection<String> getRootNamespaces( final String repoId )
452 throws MetadataResolutionException
454 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
455 QueryResult<OrderedRows<String, String, String>> result = HFactory //
456 .createRangeSlicesQuery( keyspace, //
457 StringSerializer.get(), //
458 StringSerializer.get(), //
459 StringSerializer.get() ) //
460 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
461 .setColumnNames( "name" ) //
462 .addEqualsExpression( "repositoryName", repoId ) //
465 Set<String> namespaces = new HashSet<String>( result.get().getCount() );
467 for ( Row<String, String, String> row : result.get() )
470 StringUtils.substringBefore( row.getColumnSlice().getColumnByName( "name" ).getValue(), "." ) );
478 public Collection<String> getNamespaces( final String repoId, final String namespaceId )
479 throws MetadataResolutionException
481 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
482 QueryResult<OrderedRows<String, String, String>> result = HFactory //
483 .createRangeSlicesQuery( keyspace, //
484 StringSerializer.get(), //
485 StringSerializer.get(), //
486 StringSerializer.get() ) //
487 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
488 .setColumnNames( "name" ) //
489 .addEqualsExpression( "repositoryName", repoId ) //
492 List<String> namespaces = new ArrayList<String>( result.get().getCount() );
494 for ( Row<String, String, String> row : result.get() )
496 String currentNamespace = row.getColumnSlice().getColumnByName( "name" ).getValue();
497 if ( StringUtils.startsWith( currentNamespace, namespaceId ) && ( StringUtils.length( currentNamespace )
498 > StringUtils.length( namespaceId ) ) )
500 // store after namespaceId '.' but before next '.'
501 // call org namespace org.apache.maven.shared -> stored apache
503 String calledNamespace = StringUtils.endsWith( namespaceId, "." ) ? namespaceId : namespaceId + ".";
504 String storedNamespace = StringUtils.substringAfter( currentNamespace, calledNamespace );
506 storedNamespace = StringUtils.substringBefore( storedNamespace, "." );
508 namespaces.add( storedNamespace );
517 public List<String> getNamespaces( final String repoId )
518 throws MetadataResolutionException
520 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
521 QueryResult<OrderedRows<String, String, String>> result = HFactory //
522 .createRangeSlicesQuery( keyspace, //
523 StringSerializer.get(), //
524 StringSerializer.get(), //
525 StringSerializer.get() ) //
526 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
527 .setColumnNames( "name" ) //
528 .addEqualsExpression( "repositoryName", repoId ) //
531 List<String> namespaces = new ArrayList<String>( result.get().getCount() );
533 for ( Row<String, String, String> row : result.get() )
535 namespaces.add( row.getColumnSlice().getColumnByName( "name" ).getValue() );
543 public void updateProject( String repositoryId, ProjectMetadata projectMetadata )
544 throws MetadataRepositoryException
546 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
548 QueryResult<OrderedRows<String, String, String>> result = HFactory //
549 .createRangeSlicesQuery( keyspace, //
550 StringSerializer.get(), //
551 StringSerializer.get(), //
552 StringSerializer.get() ) //
553 .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
554 .setColumnNames( "projectId" ) //
555 .addEqualsExpression( "repositoryName", repositoryId ) //
556 .addEqualsExpression( "namespaceId", projectMetadata.getNamespace() ) //
557 .addEqualsExpression( "projectId", projectMetadata.getId() ) //
562 // project exists ? if yes return nothing to update here
563 if ( result.get().getCount() > 0 )
569 Namespace namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() );
572 new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace( namespace ).build();
574 projectTemplate.createMutator()
576 .addInsertion( key, //
577 cassandraArchivaManager.getProjectFamilyName(), //
578 CassandraUtils.column( "projectId", projectMetadata.getId() ) ) //
579 .addInsertion( key, //
580 cassandraArchivaManager.getProjectFamilyName(), //
581 CassandraUtils.column( "repositoryName", repositoryId ) ) //
582 .addInsertion( key, //
583 cassandraArchivaManager.getProjectFamilyName(), //
584 CassandraUtils.column( "namespaceId", projectMetadata.getNamespace() ) )//
590 public Collection<String> getProjects( final String repoId, final String namespace )
591 throws MetadataResolutionException
594 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
596 QueryResult<OrderedRows<String, String, String>> result = HFactory //
597 .createRangeSlicesQuery( keyspace, //
598 StringSerializer.get(), //
599 StringSerializer.get(), //
600 StringSerializer.get() ) //
601 .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
602 .setColumnNames( "projectId" ) //
603 .addEqualsExpression( "repositoryName", repoId ) //
604 .addEqualsExpression( "namespaceId", namespace ) //
607 final Set<String> projects = new HashSet<String>( result.get().getCount() );
609 for ( Row<String, String, String> row : result.get() )
611 projects.add( row.getColumnSlice().getColumnByName( "projectId" ).getValue() );
618 public void removeProject( final String repositoryId, final String namespaceId, final String projectId )
619 throws MetadataRepositoryException
622 String key = new Project.KeyBuilder() //
623 .withProjectId( projectId ) //
624 .withNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) ) //
627 HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
628 .addDeletion( key, cassandraArchivaManager.getProjectFamilyName() ) //
631 // TODO finish linked data to delete
633 /* // cleanup ArtifactMetadataModel
634 final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
636 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
639 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
641 if ( artifactMetadataModel != null )
643 if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId )
644 && StringUtils.equals( artifactMetadataModel.getNamespace(), namespaceId )
645 && StringUtils.equals( artifactMetadataModel.getProject(), projectId ) )
647 artifactMetadataModels.add( artifactMetadataModel );
654 getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
656 Namespace namespace = new Namespace( namespaceId, new Repository( repositoryId ) );
658 final List<ProjectVersionMetadataModel> projectVersionMetadataModels =
659 new ArrayList<ProjectVersionMetadataModel>();
661 getProjectVersionMetadataModelEntityManager().visitAll( new Function<ProjectVersionMetadataModel, Boolean>()
664 public Boolean apply( ProjectVersionMetadataModel projectVersionMetadataModel )
666 if ( projectVersionMetadataModel != null )
668 if ( StringUtils.equals( repositoryId,
669 projectVersionMetadataModel.getNamespace().getRepository().getName() )
670 && StringUtils.equals( namespaceId, projectVersionMetadataModel.getNamespace().getName() )
671 && StringUtils.equals( projectId, projectVersionMetadataModel.getProjectId() ) )
673 projectVersionMetadataModels.add( projectVersionMetadataModel );
680 if ( !projectVersionMetadataModels.isEmpty() )
682 getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
685 String key = new Project.KeyBuilder().withNamespace( namespace ).withProjectId( projectId ).build();
687 Project project = getProjectEntityManager().get( key );
688 if ( project == null )
690 logger.debug( "removeProject notfound" );
693 logger.debug( "removeProject {}", project );
695 getProjectEntityManager().remove( project );*/
699 public Collection<String> getProjectVersions( final String repoId, final String namespace, final String projectId )
700 throws MetadataResolutionException
703 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
705 QueryResult<OrderedRows<String, String, String>> result = HFactory //
706 .createRangeSlicesQuery( keyspace, //
707 StringSerializer.get(), //
708 StringSerializer.get(), //
709 StringSerializer.get() ) //
710 .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataModelFamilyName() ) //
711 .setColumnNames( "id" ) //
712 .addEqualsExpression( "repositoryName", repoId ) //
713 .addEqualsExpression( "namespaceId", namespace ) //
714 .addEqualsExpression( "projectId", projectId ) //
717 int count = result.get().getCount();
721 return Collections.emptyList();
724 Set<String> versions = new HashSet<String>( count );
726 for ( Row<String, String, String> orderedRows : result.get() )
728 versions.add( orderedRows.getColumnSlice().getColumnByName( "id" ).getValue() );
736 public ProjectMetadata getProject( final String repoId, final String namespace, final String id )
737 throws MetadataResolutionException
740 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
742 QueryResult<OrderedRows<String, String, String>> result = HFactory //
743 .createRangeSlicesQuery( keyspace, //
744 StringSerializer.get(), //
745 StringSerializer.get(), //
746 StringSerializer.get() ) //
747 .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
748 .setColumnNames( "projectId" ) //
749 .addEqualsExpression( "repositoryName", repoId ) //
750 .addEqualsExpression( "namespaceId", namespace ) //
751 .addEqualsExpression( "projectId", id ) //
754 int count = result.get().getCount();
761 ProjectMetadata projectMetadata = new ProjectMetadata();
762 projectMetadata.setId( id );
763 projectMetadata.setNamespace( namespace );
765 logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id,
768 return projectMetadata;
771 protected ProjectVersionMetadataModel map( ColumnSlice<String, String> columnSlice )
773 ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
774 projectVersionMetadataModel.setId( columnSlice.getColumnByName( "id" ).getValue() );
775 projectVersionMetadataModel.setDescription( columnSlice.getColumnByName( "description" ).getValue() );
776 projectVersionMetadataModel.setName( columnSlice.getColumnByName( "name" ).getValue() );
777 projectVersionMetadataModel.setNamespace(
778 new Namespace( columnSlice.getColumnByName( "namespaceId" ).getValue(), //
779 new Repository( columnSlice.getColumnByName( "repositoryName" ).getValue() ) )
781 projectVersionMetadataModel.setIncomplete(
782 Boolean.parseBoolean( columnSlice.getColumnByName( "incomplete" ).getValue() ) );
783 projectVersionMetadataModel.setProjectId( columnSlice.getColumnByName( "projectId" ).getValue() );
784 projectVersionMetadataModel.setUrl( columnSlice.getColumnByName( "url" ).getValue() );
785 return projectVersionMetadataModel;
789 public void updateProjectVersion( String repositoryId, String namespaceId, String projectId,
790 ProjectVersionMetadata versionMetadata )
791 throws MetadataRepositoryException
795 Namespace namespace = getNamespace( repositoryId, namespaceId );
797 if ( namespace == null )
799 namespace = updateOrAddNamespace( repositoryId, namespaceId );
802 if ( getProject( repositoryId, namespaceId, projectId ) == null )
804 ProjectMetadata projectMetadata = new ProjectMetadata();
805 projectMetadata.setNamespace( namespaceId );
806 projectMetadata.setId( projectId );
807 updateProject( repositoryId, projectMetadata );
811 catch ( MetadataResolutionException e )
813 throw new MetadataRepositoryException( e.getMessage(), e );
816 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
817 QueryResult<OrderedRows<String, String, String>> result = HFactory //
818 .createRangeSlicesQuery( keyspace, //
819 StringSerializer.get(), //
820 StringSerializer.get(), //
821 StringSerializer.get() ) //
822 .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataModelFamilyName() ) //
823 .setColumnNames( "id" ) //
824 .addEqualsExpression( "repositoryName", repositoryId ) //
825 .addEqualsExpression( "namespaceId", namespaceId ) //
826 .addEqualsExpression( "projectId", projectId ) //
827 .addEqualsExpression( "id", versionMetadata.getId() ).execute();
829 ProjectVersionMetadataModel projectVersionMetadataModel = null;
830 boolean creation = true;
831 if ( result.get().getCount() > 0 )
833 projectVersionMetadataModel = map( result.get().getList().get( 0 ).getColumnSlice() );
838 projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
841 projectVersionMetadataModel.setProjectId( projectId );
842 projectVersionMetadataModel.setNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) );
843 projectVersionMetadataModel.setCiManagement( versionMetadata.getCiManagement() );
844 projectVersionMetadataModel.setIssueManagement( versionMetadata.getIssueManagement() );
845 projectVersionMetadataModel.setOrganization( versionMetadata.getOrganization() );
846 projectVersionMetadataModel.setScm( versionMetadata.getScm() );
848 projectVersionMetadataModel.setMailingLists( versionMetadata.getMailingLists() );
849 projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() );
850 projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() );
852 // we don't test of repository and namespace really exist !
853 String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
854 namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build();
856 // FIXME nested objects to store!!!
859 String cf = cassandraArchivaManager.getProjectFamilyName();
860 projectVersionMetadataModelTemplate.createMutator()
862 .addInsertion( key, //
864 CassandraUtils.column( "projectId", projectId ) ) //
865 .addInsertion( key, //
867 CassandraUtils.column( "repositoryName", repositoryId ) ) //
868 .addInsertion( key, //
870 CassandraUtils.column( "namespaceId", namespaceId ) )//
871 .addInsertion( key, //
873 CassandraUtils.column( "id", versionMetadata.getVersion() ) ) //
874 .addInsertion( key, //
876 CassandraUtils.column( "description", versionMetadata.getDescription() ) ) //
877 .addInsertion( key, //
879 CassandraUtils.column( "name", versionMetadata.getName() ) ) //
880 .addInsertion( key, //
882 CassandraUtils.column( "incomplete", Boolean.toString( versionMetadata.isIncomplete() ) )
884 .addInsertion( key, //
886 CassandraUtils.column( "url", versionMetadata.getUrl() ) ) //
891 ColumnFamilyUpdater<String, String> updater = projectVersionMetadataModelTemplate.createUpdater( key );
892 updater.setString( "projectId", projectId );
893 updater.setString( "repositoryName", repositoryId );
894 updater.setString( "namespaceId", namespaceId );
895 updater.setString( "id", versionMetadata.getVersion() );
896 updater.setString( "description", versionMetadata.getDescription() );
897 updater.setString( "name", versionMetadata.getName() );
898 updater.setString( "incomplete", Boolean.toString( versionMetadata.isIncomplete() ) );
899 updater.setString( "url", versionMetadata.getUrl() );
901 projectVersionMetadataModelTemplate.update( updater );
905 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
907 /*artifactMetadataModel.setArtifactMetadataModelId(
908 new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
909 repositoryId ).withNamespace( namespaceId ).withProjectVersion(
910 versionMetadata.getVersion() ).withProject( projectId ).build()
912 artifactMetadataModel.setRepositoryId( repositoryId );
913 artifactMetadataModel.setNamespace( namespaceId );
914 artifactMetadataModel.setProject( projectId );
915 artifactMetadataModel.setProjectVersion( versionMetadata.getVersion() );
916 artifactMetadataModel.setVersion( versionMetadata.getVersion() );
917 updateFacets( versionMetadata, artifactMetadataModel );
919 /* String namespaceKey =
920 new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
921 Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
922 if ( namespace == null )
924 namespace = updateOrAddNamespace( repositoryId, namespaceId );
927 String key = new Project.KeyBuilder().withNamespace( namespace ).withProjectId( projectId ).build();
929 Project project = getProjectEntityManager().get( key );
930 if ( project == null )
932 project = new Project( key, projectId, namespace );
933 getProjectEntityManager().put( project );
936 // we don't test of repository and namespace really exist !
937 key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
938 namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build();
940 ProjectVersionMetadataModel projectVersionMetadataModel =
941 getProjectVersionMetadataModelEntityManager().get( key );
943 if ( projectVersionMetadataModel == null )
945 projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
946 projectVersionMetadataModel.setRowId( key );
948 projectVersionMetadataModel.setProjectId( projectId );
949 projectVersionMetadataModel.setNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) );
950 projectVersionMetadataModel.setCiManagement( versionMetadata.getCiManagement() );
951 projectVersionMetadataModel.setIssueManagement( versionMetadata.getIssueManagement() );
952 projectVersionMetadataModel.setOrganization( versionMetadata.getOrganization() );
953 projectVersionMetadataModel.setScm( versionMetadata.getScm() );
955 projectVersionMetadataModel.setMailingLists( versionMetadata.getMailingLists() );
956 projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() );
957 projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() );
961 getProjectVersionMetadataModelEntityManager().put( projectVersionMetadataModel );
963 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
964 artifactMetadataModel.setArtifactMetadataModelId(
965 new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
966 repositoryId ).withNamespace( namespaceId ).withProjectVersion(
967 versionMetadata.getVersion() ).withProject( projectId ).build()
969 artifactMetadataModel.setRepositoryId( repositoryId );
970 artifactMetadataModel.setNamespace( namespaceId );
971 artifactMetadataModel.setProject( projectId );
972 artifactMetadataModel.setProjectVersion( versionMetadata.getVersion() );
973 artifactMetadataModel.setVersion( versionMetadata.getVersion() );
975 updateFacets( versionMetadata, artifactMetadataModel );
977 catch ( PersistenceException e )
979 throw new MetadataRepositoryException( e.getMessage(), e );
985 public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
986 ArtifactMetadata artifactMeta )
987 throws MetadataRepositoryException
990 Namespace namespace = getNamespace( repositoryId, namespaceId );
991 if ( namespace == null )
993 namespace = updateOrAddNamespace( repositoryId, namespaceId );
996 ProjectMetadata projectMetadata = new ProjectMetadata();
997 projectMetadata.setId( projectId );
998 projectMetadata.setNamespace( namespaceId );
999 updateProject( repositoryId, projectMetadata );
1001 String key = new ArtifactMetadataModel.KeyBuilder().withNamespace( namespace ).withProject( projectId ).withId(
1002 artifactMeta.getId() ).withProjectVersion( projectVersion ).build();
1006 boolean exists = this.artifactMetadataTemplate.isColumnsExist( key );
1011 ColumnFamilyUpdater<String, String> updater = this.artifactMetadataTemplate.createUpdater( key );
1012 updater.setLong( "fileLastModified", artifactMeta.getFileLastModified().getTime() );
1013 updater.setLong( "whenGathered", artifactMeta.getWhenGathered().getTime() );
1014 updater.setLong( "size", artifactMeta.getSize() );
1015 updater.setString( "md5", artifactMeta.getMd5() );
1016 updater.setString( "sha1", artifactMeta.getSha1() );
1017 updater.setString( "version", artifactMeta.getVersion() );
1018 this.artifactMetadataTemplate.update( updater );
1022 String cf = this.cassandraArchivaManager.getArtifactMetadataModelFamilyName();
1024 this.artifactMetadataTemplate.createMutator().addInsertion( key, //
1026 column( "id", artifactMeta.getId() ) )//
1027 .addInsertion( key, //
1029 column( "repositoryName", repositoryId ) ) //
1030 .addInsertion( key, //
1032 column( "namespaceId", namespaceId ) ).addInsertion( key, //
1035 artifactMeta.getProject() )
1037 .addInsertion( key, //
1039 column( "projectVersion", artifactMeta.getProjectVersion() ) ) //
1040 .addInsertion( key, //
1042 column( "version", artifactMeta.getVersion() ) ) //
1043 .addInsertion( key, //
1045 column( "fileLastModified", artifactMeta.getFileLastModified().getTime() ) ) //
1046 .addInsertion( key, //
1048 column( "size", artifactMeta.getSize() ) ) //
1049 .addInsertion( key, //
1051 column( "md5", artifactMeta.getMd5() ) ) //
1052 .addInsertion( key, //
1054 column( "sha1", artifactMeta.getSha1() ) ) //
1055 .addInsertion( key, //
1057 column( "whenGathered", artifactMeta.getWhenGathered().getTime() ) )//
1061 key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
1062 namespace ).withProjectId( projectId ).withId( projectVersion ).build();
1064 exists = this.projectVersionMetadataModelTemplate.isColumnsExist( key );
1068 ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
1069 projectVersionMetadataModel.setProjectId( projectId );
1070 projectVersionMetadataModel.setId( projectVersion );
1071 projectVersionMetadataModel.setNamespace( namespace );
1073 String cf = this.cassandraArchivaManager.getProjectVersionMetadataModelFamilyName();
1075 projectVersionMetadataModelTemplate.createMutator() //
1076 .addInsertion( key, cf, column( "namespaceId", namespace.getName() ) ) //
1077 .addInsertion( key, cf, column( "repositoryName", repositoryId ) ) //
1078 .addInsertion( key, cf, column( "id", artifactMeta.getId() ) ) //
1079 .addInsertion( key, cf, column( "projectId", projectId ) ) //
1084 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
1086 /*artifactMetadataModel.setArtifactMetadataModelId(
1087 new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
1088 repositoryId ).withNamespace( namespaceId ).withProjectVersion(
1089 versionMetadata.getVersion() ).withProject( projectId ).build()
1091 artifactMetadataModel.setRepositoryId( repositoryId );
1092 artifactMetadataModel.setNamespace( namespaceId );
1093 artifactMetadataModel.setProject( projectId );
1094 artifactMetadataModel.setProjectVersion( artifactMeta.getVersion() );
1095 artifactMetadataModel.setVersion( artifactMeta.getVersion() );
1097 updateFacets( artifactMeta, artifactMetadataModel );
1100 /* String namespaceKey =
1101 new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
1102 // create the namespace if not exists
1103 Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
1104 if ( namespace == null )
1106 namespace = updateOrAddNamespace( repositoryId, namespaceId );
1109 // create the project if not exist
1110 String projectKey = new Project.KeyBuilder().withNamespace( namespace ).withProjectId( projectId ).build();
1112 Project project = getProjectEntityManager().get( projectKey );
1113 if ( project == null )
1115 project = new Project( projectKey, projectId, namespace );
1118 getProjectEntityManager().put( project );
1120 catch ( PersistenceException e )
1122 throw new MetadataRepositoryException( e.getMessage(), e );
1126 String key = new ArtifactMetadataModel.KeyBuilder().withNamespace( namespace ).withProject( projectId ).withId(
1127 artifactMeta.getId() ).withProjectVersion( projectVersion ).build();
1129 ArtifactMetadataModel artifactMetadataModel = getArtifactMetadataModelEntityManager().get( key );
1130 if ( artifactMetadataModel == null )
1132 artifactMetadataModel = new ArtifactMetadataModel( key, artifactMeta.getId(), repositoryId, namespaceId,
1133 artifactMeta.getProject(), projectVersion,
1134 artifactMeta.getVersion(),
1135 artifactMeta.getFileLastModified(),
1136 artifactMeta.getSize(), artifactMeta.getMd5(),
1137 artifactMeta.getSha1(), artifactMeta.getWhenGathered() );
1142 artifactMetadataModel.setFileLastModified( artifactMeta.getFileLastModified().getTime() );
1143 artifactMetadataModel.setWhenGathered( artifactMeta.getWhenGathered().getTime() );
1144 artifactMetadataModel.setSize( artifactMeta.getSize() );
1145 artifactMetadataModel.setMd5( artifactMeta.getMd5() );
1146 artifactMetadataModel.setSha1( artifactMeta.getSha1() );
1147 artifactMetadataModel.setVersion( artifactMeta.getVersion() );
1152 getArtifactMetadataModelEntityManager().put( artifactMetadataModel );
1154 catch ( PersistenceException e )
1156 throw new MetadataRepositoryException( e.getMessage(), e );
1159 key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
1160 namespace ).withProjectId( projectId ).withId( projectVersion ).build();
1162 ProjectVersionMetadataModel projectVersionMetadataModel =
1163 getProjectVersionMetadataModelEntityManager().get( key );
1165 if ( projectVersionMetadataModel == null )
1167 projectVersionMetadataModel = new ProjectVersionMetadataModel();
1168 projectVersionMetadataModel.setRowId( key );
1169 projectVersionMetadataModel.setProjectId( projectId );
1170 projectVersionMetadataModel.setId( projectVersion );
1171 projectVersionMetadataModel.setNamespace( namespace );
1173 getProjectVersionMetadataModelEntityManager().put( projectVersionMetadataModel );
1178 updateFacets( artifactMeta, artifactMetadataModel );*/
1183 public Collection<String> getArtifactVersions( final String repoId, final String namespace, final String projectId,
1184 final String projectVersion )
1185 throws MetadataResolutionException
1187 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
1189 QueryResult<OrderedRows<String, String, String>> result = HFactory //
1190 .createRangeSlicesQuery( keyspace, //
1191 StringSerializer.get(), //
1192 StringSerializer.get(), //
1193 StringSerializer.get() ) //
1194 .setColumnFamily( cassandraArchivaManager.getArtifactMetadataModelFamilyName() ) //
1195 .setColumnNames( "version" ) //
1196 .addEqualsExpression( "repositoryName", repoId ) //
1197 .addEqualsExpression( "namespaceId", namespace ) //
1198 .addEqualsExpression( "projectId", projectId ) //
1199 .addEqualsExpression( "projectVersion", projectVersion ).execute();
1201 final Set<String> versions = new HashSet<String>();
1203 for ( Row<String, String, String> row : result.get() )
1205 versions.add( row.getColumnSlice().getColumnByName( "version" ).getValue() );
1210 /* final Set<String> versions = new HashSet<String>();
1211 // FIXME use cql query
1212 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1215 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1217 if ( artifactMetadataModel != null )
1219 if ( StringUtils.equals( repoId, artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1220 namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals( projectId,
1221 artifactMetadataModel.getProject() )
1222 && StringUtils.equals( projectVersion, artifactMetadataModel.getProjectVersion() ) )
1224 versions.add( artifactMetadataModel.getVersion() );
1227 return Boolean.TRUE;
1236 * iterate over available facets to remove/add from the artifactMetadata
1238 * @param facetedMetadata
1239 * @param artifactMetadataModel only use for the key
1241 private void updateFacets( final FacetedMetadata facetedMetadata,
1242 final ArtifactMetadataModel artifactMetadataModel )
1245 /* for ( final String facetId : metadataFacetFactories.keySet() )
1247 MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId );
1248 if ( metadataFacet == null )
1254 final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
1256 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1259 public Boolean apply( MetadataFacetModel metadataFacetModel )
1261 ArtifactMetadataModel tmp = metadataFacetModel.getArtifactMetadataModel();
1262 if ( StringUtils.equals( metadataFacetModel.getFacetId(), facetId ) && StringUtils.equals(
1263 tmp.getRepositoryId(), artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1264 tmp.getNamespace(), artifactMetadataModel.getNamespace() ) && StringUtils.equals(
1265 tmp.getProject(), artifactMetadataModel.getProject() ) )
1267 metadataFacetModels.add( metadataFacetModel );
1269 return Boolean.TRUE;
1273 getMetadataFacetModelEntityManager().remove( metadataFacetModels );
1275 Map<String, String> properties = metadataFacet.toProperties();
1277 final List<MetadataFacetModel> metadataFacetModelsToAdd =
1278 new ArrayList<MetadataFacetModel>( properties.size() );
1280 for ( Map.Entry<String, String> entry : properties.entrySet() )
1282 String key = new MetadataFacetModel.KeyBuilder().withKey( entry.getKey() ).withArtifactMetadataModel(
1283 artifactMetadataModel ).withFacetId( facetId ).withName( metadataFacet.getName() ).build();
1284 MetadataFacetModel metadataFacetModel =
1285 new MetadataFacetModel( key, artifactMetadataModel, facetId, entry.getKey(), entry.getValue(),
1286 metadataFacet.getName() );
1287 metadataFacetModelsToAdd.add( metadataFacetModel );
1290 getMetadataFacetModelEntityManager().put( metadataFacetModelsToAdd );
1296 public List<String> getMetadataFacets( final String repositoryId, final String facetId )
1297 throws MetadataRepositoryException
1300 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
1302 QueryResult<OrderedRows<String, String, String>> result = HFactory //
1303 .createRangeSlicesQuery( keyspace, //
1304 StringSerializer.get(), //
1305 StringSerializer.get(), //
1306 StringSerializer.get() ) //
1307 .setColumnFamily( cassandraArchivaManager.getMetadataFacetModelFamilyName() ) //
1308 .setColumnNames( "name" ) //
1309 .addEqualsExpression( "repositoryName", repositoryId ) //
1310 .addEqualsExpression( "facetId", facetId ) //
1313 final List<String> facets = new ArrayList<String>();
1315 for ( Row<String, String, String> row : result.get() )
1317 facets.add( row.getColumnSlice().getColumnByName( "name" ).getValue() );
1323 public boolean hasMetadataFacet( String repositoryId, String facetId )
1324 throws MetadataRepositoryException
1326 return !getMetadataFacets( repositoryId, facetId ).isEmpty();
1330 public MetadataFacet getMetadataFacet( final String repositoryId, final String facetId, final String name )
1331 throws MetadataRepositoryException
1334 MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get( facetId );
1335 if ( metadataFacetFactory == null )
1340 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
1342 QueryResult<OrderedRows<String, String, String>> result = HFactory //
1343 .createRangeSlicesQuery( keyspace, //
1344 StringSerializer.get(), //
1345 StringSerializer.get(), //
1346 StringSerializer.get() ) //
1347 .setColumnFamily( cassandraArchivaManager.getMetadataFacetModelFamilyName() ) //
1348 .setColumnNames( "key", "value" ) //
1349 .addEqualsExpression( "repositoryName", repositoryId ) //
1350 .addEqualsExpression( "facetId", facetId ) //
1351 .addEqualsExpression( "name", name ) //
1354 MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet( repositoryId, name );
1355 Map<String, String> map = new HashMap<String, String>( result.get().getCount() );
1356 for ( Row<String, String, String> row : result.get() )
1358 ColumnSlice<String, String> columnSlice = row.getColumnSlice();
1359 map.put( columnSlice.getColumnByName( "key" ).getValue(),
1360 columnSlice.getColumnByName( "value" ).getValue() );
1362 metadataFacet.fromProperties( map );
1363 return metadataFacet;
1367 final List<MetadataFacetModel> facets = new ArrayList<MetadataFacetModel>();
1368 this.getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1371 public Boolean apply( MetadataFacetModel metadataFacetModel )
1373 if ( metadataFacetModel != null )
1375 if ( StringUtils.equals( metadataFacetModel.getArtifactMetadataModel().getRepositoryId(),
1376 repositoryId ) && StringUtils.equals( metadataFacetModel.getFacetId(),
1377 facetId ) && StringUtils.equals(
1378 metadataFacetModel.getName(), name ) )
1380 facets.add( metadataFacetModel );
1383 return Boolean.TRUE;
1387 if ( facets.isEmpty() )
1392 MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get( facetId );
1393 if ( metadataFacetFactory == null )
1397 MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet( repositoryId, name );
1398 Map<String, String> map = new HashMap<String, String>( facets.size() );
1399 for ( MetadataFacetModel metadataFacetModel : facets )
1401 map.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
1403 metadataFacet.fromProperties( map );
1404 return metadataFacet;*/
1408 public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
1409 throws MetadataRepositoryException
1412 if ( metadataFacet == null )
1417 if ( metadataFacet.toProperties().isEmpty() )
1419 String key = new MetadataFacetModel.KeyBuilder().withRepositoryId( repositoryId ).withFacetId(
1420 metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).build();
1422 boolean exists = this.metadataFacetTemplate.isColumnsExist( key );
1426 ColumnFamilyUpdater<String, String> updater = this.metadataFacetTemplate.createUpdater( key );
1427 updater.setString( "facetId", metadataFacet.getFacetId() );
1428 updater.setString( "name", metadataFacet.getName() );
1429 this.metadataFacetTemplate.update( updater );
1433 String cf = this.cassandraArchivaManager.getMetadataFacetModelFamilyName();
1434 this.metadataFacetTemplate.createMutator() //
1435 .addInsertion( key, cf, column( "repositoryName", repositoryId ) ) //
1436 .addInsertion( key, cf, column( "facetId", metadataFacet.getFacetId() ) ) //
1437 .addInsertion( key, cf, column( "name", metadataFacet.getName() ) ) //
1444 for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() )
1447 String key = new MetadataFacetModel.KeyBuilder().withRepositoryId( repositoryId ).withFacetId(
1448 metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).withKey( entry.getKey() ).build();
1450 boolean exists = this.metadataFacetTemplate.isColumnsExist( key );
1453 //metadataFacetModel = new MetadataFacetModel();
1454 // we need to store the repositoryId
1455 //ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
1456 //artifactMetadataModel.setRepositoryId( repositoryId );
1457 //metadataFacetModel.setArtifactMetadataModel( artifactMetadataModel );
1458 //metadataFacetModel.setId( key );
1459 //metadataFacetModel.setKey( entry.getKey() );
1460 //metadataFacetModel.setFacetId( metadataFacet.getFacetId() );
1461 //metadataFacetModel.setName( metadataFacet.getName() );
1463 String cf = this.cassandraArchivaManager.getMetadataFacetModelFamilyName();
1464 this.metadataFacetTemplate.createMutator() //
1465 .addInsertion( key, cf, column( "repositoryName", repositoryId ) ) //
1466 .addInsertion( key, cf, column( "facetId", metadataFacet.getFacetId() ) ) //
1467 .addInsertion( key, cf, column( "name", metadataFacet.getName() ) ) //
1468 .addInsertion( key, cf, column( "key", entry.getKey() ) ) //
1469 .addInsertion( key, cf, column( "value", entry.getValue() ) ) //
1475 ColumnFamilyUpdater<String, String> updater = this.metadataFacetTemplate.createUpdater( key );
1476 updater.setString( "value", entry.getValue() );
1477 this.metadataFacetTemplate.update( updater );
1484 public void removeMetadataFacets( final String repositoryId, final String facetId )
1485 throws MetadataRepositoryException
1487 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
1489 QueryResult<OrderedRows<String, String, String>> result = HFactory //
1490 .createRangeSlicesQuery( keyspace, //
1491 StringSerializer.get(), //
1492 StringSerializer.get(), //
1493 StringSerializer.get() ) //
1494 .setColumnFamily( cassandraArchivaManager.getMetadataFacetModelFamilyName() ) //
1495 .setColumnNames( "key", "value" ) //
1496 .addEqualsExpression( "repositoryName", repositoryId ) //
1497 .addEqualsExpression( "facetId", facetId ) //
1500 for ( Row<String, String, String> row : result.get() )
1502 this.metadataFacetTemplate.deleteRow( row.getKey() );
1508 public void removeMetadataFacet( final String repositoryId, final String facetId, final String name )
1509 throws MetadataRepositoryException
1511 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
1513 QueryResult<OrderedRows<String, String, String>> result = HFactory //
1514 .createRangeSlicesQuery( keyspace, //
1515 StringSerializer.get(), //
1516 StringSerializer.get(), //
1517 StringSerializer.get() ) //
1518 .setColumnFamily( cassandraArchivaManager.getMetadataFacetModelFamilyName() ) //
1519 .setColumnNames( "key", "value" ) //
1520 .addEqualsExpression( "repositoryName", repositoryId ) //
1521 .addEqualsExpression( "facetId", facetId ) //
1522 .addEqualsExpression( "name", name ) //
1525 for ( Row<String, String, String> row : result.get() )
1527 this.metadataFacetTemplate.deleteRow( row.getKey() );
1532 public List<ArtifactMetadata> getArtifactsByDateRange( final String repositoryId, final Date startTime,
1533 final Date endTime )
1534 throws MetadataRepositoryException
1537 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
1539 // FIXME cql query to filter in repositoryName column
1541 QueryResult<OrderedRows<String, String, Long>> result = HFactory //
1542 .createRangeSlicesQuery( keyspace, //
1543 StringSerializer.get(), //
1544 StringSerializer.get(), //
1545 LongSerializer.get() ) //
1547 .setColumnFamily( cassandraArchivaManager.getArtifactMetadataModelFamilyName() ) //
1548 .setColumnNames( "whenGathered", "repositoryName" ) //
1549 .addGteExpression( "whenGathered", startTime.getTime() ) //
1550 .addLteExpression( "whenGathered", endTime.getTime() )
1553 StringSerializer ss = StringSerializer.get();
1554 CqlQuery<String,String,String> cqlQuery = new CqlQuery<String,String,String>(keyspace, ss, ss, ss);
1555 cqlQuery.setQuery("select * from " + cassandraArchivaManager.getArtifactMetadataModelFamilyName() //
1556 + " where 'whenGathered' >= " + startTime.getTime() //
1557 + " and 'whenGathered' <= " + endTime.getTime() //
1558 + " and respositoryName = '" + repositoryId + "'");
1559 QueryResult<CqlRows<String,String,String>> result = cqlQuery.execute();
1560 List<String> keys = new ArrayList<String>( result.get().getCount() );
1562 for (Row<String,String,String> row : result.get())
1564 keys.add( row.getKey() );
1569 /* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1572 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1575 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1577 if ( artifactMetadataModel != null )
1579 if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId )
1580 && artifactMetadataModel.getNamespace() != null &&
1581 artifactMetadataModel.getProject() != null && artifactMetadataModel.getId() != null )
1584 Date when = artifactMetadataModel.getWhenGathered();
1585 if ( ( startTime != null ? when.getTime() >= startTime.getTime() : true ) && ( endTime != null ?
1586 when.getTime() <= endTime.getTime() : true ) )
1588 logger.debug( "getArtifactsByDateRange visitAll found: {}", artifactMetadataModel );
1589 artifactMetadataModels.add( artifactMetadataModel );
1593 return Boolean.TRUE;
1596 List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
1598 for ( ArtifactMetadataModel model : artifactMetadataModels )
1600 ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
1601 populateFacets( artifactMetadata );
1602 artifactMetadatas.add( artifactMetadata );
1607 logger.debug( "getArtifactsByDateRange repositoryId: {}, startTime: {}, endTime: {}, artifactMetadatas: {}",
1608 repositoryId, startTime, endTime, artifactMetadatas );
1610 return artifactMetadatas;*/
1611 return Collections.emptyList();
1614 protected void populateFacets( final ArtifactMetadata artifactMetadata )
1616 /* final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
1618 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1621 public Boolean apply( MetadataFacetModel metadataFacetModel )
1623 if ( metadataFacetModel != null )
1625 ArtifactMetadataModel artifactMetadataModel = metadataFacetModel.getArtifactMetadataModel();
1626 if ( artifactMetadataModel != null )
1628 if ( StringUtils.equals( artifactMetadata.getRepositoryId(),
1629 artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1630 artifactMetadata.getNamespace(), artifactMetadataModel.getNamespace() )
1631 && StringUtils.equals( artifactMetadata.getRepositoryId(),
1632 artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1633 artifactMetadata.getProject(), artifactMetadataModel.getProject() ) && StringUtils.equals(
1634 artifactMetadata.getId(), artifactMetadataModel.getId() ) )
1636 metadataFacetModels.add( metadataFacetModel );
1640 return Boolean.TRUE;
1643 Map<String, Map<String, String>> facetValuesPerFacet = new HashMap<String, Map<String, String>>();
1645 for ( MetadataFacetModel model : metadataFacetModels )
1647 Map<String, String> values = facetValuesPerFacet.get( model.getName() );
1648 if ( values == null )
1650 values = new HashMap<String, String>();
1652 values.put( model.getKey(), model.getValue() );
1653 facetValuesPerFacet.put( model.getName(), values );
1656 for ( Map.Entry<String, Map<String, String>> entry : facetValuesPerFacet.entrySet() )
1658 MetadataFacetFactory factory = metadataFacetFactories.get( entry.getKey() );
1659 if ( factory == null )
1663 MetadataFacet metadataFacet =
1664 factory.createMetadataFacet( artifactMetadata.getRepositoryId(), entry.getKey() );
1665 metadataFacet.fromProperties( entry.getValue() );
1666 artifactMetadata.addFacet( metadataFacet );
1671 public List<ArtifactMetadata> getArtifactsByChecksum( final String repositoryId, final String checksum )
1672 throws MetadataRepositoryException
1674 /* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1676 if ( logger.isDebugEnabled() )
1678 logger.debug( "all ArtifactMetadataModel: {}", getArtifactMetadataModelEntityManager().getAll() );
1682 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1685 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1687 if ( artifactMetadataModel != null )
1689 if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId )
1690 && artifactMetadataModel.getNamespace() != null &&
1691 artifactMetadataModel.getProject() != null && artifactMetadataModel.getId() != null )
1694 if ( StringUtils.equals( checksum, artifactMetadataModel.getMd5() ) || StringUtils.equals(
1695 checksum, artifactMetadataModel.getSha1() ) )
1697 artifactMetadataModels.add( artifactMetadataModel );
1701 return Boolean.TRUE;
1704 List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
1706 for ( ArtifactMetadataModel model : artifactMetadataModels )
1708 ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
1709 populateFacets( artifactMetadata );
1710 artifactMetadatas.add( artifactMetadata );
1713 logger.debug( "getArtifactsByChecksum repositoryId: {}, checksum: {}, artifactMetadatas: {}", repositoryId,
1714 checksum, artifactMetadatas );
1716 return artifactMetadatas;*/
1717 return Collections.emptyList();
1721 public void removeArtifact( final String repositoryId, final String namespace, final String project,
1722 final String version, final String id )
1723 throws MetadataRepositoryException
1725 /* logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
1726 repositoryId, namespace, project, version, id );
1728 new ArtifactMetadataModel.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespace ).withId(
1729 id ).withProjectVersion( version ).withProject( project ).build();
1731 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
1732 artifactMetadataModel.setArtifactMetadataModelId( key );
1734 getArtifactMetadataModelEntityManager().remove( artifactMetadataModel );
1737 new ProjectVersionMetadataModel.KeyBuilder().withId( version ).withRepository( repositoryId ).withNamespace(
1738 namespace ).withProjectId( project ).build();
1740 ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
1741 projectVersionMetadataModel.setRowId( key );
1743 getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );*/
1747 public void removeArtifact( ArtifactMetadata artifactMetadata, String baseVersion )
1748 throws MetadataRepositoryException
1750 logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
1751 artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(),
1752 artifactMetadata.getProject(), baseVersion, artifactMetadata.getId() );
1754 new ArtifactMetadataModel.KeyBuilder().withRepositoryId( artifactMetadata.getRepositoryId() ).withNamespace(
1755 artifactMetadata.getNamespace() ).withId( artifactMetadata.getId() ).withProjectVersion(
1756 baseVersion ).withProject( artifactMetadata.getProject() ).build();
1758 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
1759 artifactMetadataModel.setArtifactMetadataModelId( key );
1761 getArtifactMetadataModelEntityManager().remove( artifactMetadataModel );*/
1765 public void removeArtifact( final String repositoryId, final String namespace, final String project,
1766 final String version, final MetadataFacet metadataFacet )
1767 throws MetadataRepositoryException
1772 /* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1773 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1776 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1778 if ( artifactMetadataModel != null )
1780 if ( StringUtils.equals( repositoryId, artifactMetadataModel.getRepositoryId() )
1781 && StringUtils.equals( namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals(
1782 project, artifactMetadataModel.getProject() ) && StringUtils.equals( project,
1783 artifactMetadataModel.getVersion() ) )
1785 artifactMetadataModels.add( artifactMetadataModel );
1788 return Boolean.TRUE;
1791 getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );*/
1797 public List<ArtifactMetadata> getArtifacts( final String repositoryId )
1798 throws MetadataRepositoryException
1800 /* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1801 // FIXME use cql query !
1802 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1805 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1807 if ( artifactMetadataModel != null )
1809 if ( StringUtils.equals( repositoryId, artifactMetadataModel.getRepositoryId() ) )
1811 artifactMetadataModels.add( artifactMetadataModel );
1815 return Boolean.TRUE;
1819 List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
1821 for ( ArtifactMetadataModel model : artifactMetadataModels )
1823 ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
1824 populateFacets( artifactMetadata );
1825 artifactMetadatas.add( artifactMetadata );
1828 return artifactMetadatas;*/
1829 return Collections.emptyList();
1834 public ProjectVersionMetadata getProjectVersion( final String repoId, final String namespace,
1835 final String projectId, final String projectVersion )
1836 throws MetadataResolutionException
1838 /* String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace(
1839 namespace ).withProjectId( projectId ).withId( projectVersion ).build();
1841 ProjectVersionMetadataModel projectVersionMetadataModel =
1842 getProjectVersionMetadataModelEntityManager().get( key );
1844 if ( projectVersionMetadataModel == null )
1847 "getProjectVersion repoId: '{}', namespace: '{}', projectId: '{}', projectVersion: {} -> not found",
1848 repoId, namespace, projectId, projectVersion );
1852 ProjectVersionMetadata projectVersionMetadata =
1853 getModelMapper().map( projectVersionMetadataModel, ProjectVersionMetadata.class );
1855 logger.debug( "getProjectVersion repoId: '{}', namespace: '{}', projectId: '{}', projectVersion: {} -> {}",
1856 repoId, namespace, projectId, projectVersion, projectVersionMetadata );
1858 projectVersionMetadata.setCiManagement( projectVersionMetadataModel.getCiManagement() );
1859 projectVersionMetadata.setIssueManagement( projectVersionMetadataModel.getIssueManagement() );
1860 projectVersionMetadata.setOrganization( projectVersionMetadataModel.getOrganization() );
1861 projectVersionMetadata.setScm( projectVersionMetadataModel.getScm() );
1863 // FIXME complete collections !!
1866 final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
1867 // FIXME use cql query
1868 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1871 public Boolean apply( MetadataFacetModel metadataFacetModel )
1873 if ( metadataFacetModel != null )
1875 if ( StringUtils.equals( repoId, metadataFacetModel.getArtifactMetadataModel().getRepositoryId() )
1876 && StringUtils.equals( namespace, metadataFacetModel.getArtifactMetadataModel().getNamespace() )
1877 && StringUtils.equals( projectId, metadataFacetModel.getArtifactMetadataModel().getProject() )
1878 && StringUtils.equals( projectVersion,
1879 metadataFacetModel.getArtifactMetadataModel().getProjectVersion() ) )
1881 metadataFacetModels.add( metadataFacetModel );
1884 return Boolean.TRUE;
1887 Map<String, Map<String, String>> metadataFacetsPerFacetIds = new HashMap<String, Map<String, String>>();
1888 for ( MetadataFacetModel metadataFacetModel : metadataFacetModels )
1891 Map<String, String> metaValues = metadataFacetsPerFacetIds.get( metadataFacetModel.getFacetId() );
1892 if ( metaValues == null )
1894 metaValues = new HashMap<String, String>();
1895 metadataFacetsPerFacetIds.put( metadataFacetModel.getFacetId(), metaValues );
1897 metaValues.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
1901 if ( !metadataFacetsPerFacetIds.isEmpty() )
1903 for ( Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet() )
1905 MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get( entry.getKey() );
1906 if ( metadataFacetFactory != null )
1908 MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet( repoId, entry.getKey() );
1909 metadataFacet.fromProperties( entry.getValue() );
1910 projectVersionMetadata.addFacet( metadataFacet );
1915 return projectVersionMetadata;*/
1921 public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
1922 String projectVersion )
1923 throws MetadataResolutionException
1925 // FIXME implement this
1926 return Collections.emptyList();
1930 public void removeProjectVersion( final String repoId, final String namespace, final String projectId,
1931 final String projectVersion )
1932 throws MetadataRepositoryException
1935 final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1937 // FIXME use cql query
1939 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1942 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1944 if ( artifactMetadataModel != null )
1946 if ( StringUtils.equals( repoId, artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1947 namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals( projectId,
1948 artifactMetadataModel.getProject() )
1949 && StringUtils.equals( projectVersion, artifactMetadataModel.getProjectVersion() ) )
1951 artifactMetadataModels.add( artifactMetadataModel );
1954 return Boolean.TRUE;
1958 logger.debug( "removeProjectVersions:{}", artifactMetadataModels );
1959 if ( artifactMetadataModels.isEmpty() )
1964 getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
1966 String key = new ProjectVersionMetadataModel.KeyBuilder().withProjectId( projectId ).withId(
1967 projectVersion ).withRepository( repoId ).withNamespace( namespace ).build();
1969 ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
1970 projectVersionMetadataModel.setRowId( key );
1972 getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );
1977 public Collection<ArtifactMetadata> getArtifacts( final String repoId, final String namespace,
1978 final String projectId, final String projectVersion )
1979 throws MetadataResolutionException
1981 final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1983 // FIXME use cql query !
1984 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1987 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1989 if ( artifactMetadataModel != null )
1991 if ( StringUtils.equals( repoId, artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1992 namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals( projectId,
1993 artifactMetadataModel.getProject() )
1994 && StringUtils.equals( projectVersion, artifactMetadataModel.getProjectVersion() ) )
1996 artifactMetadataModels.add( artifactMetadataModel );
2000 return Boolean.TRUE;
2004 List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
2006 for ( ArtifactMetadataModel model : artifactMetadataModels )
2008 ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
2009 populateFacets( artifactMetadata );
2010 artifactMetadatas.add( artifactMetadata );
2014 final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
2015 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
2018 public Boolean apply( MetadataFacetModel metadataFacetModel )
2020 if ( metadataFacetModel != null )
2022 if ( StringUtils.equals( repoId, metadataFacetModel.getArtifactMetadataModel().getRepositoryId() )
2023 && StringUtils.equals( namespace, metadataFacetModel.getArtifactMetadataModel().getNamespace() )
2024 && StringUtils.equals( projectId, metadataFacetModel.getArtifactMetadataModel().getProject() )
2025 && StringUtils.equals( projectVersion,
2026 metadataFacetModel.getArtifactMetadataModel().getProjectVersion() ) )
2028 metadataFacetModels.add( metadataFacetModel );
2032 return Boolean.TRUE;
2036 // rebuild MetadataFacet for artifacts
2038 for ( final ArtifactMetadata artifactMetadata : artifactMetadatas )
2040 Iterable<MetadataFacetModel> metadataFacetModelIterable =
2041 Iterables.filter( metadataFacetModels, new Predicate<MetadataFacetModel>()
2044 public boolean apply( MetadataFacetModel metadataFacetModel )
2046 if ( metadataFacetModel != null )
2048 return StringUtils.equals( artifactMetadata.getVersion(),
2049 metadataFacetModel.getArtifactMetadataModel().getVersion() );
2054 Iterator<MetadataFacetModel> iterator = metadataFacetModelIterable.iterator();
2055 Map<String, List<MetadataFacetModel>> metadataFacetValuesPerFacetId =
2056 new HashMap<String, List<MetadataFacetModel>>();
2057 while ( iterator.hasNext() )
2059 MetadataFacetModel metadataFacetModel = iterator.next();
2060 List<MetadataFacetModel> values = metadataFacetValuesPerFacetId.get( metadataFacetModel.getName() );
2061 if ( values == null )
2063 values = new ArrayList<MetadataFacetModel>();
2064 metadataFacetValuesPerFacetId.put( metadataFacetModel.getFacetId(), values );
2066 values.add( metadataFacetModel );
2070 for ( Map.Entry<String, List<MetadataFacetModel>> entry : metadataFacetValuesPerFacetId.entrySet() )
2072 MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get( entry.getKey() );
2073 if ( metadataFacetFactory != null )
2075 List<MetadataFacetModel> facetModels = entry.getValue();
2076 if ( !facetModels.isEmpty() )
2078 MetadataFacet metadataFacet =
2079 metadataFacetFactory.createMetadataFacet( repoId, facetModels.get( 0 ).getName() );
2080 Map<String, String> props = new HashMap<String, String>( facetModels.size() );
2081 for ( MetadataFacetModel metadataFacetModel : facetModels )
2083 props.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
2085 metadataFacet.fromProperties( props );
2086 artifactMetadata.addFacet( metadataFacet );
2094 return artifactMetadatas;
2100 logger.trace( "save" );
2105 throws MetadataRepositoryException
2107 logger.trace( "close" );
2111 public void revert()
2113 logger.warn( "CassandraMetadataRepository cannot revert" );
2117 public boolean canObtainAccess( Class<?> aClass )
2123 public <T> T obtainAccess( Class<T> aClass )
2124 throws MetadataRepositoryException
2126 throw new IllegalArgumentException(
2127 "Access using " + aClass + " is not supported on the cassandra metadata storage" );
2131 private static class ModelMapperHolder
2133 private static ModelMapper MODEL_MAPPER = new ModelMapper();
2136 protected ModelMapper getModelMapper()
2138 return ModelMapperHolder.MODEL_MAPPER;