135 lines
6.0 KiB
Java
135 lines
6.0 KiB
Java
// package org.sadigit.scheduling.Maximo;
|
|
|
|
// import com.google.gson.Gson;
|
|
// import com.google.gson.GsonBuilder;
|
|
// import
|
|
// com.iconpln.schedulerintegmaximoupdate.Interceptor.AuthenticationInterceptor;
|
|
// import com.iconpln.schedulerintegmaximoupdate.dao.TrafoDao;
|
|
// import com.iconpln.schedulerintegmaximoupdate.model.dto.DataTrafo;
|
|
// import com.iconpln.schedulerintegmaximoupdate.model.payload.ResponseTrafo;
|
|
// import lombok.extern.slf4j.Slf4j;
|
|
// import org.springframework.beans.factory.annotation.Autowired;
|
|
// import org.springframework.beans.factory.annotation.Value;
|
|
// import org.springframework.http.HttpEntity;
|
|
// import org.springframework.http.HttpMethod;
|
|
// import org.springframework.http.ResponseEntity;
|
|
// import org.springframework.http.client.ClientHttpRequestInterceptor;
|
|
// import org.springframework.http.converter.StringHttpMessageConverter;
|
|
// import
|
|
// org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
// import org.springframework.stereotype.Component;
|
|
// import org.springframework.web.client.RestTemplate;
|
|
|
|
// import java.io.IOException;
|
|
// import java.text.SimpleDateFormat;
|
|
// import java.util.*;
|
|
|
|
// @Slf4j
|
|
// @Component("jobGetTrafoUpdate")
|
|
// public class JobGetTrafoUpdate {
|
|
|
|
// @Value("${url.api.maximo1}")
|
|
// private String URL;
|
|
|
|
// @Value("${auth.api.maximo}")
|
|
// private String AUTH;
|
|
|
|
// // @Value("${content.api.maximo}")
|
|
// // private String CONTENT;
|
|
|
|
// @Autowired
|
|
// private TrafoDao trafoDao;
|
|
|
|
// public void executeGetTrafoUpdate() throws IOException {
|
|
// log.info("--- JOB GET TRAFO ---");
|
|
// List<Map<String, String>> lstMap = getDataSiapAmbil();
|
|
// // log.info("JML DATA CXUNIT : {}", lstMap.size());
|
|
// if (!lstMap.isEmpty()) {
|
|
// for (Map<String, String> map : lstMap) {
|
|
// if (map.get("tipe").toString().equals("TRAFO") ) {
|
|
// ResponseTrafo response = getTrafoUpdateEndPoint(map);
|
|
// log.info("JML DATA TRAFO : {}", response.getMember().size());
|
|
// log.info("CXUNIT : {}", map.get("unitid").toString());
|
|
// log.info("TIPE : {}", map.get("tipe").toString());
|
|
|
|
// if (response.getMember() != null) {
|
|
// Map<String, String> mapSimpanDataTrafoKolektif =
|
|
// SimpanDataTrafoKolektif(map.get("unitid").toString(), response.getMember());
|
|
// if (mapSimpanDataTrafoKolektif.get("return").equals("1")) {
|
|
// log.info("SIMPAN DATA TRAFO : {}", mapSimpanDataTrafoKolektif);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// private List<Map<String, String>> getDataSiapAmbil() {
|
|
// List<Map<String, String>> lstMap = trafoDao.getAmbilDataTrafo();
|
|
// return lstMap;
|
|
// }
|
|
|
|
// private ResponseTrafo getTrafoUpdateEndPoint (Map<String, String> map) {
|
|
// RestTemplate restTemplate = new RestTemplate();
|
|
// Map<String, Object> mapParams = new HashMap<>();
|
|
// ResponseTrafo response = new ResponseTrafo();
|
|
// ResponseEntity<ResponseTrafo> res = null;
|
|
// try {
|
|
// ClientHttpRequestInterceptor authenticationInterceptor = new
|
|
// AuthenticationInterceptor(AUTH);
|
|
// restTemplate.setInterceptors(Collections.singletonList(authenticationInterceptor));
|
|
// restTemplate.getMessageConverters().add(new
|
|
// MappingJackson2HttpMessageConverter());
|
|
// restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
|
|
|
|
// Date date = new Date();
|
|
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
// // String url = URL +
|
|
// "os/mxasset_test?oslc.select=assetnum,apkt_numbers,description,location--assetlocation,tujdnumber,cxunit,cxclassificationdesc,installvendor,installdate,actualoprdate,changedate,assetspec,location.saddresscode,locations{serviceaddress.longitudex,serviceaddress.latitudey,serviceaddress.FORMATTEDADDRESS,cxunit},lochierarchy,manufacturer&oslc.where=status=\"OPERATING\"
|
|
// and cxclassificationdesc=\"Trafo\" and
|
|
// cxunit=\"{unitid}\"&ignorecollectionref=1&lean=1&collectioncount=1";
|
|
// // String url = URL +
|
|
// "os/mxasset_test?oslc.select=assetnum,apkt_numbers,description,location--assetlocation,tujdnumber,cxunit,cxclassificationdesc,installvendor,installdate,actualoprdate,changedate,assetspec,location.saddresscode,locations{serviceaddress.longitudex,serviceaddress.latitudey,serviceaddress.FORMATTEDADDRESS,cxunit},lochierarchy,manufacturer&oslc.where=status=\"OPERATING\"
|
|
// and cxclassificationdesc=\"Trafo\" and cxunit=\"{unitid}\" and
|
|
// changedate>\"{currentdate}\"&ignorecollectionref=1&lean=1&collectioncount=1";
|
|
// String url = URL +
|
|
// "os/mxasset_test?oslc.select=assetnum,apkt_numbers,description,location--assetlocation,tujdnumber,cxunit,cxclassificationdesc,installvendor,installdate,actualoprdate,changedate,assetspec,location.saddresscode,locations{serviceaddress.longitudex,serviceaddress.latitudey,serviceaddress.FORMATTEDADDRESS,cxunit},lochierarchy,manufacturer&oslc.where=status=\"OPERATING\"
|
|
// and cxclassificationdesc=\"Trafo\" and cxunit=\"{unitid}\" and
|
|
// changedate>\"2021-08-05\"&ignorecollectionref=1&lean=1&collectioncount=1";
|
|
// Object mapValue =
|
|
// "{serviceaddress.longitudex,serviceaddress.latitudey,serviceaddress.FORMATTEDADDRESS,cxunit}";
|
|
// mapParams.put("serviceaddress.longitudex,serviceaddress.latitudey,serviceaddress.FORMATTEDADDRESS,cxunit",
|
|
// mapValue);
|
|
// mapParams.put("unitid", map.get("unitid").toString());
|
|
// mapParams.put("currentdate", formatter.format(date));
|
|
// // Map mapParam = new HashMap();
|
|
// // res = restTemplate.getForEntity(url, null, ResponseTrafo.class, mapParam);
|
|
// res = restTemplate.exchange(url, HttpMethod.GET, HttpEntity.EMPTY,
|
|
// ResponseTrafo.class, mapParams);
|
|
// // log.info("res : {}", res);
|
|
|
|
// Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
// String jsonifyresponse = gson.toJson(res.getBody());
|
|
// log.info("RESPONSE : {}", jsonifyresponse);
|
|
|
|
// } catch (Exception ex) {
|
|
// ex.printStackTrace();
|
|
// log.error("ERROR GET TRAFO : {}", ex);
|
|
// // response.setRc("01");
|
|
// response.setMessage("Error, "+ex.getMessage());
|
|
// response.setMember(null);
|
|
// return response;
|
|
// }
|
|
|
|
// return res.getBody();
|
|
// }
|
|
|
|
// private Map<String, String> SimpanDataTrafoKolektif(String unitid,
|
|
// List<DataTrafo> lstTrafo){
|
|
// Map<String, String> mapResult = new HashMap<>();
|
|
// mapResult = trafoDao.SimpanDataTrafoKolektif(unitid, lstTrafo);
|
|
// return mapResult;
|
|
// }
|
|
|
|
// } |