gt: 			if( orgIdList == null ) {
context: /*
   * Created on 27 Jul 2015 ( Time 15:58:02 )
   * Generated by Telosys Tools Generator ( version 2.1.0 )
   */
  package com.abm.mainet.common.master.service;
  
  import java.io.IOException;
  import java.lang.reflect.InvocationTargetException;
  import java.net.URISyntaxException;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Set;
  
  import javax.annotation.Resource;
  
  import org.apache.commons.beanutils.BeanUtils;
  import org.apache.log4j.Logger;
  import org.codehaus.jackson.JsonGenerationException;
  import org.codehaus.jackson.map.JsonMappingException;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.ResponseEntity;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.abm.mainet.common.constant.MainetConstants;
  import com.abm.mainet.common.domain.Department;
  import com.abm.mainet.common.domain.DeptOrgMap;
  import com.abm.mainet.common.domain.Designation;
  import com.abm.mainet.common.domain.Employee;
  import com.abm.mainet.common.domain.GroupMaster;
  import com.abm.mainet.common.domain.LocationMasEntity;
  import com.abm.mainet.common.domain.Organisation;
  import com.abm.mainet.common.domain.SystemModuleFunction;
  import com.abm.mainet.common.domain.TbComparamDetEntity;
  import com.abm.mainet.common.domain.TbComparamMasEntity;
  import com.abm.mainet.common.domain.TbComparentMasEntity;
  import com.abm.mainet.common.entitlement.domain.RoleEntitlement;
  import com.abm.mainet.common.integration.dto.WSRequestDTO;
  import com.abm.mainet.common.master.dto.DesignationBean;
  import com.abm.mainet.common.master.dto.TbComparamDet;
  import com.abm.mainet.common.master.dto.TbComparentMas;
  import com.abm.mainet.common.master.dto.TbDeporgMap;
  import com.abm.mainet.common.master.dto.TbDeptLocation;
  import com.abm.mainet.common.master.dto.TbFinancialyear;
  import com.abm.mainet.common.master.dto.TbFincialyearorgMap;
  import com.abm.mainet.common.master.dto.TbOrgDesignation;
  import com.abm.mainet.common.master.dto.TbOrganisation;
  import com.abm.mainet.common.master.dto.TbOrganisationRest;
  import com.abm.mainet.common.master.dto.TbServicesMst;
  import com.abm.mainet.common.master.mapper.TbComparamMasServiceMapper;
  import com.abm.mainet.common.master.mapper.TbDeporgMapServiceMapper;
  import com.abm.mainet.common.master.mapper.TbOrganisationAddDetServiceMapper;
  import com.abm.mainet.common.master.mapper.TbOrganisationServiceMapper;
  import com.abm.mainet.common.master.repository.TbOrganisationJpaRepository;
  import com.abm.mainet.common.service.IEmployeeService;
  import com.abm.mainet.common.service.ILocationMasService;
  import com.abm.mainet.common.service.IOrganisationService;
  import com.abm.mainet.common.service.TbComparamDetService;
  import com.abm.mainet.common.service.TbComparamMasService;
  import com.abm.mainet.common.service.TbComparentMasService;
  import com.abm.mainet.common.utility.ApplicationSession;
  import com.abm.mainet.common.utility.CommonMasterUtility;
  import com.abm.mainet.common.utility.LookUp;
  import com.abm.mainet.common.utility.RestClient;
  import com.abm.mainet.common.utility.UserSession;
  import com.abm.mainet.common.utility.Utility;
  import com.fasterxml.jackson.core.type.TypeReference;
  import com.fasterxml.jackson.databind.util.BeanUtil;
  import com.mchange.v2.codegen.bean.BeangenUtils;
  
  
  /**
   * Implementation of TbOrganisationService
   */
  @Service
  public class TbOrganisationServiceImpl implements TbOrganisationService {
  
  	@Resource
  	private TbOrganisationJpaRepository tbOrganisationJpaRepository;
  	
  	@Resource
  	private TbOrganisationServiceMapper tbOrganisationServiceMapper;
  	
  	@Resource
  	TbOrganisationAddDetServiceMapper tbOrganisationAddDetServiceMapper;
  	
  	@Resource
  	private TbDeporgMapServiceMapper tbDeporgMapServiceMapper;
  
  	@Resource
  	private TbComparamMasServiceMapper tbComparamMasServiceMapper;
  
  	@Resource
  	private ILocationMasService locationMasService;
  
  	@Resource
  	private SysmodfunctionService sysmodfunctionService;
  
  	@Autowired
  	private DesignationService designationService;
  
  	@Resource
  	private TbDepartmentService tbDepartmentService;
  
  	@Resource
  	private TbDeporgMapService tbDeporgMapService;
  
  	@Resource
  	private GroupMasterService groupMasService;
  
  	@Resource
  	private IEmployeeService employeeService;
  
  	@Resource
  	private TbOrgDesignationService tbOrgDesignationService;
  
  	@Autowired
  	private IOrganisationService organisationService;
  
  	@Resource
  	private TbComparamMasService tbComparamMasService;
  
  	@Resource
  	private TbComparamDetService tbComparamDetService;
  
  	@Resource
  	private TbComparentMasService tbComparentMasService;
  	
  	@Resource
  	private DeptLocationService deptLocationService;
  	
  	@Resource 
  	TbServicesMstService tbServicesMstService;
  	
  	@Resource
  	private TbFinancialyearService tbFinancialyearService;
  	
  	@Resource
  	private TbFinancialyearOrgMapService tbFinancialyearOrgMapService;
  	
  	private static Logger logger = Logger.getLogger(TbOrganisationServiceImpl.class);
  	
  	@Override
  	@Transactional
  	public TbOrganisation findById(Long orgid) {
  		Organisation tbOrganisationEntity = tbOrganisationJpaRepository.findOne(orgid);
  		return tbOrganisationServiceMapper.mapTbOrganisationEntityToTbOrganisation(tbOrganisationEntity);
  	}
  
  	@Override
  	@Transactional
  	public List<TbOrganisation> findAll() {
  		List<Organisation> entities = tbOrganisationJpaRepository.findActiveOrgList();
  		List<TbOrganisation> beans = new ArrayList<TbOrganisation>();
  		for(Organisation tbOrganisationEntity : entities) {
  			beans.add(tbOrganisationServiceMapper.mapTbOrganisationEntityToTbOrganisation(tbOrganisationEntity));
  		}
  		return beans;
  	}
  
  	@Override
  	@Transactional
  	public TbOrganisation create(TbOrganisation tbOrganisation,ApplicationSession appSession,UserSession userSession) throws JsonGenerationException, JsonMappingException, URISyntaxException, IOException, IllegalAccessException, InvocationTargetException{
  		
  		logger.info("Create new organisation execution starts.");
  		
  		Employee sessionEmp = userSession.getEmployee();
  		int sessionLangId = userSession.getLanguageId();
  		
  		GroupMaster groupMasterSaved =null;
  		LocationMasEntity tbLocationMasEntitySaved = null;
  		Organisation orgSession = UserSession.getCurrent().getOrganisation();
  		
  		Organisation organisationEntity=new Organisation();
  		tbOrganisation.setOrgStatus(appSession.getMessage("organisation.status"));
  		tbOrganisation.setOrgStatus(MainetConstants.STATUS.ACTIVE);
  		tbOrganisationServiceMapper.mapTbOrganisationToTbOrganisationEntity(tbOrganisation, organisationEntity);
  
  		Organisation tbOrganisationEntitySaved = tbOrganisationJpaRepository.save(organisationEntity);
  
  		LocationMasEntity tbLocationMasEntity = new LocationMasEntity();
  		tbLocationMasEntity.setLocNameEng(appSession.getMessage("location.LocNameEng"));
  		tbLocationMasEntity.setLocNameReg(appSession.getMessage("location.LocNameReg"));
  		tbLocationMasEntity.setLocArea(appSession.getMessage("location.LocArea"));
  		tbLocationMasEntity.setLocAddress(appSession.getMessage("location.LocAddress"));
  		tbLocationMasEntity.setDeptLoc('Y');
  		tbLocationMasEntity.setUserId(sessionEmp.getEmpId());
  		tbLocationMasEntity.setLangId(sessionLangId);
  		tbLocationMasEntity.setLocSource("O");
  		tbLocationMasEntity.setLocActive(MainetConstants.Common_Constant.YES);
  		tbLocationMasEntity.setLmoddate(new Date());
  		tbLocationMasEntity.setOrganisation(tbOrganisationEntitySaved);
  		tbLocationMasEntitySaved = locationMasService.createDefaultLocationMas(tbLocationMasEntity,organisationEntity);
  
  		List<SystemModuleFunction> sysModFunctionList = sysmodfunctionService.
  				findBySmfaction(appSession.getMessage("systemmodulefunction.smfaction"),appSession.getMessage("systemmodulefunction.smfname"));
  
  		GroupMaster groupMasEntity = new GroupMaster();
  		groupMasEntity.setOrgId(tbOrganisationEntitySaved);
  		groupMasEntity.setGrCode(appSession.getMessage("groupmaster.GrCode"));
  		groupMasEntity.setGrDescEng(appSession.getMessage("groupmaster.GrDescEng"));
  		groupMasEntity.setGrDescReg(appSession.getMessage("groupmaster.GrDescReg"));
  		groupMasEntity.setGrStatus(MainetConstants.Common_Constant.ACTIVE_FLAG);
  		groupMasEntity.setLangId(sessionLangId);
  		groupMasEntity.setUpdatedDate(new Date());
  		groupMasEntity.setUpdatedBy(sessionEmp);
  		groupMasEntity.setUserId(sessionEmp);
  
  		RoleEntitlement roleEntitlement =null;
  		Set<RoleEntitlement> entitlementSet= new HashSet<RoleEntitlement>();
  		for(SystemModuleFunction sysmodFunction: sysModFunctionList){
  			roleEntitlement = new RoleEntitlement();
              if(sysmodFunction.getModuleFunction()==null){
  				roleEntitlement.setParentId(Long.valueOf(0));
  			}else{
  				roleEntitlement.setParentId(Long.valueOf(1));
  			} 
  			roleEntitlement.setEntitle(sysmodFunction);
  			roleEntitlement.setIsActive(MainetConstants.Common_Constant.ZERO_SEC);
  			roleEntitlement.setOrganisation(tbOrganisationEntitySaved);
  			roleEntitlement.setUpdatedBy(sessionEmp.getUserId());
  			roleEntitlement.setUpdatedDate(new Date());
  			roleEntitlement.setGroupMaster(groupMasterSaved);
  			entitlementSet.add(roleEntitlement);
  
  		}
  		groupMasEntity.setEntitlements(entitlementSet);
  		groupMasterSaved = groupMasService.createGroupMaster(groupMasEntity, tbOrganisationEntitySaved);
  
  		Designation designation= designationService.findByName(appSession.getMessage("organisation.designation"));
  		
  
  		Employee employee = new Employee();
  		employee.setLangId(sessionLangId); 
  		employee.setUpdatedBy(sessionEmp.getEmpId());
  		employee.setLmodDate(new Date()); 
  		employee.setUserId(sessionEmp.getEmpId());
  		employee.setLgIpMac(Utility.getMacAddress());
  		employee.setIsDeleted(MainetConstants.Common_Constant.ZERO_SEC);
  		employee.setIsuploaded(MainetConstants.Common_Constant.YES);
  		employee.setAutMob(MainetConstants.Common_Constant.YES);
  		employee.setAutEmail(MainetConstants.Common_Constant.YES);
  		employee.setAuthStatus(MainetConstants.STATUS.ACTIVE);
  		employee.setEmpname(appSession.getMessage("employee.Empname"));
  		employee.setEmposloginname(appSession.getMessage("employee.Emposloginname"));
  		employee.setEmploginname(appSession.getMessage("employee.Emploginname"));
  		Calendar now = Calendar.getInstance();
  		now.add(Calendar.DATE,1);
  		Date date= now.getTime();
  		employee.setEmpexpiredt(date);
  		employee.setEmppassword(Utility.encryptPassword(appSession.getMessage("employee.Emploginname"), appSession.getMessage("employee.Password")));
  		employee.setUpdatedDate(new Date());
  		employee.setDesignation(designation);
  		/*if(!designation.equals(null)){
  			employee.setDesignation(designation);
  		}else{
  			Designation adminDesignation = new Designation();
  			adminDesignation = createDefaultDesignation(appSession.getMessage("organisation.designation"), appSession.getMessage("default.designation.shortcode"));
  			employee.setDesignation(adminDesignation);
  		}
  		
  		Designation citizenDesg = designationService.findByName(appSession.getMessage("default.desgn.citizen.dsgname"));
  		if(!citizenDesg.equals(null)){
  			//employee.setDesignation(designation);
  			//push to portal
  		}else{
  			Designation savedDesg = new Designation();
  			savedDesg = createDefaultDesignation(appSession.getMessage("default.desgn.citizen.dsgname"), appSession.getMessage("default.desgn.citizen.shortcode"));
  			//employee.setDesignation(adminDesignation);
  		}*/
  		
  		employee.setTbLocationMas(tbLocationMasEntitySaved);
  
  		Department department = tbDepartmentService.findDepartmentByCode(appSession.getMessage("organisation.department"));
  
  		DeptOrgMap deptOrgMap=new DeptOrgMap();
  		deptOrgMap.setMapStatus(MainetConstants.STATUS.ACTIVE);
  		deptOrgMap.setUserId(Integer.valueOf(sessionEmp.getUserId().toString()));
  		deptOrgMap.setLangId(sessionLangId);
  		deptOrgMap.setLmoddate(new Date());
  		deptOrgMap.setUpdatedBy(Integer.parseInt(sessionEmp.getEmpId().toString()));
  		deptOrgMap.setUpdatedDate(new Date());
  		deptOrgMap.setDepartment(department);
  		deptOrgMap.setOrgid(organisationEntity.getOrgid());
  
  		TbDeporgMap tbDeporgMap = tbDeporgMapServiceMapper.mapTbDeporgMapEntityToTbDeporgMap(deptOrgMap);
  		List<TbDeporgMap> deptOrgMapList = new ArrayList<TbDeporgMap>();
  		deptOrgMapList.add(tbDeporgMap);
  		tbDeporgMapService.createDepOrgData(tbDeporgMap, deptOrgMapList);
  
  		TbOrgDesignation tbOrgDesignationMap = new TbOrgDesignation();
  		tbOrgDesignationMap.setUserId(sessionEmp.getUserId());
  		tbOrgDesignationMap.setUpdatedDate(new Date());
  		tbOrgDesignationMap.setUpdatedBy(sessionEmp.getEmpId());
  		tbOrgDesignationMap.setOrgid(organisationEntity.getOrgid());
  		tbOrgDesignationMap.setLmoddate(new Date());
  		tbOrgDesignationMap.setDsgid(designation.getDsgid());
  		List<TbOrgDesignation> tbOrgDesignationMapList = new ArrayList<TbOrgDesignation>();
  		tbOrgDesignationMapList.add(tbOrgDesignationMap);
  		tbOrgDesignationService.createDesgOrgData(tbOrgDesignationMap, tbOrgDesignationMapList);
  		
  		TbDeptLocation deptLocBean = new TbDeptLocation();
  		deptLocBean.setDpDeptid(department.getDpDeptid());
  		deptLocBean.setOrgid(tbOrganisationEntitySaved.getOrgid());
  		deptLocBean.setUserId(sessionEmp.getUserId());
  		deptLocBean.setLangId(Long.valueOf(sessionLangId));
  		deptLocBean.setUpdatedBy(sessionEmp.getEmpId());
  		deptLocBean.setUpdatedDate(new Date());
  		deptLocBean.setLocId(tbLocationMasEntitySaved.getLocId());
  		deptLocBean.setIsdeleted(MainetConstants.Common_Constant.ZERO_SEC);
  		deptLocationService.create(deptLocBean);
  
  		List<TbComparamMasEntity> tbComparamMasEntity=null;
  		Long cpmId=null;
  		List<TbComparamDetEntity> tbComparamDetlist=null;
  		TbComparamDet tbComparamBean= null;
  		tbComparamMasEntity = tbComparamMasService.findAllByCpmReplicateFlag(MainetConstants.Common_Constant.YES, MainetConstants.Common_Constant.NO);
  		for(TbComparamMasEntity tbCmprm: tbComparamMasEntity){     
  			cpmId = tbCmprm.getCpmId();
  			tbComparamDetlist = tbComparamDetService.findCmprmDetDataByCpmId(cpmId);
  			for(TbComparamDetEntity tbComparamDetEntityList: tbComparamDetlist){
  				tbComparamBean = new TbComparamDet();
  				tbComparamBean.setOrgid(tbOrganisationEntitySaved.getOrgid());
  				tbComparamBean.setCpdDesc(tbComparamDetEntityList.getCpdDesc());
  				tbComparamBean.setCpdStatus(tbComparamDetEntityList.getCpdStatus());
  				tbComparamBean.setCpdDescMar(tbComparamDetEntityList.getCpdDescMar());
  				tbComparamBean.setCpdValue(tbComparamDetEntityList.getCpdValue());
  				tbComparamBean.setUserId(sessionEmp.getUserId());
  				tbComparamBean.setLmoddate(new Date());
  				tbComparamBean.setLangId(Long.valueOf(sessionLangId));
  				tbComparamBean.setCpmId(cpmId);
  				tbComparamBean.setUpdatedBy(sessionEmp.getUserId());
  				tbComparamBean.setUpdatedDate(new Date());
  				tbComparamDetService.create(tbComparamBean);
  			}
  
  		}
  		tbComparamMasEntity = tbComparamMasService.findAllByCpmReplicateFlag(MainetConstants.Common_Constant.YES,MainetConstants.LookUp.HIERARCHICAL);
  		List<TbComparentMas> tbComparentMasList=null;
  		TbComparentMasEntity tbComparentMasEntity=null;
  		for(TbComparamMasEntity tbComparam: tbComparamMasEntity){
  			cpmId = tbComparam.getCpmId();
  			tbComparentMasList = tbComparentMasService.findComparentMasDataByCpmId(cpmId);
  			for(TbComparentMas tbComparentMas: tbComparentMasList){
  				tbComparentMasEntity = new TbComparentMasEntity();
  				tbComparentMasEntity.setTbComparamMas(tbComparam);
  				tbComparentMasEntity.setComDesc(tbComparentMas.getComDesc());
  				tbComparentMasEntity.setComDescMar(tbComparentMas.getComDescMar());
  				tbComparentMasEntity.setComValue(tbComparentMas.getComValue());
  				tbComparentMasEntity.setComLevel(tbComparentMas.getComLevel());
  				tbComparentMasEntity.setOrgid(tbOrganisationEntitySaved.getOrgid());
  				tbComparentMasEntity.setUserId(sessionEmp.getUserId());
  				tbComparentMasEntity.setLangId(Long.valueOf(sessionLangId));
  				tbComparentMasEntity.setLmoddate(new Date());
  				tbComparentMasEntity.setUpdatedBy(sessionEmp.getUserId());
  				tbComparentMasEntity.setUpdatedDate(new Date());
  				tbComparentMasService.create(tbComparentMasEntity);
  			}
  		}
  		
  		List<TbServicesMst> serviceList = tbServicesMstService.findAllServiceListByOrgId(orgSession.getOrgid());
  		TbServicesMst serviceBean = null;
  		LookUp activenessLookup = CommonMasterUtility.getLookUpFromPrefixLookUpValue(MainetConstants.IsLookUp.INACTIVE, MainetConstants.LookUp.ACN,sessionLangId,orgSession);
  		Long activenessLookupId = activenessLookup.getLookUpId();
  		
  		if(serviceList != null && !serviceList.isEmpty()){
  			for(TbServicesMst bean:serviceList){
  				serviceBean = new TbServicesMst();
  				serviceBean.setSmShortdesc(bean.getSmShortdesc());
  				serviceBean.setSmServActive(activenessLookupId);
  				serviceBean.setOrgid(tbOrganisationEntitySaved.getOrgid());
  				serviceBean.setUserId(sessionEmp.getEmpId());
  				serviceBean.setLangId(Long.valueOf(sessionLangId));
  				serviceBean.setSmServiceName(bean.getSmServiceName());
  				serviceBean.setSmServiceNameMar(bean.getSmServiceNameMar());
  				serviceBean.setCdmDeptId(bean.getCdmDeptId());
  				tbServicesMstService.create(serviceBean);
  			}
  		}
  		
  		
  		employee.setTbDepartment(department);
  		employee.setOrganisation(tbOrganisationEntitySaved);
  		employee.setGmid(groupMasterSaved.getGmId());
  		employeeService.saveEmployee(employee);
  		
  		Date estdDate = tbOrganisation.getEsdtDate();
  		TbFinancialyear finYearBean = tbFinancialyearService.findFinancialYear(estdDate);
  		
  		if(finYearBean != null){
  			List<TbFinancialyear> financialYearList = tbFinancialyearService.getFinanciaYearsFromDate(finYearBean.getFaFromDate());
  			TbFincialyearorgMap finYearOrgMapBean = null;
  			for(TbFinancialyear finbean:financialYearList){
  				finYearOrgMapBean = new TbFincialyearorgMap();
  				finYearOrgMapBean.setOrgid(tbOrganisationEntitySaved.getOrgid());
  				finYearOrgMapBean.setFaYearid(finbean.getFaYear());
  				tbFinancialyearOrgMapService.create(finYearOrgMapBean);
  			}
  		}		
  		//createPortalOrganisation(tbOrganisation,appSession,userSession);
  		return tbOrganisationServiceMapper.mapTbOrganisationEntityToTbOrganisation(tbOrganisationEntitySaved);
  	}
  
  	@Override
  	@Transactional
  	public TbOrganisation update(TbOrganisation tbOrganisation) {
  		Organisation tbOrganisationEntity = tbOrganisationJpaRepository.findOrgById(tbOrganisation.getUlbOrgID());
  		if(tbOrganisation.getOrgStatus() == null || tbOrganisation.getOrgStatus() == ""){
  			tbOrganisation.setOrgStatus(MainetConstants.STATUS.ACTIVE);
  		}
  		tbOrganisationServiceMapper.mapTbOrganisationToTbOrganisationEntity(tbOrganisation, tbOrganisationEntity);
  		Organisation tbOrganisationEntitySaved = tbOrganisationJpaRepository.save(tbOrganisationEntity);
  		return tbOrganisationServiceMapper.mapTbOrganisationEntityToTbOrganisation(tbOrganisationEntitySaved);
  	}
  
  
  	@Override
  	@Transactional
  	public void delete(Long orgid) {
  		Organisation tbOrganisationEntity = tbOrganisationJpaRepository.findOne(orgid);
  		tbOrganisationEntity.setOrgStatus("I");
  		tbOrganisationJpaRepository.save(tbOrganisationEntity);
  	}
  
  	public TbOrganisationJpaRepository getTbOrganisationJpaRepository() {
  		return tbOrganisationJpaRepository;
  	}
  
  	public void setTbOrganisationJpaRepository(TbOrganisationJpaRepository tbOrganisationJpaRepository) {
  		this.tbOrganisationJpaRepository = tbOrganisationJpaRepository;
  	}
  
  	public TbOrganisationServiceMapper getTbOrganisationServiceMapper() {
  		return tbOrganisationServiceMapper;
  	}
  
  	public void setTbOrganisationServiceMapper(TbOrganisationServiceMapper tbOrganisationServiceMapper) {
  		this.tbOrganisationServiceMapper = tbOrganisationServiceMapper;
  	}
  
  	@Override
  	@Transactional
  	public boolean defaultexist(String defaultStatus) {
  	List<Organisation> list=tbOrganisationJpaRepository.defaultexist(defaultStatus);
  	if(list != null && !list.isEmpty())
  	{
  		return true;	
  	}
  		return false;
  	}
  
  
  	/* (non-Javadoc)
  	 * @see com.abm.mainetservice.web.masters.organisation.business.service.TbOrganisationService#exist(java.lang.String, java.lang.Long, java.lang.String, java.lang.String)
  	 */
  	@Override
  	@Transactional
  	public String exist(String mode, Long ulbOrgId, String orgName,
  			String orgNameMar) {
  		String exist = null;
  		String orgNameNew = orgName.trim();
  		Organisation orgIdList = tbOrganisationJpaRepository.findOrgById(ulbOrgId);
  		if(mode.equalsIgnoreCase("create")){
  