Migration from Ontimize 1.x.x to 3.x.x

Introduction

In this tutorial we are going to explain how to migrate a project from Ontimize version 1.x.x that works with JDK 8 to Ontimize version 3.x.x that works with JDK 11. For this example we will download a project like the explained in this training course.

Prerequisites

You can follow this tutorial using your own application, although for this example we will use an application created using the archetype that can be found on this page and with a REST service.

There are 2 options to follow this tutorial, clone the repository with the initial state and follow the tutorial step by step, or download the final example and see which files are new and which have been updated.

Initial project

/$ git clone https://github.com/ontimize/ontimize-examples 
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-migration-3.x.x-initial

Final example

/$ git clone https://github.com/ontimize/ontimize-examples 
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-migration-3.x.x

Note: To simplify the code being written, three dots (…) may appear in some parts of the code. This indicates that there may be previous code before and after those dots.

Steps

Ontimize version

First of all we need to update the version of Ontimize (ontimize-boot-parent) located in the parent of the project. Use always the latest version: Ontimize Boot Parent

  • ontimize-examples
    • hr-api
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IMasterService.java
                        • IOfferService.java
                        • IUserService.java
      • pom.xml
    • hr-boot
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • hr-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • hr
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • EducationDao.java
                        • ExperienceLevelDao.java
                        • OfferCandidatesDao.java
                        • OfferCandidateStatusDao.java
                        • OfferDao.java
                        • OfferStatusDao.java
                        • OriginDao.java
                        • ProfileDao.java
                        • StatusDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • MasterService.java
                        • OfferService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • EducationDao.xml
              • ExperienceLevelDao.xml
              • OfferCandidatesDao.xml
              • OfferCandidateStatusDao.xml
              • OfferDao.xml
              • OfferStatusDao.xml
              • OriginDao.xml
              • placeholders.properties
              • ProfileDao.xml
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • StatusDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • hr-ws
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • MasterRestController.java
                        • OfferRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

pom.xml

  <parent>
    <groupId>com.ontimize.boot</groupId>
    <artifactId>ontimize-boot-parent</artifactId>
    <version>3.x.x</version>
  </parent>

Java version

In the project properties we will change the java version from 1.8 to 11, both for the main pom.xml and for the hr-model module pom.xml.

  • ontimize-examples
    • hr-api
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IMasterService.java
                        • IOfferService.java
                        • IUserService.java
      • pom.xml
    • hr-boot
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • hr-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • hr
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • EducationDao.java
                        • ExperienceLevelDao.java
                        • OfferCandidatesDao.java
                        • OfferCandidateStatusDao.java
                        • OfferDao.java
                        • OfferStatusDao.java
                        • OriginDao.java
                        • ProfileDao.java
                        • StatusDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • MasterService.java
                        • OfferService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • EducationDao.xml
              • ExperienceLevelDao.xml
              • OfferCandidatesDao.xml
              • OfferCandidateStatusDao.xml
              • OfferDao.xml
              • OfferStatusDao.xml
              • OriginDao.xml
              • placeholders.properties
              • ProfileDao.xml
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • StatusDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • hr-ws
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • MasterRestController.java
                        • OfferRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

pom.xml

  <properties>
    . . .
    <java.version>11</java.version>
    . . .
  </properties>

Modifying application.yml

In the new version of Ontimize Boot, it has been decided to change the properties from camelCase to kebab-case, so you have to modify the application.yml.

endpoints:
   api:
      enabled: true
logging:
   level:
      root: info
