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.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Service;
- /**
- * Business Transactions: Add Region Customer
- *
- * @author Nadia , 14 Sept 2016
- */
- // @formatter:off
- @Service
- @InfoIn(value = {
- @Info(name = "tenantLoginId", description = "tenant Login Id", type = Long.class, required = true),
- @Info(name = "roleLoginId", description = "role Login Id", type = Long.class, required = true),
- @Info(name = "userLoginId", description = "user Login Id", 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 = Long.class),
- @Info(name = "tenantId", description = "tenant Id", type = Long.class),
- @Info(name = "regionId", description = "region Id", type = Long.class),
- @Info(name = "customerId", description = "customer 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 = Long.class)
- })
- // @formatter:on
- @ErrorList(errorKeys = { MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS })
- public class AddRegionCustomer extends DefaultBusinessTransaction implements
- BusinessTransaction {
- @Autowired
- RegionCustomerDao regionCustomerDao;
- @Autowired
- @Qualifier("findRegionCustomerByIndex")
- BusinessFunction findRegionCustomerByIndex;
- @Autowired
- @Qualifier("findRegionCustomerById")
- BusinessFunction findRegionCustomerById;
- @Autowired
- @Qualifier("valRegionCustomerExistsByIndex")
- BusinessFunction valRegionCustomerExistsByIndex;
- @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");
- ValidationUtil.valDatetime(inputDto, "datetime");
- Long id = inputDto.getLong("id");
- Long tenantLoginId = inputDto.getLong("tenantLoginId");
- 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");
- // Validation data (business key) is not exists yet in db (add)
- Dto inputDtoForIsRegionCustomerExistsByIndexDto = new Dto();
- Dto paramCheckUniqueDto = new Dto();
- paramCheckUniqueDto.put("regionId", regionId);
- paramCheckUniqueDto.put("customerId", customerId);
- Dto resultCheckUniqueDto = isRegionCustomerExistsByIndex
- .execute(paramCheckUniqueDto);
- if (resultCheckUniqueDto.getBoolean("exists")) {
- throw new CoreException(
- MasterExceptionConstantsForDlg.REGION_CUSTOMER_ALREADY_EXISTS,
- resultCheckUniqueDto.getLong("regionCustomerDto.regionId"),
- resultCheckUniqueDto.getLong("regionCustomerDto.customerId"));
- }
- Dto addRegionCustomerDto = new Dto();
- addRegionCustomerDto.put("id", id);
- addRegionCustomerDto.put("tenantLoginId", tenantLoginId);
- addRegionCustomerDto.put("roleLoginId", roleLoginId);
- addRegionCustomerDto.put("userLoginId", userLoginId);
- addRegionCustomerDto.put("datetime", datetime);
- addRegionCustomerDto.put("regionId", regionId);
- addRegionCustomerDto.put("customerId", customerId);
- // Set active datetime if active = Y
- if (inputDto.getString("active").equals(GeneralConstants.YES)) {
- addRegionCustomerDto.put("activeDateTime", inputDto.get("datetime"));
- addRegionCustomerDto
- .put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
- } else {
- addRegionCustomerDto.put("activeDateTime", GeneralConstants.SPACE_VALUE);
- addRegionCustomerDto
- .put("nonActiveDateTime", GeneralConstants.SPACE_VALUE);
- }
- prepareInsertAudit(addRegionCustomerDto,
- userLoginId,
- datetime);
- prepareUpdateAudit(addRegionCustomerDto,
- userLoginId,
- datetime);
- inputDto.put("regionCustomerDto", addRegionCustomerDto);
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment