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 org.apache.archiva.configuration.ArchivaConfiguration;
23 import org.apache.archiva.metadata.model.MetadataFacetFactory;
24 import org.apache.archiva.metadata.repository.MetadataResolver;
25 import org.apache.archiva.metadata.repository.RepositorySession;
26 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
27 import org.apache.commons.lang.StringUtils;
28 import org.springframework.context.ApplicationContext;
29 import org.springframework.stereotype.Service;
31 import javax.annotation.PostConstruct;
32 import javax.inject.Inject;
33 import javax.inject.Named;
34 import java.util.HashMap;
38 * @author Olivier Lamy
41 @Service("repositorySessionFactory#cassandra")
42 public class CassandraRepositorySessionFactory
43 implements RepositorySessionFactory
46 private Map<String, MetadataFacetFactory> metadataFacetFactories;
49 @Named(value = "archivaConfiguration#default")
50 private ArchivaConfiguration configuration;
53 private MetadataResolver metadataResolver;
56 private ApplicationContext applicationContext;
59 private CassandraArchivaManager cassandraArchivaManager;
62 public void initialize()
64 Map<String, MetadataFacetFactory> tmpMetadataFacetFactories =
65 applicationContext.getBeansOfType( MetadataFacetFactory.class );
66 // olamy with spring the ID.toString() is now "metadataFacetFactory#hint"
67 // whereas was only hint with plexus so let remove metadataFacetFactory#
68 metadataFacetFactories = new HashMap<>( tmpMetadataFacetFactories.size() );
70 for ( Map.Entry<String, MetadataFacetFactory> entry : tmpMetadataFacetFactories.entrySet() )
72 metadataFacetFactories.put( StringUtils.substringAfterLast( entry.getKey(), "#" ), entry.getValue() );
78 public RepositorySession createSession()
80 CassandraMetadataRepository metadataRepository =
81 new CassandraMetadataRepository( metadataFacetFactories, configuration, cassandraArchivaManager );
82 return new RepositorySession( metadataRepository, metadataResolver );