1 package org.apache.archiva.redback.integration.reports;
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.commons.lang.StringUtils;
23 import org.springframework.context.ApplicationContext;
24 import org.springframework.stereotype.Service;
26 import javax.annotation.PostConstruct;
27 import javax.inject.Inject;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.List;
36 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
39 @Service( "reportManager" )
40 public class ReportManager
44 private List<Report> availableReports;
47 private ApplicationContext applicationContext;
49 private Map<String, Map<String, Report>> reportMap;
51 public Report findReport( String id, String type )
52 throws ReportException
54 if ( StringUtils.isBlank( id ) )
56 throw new ReportException( "Unable to generate report from empty report id." );
59 if ( StringUtils.isBlank( type ) )
61 throw new ReportException( "Unable to generate report from empty report type." );
64 Map<String, Report> typeMap = reportMap.get( id );
65 if ( typeMap == null )
67 throw new ReportException( "Unable to find report id [" + id + "]" );
70 Report requestedReport = typeMap.get( type );
72 if ( requestedReport == null )
74 throw new ReportException( "Unable to find report id [" + id + "] type [" + type + "]" );
77 return requestedReport;
80 public Map<String, Map<String, Report>> getReportMap()
82 return Collections.unmodifiableMap( reportMap );
85 @SuppressWarnings( "unchecked" )
87 public void initialize()
89 reportMap = new HashMap<String, Map<String, Report>>();
91 for ( Report report : availableReports )
93 Map<String, Report> typeMap = reportMap.get( report.getId() );
94 if ( typeMap == null )
96 typeMap = new HashMap<String, Report>();
99 typeMap.put( report.getType(), report );
100 reportMap.put( report.getId(), typeMap );