EMMA Coverage Report (generated Sun Sep 18 11:34:27 PHT 2011)
[all classes][org.apache.maven.continuum.web.view]

COVERAGE SUMMARY FOR SOURCE FILE [StateCell.java]

nameclass, %method, %block, %line, %
StateCell.java0%   (0/1)0%   (0/5)0%   (0/234)0%   (0/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StateCell0%   (0/1)0%   (0/5)0%   (0/234)0%   (0/44)
StateCell (): void 0%   (0/1)0%   (0/3)0%   (0/1)
createActionLink (String, ProjectScmRoot, String): String 0%   (0/1)0%   (0/49)0%   (0/5)
createActionLink (String, ProjectSummary, String): String 0%   (0/1)0%   (0/61)0%   (0/7)
getCellValue (TableModel, Column): String 0%   (0/1)0%   (0/85)0%   (0/19)
isAuthorized (String): boolean 0%   (0/1)0%   (0/36)0%   (0/12)

1package org.apache.maven.continuum.web.view;
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 
22import com.opensymphony.xwork2.ActionContext;
23 
24import java.util.HashMap;
25 
26import org.apache.continuum.model.project.ProjectScmRoot;
27import org.apache.maven.continuum.project.ContinuumProjectState;
28import org.apache.maven.continuum.security.ContinuumRoleConstants;
29import org.apache.maven.continuum.web.model.ProjectSummary;
30import org.apache.maven.continuum.web.util.StateGenerator;
31import org.apache.struts2.ServletActionContext;
32import org.apache.struts2.views.util.UrlHelper;
33import org.codehaus.plexus.PlexusConstants;
34import org.codehaus.plexus.PlexusContainer;
35import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
36import org.codehaus.plexus.redback.authorization.AuthorizationException;
37import org.codehaus.plexus.redback.system.SecuritySession;
38import org.codehaus.plexus.redback.system.SecuritySystem;
39import org.codehaus.plexus.redback.system.SecuritySystemConstants;
40import org.extremecomponents.table.bean.Column;
41import org.extremecomponents.table.cell.DisplayCell;
42import org.extremecomponents.table.core.TableModel;
43 
44/**
45 * Used in Summary view
46 *
47 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
48 * @version $Id: StateCell.java 765340 2009-04-15 20:22:00Z evenisse $
49 * @deprecated use of cells is discouraged due to lack of i18n and design in java code.
50 *             Use jsp:include instead.
51 */
52public class StateCell
53    extends DisplayCell
54{
55    protected String getCellValue( TableModel tableModel, Column column )
56    {
57        if ( tableModel.getCurrentRowBean() instanceof ProjectSummary )
58        {
59            ProjectSummary project = (ProjectSummary) tableModel.getCurrentRowBean();
60 
61            switch ( project.getState() )
62            {
63                case ContinuumProjectState.NEW:
64                case ContinuumProjectState.OK:
65                case ContinuumProjectState.FAILED:
66                case ContinuumProjectState.ERROR:
67                case ContinuumProjectState.BUILDING:
68                case ContinuumProjectState.UPDATING:
69                case ContinuumProjectState.CHECKING_OUT:
70                {
71                    String state =
72                        StateGenerator.generate( project.getState(), tableModel.getContext().getContextPath() );
73 
74                    if ( project.getLatestBuildId() != -1 && !StateGenerator.NEW.equals( state ) &&
75                        project.getState() != ContinuumProjectState.UPDATING )
76                    {
77                        if ( isAuthorized( project.getProjectGroupName() ) )
78                        {
79                            return createActionLink( "buildResult", project, state );
80                        }
81                        else
82                        {
83                            return state;
84                        }
85                    }
86                    else
87                    {
88                        return state;
89                    }
90                }
91 
92                default:
93                {
94                    return "&nbsp;";
95                }
96            }
97        }
98        else
99        {
100            ProjectScmRoot projectScmRoot = (ProjectScmRoot) tableModel.getCurrentRowBean();
101 
102            switch ( projectScmRoot.getState() )
103            {
104                case ContinuumProjectState.UPDATING:
105                case ContinuumProjectState.UPDATED:
106                case ContinuumProjectState.ERROR:
107                {
108                    String state =
109                        StateGenerator.generate( projectScmRoot.getState(), tableModel.getContext().getContextPath() );
110 
111                    if ( !StateGenerator.NEW.equals( state ) )
112                    {
113                        if ( isAuthorized( projectScmRoot.getProjectGroup().getName() ) &&
114                            projectScmRoot.getState() == ContinuumProjectState.ERROR )
115                        {
116                            return createActionLink( "scmResult", projectScmRoot, state );
117                        }
118                        else
119                        {
120                            return state;
121                        }
122                    }
123                    else
124                    {
125                        return state;
126                    }
127                }
128 
129                default:
130                {
131                    return "&nbsp;";
132                }
133            }
134        }
135    }
136 
137    private static String createActionLink( String action, ProjectSummary project, String state )
138    {
139        HashMap<String, Object> params = new HashMap<String, Object>();
140 
141        params.put( "projectId", project.getId() );
142 
143        params.put( "projectName", project.getName() );
144 
145        params.put( "buildId", project.getLatestBuildId() );
146 
147        params.put( "projectGroupId", project.getProjectGroupId() );
148 
149        String url = UrlHelper.buildUrl( "/" + action + ".action", ServletActionContext.getRequest(),
150                                         ServletActionContext.getResponse(), params );
151 
152        return "<a href=\"" + url + "\">" + state + "</a>";
153    }
154 
155    private static String createActionLink( String action, ProjectScmRoot scmRoot, String state )
156    {
157        HashMap<String, Object> params = new HashMap<String, Object>();
158 
159        params.put( "projectGroupId", scmRoot.getProjectGroup().getId() );
160 
161        params.put( "projectScmRootId", scmRoot.getId() );
162 
163        String url = UrlHelper.buildUrl( "/" + action + ".action", ServletActionContext.getRequest(),
164                                         ServletActionContext.getResponse(), params );
165 
166        return "<a href=\"" + url + "\">" + state + "</a>";
167    }
168 
169    private boolean isAuthorized( String projectGroupName )
170    {
171        // do the authz bit
172        ActionContext context = ActionContext.getContext();
173 
174        PlexusContainer container = (PlexusContainer) context.getApplication().get( PlexusConstants.PLEXUS_KEY );
175        SecuritySession securitySession =
176            (SecuritySession) context.getSession().get( SecuritySystemConstants.SECURITY_SESSION_KEY );
177 
178        try
179        {
180            SecuritySystem securitySystem = (SecuritySystem) container.lookup( SecuritySystem.ROLE );
181 
182            if ( !securitySystem.isAuthorized( securitySession, ContinuumRoleConstants.CONTINUUM_VIEW_GROUP_OPERATION,
183                                               projectGroupName ) )
184            {
185                return false;
186            }
187        }
188        catch ( ComponentLookupException cle )
189        {
190            return false;
191        }
192        catch ( AuthorizationException ae )
193        {
194            return false;
195        }
196 
197        return true;
198    }
199}

[all classes][org.apache.maven.continuum.web.view]
EMMA 2.0.5312 (C) Vladimir Roubtsov