· 5 years ago · May 19, 2020, 09:36 AM
1package org.jleaf.erp.pos_intgr.bo.hrms;
2
3import okhttp3.Call;
4import okhttp3.MediaType;
5import okhttp3.OkHttpClient;
6import okhttp3.Request;
7import okhttp3.RequestBody;
8import okhttp3.Response;
9
10import org.jleaf.core.AbstractBusinessFunction;
11import org.jleaf.core.BusinessFunction;
12import org.jleaf.core.CoreException;
13import org.jleaf.core.Dto;
14import org.jleaf.core.annotation.Info;
15import org.jleaf.core.annotation.InfoIn;
16import org.jleaf.core.annotation.InfoOut;
17import org.jleaf.erp.pos_intgr.PosIntegrationConstantsForSasa;
18import org.jleaf.erp.pos_intgr.PosIntegrationExceptionConstantsForSasa;
19import org.slf4j.Logger;
20import org.slf4j.LoggerFactory;
21import org.springframework.beans.factory.annotation.Autowired;
22import org.springframework.core.env.Environment;
23import org.springframework.stereotype.Service;
24
25/**
26 * Api Get Data Karyawan
27 *
28 * @author Gea, March 12, 2020
29 *
30 */
31// @formatter:off
32@Service
33@InfoIn({
34 @Info(name="sessionUuid", description="Session uuid", type=String.class, required=true),
35 @Info(name="apiKey", description="Api key", type=String.class, required=false),
36 @Info(name="tenantCode", description="Tenant code", type=String.class, required=true),
37 @Info(name="datetime", description="Datetime", type=String.class, required=true),
38 @Info(name="username", description="Username", type=String.class, required=true),
39 @Info(name="nip", description="Nip", type=String.class, required=true)
40})
41@InfoOut({
42 @Info(name="sessionUuid", description="Session uuid", type=String.class, required=true),
43 @Info(name="requestUuid", description="Request uuid", type=String.class, required=true),
44 @Info(name="success", description="Success", type=String.class, required=false),
45 @Info(name="errorMessage", description="Error message", type=String.class, required=true),
46 @Info(name="errorCode", description="Error code", type=String.class, required=true),
47 @Info(name="nip", description="Nip", type=String.class, required=true),
48 @Info(name="perusahaan", description="Perusahaan", type=String.class, required=true)
49})
50//@formatter:on
51public class ApiGetDataKaryawan extends AbstractBusinessFunction implements BusinessFunction {
52
53 private Logger log = LoggerFactory.getLogger(ApiGetDataKaryawan.class);
54
55 @Autowired
56 Environment env;
57
58 @Autowired
59 OkHttpClient httpClient;
60
61 @Override
62 public Dto execute(Dto inputDto) throws Exception {
63
64 String apiKey = PosIntegrationConstantsForSasa.API_KEY_HRMS;
65 String tenantCode = PosIntegrationConstantsForSasa.TENANT_CODE;
66
67 inputDto.put("apikey", apiKey);
68 inputDto.put("tenant_code", tenantCode);
69
70 log.debug("INPUT DTO "+inputDto);
71
72 String baseUrl = env.getProperty("jleaf.hrms.baseUrl");
73 log.debug("BASE URL "+baseUrl);
74 String url = baseUrl+"/employee-status";
75
76 RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), inputDto.toString());
77
78 Request request = new Request.Builder().url(url).post(body).build();
79
80 Call call = httpClient.newCall(request);
81 Response response = call.execute();
82 String reString = response.body().string();
83 Dto responseCallApi = new Dto (reString);
84 if( response.code() == 200 ){
85
86 if (responseCallApi.getBoolean("success") != true) {
87 log.debug("Masuk Exception");
88 throw new CoreException(PosIntegrationExceptionConstantsForSasa.ERROR_CALL_API_WISER, url, responseCallApi.get("error_message"));
89 }
90
91 }else {
92 log.debug("RESPONSE EMPTY");
93 }
94
95 Dto outputDto = new Dto(responseCallApi);
96 return outputDto;
97
98 }
99
100 @Override
101 public String getDescription() {
102 return "Api Get Data Karyawan";
103 }
104
105}