ontimize:
   corsfilter:
      enabled: true
   globalcors:
      cors-configurations:
         '[/**]':
            allowed-origins: "*"
            allowed-headers: "*"
            exposed-headers: ["X-Auth-Token","Content-disposition","X-Requested-With"]
            allowed-methods:
            - GET
            - POST
            - PUT
            - OPTIONS
            - DELETE
   jdbc:
      name-convention: upper
      sqlhandler: hsqldb
      sql-condition-processor:
         uppper-string: true
         upper-like: true
   security:
      mode: default
      ignore-paths: /app/**
      role-information-service:
         role-repository: UserRoleDao
         role-name-column: ROLENAME
         server-permission-query-id: serverPermissions
         server-permission-name-column: PERMISSION_NAME
         client-permission-query-id: clientPermissions
         client-permission-column: XMLCLIENTPERMISSION
      user-information-service:
         user-repository: UserDao
         user-login-column: USER_
         user-password-column: PASSWORD
         query-id: login
         other-data:
            - NAME
            - SURNAME
            - EMAIL
            - NIF
            - USERBLOCKED
            - LASTPASSWORDUPDATE
            - FIRSTLOGIN
      user-role-information-service:
         user-role-repository: UserRoleDao
         query-id: userRole
         role-login-column: USER_
         role-name-column: ROLENAME
server:
   port: 33333
   tomcat:
      uri-encoding: UTF-8
   compression:
      enabled: true
      mime-types: application/json, application/xml
spring:
   datasource:
      driver-class-name: org.hsqldb.jdbcDriver
      jdbc-url: jdbc:hsqldb:hsql://localhost:9013/templateDB
      username: SA
      password:
      initial-size: 10
      test-on-borrow: true
   main:
      banner-mode: 'off'
   session:
      store-type: none
   autoconfigure:
      exclude: |
         org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration, org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration, org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration

Renaming packages

With the new version, the ontimize-core library has been merged with ontimize-jee, and some classes have changed the name of their package, among them, the EntityResult Interface. To learn more about this class, check the following link.

The package name of EntityResult has been renamed from com.ontimize.db.EntityResult to com.ontimize.jee.common.dto.EntityResult.

Api module

In the hr-api module we need to change the name of the package of this class in all the interfaces that are using it.

  • ontimize-examples
    • hr-api
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IMasterService.java
                        • IOfferService.java
                        • IUserService.java
      • pom.xml
    • hr-boot
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • hr-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • hr
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • EducationDao.java
                        • ExperienceLevelDao.java
                        • OfferCandidatesDao.java
                        • OfferCandidateStatusDao.java
                        • OfferDao.java
                        • OfferStatusDao.java
                        • OriginDao.java
                        • ProfileDao.java
                        • StatusDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • MasterService.java
                        • OfferService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • EducationDao.xml
              • ExperienceLevelDao.xml
              • OfferCandidatesDao.xml
              • OfferCandidateStatusDao.xml
              • OfferDao.xml
              • OfferStatusDao.xml
              • OriginDao.xml
              • placeholders.properties
              • ProfileDao.xml
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • StatusDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • hr-ws
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • MasterRestController.java
                        • OfferRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

ICandidateService.java

package com.ontimize.hr.api.core.service;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

public interface ICandidateService {

 // CANDIDATE

 public EntityResult candidateQuery(Map<String, Object> keyMap, List<String> attrList) throws OntimizeJEERuntimeException;
 public EntityResult candidateInsert(Map<String, Object> attrMap) throws OntimizeJEERuntimeException;
 public EntityResult candidateUpdate(Map<String, Object> attrMap, Map<String, Object> keyMap) throws OntimizeJEERuntimeException;
 public EntityResult candidateDelete(Map<String, Object> keyMap) throws OntimizeJEERuntimeException;

}

IMasterService.java

package com.ontimize.hr.api.core.service;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

public interface IMasterService {

    . . .
	 // EDUCATION

	 public EntityResult educationQuery(Map<String, Object> keyMap, List<String> attrList) throws OntimizeJEERuntimeException;
	 public EntityResult educationInsert(Map<String, Object> attrMap) throws OntimizeJEERuntimeException;
	 public EntityResult educationUpdate(Map<String, Object> attrMap, Map<String, Object> keyMap) throws OntimizeJEERuntimeException;
	 public EntityResult educationDelete(Map<String, Object> keyMap) throws OntimizeJEERuntimeException;
     . . .
}

IOfferService.java

package com.ontimize.hr.api.core.service;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

public interface IOfferService {

    . . .
	// OFFER

	public EntityResult offerQuery(Map<String, Object> keyMap, List<String> attrList) throws OntimizeJEERuntimeException;
	public EntityResult offerInsert(Map<String, Object> attrMap) throws OntimizeJEERuntimeException;
	public EntityResult offerUpdate(Map<String, Object> attrMap, Map<String, Object> keyMap) throws OntimizeJEERuntimeException;
	public EntityResult offerDelete(Map<String, Object> keyMap) throws OntimizeJEERuntimeException;
    . . .

}

IUserService.java

package com.ontimize.hr.api.core.service;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

public interface IUserService {

	public EntityResult userQuery(Map<?, ?> keyMap, List<?> attrList);
	public EntityResult userInsert(Map<?, ?> attrMap);
	public EntityResult userUpdate(Map<?, ?> attrMap, Map<?, ?> keyMap);
	public EntityResult userDelete(Map<?, ?> keyMap);

}

Model module

Having changed the class in the interface, we also have to change it in the service. For this we go to the hr-model module and replace the import of all services.

  • ontimize-examples
    • hr-api
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IMasterService.java
                        • IOfferService.java
                        • IUserService.java
      • pom.xml
    • hr-boot
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • hr-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • hr
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • EducationDao.java
                        • ExperienceLevelDao.java
                        • OfferCandidatesDao.java
                        • OfferCandidateStatusDao.java
                        • OfferDao.java
                        • OfferStatusDao.java
                        • OriginDao.java
                        • ProfileDao.java
                        • StatusDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • MasterService.java
                        • OfferService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • EducationDao.xml
              • ExperienceLevelDao.xml
              • OfferCandidatesDao.xml
              • OfferCandidateStatusDao.xml
              • OfferDao.xml
              • OfferStatusDao.xml
              • OriginDao.xml
              • placeholders.properties
              • ProfileDao.xml
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • StatusDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • hr-ws
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • MasterRestController.java
                        • OfferRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

CandidateService.java

package com.ontimize.hr.model.core.service;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

@Service("CandidateService")
@Lazy
public class CandidateService implements ICandidateService {

	@Autowired
	private CandidateDao candidateDao;
    . . .
}

MasterService.java

package com.ontimize.hr.model.core.service;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

@Service("MasterService")
@Lazy
public class MasterService implements MasterService {

	@Autowired
	private EducationDao educationDao;
    . . .
}

OfferService.java

package com.ontimize.hr.model.core.service;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

@Service("OfferService")
@Lazy
public class OfferService implements IOfferService {

	@Autowired
	private OfferDao offerDao;
    . . .
}

UserService.java

package com.ontimize.hr.model.core.service;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

@Lazy
@Service("UserService")
public class UserService implements IUserService {

	@Autowired
	private UserDao userDao;
    . . .
}

Ws module

In this case it is not just about changing the name of the package, it must also be taken into account that the EntityResult class is now an Interface, so an object cannot be instantiated from it. To do this, we will use the EntityResultMapImpl class.

Go to the hr-ws module and replace the import of the EntityResult class in the rest controllers and make the following changes:

  • ontimize-examples
    • hr-api
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IMasterService.java
                        • IOfferService.java
                        • IUserService.java
      • pom.xml
    • hr-boot
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • hr-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • hr
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • EducationDao.java
                        • ExperienceLevelDao.java
                        • OfferCandidatesDao.java
                        • OfferCandidateStatusDao.java
                        • OfferDao.java
                        • OfferStatusDao.java
                        • OriginDao.java
                        • ProfileDao.java
                        • StatusDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • MasterService.java
                        • OfferService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • EducationDao.xml
              • ExperienceLevelDao.xml
              • OfferCandidatesDao.xml
              • OfferCandidateStatusDao.xml
              • OfferDao.xml
              • OfferStatusDao.xml
              • OriginDao.xml
              • placeholders.properties
              • ProfileDao.xml
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • StatusDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • hr-ws
      • src
        • main
          • java
            • com
              • ontimize
                • hr
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • MasterRestController.java
                        • OfferRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

OfferRestController.java

package com.ontimize.hr.ws.core.rest;

. . .
import com.ontimize.jee.common.db.SQLStatementBuilder;
import com.ontimize.jee.common.db.SQLStatementBuilder.BasicExpression;
import com.ontimize.jee.common.db.SQLStatementBuilder.BasicField;
import com.ontimize.jee.common.db.SQLStatementBuilder.BasicOperator;
import com.ontimize.jee.common.dto.EntityResult;
import com.ontimize.jee.common.dto.EntityResultMapImpl;
. . .

@RestController
@RequestMapping("/offers")
@ComponentScan(basePackageClasses = { com.ontimize.hr.api.core.service.IOfferService.class })
public class OfferRestController extends ORestController<IOfferService> {

	. . .

	@RequestMapping(value = "currentOffers/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public EntityResult currentOffersSearch(@RequestBody Map<String, Object> req) {
		try {
			List<String> columns = (List<String>) req.get("columns");
			Map<String, Object> key = new HashMap<String, Object>();
			key.put(SQLStatementBuilder.ExtendedSQLConditionValuesProcessor.EXPRESSION_KEY,
					searchBetween(OfferDao.ATTR_START_DATE));
			return offerService.offerQuery(key, columns);
		} catch (Exception e) {
			e.printStackTrace();
			EntityResult res = new EntityResultMapImpl();
			res.setCode(EntityResult.OPERATION_WRONG);
			return res;
		}
	}

	@RequestMapping(value = "yearOffers/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public EntityResult yearOffersSearch(@RequestBody Map<String, Object> req) {
		try {
			List<String> columns = (List<String>) req.get("columns");
			Map<String, Object> filter = (Map<String, Object>) req.get("filter");
			int year = (int) filter.get("YEAR");
			Map<String, Object> key = new HashMap<String, Object>();
			key.put(SQLStatementBuilder.ExtendedSQLConditionValuesProcessor.EXPRESSION_KEY,
					searchBetweenWithYear(OfferDao.ATTR_START_DATE, year));
			return offerService.offerQuery(key, columns);
		} catch (Exception e) {
			e.printStackTrace();
			EntityResult res = new EntityResultMapImpl();
			res.setCode(EntityResult.OPERATION_WRONG);
			return res;
		}
	}

    . . .

}

UserRestController.java

package com.ontimize.hr.ws.core.rest;

. . .
import com.ontimize.jee.common.dto.EntityResult;
. . .

@RestController
@RequestMapping("/users")
public class UserRestController extends ORestController<IUserService> {

	. . .
	@RequestMapping(
		value = "/login",
		method = RequestMethod.POST,
		produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<EntityResult> login() {
		return new ResponseEntity<>(HttpStatus.OK);
	}
}