finshed impl with demo project

This commit is contained in:
Gaetano Piazzolla
2020-10-28 15:38:33 +01:00
parent 1129a99c2a
commit 4d5995bd1e
65 changed files with 680 additions and 269 deletions

View File

@@ -1,39 +1,42 @@
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'io.freefair.lombok' version "4.1.6" //questo
id 'java'
id 'idea'
id 'java-gradle-plugin'
id 'maven'
}
group = 'com.gae.piaz'
version = '0.0.1-SNAPSHOT'
group = 'gae.piaz'
version = '0.0.6-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.yaml:snakeyaml:1.23'
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'com.google.guava:guava:26.0-jre'
implementation 'org.apache.commons:commons-lang3:3.8.1'
implementation 'org.reflections:reflections:0.9.12' // read classes
implementation 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
implementation 'org.reflections:reflections:0.9.11' // read classes
implementation 'org.freemarker:freemarker:2.3.23'// write classes
// needed dependency also for generated classes
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
compileOnly 'org.projectlombok:lombok:1.18.2'
compileOnly gradleApi()
annotationProcessor "org.mapstruct:mapstruct-processor:1.3.1.Final"
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
gradlePlugin {
plugins {
simplePlugin {
id = 'gae.piaz.layer3gen'
implementationClass = 'gae.piaz.layer3gen.gradle.Layer3GenPlugin'
}
}
}
/*
@@ -47,5 +50,4 @@ jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}*/
}*/

130
demo/.gitignore vendored Normal file
View File

@@ -0,0 +1,130 @@
# Directories #
/build/
bin/
repos/
/repos/
doc/
/doc/
.gradle/
/bin/
target/
# OS Files #
.DS_Store
# JetBrain's Idea specific stuff #
.idea*
*.iml
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
*.class
browscap.csv
gradle/wrapper
gradlew.bat
gradlew
# Package Files #
*.jar
*.war
*.ear
*.db
######################
# Windows
######################
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
######################
# OSX
######################
.DS_Store
.svn
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
######################
# Eclipse
######################
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
/src/main/resources/rebel.xml
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath

14
demo/HELP.md Normal file
View File

