forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
HelloWorld #3246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MatheMatrix
wants to merge
1
commit into
zsv_4.10.25
Choose a base branch
from
sync/zstackio/zhong_zhou_helloworld
base: zsv_4.10.25
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HelloWorld #3246
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| CREATE TABLE `GreetingVO` ( | ||
| `uuid` VARCHAR(32) NOT NULL, | ||
| `greeting` VARCHAR(255) NOT NULL, | ||
| `lastOpDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, | ||
| `createDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', | ||
| PRIMARY KEY (`uuid`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <service xmlns="http://zstack.org/schema/zstack"> | ||
| <id>helloworld</id> | ||
| <interceptor>HelloWorldApiInterceptor</interceptor> | ||
|
|
||
| <message> | ||
| <name>org.zstack.plugin.example.APIHelloWorldMsg</name> | ||
| </message> | ||
| <message> | ||
| <name>org.zstack.plugin.example.APICreateGreetingMsg</name> | ||
| </message> | ||
| <message> | ||
| <name>org.zstack.plugin.example.APIDeleteGreetingMsg</name> | ||
| </message> | ||
| </service> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <beans xmlns="http://www.springframework.org/schema/beans" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" | ||
| xmlns:tx="http://www.springframework.org/schema/tx" xmlns:zstack="http://zstack.org/schema/zstack" | ||
| xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
| http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | ||
| http://www.springframework.org/schema/aop | ||
| http://www.springframework.org/schema/aop/spring-aop-3.0.xsd | ||
| http://www.springframework.org/schema/tx | ||
| http://www.springframework.org/schema/tx/spring-tx-3.0.xsd | ||
| http://zstack.org/schema/zstack | ||
| http://zstack.org/schema/zstack/plugin.xsd" | ||
| default-init-method="init" default-destroy-method="destroy"> | ||
|
|
||
| <bean id="HelloWorldApiInterceptor" class="org.zstack.plugin.example.HelloWorldApiInterceptor" > | ||
| <zstack:plugin> | ||
| <zstack:extension interface="org.zstack.header.apimediator.ApiMessageInterceptor"/> | ||
| </zstack:plugin> | ||
| </bean> | ||
|
|
||
| <bean id="HelloWorldManager" class="org.zstack.plugin.example.HelloWorldManagerImpl" > | ||
| <zstack:plugin> | ||
| <zstack:extension interface="org.zstack.header.Component" /> | ||
| <zstack:extension interface="org.zstack.header.Service" /> | ||
| </zstack:plugin> | ||
| </bean> | ||
| </beans> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>plugin</artifactId> | ||
| <groupId>org.zstack</groupId> | ||
| <version>4.10.0</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>helloworld</artifactId> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>${project.compiler.version}</version> | ||
| <configuration> | ||
| <compilerId>groovy-eclipse-compiler</compilerId> | ||
| <source>${project.java.version}</source> | ||
| <target>${project.java.version}</target> | ||
| <debuglevel>lines,vars,source</debuglevel> | ||
| <debug>true</debug> | ||
| </configuration> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.codehaus.groovy</groupId> | ||
| <artifactId>groovy-eclipse-compiler</artifactId> | ||
| <version>${groovy.eclipse.compiler}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.codehaus.groovy</groupId> | ||
| <artifactId>groovy-eclipse-batch</artifactId> | ||
| <version>${groovy.eclipse.batch}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>aspectj-maven-plugin</artifactId> | ||
| <version>${aspectj.plugin.version}</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>compile</goal> | ||
| <goal>test-compile</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| <configuration> | ||
| <source>${project.java.version}</source> | ||
| <target>${project.java.version}</target> | ||
| <complianceLevel>${project.java.version}</complianceLevel> | ||
| <XnoInline>true</XnoInline> | ||
| <aspectLibraries> | ||
| <aspectLibrary> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-aspects</artifactId> | ||
| </aspectLibrary> | ||
| <aspectLibrary> | ||
| <groupId>org.zstack</groupId> | ||
| <artifactId>core</artifactId> | ||
| </aspectLibrary> | ||
| <aspectLibrary> | ||
| <groupId>org.zstack</groupId> | ||
| <artifactId>header</artifactId> | ||
| </aspectLibrary> | ||
| </aspectLibraries> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
24 changes: 24 additions & 0 deletions
24
plugin/helloworld/src/main/java/org/zstack/plugin/example/APICreateGreetingEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.zstack.plugin.example; | ||
|
|
||
| import org.zstack.header.message.APIEvent; | ||
| import org.zstack.header.rest.RestResponse; | ||
|
|
||
| @RestResponse(allTo = "inventory") | ||
| public class APICreateGreetingEvent extends APIEvent { | ||
| private GreetingInventory inventory; | ||
|
|
||
| public APICreateGreetingEvent() { | ||
| } | ||
|
|
||
| public APICreateGreetingEvent(String apiId) { | ||
| super(apiId); | ||
| } | ||
|
|
||
| public GreetingInventory getInventory() { | ||
| return inventory; | ||
| } | ||
|
|
||
| public void setInventory(GreetingInventory inventory) { | ||
| this.inventory = inventory; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
plugin/helloworld/src/main/java/org/zstack/plugin/example/APICreateGreetingMsg.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package org.zstack.plugin.example; | ||
|
|
||
| import org.springframework.http.HttpMethod; | ||
| import org.zstack.header.message.APICreateMessage; | ||
| import org.zstack.header.message.APIParam; | ||
| import org.zstack.header.rest.RestRequest; | ||
|
|
||
|
|
||
| @RestRequest(path = "/helloworld/greetings", method = HttpMethod.POST, responseClass = APICreateGreetingEvent.class, parameterName = "params") | ||
| public class APICreateGreetingMsg extends APICreateMessage { | ||
| @APIParam(emptyString = false) | ||
| private String greeting; | ||
|
|
||
| public String getGreeting() { | ||
| return greeting; | ||
| } | ||
|
|
||
| public void setGreeting(String greeting) { | ||
| this.greeting = greeting; | ||
| } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
plugin/helloworld/src/main/java/org/zstack/plugin/example/APIDeleteGreetingEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.zstack.plugin.example; | ||
|
|
||
| import org.zstack.header.message.APIEvent; | ||
| import org.zstack.header.rest.RestResponse; | ||
|
|
||
| @RestResponse | ||
| public class APIDeleteGreetingEvent extends APIEvent { | ||
| public APIDeleteGreetingEvent() { | ||
| } | ||
|
|
||
| public APIDeleteGreetingEvent(String apiId) { | ||
| super(apiId); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
plugin/helloworld/src/main/java/org/zstack/plugin/example/APIDeleteGreetingMsg.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.zstack.plugin.example; | ||
|
|
||
| import org.springframework.http.HttpMethod; | ||
| import org.zstack.header.message.APIDeleteMessage; | ||
| import org.zstack.header.rest.RestRequest; | ||
|
|
||
| @RestRequest(path = "/helloworld/greetings/{uuid}", method = HttpMethod.DELETE, responseClass = APIDeleteGreetingEvent.class) | ||
| public class APIDeleteGreetingMsg extends APIDeleteMessage implements GreetingMessage { | ||
| private String uuid; | ||
|
|
||
| public String getUuid() { | ||
| return uuid; | ||
| } | ||
|
|
||
| public void setUuid(String uuid) { | ||
| this.uuid = uuid; | ||
| } | ||
|
|
||
| @Override | ||
| public String getGreetingUuid() { | ||
| return uuid; | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
plugin/helloworld/src/main/java/org/zstack/plugin/example/APIHelloWorldEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.zstack.plugin.example; | ||
|
|
||
| import org.zstack.header.message.APIEvent; | ||
| import org.zstack.header.rest.RestResponse; | ||
|
|
||
| @RestResponse(allTo = "greeting") | ||
| public class APIHelloWorldEvent extends APIEvent { | ||
| private String greeting; | ||
|
|
||
| public APIHelloWorldEvent() { | ||
| } | ||
|
|
||
| public APIHelloWorldEvent(String apiId) { | ||
| super(apiId); | ||
| } | ||
|
|
||
| public String getGreeting() { | ||
| return greeting; | ||
| } | ||
|
|
||
| public void setGreeting(String greeting) { | ||
| this.greeting = greeting; | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
plugin/helloworld/src/main/java/org/zstack/plugin/example/APIHelloWorldMsg.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.zstack.plugin.example; | ||
|
|
||
| import org.springframework.http.HttpMethod; | ||
| import org.zstack.header.message.APIMessage; | ||
| import org.zstack.header.message.APIParam; | ||
| import org.zstack.header.rest.RestRequest; | ||
|
|
||
| @RestRequest(path = "/helloworld/greetings", method = HttpMethod.GET, responseClass = APIHelloWorldEvent.class) | ||
| public class APIHelloWorldMsg extends APIMessage { | ||
| @APIParam(maxLength = 255) | ||
| private String greeting; | ||
|
|
||
| public String getGreeting() { | ||
| return greeting; | ||
| } | ||
|
|
||
| public void setGreeting(String greeting) { | ||
| this.greeting = greeting; | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
plugin/helloworld/src/main/java/org/zstack/plugin/example/Greeting.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package org.zstack.plugin.example; | ||
|
|
||
| import org.zstack.header.message.Message; | ||
|
|
||
| public interface Greeting { | ||
| void handleMessage(Message msg); | ||
| } |
50 changes: 50 additions & 0 deletions
50
plugin/helloworld/src/main/java/org/zstack/plugin/example/GreetingBase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package org.zstack.plugin.example; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowire; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Configurable; | ||
| import org.zstack.core.cloudbus.CloudBus; | ||
| import org.zstack.core.db.DatabaseFacade; | ||
| import org.zstack.header.message.APIMessage; | ||
| import org.zstack.header.message.Message; | ||
|
|
||
| @Configurable(preConstruction = true, autowire = Autowire.BY_TYPE) | ||
| public class GreetingBase implements Greeting { | ||
| protected GreetingVO self; | ||
|
|
||
| @Autowired | ||
| protected CloudBus bus; | ||
| @Autowired | ||
| protected DatabaseFacade dbf; | ||
|
|
||
| public GreetingBase(GreetingVO self) { | ||
| this.self = self; | ||
| } | ||
|
|
||
| @Override | ||
| public void handleMessage(Message msg) { | ||
| if (msg instanceof APIMessage) { | ||
| handleApiMessage((APIMessage) msg); | ||
| } else { | ||
| handleLocalMessage(msg); | ||
| } | ||
| } | ||
|
|
||
| private void handleLocalMessage(Message msg) { | ||
| bus.dealWithUnknownMessage(msg); | ||
| } | ||
|
|
||
| private void handleApiMessage(APIMessage msg) { | ||
| if (msg instanceof APIDeleteGreetingMsg) { | ||
| handle((APIDeleteGreetingMsg) msg); | ||
| } else { | ||
| bus.dealWithUnknownMessage(msg); | ||
| } | ||
| } | ||
|
|
||
| private void handle(APIDeleteGreetingMsg msg) { | ||
| dbf.remove(self); | ||
|
|
||
| bus.publish(new APIDeleteGreetingEvent(msg.getId())); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缺少
__example__,API 文档生成会缺口。Line 10 的 API 消息类需要提供
__example__以生成 API 文档与模板。✅ 建议补充
public class APICreateGreetingMsg extends APICreateMessage { @@ public void setGreeting(String greeting) { this.greeting = greeting; } + + public static APICreateGreetingMsg __example__() { + APICreateGreetingMsg msg = new APICreateGreetingMsg(); + msg.setGreeting("hello"); + return msg; + } }🤖 Prompt for AI Agents