Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos.services.admin;
- import java.io.BufferedReader;
- import java.io.StringReader;
- import java.util.List;
- import org.jleaf.pos.PosBoConstants;
- import org.jleaf.pos.PosBoExceptionConstants;
- import org.jleaf.pos.PosProperties;
- import org.jleaf.pos.services.AbstractPosJleafService;
- import org.jleaf.pos.services.PosJleafServiceUtil;
- import org.jleaf.baseservices.util.ServiceUtil;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.core.annotation.ServiceDoc;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- /**
- * Activate outlet
- *
- * @author WTC, Mar 20, 2013
- * @version 1.0.0
- */
- @ServiceDoc
- //@formatter:off
- @InfoIn(value = {
- @Info(name = "result.header.userLoginId", description = "user login id", type = Long.class),
- @Info(name = "result.header.roleLoginId", description = "role login id", type = Long.class),
- @Info(name = "result.header.tenantLoginId", description = "tenant login id", type = Long.class),
- @Info(name = "result.header.datetime", description = "datetime", type = String.class),
- @Info(name = "result.header.sessionId", description = "session id", type = String.class),
- @Info(name = "result.header.secureKey", description = "secure key", type = String.class),
- @Info(name = "result.header.taskName", description = "task name", type = String.class),
- @Info(name = "result.payload.startTrxDate", description = "start trx date", type = String.class)
- })
- @InfoOut(value = {
- @Info(name = "result.activeDateTime", description = "active date time", type = String.class)
- })
- //@formatter:on
- public class ActivateOutletService extends AbstractPosJleafService {
- private static final Logger log = LoggerFactory.getLogger(ActivateOutletService.class);
- @Override
- public String getTaskName() {
- return "activateOutlet";
- }
- @Override
- public Dto process(Dto inputDto) throws Exception {
- log.info(getTaskName() + " :Process");
- // Declaring variables
- Dto inputDtoForCheckSysConfigValue;
- Dto outputDtoForCheckSysConfigValue;
- Dto outputDto;
- // Validation input variables
- log.info(getTaskName() + " :Validating");
- ServiceUtil.valNullParams(inputDto, "result.payload.startTrxDate",
- "result.header.sessionId", "result.header.secureKey", "result.header.tenantLoginId", "result.header.userLoginId",
- "result.header.roleLoginId", "result.header.datetime");
- // Preparing input parameters
- String startTrxDate = inputDto.getString("result.payload.startTrxDate");
- Long tenantLoginId = Long.parseLong(inputDto.getString("result.header.tenantLoginId"));
- Long userLoginId = Long.parseLong(inputDto.getString("result.header.userLoginId"));
- Long roleLoginId = Long.parseLong(inputDto.getString("result.header.roleLoginId"));
- String datetime = inputDto.getString("result.header.datetime");
- // Validate this outlet has not been activated yet
- inputDtoForCheckSysConfigValue = new Dto();
- inputDtoForCheckSysConfigValue.put("tenantId", tenantLoginId);
- inputDtoForCheckSysConfigValue.put("parameterCode", PosBoConstants.PARAM_ACTIVE_DATE_TIME);
- inputDtoForCheckSysConfigValue.put("value", GeneralConstants.SPACE_VALUE);
- outputDtoForCheckSysConfigValue = getBusinessFunction("isMatchSystemConfigValueByParameterCode").execute(inputDtoForCheckSysConfigValue);
- if (!outputDtoForCheckSysConfigValue.getBoolean("isTrue"))
- throw new CoreException(PosBoExceptionConstants.VAL_OUTLET_INACTIVE);
- log.info(getTaskName() + " :send request to Server Center");
- // Preparing
- Dto tenantDto = new Dto();
- tenantDto.put("id", tenantLoginId);
- tenantDto = getBusinessFunction("findTenantById").execute(tenantDto);
- String tenantKey = tenantDto.getString("key");
- Dto systemConfigDto = new Dto();
- systemConfigDto.put("parameterCode", PosBoConstants.PARAM_OUTLET_ID);
- systemConfigDto.put("tenantId", tenantLoginId);
- systemConfigDto = getBusinessFunction("findSystemConfigByParamCode").execute(systemConfigDto);
- Long outletId = Long.parseLong(systemConfigDto.getString("value"));
- String url = PosProperties.getProperties().getProperty(PosBoConstants.PROP_ACTIVATE_OUTLET_URL);
- // Connect to server center
- Dto inputDtoForActivateOutletAtHO = new Dto();
- inputDtoForActivateOutletAtHO.put("input.header.sessionId", inputDto.getString("result.header.sessionId"));
- inputDtoForActivateOutletAtHO.put("input.header.datetime", datetime);
- inputDtoForActivateOutletAtHO.put("input.header.secureKey", inputDto.getString("result.header.secureKey"));
- inputDtoForActivateOutletAtHO.put("input.header.tkey", tenantKey);
- inputDtoForActivateOutletAtHO.put("input.payload.tenantId", tenantLoginId);
- inputDtoForActivateOutletAtHO.put("input.payload.outletId", outletId);
- inputDtoForActivateOutletAtHO.put("input.payload.startTrxDate", startTrxDate);
- // Send Message
- byte[] outputByte = PosJleafServiceUtil.sendEncodedGzipMessage(url, inputDtoForActivateOutletAtHO.toString());
- // Parse data
- Dto outputDtoForActivateOutletAtHO = parseDataFromServerCenter(outputByte);
- String activeDateTime = outputDtoForActivateOutletAtHO.getString("activeDateTime");
- // Do activate outlet at local server
- Dto inputDtoForActivateOutletAtLocal = new Dto();
- inputDtoForActivateOutletAtLocal.put("activeDateTime", activeDateTime);
- inputDtoForActivateOutletAtLocal.put("startTrxDate", startTrxDate);
- inputDtoForActivateOutletAtLocal.put("tenantLoginId", tenantLoginId);
- inputDtoForActivateOutletAtLocal.put("roleLoginId", roleLoginId);
- inputDtoForActivateOutletAtLocal.put("userLoginId", userLoginId);
- inputDtoForActivateOutletAtLocal.put("datetime", datetime);
- getBusinessTransaction("activateOutlet").execute(inputDtoForActivateOutletAtLocal);
- // Preparing output parameters
- outputDto = new Dto();
- outputDto.put("result.activeDateTime", activeDateTime);
- log.info(getTaskName() + " :Output = " + outputDto);
- return outputDto;
- }
- private Dto parseDataFromServerCenter(byte[] data) throws Exception {
- log.info(getTaskName() + ":Parse data from server center");
- Dto parseDto = null;
- String thisLine;
- BufferedReader reader = new BufferedReader(new StringReader(new String(data)));
- if ((thisLine = reader.readLine()) != null) {
- Dto rawDto = new Dto(thisLine);
- log.debug(getTaskName() + ":RawDto:" + rawDto);
- // Get result
- Dto result = rawDto.getDto("result");
- String status = result.getString("status");
- // check status
- if (status != null && GeneralConstants.OK.equals(status)) {
- Dto payload = result.getDto("payload");
- parseDto = new Dto();
- parseDto.put("activeDateTime", payload.getString("openDateTime"));
- log.debug(getTaskName() + ":ParseDto:" + parseDto);
- } else if (status != null && GeneralConstants.FAIL.equals(status)) {
- @SuppressWarnings("rawtypes")
- List args = result.getList("args");
- if (args != null && !args.isEmpty())
- throw new CoreException(result.getString("errorKey"));
- else
- throw new CoreException(result.getString("errorKey"), args.toArray());
- } else if (status != null && GeneralConstants.ERROR.equals(status)) {
- throw new Exception(result.getString("message"));
- }
- }
- return parseDto;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement