Skip to content

Commit 1638f21

Browse files
committed
Added documentation.
Refactored Person properties.
1 parent 73e9415 commit 1638f21

6 files changed

Lines changed: 118 additions & 80 deletions

File tree

src/main/java/com/cortez/samples/javaee7angular/data/Person.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Person {
1818

1919
private String description;
2020

21-
private String link;
21+
private String imageUrl;
2222

2323
public Long getId() {
2424
return id;
@@ -44,12 +44,12 @@ public void setDescription(String description) {
4444
this.description = description;
4545
}
4646

47-
public String getLink() {
48-
return link;
47+
public String getImageUrl() {
48+
return imageUrl;
4949
}
5050

51-
public void setLink(String link) {
52-
this.link = link;
51+
public void setImageUrl(String link) {
52+
this.imageUrl = link;
5353
}
5454

5555
@Override

src/main/java/com/cortez/samples/javaee7angular/rest/PersonResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ public Person savePerson(Person person) {
8080
Person personToSave = new Person();
8181
personToSave.setName(person.getName());
8282
personToSave.setDescription(person.getDescription());
83-
personToSave.setLink(person.getLink());
83+
personToSave.setImageUrl(person.getImageUrl());
8484
entityManager.persist(person);
8585
} else {
8686
Person personToUpdate = getPerson(person.getId());
8787
personToUpdate.setName(person.getName());
8888
personToUpdate.setDescription(person.getDescription());
89-
personToUpdate.setLink(person.getLink());
89+
personToUpdate.setImageUrl(person.getImageUrl());
9090
person = entityManager.merge(personToUpdate);
9191
}
9292

src/main/resources/sql/create.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
CREATE SEQUENCE ID START WITH 100;
2-
CREATE TABLE PERSON("ID" INTEGER not null primary key, "NAME" VARCHAR(50), "DESCRIPTION" VARCHAR(100), "LINK" VARCHAR(500));
2+
CREATE TABLE PERSON("ID" INTEGER not null primary key, "NAME" VARCHAR(50), "DESCRIPTION" VARCHAR(100), "IMAGEURL" VARCHAR(500));

src/main/resources/sql/load.sql

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (1, 'Uzumaki Naruto', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140523045537/naruto/images/thumb/3/36/Naruto_Uzumaki.png/300px-Naruto_Uzumaki.png');
2-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (2, 'Hatake Kakashi', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140616090940/naruto/images/thumb/b/b3/KakashiHatake.png/300px-KakashiHatake.png');
3-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (3, 'Haruno Sakura', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130910111848/naruto/images/thumb/5/59/Sakura_Part_II.png/300px-Sakura_Part_II.png');
4-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (4, 'Uchiha Sasuke', 'Missing-nin', 'http://img2.wikia.nocookie.net/__cb20140124043530/naruto/images/thumb/c/ce/Sasuke_Shippuden.png/300px-Sasuke_Shippuden.png');
5-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (5, 'Gaara', 'Sunagakure', 'http://img3.wikia.nocookie.net/__cb20130910220958/naruto/images/thumb/0/0f/Gaara_Part_II.png/300px-Gaara_Part_II.png');
6-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (6, 'Killer Bee', 'Kumogakure', 'http://img1.wikia.nocookie.net/__cb20120215120020/naruto/images/thumb/3/36/Killer_Bee.png/300px-Killer_Bee.png');
7-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (7, 'Jiraya', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120925123905/naruto/images/thumb/2/21/Profile_Jiraiya.PNG/300px-Profile_Jiraiya.PNG');
8-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (8, 'Namikaze Minato', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20140209115534/naruto/images/thumb/1/1f/Minato_Namikaze.PNG/300px-Minato_Namikaze.PNG');
9-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (9, 'Uchiha Madara', 'Missing-nin', 'http://img2.wikia.nocookie.net/__cb20140118022828/naruto/images/thumb/2/29/Uchiha_Madara.png/300px-Uchiha_Madara.png');
10-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (10, 'Senju Hashirama', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120915132454/naruto/images/thumb/7/7e/Hashirama_Senju.png/300px-Hashirama_Senju.png');
11-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (11, 'Might Guy', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20140605202934/naruto/images/thumb/4/40/MightGuy.png/300px-MightGuy.png');
12-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (12, 'Hyuga Neji', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130913104919/naruto/images/thumb/a/a8/Neji_Part_II.png/300px-Neji_Part_II.png');
13-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (13, 'Rock Lee', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20131029112352/naruto/images/thumb/7/7d/Lee_timeskip.png/300px-Lee_timeskip.png');
14-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (14, 'Uchiha Obito', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20140616090247/naruto/images/thumb/a/a0/Obito_Uchiha2.png/300px-Obito_Uchiha2.png');
15-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (15, 'Kurama', 'Tailed Beast', 'http://img2.wikia.nocookie.net/__cb20100601024642/naruto/images/thumb/2/28/9_tails.PNG/300px-9_tails.PNG');
16-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (16, 'Uzumaki Kushina', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20121006054451/naruto/images/thumb/4/4d/Kushina_2.png/300px-Kushina_2.png');
17-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (17, 'Nara Shikamaru', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130917013425/naruto/images/thumb/9/9a/Shikamaru_Nara.png/300px-Shikamaru_Nara.png');
18-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (18, 'Sarutobi Hiruzen', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20120912121115/naruto/images/thumb/e/e4/Hiruzen_Sarutobi.png/300px-Hiruzen_Sarutobi.png');
19-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (19, 'Tsunade', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20140417023105/naruto/images/thumb/1/14/Tsunade_newshot.png/300px-Tsunade_newshot.png');
20-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (20, 'Orochimaru', 'Missing-nin', 'http://img3.wikia.nocookie.net/__cb20100623204832/naruto/images/thumb/e/e8/Orochimaru2.jpg/300px-Orochimaru2.jpg');
21-
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "LINK") VALUES (21, 'Uchicha Itachi', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20110723152743/naruto/images/thumb/8/8d/UchihaItachi.png/300px-UchihaItachi.png');
1+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (1, 'Uzumaki Naruto', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140523045537/naruto/images/thumb/3/36/Naruto_Uzumaki.png/300px-Naruto_Uzumaki.png');
2+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (2, 'Hatake Kakashi', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20140616090940/naruto/images/thumb/b/b3/KakashiHatake.png/300px-KakashiHatake.png');
3+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (3, 'Haruno Sakura', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130910111848/naruto/images/thumb/5/59/Sakura_Part_II.png/300px-Sakura_Part_II.png');
4+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (4, 'Uchiha Sasuke', 'Missing-nin', 'http://img2.wikia.nocookie.net/__cb20140124043530/naruto/images/thumb/c/ce/Sasuke_Shippuden.png/300px-Sasuke_Shippuden.png');
5+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (5, 'Gaara', 'Sunagakure', 'http://img3.wikia.nocookie.net/__cb20130910220958/naruto/images/thumb/0/0f/Gaara_Part_II.png/300px-Gaara_Part_II.png');
6+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (6, 'Killer Bee', 'Kumogakure', 'http://img1.wikia.nocookie.net/__cb20120215120020/naruto/images/thumb/3/36/Killer_Bee.png/300px-Killer_Bee.png');
7+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (7, 'Jiraya', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120925123905/naruto/images/thumb/2/21/Profile_Jiraiya.PNG/300px-Profile_Jiraiya.PNG');
8+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (8, 'Namikaze Minato', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20140209115534/naruto/images/thumb/1/1f/Minato_Namikaze.PNG/300px-Minato_Namikaze.PNG');
9+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (9, 'Uchiha Madara', 'Missing-nin', 'http://img2.wikia.nocookie.net/__cb20140118022828/naruto/images/thumb/2/29/Uchiha_Madara.png/300px-Uchiha_Madara.png');
10+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (10, 'Senju Hashirama', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20120915132454/naruto/images/thumb/7/7e/Hashirama_Senju.png/300px-Hashirama_Senju.png');
11+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (11, 'Might Guy', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20140605202934/naruto/images/thumb/4/40/MightGuy.png/300px-MightGuy.png');
12+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (12, 'Hyuga Neji', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130913104919/naruto/images/thumb/a/a8/Neji_Part_II.png/300px-Neji_Part_II.png');
13+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (13, 'Rock Lee', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20131029112352/naruto/images/thumb/7/7d/Lee_timeskip.png/300px-Lee_timeskip.png');
14+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (14, 'Uchiha Obito', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20140616090247/naruto/images/thumb/a/a0/Obito_Uchiha2.png/300px-Obito_Uchiha2.png');
15+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (15, 'Kurama', 'Tailed Beast', 'http://img2.wikia.nocookie.net/__cb20100601024642/naruto/images/thumb/2/28/9_tails.PNG/300px-9_tails.PNG');
16+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (16, 'Uzumaki Kushina', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20121006054451/naruto/images/thumb/4/4d/Kushina_2.png/300px-Kushina_2.png');
17+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (17, 'Nara Shikamaru', 'Konoha', 'http://img1.wikia.nocookie.net/__cb20130917013425/naruto/images/thumb/9/9a/Shikamaru_Nara.png/300px-Shikamaru_Nara.png');
18+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (18, 'Sarutobi Hiruzen', 'Konoha', 'http://img4.wikia.nocookie.net/__cb20120912121115/naruto/images/thumb/e/e4/Hiruzen_Sarutobi.png/300px-Hiruzen_Sarutobi.png');
19+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (19, 'Tsunade', 'Konoha', 'http://img2.wikia.nocookie.net/__cb20140417023105/naruto/images/thumb/1/14/Tsunade_newshot.png/300px-Tsunade_newshot.png');
20+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (20, 'Orochimaru', 'Missing-nin', 'http://img3.wikia.nocookie.net/__cb20100623204832/naruto/images/thumb/e/e8/Orochimaru2.jpg/300px-Orochimaru2.jpg');
21+
INSERT INTO PERSON("ID", "NAME", "DESCRIPTION", "IMAGEURL") VALUES (21, 'Uchicha Itachi', 'Missing-nin', 'http://img1.wikia.nocookie.net/__cb20110723152743/naruto/images/thumb/8/8d/UchihaItachi.png/300px-UchihaItachi.png');

src/main/webapp/index.html

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ <h1>Java EE - Angular Application</h1>
3636

3737
<br/>
3838

39+
<!-- Specify a Angular controller script that binds Javascript variables to the feedback messages.-->
3940
<div class="message" ng-controller="alertMessagesController">
4041
<alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</alert>
4142
</div>
4243

4344
<br>
4445

45-
<!-- Specify a JavaScript controller script that binds Javascript variables to the HTML.-->
46+
<!-- Specify a Angular controller script that binds Javascript variables to the grid.-->
4647
<div class="grid" ng-controller="personsListController">
4748
<div>
4849
<h3>List Persons</h3>
@@ -58,62 +59,73 @@ <h3>List Persons</h3>
5859
</pagination>
5960
</div>
6061

61-
62-
62+
<!-- Specify a Angular controller script that binds Javascript variables to the form.-->
6363
<div class="form" ng-controller="personsFormController">
64+
<!-- Verify person, if there is no id present, that we are Adding a Person -->
6465
<div ng-if="person.id == null">
6566
<h3>Add Person</h3>
6667
</div>
67-
68+
<!-- Otherwise it's an Edit -->
6869
<div ng-if="person.id != null">
6970
<h3>Edit Person</h3>
7071
</div>
7172

7273
<div>
74+
<!-- Specify the function to be called on submit and disable HTML5 validation, since we're using Angular validation-->
7375
<form name="personForm" ng-submit="updatePerson()" novalidate>
7476

77+
<!-- Display an error if the input is invalid and is dirty (only when someone changes the value) -->
7578
<div class="form-group" ng-class="{'has-error' : personForm.name.$invalid && personForm.name.$dirty}">
7679
<label for="name">Name:</label>
80+
<!-- Display a check when the field is valid and was modified -->
7781
<span ng-class="{'glyphicon glyphicon-ok' : personForm.name.$valid && personForm.name.$dirty}"></span>
7882

7983
<input id="name" name="name" type="text" class="form-control" maxlength="50"
8084
ng-model="person.name"
8185
required ng-minlength="2" ng-maxlength="50"/>
8286

87+
<!-- Validation messages to be displayed on required, minlength and maxlength -->
8388
<p class="help-block" ng-show="personForm.name.$error.required">Add Name.</p>
8489
<p class="help-block" ng-show="personForm.name.$error.minlength">Name must be at least 2 characters long.</p>
8590
<p class="help-block" ng-show="personForm.name.$error.maxlength">Name cannot be longer than 50 characters.</p>
8691
</div>
8792

93+
<!-- Display an error if the input is invalid and is dirty (only when someone changes the value) -->
8894
<div class="form-group" ng-class="{'has-error' : personForm.description.$invalid && personForm.description.$dirty}">
8995
<label for="description">Description:</label>
96+
<!-- Display a check when the field is valid and was modified -->
9097
<span ng-class="{'glyphicon glyphicon-ok' : personForm.description.$valid && personForm.description.$dirty}"></span>
9198

9299
<input id="description" name="description" type="text" class="form-control" maxlength="100"
93100
ng-model="person.description"
94101
required ng-minlength="5" ng-maxlength="100"/>
95102

103+
<!-- Validation messages to be displayed on required, minlength and maxlength -->
96104
<p class="help-block" ng-show="personForm.description.$error.required">Add Description.</p>
97105
<p class="help-block" ng-show="personForm.description.$error.minlength">Description must be at least 5 characters long.</p>
98106
<p class="help-block" ng-show="personForm.description.$error.maxlength">Description cannot be longer than 100 characters.</p>
99107
</div>
100108

101-
<div class="form-group" ng-class="{'has-error' : personForm.link.$invalid && personForm.link.$dirty}">
102-
<label for="link">Link:</label>
103-
<span ng-class="{'glyphicon glyphicon-ok' : personForm.link.$valid && personForm.link.$dirty}"></span>
109+
<!-- Display an error if the input is invalid and is dirty (only when someone changes the value) -->
110+
<div class="form-group" ng-class="{'has-error' : personForm.imageUrl.$invalid && personForm.imageUrl.$dirty}">
111+
<label for="imageUrl">Image URL:</label>
112+
<!-- Display a check when the field is valid and was modified -->
113+
<span ng-class="{'glyphicon glyphicon-ok' : personForm.imageUrl.$valid && personForm.imageUrl.$dirty}"></span>
104114

105-
<input id="link" name="link" type="url" class="form-control" maxlength="500"
106-
ng-model="person.link"
115+
<input id="imageUrl" name="imageUrl" type="url" class="form-control" maxlength="500"
116+
ng-model="person.imageUrl"
107117
required/>
108118

109-
<p class="help-block" ng-show="personForm.link.$error.required">Add Link.</p>
110-
<p class="help-block" ng-show="personForm.link.$invalid && personForm.link.$dirty">Invalid Link.</p>
119+
<!-- Validation messages to be displayed on required and invalid. Type 'url' makes checks to a proper url format. -->
120+
<p class="help-block" ng-show="personForm.imageUrl.$error.required">Add Image URL.</p>
121+
<p class="help-block" ng-show="personForm.imageUrl.$invalid && personForm.imageUrl.$dirty">Invalid Image URL.</p>
111122
</div>
112123

113-
<div class="avatar" ng-if="person.link">
114-
<img ng-src="{{person.link}}" width="400" height="250"/>
124+
<div class="avatar" ng-if="person.imageUrl">
125+
<img ng-src="{{person.imageUrl}}" width="400" height="250"/>
115126
</div>
116127

128+
<!-- Form buttons. The 'Save' button is only enabled when the form is valid. -->
117129
<div class="buttons">
118130
<button type="button" class="btn btn-primary" ng-click="clearForm()">Clear</button>
119131
<button type="submit" class="btn btn-primary" ng-disabled="personForm.$invalid">Save</button>

0 commit comments

Comments
 (0)