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