· 4 years ago · May 24, 2021, 09:30 AM
1package org.jleaf.erp.sls.bo.apisobat;
2
3import javax.persistence.Query;
4
5import org.jleaf.core.AbstractBusinessFunction;
6import org.jleaf.core.BusinessFunction;
7import org.jleaf.core.CoreException;
8import org.jleaf.core.Dto;
9import org.jleaf.core.annotation.ErrorList;
10import org.jleaf.core.annotation.Info;
11import org.jleaf.core.annotation.InfoIn;
12import org.jleaf.core.annotation.InfoOut;
13import org.jleaf.core.dao.QueryBuilder;
14import org.jleaf.util.ValidationUtil;
15import org.springframework.beans.factory.annotation.Autowired;
16import org.springframework.stereotype.Service;
17
18import org.jleaf.erp.sls.dao.SalesOrderCashItemDao;
19import org.jleaf.erp.sls.SalesConstantsForSasa;
20import org.jleaf.erp.sls.SalesExceptionConstants;
21import org.jleaf.erp.sls.SalesExceptionConstantsForSasa;
22
23//@ formatter:off
24@Service
25@InfoIn(value = {
26 @Info(name = "apiKey", description = "apiKey", type = String.class, required = true)
27})
28@InfoOut(value = {
29
30})
31@ErrorList(errorKeys = {
32 SalesExceptionConstantsForSasa.SALES_ORDER_CASH_ITEM_ID_NOT_EXISTS
33})
34//@ formatter:on
35public class ValApiKeyForSobat extends AbstractBusinessFunction implements BusinessFunction {
36// private static Logger log = LoggerFactory.getLogger(ValSalesOrderCashItemExistsById.class);
37
38 @Autowired
39 private SalesOrderCashItemDao salesOrderCashItemDao;
40
41 @Override
42 public Dto execute(Dto inputDto) throws Exception {
43 ValidationUtil.valDtoContainsKey(inputDto, "apiKey");
44
45 String apiKey = inputDto.getString("apiKey");
46
47 QueryBuilder builder = new QueryBuilder();
48 builder.add(" SELECT B.parameter_value ");
49 builder.add("FROM t_parameter A ");
50 builder.add("INNER JOIN t_system_config B ON A.parameter_id = B.parameter_id ");
51 builder.add("WHERE parameter_code= :parameterCode ");
52
53 Query q = salesOrderCashItemDao.createNativeQuery(builder.toString());
54 q.setParameter("parameterCode", SalesConstantsForSasa.API_KEY_SOBAT_CODE);
55
56 Object apiKeyObject = q.getSingleResult();
57
58 String defApiKey = apiKeyObject.toString().isEmpty() ? "" : apiKeyObject.toString();
59
60 if (!defApiKey.equals(apiKey)) {
61 throw new CoreException(" Api Key Tidak Valid");
62 }
63
64 return null;
65 }
66
67 @Override
68 public String getDescription() {
69 return "Validation if api key not valid";
70 }
71}
72