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.serializers.StringSerializer;
23 import me.prettyprint.hector.api.Keyspace;
24 import me.prettyprint.hector.api.beans.ColumnSlice;
25 import me.prettyprint.hector.api.beans.OrderedRows;
26 import me.prettyprint.hector.api.beans.Row;
27 import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
28 import me.prettyprint.hector.api.factory.HFactory;
29 import me.prettyprint.hector.api.mutation.MutationResult;
30 import me.prettyprint.hector.api.query.QueryResult;
31 import org.apache.archiva.configuration.ArchivaConfiguration;
32 import org.apache.archiva.metadata.model.ArtifactMetadata;
33 import org.apache.archiva.metadata.model.FacetedMetadata;
34 import org.apache.archiva.metadata.model.MetadataFacet;
35 import org.apache.archiva.metadata.model.MetadataFacetFactory;
36 import org.apache.archiva.metadata.model.ProjectMetadata;
37 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
38 import org.apache.archiva.metadata.model.ProjectVersionReference;
39 import org.apache.archiva.metadata.repository.MetadataRepository;
40 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
41 import org.apache.archiva.metadata.repository.MetadataResolutionException;
42 import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel;
43 import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
44 import org.apache.archiva.metadata.repository.cassandra.model.Project;
45 import org.apache.archiva.metadata.repository.cassandra.model.Repository;
46 import org.apache.commons.lang.StringUtils;
47 import org.modelmapper.ModelMapper;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
51 import javax.persistence.PersistenceException;
52 import java.util.ArrayList;
53 import java.util.Collection;
54 import java.util.Collections;
55 import java.util.Date;
56 import java.util.HashSet;
57 import java.util.List;
62 * @author Olivier Lamy
65 public class CassandraMetadataRepository
66 implements MetadataRepository
69 private Logger logger = LoggerFactory.getLogger( getClass() );
71 private ArchivaConfiguration configuration;
73 private final Map<String, MetadataFacetFactory> metadataFacetFactories;
75 private CassandraArchivaManager cassandraArchivaManager;
77 public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
78 ArchivaConfiguration configuration,
79 CassandraArchivaManager cassandraArchivaManager )
81 this.metadataFacetFactories = metadataFacetFactories;
82 this.configuration = configuration;
83 this.cassandraArchivaManager = cassandraArchivaManager;
88 * if the repository doesn't exist it will be created
93 public Repository getOrCreateRepository( String repositoryId )
94 throws MetadataRepositoryException
96 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
97 QueryResult<OrderedRows<String, String, String>> result = HFactory //
98 .createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(),
99 StringSerializer.get() ) //
100 .setColumnFamily( cassandraArchivaManager.getRepositoryFamilyName() ) //
101 .setColumnNames( "id", "name" ) //
102 .addEqualsExpression( "id", repositoryId ) //
105 if ( result.get().getCount() < 1 )
107 // we need to create the repository
108 Repository repository = new Repository( repositoryId );
112 MutationResult mutationResult = HFactory.createMutator( keyspace, StringSerializer.get() ) //
114 .addInsertion( repositoryId, //
115 cassandraArchivaManager.getRepositoryFamilyName(), //
116 CassandraUtils.column( "id", repository.getId() ) ) //
117 .addInsertion( repositoryId, //
118 cassandraArchivaManager.getRepositoryFamilyName(), //
119 CassandraUtils.column( "name", repository.getName() ) ) //
123 catch ( HInvalidRequestException e )
125 logger.error( e.getMessage(), e );
126 throw new MetadataRepositoryException( e.getMessage(), e );
131 return new Repository( result.get().getList().get( 0 ).getColumnSlice().getColumnByName( "id" ).getValue() );
135 protected Repository getRepository( String repositoryId )
136 throws MetadataRepositoryException
138 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
139 QueryResult<OrderedRows<String, String, String>> result = HFactory //
140 .createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(),
141 StringSerializer.get() ) //
142 .setColumnFamily( cassandraArchivaManager.getRepositoryFamilyName() ) //
143 .setColumnNames( "id", "name" ) //
144 .addEqualsExpression( "id", repositoryId ) //
146 return ( result.get().getCount() > 0 ) ? new Repository( repositoryId ) : null;
150 public void updateNamespace( String repositoryId, String namespaceId )
151 throws MetadataRepositoryException
153 updateOrAddNamespace( repositoryId, namespaceId );
157 public Namespace updateOrAddNamespace( String repositoryId, String namespaceId )
158 throws MetadataRepositoryException
162 Repository repository = getOrCreateRepository( repositoryId );
164 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
166 Namespace namespace = getNamespace( repositoryId, namespaceId );
167 if ( namespace == null )
169 namespace = new Namespace( namespaceId, repository );
170 HFactory.createMutator( keyspace, StringSerializer.get() )
172 .addInsertion( namespace.getId(), //
173 cassandraArchivaManager.getNamespaceFamilyName(), //
174 CassandraUtils.column( "name", namespace.getName() ) ) //
175 .addInsertion( namespace.getId(), //
176 cassandraArchivaManager.getNamespaceFamilyName(), //
177 CassandraUtils.column( "repositoryId", repository.getId() ) ) //
183 catch ( HInvalidRequestException e )
185 logger.error( e.getMessage(), e );
186 throw new MetadataRepositoryException( e.getMessage(), e );
190 protected Namespace getNamespace( String repositoryId, String namespaceId )
192 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
193 QueryResult<OrderedRows<String, String, String>> result = HFactory //
194 .createRangeSlicesQuery( keyspace, //
195 StringSerializer.get(), //
196 StringSerializer.get(), //
197 StringSerializer.get() ) //
198 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
199 .setColumnNames( "repositoryId", "name" ) //
200 .addEqualsExpression( "repositoryId", repositoryId ) //
201 .addEqualsExpression( "name", namespaceId ) //
203 if ( result.get().getCount() > 0 )
205 ColumnSlice<String, String> columnSlice = result.get().getList().get( 0 ).getColumnSlice();
206 return new Namespace( columnSlice.getColumnByName( "name" ).getValue(), //
207 new Repository( columnSlice.getColumnByName( "repositoryId" ).getValue() ) );
215 public void removeNamespace( String repositoryId, String namespaceId )
216 throws MetadataRepositoryException
221 new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build();
223 MutationResult result =
224 HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
225 .addDeletion( key, cassandraArchivaManager.getNamespaceFamilyName() ) //
230 catch ( HInvalidRequestException e )
232 logger.error( e.getMessage(), e );
233 throw new MetadataRepositoryException( e.getMessage(), e );
239 public void removeRepository( final String repositoryId )
240 throws MetadataRepositoryException
243 // FIXME remove all datas attached to the repositoryId
245 // retrieve and delete all namespace with this repositoryId
247 List<String> namespacesKey = new ArrayList<String>();
249 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
250 QueryResult<OrderedRows<String, String, String>> result = HFactory //
251 .createRangeSlicesQuery( keyspace, //
252 StringSerializer.get(), //
253 StringSerializer.get(), //
254 StringSerializer.get() ) //
255 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
256 .setColumnNames( "repositoryId", "name" ) //
257 .addEqualsExpression( "repositoryId", repositoryId ) //
260 for ( Row<String, String, String> row : result.get().getList() )
262 namespacesKey.add( row.getKey() );
265 HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
266 .addDeletion( namespacesKey, cassandraArchivaManager.getNamespaceFamilyName() ) //
269 //delete repositoryId
270 HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
271 .addDeletion( repositoryId, cassandraArchivaManager.getRepositoryFamilyName() ) //
275 final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
277 // remove data related to the repository
278 this.getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
281 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
283 if ( artifactMetadataModel != null )
285 if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId ) )
287 artifactMetadataModels.add( artifactMetadataModel );
294 getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
296 final List<Namespace> namespaces = new ArrayList<Namespace>();
298 getNamespaceEntityManager().visitAll( new Function<Namespace, Boolean>()
301 public Boolean apply( Namespace namespace )
303 if ( namespace != null )
305 if ( StringUtils.equals( namespace.getRepository().getId(), repositoryId ) )
307 namespaces.add( namespace );
314 getNamespaceEntityManager().remove( namespaces );
316 final List<Project> projects = new ArrayList<Project>();
317 getProjectEntityManager().visitAll( new Function<Project, Boolean>()
320 public Boolean apply( Project project )
322 if ( project != null )
324 if ( StringUtils.equals( project.getNamespace().getRepository().getId(), repositoryId ) )
326 projects.add( project );
333 getProjectEntityManager().remove( projects );
335 // TODO cleanup or not
336 //final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>( );
337 //getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
339 final List<ProjectVersionMetadataModel> projectVersionMetadataModels =
340 new ArrayList<ProjectVersionMetadataModel>();
342 getProjectVersionMetadataModelEntityManager().visitAll( new Function<ProjectVersionMetadataModel, Boolean>()
345 public Boolean apply( ProjectVersionMetadataModel projectVersionMetadataModel )
347 if ( projectVersionMetadataModel != null )
349 if ( StringUtils.equals( projectVersionMetadataModel.getNamespace().getRepository().getId(),
352 projectVersionMetadataModels.add( projectVersionMetadataModel );
359 getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
361 Repository repository = getRepositoryEntityManager().get( repositoryId );
362 if ( repository != null )
364 getRepositoryEntityManager().remove( repository );
371 public Collection<String> getRepositories()
372 throws MetadataRepositoryException
376 logger.debug( "getRepositories" );
378 final QueryResult<OrderedRows<String, String, String>> cResult = //
379 HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), //
380 StringSerializer.get(), //
381 StringSerializer.get(), //
382 StringSerializer.get() ) //
383 .setColumnFamily( "repository" ) //
384 .setColumnNames( "name" ) //
385 .setRange( null, null, false, Integer.MAX_VALUE ) //
388 List<String> repoIds = new ArrayList<String>( cResult.get().getCount() );
390 for ( Row<String, String, String> row : cResult.get() )
392 repoIds.add( row.getColumnSlice().getColumnByName( "name" ).getValue() );
397 catch ( PersistenceException e )
399 throw new MetadataRepositoryException( e.getMessage(), e );
406 public Collection<String> getRootNamespaces( final String repoId )
407 throws MetadataResolutionException
409 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
410 QueryResult<OrderedRows<String, String, String>> result = HFactory //
411 .createRangeSlicesQuery( keyspace, //
412 StringSerializer.get(), //
413 StringSerializer.get(), //
414 StringSerializer.get() ) //
415 .setColumnFamily( "namespace" ) //
416 .setColumnNames( "name" ) //
417 .addEqualsExpression( "repositoryId", repoId ) //
420 Set<String> namespaces = new HashSet<String>( result.get().getCount() );
422 for ( Row<String, String, String> row : result.get() )
425 StringUtils.substringBefore( row.getColumnSlice().getColumnByName( "name" ).getValue(), "." ) );
433 public Collection<String> getNamespaces( final String repoId, final String namespaceId )
434 throws MetadataResolutionException
436 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
437 QueryResult<OrderedRows<String, String, String>> result = HFactory //
438 .createRangeSlicesQuery( keyspace, //
439 StringSerializer.get(), //
440 StringSerializer.get(), //
441 StringSerializer.get() ) //
442 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
443 .setColumnNames( "name" ) //
444 .addEqualsExpression( "repositoryId", repoId ) //
447 List<String> namespaces = new ArrayList<String>( result.get().getCount() );
449 for ( Row<String, String, String> row : result.get() )
451 String currentNamespace = row.getColumnSlice().getColumnByName( "name" ).getValue();
452 if ( StringUtils.startsWith( currentNamespace, namespaceId ) && ( StringUtils.length( currentNamespace )
453 > StringUtils.length( namespaceId ) ) )
455 // store after namespaceId '.' but before next '.'
456 // call org namespace org.apache.maven.shared -> stored apache
458 String calledNamespace = StringUtils.endsWith( namespaceId, "." ) ? namespaceId : namespaceId + ".";
459 String storedNamespace = StringUtils.substringAfter( currentNamespace, calledNamespace );
461 storedNamespace = StringUtils.substringBefore( storedNamespace, "." );
463 namespaces.add( storedNamespace );
472 public List<String> getNamespaces( final String repoId )
473 throws MetadataResolutionException
475 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
476 QueryResult<OrderedRows<String, String, String>> result = HFactory //
477 .createRangeSlicesQuery( keyspace, //
478 StringSerializer.get(), //
479 StringSerializer.get(), //
480 StringSerializer.get() ) //
481 .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
482 .setColumnNames( "name" ) //
483 .addEqualsExpression( "repositoryId", repoId ) //
486 List<String> namespaces = new ArrayList<String>( result.get().getCount() );
488 for ( Row<String, String, String> row : result.get() )
490 namespaces.add( row.getColumnSlice().getColumnByName( "name" ).getValue() );
498 public void updateProject( String repositoryId, ProjectMetadata projectMetadata )
499 throws MetadataRepositoryException
501 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
503 QueryResult<OrderedRows<String, String, String>> result = HFactory //
504 .createRangeSlicesQuery( keyspace, //
505 StringSerializer.get(), //
506 StringSerializer.get(), //
507 StringSerializer.get() ) //
508 .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
509 .setColumnNames( "projectId" ) //
510 .addEqualsExpression( "repositoryId", repositoryId ) //
511 .addEqualsExpression( "namespaceId", projectMetadata.getNamespace() ) //
512 .addEqualsExpression( "projectId", projectMetadata.getId() ) //
515 // project exists ? if yes return
516 if ( result.get().getCount() > 0 )
521 Namespace namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() );
524 new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace( namespace ).build();
526 HFactory.createMutator( keyspace, StringSerializer.get() )
528 .addInsertion( key, //
529 cassandraArchivaManager.getProjectFamilyName(), //
530 CassandraUtils.column( "projectId", projectMetadata.getId() ) ) //
531 .addInsertion( key, //
532 cassandraArchivaManager.getProjectFamilyName(), //
533 CassandraUtils.column( "repositoryId", repositoryId ) ) //
534 .addInsertion( key, //
535 cassandraArchivaManager.getProjectFamilyName(), //
536 CassandraUtils.column( "namespaceId", projectMetadata.getNamespace() ) )//
541 public Collection<String> getProjects( final String repoId, final String namespace )
542 throws MetadataResolutionException
545 Keyspace keyspace = cassandraArchivaManager.getKeyspace();
547 QueryResult<OrderedRows<String, String, String>> result = HFactory //
548 .createRangeSlicesQuery( keyspace, //
549 StringSerializer.get(), //
550 StringSerializer.get(), //
551 StringSerializer.get() ) //
552 .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
553 .setColumnNames( "projectId" ) //
554 .addEqualsExpression( "repositoryId", repoId ) //
555 .addEqualsExpression( "namespaceId", namespace ) //
558 final Set<String> projects = new HashSet<String>( result.get().getCount() );
560 for ( Row<String, String, String> row : result.get() )
562 projects.add( row.getColumnSlice().getColumnByName( "projectId" ).getValue() );
569 public void removeProject( final String repositoryId, final String namespaceId, final String projectId )
570 throws MetadataRepositoryException
573 /* // cleanup ArtifactMetadataModel
574 final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
576 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
579 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
581 if ( artifactMetadataModel != null )
583 if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId )
584 && StringUtils.equals( artifactMetadataModel.getNamespace(), namespaceId )
585 && StringUtils.equals( artifactMetadataModel.getProject(), projectId ) )
587 artifactMetadataModels.add( artifactMetadataModel );
594 getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
596 Namespace namespace = new Namespace( namespaceId, new Repository( repositoryId ) );
598 final List<ProjectVersionMetadataModel> projectVersionMetadataModels =
599 new ArrayList<ProjectVersionMetadataModel>();
601 getProjectVersionMetadataModelEntityManager().visitAll( new Function<ProjectVersionMetadataModel, Boolean>()
604 public Boolean apply( ProjectVersionMetadataModel projectVersionMetadataModel )
606 if ( projectVersionMetadataModel != null )
608 if ( StringUtils.equals( repositoryId,
609 projectVersionMetadataModel.getNamespace().getRepository().getName() )
610 && StringUtils.equals( namespaceId, projectVersionMetadataModel.getNamespace().getName() )
611 && StringUtils.equals( projectId, projectVersionMetadataModel.getProjectId() ) )
613 projectVersionMetadataModels.add( projectVersionMetadataModel );
620 if ( !projectVersionMetadataModels.isEmpty() )
622 getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
625 String key = new Project.KeyBuilder().withNamespace( namespace ).withProjectId( projectId ).build();
627 Project project = getProjectEntityManager().get( key );
628 if ( project == null )
630 logger.debug( "removeProject notfound" );
633 logger.debug( "removeProject {}", project );
635 getProjectEntityManager().remove( project );*/
639 public Collection<String> getProjectVersions( final String repoId, final String namespace, final String projectId )
640 throws MetadataResolutionException
643 /* final Set<String> versions = new HashSet<String>();
644 getProjectVersionMetadataModelEntityManager().visitAll( new Function<ProjectVersionMetadataModel, Boolean>()
647 public Boolean apply( ProjectVersionMetadataModel projectVersionMetadataModel )
649 if ( projectVersionMetadataModel != null )
651 if ( StringUtils.equals( repoId,
652 projectVersionMetadataModel.getNamespace().getRepository().getName() )
653 && StringUtils.startsWith( projectVersionMetadataModel.getNamespace().getName(), namespace )
654 && StringUtils.equals( projectId, projectVersionMetadataModel.getProjectId() ) )
656 versions.add( projectVersionMetadataModel.getId() );
662 // FIXME use cql query
663 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
666 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
668 if ( artifactMetadataModel != null )
670 if ( StringUtils.equals( repoId, artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
671 namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals( projectId,
672 artifactMetadataModel.getProject() ) )
674 versions.add( artifactMetadataModel.getProjectVersion() );
685 public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
686 ArtifactMetadata artifactMeta )
687 throws MetadataRepositoryException
689 /* String namespaceKey =
690 new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
691 // create the namespace if not exists
692 Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
693 if ( namespace == null )
695 namespace = updateOrAddNamespace( repositoryId, namespaceId );
698 // create the project if not exist
699 String projectKey = new Project.KeyBuilder().withNamespace( namespace ).withProjectId( projectId ).build();
701 Project project = getProjectEntityManager().get( projectKey );
702 if ( project == null )
704 project = new Project( projectKey, projectId, namespace );
707 getProjectEntityManager().put( project );
709 catch ( PersistenceException e )
711 throw new MetadataRepositoryException( e.getMessage(), e );
715 String key = new ArtifactMetadataModel.KeyBuilder().withNamespace( namespace ).withProject( projectId ).withId(
716 artifactMeta.getId() ).withProjectVersion( projectVersion ).build();
718 ArtifactMetadataModel artifactMetadataModel = getArtifactMetadataModelEntityManager().get( key );
719 if ( artifactMetadataModel == null )
721 artifactMetadataModel = new ArtifactMetadataModel( key, artifactMeta.getId(), repositoryId, namespaceId,
722 artifactMeta.getProject(), projectVersion,
723 artifactMeta.getVersion(),
724 artifactMeta.getFileLastModified(),
725 artifactMeta.getSize(), artifactMeta.getMd5(),
726 artifactMeta.getSha1(), artifactMeta.getWhenGathered() );
731 artifactMetadataModel.setFileLastModified( artifactMeta.getFileLastModified().getTime() );
732 artifactMetadataModel.setWhenGathered( artifactMeta.getWhenGathered().getTime() );
733 artifactMetadataModel.setSize( artifactMeta.getSize() );
734 artifactMetadataModel.setMd5( artifactMeta.getMd5() );
735 artifactMetadataModel.setSha1( artifactMeta.getSha1() );
736 artifactMetadataModel.setVersion( artifactMeta.getVersion() );
741 getArtifactMetadataModelEntityManager().put( artifactMetadataModel );
743 catch ( PersistenceException e )
745 throw new MetadataRepositoryException( e.getMessage(), e );
748 key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
749 namespace ).withProjectId( projectId ).withId( projectVersion ).build();
751 ProjectVersionMetadataModel projectVersionMetadataModel =
752 getProjectVersionMetadataModelEntityManager().get( key );
754 if ( projectVersionMetadataModel == null )
756 projectVersionMetadataModel = new ProjectVersionMetadataModel();
757 projectVersionMetadataModel.setRowId( key );
758 projectVersionMetadataModel.setProjectId( projectId );
759 projectVersionMetadataModel.setId( projectVersion );
760 projectVersionMetadataModel.setNamespace( namespace );
762 getProjectVersionMetadataModelEntityManager().put( projectVersionMetadataModel );
767 updateFacets( artifactMeta, artifactMetadataModel );*/
772 public Collection<String> getArtifactVersions( final String repoId, final String namespace, final String projectId,
773 final String projectVersion )
774 throws MetadataResolutionException
776 /* final Set<String> versions = new HashSet<String>();
777 // FIXME use cql query
778 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
781 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
783 if ( artifactMetadataModel != null )
785 if ( StringUtils.equals( repoId, artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
786 namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals( projectId,
787 artifactMetadataModel.getProject() )
788 && StringUtils.equals( projectVersion, artifactMetadataModel.getProjectVersion() ) )
790 versions.add( artifactMetadataModel.getVersion() );
802 * iterate over available facets to remove/add from the artifactMetadata
804 * @param facetedMetadata
805 * @param artifactMetadataModel only use for the key
807 private void updateFacets( final FacetedMetadata facetedMetadata,
808 final ArtifactMetadataModel artifactMetadataModel )
811 /* for ( final String facetId : metadataFacetFactories.keySet() )
813 MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId );
814 if ( metadataFacet == null )
820 final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
822 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
825 public Boolean apply( MetadataFacetModel metadataFacetModel )
827 ArtifactMetadataModel tmp = metadataFacetModel.getArtifactMetadataModel();
828 if ( StringUtils.equals( metadataFacetModel.getFacetId(), facetId ) && StringUtils.equals(
829 tmp.getRepositoryId(), artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
830 tmp.getNamespace(), artifactMetadataModel.getNamespace() ) && StringUtils.equals(
831 tmp.getProject(), artifactMetadataModel.getProject() ) )
833 metadataFacetModels.add( metadataFacetModel );
839 getMetadataFacetModelEntityManager().remove( metadataFacetModels );
841 Map<String, String> properties = metadataFacet.toProperties();
843 final List<MetadataFacetModel> metadataFacetModelsToAdd =
844 new ArrayList<MetadataFacetModel>( properties.size() );
846 for ( Map.Entry<String, String> entry : properties.entrySet() )
848 String key = new MetadataFacetModel.KeyBuilder().withKey( entry.getKey() ).withArtifactMetadataModel(
849 artifactMetadataModel ).withFacetId( facetId ).withName( metadataFacet.getName() ).build();
850 MetadataFacetModel metadataFacetModel =
851 new MetadataFacetModel( key, artifactMetadataModel, facetId, entry.getKey(), entry.getValue(),
852 metadataFacet.getName() );
853 metadataFacetModelsToAdd.add( metadataFacetModel );
856 getMetadataFacetModelEntityManager().put( metadataFacetModelsToAdd );
861 public void updateProjectVersion( String repositoryId, String namespaceId, String projectId,
862 ProjectVersionMetadata versionMetadata )
863 throws MetadataRepositoryException
865 /* String namespaceKey =
866 new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
867 Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
868 if ( namespace == null )
870 namespace = updateOrAddNamespace( repositoryId, namespaceId );
873 String key = new Project.KeyBuilder().withNamespace( namespace ).withProjectId( projectId ).build();
875 Project project = getProjectEntityManager().get( key );
876 if ( project == null )
878 project = new Project( key, projectId, namespace );
879 getProjectEntityManager().put( project );
882 // we don't test of repository and namespace really exist !
883 key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
884 namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build();
886 ProjectVersionMetadataModel projectVersionMetadataModel =
887 getProjectVersionMetadataModelEntityManager().get( key );
889 if ( projectVersionMetadataModel == null )
891 projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
892 projectVersionMetadataModel.setRowId( key );
894 projectVersionMetadataModel.setProjectId( projectId );
895 projectVersionMetadataModel.setNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) );
896 projectVersionMetadataModel.setCiManagement( versionMetadata.getCiManagement() );
897 projectVersionMetadataModel.setIssueManagement( versionMetadata.getIssueManagement() );
898 projectVersionMetadataModel.setOrganization( versionMetadata.getOrganization() );
899 projectVersionMetadataModel.setScm( versionMetadata.getScm() );
901 projectVersionMetadataModel.setMailingLists( versionMetadata.getMailingLists() );
902 projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() );
903 projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() );
907 getProjectVersionMetadataModelEntityManager().put( projectVersionMetadataModel );
909 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
910 artifactMetadataModel.setArtifactMetadataModelId(
911 new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
912 repositoryId ).withNamespace( namespaceId ).withProjectVersion(
913 versionMetadata.getVersion() ).withProject( projectId ).build()
915 artifactMetadataModel.setRepositoryId( repositoryId );
916 artifactMetadataModel.setNamespace( namespaceId );
917 artifactMetadataModel.setProject( projectId );
918 artifactMetadataModel.setProjectVersion( versionMetadata.getVersion() );
919 artifactMetadataModel.setVersion( versionMetadata.getVersion() );
921 updateFacets( versionMetadata, artifactMetadataModel );
923 catch ( PersistenceException e )
925 throw new MetadataRepositoryException( e.getMessage(), e );
930 private static class BooleanHolder
932 private boolean value = false;
936 public List<String> getMetadataFacets( final String repositoryId, final String facetId )
937 throws MetadataRepositoryException
939 /* // FIXME use cql query !!
940 final List<String> facets = new ArrayList<String>();
941 this.getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
944 public Boolean apply( MetadataFacetModel metadataFacetModel )
946 if ( metadataFacetModel != null )
948 if ( StringUtils.equals( metadataFacetModel.getArtifactMetadataModel().getRepositoryId(),
949 repositoryId ) && StringUtils.equals( metadataFacetModel.getFacetId(),
952 facets.add( metadataFacetModel.getName() );
965 public boolean hasMetadataFacet( String repositoryId, String facetId )
966 throws MetadataRepositoryException
968 return !getMetadataFacets( repositoryId, facetId ).isEmpty();
972 public MetadataFacet getMetadataFacet( final String repositoryId, final String facetId, final String name )
973 throws MetadataRepositoryException
975 /* // FIXME use cql query !!
976 final List<MetadataFacetModel> facets = new ArrayList<MetadataFacetModel>();
977 this.getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
980 public Boolean apply( MetadataFacetModel metadataFacetModel )
982 if ( metadataFacetModel != null )
984 if ( StringUtils.equals( metadataFacetModel.getArtifactMetadataModel().getRepositoryId(),
985 repositoryId ) && StringUtils.equals( metadataFacetModel.getFacetId(),
986 facetId ) && StringUtils.equals(
987 metadataFacetModel.getName(), name ) )
989 facets.add( metadataFacetModel );
996 if ( facets.isEmpty() )
1001 MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get( facetId );
1002 if ( metadataFacetFactory == null )
1006 MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet( repositoryId, name );
1007 Map<String, String> map = new HashMap<String, String>( facets.size() );
1008 for ( MetadataFacetModel metadataFacetModel : facets )
1010 map.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
1012 metadataFacet.fromProperties( map );
1013 return metadataFacet;*/
1018 public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
1019 throws MetadataRepositoryException
1022 if ( metadataFacet == null )
1027 if ( metadataFacet.toProperties().isEmpty() )
1029 String key = new MetadataFacetModel.KeyBuilder().withRepositoryId( repositoryId ).withFacetId(
1030 metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).build();
1031 MetadataFacetModel metadataFacetModel = getMetadataFacetModelEntityManager().get( key );
1032 if ( metadataFacetModel == null )
1034 metadataFacetModel = new MetadataFacetModel();
1036 // we need to store the repositoryId
1037 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
1038 artifactMetadataModel.setRepositoryId( repositoryId );
1039 metadataFacetModel.setArtifactMetadataModel( artifactMetadataModel );
1040 metadataFacetModel.setId( key );
1041 metadataFacetModel.setFacetId( metadataFacet.getFacetId() );
1042 metadataFacetModel.setName( metadataFacet.getName() );
1046 getMetadataFacetModelEntityManager().put( metadataFacetModel );
1048 catch ( PersistenceException e )
1050 throw new MetadataRepositoryException( e.getMessage(), e );
1055 for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() )
1058 String key = new MetadataFacetModel.KeyBuilder().withRepositoryId( repositoryId ).withFacetId(
1059 metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).withKey( entry.getKey() ).build();
1061 MetadataFacetModel metadataFacetModel = getMetadataFacetModelEntityManager().get( key );
1062 if ( metadataFacetModel == null )
1064 metadataFacetModel = new MetadataFacetModel();
1065 // we need to store the repositoryId
1066 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
1067 artifactMetadataModel.setRepositoryId( repositoryId );
1068 metadataFacetModel.setArtifactMetadataModel( artifactMetadataModel );
1069 metadataFacetModel.setId( key );
1070 metadataFacetModel.setKey( entry.getKey() );
1071 metadataFacetModel.setFacetId( metadataFacet.getFacetId() );
1072 metadataFacetModel.setName( metadataFacet.getName() );
1074 metadataFacetModel.setValue( entry.getValue() );
1077 getMetadataFacetModelEntityManager().put( metadataFacetModel );
1079 catch ( PersistenceException e )
1081 throw new MetadataRepositoryException( e.getMessage(), e );
1089 public void removeMetadataFacets( final String repositoryId, final String facetId )
1090 throws MetadataRepositoryException
1092 /* logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
1093 final List<MetadataFacetModel> toRemove = new ArrayList<MetadataFacetModel>();
1096 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1099 public Boolean apply( MetadataFacetModel metadataFacetModel )
1101 if ( metadataFacetModel != null )
1103 if ( StringUtils.equals( metadataFacetModel.getArtifactMetadataModel().getRepositoryId(),
1104 repositoryId ) && StringUtils.equals( metadataFacetModel.getFacetId(),
1107 toRemove.add( metadataFacetModel );
1110 return Boolean.TRUE;
1113 logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}', toRemove: {}", repositoryId, facetId,
1115 getMetadataFacetModelEntityManager().remove( toRemove );*/
1119 public void removeMetadataFacet( final String repositoryId, final String facetId, final String name )
1120 throws MetadataRepositoryException
1122 /* logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
1123 final List<MetadataFacetModel> toRemove = new ArrayList<MetadataFacetModel>();
1126 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1129 public Boolean apply( MetadataFacetModel metadataFacetModel )
1131 if ( metadataFacetModel != null )
1133 if ( StringUtils.equals( metadataFacetModel.getArtifactMetadataModel().getRepositoryId(),
1134 repositoryId ) && StringUtils.equals( metadataFacetModel.getFacetId(),
1135 facetId ) && StringUtils.equals(
1136 metadataFacetModel.getName(), name ) )
1138 toRemove.add( metadataFacetModel );
1141 return Boolean.TRUE;
1144 logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}', toRemove: {}", repositoryId, facetId,
1146 getMetadataFacetModelEntityManager().remove( toRemove );*/
1150 public List<ArtifactMetadata> getArtifactsByDateRange( final String repositoryId, final Date startTime,
1151 final Date endTime )
1152 throws MetadataRepositoryException
1155 /* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1158 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1161 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1163 if ( artifactMetadataModel != null )
1165 if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId )
1166 && artifactMetadataModel.getNamespace() != null &&
1167 artifactMetadataModel.getProject() != null && artifactMetadataModel.getId() != null )
1170 Date when = artifactMetadataModel.getWhenGathered();
1171 if ( ( startTime != null ? when.getTime() >= startTime.getTime() : true ) && ( endTime != null ?
1172 when.getTime() <= endTime.getTime() : true ) )
1174 logger.debug( "getArtifactsByDateRange visitAll found: {}", artifactMetadataModel );
1175 artifactMetadataModels.add( artifactMetadataModel );
1179 return Boolean.TRUE;
1182 List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
1184 for ( ArtifactMetadataModel model : artifactMetadataModels )
1186 ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
1187 populateFacets( artifactMetadata );
1188 artifactMetadatas.add( artifactMetadata );
1193 logger.debug( "getArtifactsByDateRange repositoryId: {}, startTime: {}, endTime: {}, artifactMetadatas: {}",
1194 repositoryId, startTime, endTime, artifactMetadatas );
1196 return artifactMetadatas;*/
1197 return Collections.emptyList();
1200 protected void populateFacets( final ArtifactMetadata artifactMetadata )
1202 /* final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
1204 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1207 public Boolean apply( MetadataFacetModel metadataFacetModel )
1209 if ( metadataFacetModel != null )
1211 ArtifactMetadataModel artifactMetadataModel = metadataFacetModel.getArtifactMetadataModel();
1212 if ( artifactMetadataModel != null )
1214 if ( StringUtils.equals( artifactMetadata.getRepositoryId(),
1215 artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1216 artifactMetadata.getNamespace(), artifactMetadataModel.getNamespace() )
1217 && StringUtils.equals( artifactMetadata.getRepositoryId(),
1218 artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1219 artifactMetadata.getProject(), artifactMetadataModel.getProject() ) && StringUtils.equals(
1220 artifactMetadata.getId(), artifactMetadataModel.getId() ) )
1222 metadataFacetModels.add( metadataFacetModel );
1226 return Boolean.TRUE;
1229 Map<String, Map<String, String>> facetValuesPerFacet = new HashMap<String, Map<String, String>>();
1231 for ( MetadataFacetModel model : metadataFacetModels )
1233 Map<String, String> values = facetValuesPerFacet.get( model.getName() );
1234 if ( values == null )
1236 values = new HashMap<String, String>();
1238 values.put( model.getKey(), model.getValue() );
1239 facetValuesPerFacet.put( model.getName(), values );
1242 for ( Map.Entry<String, Map<String, String>> entry : facetValuesPerFacet.entrySet() )
1244 MetadataFacetFactory factory = metadataFacetFactories.get( entry.getKey() );
1245 if ( factory == null )
1249 MetadataFacet metadataFacet =
1250 factory.createMetadataFacet( artifactMetadata.getRepositoryId(), entry.getKey() );
1251 metadataFacet.fromProperties( entry.getValue() );
1252 artifactMetadata.addFacet( metadataFacet );
1257 public List<ArtifactMetadata> getArtifactsByChecksum( final String repositoryId, final String checksum )
1258 throws MetadataRepositoryException
1260 /* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1262 if ( logger.isDebugEnabled() )
1264 logger.debug( "all ArtifactMetadataModel: {}", getArtifactMetadataModelEntityManager().getAll() );
1268 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1271 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1273 if ( artifactMetadataModel != null )
1275 if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId )
1276 && artifactMetadataModel.getNamespace() != null &&
1277 artifactMetadataModel.getProject() != null && artifactMetadataModel.getId() != null )
1280 if ( StringUtils.equals( checksum, artifactMetadataModel.getMd5() ) || StringUtils.equals(
1281 checksum, artifactMetadataModel.getSha1() ) )
1283 artifactMetadataModels.add( artifactMetadataModel );
1287 return Boolean.TRUE;
1290 List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
1292 for ( ArtifactMetadataModel model : artifactMetadataModels )
1294 ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
1295 populateFacets( artifactMetadata );
1296 artifactMetadatas.add( artifactMetadata );
1299 logger.debug( "getArtifactsByChecksum repositoryId: {}, checksum: {}, artifactMetadatas: {}", repositoryId,
1300 checksum, artifactMetadatas );
1302 return artifactMetadatas;*/
1303 return Collections.emptyList();
1307 public void removeArtifact( final String repositoryId, final String namespace, final String project,
1308 final String version, final String id )
1309 throws MetadataRepositoryException
1311 /* logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
1312 repositoryId, namespace, project, version, id );
1314 new ArtifactMetadataModel.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespace ).withId(
1315 id ).withProjectVersion( version ).withProject( project ).build();
1317 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
1318 artifactMetadataModel.setArtifactMetadataModelId( key );
1320 getArtifactMetadataModelEntityManager().remove( artifactMetadataModel );
1323 new ProjectVersionMetadataModel.KeyBuilder().withId( version ).withRepository( repositoryId ).withNamespace(
1324 namespace ).withProjectId( project ).build();
1326 ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
1327 projectVersionMetadataModel.setRowId( key );
1329 getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );*/
1333 public void removeArtifact( ArtifactMetadata artifactMetadata, String baseVersion )
1334 throws MetadataRepositoryException
1336 logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
1337 artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(),
1338 artifactMetadata.getProject(), baseVersion, artifactMetadata.getId() );
1340 new ArtifactMetadataModel.KeyBuilder().withRepositoryId( artifactMetadata.getRepositoryId() ).withNamespace(
1341 artifactMetadata.getNamespace() ).withId( artifactMetadata.getId() ).withProjectVersion(
1342 baseVersion ).withProject( artifactMetadata.getProject() ).build();
1344 ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
1345 artifactMetadataModel.setArtifactMetadataModelId( key );
1347 getArtifactMetadataModelEntityManager().remove( artifactMetadataModel );*/
1351 public void removeArtifact( final String repositoryId, final String namespace, final String project,
1352 final String version, final MetadataFacet metadataFacet )
1353 throws MetadataRepositoryException
1355 /* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1356 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1359 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1361 if ( artifactMetadataModel != null )
1363 if ( StringUtils.equals( repositoryId, artifactMetadataModel.getRepositoryId() )
1364 && StringUtils.equals( namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals(
1365 project, artifactMetadataModel.getProject() ) && StringUtils.equals( project,
1366 artifactMetadataModel.getVersion() ) )
1368 artifactMetadataModels.add( artifactMetadataModel );
1371 return Boolean.TRUE;
1374 getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );*/
1380 public List<ArtifactMetadata> getArtifacts( final String repositoryId )
1381 throws MetadataRepositoryException
1383 /* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1384 // FIXME use cql query !
1385 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1388 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1390 if ( artifactMetadataModel != null )
1392 if ( StringUtils.equals( repositoryId, artifactMetadataModel.getRepositoryId() ) )
1394 artifactMetadataModels.add( artifactMetadataModel );
1398 return Boolean.TRUE;
1402 List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
1404 for ( ArtifactMetadataModel model : artifactMetadataModels )
1406 ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
1407 populateFacets( artifactMetadata );
1408 artifactMetadatas.add( artifactMetadata );
1411 return artifactMetadatas;*/
1412 return Collections.emptyList();
1416 public ProjectMetadata getProject( final String repoId, final String namespace, final String id )
1417 throws MetadataResolutionException
1420 /* //basically just checking it exists
1421 // FIXME use cql query
1423 final BooleanHolder booleanHolder = new BooleanHolder();
1425 getProjectEntityManager().visitAll( new Function<Project, Boolean>()
1428 public Boolean apply( Project project )
1430 if ( project != null )
1432 if ( StringUtils.equals( repoId, project.getNamespace().getRepository().getName() )
1433 && StringUtils.equals( namespace, project.getNamespace().getName() ) && StringUtils.equals( id,
1434 project.getProjectId() ) )
1436 booleanHolder.value = true;
1439 return Boolean.TRUE;
1443 if ( !booleanHolder.value )
1448 ProjectMetadata projectMetadata = new ProjectMetadata();
1449 projectMetadata.setId( id );
1450 projectMetadata.setNamespace( namespace );
1452 logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id,
1455 return projectMetadata;*/
1460 public ProjectVersionMetadata getProjectVersion( final String repoId, final String namespace,
1461 final String projectId, final String projectVersion )
1462 throws MetadataResolutionException
1464 /* String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace(
1465 namespace ).withProjectId( projectId ).withId( projectVersion ).build();
1467 ProjectVersionMetadataModel projectVersionMetadataModel =
1468 getProjectVersionMetadataModelEntityManager().get( key );
1470 if ( projectVersionMetadataModel == null )
1473 "getProjectVersion repoId: '{}', namespace: '{}', projectId: '{}', projectVersion: {} -> not found",
1474 repoId, namespace, projectId, projectVersion );
1478 ProjectVersionMetadata projectVersionMetadata =
1479 getModelMapper().map( projectVersionMetadataModel, ProjectVersionMetadata.class );
1481 logger.debug( "getProjectVersion repoId: '{}', namespace: '{}', projectId: '{}', projectVersion: {} -> {}",
1482 repoId, namespace, projectId, projectVersion, projectVersionMetadata );
1484 projectVersionMetadata.setCiManagement( projectVersionMetadataModel.getCiManagement() );
1485 projectVersionMetadata.setIssueManagement( projectVersionMetadataModel.getIssueManagement() );
1486 projectVersionMetadata.setOrganization( projectVersionMetadataModel.getOrganization() );
1487 projectVersionMetadata.setScm( projectVersionMetadataModel.getScm() );
1489 // FIXME complete collections !!
1492 final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
1493 // FIXME use cql query
1494 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1497 public Boolean apply( MetadataFacetModel metadataFacetModel )
1499 if ( metadataFacetModel != null )
1501 if ( StringUtils.equals( repoId, metadataFacetModel.getArtifactMetadataModel().getRepositoryId() )
1502 && StringUtils.equals( namespace, metadataFacetModel.getArtifactMetadataModel().getNamespace() )
1503 && StringUtils.equals( projectId, metadataFacetModel.getArtifactMetadataModel().getProject() )
1504 && StringUtils.equals( projectVersion,
1505 metadataFacetModel.getArtifactMetadataModel().getProjectVersion() ) )
1507 metadataFacetModels.add( metadataFacetModel );
1510 return Boolean.TRUE;
1513 Map<String, Map<String, String>> metadataFacetsPerFacetIds = new HashMap<String, Map<String, String>>();
1514 for ( MetadataFacetModel metadataFacetModel : metadataFacetModels )
1517 Map<String, String> metaValues = metadataFacetsPerFacetIds.get( metadataFacetModel.getFacetId() );
1518 if ( metaValues == null )
1520 metaValues = new HashMap<String, String>();
1521 metadataFacetsPerFacetIds.put( metadataFacetModel.getFacetId(), metaValues );
1523 metaValues.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
1527 if ( !metadataFacetsPerFacetIds.isEmpty() )
1529 for ( Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet() )
1531 MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get( entry.getKey() );
1532 if ( metadataFacetFactory != null )
1534 MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet( repoId, entry.getKey() );
1535 metadataFacet.fromProperties( entry.getValue() );
1536 projectVersionMetadata.addFacet( metadataFacet );
1541 return projectVersionMetadata;*/
1547 public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
1548 String projectVersion )
1549 throws MetadataResolutionException
1551 // FIXME implement this
1552 return Collections.emptyList();
1556 public void removeProjectVersion( final String repoId, final String namespace, final String projectId,
1557 final String projectVersion )
1558 throws MetadataRepositoryException
1561 final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1563 // FIXME use cql query
1565 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1568 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1570 if ( artifactMetadataModel != null )
1572 if ( StringUtils.equals( repoId, artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1573 namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals( projectId,
1574 artifactMetadataModel.getProject() )
1575 && StringUtils.equals( projectVersion, artifactMetadataModel.getProjectVersion() ) )
1577 artifactMetadataModels.add( artifactMetadataModel );
1580 return Boolean.TRUE;
1584 logger.debug( "removeProjectVersions:{}", artifactMetadataModels );
1585 if ( artifactMetadataModels.isEmpty() )
1590 getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
1592 String key = new ProjectVersionMetadataModel.KeyBuilder().withProjectId( projectId ).withId(
1593 projectVersion ).withRepository( repoId ).withNamespace( namespace ).build();
1595 ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
1596 projectVersionMetadataModel.setRowId( key );
1598 getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );
1603 public Collection<ArtifactMetadata> getArtifacts( final String repoId, final String namespace,
1604 final String projectId, final String projectVersion )
1605 throws MetadataResolutionException
1607 final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
1609 // FIXME use cql query !
1610 getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
1613 public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
1615 if ( artifactMetadataModel != null )
1617 if ( StringUtils.equals( repoId, artifactMetadataModel.getRepositoryId() ) && StringUtils.equals(
1618 namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals( projectId,
1619 artifactMetadataModel.getProject() )
1620 && StringUtils.equals( projectVersion, artifactMetadataModel.getProjectVersion() ) )
1622 artifactMetadataModels.add( artifactMetadataModel );
1626 return Boolean.TRUE;
1630 List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
1632 for ( ArtifactMetadataModel model : artifactMetadataModels )
1634 ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
1635 populateFacets( artifactMetadata );
1636 artifactMetadatas.add( artifactMetadata );
1640 final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
1641 getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
1644 public Boolean apply( MetadataFacetModel metadataFacetModel )
1646 if ( metadataFacetModel != null )
1648 if ( StringUtils.equals( repoId, metadataFacetModel.getArtifactMetadataModel().getRepositoryId() )
1649 && StringUtils.equals( namespace, metadataFacetModel.getArtifactMetadataModel().getNamespace() )
1650 && StringUtils.equals( projectId, metadataFacetModel.getArtifactMetadataModel().getProject() )
1651 && StringUtils.equals( projectVersion,
1652 metadataFacetModel.getArtifactMetadataModel().getProjectVersion() ) )
1654 metadataFacetModels.add( metadataFacetModel );
1658 return Boolean.TRUE;
1662 // rebuild MetadataFacet for artifacts
1664 for ( final ArtifactMetadata artifactMetadata : artifactMetadatas )
1666 Iterable<MetadataFacetModel> metadataFacetModelIterable =
1667 Iterables.filter( metadataFacetModels, new Predicate<MetadataFacetModel>()
1670 public boolean apply( MetadataFacetModel metadataFacetModel )
1672 if ( metadataFacetModel != null )
1674 return StringUtils.equals( artifactMetadata.getVersion(),
1675 metadataFacetModel.getArtifactMetadataModel().getVersion() );
1680 Iterator<MetadataFacetModel> iterator = metadataFacetModelIterable.iterator();
1681 Map<String, List<MetadataFacetModel>> metadataFacetValuesPerFacetId =
1682 new HashMap<String, List<MetadataFacetModel>>();
1683 while ( iterator.hasNext() )
1685 MetadataFacetModel metadataFacetModel = iterator.next();
1686 List<MetadataFacetModel> values = metadataFacetValuesPerFacetId.get( metadataFacetModel.getName() );
1687 if ( values == null )
1689 values = new ArrayList<MetadataFacetModel>();
1690 metadataFacetValuesPerFacetId.put( metadataFacetModel.getFacetId(), values );
1692 values.add( metadataFacetModel );
1696 for ( Map.Entry<String, List<MetadataFacetModel>> entry : metadataFacetValuesPerFacetId.entrySet() )
1698 MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get( entry.getKey() );
1699 if ( metadataFacetFactory != null )
1701 List<MetadataFacetModel> facetModels = entry.getValue();
1702 if ( !facetModels.isEmpty() )
1704 MetadataFacet metadataFacet =
1705 metadataFacetFactory.createMetadataFacet( repoId, facetModels.get( 0 ).getName() );
1706 Map<String, String> props = new HashMap<String, String>( facetModels.size() );
1707 for ( MetadataFacetModel metadataFacetModel : facetModels )
1709 props.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
1711 metadataFacet.fromProperties( props );
1712 artifactMetadata.addFacet( metadataFacet );
1720 return artifactMetadatas;
1726 logger.trace( "save" );
1731 throws MetadataRepositoryException
1733 logger.trace( "close" );
1737 public void revert()
1739 logger.warn( "CassandraMetadataRepository cannot revert" );
1743 public boolean canObtainAccess( Class<?> aClass )
1749 public <T> T obtainAccess( Class<T> aClass )
1750 throws MetadataRepositoryException
1752 throw new IllegalArgumentException(
1753 "Access using " + aClass + " is not supported on the cassandra metadata storage" );
1757 private static class ModelMapperHolder
1759 private static ModelMapper MODEL_MAPPER = new ModelMapper();
1762 protected ModelMapper getModelMapper()
1764 return ModelMapperHolder.MODEL_MAPPER;