@@ -0,0 +1,14 @@
# Getting Started
### Reference Documentation
For further reference, please consider the following sections:
* [Official Gradle documentation](https://docs.gradle.org)
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.3.4.RELEASE/gradle-plugin/reference/html/)
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.3.4.RELEASE/gradle-plugin/reference/html/#build-image)
### Additional Links
These additional references should also help you:
* [Gradle Build Scans insights for your project's build](https://scans.gradle.com#gradle)

52
demo/build.gradle Normal file
View File

@@ -0,0 +1,52 @@
buildscript {
dependencies {
classpath 'gae.piaz:layer3gen:0.0.6-SNAPSHOT'
}
repositories {
mavenCentral()
mavenLocal()
}
}
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
repositories {
mavenCentral()
mavenLocal()
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
// needed dependency also for generated classes
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
compileOnly 'org.projectlombok:lombok:1.18.2'
annotationProcessor "org.mapstruct:mapstruct-processor:1.3.1.Final"
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
apply plugin: 'gae.piaz.layer3gen'
layer3gen {
configPath = 'src/main/resources/3layer-settings.yml'
}

1
demo/settings.gradle Normal file
View File

@@ -0,0 +1 @@
rootProject.name = 'demo'

View File

@@ -0,0 +1,13 @@
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

View File

@@ -1,7 +1,7 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.model.Books;
import com.autogen.example.service.BooksService;
import com.example.demo.model.Books;
import com.example.demo.service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -11,7 +11,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/books/")

View File

@@ -1,9 +1,9 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.controller.dto.BooksDTO;
import com.autogen.example.model.Books;
import com.autogen.example.service.BooksService;
import com.autogen.example.service.mapper.BooksMapper;
import com.example.demo.model.Books;
import com.example.demo.controller.dto.BooksDTO;
import com.example.demo.service.BooksService;
import com.example.demo.service.mapper.BooksMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
@@ -13,7 +13,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/books-dto/")

View File

@@ -1,7 +1,7 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.model.Carts;
import com.autogen.example.service.CartsService;
import com.example.demo.model.Carts;
import com.example.demo.service.CartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -11,7 +11,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/carts/")

View File

@@ -1,9 +1,9 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.controller.dto.CartsDTO;
import com.autogen.example.model.Carts;
import com.autogen.example.service.CartsService;
import com.autogen.example.service.mapper.CartsMapper;
import com.example.demo.model.Carts;
import com.example.demo.controller.dto.CartsDTO;
import com.example.demo.service.CartsService;
import com.example.demo.service.mapper.CartsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
@@ -13,7 +13,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/carts-dto/")

View File

@@ -1,4 +1,4 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
@@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
public interface CrudController<O,P>{

View File

@@ -1,7 +1,7 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.model.Orders;
import com.autogen.example.service.OrdersService;
import com.example.demo.model.Orders;
import com.example.demo.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -11,7 +11,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/orders/")

View File

@@ -1,9 +1,9 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.controller.dto.OrdersDTO;
import com.autogen.example.model.Orders;
import com.autogen.example.service.OrdersService;
import com.autogen.example.service.mapper.OrdersMapper;
import com.example.demo.model.Orders;
import com.example.demo.controller.dto.OrdersDTO;
import com.example.demo.service.OrdersService;
import com.example.demo.service.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
@@ -13,7 +13,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/orders-dto/")

View File

@@ -1,7 +1,7 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.model.Personphone;
import com.autogen.example.service.PersonphoneService;
import com.example.demo.model.Personphone;
import com.example.demo.service.PersonphoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -11,7 +11,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/personphone/")

View File

@@ -1,9 +1,9 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.controller.dto.PersonphoneDTO;
import com.autogen.example.model.Personphone;
import com.autogen.example.service.PersonphoneService;
import com.autogen.example.service.mapper.PersonphoneMapper;
import com.example.demo.model.Personphone;
import com.example.demo.controller.dto.PersonphoneDTO;
import com.example.demo.service.PersonphoneService;
import com.example.demo.service.mapper.PersonphoneMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
@@ -13,7 +13,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/personphone-dto/")

View File

@@ -1,7 +1,7 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.model.Users;
import com.autogen.example.service.UsersService;
import com.example.demo.model.Users;
import com.example.demo.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -11,7 +11,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/users/")

View File

@@ -1,9 +1,9 @@
package com.autogen.example.controller;
package com.example.demo.controller;
import com.autogen.example.controller.dto.UsersDTO;
import com.autogen.example.model.Users;
import com.autogen.example.service.UsersService;
import com.autogen.example.service.mapper.UsersMapper;
import com.example.demo.model.Users;
import com.example.demo.controller.dto.UsersDTO;
import com.example.demo.service.UsersService;
import com.example.demo.service.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
@@ -13,7 +13,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@RestController
@RequestMapping("/users-dto/")

View File

@@ -1,4 +1,4 @@
package com.autogen.example.controller.dto;
package com.example.demo.controller.dto;
import lombok.Data;
@@ -6,7 +6,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Data
public class BooksDTO {

View File

@@ -1,4 +1,4 @@
package com.autogen.example.controller.dto;
package com.example.demo.controller.dto;
import lombok.Data;
@@ -6,7 +6,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Data
public class CartsDTO {

View File

@@ -1,4 +1,4 @@
package com.autogen.example.controller.dto;
package com.example.demo.controller.dto;
import lombok.Data;
@@ -6,7 +6,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Data
public class OrdersDTO {

View File

@@ -1,4 +1,4 @@
package com.autogen.example.controller.dto;
package com.example.demo.controller.dto;
import lombok.Data;
@@ -6,7 +6,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Data
public class PersonphoneDTO {

View File

@@ -1,4 +1,4 @@
package com.autogen.example.controller.dto;
package com.example.demo.controller.dto;
import lombok.Data;
@@ -6,7 +6,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Data
public class UsersDTO {

View File

@@ -0,0 +1,25 @@
package com.example.demo.model;
import lombok.Data;
import javax.persistence.*;
@Data
@Entity
@Table(name = "books")
public class Books {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "\"book_id\"", nullable = false)
private Integer bookId;
@Column(name = "\"title\"", nullable = false)
private String title;
@Column(name = "\"author\"", nullable = false)
private String author;
@Column(name = "\"isbn\"", nullable = false)
private String isbn;
@Column(name = "\"year\"", nullable = false)
private Integer year;
}

View File

@@ -0,0 +1,27 @@
package com.example.demo.model;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
@Data
@Entity(name = "com.gae.piaz.autogen.entities.Carts")
@Table(name = "carts")
@IdClass(Carts.PrimaryKeys.class)
public class Carts {
@Data
public static class PrimaryKeys implements Serializable {
private Integer userId;
private Integer bookId;
}
@Id
@Column(name = "\"user_id\"", nullable = false)
private Integer userId;
@Id
@Column(name = "\"book_id\"", nullable = false)
private Integer bookId;
@Column(name = "\"quantity\"", nullable = false)
private Integer quantity;
}

View File

@@ -0,0 +1,22 @@
package com.example.demo.model;
import lombok.Data;
import javax.persistence.*;
@Data
@Entity(name = "com.gae.piaz.autogen.entities.Orders")
@Table(name = "orders")
public class Orders {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "\"order_id\"", nullable = false)
private Integer orderId;
@Column(name = "\"user_id\"", nullable = false)
private Integer userId;
@Column(name = "\"book_id\"", nullable = false)
private Integer bookId;
@Column(name = "\"quantity\"", nullable = false)
private Integer quantity;
}

View File

@@ -0,0 +1,22 @@
package com.example.demo.model;
import lombok.Data;
import javax.persistence.*;
import java.sql.Timestamp;
@Data
@Entity(name = "com.gae.piaz.autogen.entities.Personphone")
@Table(name = "personphone")
public class Personphone {
@Column(name = "\"businessentityid\"", nullable = false)
private Integer businessentityid;
@Id
@Column(name = "\"phonenumber\"", nullable = false)
private Integer phonenumber;
@Column(name = "\"phonenumbertypeid\"", nullable = false)
private Integer phonenumbertypeid;
@Column(name = "\"modifieddate\"", nullable = false)
private Timestamp modifieddate;
}

View File

@@ -0,0 +1,20 @@
package com.example.demo.model;
import lombok.Data;
import javax.persistence.*;
@Data
@Entity(name = "com.gae.piaz.autogen.entities.Users")
@Table(name = "users")
public class Users {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "\"user_id\"", nullable = false)
private Integer userId;
@Column(name = "\"first_name\"", nullable = false)
private String firstName;
@Column(name = "\"last_name\"", nullable = false)
private String lastName;
}

View File

@@ -1,11 +1,11 @@
package com.autogen.example.repository;
package com.example.demo.repository;
import com.autogen.example.model.Books;
import com.example.demo.model.Books;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Repository
public interface BooksRepository extends JpaRepository<Books, java.lang.Integer> {

View File

@@ -1,11 +1,11 @@
package com.autogen.example.repository;
package com.example.demo.repository;
import com.autogen.example.model.Carts;
import com.example.demo.model.Carts;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Repository
public interface CartsRepository extends JpaRepository<Carts, java.lang.Integer> {

View File

@@ -1,11 +1,11 @@
package com.autogen.example.repository;
package com.example.demo.repository;
import com.autogen.example.model.Orders;
import com.example.demo.model.Orders;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Repository
public interface OrdersRepository extends JpaRepository<Orders, java.lang.Integer> {

View File

@@ -1,11 +1,11 @@
package com.autogen.example.repository;
package com.example.demo.repository;
import com.autogen.example.model.Personphone;
import com.example.demo.model.Personphone;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Repository
public interface PersonphoneRepository extends JpaRepository<Personphone, java.lang.Integer> {

View File

@@ -1,11 +1,11 @@
package com.autogen.example.repository;
package com.example.demo.repository;
import com.autogen.example.model.Users;
import com.example.demo.model.Users;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Repository
public interface UsersRepository extends JpaRepository<Users, java.lang.Integer> {

View File

@@ -1,7 +1,7 @@
package com.autogen.example.service;
package com.example.demo.service;
import com.autogen.example.model.Books;
import com.autogen.example.repository.BooksRepository;
import com.example.demo.model.Books;
import com.example.demo.repository.BooksRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
@@ -10,7 +10,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Service
public class BooksService implements CrudService<Books,java.lang.Integer> {

View File

@@ -1,7 +1,7 @@
package com.autogen.example.service;
package com.example.demo.service;
import com.autogen.example.model.Carts;
import com.autogen.example.repository.CartsRepository;
import com.example.demo.model.Carts;
import com.example.demo.repository.CartsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
@@ -10,7 +10,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Service
public class CartsService implements CrudService<Carts,java.lang.Integer> {

View File

@@ -1,10 +1,10 @@
package com.autogen.example.service;
package com.example.demo.service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
public interface CrudService<E,P> {

View File

@@ -1,7 +1,7 @@
package com.autogen.example.service;
package com.example.demo.service;
import com.autogen.example.model.Orders;
import com.autogen.example.repository.OrdersRepository;
import com.example.demo.model.Orders;
import com.example.demo.repository.OrdersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
@@ -10,7 +10,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Service
public class OrdersService implements CrudService<Orders,java.lang.Integer> {

View File

@@ -1,7 +1,7 @@
package com.autogen.example.service;
package com.example.demo.service;
import com.autogen.example.model.Personphone;
import com.autogen.example.repository.PersonphoneRepository;
import com.example.demo.model.Personphone;
import com.example.demo.repository.PersonphoneRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
@@ -10,7 +10,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Service
public class PersonphoneService implements CrudService<Personphone,java.lang.Integer> {

View File

@@ -1,7 +1,7 @@
package com.autogen.example.service;
package com.example.demo.service;
import com.autogen.example.model.Users;
import com.autogen.example.repository.UsersRepository;
import com.example.demo.model.Users;
import com.example.demo.repository.UsersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
@@ -10,7 +10,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Service
public class UsersService implements CrudService<Users,java.lang.Integer> {

View File

@@ -0,0 +1,17 @@
package com.example.demo.service.mapper;
import com.example.demo.model.Books;
import com.example.demo.controller.dto.BooksDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Mapper(componentModel = "spring")
public interface BooksMapper {
Books toEntity(BooksDTO dto);
BooksDTO toDto(Books entity);
}

View File

@@ -0,0 +1,17 @@
package com.example.demo.service.mapper;
import com.example.demo.model.Carts;
import com.example.demo.controller.dto.CartsDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Mapper(componentModel = "spring")
public interface CartsMapper {
Carts toEntity(CartsDTO dto);
CartsDTO toDto(Carts entity);
}

View File

@@ -0,0 +1,17 @@
package com.example.demo.service.mapper;
import com.example.demo.model.Orders;
import com.example.demo.controller.dto.OrdersDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Mapper(componentModel = "spring")
public interface OrdersMapper {
Orders toEntity(OrdersDTO dto);
OrdersDTO toDto(Orders entity);
}

View File

@@ -0,0 +1,17 @@
package com.example.demo.service.mapper;
import com.example.demo.model.Personphone;
import com.example.demo.controller.dto.PersonphoneDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Mapper(componentModel = "spring")
public interface PersonphoneMapper {
Personphone toEntity(PersonphoneDTO dto);
PersonphoneDTO toDto(Personphone entity);
}

View File

@@ -0,0 +1,17 @@
package com.example.demo.service.mapper;
import com.example.demo.model.Users;
import com.example.demo.controller.dto.UsersDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 28 ott 2020, 15:31:03
*/
@Mapper(componentModel = "spring")
public interface UsersMapper {
Users toEntity(UsersDTO dto);
UsersDTO toDto(Users entity);
}

View File

@@ -0,0 +1,12 @@
projectPath: /home/tano/workspace_autogenerate/demo
outputDirectory : /src/main/java
options:
dtoLayer : true
inputPackages:
jpaEntities : com.example.demo.model
outputPackages:
repositories : com.example.demo.repository
services: com.example.demo.service
controllers: com.example.demo.controller

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,13 @@
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DemoApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -1 +1 @@
rootProject.name = 'springboot-3layer-generator'
rootProject.name = 'layer3gen'

View File

@@ -1,13 +0,0 @@
package com.autogen.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AutogenExampleApplication {
public static void main(String[] args) {
SpringApplication.run(AutogenExampleApplication.class, args);
}
}

View File

@@ -1,17 +0,0 @@
package com.autogen.example.service.mapper;
import com.autogen.example.model.Books;
import com.autogen.example.controller.dto.BooksDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
*/
@Mapper(componentModel = "spring")
public interface BooksMapper {
Books toEntity(BooksDTO dto);
BooksDTO toDto(Books entity);
}

View File

@@ -1,17 +0,0 @@
package com.autogen.example.service.mapper;
import com.autogen.example.model.Carts;
import com.autogen.example.controller.dto.CartsDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
*/
@Mapper(componentModel = "spring")
public interface CartsMapper {
Carts toEntity(CartsDTO dto);
CartsDTO toDto(Carts entity);
}

View File

@@ -1,17 +0,0 @@
package com.autogen.example.service.mapper;
import com.autogen.example.model.Orders;
import com.autogen.example.controller.dto.OrdersDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
*/
@Mapper(componentModel = "spring")
public interface OrdersMapper {
Orders toEntity(OrdersDTO dto);
OrdersDTO toDto(Orders entity);
}

View File

@@ -1,17 +0,0 @@
package com.autogen.example.service.mapper;
import com.autogen.example.model.Personphone;
import com.autogen.example.controller.dto.PersonphoneDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
*/
@Mapper(componentModel = "spring")
public interface PersonphoneMapper {
Personphone toEntity(PersonphoneDTO dto);
PersonphoneDTO toDto(Personphone entity);
}

View File

@@ -1,17 +0,0 @@
package com.autogen.example.service.mapper;
import com.autogen.example.model.Users;
import com.autogen.example.controller.dto.UsersDTO;
import org.mapstruct.Mapper;
/**
* Generated by Springboot-3layer-Generator at 27 ott 2020, 19:52:19
*/
@Mapper(componentModel = "spring")
public interface UsersMapper {
Users toEntity(UsersDTO dto);
UsersDTO toDto(Users entity);
}

View File

@@ -1,47 +1,40 @@
package gae.piaz.spring3layergen;
package gae.piaz.layer3gen;
import freemarker.template.TemplateException;
import gae.piaz.spring3layergen.config.CodeGeneratorConfig;
import gae.piaz.layer3gen.config.CodeGeneratorConfig;
import lombok.extern.slf4j.Slf4j;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSetContainer;
import org.reflections.Reflections;
import org.reflections.scanners.FieldAnnotationsScanner;
import org.reflections.util.ConfigurationBuilder;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
@Slf4j
public class Main {
public class CodeGenerator {
private static CodeGeneratorConfig config;
public static void main(String[] args) throws Exception {
public static Project project;
log.info("Starting generation");
run(args);
log.info("Finished generation");
public static void run(CodeGeneratorConfig arg, Project arg2) throws Exception {
}
config = arg;
project = arg2;
public static void run(String[] args) throws Exception {
if(args == null || args.length==0) {
throw new Exception("missing argument path for configuration file");
}
config = CodeGeneratorConfig.load(args[0]);
log.debug("starting configuration: {}",config);
Reflections reflections = new Reflections(config.getInputPackages().getJpaEntities());
Set<Class<?>> entities = reflections.getTypesAnnotatedWith(javax.persistence.Entity.class);
Set<Class<?>> entities = getEntityClasses();
log.debug("found {} entities",entities.size());
createCrudInterfaces();
@@ -59,6 +52,22 @@ public class Main {
}
}
private static Set<Class<?>> getEntityClasses() throws MalformedURLException {
List<URL> listOfURL = new ArrayList<>();
SourceSetContainer ssc = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
FileCollection classesDir = ssc.getByName("main").getOutput().getClassesDirs();
for (File file : classesDir) {
listOfURL.add(file.toURI().toURL());
}
ClassLoader classLoader = new java.net.URLClassLoader(listOfURL.toArray(new URL[0]));
Reflections reflections = new Reflections(config.getInputPackages().getJpaEntities(), classLoader);
return reflections.getTypesAnnotatedWith(javax.persistence.Entity.class);
}
private static void createControllerDTO(Class<?> entity) throws IOException, TemplateException {
CodeRenderer.RenderingData data = new CodeRenderer.RenderingData();
@@ -172,30 +181,26 @@ public class Main {
log.debug("path: {}, code: {}", path, code);
}
private static String getPrimaryKeyClass(Class<?> entity) {
Set<Field> ids = findFields(entity, List.of(javax.persistence.Id.class,javax.persistence.EmbeddedId.class));
private static String getPrimaryKeyClass(Class<?> entity) throws MalformedURLException {
List<URL> listOfURL = new ArrayList<>();
SourceSetContainer ssc = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
FileCollection classesDir = ssc.getByName("main").getOutput().getClassesDirs();
for (File file : classesDir) {
listOfURL.add(file.toURI().toURL());
}
ClassLoader classLoader = new java.net.URLClassLoader(listOfURL.toArray(new URL[0]));
Reflections reflections = new Reflections(entity, classLoader, new FieldAnnotationsScanner());
Set<Field> ids = reflections.getFieldsAnnotatedWith(javax.persistence.Id.class);
if(ids.isEmpty()){
System.err.println("No @Id found for "+entity+" using generic object \"?\" ");
return "?";
ids = reflections.getFieldsAnnotatedWith(javax.persistence.EmbeddedId.class);
if(ids.isEmpty()) {
log.warn("No @Id found for " + entity + " using generic object \"Object\" ");
return "Object";
}
}
return ids.stream().findFirst().get().getType().getName();
}
public static Set<Field> findFields(Class<?> clasz, List<Class<? extends Annotation>> anns) {
Set<Field> set = new HashSet<>();
Class<?> c = clasz;
while (c != null) {
for (Field field : c.getDeclaredFields()) {
for (Class<? extends Annotation> ann : anns) {
if (field.isAnnotationPresent(ann)) {
set.add(field);
}
}
}
c = c.getSuperclass();
}
return set;
}
}

View File

@@ -1,4 +1,4 @@
package gae.piaz.spring3layergen;
package gae.piaz.layer3gen;
import freemarker.cache.StringTemplateLoader;
import freemarker.ext.beans.BeansWrapper;
@@ -6,12 +6,11 @@ import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import gae.piaz.spring3layergen.config.CodeGeneratorConfig;
import gae.piaz.layer3gen.config.CodeGeneratorConfig;
import lombok.Data;
import java.io.*;
import java.lang.reflect.Field;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

View File

@@ -1,4 +1,4 @@
package gae.piaz.spring3layergen;
package gae.piaz.layer3gen;
import java.io.File;
import java.io.FileInputStream;

View File

@@ -1,6 +1,6 @@
package gae.piaz.spring3layergen.config;
package gae.piaz.layer3gen.config;
import gae.piaz.spring3layergen.ResourceReader;
import gae.piaz.layer3gen.ResourceReader;
import lombok.Data;
import org.yaml.snakeyaml.Yaml;

View File

@@ -1,4 +1,4 @@
package gae.piaz.spring3layergen.config;
package gae.piaz.layer3gen.config;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package gae.piaz.spring3layergen.config;
package gae.piaz.layer3gen.config;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package gae.piaz.spring3layergen.config;
package gae.piaz.layer3gen.config;
import lombok.Data;

View File

@@ -0,0 +1,10 @@
package gae.piaz.layer3gen.gradle;
import lombok.Data;
@Data
public class Layer3GenExtension {
private String configPath = "3layer-settings.yml";
}

View File

@@ -0,0 +1,20 @@
package gae.piaz.layer3gen.gradle;
import gae.piaz.layer3gen.CodeGenerator;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
/**
* entityGen Gradle plugin.
*/
public class Layer3GenPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.getExtensions().create("layer3gen", Layer3GenExtension.class);
Task task = project.getTasks().create("layer3gen", Layer3GenTask.class);
org.gradle.api.Task javaCompile = project.getTasks().getByName("compileJava");
task.dependsOn(javaCompile);
}
}

View File

@@ -0,0 +1,23 @@
package gae.piaz.layer3gen.gradle;
import gae.piaz.layer3gen.CodeGenerator;
import gae.piaz.layer3gen.config.CodeGeneratorConfig;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
/**
* entityGen Gradle task.
*/
public class Layer3GenTask extends DefaultTask {
@TaskAction
public void generateAll() throws Exception {
Layer3GenExtension ext = getProject().getExtensions().getByType(Layer3GenExtension.class);
if (ext == null) {
ext = new Layer3GenExtension();
}
CodeGeneratorConfig config = CodeGeneratorConfig.load(ext.getConfigPath());
CodeGenerator.run(config,getProject());
}
}

View File

@@ -0,0 +1,13 @@
package gae.piaz.layer3gen.main;
import gae.piaz.layer3gen.CodeGenerator;
import gae.piaz.layer3gen.config.CodeGeneratorConfig;
public class Main {
public static void main(String[] args) throws Exception {
CodeGeneratorConfig config = CodeGeneratorConfig.load(args[0]);
CodeGenerator.run(config,null);
}
}