Skip to content

Latest commit

 

History

History
151 lines (135 loc) · 5.47 KB

README.md

File metadata and controls

151 lines (135 loc) · 5.47 KB

FPI Framework

Maven Central version GitHub Workflow Status License GitHub commit activity Sonarcloud Status Duplicated Lines (%) Reliability Rating SonarCloud Bugs SonarCloud Vulnerabilities Security Rating Lines of Code

Importing the POM (choose 1 option)

As Parent POM

<parent>
  <!-- FPI Framework Parent POM -->
  <groupId>com.abavilla</groupId>
  <artifactId>fpi-framework-pom</artifactId>
  <version>1.1.1</version> <!-- replace with latest version -->
</parent>
<!-- As dependencies are defined in parent POM
 no need to add FPI Framework Core as a dependency -->

As BOM

<dependencyManagement>
  <dependency>
    <!-- FPI Framework BOM -->
    <groupId>com.abavilla</groupId>
    <artifactId>fpi-framework-bom</artifactId>
    <version>1.1.1</version> <!-- replace with latest version -->
    <type>pom</type>
    <scope>import</scope>
  </dependency>
</dependencyManagement>

<dependencies>
  <!-- FPI Framework Core dependency -->
  <dependency>
    <groupId>com.abavilla</groupId>
    <artifactId>fpi-framework-core</artifactId>
  </dependency>
</dependencies>

Sample Usage

Entity

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@BsonDiscriminator
@MongoEntity(collection="students")
public class Student extends AbsMongoItem {
  /** Student name */
  private String name;
  /** Student home address */
  private String address;
  /** Student gender */
  private String gender;

  // Getters and setters are generated by lombok
  // during compile time, no need to specify them
}

DTO (Data Transfer Object)

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class StudentDto extends AbsDto {
  /** Student name */
  private String name;
  /** Student gender */
  private String gender;
  
  // Getters and setters are generated by lombok
  // during compile time, no need to specify them
}

Repository

@ApplicationScoped
public class StudentRepo 
  extends AbsMongoRepo<Student> {
  // No need to specify a body as AbsMongoRepo
  // extends from Panache repository, and already
  // implements the basic CRUD methods
}

DTO to Entity Mapstruct Mapper

@Mapper(componentModel = MappingConstants.ComponentModel.CDI,
    injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface StudentMapper 
  extends IDtoToEntityMapper<StudentDto, Student> {
  // Mapstruct will generate the mappings during compile time,
  // and mo need to specify a body as IDtoToEntityMapper specifies
  // the commonly used mapping methods
}

Service Layer

@ApplicationScoped
public class StudentSvc
  // Alternatively, may extend with AbsRepoSvc if
  // you need a customized repository
  extends AbsSvc<StudentDto, Student> {
  /** Mapstruct Mapper */
  @Inject
  StudentMapper mapper;
  
  // Built in asynchronous (Mutiny) CRUD methods, all you 
  // have to specify are the mapping methods to convert
  // a DTO to entity and vice versa
  
  @Override
  public StudentDto mapToDto(Student entity) {
    return mapper.mapToDto(entity);
  }

  @Override
  public Student mapToEntity(StudentDto dto) {
    return mapper.mapToEntity(dto);
  }
}

REST Controller

@Path("/fpi/cx")
public class StudentResource
    // Alternatively, may extend from AbsBaseResource,
    // or AbsReadOnlyResource for specific use case scenarios 
    extends AbsResource<StudentDto, Student, StudentSvc> {
  // ...
  // Built in asynchronous (Mutiny) CRUD methods for GET, POST,
  // PATCH, DELETE are implemented by default, you may customize
  // or add your own methods for specific requirements
  // ...
}