-
Notifications
You must be signed in to change notification settings - Fork 0
LocationServer
This is a server for location service
- controller : spring controller
- service : spring service
- converter : spring converter
- exception : spring exception handler and custom exceptions
- interceptor: spring interceptor
- task : spring task
- entity : hibernate orm entity
- data : internal processing data
controller handles all request so it should call corresponding service to fetch data based on the type of request. while all return values from service are in type of entity, we have to convert the data using converters. when finally receive all required data, those data will be returned to client in format of json.
@RequestMapping( value = "name/{name}" )
public Person[] getPersonLocationByName( @PathVariable( "name" ) String name ) {
return ( Person[] ) conversionService.convert(
personService.getPeople( name ),
TypeDescriptor.collection( List.class, TypeDescriptor.valueOf( PersonEntity.class ) ),
TypeDescriptor.array( TypeDescriptor.valueOf( Person.class ) )
);
}
there is another important thing: since we have to index the data for fuzzy search, it is necessary to update indexes periodly, this is executed by task.
@Scheduled( initialDelay = xxx, fixedDelay = xxx )
public void run() {
clearIndexes();
indexPlaces ();
indexPeople ();
indexUnits();
}
-
controller are all restfult controller and they are separated by api versions
-
service are simply divided into two types :
- database type: they all extend the
entityManagerContainer
so that they can use JPA to fetch data - index type : use indexer from lucene to manage data
- database type: they all extend the
-
exception contains a
ApplicationExceptionHandler
, this is a global spring exception handler, it can block all exception, log them and then return a readable message -
interceptor contains a
ApplicationInterceptor
, it can log all request message -
task contains a
IndexUpdateTask
, which use spring-task annotation to schedule the index update task