This project has retired. For details please refer to its Attic page.
CassandraRepositorySessionFactory xref
View Javadoc
1   package org.apache.archiva.metadata.repository.cassandra;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
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;
30  
31  import javax.annotation.PostConstruct;
32  import javax.inject.Inject;
33  import javax.inject.Named;
34  import java.util.HashMap;
35  import java.util.Map;
36  
37  /**
38   * @author Olivier Lamy
39   * @since 2.0.0
40   */
41  @Service("repositorySessionFactory#cassandra")
42  public class CassandraRepositorySessionFactory
43      implements RepositorySessionFactory
44  {
45  
46      private Map<String, MetadataFacetFactory> metadataFacetFactories;
47  
48      @Inject
49      @Named(value = "archivaConfiguration#default")
50      private ArchivaConfiguration configuration;
51  
52      @Inject
53      private MetadataResolver metadataResolver;
54  
55      @Inject
56      private ApplicationContext applicationContext;
57  
58      @Inject
59      private CassandraArchivaManager cassandraArchivaManager;
60  
61      @PostConstruct
62      public void 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() );
69  
70          for ( Map.Entry<String, MetadataFacetFactory> entry : tmpMetadataFacetFactories.entrySet() )
71          {
72              metadataFacetFactories.put( StringUtils.substringAfterLast( entry.getKey(), "#" ), entry.getValue() );
73          }
74      }
75  
76  
77      @Override
78      public RepositorySession createSession()
79      {
80          CassandraMetadataRepository metadataRepository =
81              new CassandraMetadataRepository( metadataFacetFactories, configuration, cassandraArchivaManager );
82          return new RepositorySession( metadataRepository, metadataResolver );
83      }
84  
85  }