-
Notifications
You must be signed in to change notification settings - Fork 37
tutorial for cobigen angular client generation #73
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
Changes from 21 commits
2d2b30e
e09029a
e76adf1
c04434a
664670a
00e9905
8db291b
e054940
6d191a2
4b8a270
75a54c9
63bc32a
49cdc6a
f7fbe22
afb0eb4
3458de2
1c7b2ad
b94221c
7c2f64a
c951a28
ec0a3d7
4b84226
af5ea9c
3a59430
baaf8f5
393b9e5
9d9a4d4
85382a3
5403dec
fbc4e56
01c3fbe
c84e0a9
2df2803
8984313
126b959
7c5868b
52d1699
892cdd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.example.application.cobigenangularexample.customermanagement.dataaccess.api; | ||
|
||
import java.sql.Timestamp; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "Customer") | ||
public class CustomerEntity { | ||
|
||
private String firstname; | ||
|
||
private String lastname; | ||
|
||
private int age; | ||
|
||
/** | ||
* @return the firstname | ||
*/ | ||
public String getFirstname() { | ||
return firstname; | ||
} | ||
|
||
/** | ||
* @param firstname the firstname to set | ||
*/ | ||
public void setFirstname(String firstname) { | ||
this.firstname = firstname; | ||
} | ||
|
||
/** | ||
* @return the lastname | ||
*/ | ||
public String getLastname() { | ||
return lastname; | ||
} | ||
|
||
/** | ||
* @param lastname the lastname to set | ||
*/ | ||
public void setLastname(String lastname) { | ||
this.lastname = lastname; | ||
} | ||
|
||
/** | ||
* @return the age | ||
*/ | ||
public int getAge() { | ||
return age; | ||
} | ||
|
||
/** | ||
* @param age the age to set | ||
*/ | ||
public void setAge(int age) { | ||
this.age = age; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
private int age; | ||
private String company; | ||
|
||
public String getCompany() { | ||
return company; | ||
} | ||
public void setCompany(String company) { | ||
this.company = company; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
= Generate Angular Client with devonfw | ||
== angular client generation with cobigen | ||
==== | ||
With the CobiGen code generator you can easily generate components for your angular application. | ||
The following tutorial provides an example for using the CobiGen cli. | ||
You can find more information on https://github.com/devonfw/cobigen/wiki/howto_angular-client-generation | ||
## Prerequisites | ||
* devonfw Ide | ||
* Install yarn globally | ||
## Learning goals. | ||
GuentherJulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Here in this tutorial we will learn the following: | ||
* Create an angular project | ||
* Cobigen to generate the angular source code out of the java files | ||
* Change the user interface in the angular project to show the new components | ||
* Show the newly created components | ||
GuentherJulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
==== | ||
|
||
[step] | ||
-- | ||
restoreDevonfwIde(["java", "mvn", "node", "ng", "npm"]) | ||
GuentherJulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-- | ||
|
||
For this tutorial an installation of the devonfw IDE is required, which was already set up for you. The next step is to install the CobiGen CLI. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should say that this is only required the first time you use it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Added in the above line.. |
||
[step] | ||
-- | ||
installCobiGen() | ||
-- | ||
|
||
CobiGen uses the backend classes for generating your code used in the angular application. So in the next steps you will create a java project, create a simple java class and run the backend server. | ||
[step] | ||
-- | ||
createDevon4jProject("cobigenjavaexample") | ||
-- | ||
|
||
==== | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opening with |
||
[step] | ||
== Build and Run Java Server | ||
-- | ||
buildJava("cobigenjavaexample") | ||
runServerJava("cobigenjavaexample/server",{ "startupTime": 180, "port": 8080, "path": "cobigenjavaexample" }) | ||
-- | ||
Now the Java Server should be running. | ||
==== | ||
|
||
GuentherJulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CobiGen is integrated via plugin in the VS Code IDE. We will use it to generate code from one single java class based on existing templates. | ||
[step] | ||
-- | ||
createDevon4ngProject("cobigenangularexample", "") | ||
GuentherJulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
buildNg("cobigenangularexample") | ||
runClientNg("cobigenangularexample/angular", { "startupTime": 200, "port": 4200, "path": "" }) | ||
GuentherJulian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
createFile("cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/dataaccess/api/CustomerEntity.java", "files/CustomerEntity.java") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file has to be created in the java project not the angular project There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createFile("cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/dataaccess/api/CustomerEntity.java", "files/CustomerEntity.java") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed with @GuentherJulian its fixed with Angular client generation. |
||
adaptTemplatesCobiGen() | ||
cobiGenJava("cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/dataaccess/api/CustomerEntity.java",[1,3,5,6,8]) | ||
-- | ||
The CobiGen code generator will generate some java classes for you. These contain code for basic CRUD operations, REST service handling and data access. | ||
|
||
For example, the following files are generated by CobiGen when using the specified templates: | ||
|
||
(1) CRUD logic: Generates the logic layer and implementations for some use cases. | ||
- `devonfw/workspaces/main/cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/logic/impl/CustomermanagementImpl.java`{{open}} | ||
- `devonfw/workspaces/main/cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/logic/impl/usecase/UcManageCustomerImpl.java`{{open}} | ||
- `devonfw/workspaces/main/cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/logic/impl/usecase/UcFindCustomerImpl.java`{{open}} | ||
- `devonfw/workspaces/main/cobigenangularexample/api/src/main/java/com/example/application/cobigenangularexample/customermanagement/logic/api/Customermanagement.java`{{open}} | ||
|
||
(3) CRUD REST services: Generates the service layer with CRUD operations for using in REST services. | ||
- `devonfw/workspaces/main/cobigenangularexample/api/src/main/java/com/example/application/cobigenangularexample/customermanagement/service/api/rest/CustomermanagementRestService.java`{{open}} | ||
- `devonfw/workspaces/main/cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/service/impl/rest/CustomermanagementRestServiceImpl.java`{{open}} | ||
|
||
(5) TO's: Generates the related Transfer Objects. | ||
- `devonfw/workspaces/main/cobigenangularexample/api/src/main/java/com/example/application/cobigenangularexample/customermanagement/logic/api/to/CustomerEto.java`{{open}} | ||
- `devonfw/workspaces/main/cobigenangularexample/api/src/main/java/com/example/application/cobigenangularexample/customermanagement/logic/api/to/CustomerSearchCriteriaTo.java`{{open}} | ||
|
||
(6) Entity infrastructure: Creates the entity main interface and edits (by a merge) the current entity to extend the newly generated classes. | ||
- `devonfw/workspaces/main/cobigenangularexample/api/src/main/java/com/example/application/cobigenangularexample/customermanagement/common/api/Customer.java`{{open}} | ||
- `devonfw/workspaces/main/cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/dataaccess/api/CustomerEntity.java`{{open}} (changed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not use Katacoda Scenario Syntax as this may result in parsing issues. Please use the tutorial-compiler functions instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we have also used this block of text in the cobigen tutorial before. |
||
|
||
(8) CRUD SpringData Repository: Generates the entity repository (that contains the CRUD operations) in the data access layer. | ||
- `devonfw/workspaces/main/cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/dataaccess/api/repo/CustomerRepository.java`{{open}} | ||
==== | ||
|
||
Furthermore, we can change the CustomerEntity afterwards and update our source files simply by running cobigen again. | ||
[step] | ||
== Change Entity and run cobigen again | ||
-- | ||
changeFile("cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/dataaccess/api/CustomerEntity.java", { "file": "files/Placeholder.java", "placeholder": "private int age;" }) | ||
cobiGenJava("cobigenangularexample/core/src/main/java/com/example/application/cobigenangularexample/customermanagement/dataaccess/api/CustomerEntity.java",[1,3,5,6,8]) | ||
-- | ||
==== | ||
Conclusion: In this Tutorial we learned the following things below. | ||
Create an angular project | ||
Cobigen to generate the angular source code out of the java files | ||
Change the user interface in the angular project to show the new components | ||
Show the newly created components | ||
==== |
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.
You can now add a subtitle with the == syntax. See https://github.com/devonfw-tutorials/tutorials/wiki/Development