Skip to content

Commit f777f83

Browse files
author
Daman Arora
committed
add CreateCoffeeCmd
1 parent 52ced8e commit f777f83

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
}

plugins/hackerbook/feature/src/main/java/org/apache/cloudstack/coffee/CoffeeService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.cloud.utils.component.PluggableService;
2323
import org.apache.cloudstack.api.command.ListCoffeeCmd;
24+
import org.apache.cloudstack.api.command.CreateCoffeeCmd;
2425

2526
import java.util.ArrayList;
2627
import java.util.List;
@@ -30,6 +31,7 @@ public class CoffeeService implements PluggableService {
3031
@Override
3132
public List<Class<?>> getCommands() {
3233
List<Class<?>> cmdList = new ArrayList<>();
34+
cmdList.add(CreateCoffeeCmd.class);
3335
cmdList.add(ListCoffeeCmd.class);
3436
return cmdList;
3537
}

0 commit comments

Comments
 (0)