Advertisement
aadddrr

Untitled

Dec 3rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.31 KB | None | 0 0
  1. package org.jleaf.pos.services.admin;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.StringReader;
  5. import java.util.List;
  6.  
  7. import org.jleaf.pos.PosBoConstants;
  8. import org.jleaf.pos.PosBoExceptionConstants;
  9. import org.jleaf.pos.PosProperties;
  10. import org.jleaf.pos.services.AbstractPosJleafService;
  11. import org.jleaf.pos.services.PosJleafServiceUtil;
  12. import org.jleaf.baseservices.util.ServiceUtil;
  13. import org.jleaf.core.CoreException;
  14. import org.jleaf.core.Dto;
  15. import org.jleaf.core.GeneralConstants;
  16. import org.jleaf.core.annotation.Info;
  17. import org.jleaf.core.annotation.InfoIn;
  18. import org.jleaf.core.annotation.InfoOut;
  19. import org.jleaf.core.annotation.ServiceDoc;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22.  
  23. /**
  24.  * Activate outlet
  25.  *
  26.  * @author WTC, Mar 20, 2013
  27.  * @version 1.0.0
  28.  */
  29. @ServiceDoc
  30. //@formatter:off
  31. @InfoIn(value = {
  32.         @Info(name = "result.header.userLoginId", description = "user login id", type = Long.class),
  33.         @Info(name = "result.header.roleLoginId", description = "role login id", type = Long.class),
  34.         @Info(name = "result.header.tenantLoginId", description = "tenant login id", type = Long.class),
  35.         @Info(name = "result.header.datetime", description = "datetime", type = String.class),
  36.         @Info(name = "result.header.sessionId", description = "session id", type = String.class),
  37.         @Info(name = "result.header.secureKey", description = "secure key", type = String.class),
  38.         @Info(name = "result.header.taskName", description = "task name", type = String.class),
  39.         @Info(name = "result.payload.startTrxDate", description = "start trx date", type = String.class)
  40. })
  41. @InfoOut(value = {
  42.         @Info(name = "result.activeDateTime", description = "active date time", type = String.class)
  43. })
  44. //@formatter:on
  45. public class ActivateOutletService extends AbstractPosJleafService {
  46.  
  47.     private static final Logger log = LoggerFactory.getLogger(ActivateOutletService.class);
  48.  
  49.     @Override
  50.     public String getTaskName() {
  51.         return "activateOutlet";
  52.     }
  53.  
  54.     @Override
  55.     public Dto process(Dto inputDto) throws Exception {
  56.         log.info(getTaskName() + " :Process");
  57.  
  58.         // Declaring variables
  59.         Dto inputDtoForCheckSysConfigValue;
  60.         Dto outputDtoForCheckSysConfigValue;
  61.         Dto outputDto;
  62.  
  63.         // Validation input variables
  64.         log.info(getTaskName() + " :Validating");
  65.         ServiceUtil.valNullParams(inputDto, "result.payload.startTrxDate",
  66.                 "result.header.sessionId", "result.header.secureKey", "result.header.tenantLoginId", "result.header.userLoginId",
  67.                 "result.header.roleLoginId", "result.header.datetime");
  68.  
  69.         // Preparing input parameters
  70.         String startTrxDate = inputDto.getString("result.payload.startTrxDate");
  71.         Long tenantLoginId = Long.parseLong(inputDto.getString("result.header.tenantLoginId"));
  72.         Long userLoginId = Long.parseLong(inputDto.getString("result.header.userLoginId"));
  73.         Long roleLoginId = Long.parseLong(inputDto.getString("result.header.roleLoginId"));
  74.         String datetime = inputDto.getString("result.header.datetime");
  75.  
  76.         // Validate this outlet has not been activated yet
  77.         inputDtoForCheckSysConfigValue = new Dto();
  78.         inputDtoForCheckSysConfigValue.put("tenantId", tenantLoginId);
  79.         inputDtoForCheckSysConfigValue.put("parameterCode", PosBoConstants.PARAM_ACTIVE_DATE_TIME);
  80.         inputDtoForCheckSysConfigValue.put("value", GeneralConstants.SPACE_VALUE);
  81.         outputDtoForCheckSysConfigValue = getBusinessFunction("isMatchSystemConfigValueByParameterCode").execute(inputDtoForCheckSysConfigValue);
  82.         if (!outputDtoForCheckSysConfigValue.getBoolean("isTrue"))
  83.             throw new CoreException(PosBoExceptionConstants.VAL_OUTLET_INACTIVE);
  84.  
  85.         log.info(getTaskName() + " :send request to Server Center");
  86.         // Preparing
  87.         Dto tenantDto = new Dto();
  88.         tenantDto.put("id", tenantLoginId);
  89.         tenantDto = getBusinessFunction("findTenantById").execute(tenantDto);
  90.         String tenantKey = tenantDto.getString("key");
  91.  
  92.         Dto systemConfigDto = new Dto();
  93.         systemConfigDto.put("parameterCode", PosBoConstants.PARAM_OUTLET_ID);
  94.         systemConfigDto.put("tenantId", tenantLoginId);
  95.         systemConfigDto = getBusinessFunction("findSystemConfigByParamCode").execute(systemConfigDto);
  96.         Long outletId = Long.parseLong(systemConfigDto.getString("value"));
  97.  
  98.         String url = PosProperties.getProperties().getProperty(PosBoConstants.PROP_ACTIVATE_OUTLET_URL);
  99.  
  100.         // Connect to server center
  101.         Dto inputDtoForActivateOutletAtHO = new Dto();
  102.         inputDtoForActivateOutletAtHO.put("input.header.sessionId", inputDto.getString("result.header.sessionId"));
  103.         inputDtoForActivateOutletAtHO.put("input.header.datetime", datetime);
  104.         inputDtoForActivateOutletAtHO.put("input.header.secureKey", inputDto.getString("result.header.secureKey"));
  105.         inputDtoForActivateOutletAtHO.put("input.header.tkey", tenantKey);
  106.         inputDtoForActivateOutletAtHO.put("input.payload.tenantId", tenantLoginId);
  107.         inputDtoForActivateOutletAtHO.put("input.payload.outletId", outletId);
  108.         inputDtoForActivateOutletAtHO.put("input.payload.startTrxDate", startTrxDate);
  109.  
  110.         // Send Message
  111.         byte[] outputByte = PosJleafServiceUtil.sendEncodedGzipMessage(url, inputDtoForActivateOutletAtHO.toString());
  112.  
  113.         // Parse data
  114.         Dto outputDtoForActivateOutletAtHO = parseDataFromServerCenter(outputByte);
  115.         String activeDateTime = outputDtoForActivateOutletAtHO.getString("activeDateTime");
  116.  
  117.         // Do activate outlet at local server
  118.         Dto inputDtoForActivateOutletAtLocal = new Dto();
  119.         inputDtoForActivateOutletAtLocal.put("activeDateTime", activeDateTime);
  120.         inputDtoForActivateOutletAtLocal.put("startTrxDate", startTrxDate);
  121.         inputDtoForActivateOutletAtLocal.put("tenantLoginId", tenantLoginId);
  122.         inputDtoForActivateOutletAtLocal.put("roleLoginId", roleLoginId);
  123.         inputDtoForActivateOutletAtLocal.put("userLoginId", userLoginId);
  124.         inputDtoForActivateOutletAtLocal.put("datetime", datetime);
  125.  
  126.         getBusinessTransaction("activateOutlet").execute(inputDtoForActivateOutletAtLocal);
  127.  
  128.         // Preparing output parameters
  129.         outputDto = new Dto();
  130.         outputDto.put("result.activeDateTime", activeDateTime);
  131.  
  132.         log.info(getTaskName() + " :Output = " + outputDto);
  133.         return outputDto;
  134.     }
  135.  
  136.     private Dto parseDataFromServerCenter(byte[] data) throws Exception {
  137.         log.info(getTaskName() + ":Parse data from server center");
  138.         Dto parseDto = null;
  139.         String thisLine;
  140.         BufferedReader reader = new BufferedReader(new StringReader(new String(data)));
  141.         if ((thisLine = reader.readLine()) != null) {
  142.             Dto rawDto = new Dto(thisLine);
  143.             log.debug(getTaskName() + ":RawDto:" + rawDto);
  144.            
  145.             // Get result
  146.             Dto result = rawDto.getDto("result");
  147.             String status = result.getString("status");
  148.            
  149.             // check status
  150.             if (status != null && GeneralConstants.OK.equals(status)) {
  151.                 Dto payload = result.getDto("payload");
  152.    
  153.                 parseDto = new Dto();
  154.                 parseDto.put("activeDateTime", payload.getString("openDateTime"));
  155.    
  156.                 log.debug(getTaskName() + ":ParseDto:" + parseDto);
  157.             } else if (status != null && GeneralConstants.FAIL.equals(status)) {
  158.                 @SuppressWarnings("rawtypes")
  159.                 List args = result.getList("args");
  160.                 if (args != null && !args.isEmpty())
  161.                     throw new CoreException(result.getString("errorKey"));
  162.                 else
  163.                     throw new CoreException(result.getString("errorKey"), args.toArray());
  164.             } else if (status != null && GeneralConstants.ERROR.equals(status)) {
  165.                 throw new Exception(result.getString("message"));
  166.             }
  167.         }
  168.  
  169.         return parseDto;
  170.     }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement