Service Layer - Create Service Example

The following example is using the Country Hibernate Object to perform a create action on the database(if you have not created the Hibernate Object click here). The developer has to define the Business Class and the xml that will plug it to the application

Normally you should receive from an analyst a descriptive document like the following

Name CountryCreateService
Package org.jprovocateur.archetype.businesslayer.country
Description Create a country service
Service Type CREATE
Transactional True
Input Object Country
InitMetadata Default
execute Default
Validate Default
Realization Default

The above table says, create a class with name CountryCreateService in a specific package with the default behavior.

Implementation of the Service

The implementation of the class is easy since only the default behavior is needed, just create the above class extending the BusinessLogic class

CountryCreateService .java
package org.jprovocateur.archetype.businesslayer.country;

import javax.annotation.Resource;

import org.jprovocateur.archetype.objectmodel.country.Country;
import org.jprovocateur.basis.datalayer.GenericDaoDBInt;
import org.jprovocateur.basis.serviceslayer.BusinessLogicInt;
import org.jprovocateur.basis.serviceslayer.impl.BusinessLogic;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;




@Service("countryCreateService")
@Scope("prototype")
@Transactional(readOnly = false)
public class CountryCreateService extends BusinessLogic{
	@Resource(name="genericDaoDB")
	private GenericDaoDBInt dao;
	
	public GenericDaoDBInt getDao() {
		return dao;
	}

	public String getExecutionType() {
		return BusinessLogicInt.CREATE;
	}	

}

Declaring the Service and defining Access Rights

In order to make the service available you have to register it in the database and defined its basic characteristics. All services are registered in table BC.

Column Value Description
CLASSNAME org.jprovocateur.archetype.businesslayer.country.CountryCreateService the class of the service
DISABLED 0 defines if the service is disabled, possible values 0(false)/1(true)
Defining the Access Rights

Security is based on roles. Each service are accessible only if the user has one of the configured roles. Jprovocateur is offering a web interface to manage user, roles, service and access rights.

    Important tables in the database are
  • Users:users of the application
  • Roles:roles configured in the application
  • UserRights:assigned roles to the user.
  • Access_Rights: Services and roles relation (which role can access which serice)
  • Service: Your services

 

JUnit Client Creation

The following JUnit class will run the service.

 
Design downloaded from free website templates.
 
Web Templates created with FlashMint. .