1 package org.apache.maven.continuum.web.action;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.continuum.ContinuumException;
23 import org.apache.maven.continuum.model.project.BuildResult;
24 import org.apache.maven.continuum.model.project.Project;
25 import org.apache.maven.continuum.model.project.ProjectGroup;
26 import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import java.util.Date;
31
32
33
34
35
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
99
100
101
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 }