1 | package org.apache.maven.continuum.web.action; |
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 | |
22 | import java.util.Date; |
23 | |
24 | import org.apache.maven.continuum.ContinuumException; |
25 | import org.apache.maven.continuum.model.project.BuildResult; |
26 | import org.apache.maven.continuum.model.project.Project; |
27 | import org.apache.maven.continuum.model.project.ProjectGroup; |
28 | import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; |
29 | import org.slf4j.Logger; |
30 | import org.slf4j.LoggerFactory; |
31 | |
32 | /** |
33 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
34 | * @version $Id: ProjectViewAction.java 765340 2009-04-15 20:22:00Z evenisse $ |
35 | * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="projectView" |
36 | */ |
37 | public class ProjectViewAction |
38 | extends ContinuumActionSupport |
39 | { |
40 | private static final Logger logger = LoggerFactory.getLogger( ProjectViewAction.class ); |
41 | |
42 | private Project project; |
43 | |
44 | private int projectId; |
45 | |
46 | private String lastBuildDateTime; |
47 | |
48 | public String execute() |
49 | throws ContinuumException |
50 | { |
51 | ProjectGroup projectGroup = getProjectGroup(); |
52 | |
53 | try |
54 | { |
55 | checkViewProjectGroupAuthorization( projectGroup.getName() ); |
56 | } |
57 | catch ( AuthorizationRequiredException e ) |
58 | { |
59 | return REQUIRES_AUTHORIZATION; |
60 | } |
61 | |
62 | project = getContinuum().getProjectWithAllDetails( projectId ); |
63 | if ( project.getLatestBuildId() > 0 ) |
64 | { |
65 | try |
66 | { |
67 | BuildResult lastBuildResult = getContinuum().getBuildResult( project.getLatestBuildId() ); |
68 | if ( lastBuildResult != null ) |
69 | { |
70 | this.setLastBuildDateTime( dateFormatter.format( new Date( lastBuildResult.getEndTime() ) ) ); |
71 | } |
72 | } |
73 | catch ( ContinuumException e ) |
74 | { |
75 | logger.info( "buildResult with id " + project.getLatestBuildId() + " has been deleted" ); |
76 | } |
77 | } |
78 | |
79 | return SUCCESS; |
80 | } |
81 | |
82 | public void setProjectId( int projectId ) |
83 | { |
84 | this.projectId = projectId; |
85 | } |
86 | |
87 | public Project getProject() |
88 | { |
89 | return project; |
90 | } |
91 | |
92 | public int getProjectId() |
93 | { |
94 | return projectId; |
95 | } |
96 | |
97 | /** |
98 | * Returns the {@link ProjectGroup} instance obtained for |
99 | * the specified project group Id, or null if it were not set. |
100 | * |
101 | * @return the projectGroup |
102 | */ |
103 | public ProjectGroup getProjectGroup() |
104 | throws ContinuumException |
105 | { |
106 | return getContinuum().getProjectGroupByProjectId( projectId ); |
107 | } |
108 | |
109 | public String getLastBuildDateTime() |
110 | { |
111 | return lastBuildDateTime; |
112 | } |
113 | |
114 | public void setLastBuildDateTime( String lastBuildDateTime ) |
115 | { |
116 | this.lastBuildDateTime = lastBuildDateTime; |
117 | } |
118 | } |