Skip to content

Commit

Permalink
Release3 (#22)
Browse files Browse the repository at this point in the history
* partial fix

* Set<> changed to List<>

* improvements and guid type changed to Integer

* Changed GUID type

* #2 groupdId packange naming changed. version upgraded

* improvements

* fixed cli

* pipeline updated

* Closes #3

* improvements

* partial fix

* fixed duplicated left joins

* refactored

* bug fixed

* updated

* Closes #1

* updated README

* Release/2.0.0 (#16)

* Enhance finder #7 (#14)

* release version

* Hotfix/deployment (#17)

* Feature/improvements (#19)

* #18 renamed classes

* #18 moved to another package

* processor implemented

* major cleanup and javadoc

* README updated

* #18 READEME updated and minor fixes

* #18 replaced Sets from Google to own impl and defined mappers

* #18 improving verbose messaging

* improvements

* introduces sql helper

* removed impl related to Finder's feature

* additional method

* mappers changed

* Updated Readme

* Update README.md

* Updated README

* Feature/improvements (#20)

* #18 renamed classes

* #18 moved to another package

* processor implemented

* major cleanup and javadoc

* README updated

* #18 READEME updated and minor fixes

* #18 replaced Sets from Google to own impl and defined mappers

* #18 improving verbose messaging

* improvements

* introduces sql helper

* removed impl related to Finder's feature

* additional method

* mappers changed

* Updated README
  • Loading branch information
nirodg authored Dec 13, 2018
1 parent d383f5a commit b8770a6
Show file tree
Hide file tree
Showing 96 changed files with 13,588 additions and 11,611 deletions.
90 changes: 51 additions & 39 deletions .m2/settings.xml
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://eorghe.com:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://eorghe.com:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://eorghe.com:8081/repository/maven-central/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<properties>
<url>http://eorghe.com:8081/repository/maven-releases/</url>
<url-snapshopt>http://eorghe.com:8081/repository/maven-snapshots/</url-snapshopt>
</properties>
<repositories>
<repository>
<id>central</id>
<url>http://eorghe.com:8081/repository/maven-central/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://eorghe.com:8081/repository/maven-central/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<servers>
<pluginRepository>
<id>central</id>
<url>http://eorghe.com:8081/repository/maven-central/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<servers>
<server>
<id>nexus</id>
<username>${env.MAVEN_REPO_USER}</username>
<password>${env.MAVEN_REPO_PASS}</password>
<id>nexus</id>
<username>${env.MAVEN_REPO_USER}</username>
<password>${env.MAVEN_REPO_PASS}</password>
</server>
</servers>

<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>

</settings>
131 changes: 88 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# dodo
mini framework with JEE technologies

A bunch of classes build with JEE technologies under the hood for making easier the development of microservices.

For the showcase please [click here](https://github.com/nirodg/dodo-example/)

Expand All @@ -9,7 +10,7 @@ For the showcase please [click here](https://github.com/nirodg/dodo-example/)
# Defining the entity
```java
// imports
import com.brage.dodo.jpa.AbstractModel;
import ro.brage.dodo.jpa.Model;

@Entity
@Table(name = "CAR")
Expand All @@ -24,6 +25,9 @@ public class Car extends Model {
@Column(name = "LICENSE_PLATE")
private String licensePlate;

@OneToMany
private Set<Accessory> accesories;

// Getters and Setters

}
Expand All @@ -33,81 +37,118 @@ public class Car extends Model {
# Define a DTO
```java
// imports
import com.brage.dodo.jpa.AbstractDTOModel;
import ro.brage.dodo.rs.DtoModel;

public class CarDTO extends AbstractDTOModel {
public class CarDto extends DtoModel {

private String make;

private String model;

private String licensePlate;

private Set<AccessoryDto> accesories;

// Getters and Setters
}
```


# Defining a mapper
Comlex entity? or just an easy class you would like to map? THen you can choose between `AdvancedMapper` and `SimpleMapper`


### Advanced Mapper

Let's say you want to map the Car to CarDto

```java
// imports
import com.brage.dodo.jpa.mapper.AbstractModelMapper;
import ro.brage.dodo.rs.mappers.AdvancedMapper;

@Mapper(componentModel = "cdi")
public abstract class CarMapper extends AbstractModelMapper<Car, CarDTO> {
public abstract class CarMapper extends AdvancedMapper<Car, CarDTO> {

// override method if needed
// override methods if needed

}
```

### SimpleMapper

You need to map something less complex? Great!


```java
import ro.brage.dodo.rs.mappers.SimpleMapper;

@Mapper(componentModel = "cdi")
public abstract class AccessoryDto extends SimpleMapper<Accessory, AccessoryDto> {

}
```

And for the sake of the explanation our `Accessory`'s entity and it's DTO will have the same fields and it's the following:

```java
public class Accessory {

private String name;
private double price;
private int quantity;

}

```

By default the generated mappers will be under `/target/generated-sources/java`. If you're using Eclipse make sure to add this folder as a Source Folder (`Right click -> Built Path -> Use as Source Folder`), for Netbeans this is done automatically.


# Defining the service
Pretty much straight forward, there are a few ways how to fetch the data and it's as follows:


```java
// imports
import com.brage.dodo.jpa.AbstractService;
import com.brage.dodo.jpa.Finder;
import ro.brage.dodo.jpa.EntityService;
import ro.brage.dodo.jpa.Finder;

@Stateless
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class CarService extends AbstractService<Car, CarDTO> {
public class CarService extends EntityService<Car> {

public Car getByLicensePlate(String licensePlate) throws Exception {
return new Finder<>(this)
.equalTo(Car_.licensePlate, licensePlate)
.findItem();
}

public Car getByOwnerIdCard(String ownerIdCard) throws Exception {
return new Finder<>(this)
.equalTo(Car_.owner, Client_.idCard, ownerIdCard)
.findItem();
}

public List<Car> getByMakeAndModel(String make, String model) throws Exception {
return new Finder<>(this)
.equalTo(Car_.make, make)
.equalTo(Car_.model, model)
.findItems();
}

public List<Car> getByModelAndFromYearToCurrent(String model, Date fromYear) throws Exception {
return new Finder<>(this)
.equalTo(Car_.model, model)
.between(Car_.year, fromYear, new Date())
.orderBy(Car_.year, OrderBy.ASC)
.findItems();
}

public List<Car> filterByYears(Date from, Date to) throws Exception {
return new Finder<>(this)
.between(Car_.year, from, to)
.orderBy(Car_.year, OrderBy.ASC)
.maxItems(5)
.findItems();
}

// Using the generated class for Entities annotated with @Finder
public List<Car> getByMakeAndModel(String make, String model) throws Exception {
return new CarFinder(this)
.make().equalsTo(make)
.model().equalsTo(model)
.findItems();
}

public void disableCar(String id) {
String updateQuery = "UPDATE Car c SET c.enabled=0 where c.id:id";
getEntityManager().createQuery(updateQuery).setParameter("id", id).executeUpdate();
// Static queries
public void disableCarByGuid(String guid) {
String updateQuery = "UPDATE Car c SET c.enabled=0 where c.guid: guid";
getEntityManager().createQuery(updateQuery).setParameter("guid", guid).executeUpdate();
}

// Static queries with inherited methods and the QueryParams class
public List<Car> findEnabledCarsByGuid() {
return getService().getResults("SELECT c FROM Car c WHERE c.enabled=1",
new QueryParams()
.addParameter(Todo_.enabled, true));
}

public Long getTotalEntities() {
Expand All @@ -117,18 +158,19 @@ public class CarService extends AbstractService<Car, CarDTO> {

}
```
Are you looking for the PersistentManager? Then call it's getter `getEntityManager()` , for more details feel free to check the abstract class `EntityService`

# The API
Remember to define the [@ApplicationPath](https://docs.oracle.com/cd/E24329_01/web.1211/e24983/configure.htm#RESTF189)

```java
// imports
import com.brage.dodo.rs.AbstractRestService;
import com.brage.dodo.rs.RestApi;

@Path("/cars")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface CarRestService extends AbstractRestService<CarDTO> {
public interface CarRestApi extends RestApi<CarDTO> {

@GET
@Path("/getByLicensePlate/{licensePlate}")
Expand All @@ -140,34 +182,37 @@ public interface CarRestService extends AbstractRestService<CarDTO> {
For more information regarding Jax-RS please check the [Oracle's documentation](https://docs.oracle.com/javaee/7/tutorial/jaxrs002.htm)

# The Rest Service

So let's implement the `CarRestApi`

```java
// imports
import com.brage.dodo.rs.AbstractRestServiceBean;
import ro.brage.dodo.rs.RestApiService;

@Stateless
@Local(CarRestService.class)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class CarRestServiceBean extends AbstractRestServiceBean<Car, CarDTO, CarService, CarMapper> implements CarRestService {
public class CarRestService extends RestApiService<Car, CarDTO, CarService, CarMapper> implements CarRestApi {

@Override
public CarDTO getByLicensePlate(String licensePlate) {
getLogger().info("getByLicensePlate({})", licensePlate);

Car car = getService().getByLicensePlate(licensePlate);
return getMapper().find(car);
return getMapper().map(car);
}

}

```

Also a logger is provided from the abstract layer 😉

# Versioning

[SemVer](http://semver.org/) will be used for versioning because it provides a clear documentation. For the versions available, see the [tags on this repository](https://github.com/nirodg/dodo/releases).

# Contribute

In case you would like to contribute updating the documentation, improving the functionalities, reporting issues or fixing them please, you\`re more than welcome 😄 . However, please have a look to the already defined [contribute](/docs/CONTRIBUTING.md)'s guide
In case you would like to contribute updating the documentation, improving the functionalities, reporting issues or fixing them please, you're more than welcome 😄 . However, please have a look to the already defined [contribute](/docs/CONTRIBUTING.md)'s guide

# License

Expand Down
Loading

0 comments on commit b8770a6

Please sign in to comment.