People Service Guide
What you'll build
You will build a simple service that allows managing people.
What you’ll need
A Java™ Development Kit (JDK) installed. We recommend AdoptOpenJDK version 11 or 8.
Apache Maven version 3.1 or later installed.
An Integrated Developer Environment (IDE)
Popular choices include IntelliJ IDEA, Spring Tools, Visual Studio Code, or Eclipse, and many more.
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
Create a new Maven Project with the following structure:
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.
Personobject inherits from
Baseclasssince we want to be able to govern permissions for it
copy persistence.xml content from here.
this will allow automatic generation of JPA metamodels required to implement Criteria API based queries.
./cp target/person-model-1.0.0-jar /home/flexiCore/entities
create a maven project with the following structure:
lets define objects that will be consumed by our api:
PersonCreate– this object will contain all required details for creating a person it will also inherit from
BaseclassCreateobject as we would like to extend
PersonUpdate– this object will extend
PersonCreateobject and id of the person to update
PersonFilter– this object will be sent by the client when fetching people containing filtering options.
lets define the repository that will be used to fetch and save people from database.
@Extensionannotation to allow FlexiCore to load it as a plugin
@PluginInfoannotation to allow future versioning support
@Componentannotation to let spring know it is a bean.
AbstractRepositoryPluginwhich provides easy method for access control and out of the box methods for persisting objects
addPersonPredicateswhich adds the required predicates , all access control predicates are automatically added when
addPersonPredicatesuses JPA Criteria Api to filter data based on
PersonFilterobject we have created in previous phase , it is empty as we currently have not specific filters.
lets define the service that will be used by other plugins and REST api (or any other API implementations for that matter)
lets define the REST service that will expose REST api that our clients will use: