Skip to content

Commit 8ab8a65

Browse files
author
bernard
committed
#10 Angular JS consuming REST services
1 parent e91d3a4 commit 8ab8a65

30 files changed

+24975
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ bin/
44
target/
55
libs/
66
tmp/
7+
node_modules/
78

89
# OS Files #
910
.DS_Store

jaxrs/angularjs/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "jax-rs-angularjs",
3+
"version": "0.1.0",
4+
"description": "Angular JS consuming REST services",
5+
"engines": {
6+
"node": "~0.10"
7+
},
8+
"main": "web-server.js",
9+
"dependencies": {
10+
},
11+
"devDependencies": {
12+
"http-proxy": "0.10.3",
13+
"karma": "0.10.2",
14+
"karma-coverage": "0.1.0",
15+
"karma-jasmine": "0.1.3",
16+
"karma-junit-reporter": "0.1.0",
17+
"karma-spec-reporter": "0.0.5",
18+
"karma-ng-scenario": "0.1.0"
19+
},
20+
"scripts": {
21+
"test": "karma start src/test/javascript/karma.conf.js --browsers PhantomJS --singleRun true"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/javaee-samples/javaee7-samples.git"
26+
},
27+
"author": "Bernard Labno"
28+
}

jaxrs/angularjs/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<parent>
5+
<artifactId>jaxrs-samples</artifactId>
6+
<groupId>org.javaee7.jaxrs</groupId>
7+
<version>1.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
<artifactId>jax-rs-angularjs</artifactId>
12+
<packaging>war</packaging>
13+
<description>Angular JS consuming REST services</description>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.jboss.arquillian.extension</groupId>
17+
<artifactId>arquillian-persistence-impl</artifactId>
18+
<version>1.0.0.Alpha6</version>
19+
<scope>test</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.jboss.arquillian.extension</groupId>
23+
<artifactId>arquillian-rest-client-api</artifactId>
24+
<version>1.0.0.Alpha1</version>
25+
<scope>test</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.jboss.arquillian.extension</groupId>
29+
<artifactId>arquillian-rest-client-impl-3x</artifactId>
30+
<version>1.0.0.Alpha1</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.jboss.arquillian.graphene</groupId>
35+
<artifactId>graphene-webdriver</artifactId>
36+
<version>2.0.0.Final</version>
37+
<type>pom</type>
38+
<scope>test</scope>
39+
</dependency>
40+
</dependencies>
41+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.example.domain;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.Id;
6+
7+
@Entity
8+
public class Note {
9+
10+
@GeneratedValue
11+
@Id
12+
private Long id;
13+
14+
private String summary;
15+
16+
private String title;
17+
18+
public Long getId()
19+
{
20+
return id;
21+
}
22+
23+
public void setId(Long id)
24+
{
25+
this.id = id;
26+
}
27+
28+
public String getSummary()
29+
{
30+
return summary;
31+
}
32+
33+
public void setSummary(String summary)
34+
{
35+
this.summary = summary;
36+
}
37+
38+
public String getTitle()
39+
{
40+
return title;
41+
}
42+
43+
public void setTitle(String title)
44+
{
45+
this.title = title;
46+
}
47+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.rest;
2+
3+
import javax.ws.rs.ApplicationPath;
4+
import javax.ws.rs.core.Application;
5+
6+
@ApplicationPath("/rest")
7+
public class NoteApp extends Application {
8+
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.rest;
2+
3+
import com.example.domain.Note;
4+
5+
import javax.ws.rs.DELETE;
6+
import javax.ws.rs.GET;
7+
import javax.ws.rs.POST;
8+
import javax.ws.rs.Path;
9+
import javax.ws.rs.PathParam;
10+
import java.util.List;
11+
12+
@Path("/note")
13+
public interface NoteResource {
14+
15+
@GET
16+
@Path("/")
17+
List<Note> getNotes();
18+
19+
@DELETE
20+
@Path("/{id}")
21+
void removeNote(@PathParam("id") Long noteId);
22+
23+
@POST
24+
@Path("/")
25+
Note saveNote(Note note);
26+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.example.rest;
2+
3+
import com.example.domain.Note;
4+
5+
import javax.ejb.Stateless;
6+
import javax.persistence.EntityManager;
7+
import javax.persistence.NoResultException;
8+
import javax.persistence.PersistenceContext;
9+
import java.util.List;
10+
11+
@Stateless
12+
public class NoteResourceImpl implements NoteResource {
13+
14+
@PersistenceContext
15+
private EntityManager entityManager;
16+
17+
@Override
18+
public List<Note> getNotes()
19+
{
20+
return entityManager.createQuery("from Note order by id", Note.class).getResultList();
21+
}
22+
23+
@Override
24+
public void removeNote(Long noteId)
25+
{
26+
final Note note = entityManager.find(Note.class, noteId);
27+
if (null == note) {
28+
throw new NoResultException("No note with id " + noteId + " found");
29+
}
30+
entityManager.remove(note);
31+
}
32+
33+
@Override
34+
public Note saveNote(Note note)
35+
{
36+
entityManager.persist(note);
37+
return note;
38+
}
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
4+
5+
<persistence-unit name="test">
6+
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
7+
<properties>
8+
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
9+
</properties>
10+
</persistence-unit>
11+
12+
</persistence>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
insert into note (id,title,summary) values (nextval('hibernate_sequence'),'Hello','First note');
2+
insert into note (id,title,summary) values (nextval('hibernate_sequence'),'Good bye','Another note');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<%@ page contentType="script/javascript;charset=UTF-8" language="java" %>
2+
window.applicationContextPath="<%=request.getContextPath()%>";

0 commit comments

Comments
 (0)