Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package id.co.sts.firebase.bo.device;
- import id.co.sts.firebase.dao.DeviceDao;
- import id.co.sts.firebase.dao.DeviceLogDao;
- import id.co.sts.firebase.entity.Device;
- import id.co.sts.firebase.entity.DeviceLog;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.DefaultBusinessTransaction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.util.GsonUtil;
- import org.jleaf.util.ValidationUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Service;
- @Service
- @InfoIn(value = {
- @Info(name="projectId", description="Project id", type=String.class, required=true),
- @Info(name="uuid", description="user uid", type=Long.class, required=true)
- })
- @InfoOut(value = {
- @Info(name = "id", description = "device id", type = Long.class),
- @Info(name = "tenantId", description = "tenant id", type = Long.class),
- @Info(name = "projectId", description = "project id", type = Long.class),
- @Info(name = "uuid", description = "user uid", type = String.class),
- @Info(name = "refCode", description = "ref code", type = String.class),
- @Info(name = "token", description = "token", type = String.class),
- @Info(name = "createDateTime", description = "create date time", type = String.class),
- @Info(name = "updateDateTime", description = "update date time", type = String.class),
- @Info(name = "createUserId", description = "create user id", type = Long.class),
- @Info(name = "updateUserId", description = "update user id", type = Long.class),
- @Info(name = "version", description = "version", type = Long.class),
- @Info(name = "active", description = "active", type = String.class),
- @Info(name = "activeDateTime", description = "active date time", type = String.class),
- @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class)
- })
- @ErrorList(errorKeys = {})
- public class InactiveDevice extends DefaultBusinessTransaction implements BusinessTransaction{
- private final static Logger log = LoggerFactory.getLogger(AddOrEditDevice.class);
- @Autowired
- DeviceDao deviceDao;
- @Autowired
- DeviceLogDao deviceLogDao;
- @Autowired
- @Qualifier("findDeviceByIndex")
- BusinessFunction findDeviceByIndex;
- public String getDescription() {
- // TODO Auto-generated method stub
- return "Inactive Device";
- }
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- // TODO Auto-generated method stub
- ValidationUtil.valBlankOrNull(inputDto, "projectId");
- ValidationUtil.valBlankOrNull(inputDto, "uuid");
- ValidationUtil.valBlankOrNull(inputDto, "active");
- log.debug("Call find device by index");
- log.debug("Input : "+inputDto);
- Dto outputFindDeviceByIndex = findDeviceByIndex.execute(inputDto);
- Long projectId = outputFindDeviceByIndex.getLong("projectId");
- inputDto.put("projectId", projectId);
- log.debug("Output: ");
- log.debug(outputFindDeviceByIndex.toString());
- Dto device = new Dto();
- device.put("projectId", projectId);
- device.put("uuid", inputDto.get("uuid"));
- device.put("active", inputDto.get("active"));
- this.prepareInsertAudit(device, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
- this.prepareUpdateAudit(device, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
- inputDto.put("device", device);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- Dto deviceDto = inputDto.getDto("device");
- Device device;
- DeviceLog deviceLog;
- if(GeneralConstants.YES.equals(deviceDto.get("active"))){
- deviceDto.put("active", GeneralConstants.NO);
- }
- log.debug("Before merge");
- log.debug(deviceDto.toString());
- device = GsonUtil.fromDto(deviceDto, Device.class);
- deviceDao.merge(deviceDto.getLong("id"),device);
- deviceDao.flush();
- deviceDto.put("deviceId", deviceDto.getLong("id"));
- deviceLog = GsonUtil.fromDto(deviceDto, DeviceLog.class);
- deviceLog.setId(null);
- log.debug("Device log");
- log.debug(deviceLog.toString());
- deviceLogDao.persist(deviceLog);
- deviceLogDao.flush();
- return new Dto(device);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement