1 package org.apache.maven.archiva.web.action.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 com.opensymphony.webwork.interceptor.ServletRequestAware;
23 import org.apache.maven.archiva.database.ArchivaDAO;
24 import org.apache.maven.archiva.database.Constraint;
25 import org.apache.maven.archiva.database.constraints.RangeConstraint;
26 import org.apache.maven.archiva.database.constraints.RepositoryProblemByGroupIdConstraint;
27 import org.apache.maven.archiva.database.constraints.RepositoryProblemByRepositoryIdConstraint;
28 import org.apache.maven.archiva.database.constraints.RepositoryProblemConstraint;
29 import org.apache.maven.archiva.model.RepositoryProblem;
30 import org.apache.maven.archiva.model.RepositoryProblemReport;
31 import org.apache.maven.archiva.security.ArchivaRoleConstants;
32 import org.codehaus.plexus.redback.rbac.Resource;
33 import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
34 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
35 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
36 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
38 import javax.servlet.http.HttpServletRequest;
39 import java.util.ArrayList;
40 import java.util.List;
43 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="generateReportAction"
45 public class GenerateReportAction
46 extends PlexusActionSupport
47 implements SecureAction, ServletRequestAware
50 * @plexus.requirement role-hint="jdo"
52 protected ArchivaDAO dao;
54 protected Constraint constraint;
56 protected HttpServletRequest request;
58 protected List reports = new ArrayList();
60 protected String groupId;
62 protected String repositoryId;
64 protected String prev;
66 protected String next;
68 protected int[] range = new int[2];
70 protected int page = 1;
72 protected int rowCount = 100;
74 protected boolean isLastPage = false;
76 public static final String BLANK = "blank";
78 public static final String BASIC = "basic";
80 private static Boolean jasperPresent;
82 public String execute()
85 List problemArtifacts = dao.getRepositoryProblemDAO().queryRepositoryProblems( configureConstraint() );
88 request.getRequestURL().substring( 0, request.getRequestURL().indexOf( request.getRequestURI() ) );
89 RepositoryProblem problemArtifact;
90 RepositoryProblemReport problemArtifactReport;
91 for ( int i = 0; i < problemArtifacts.size(); i++ )
93 problemArtifact = (RepositoryProblem) problemArtifacts.get( i );
94 problemArtifactReport = new RepositoryProblemReport( problemArtifact );
96 problemArtifactReport.setGroupURL( contextPath + "/browse/" + problemArtifact.getGroupId() );
97 problemArtifactReport.setArtifactURL(
98 contextPath + "/browse/" + problemArtifact.getGroupId() + "/" + problemArtifact.getArtifactId() );
100 reports.add( problemArtifactReport );
103 if ( reports.size() <= rowCount )
109 reports.remove( rowCount );
112 prev = request.getRequestURL() + "?page=" + ( page - 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId +
113 "&repositoryId=" + repositoryId;
114 next = request.getRequestURL() + "?page=" + ( page + 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId +
115 "&repositoryId=" + repositoryId;
117 if ( reports.size() == 0 && page == 1 )
121 else if ( !isJasperPresent() )
131 private static boolean isJasperPresent()
133 if ( jasperPresent == null )
137 Class.forName( "net.sf.jasperreports.engine.JRExporterParameter" );
138 jasperPresent = Boolean.TRUE;
140 catch ( ClassNotFoundException e )
142 jasperPresent = Boolean.FALSE;
145 return jasperPresent.booleanValue();
148 private Constraint configureConstraint()
150 Constraint constraint;
152 range[0] = ( page - 1 ) * rowCount;
153 range[1] = ( page * rowCount ) + 1; // Add 1 to check if it's the last page or not.
155 if ( groupId != null && ( !groupId.equals( "" ) ) )
157 if ( repositoryId != null && ( !repositoryId.equals( "" ) ) )
159 constraint = new RepositoryProblemConstraint( range, groupId, repositoryId );
163 constraint = new RepositoryProblemByGroupIdConstraint( range, groupId );
166 else if ( repositoryId != null && ( !repositoryId.equals( "" ) ) )
168 constraint = new RepositoryProblemByRepositoryIdConstraint( range, repositoryId );
172 constraint = new RangeConstraint( range );
178 public void setServletRequest( HttpServletRequest request )
180 this.request = request;
183 public List getReports()
188 public String getGroupId()
193 public void setGroupId( String groupId )
195 this.groupId = groupId;
198 public String getRepositoryId()
203 public void setRepositoryId( String repositoryId )
205 this.repositoryId = repositoryId;
208 public String getPrev()
213 public String getNext()
223 public void setPage( int page )
228 public int getRowCount()
233 public void setRowCount( int rowCount )
235 this.rowCount = rowCount;
238 public boolean getIsLastPage()
243 public SecureActionBundle getSecureActionBundle()
244 throws SecureActionException
246 SecureActionBundle bundle = new SecureActionBundle();
248 bundle.setRequiresAuthentication( true );
249 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_ACCESS_REPORT, Resource.GLOBAL );