Skip to content

Commit d338f93

Browse files
authored
Merge pull request #18 from entityc/more-setup-fixes
Fixed setups to work properly.
2 parents b9aa32b + 41e198c commit d338f93

File tree

11 files changed

+146
-37
lines changed

11 files changed

+146
-37
lines changed

README.md

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,20 @@ The following are the major technologies are used by this library:
3737

3838
## How to Use
3939

40-
With your Entity Compiler project setup, the library is used by declaring it as a `repository` in your project's
41-
`Space` referencing a specific tag, where the tag corresponds to a version of the library.
40+
The easiest way to get started is to install a sample project. This can be done using the Entity Compiler's `setup` command. To do this you first need to have the Entity Compiler installed. See
4241

43-
Your repository declaration may look like:
42+
On a command line run the following command:
4443

44+
```zsh
45+
ec setup github:entityc/ec-springboot-lib:production/setups/BasicWebApp
4546
```
46-
repository SpringbootTemplates {
47-
type github
48-
organization "entityc"
49-
name "ec-springboot-lib"
50-
path "templates"
51-
tag "v0.7.0"
52-
}
53-
```
54-
55-
You can then import the templates using something like the following:
5647

57-
```
58-
output ServerCode {
59-
path "src/main/java"
60-
}
48+
This will start the process of installing a basic spring boot application.
49+
It will prompt you to enter information about the microservice it is creating for you.
50+
Many of the prompts have default values; you can either just hit return to get the default value
51+
or enter another value.
6152

