Skip to content

Latest commit

 

History

History
101 lines (80 loc) · 3.67 KB

13-Template.md

File metadata and controls

101 lines (80 loc) · 3.67 KB

⌂ Catalog
⇦ Previous section 12 - Job Scheduler       ⇨ Next section 14 - Web Context bean

13 - Template

Introduction

bambooBSC template model.

You must first understand the following framework

  1. Spring http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/
  2. Apache FreeMarker http://freemarker.org/

Create template resource

create a template resource. Image of BPMN-res-mgr1

Image of BPMN-res-mgr1

Settings variable mapper.
Image of BPMN-res-mgr1

Example java code:

TemplateResultObj tplResultObj = TemplateUtils.getResult("TPL-MSG-77", vision);

Full code:

@ServiceMethodAuthority(type={ServiceMethodType.INSERT})
@Transactional(
		propagation=Propagation.REQUIRED, 
		readOnly=false,
		rollbackFor={RuntimeException.class, IOException.class, Exception.class} )			
@Override
public DefaultResult<VisionVO> create(VisionVO vision) throws ServiceException, Exception {
	if (null == vision) {
		throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
	}
	if ( !SimpleUtils.checkBeTrueOf_azAZ09(4, 14, vision.getVisId()) ) { // for import-mode from csv file VIS_ID is old(before id).			
		vision.setVisId( this.findForMaxVisId(SimpleUtils.getStrYMD("")) );
	}				
		
		
	/**
	 * TEST Template : TPL-MSG-77
	 */
	TemplateResultObj tplResultObj = TemplateUtils.getResult("TPL-MSG-77", vision);
	
	MailClientUtils.send(
			"root@localhost", 
			"chen.xin.nien@gmail.com", 
			tplResultObj.getTitle(), 
			tplResultObj.getContent());
		
		
	return this.visionService.saveObject(vision);
}

Test result

The test use sendmail to send template result content. Image of BPMN-res-mgr1

TemplateUtils

TemplateUtils is bambooBSC template util.

Name return description
getResult(String templateId, Object dataObj) TemplateResultObj do template from resource, templateId is template-Id, dataObj is value object
getResourceSrc(ClassLoader classLoader, String metaInfFile) String get FreeMarker ftl resource content, classLoader ClassLoader, metaInfFile resource on META-INF fullpath
processTemplate(String name, ClassLoader classLoader, String templateResource, Map<String, Object> parameter) String do template from resource, name this event name, classLoader ClassLoader, templateResource resource on META-INF fullpath, parameter is Map<String, Object> param put template need variable's value


processTemplate(String name, ClassLoader classLoader, String templateResource, Map<String, Object> parameter) Example:

Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("labels", labels);
paramMap.put("searchDatas", this.searchDatas);
this.gridContent = TemplateUtils.processTemplate(
		"resourceTemplate", 
		QueryDataUtils.class.getClassLoader(), 
		"META-INF/resource/data-query-grid.ftl", 
		paramMap);