Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos2.bo.vehicle;
- import org.jleaf.common.ComboIdConstants;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.CoreException;
- 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.pos2.PosMasterExceptionConstants;
- import org.jleaf.pos2.dao.VehicleDao;
- import org.jleaf.pos2.entity.Vehicle;
- import org.jleaf.pos2.util.PosUtil;
- import org.jleaf.util.GsonUtil;
- import org.jleaf.util.ValidationUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Service;
- /**
- * Business Transactions: Add Vehicle
- *
- * @author Henokh Marjie Rivaldy , 26 Juli 2016
- */
- // @formatter:off
- @Service
- @InfoIn(value = {
- @Info(name = "licenseNo", description = "license no", type = String.class, required = true),
- @Info(name = "ownerName", description = "owner name", type = String.class, required = true),
- @Info(name = "chassisNo", description = "chassis no", type = String.class, required = true),
- @Info(name = "engineNo", description = "engine no", type = String.class, required = true),
- @Info(name = "vehicleGroupCode",description = "vehicle group code", type = String.class, required = true),
- @Info(name = "vehicleTypeCode", description = "vehicle type code", type = String.class, required = true),
- @Info(name = "yearMade", description = "year made", type = String.class, required = true),
- @Info(name = "customerName", description = "customer name", type = String.class, required = true),
- @Info(name = "address1", description = "address1", type = String.class, required = true),
- @Info(name = "address2", description = "address2", type = String.class, required = true),
- @Info(name = "address3", description = "address3", type = String.class, required = true),
- @Info(name = "phone1", description = "phone1", type = String.class, required = true),
- @Info(name = "phone2", description = "phone2", type = String.class, required = true),
- @Info(name = "active", description = "active", type = String.class),
- @Info(name = "datetime", description = "date time", type = String.class),
- @Info(name = "userLoginId", description = "user login id", type = Long.class),
- @Info(name = "userLoginName", description = "user login name", type = String.class),
- @Info(name = "roleLoginId", description = "role login id", type = Long.class),
- @Info(name = "roleLoginName", description = "role login name", type = String.class)
- })
- @InfoOut(value = {
- @Info(name = "vehicleCode", description = "vehicle code", type = String.class),
- @Info(name = "licenseNo", description = "license no", type = String.class),
- @Info(name = "chassisNo", description = "chassis no", type = String.class),
- @Info(name = "engineNo", description = "engine no", type = String.class),
- @Info(name = "vehicleGroupCode",description = "vehicle group code", type = String.class), @Info(name = "vehicleTypeCode", description = "vehicle type code", type = String.class),
- @Info(name = "yearMade", description = "year made", type = String.class),
- @Info(name = "customerName", description = "customer name", type = String.class),
- @Info(name = "address1", description = "address1", type = String.class),
- @Info(name = "address2", description = "address2", type = String.class),
- @Info(name = "address3", description = "address3", type = String.class),
- @Info(name = "phone1", description = "phone1", type = String.class),
- @Info(name = "phone2", description = "phone2", type = String.class),
- @Info(name = "address1", description = "address1", type = String.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 datetime",type = String.class),
- @Info(name = "createUsername", description = "create username", type = String.class),
- @Info(name = "updateDatetime", description = "update datetime", type = String.class),
- @Info(name = "updateUsername", description = "update username", type = String.class) })
- // @formatter:on
- @ErrorList(errorKeys = { PosMasterExceptionConstants.VEHICLE_ALREADY_EXISTS })
- public class AddVehicle extends DefaultBusinessTransaction implements
- BusinessTransaction {
- @Autowired
- VehicleDao vehicleDao;
- @Autowired
- @Qualifier("findVehicleGroupById")
- BusinessFunction findVehicleGroupById;
- @Autowired
- @Qualifier("findVehicleTypeById")
- BusinessFunction findVehicleTypeById;
- @Autowired
- @Qualifier("valComboValueByCode")
- BusinessFunction valComboValueByCode;
- @Autowired
- @Qualifier("isVehicleExistsById")
- BusinessFunction isVehicleExistsById;
- @Override
- public String getDescription() {
- return "Add Vehicle";
- }
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- ValidationUtil.valBlankOrNull(inputDto, "licenseNo");
- ValidationUtil.valDtoContainsKey(inputDto, "ownerName");
- ValidationUtil.valDtoContainsKey(inputDto, "chassisNo");
- ValidationUtil.valDtoContainsKey(inputDto, "engineNo");
- ValidationUtil.valBlankOrNull(inputDto, "vehicleGroupCode");
- ValidationUtil.valBlankOrNull(inputDto, "vehicleTypeCode");
- ValidationUtil.valDtoContainsKey(inputDto, "yearMade");
- ValidationUtil.valBlankOrNull(inputDto, "customerName");
- ValidationUtil.valDtoContainsKey(inputDto, "address1");
- ValidationUtil.valDtoContainsKey(inputDto, "address2");
- ValidationUtil.valDtoContainsKey(inputDto, "address3");
- ValidationUtil.valDtoContainsKey(inputDto, "phone1");
- ValidationUtil.valDtoContainsKey(inputDto, "phone2");
- ValidationUtil.valBlankOrNull(inputDto, "active");
- ValidationUtil.valBlankOrNull(inputDto, "datetime");
- ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "userLoginName");
- ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "roleLoginName");
- ValidationUtil.valDatetime(inputDto, "datetime");
- String licenseNo = inputDto.getString("licenseNo").trim().toUpperCase();
- String ownerName = inputDto.getString("ownerName");
- String chassisNo = inputDto.getString("chassisNo");
- String engineNo = inputDto.getString("engineNo");
- String vehicleGroupCode = inputDto.getString("vehicleGroupCode");
- String vehicleTypeCode = inputDto.getString("vehicleTypeCode");
- String yearMade = inputDto.getString("yearMade");
- String customerName = inputDto.getString("customerName");
- String address1 = inputDto.getString("address1");
- String address2 = inputDto.getString("address2");
- String address3 = inputDto.getString("address3");
- String phone1 = inputDto.getString("phone1");
- String phone2 = inputDto.getString("phone2");
- String active = inputDto.getString("active");
- String datetime = inputDto.getString("datetime");
- String userLoginId = inputDto.getString("userLoginId");
- String userLoginName = inputDto.getString("userLoginName");
- String roleLoginId = inputDto.getString("roleLoginId");
- String roleLoginName = inputDto.getString("roleLoginName");
- String vehicleCode = licenseNo
- .toUpperCase()
- .trim()
- .replace(GeneralConstants.SPACE_VALUE,
- GeneralConstants.EMPTY_VALUE);
- // Validasi harus referensi ke master vehivle group
- // panggil BF findVehicleGroupById dengan inputan vehicleGroupCode
- Dto inputDtoForFindVehicleGroupById = new Dto();
- inputDtoForFindVehicleGroupById.put("vehicleGroupCode",
- vehicleGroupCode);
- findVehicleGroupById.execute(inputDtoForFindVehicleGroupById);
- // Validasi harus referensi ke master vehivle type
- // panggil BF findVehicleTypeById dengan inputan vehicleTypeCode
- Dto inputDtoForFindVehicleTypeById = new Dto();
- inputDtoForFindVehicleTypeById.put("vehicleTypeCode", vehicleTypeCode);
- findVehicleTypeById.execute(inputDtoForFindVehicleTypeById);
- // Validation active must be suitable with combo YES NO
- Dto paramActiveDto = new Dto();
- paramActiveDto.put("comboId", ComboIdConstants.COMBO_YES_NO);
- paramActiveDto.put("code", active);
- paramActiveDto.put("varName", "active");
- valComboValueByCode.execute(paramActiveDto);
- // Validation data (business key) is not exists yet in db (add)
- Dto paramCheckUniqueDto = new Dto();
- paramCheckUniqueDto.put("vehicleCode", vehicleCode);
- Dto resultCheckUniqueDto = isVehicleExistsById
- .execute(paramCheckUniqueDto);
- if (resultCheckUniqueDto.getBoolean("exists")) {
- throw new CoreException(
- PosMasterExceptionConstants.VEHICLE_ALREADY_EXISTS,
- resultCheckUniqueDto.getString("vehicleDto.vehicleCode"));
- }
- Dto addVehicleDto = new Dto();
- addVehicleDto.put("vehicleCode", vehicleCode);
- addVehicleDto.put("licenseNo", licenseNo);
- addVehicleDto.put("ownerName", ownerName);
- addVehicleDto.put("chassisNo", chassisNo);
- addVehicleDto.put("engineNo", engineNo);
- addVehicleDto.put("vehicleGroupCode", vehicleGroupCode);
- addVehicleDto.put("vehicleTypeCode", vehicleTypeCode);
- addVehicleDto.put("yearMade", yearMade);
- addVehicleDto.put("customerName", customerName);
- addVehicleDto.put("address1", address1);
- addVehicleDto.put("address2", address2);
- addVehicleDto.put("address3", address3);
- addVehicleDto.put("phone1", phone1);
- addVehicleDto.put("phone2", phone2);
- addVehicleDto.put("active", active);
- // Set active datetime if active = Y
- if (inputDto.getString("active").equals(GeneralConstants.YES)) {
- addVehicleDto.put("activeDateTime", inputDto.get("datetime"));
- addVehicleDto
- .put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
- } else {
- addVehicleDto.put("activeDateTime", GeneralConstants.SPACE_VALUE);
- addVehicleDto
- .put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
- }
- PosUtil.prepareInsertAudit(addVehicleDto,
- userLoginName,
- datetime);
- PosUtil.prepareUpdateAudit(addVehicleDto,
- userLoginName,
- datetime);
- inputDto.put("vehicleDto", addVehicleDto);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- Dto vehicleDto = inputDto.getDto("vehicleDto");
- Vehicle entity = GsonUtil.fromDto(vehicleDto, Vehicle.class);
- vehicleDao.persist(entity);
- return new Dto(entity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment