Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.master.bo.customervsrayon;
- 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.erp.master.MasterExceptionConstantsForDlg;
- import org.jleaf.erp.master.dao.RegionCustomerDao;
- import org.jleaf.erp.master.entity.RegionCustomer;
- 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;
- /**
- *
- * BT Add Region Customer
- *
- * @author Nadia, Sept 14, 2016
- *
- */
- @Service
- @InfoIn(value = {
- @Info(name = "tenantLoginId", description = "tenant login id", type = String.class),
- @Info(name = "roleLoginId", description = "role login id", type = String.class),
- @Info(name = "userLoginId", description = "user Id", type = String.class),
- @Info(name = "datetime", description = "datetime", type = String.class),
- @Info(name = "regionId", description = "region Id", type = String.class),
- @Info(name = "customerId", description = "customer Id", type = String.class)
- })
- @InfoOut(value = {
- @Info(name = "id", description = "id", type = Long.class),
- @Info(name = "tenantId", description = "tenantId", type = String.class),
- @Info(name = "regionId", description = "id", type = String.class),
- @Info(name = "customerId", description = "id", 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 = String.class),
- @Info(name = "version", description = "version", type = String.class)
- })
- @ErrorList(errorKeys = { MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS })
- public class AddRegionCustomer extends DefaultBusinessTransaction implements
- BusinessTransaction {
- @Autowired
- @Qualifier("valRegionCustomerExistsById")
- BusinessFunction valRegionCustomerExistsById;
- @Autowired
- @Qualifier("findRegionCustomerById")
- BusinessFunction findRegionCustomerById;
- @Autowired
- @Qualifier("isRegionCustomerExistsById")
- BusinessFunction isRegionCustomerExistsById;
- @Autowired
- private RegionCustomerDao regionCustomerDao;
- @Override
- public String getDescription() {
- return " Add region customer ";
- }
- private static final Logger log = LoggerFactory
- .getLogger(AddRegionCustomer.class);
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- log.debug("ini isi input Dto" + inputDto);
- // Pastikan input benar/lengkap
- // ValidationUtil.valBlankOrNull(inputDto, "id");
- ValidationUtil.valBlankOrNull(inputDto, "tenantLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "datetime");
- ValidationUtil.valBlankOrNull(inputDto, "regionId");
- ValidationUtil.valBlankOrNull(inputDto, "customerId");
- // Long Id = inputDto.getLong("id");
- String tenantLoginId = inputDto.getString("tenantLoginId");
- @SuppressWarnings("unused")
- String roleLoginId = inputDto.getString("roleLoginId");
- @SuppressWarnings("unused")
- String userLoginId = inputDto.getString("userLoginId");
- @SuppressWarnings("unused")
- String datetime = inputDto.getString("datetime");
- String regionId = inputDto.getString("regionId");
- String customerId = inputDto.getString("customerId");
- // validasi data (business key) is not exists yet in db (add)
- Dto paramCheckUniqueDto = new Dto();
- paramCheckUniqueDto.put("tenantId", inputDto.getString("tenantLoginId"));
- paramCheckUniqueDto.put("regionId", inputDto.getString("regionId"));
- Dto resultCheckUniqueDto =findRegionCustomerById.execute(paramCheckUniqueDto);
- if (resultCheckUniqueDto.getBoolean("exists")){
- throw new CoreException(MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS,
- resultCheckUniqueDto.getString("regionCustomerDto.tenantId"),
- resultCheckUniqueDto.get("regionCustomerDto.regionId"));
- }
- // prepare data
- Dto dtoAdd = new Dto();
- dtoAdd.put("tenantLoginId", tenantLoginId);
- dtoAdd.put("regionId", regionId);
- dtoAdd.put("customerId", customerId);
- dtoAdd.put("active", inputDto.getString("active"));
- dtoAdd.put("version", inputDto.getLong("version"));
- // Set active datetime if active = Y
- if (dtoAdd.getString("active").equals(GeneralConstants.YES)) {
- dtoAdd.put("activeDateTime", inputDto.get("datetime"));
- dtoAdd.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
- } else {
- dtoAdd.put("activeDateTime", GeneralConstants.SPACE_VALUE);
- dtoAdd.put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
- }
- log.debug("ini yang di add" + dtoAdd);
- // Copy process date and userLoginId
- prepareInsertAudit(inputDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
- prepareUpdateAudit(inputDto, inputDto.getLong("userLoginId"), inputDto.getString("datetime"));
- inputDto.put("dtoAdd", dtoAdd);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- RegionCustomer entity = GsonUtil.fromDto(inputDto.getDto("dtoAdd"), RegionCustomer.class);
- //INSERT to database
- regionCustomerDao.persist(entity);
- return new Dto(entity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment