001package org.apache.archiva.metadata.repository.cassandra; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.archiva.configuration.ArchivaConfiguration; 023import org.apache.archiva.metadata.model.MetadataFacetFactory; 024import org.apache.archiva.metadata.repository.MetadataResolver; 025import org.apache.archiva.metadata.repository.RepositorySession; 026import org.apache.archiva.metadata.repository.RepositorySessionFactory; 027import org.apache.commons.lang.StringUtils; 028import org.springframework.context.ApplicationContext; 029import org.springframework.stereotype.Service; 030 031import javax.annotation.PostConstruct; 032import javax.inject.Inject; 033import javax.inject.Named; 034import java.util.HashMap; 035import java.util.Map; 036 037/** 038 * @author Olivier Lamy 039 * @since 2.0.0 040 */ 041@Service("repositorySessionFactory#cassandra") 042public class CassandraRepositorySessionFactory 043 implements RepositorySessionFactory 044{ 045 046 private Map<String, MetadataFacetFactory> metadataFacetFactories; 047 048 @Inject 049 @Named(value = "archivaConfiguration#default") 050 private ArchivaConfiguration configuration; 051 052 @Inject 053 private MetadataResolver metadataResolver; 054 055 @Inject 056 private ApplicationContext applicationContext; 057 058 @Inject 059 private CassandraArchivaManager cassandraArchivaManager; 060 061 @PostConstruct 062 public void initialize() 063 { 064 Map<String, MetadataFacetFactory> tmpMetadataFacetFactories = 065 applicationContext.getBeansOfType( MetadataFacetFactory.class ); 066 // olamy with spring the ID.toString() is now "metadataFacetFactory#hint" 067 // whereas was only hint with plexus so let remove metadataFacetFactory# 068 metadataFacetFactories = new HashMap<>( tmpMetadataFacetFactories.size() ); 069 070 for ( Map.Entry<String, MetadataFacetFactory> entry : tmpMetadataFacetFactories.entrySet() ) 071 { 072 metadataFacetFactories.put( StringUtils.substringAfterLast( entry.getKey(), "#" ), entry.getValue() ); 073 } 074 } 075 076 077 @Override 078 public RepositorySession createSession() 079 { 080 CassandraMetadataRepository metadataRepository = 081 new CassandraMetadataRepository( metadataFacetFactories, configuration, cassandraArchivaManager ); 082 return new RepositorySession( metadataRepository, metadataResolver ); 083 } 084 085}