1package org.apache.archiva.metadata.repository.cassandra;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import org.apache.archiva.configuration.ArchivaConfiguration;
23import org.apache.archiva.metadata.model.MetadataFacetFactory;
24import org.apache.archiva.metadata.repository.MetadataResolver;
25import org.apache.archiva.metadata.repository.RepositorySession;
26import org.apache.archiva.metadata.repository.RepositorySessionFactory;
27import org.apache.commons.lang.StringUtils;
28import org.springframework.context.ApplicationContext;
29import org.springframework.stereotype.Service;
3031import javax.annotation.PostConstruct;
32import javax.inject.Inject;
33import javax.inject.Named;
34import java.util.HashMap;
35import java.util.Map;
3637/**38 * @author Olivier Lamy39 * @since 2.0.040 */41 @Service("repositorySessionFactory#cassandra")
42publicclassCassandraRepositorySessionFactory43implementsRepositorySessionFactory44 {
4546private Map<String, MetadataFacetFactory> metadataFacetFactories;
4748 @Inject
49 @Named(value = "archivaConfiguration#default")
50privateArchivaConfiguration configuration;
5152 @Inject
53privateMetadataResolver metadataResolver;
5455 @Inject
56private ApplicationContext applicationContext;
5758 @Inject
59privateCassandraArchivaManager cassandraArchivaManager;
6061 @PostConstruct
62publicvoid initialize()
63 {
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() );
6970for ( Map.Entry<String, MetadataFacetFactory> entry : tmpMetadataFacetFactories.entrySet() )
71 {
72 metadataFacetFactories.put( StringUtils.substringAfterLast( entry.getKey(), "#" ), entry.getValue() );
73 }
74 }
757677 @Override
78publicRepositorySession createSession()
79 {
80CassandraMetadataRepository metadataRepository =
81newCassandraMetadataRepository( metadataFacetFactories, configuration, cassandraArchivaManager );
82returnnewRepositorySession( metadataRepository, metadataResolver );
83 }
8485 }