People Service Guide

What you'll build

You will build a simple service that allows managing people.

What you’ll need

Development requirements

A Java™ Development Kit (JDK) installed. We recommend AdoptOpenJDK version 11 or 8.

Apache Maven version 3.1 or later installed.

Optional

An Integrated Developer Environment (IDE)

Popular choices include IntelliJ IDEA, Spring Tools, Visual Studio Code, or Eclipse, and many more.

Testing and running requirements

A FlexiCore based server running locally or on an accessible server.

One-click, no prerequisites installation is available for Linux (AMD64, ARM64) and Windows (AMD64) here 

A Docker image with fully installed FlexiCore and prerequisites is available here

Step 1: Person Model

Create a new Maven Project with the following structure:

People Model Project Structure

update your pom.xml from here

Step 1.a: Create Person Entity

Open up the project in your IDE and create the Person.java file in the src/main/java/com/flexicore/examples/person/model folder. Now change the contents of the file by adding the extra method and annotations shown in the code below. You can copy and paste the code or just type it.

  1. Our Person object inherits from Baseclass since we want to be able to govern permissions for it

Step 1.b: Create Persistence.xml

copy persistence.xml content from here.

this will allow automatic generation of JPA metamodels required to implement Criteria API based queries.

Step 1.c: install person model

./mvn install

./cp target/person-model-1.0.0-jar /home/flexiCore/entities

Step 2: Person Service

create a maven project with the following structure:

people service project structure

update your pom.xml from here

Step 2.a: Create Person service request objects2.a

lets define objects that will be consumed by our api:

  1. PersonCreate – this object will contain all required details for creating a person it will also inherit from BaseclassCreate object as we would like to extend Baseclass capabilities
  2. PersonUpdate – this object will extend PersonCreate object and id of the person to update
  3. PersonFilter – this object will be sent by the client when fetching people containing filtering options.

Step 2.b: Create Person Repository

lets define the repository that will be used to fetch and save people from database.

  1. the repository is annotated by
    •  @Extension annotation to allow FlexiCore to load it as a plugin 
    • @PluginInfo annotation to allow future versioning support
    • @Component annotation to let spring know it is a bean.
  2. the repository class extends AbstractRepositoryPlugin which provides easy method for access control and out of the box methods for persisting objects
  3. the repository exposes methods for listing and counting people both are calling the addPersonPredicates which adds the required predicates , all access control predicates are automatically added when countAllFiltered and getAllFiltered are called
  4. addPersonPredicates uses JPA Criteria Api to filter data based on PersonFilter object we have created in previous phase , it is empty as we currently have not specific filters.

Step 2.c: Create Person Service

lets define the service that will be used by other plugins and REST api (or any other API implementations for that matter)

Step 2.d: Create Person REST Service

lets define the REST service that will expose REST api that our clients will use: