1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one
3+ * or more contributor license agreements. See the NOTICE file
4+ * distributed with this work for additional information
5+ * regarding copyright ownership. The ASF licenses this file
6+ * to you under the Apache License, Version 2.0 (the
7+ * "License"); you may not use this file except in compliance
8+ * with the License. You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing,
13+ * software distributed under the License is distributed on an
14+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ * KIND, either express or implied. See the License for the
16+ * specific language governing permissions and limitations
17+ * under the License.
18+ */
19+
20+ package org .apache .cloudstack .api .command ;
21+
22+ import org .apache .cloudstack .api .APICommand ;
23+ import org .apache .cloudstack .api .ApiConstants ;
24+ import org .apache .cloudstack .api .BaseAsyncCreateCmd ;
25+ import org .apache .cloudstack .api .Parameter ;
26+ import org .apache .cloudstack .api .response .CoffeeResponse ;
27+ import org .apache .cloudstack .acl .RoleType ;
28+
29+ import java .util .Map ;
30+
31+ @ APICommand (
32+ name = "createCoffee" ,
33+ description = "Creates a new coffee order" ,
34+ responseObject = CoffeeResponse .class ,
35+ since = "4.23.0.0" ,
36+ requestHasSensitiveInfo = false ,
37+ responseHasSensitiveInfo = false ,
38+ authorized = {RoleType .Admin , RoleType .ResourceAdmin , RoleType .DomainAdmin , RoleType .User }
39+ )
40+ public class CreateCoffeeCmd extends BaseAsyncCreateCmd {
41+
42+ @ Parameter (name = ApiConstants .NAME ,
43+ type = CommandType .STRING ,
44+ required = true ,
45+ description = "name of the coffee order" )
46+ private String name ;
47+
48+ @ Parameter (name = "offering" ,
49+ type = CommandType .STRING ,
50+ required = true ,
51+ description = "type of coffee (Espresso, Cappuccino, Mocha, Latte)" )
52+ private String offering ;
53+
54+ @ Parameter (name = "size" ,
55+ type = CommandType .STRING ,
56+ required = true ,
57+ description = "size of coffee (SMALL, MEDIUM, LARGE)" )
58+ private String size ;
59+
60+ @ Parameter (name = "details" ,
61+ type = CommandType .MAP ,
62+ required = false ,
63+ description = "details for the coffee order" )
64+ private Map <String , String > details ;
65+
66+ private Long coffeeId ;
67+
68+ @ Override
69+ public void create () {
70+ // Just set a fake ID for now
71+ coffeeId = 3L ;
72+ setEntityId (coffeeId );
73+ setEntityUuid ("fake-uuid-" + coffeeId );
74+ }
75+
76+ @ Override
77+ public void execute () {
78+ // Hardcoded response for now
79+ CoffeeResponse response = new CoffeeResponse ();
80+ response .setId (String .valueOf (coffeeId ));
81+ response .setName (name );
82+ response .setOffering (offering );
83+ response .setSize (size );
84+ response .setState ("Created" );
85+ response .setObjectName ("coffee" );
86+ response .setResponseName (getCommandName ());
87+
88+ setResponseObject (response );
89+ }
90+
91+ @ Override
92+ public String getEventType () {
93+ return "COFFEE.CREATE" ;
94+ }
95+
96+ @ Override
97+ public String getEventDescription () {
98+ return "Creating coffee: " + name ;
99+ }
100+
101+ @ Override
102+ public long getEntityOwnerId () {
103+ return com .cloud .user .Account .ACCOUNT_ID_SYSTEM ;
104+ }
105+
106+ public String getName () {
107+ return name ;
108+ }
109+
110+ public String getOffering () {
111+ return offering ;
112+ }
113+
114+ public String getSize () {
115+ return size ;
116+ }
117+
118+ public Map <String , String > getDetails () {
119+ return details ;
120+ }
121+ }
0 commit comments