1+ /**
2+ * Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+ *
4+ * This software is licensed under the GNU General Public License v3 or later.
5+ *
6+ * It is free software: you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation, either version 3 of the License, or any later version.
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ *
17+ */
18+
19+ package com .cloud .api .commands ;
20+
21+ import org .apache .log4j .Logger ;
22+
23+ import com .cloud .api .ApiConstants ;
24+ import com .cloud .api .BaseCmd ;
25+ import com .cloud .api .Implementation ;
26+ import com .cloud .api .Parameter ;
27+ import com .cloud .api .ServerApiException ;
28+ import com .cloud .api .response .SuccessResponse ;
29+ import com .cloud .user .Account ;
30+
31+ @ Implementation (description ="Adds acoount to a project" , responseObject =SuccessResponse .class )
32+ public class AddAccountToProjectCmd extends BaseCmd {
33+ public static final Logger s_logger = Logger .getLogger (AddAccountToProjectCmd .class .getName ());
34+
35+ private static final String s_name = "addaccounttoprojectresponse" ;
36+
37+ /////////////////////////////////////////////////////
38+ //////////////// API parameters /////////////////////
39+ /////////////////////////////////////////////////////
40+
41+ @ Parameter (name =ApiConstants .PROJECT_ID , type =CommandType .LONG , required =true , description ="id of the project to add the account to" )
42+ private Long projectId ;
43+
44+ @ Parameter (name =ApiConstants .ACCOUNT , type =CommandType .STRING , required =true , description ="name of the account to be added to the project" )
45+ private String accountName ;
46+
47+ /////////////////////////////////////////////////////
48+ /////////////////// Accessors ///////////////////////
49+ /////////////////////////////////////////////////////
50+
51+
52+ public String getAccountName () {
53+ return accountName ;
54+ }
55+
56+ public Long getProjectId () {
57+ return projectId ;
58+ }
59+
60+ public void setProjectId (Long projectId ) {
61+ this .projectId = projectId ;
62+ }
63+
64+ @ Override
65+ public String getCommandName () {
66+ return s_name ;
67+ }
68+
69+ /////////////////////////////////////////////////////
70+ /////////////// API Implementation///////////////////
71+ /////////////////////////////////////////////////////
72+
73+ @ Override
74+ public void execute (){
75+ boolean result = _projectService .addAccountToProject (getProjectId (), getAccountName ());
76+ if (result ) {
77+ SuccessResponse response = new SuccessResponse (getCommandName ());
78+ this .setResponseObject (response );
79+ } else {
80+ throw new ServerApiException (BaseCmd .INTERNAL_ERROR , "Failed to add account to the project" );
81+ }
82+ }
83+
84+ @ Override
85+ public long getEntityOwnerId () {
86+ //TODO - return project entity ownerId
87+ return Account .ACCOUNT_ID_SYSTEM ; // no account info given, parent this command to SYSTEM so ERROR events are tracked
88+ }
89+ }
0 commit comments