2121import org .apache .log4j .Logger ;
2222
2323import com .cloud .api .ApiConstants ;
24+ import com .cloud .api .BaseAsyncCreateCmd ;
2425import com .cloud .api .BaseCmd ;
2526import com .cloud .api .Implementation ;
2627import com .cloud .api .Parameter ;
2728import com .cloud .api .ServerApiException ;
2829import com .cloud .api .response .ProjectResponse ;
30+ import com .cloud .event .EventTypes ;
2931import com .cloud .exception .InvalidParameterValueException ;
3032import com .cloud .exception .ResourceAllocationException ;
3133import com .cloud .projects .Project ;
3234import com .cloud .user .Account ;
3335import com .cloud .user .UserContext ;
3436
3537@ Implementation (description ="Creates a project" , responseObject =ProjectResponse .class )
36- public class CreateProjectCmd extends BaseCmd {
38+ public class CreateProjectCmd extends BaseAsyncCreateCmd {
3739 public static final Logger s_logger = Logger .getLogger (CreateProjectCmd .class .getName ());
3840
3941 private static final String s_name = "createprojectresponse" ;
@@ -59,11 +61,20 @@ public class CreateProjectCmd extends BaseCmd {
5961 /////////////////////////////////////////////////////
6062
6163 public String getAccountName () {
62- return accountName ;
64+ if (accountName != null ) {
65+ return accountName ;
66+ } else {
67+ return UserContext .current ().getCaller ().getAccountName ();
68+ }
6369 }
6470
6571 public Long getDomainId () {
66- return domainId ;
72+ if (domainId != null ) {
73+ return domainId ;
74+ } else {
75+ return UserContext .current ().getCaller ().getDomainId ();
76+ }
77+
6778 }
6879
6980 public String getName () {
@@ -100,9 +111,8 @@ public long getEntityOwnerId() {
100111 /////////////////////////////////////////////////////
101112
102113 @ Override
103- public void execute () throws ResourceAllocationException {
104- UserContext .current ().setEventDetails ("Project Name: " + getName ());
105- Project project = _projectService .createProject (getName (), getDisplayText (), getAccountName (), getDomainId ());
114+ public void execute (){
115+ Project project = _projectService .enableProject (this .getEntityId ());
106116 if (project != null ) {
107117 ProjectResponse response = _responseGenerator .createProjectResponse (project );
108118 response .setResponseName (getCommandName ());
@@ -111,4 +121,25 @@ public void execute() throws ResourceAllocationException{
111121 throw new ServerApiException (BaseCmd .INTERNAL_ERROR , "Failed to create a project" );
112122 }
113123 }
124+
125+ @ Override
126+ public void create () throws ResourceAllocationException {
127+ UserContext .current ().setEventDetails ("Project Name: " + getName ());
128+ Project project = _projectService .createProject (getName (), getDisplayText (), getAccountName (), getDomainId ());
129+ if (project != null ) {
130+ this .setEntityId (project .getId ());
131+ } else {
132+ throw new ServerApiException (BaseCmd .INTERNAL_ERROR , "Failed to create a project" );
133+ }
134+ }
135+
136+ @ Override
137+ public String getEventType () {
138+ return EventTypes .EVENT_PROJECT_CREATE ;
139+ }
140+
141+ @ Override
142+ public String getEventDescription () {
143+ return "creating project" ;
144+ }
114145}
0 commit comments