1 | package org.apache.maven.continuum.web.action; |
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 java.util.ArrayList; |
23 | import java.util.Collection; |
24 | import java.util.List; |
25 | import java.util.Map; |
26 | |
27 | import org.apache.continuum.model.project.ProjectGroupSummary; |
28 | import org.apache.maven.continuum.ContinuumException; |
29 | import org.apache.maven.continuum.model.project.ProjectGroup; |
30 | import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; |
31 | import org.apache.maven.continuum.web.model.GroupSummary; |
32 | import org.slf4j.Logger; |
33 | import org.slf4j.LoggerFactory; |
34 | |
35 | /** |
36 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
37 | * @version $Id: GroupSummaryAction.java 787653 2009-06-23 12:07:35Z evenisse $ |
38 | * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="groupSummary" |
39 | */ |
40 | public class GroupSummaryAction |
41 | extends ContinuumActionSupport |
42 | { |
43 | private static final Logger logger = LoggerFactory.getLogger( GroupSummaryAction.class ); |
44 | |
45 | private String infoMessage; |
46 | |
47 | private List<GroupSummary> groups; |
48 | |
49 | public String execute() |
50 | throws ContinuumException |
51 | { |
52 | groups = new ArrayList<GroupSummary>(); |
53 | |
54 | //TODO: Merge this two requests to one |
55 | Collection<ProjectGroup> projectGroups = getContinuum().getAllProjectGroups(); |
56 | Map<Integer, ProjectGroupSummary> summaries = getContinuum().getProjectsSummaryByGroups(); |
57 | |
58 | for ( ProjectGroup projectGroup : projectGroups ) |
59 | { |
60 | |
61 | if ( isAuthorized( projectGroup.getName() ) ) |
62 | { |
63 | if ( logger.isDebugEnabled() ) |
64 | { |
65 | logger.debug( "GroupSummaryAction: building group " + projectGroup.getName() ); |
66 | } |
67 | |
68 | GroupSummary groupModel = new GroupSummary(); |
69 | groupModel.setId( projectGroup.getId() ); |
70 | groupModel.setGroupId( projectGroup.getGroupId() ); |
71 | groupModel.setName( projectGroup.getName() ); |
72 | groupModel.setDescription( projectGroup.getDescription() ); |
73 | |
74 | ProjectGroupSummary summary = summaries.get( projectGroup.getId() ); |
75 | |
76 | if ( summary != null ) |
77 | { |
78 | groupModel.setNumProjects( summary.getNumberOfProjects() ); |
79 | groupModel.setNumErrors( summary.getNumberOfErrors() ); |
80 | groupModel.setNumFailures( summary.getNumberOfFailures() ); |
81 | groupModel.setNumSuccesses( summary.getNumberOfSuccesses() ); |
82 | } |
83 | |
84 | //todo wire in the next scheduled build for the project group and a meaningful status message |
85 | //groupModel.setNextScheduledBuild( "unknown" ); |
86 | //groupModel.setStatusMessage( "none" ); |
87 | if ( logger.isDebugEnabled() ) |
88 | { |
89 | logger.debug( "GroupSummaryAction: adding group to groups list " + groupModel.getName() ); |
90 | } |
91 | groups.add( groupModel ); |
92 | } |
93 | } |
94 | |
95 | return SUCCESS; |
96 | } |
97 | |
98 | public List<GroupSummary> getGroups() |
99 | { |
100 | return groups; |
101 | } |
102 | |
103 | |
104 | public String getInfoMessage() |
105 | { |
106 | return infoMessage; |
107 | } |
108 | |
109 | public void setInfoMessage( String infoMessage ) |
110 | { |
111 | this.infoMessage = infoMessage; |
112 | } |
113 | |
114 | private boolean isAuthorized( String projectGroupName ) |
115 | { |
116 | try |
117 | { |
118 | checkViewProjectGroupAuthorization( projectGroupName ); |
119 | return true; |
120 | } |
121 | catch ( AuthorizationRequiredException authzE ) |
122 | { |
123 | return false; |
124 | } |
125 | } |
126 | } |