1 package org.apache.maven.continuum.web.view;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.opensymphony.xwork2.ActionContext;
23
24 import java.util.HashMap;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.servlet.jsp.PageContext;
29
30 import org.apache.maven.continuum.security.ContinuumRoleConstants;
31 import org.apache.maven.continuum.web.model.ProjectSummary;
32 import org.apache.struts2.views.util.UrlHelper;
33 import org.codehaus.plexus.PlexusConstants;
34 import org.codehaus.plexus.PlexusContainer;
35 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
36 import org.codehaus.plexus.redback.authorization.AuthorizationException;
37 import org.codehaus.plexus.redback.system.SecuritySession;
38 import org.codehaus.plexus.redback.system.SecuritySystem;
39 import org.codehaus.plexus.redback.system.SecuritySystemConstants;
40 import org.extremecomponents.table.bean.Column;
41 import org.extremecomponents.table.cell.DisplayCell;
42 import org.extremecomponents.table.core.TableModel;
43
44
45
46
47
48
49
50
51
52 public class BuildCell
53 extends DisplayCell
54 {
55 protected String getCellValue( TableModel tableModel, Column column )
56 {
57 ProjectSummary project = (ProjectSummary) tableModel.getCurrentRowBean();
58 String contextPath = tableModel.getContext().getContextPath();
59
60 int buildNumber = project.getBuildNumber();
61
62 String result = "<div align=\"center\">";
63
64 if ( project.isInBuildingQueue() )
65 {
66 result +=
67 "<img src=\"" + contextPath + "/images/inqueue.gif\" alt=\"In Queue\" title=\"In Queue\" border=\"0\">";
68 }
69 else if ( project.isInCheckoutQueue() )
70 {
71 result += "<img src=\"" + contextPath +
72 "/images/checkingout.gif\" alt=\"Checking Out sources\" title=\"Checking Out sources\" border=\"0\">";
73 }
74 else
75 {
76 if ( project.getState() == 1 || project.getState() == 10 || project.getState() == 2 ||
77 project.getState() == 3 || project.getState() == 4 )
78 {
79 if ( buildNumber > 0 )
80 {
81 HashMap<String, Object> params = new HashMap<String, Object>();
82
83 params.put( "projectId", project.getId() );
84
85 params.put( "projectName", project.getName() );
86
87 params.put( "buildId", project.getBuildInSuccessId() );
88
89 params.put( "projectGroupId", project.getProjectGroupId() );
90
91 PageContext pageContext = (PageContext) tableModel.getContext().getContextObject();
92
93 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
94
95 HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
96
97 String url = UrlHelper.buildUrl( "/buildResult.action", request, response, params );
98
99 if ( isAuthorized( project ) )
100 {
101
102 result += "<a href=\"" + url + "\">" + buildNumber + "</a>";
103 }
104 else
105 {
106 result += buildNumber;
107 }
108 }
109 else
110 {
111 result += " ";
112 }
113 }
114 else if ( project.getState() == 6 )
115 {
116 result += "<img src=\"" + contextPath +
117 "/images/building.gif\" alt=\"Building\" title=\"Building\" border=\"0\">";
118 }
119 else if ( project.getState() == 7 )
120 {
121 result += "<img src=\"" + contextPath +
122 "/images/checkingout.gif\" alt=\"Checking Out sources\" title=\"Checking Out sources\" border=\"0\">";
123 }
124 else if ( project.getState() == 8 )
125 {
126 result += "<img src=\"" + contextPath +
127 "/images/checkingout.gif\" alt=\"Updating sources\" title=\"Updating sources\" border=\"0\">";
128 }
129 else
130 {
131 result += "<img src=\"" + contextPath +
132 "/images/inqueue.gif\" alt=\"In Queue\" title=\"In Queue\" border=\"0\">";
133 }
134 }
135
136 return result + "</div>";
137 }
138
139 private boolean isAuthorized( ProjectSummary project )
140 {
141
142 ActionContext context = ActionContext.getContext();
143
144 PlexusContainer container = (PlexusContainer) context.getApplication().get( PlexusConstants.PLEXUS_KEY );
145 SecuritySession securitySession =
146 (SecuritySession) context.getSession().get( SecuritySystemConstants.SECURITY_SESSION_KEY );
147
148 try
149 {
150 SecuritySystem securitySystem = (SecuritySystem) container.lookup( SecuritySystem.ROLE );
151
152 if ( !securitySystem.isAuthorized( securitySession, ContinuumRoleConstants.CONTINUUM_VIEW_GROUP_OPERATION,
153 project.getProjectGroupName() ) )
154 {
155 return false;
156 }
157 }
158 catch ( ComponentLookupException cle )
159 {
160 return false;
161 }
162 catch ( AuthorizationException ae )
163 {
164 return false;
165 }
166
167 return true;
168 }
169 }