62-
templates {
63-
import from SpringbootTemplates
64-
65-
template Microservice {
66-
output primary ServerCode
67-
}
68-
}
69-
```
53+
It will then print out instructions on how to bring up the microservice.
7054

7155
## Licensing
7256

project/ApplicationPropertiesTemplate.eml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $[D ""]
44
$[D "> In the future it may be capable of merging with an existing application.properties file but"]
55
$[D "for now it only. generates the initial version of the file."]
66

7-
$[let microserviceTitle = space.getMetadataValue("microserviceTitle")]
7+
$[let databaseName = space.getMetadataValue("databaseName")]
88
$[file ifdoesnotexist "src/main/resources" "application" "yml"]
99
info:
1010
app:
@@ -40,9 +40,9 @@ spring:
4040
application:
4141
name: '@artifactId@'
4242
datasource:
43-
url: ''
44-
username: ''
45-
password: ''
43+
url: 'jdbc:postgresql://localhost:5432/${databaseName}'
44+
username: 'postgres'
45+
password: 'postgres'
4646
jpa:
4747
hibernate:
4848
ddl-auto: update

project/ScriptsTemplate.eml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$[file ifdoesnotexist "" "build" "sh"]
22
mvn clean package spring-boot:repackage
33
$[/file]
4-
$[file ifdoesnotexist "" "run" "sh"]
4+
$[file ifdoesnotexist "" "start" "sh"]
55
./build.sh
66
mvn spring-boot:run
77
$[/file]

setups/BasicWebAppSetupTemplate.eml

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,63 @@ $[ D "compiler input files to generate the application." ]
77
$[ let repoTag = "production" ]
88
$[ let stdLibRepoName = "ec-std-lib" ]
99
$[ let stdLibRepoTag = "v0.10.0" ]
10+
$[ let appFolderName = (#SetupDirectoryName:"BasicWebApp") ]
1011

1112
$[* -------------- PROMPTS -------------- *]
12-
$[ log ]$[/ log ]
13+
$[ log ]
14+
15+
----------------------------------------------------------------------------------
16+
Configure your Microservice
17+
----------------------------------------------------------------------------------
18+
19+
$[/ log ]
1320

1421
$[* APPLICATION NAME *]
1522
$[ let appName = (#appName:"MyApp") ]
1623
$[ prompt appName: string ]Enter the name of the application [${appName}]: $[/ prompt ]
1724
$[ if !(appName|is:identifier) ]
18-
$[ log fatal ]The application name must start with a letter and only contain letters and numbers.$[/ log ]
25+
$[ log fatal ]The application name must start with a capital letter and only contain letters and numbers.$[/ log ]
1926
$[/ if ]
2027
$[ if appName|is:uncapitalized ]
2128
$[ let appName = appName|capitalize ]
2229
$[ log info ]Capitalizing application name: ${appName}$[/ log ]
2330
$[/ if ]
2431

32+
$[ log ]$[/ log ]
33+
2534
$[* API PREFIX NAMESPACE *]
26-
$[ let urlPrefix = #urlPrefix ]
27-
$[ prompt urlPrefix: string ]Enter optional URL prefix for the application (e.g., my/app): $[/ prompt ]
35+
$[ let urlPrefix = (#urlPrefix:"my/app") ]
36+
$[ prompt urlPrefix: string ]Enter optional URL prefix for the application [${urlPrefix}]: $[/ prompt ]
2837
$[ if urlPrefix == null ]
2938
$[ let urlPrefix = "" ]
3039
$[/ if ]
3140
$[ if !(urlPrefix|is:path) ]
3241
$[ log fatal ]The URL prefix must be a valid URL path (letters, numbers, '-' and '/').$[/ log ]
3342
$[/ if ]
3443

44+
$[ log ]$[/ log ]
45+
3546
$[* APP BASE JAVA PACKAGE *]
36-
$[ let appBasePackage = #appBasePackage ]
37-
$[ prompt appBasePackage: string ]Enter the base Java package for all installed/generated source files: $[/ prompt ]
47+
$[ let appBasePackage = (#appBasePackage:"com.example.service") ]
48+
$[ prompt appBasePackage: string ]Enter the base Java package for all installed/generated source files [${appBasePackage}]: $[/ prompt ]
3849
$[ if appBasePackage == null || appBasePackage.length == 0 ]
3950
$[ log fatal ]You must specify at least one level of package.$[/ log ]
4051
$[/ if ]
4152
$[ if !(appBasePackage|is:namespace) ]
4253
$[ log fatal ]The specified package is not a valid Java package.$[/ log ]
4354
$[/ if ]
4455

56+
$[ log ]$[/ log ]
57+
58+
$[* DATABASE NAME *]
59+
$[ let databaseName = (#databaseName:"postgres") ]
60+
$[ prompt databaseName: string ]Enter the name of the postgres database to use [${databaseName}]: $[/ prompt ]
61+
$[ if !(databaseName|is:identifier) ]
62+
$[ log fatal ]The database name must start with a letter and contain only letters and numbers.$[/ log ]
63+
$[/ if ]
64+
65+
$[ log ]$[/ log ]
66+
4567
$[* ENTITY NAME *]
4668
$[ let entityName = (#entityName:"Widget") ]
4769
$[ prompt entityName: string ]Enter an entity name to get things started [${entityName}]: $[/ prompt ]
@@ -53,6 +75,8 @@ $[ if entityName|is:uncapitalized ]
5375
$[ log info ]Capitalizing entity name: ${entityName}$[/ log ]
5476
$[/ if ]
5577

78+
$[ log ]$[/ log ]
79+
5680
$[ let protobufOption = (#protobuf:"n") ]
5781
$[ prompt protobufOption: boolean ]Would you like to include Protobuf support (y/n)? [${protobufOption}]: $[/ prompt ]
5882

@@ -61,6 +85,8 @@ $[ if protobufOption ]
6185
$[ do extraDomains.add("ProtobufDTO") ]
6286
$[/ if ]
6387

88+
$[ log ]$[/ log ]
89+
6490
$[* -------------- INSTALLS -------------- *]
6591

6692
$[* Entities *]
@@ -77,4 +103,49 @@ $[ install "authors/PomAuthor.eml" "authors" ]
77103

78104
$[* Base *]
79105
$[ install "basicWebApp/Configuration.edl" "" ]
80-
$[ install "basicWebApp/Space.edl" "" ]
106+
$[ install "basicWebApp/Space.edl" "" ]
107+
108+
$[log]
109+
110+
----------------------------------------------------------------------------------
111+
Build and Bring up Microservice
112+
----------------------------------------------------------------------------------
113+
114+
An Entity Compiler project has been created in a folder named "${appFolderName}". You will need to do the following:
115+
116+
1) You need to have Postgres installed on your local machine.
117+
118+
2) In Postgres, create a database named "${databaseName}" owned by username "postgres" with password "postgres".
119+
These are defaults, you can edit the projects "application.yaml" file to change these settings to be more secure.
120+
121+
3) With a command line, go into the "${appFolderName}" directory and run the "runec.sh" script:
122+
% cd ${appFolderName}
123+
% ./runec.sh
124+
This will run the Entity Compiler to generate all the microservice files.
125+
126+
4) You should now see a script called "build.sh", run this:
127+
% ./build.sh
128+
This will enscure that the source files for the microservice were generated properly. If you receive an error,
129+
go to the Github repository https://github.com/entityc/ec-springboot-lib and create an issue describing the
130+
error you received.
131+
132+
5) Now you are ready to bring up the microservice. Run the "start.sh" script:
133+
% ./start.sh
134+
This will startup the microservice and setup the database. However, you do not yet have an initial admin user.
135+
136+
6) Shutdown the microservice by hitting Ctrl-C.
137+
138+
7) Run the "restore_admin_user.sh" script:
139+
% ./restore_admin_user.sh
140+
This will install an admin user directly into the database.
141+
142+
8) Bring up the microservice again:
143+
% ./start.sh
144+
145+
$[let prefix = urlPrefix != "" ? urlPrefix + "/" : ""]
146+
9) Open a web browser to http://localhost:8080/${prefix}auth/login
147+
You will need to login with:
148+
149+
Password: admin
150+
This will bring you to the main admin page where you can see a button for your entity "${entityName}"
151+
$[/log]

setups/MakeRunECScriptTemplate.eml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
$[D summary, main "This setup template creates a script that you run after setup completes that will run the"]
22
$[D summary, main "entity compiler for this project."]
33

4+
$[log]Installing scripts...$[/log]
45
$[install "basicWebApp/runec.sh" ""]
6+
$[install "basicWebApp/platform_admin_user.dmp" ""]
7+
$[install "basicWebApp/restore_admin_user.sh" ""]

setups/basicWebApp/Space.edl.eml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ space ${appName} {
99
"microserviceTitle" : "${appName|title}",
1010
"microserviceName" : "${appName}",
1111
"basePackage" : "${appBasePackage}",
12+
"databaseName" : "${databaseName}",
1213
$[if appBaseUrlPath != null]
1314
"appBaseUrlPath" : "${appBaseUrlPath}",
1415
$[/if]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--
2+
-- PostgreSQL database dump
3+
--
4+
5+
-- Dumped from database version 13.4
6+
-- Dumped by pg_dump version 14.6 (Homebrew)
7+
8+
SET statement_timeout = 0;
9+
SET lock_timeout = 0;
10+
SET idle_in_transaction_session_timeout = 0;
11+
SET client_encoding = 'UTF8';
12+
SET standard_conforming_strings = on;
13+
SELECT pg_catalog.set_config('search_path', '', false);
14+
SET check_function_bodies = false;
15+
SET xmloption = content;
16+
SET client_min_messages = warning;
17+
SET row_security = off;
18+
19+
--
20+
-- Data for Name: platform_user; Type: TABLE DATA; Schema: public; Owner: postgres
21+
--
22+
23+
COPY public.platform_user (created_on, email, enabled, encoded_password, first_name, last_name, modified_on, user_id) FROM stdin;
24+
2023-06-05 07:03:20.797815-07 [email protected] t $2a$14$ogUcrQdidi5RkESh.YeeeeALgU1nimQQkpMiGcss/qmaHmkxv7eSi admin user 2023-12-21 04:35:41.76295-08 d8c49f52-1a34-4d63-9390-fa59b09e0f2b
25+
\.
26+
27+
28+
--
29+
-- Data for Name: platform_user_roles; Type: TABLE DATA; Schema: public; Owner: postgres
30+
--
31+
32+
COPY public.platform_user_roles (user_id, value) FROM stdin;
33+
d8c49f52-1a34-4d63-9390-fa59b09e0f2b 1
34+
d8c49f52-1a34-4d63-9390-fa59b09e0f2b 2
35+
\.
36+
37+
--
38+
-- PostgreSQL database dump complete
39+
--
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export PGPASSWORD=postgres
2+
psql --username=postgres --dbname=postgres < platform_admin_user.dmp

setups/domains/AdminUIDomain.edl.eml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
domain AdminUI (${appName}) {
22

3+
enum Role {
4+
T "role"
5+
Editor { T "canAccess" }
6+
Administrator { T "canAccess" }
7+
}
8+
39
entity ${entityName} {
410
T "home", "edit"
511
attributes {

setups/domains/SecurityDomain.edl.eml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ domain Security (${appName}) {
4040

4141
entity ${entityName} {
4242
T "access:write:role:editor"
43+
T "access:read:role:editor"
44+
T "access:read:role:default"
4345
relationships {
4446
createdUser {
4547
T "user:created"

0 commit comments

Comments
 (0)