Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Eclipse project #1

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
42 changes: 42 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>person-service</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
129 changes: 74 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,84 @@
Person Service
==============

A simple JPA backend service that loads data from a CSV file and make it
accessible through `Person` entity.
**You can clone this project and import it directly into Eclipse**

It can be easily upgraded to read/write from a real database instead of the CSV
file.
A simple JPA backend service that loads data from a CSV file and make it accessible through `Person` entity.

You can modify the provided demo data from `Persons.csv` located under
`src/resources`.
It can be easily upgraded to read/write from a real database instead of the CSV file.

You can modify the provided demo data from `Persons.csv` located under `src/resources`.

Watch step by step on how to use this backend in a Vaadin project
-

[![Vaadin Demo Coding in a Youtube Video](http://img.youtube.com/vi/Lwhg3NrOLVA/0.jpg)](https://www.youtube.com/watch?v=Lwhg3NrOLVA)

Referencing This Project Into Another Maven Project
-

After installing this project locally, you can reference it by including it as a dependency into the front-end project. Most probably you will need to include JavaEE dependencies as well:

```xml
<dependencies>
...

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.vaadin.stepbystep</groupId>
<artifactId>person-service</artifactId>
<version>2.0</version>
</dependency>

...
</dependencies>
```

Usage
-

- Inject `PersonService`.
- Call `getEntries()` to return a list of `Person`.
- Call `delete()` or `save()` to update a given entity.
- Call `getFirst()` to retrieve the first entity.
- Call `getById()` to retrieve an entity by its id.

Example
-

```java
@Inject
PersonService service;

void load() {
component.bind(service.getEntries());
}
```

Obtain Maven dependency
-

You can obtain the maven dependency from [Vaadin Directory](https://vaadin.com/directory/#!addon/demo-person-service) without any downloads or installs.

Import & Install Using CLI
-

Platform and IDE independent, you can install this project locally using the following three commands:
```bash
$ git clone git@github.com:amahdy/person-service.git
$ cd person-service
$ mvn install
```
Or alternatively:

Import Into Eclipse
===================
-

This project is easy to import into Eclipse from the [eclipse-project branch](https://github.com/amahdy/person-service/tree/eclipse-project). Here are the direct steps to get started:

Expand Down Expand Up @@ -58,51 +125,3 @@ This project is easy to import into Eclipse from the [eclipse-project branch](ht
**Step 11) You should get a BUILD SUCCESS in the Console, now the project is ready to be used locally**

![You should get a BUILD SUCCESS in the Console, now the project is ready to be used locally](/readme_files/step11.png?raw=true "You should get a BUILD SUCCESS in the Console, now the project is ready to be used locally")

Referencing this project into another Maven project
===================================================
After installing this project locally, you can easily reference it by including it as a dependecy into the front-end project. Most porbably you will need to include JavaEE dependencies as well:

```xml
<dependencies>
...

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.vaadin.stepbystep</groupId>
<artifactId>person-service</artifactId>
<version>1.0</version>
</dependency>

...
</dependencies>
```

Usage
=====

- Inject `PersonService`.
- Call `loadData()` to load the data from the CSV file.
- Call `getEntries()` to return a list of `Person`.
- Call `delete()` or `save()` to update a given entity.

Example
=======

```java
@Inject
PersonService service;

@PostConstruct
void load() {
service.loadData();

container.bind(service.getEntries());
}
```
34 changes: 32 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
<groupId>org.vaadin.stepbystep</groupId>
<artifactId>person-service</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>Person Service: Step by step backend demo for a Vaadin app</name>
<version>2.0</version>
<name>Demo Person Service</name>
<organization>
<name>AMahdy</name>
</organization>

<prerequisites>
<maven>3</maven>
Expand All @@ -18,6 +21,12 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<deltaspike.version>1.4.1</deltaspike.version>
<Implementation-Version>${project.version}</Implementation-Version>
<!-- Must not change this because of the Directory -->
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
<Vaadin-License-Title>Apache License 2.0</Vaadin-License-Title>
<Vaadin-Addon>${project.artifactId}-${project.version}.jar</Vaadin-Addon>
</properties>

<dependencies>
Expand Down Expand Up @@ -62,5 +71,26 @@
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<!-- Package format version - do not change -->
<Vaadin-Package-Version>1</Vaadin-Package-Version>
<Vaadin-License-Title>${Vaadin-License-Title}</Vaadin-License-Title>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.vaadin.stepbystep.person.backend;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.sql.Date;
import java.time.LocalDate;

@Converter(autoApply = true)
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {

@Override
public Date convertToDatabaseColumn(LocalDate locDate) {
return (locDate == null ? null : Date.valueOf(locDate));
}

@Override
public LocalDate convertToEntityAttribute(Date sqlDate) {
return (sqlDate == null ? null : sqlDate.toLocalDate());
}
}
45 changes: 21 additions & 24 deletions src/main/java/org/vaadin/stepbystep/person/backend/Person.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.vaadin.stepbystep.person.backend;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Temporal;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.time.LocalDate;

/**
* A domain object example. In a real application this would probably be a JPA
Expand All @@ -18,20 +16,19 @@
@Entity
public class Person extends AbstractEntity {

@NotNull(message = "Firstname is required")
@Size(min = 3, max = 40, message = "Firstname must be longer than 3 and less than 40 characters")
private String firstname;
@NotNull(message = "First Name is required")
@Size(min = 3, max = 40, message = "First Name must be longer than 3 and less than 40 characters")
private String firstName;

@NotNull(message = "Lastname is required")
@Size(min = 3, max = 40, message = "Lastname must be longer than 3 and less than 40 characters")
private String lastname;
@NotNull(message = "Last Name is required")
@Size(min = 3, max = 40, message = "Last Name must be longer than 3 and less than 40 characters")
private String lastName;

@NotNull(message = "Email is required")
@Pattern(regexp = ".+@.+\\.[a-z]+", message = "Must be valid email")
private String email;

@Temporal(javax.persistence.TemporalType.DATE)
private Date birthDate;
private LocalDate dateOfBirth;

private boolean remind = false;

Expand All @@ -44,20 +41,20 @@ public class Person extends AbstractEntity {
public Person() {
}

public String getFirstname() {
return firstname;
public String getFirstName() {
return firstName;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastname() {
return lastname;
public String getLastName() {
return lastName;
}

public void setLastname(String lastname) {
this.lastname = lastname;
public void setLastName(String lastName) {
this.lastName = lastName;
}

public boolean isRemind() {
Expand All @@ -76,12 +73,12 @@ public void setEmail(String email) {
this.email = email;
}

public Date getBirthDate() {
return birthDate;
public LocalDate getDateOfBirth() {
return dateOfBirth;
}

public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
public void setDateOfBirth(LocalDate dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}

public String getPicture() {
Expand Down
Loading