Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.bo.customer.vs.rayon;
- 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.RegionCustomerDao;
- import org.jleaf.pos2.entity.RegionCustomer;
- 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 Region Customer
- *
- * @author Nadia , 21 Sept 2016
- */
- // @formatter:off
- @Service
- @InfoIn(value = {
- @Info(name = "tenantLoginId", description = "tenantLoginId", type = Long.class, required = true),
- @Info(name = "roleLoginId", description = "roleLoginId", type = Long.class, required = true),
- @Info(name = "userLoginId", description = "userLoginId", type = Long.class, required = true),
- @Info(name = "datetime", description = "datetime", type = String.class, required = true),
- @Info(name = "regionId", description = "role login id", type = Long.class),
- @Info(name = "customerId", description = "role login name", type = Long.class)
- })
- @InfoOut(value = {
- @Info(name = "id", description = "id", type = String.class),
- @Info(name = "tenantId", description = "tenantId", type = String.class),
- @Info(name = "regionId", description = "regionId", type = String.class),
- @Info(name = "customerId", description = "customerId", type = String.class),
- @Info(name = "createDateTime", description = "createDateTime", type = String.class),
- @Info(name = "updateDateTime", description = "updateDateTime", type = String.class),
- @Info(name = "createUserId", description = "createUserId", type = String.class),
- @Info(name = "updateUserId", description = "updateUserId", type = String.class),
- @Info(name = "version", description = "version", type = String.class)
- })
- // @formatter:on
- @ErrorList(errorKeys = { MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS })
- public class AddRegionCustomer extends DefaultBusinessTransaction implements
- BusinessTransaction {
- @Autowired
- VehicleDao regionCustomerDao;
- @Autowired
- @Qualifier("findRegionCustomerByIndex")
- BusinessFunction findRegionCustomerByIndex;
- @Autowired
- @Qualifier("findVehicleTypeById")
- BusinessFunction findVehicleTypeById;
- @Autowired
- @Qualifier("valRegionCustomerByIndex")
- BusinessFunction valRegionCustomerByIndex;
- @Autowired
- @Qualifier("isRegionCustomerExistsByIndex")
- BusinessFunction isRegionCustomerExistsByIndex;
- @Override
- public String getDescription() {
- return "Add Region Customer";
- }
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- ValidationUtil.valBlankOrNull(inputDto, "tenantLoginId");
- ValidationUtil.valDtoContainsKey(inputDto, "roleLoginId");
- ValidationUtil.valDtoContainsKey(inputDto, "userLoginId");
- ValidationUtil.valDtoContainsKey(inputDto, "datetime");
- ValidationUtil.valBlankOrNull(inputDto, "regionId");
- ValidationUtil.valBlankOrNull(inputDto, "customerId");
- Long licenseNo = inputDto.getLong("tenantLoginId").trim().toUpperCase();
- Long ownerName = inputDto.getLong("roleLoginId");
- Long chassisNo = inputDto.getLong("userLoginId");
- String engineNo = inputDto.getString("datetime");
- Long vehicleGroupCode = inputDto.getLong("regionId");
- Long vehicleTypeCode = inputDto.getLong("customerId");
- String id = tenantId
- .toUpperCase()
- .trim()
- .replace(GeneralConstants.SPACE_VALUE,
- GeneralConstants.EMPTY_VALUE);
- // Validasi harus referensi ke master region
- // panggil BF findRegionCustomerByIndex dengan inputan regionId
- Dto inputDtoForFindRegionCustomerByIndex = new Dto();
- inputDtoForFindRegionCustomerByIndex.put("regionId",
- regionId);
- findRegionCustomerByIndex.execute(inputDtoForFindRegionCustomerByIndex);
- // Validasi harus referensi ke master partner
- // panggil BF findRegionCustomerById dengan inputan regionId
- Dto inputDtoForFindRegionCustomerById = new Dto();
- inputDtoForFindRegionCustomerById.put("regionId", regionId);
- findRegionCustomerById.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("regionId", regionId);
- paramCheckUniqueDto.put("customerId", customerId);
- Dto resultCheckUniqueDto = isRegionCustomerByIndex
- .execute(paramCheckUniqueDto);
- if (resultCheckUniqueDto.getBoolean("exists")) {
- throw new CoreException(
- MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS,
- resultCheckUniqueDto.getString("regionCustomerDto.regionId"),
- resultCheckUniqueDto.getString("regionCustomerDto.customerId"));
- }
- Dto addRegionCustomerDto = new Dto();
- addVehicleDto.put("id", id);
- addVehicleDto.put("tenantId", tenantId);
- addVehicleDto.put("regionId", regionId);
- addVehicleDto.put("customerId", customerId);
- addVehicleDto.put("createDatetime", createDatetime);
- addVehicleDto.put("updateDatetime", updateDatetime);
- addVehicleDto.put("createUserId", createUserId);
- addVehicleDto.put("updateUserId", updateUserId);
- addVehicleDto.put("version", version);
- // 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(addRegionCustomerDto,
- userLoginName,
- datetime);
- PosUtil.prepareUpdateAudit(addRegionCustomerDto,
- userLoginName,
- datetime);
- inputDto.put("regionCustomerDto", regionCustomerDto);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- Dto regionCustomerDto = inputDto.getDto("regionCustomerDto");
- RegionCustomer entity = GsonUtil.fromDto(regionCustomerDto, RegionCustomer.class);
- regionCustomerDao.persist(entity);
- return new Dto(entity);
- }
- }
Add Comment
Please, Sign In to add comment