Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.pos2.bo.postransaction;
- import java.util.List;
- import javax.persistence.*;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.Dto;
- 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.dao.PosItemDao;
- import org.jleaf.pos2.entity.PosItem;
- import org.jleaf.util.ValidationUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * IsTransactionItemExistsByProductCode
- *
- * @author Widana Nur Azis, Oct 24, 2016
- * @version 1.0
- */
- //@ formatter:off
- @Service
- @InfoIn(value = {
- @Info(name = "productCode", description = "productCode", type = String.class, required = true),
- @Info(name = "posId", description = "posId", type = Long.class, required = true)
- })
- @InfoOut(value = {
- @Info(name = "exists", description = "PosItem exists", type = Boolean.class, required = true),
- @Info(name = "productTransactionItemDto", description = "productTransactionItem Dto", type = Dto.class, required = true)
- })
- @ErrorList(errorKeys = {
- })
- //@ formatter:on
- public class IsTransactionItemExistsByProductCode extends AbstractBusinessFunction implements BusinessFunction {
- @Autowired
- PosItemDao posItemDao;
- @Override
- public String getDescription() {
- // TODO Auto-generated method stub
- return null;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- // TODO Auto-generated method stub
- ValidationUtil.valBlankOrNull(inputDto, "productCode");
- ValidationUtil.valBlankOrNull(inputDto, "posId");
- ValidationUtil.valDtoContainsKey(inputDto, "productCode");
- ValidationUtil.valDtoContainsKey(inputDto, "posId");
- Dto outputDto;
- boolean exists = false;
- Query query = posItemDao.createQuery(" SELECT a FROM org.jleaf.pos2.entity.PosItem a WHERE a.productCode = :productCode AND a.posId = :posId ");
- query.setParameter("productCode", inputDto.getString("productCode"));
- query.setParameter("posId", inputDto.getLong("posId"));
- List<PosItem> list = query.getResultList();
- outputDto = new Dto();
- if(list.size() > 0){
- exists = true;
- outputDto.put("productTransactionItemDto", new Dto(list.get(0)));
- }
- outputDto.put("exists", exists);
- return outputDto;
- }
- }
Add Comment
Please, Sign In to add comment