Advertisement
aadddrr

ValOUAsMainBusinessUnitOrBranch

Aug 20th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.29 KB | None | 0 0
  1. package org.jleaf.common.bo.ou;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.common.CommonExceptionConstants;
  8. import org.jleaf.common.dao.OUDao;
  9. import org.jleaf.common.dao.OUTypeDao;
  10. import org.jleaf.common.entity.OU;
  11. import org.jleaf.core.AbstractBusinessFunction;
  12. import org.jleaf.core.BusinessFunction;
  13. import org.jleaf.core.CoreException;
  14. import org.jleaf.core.Dto;
  15. import org.jleaf.core.GeneralConstants;
  16. import org.jleaf.core.annotation.ErrorList;
  17. import org.jleaf.core.annotation.Info;
  18. import org.jleaf.core.annotation.InfoIn;
  19. import org.jleaf.core.annotation.InfoOut;
  20. import org.jleaf.util.DtoUtil;
  21. import org.jleaf.util.ValidationUtil;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26.  
  27.  
  28. /**
  29.  *
  30.  * Validate ou must a main Business Unit or branch ( active )
  31.  *  
  32.  * @author NK
  33.  * @version 1.0
  34.  */
  35.  
  36. @Service
  37. @InfoIn(value={
  38.             @Info(name="id",description="ou id",type=Long.class)})
  39. @InfoOut(value = {
  40.         @Info(name = "id", description = "ou id - auto generated", type = Long.class),
  41.         @Info(name = "tenantId", description = "tenant id", type = Long.class),
  42.         @Info(name = "code", description = "ou code", type = String.class),
  43.         @Info(name = "name", description = "ou name", type = String.class),
  44.         @Info(name = "parentId", description = "ou parent id", type = Long.class),     
  45.         @Info(name = "typeId", description = "ou type id", type = Long.class),
  46.         @Info(name = "version", description = "version", type = Long.class),
  47.         @Info(name = "active", description = "active status", type = String.class),
  48.         @Info(name = "activeDateTime", description = "active date time", type = String.class),
  49.         @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class),
  50.         @Info(name = "createUserId", description = "create user id", type = Long.class),
  51.         @Info(name = "createDateTime", description = "create date time", type = String.class),
  52.         @Info(name = "updateUserId", description = "update user id", type = Long.class),
  53.         @Info(name = "updateDateTime", description = "update date time", type = String.class) })
  54. @ErrorList(errorKeys={CommonExceptionConstants.OUTYPE_ID_NOT_FOUND,
  55.                     CommonExceptionConstants.OU_ID_NOT_FOUND,
  56.                         CommonExceptionConstants.OU_NOT_MAIN_BUSINESS_UNIT_OR_BRANCH})
  57. public class ValOUAsMainBusinessUnitOrBranch extends AbstractBusinessFunction implements BusinessFunction {
  58.    
  59.     private static final Logger log = LoggerFactory.getLogger(ValOUAsMainBusinessUnitOrBranch.class);
  60.  
  61.     @Autowired
  62.     OUTypeDao ouTypeDao;
  63.    
  64.     @Autowired
  65.     OUDao ouDao;
  66.        
  67.     @Override
  68.     public String getDescription(){
  69.         return "Validate ou must a main business unit or branch ( active )";
  70.     }
  71.  
  72.     @SuppressWarnings("unchecked")
  73.     @Override
  74.     public Dto execute(Dto inputDto) throws Exception {
  75.        
  76.         Dto outputDto = null;
  77.  
  78.         ValidationUtil.valDtoContainsKey(inputDto, "id");
  79.  
  80.         Long idLong = inputDto.getLong("id");
  81.  
  82.         OU ou = ouDao.findByPk(idLong);
  83.         if (ou == null) {
  84.             throw new CoreException(CommonExceptionConstants.OU_ID_NOT_FOUND, idLong);
  85.         } else {
  86.             if (!ou.getActive().equals(GeneralConstants.YES)) {
  87.                 throw new CoreException(CommonExceptionConstants.OU_NOT_ACTIVE, ou.getName());
  88.             }
  89.         }
  90.  
  91.         Query query = ouTypeDao.createQuery("SELECT e.flagBusinessUnit, e.flagBranch, e.flagSubBusinessUnit, e.flagAccounting FROM org.jleaf.common.entity.OUType e WHERE e.id = :id");
  92.         query.setParameter("id", ou.getTypeId());
  93.  
  94.         log.debug("query:" + query.toString());
  95.         List<Object[]> ouTypeList = query.getResultList();
  96.         if (ouTypeList.size() > 0) {
  97.             List<Dto> list = DtoUtil.createDtoListFromArray(ouTypeList, "flagBusinessUnit", "flagBranch", "flagSubBusinessUnit", "flagAccounting");
  98.             String flagSubBusinessUnit = list.get(0).getString("flagSubBusinessUnit");
  99.             String flagAccounting = list.get(0).getString("flagAccounting");
  100.  
  101.             if (GeneralConstants.YES.equals(flagSubBusinessUnit) || GeneralConstants.YES.equals(flagAccounting)) {
  102.                 throw new CoreException(CommonExceptionConstants.OU_NOT_MAIN_BUSINESS_UNIT_OR_BRANCH, ou.getName());
  103.             }
  104.         } else {
  105.             throw new CoreException(CommonExceptionConstants.OUTYPE_ID_NOT_FOUND, ou.getTypeId());
  106.         }
  107.  
  108.         outputDto = new Dto(ou);
  109.  
  110.         return outputDto;      
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement