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="generateReport"
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<RepositoryProblemReport> reports = new ArrayList<RepositoryProblemReport>();
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;
85 List<RepositoryProblem> 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 ( NoClassDefFoundError e )
142 jasperPresent = Boolean.FALSE;
144 catch ( ClassNotFoundException e )
146 jasperPresent = Boolean.FALSE;
149 return jasperPresent.booleanValue();
152 private Constraint configureConstraint()
154 Constraint constraint;
156 range[0] = ( page - 1 ) * rowCount;
157 range[1] = ( page * rowCount ) + 1; // Add 1 to check if it's the last page or not.
159 if ( groupId != null && ( !groupId.equals( "" ) ) )
161 if ( repositoryId != null && ( !repositoryId.equals( "" ) && !repositoryId.equals( PickReportAction.ALL_REPOSITORIES ) ) )
163 constraint = new RepositoryProblemConstraint( range, groupId, repositoryId );
167 constraint = new RepositoryProblemByGroupIdConstraint( range, groupId );
170 else if ( repositoryId != null && ( !repositoryId.equals( "" ) && !repositoryId.equals( PickReportAction.ALL_REPOSITORIES ) ) )
172 constraint = new RepositoryProblemByRepositoryIdConstraint( range, repositoryId );
176 constraint = new RangeConstraint( range );
182 public void setServletRequest( HttpServletRequest request )
184 this.request = request;
187 public List<RepositoryProblemReport> getReports()
192 public String getGroupId()
197 public void setGroupId( String groupId )
199 this.groupId = groupId;
202 public String getRepositoryId()
207 public void setRepositoryId( String repositoryId )
209 this.repositoryId = repositoryId;
212 public String getPrev()
217 public String getNext()
227 public void setPage( int page )
232 public int getRowCount()
237 public void setRowCount( int rowCount )
239 this.rowCount = rowCount;
242 public boolean getIsLastPage()
247 public SecureActionBundle getSecureActionBundle()
248 throws SecureActionException
250 SecureActionBundle bundle = new SecureActionBundle();
252 bundle.setRequiresAuthentication( true );
253 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_ACCESS_REPORT, Resource.GLOBAL );