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 = "userLoginId", type = Long.class),
- @Info(name = "datetime", description = "datetime", type = String.class),
- @Info(name = "regionId", description = "regionId", type = Long.class),
- @Info(name = "customerId", description = "customerId", type = Long.class)
- })
- @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 {
- @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, "tenantLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "roleLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "userLoginId");
- ValidationUtil.valBlankOrNull(inputDto, "datetime");
- ValidationUtil.valBlankOrNull(inputDto, "regionId");
- ValidationUtil.valBlankOrNull(inputDto, "customerId");
- Long tenantLoginId = inputDto.getLong("tenantLoginId");
- @SuppressWarnings("unused")
- Long roleLoginId = inputDto.getLong("roleLoginId");
- Long userLoginId = inputDto.getLong("userLoginId");
- String datetime = inputDto.getString("datetime");
- Long regionId = inputDto.getLong("regionId");
- Long customerId = inputDto.getLong("customerId");
- // validasi region customer exists
- Dto inputIsRegionCustomerExistsByIdDto = new Dto();
- inputIsRegionCustomerExistsByIdDto.put("tenantLoginId", tenantLoginId);
- inputIsRegionCustomerExistsByIdDto.put("regionId", regionId);
- inputIsRegionCustomerExistsByIdDto.put("customerId", customerId);
- Dto outputIsRegionCustomerExistsByIdDto = isRegionCustomerExistsById
- .execute(inputIsRegionCustomerExistsByIdDto);
- if (outputIsRegionCustomerExistsByIdDto.getBoolean("exists")) {
- throw new CoreException(MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS, tenantLoginId);
- }
- // 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);
- // Prepare audit data - create_datetime, create_user_id,
- // update_datetime, update_user_id
- prepareInsertAudit(dtoAdd, userLoginId, datetime);
- prepareUpdateAudit(dtoAdd, userLoginId, 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