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 = Long.class),
- @Info(name = "roleLoginId", description = "role login id", type = Long.class),
- @Info(name = "userLoginId", description = "user Id", type = Long.class),
- @Info(name = "datetime", description = "datetime", type = String.class),
- @Info(name = "regionId", description = "region Id", type = Long.class),
- @Info(name = "customerId", description = "customer Id", type = Long.class)
- })
- @InfoOut(value={
- @Info(name = "regionCustomerList", description = "region customer list("
- + " id, tenantId, regionId, customerId,"
- + " createDatetime, updateDatetime, createUserId, "
- + " updateUserId, version ))")
- })
- //@InfoOut(value = {
- // @Info(name = "id", description = "id", type = Long.class),
- // @Info(name = "tenantId", description = "tenantId", type = Long.class),
- // @Info(name = "regionId", description = "id", type = Long.class),
- // @Info(name = "customerId", description = "id", type =Long.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 = String.class)
- //
- //})
- @ErrorList(errorKeys = { MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS })
- public class AddRegionCustomer extends DefaultBusinessTransaction implements
- BusinessTransaction {
- private static final Logger log = LoggerFactory.getLogger(AddRegionCustomer.class);
- @Autowired
- @Qualifier("findRegionCustomerByIndex")
- private BusinessFunction findRegionCustomerByIndex;
- @Autowired
- @Qualifier("isRegionCustomerExistsById")
- BusinessFunction isRegionCustomerExistsById;
- @Autowired
- private RegionCustomerDao regionCustomerDao;
- @Override
- public String getDescription() {
- return " Add region customer ";
- }
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- log.debug("ini isi input Dto" + inputDto);
- // Pastikan input benar/lengkap
- ValidationUtil.valBlankOrNull(inputDto, "tenantLoginId");
- log.debug("tenantLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
- log.debug("roleLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
- log.debug("userLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "datetime");
- log.debug("datetime");
- ValidationUtil.valBlankOrNull(inputDto, "regionId");
- log.debug("regionId");
- ValidationUtil.valBlankOrNull(inputDto, "customerId");
- log.debug("customerId");
- Long tenantLoginId = inputDto.getLong("tenantLoginId");
- @SuppressWarnings("unused")
- Long roleLoginId = inputDto.getLong("roleLoginId");
- @SuppressWarnings("unused")
- Long userLoginId = inputDto.getLong("userLoginId");
- @SuppressWarnings("unused")
- String datetime = inputDto.getString("datetime");
- Long regionId = inputDto.getLong("regionId");
- Long customerId = inputDto.getLong("customerId");
- // validasi data (business key) is not exists yet in db (add)
- Dto inputFindRegionCustomerByIndexDto = new Dto();
- inputFindRegionCustomerByIndexDto.put("regionId", inputDto.getLong("regionId"));
- inputFindRegionCustomerByIndexDto.put("customerId", inputDto.getLong("customerId"));
- Dto outputFindRegionCustomerByIndexDto =findRegionCustomerByIndex.execute(inputFindRegionCustomerByIndexDto);
- if (outputFindRegionCustomerByIndexDto.getBoolean("exists")){
- throw new CoreException(MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS,
- outputFindRegionCustomerByIndexDto.getString("regionCustomerDto.regionId"),
- outputFindRegionCustomerByIndexDto.get("regionCustomerDto.customerId"));
- }
- // prepare data
- Dto dtoAdd = new Dto();
- dtoAdd.put("tenantId", tenantLoginId);
- dtoAdd.put("roleLoginId", roleLoginId);
- dtoAdd.put("regionId", regionId);
- dtoAdd.put("userLoginId", userLoginId);
- dtoAdd.put("customerId", customerId);
- dtoAdd.put("version", inputDto.getLong("version"));
- 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