183 lines
15 KiB
HTML
183 lines
15 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="de"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>UpdateStation.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">backend</a> > <a href="index.source.html" class="el_package">com.workbenchclassic</a> > <span class="el_source">UpdateStation.java</span></div><h1>UpdateStation.java</h1><pre class="source lang-java linenums">package com.workbenchclassic;
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
|
|
import javax.ws.rs.Consumes;
|
|
import javax.ws.rs.POST;
|
|
import javax.ws.rs.Path;
|
|
import javax.ws.rs.Produces;
|
|
import javax.ws.rs.core.MediaType;
|
|
import javax.ws.rs.core.Response;
|
|
|
|
/**
|
|
* UpdateStation performs database insert depending on DB vendor (MSSQL or
|
|
* Oracle).
|
|
*/
|
|
@Path("/updateStations")
|
|
<span class="nc" id="L18">public class UpdateStation {</span>
|
|
|
|
/** Our DB service for queries (JNDI, etc.). */
|
|
<span class="nc" id="L21"> private final DBService dbService = new DBService("dsTranNJTA");</span>
|
|
|
|
@POST
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
public Response doUpdate(String jsonBody) {
|
|
try {
|
|
// 1) JSON parsen
|
|
<span class="nc" id="L29"> JSONObject json = new JSONObject(jsonBody);</span>
|
|
<span class="nc" id="L30"> String station = json.getString("station"); // z.B. "TEST"</span>
|
|
<span class="nc" id="L31"> JSONArray dataArray = json.getJSONArray("data"); // Liste mit Objekten</span>
|
|
|
|
// 2) DB-Vendor abfragen
|
|
<span class="nc" id="L34"> String vendor = dbService.getDatabaseProductName();</span>
|
|
<span class="nc" id="L35"> System.out.println("Aktueller DB-Vendor: " + vendor);</span>
|
|
<span class="nc" id="L36"> GetMetadata metadata = new GetMetadata();</span>
|
|
<span class="nc" id="L37"> String extPlantResponseString = metadata.getExtPlantJson(station);</span>
|
|
<span class="nc" id="L38"> JSONObject extPlantResponse = new JSONObject(extPlantResponseString);</span>
|
|
|
|
<span class="nc" id="L40"> String errorCode = extPlantResponse.optString("errorCode", "0");</span>
|
|
<span class="nc bnc" id="L41" title="All 2 branches missed."> if (!"0".equals(errorCode)) {</span>
|
|
// Return an HTTP 400 or 500 with that JSON
|
|
<span class="nc" id="L43"> return Response.status(Response.Status.BAD_REQUEST).entity(extPlantResponse.toString()).build();</span>
|
|
}
|
|
// 3) werknummer ermitteln
|
|
|
|
// werkResultJson könnte z.B. so aussehen:
|
|
// {"errorCode":"0","errorMessage":"Done","data":"[{\"werknummer\":\"ABC\"}]"}
|
|
|
|
<span class="nc" id="L50"> String werkData = extPlantResponse.optString("data", "[]");</span>
|
|
<span class="nc" id="L51"> JSONArray werkArr = new JSONArray(werkData);</span>
|
|
|
|
<span class="nc" id="L53"> String WERK_NR = null;</span>
|
|
<span class="nc" id="L54"> String COMPANY_NO = null;</span>
|
|
<span class="nc" id="L55"> String CLIENT_NO = null;</span>
|
|
<span class="nc bnc" id="L56" title="All 2 branches missed."> if (werkArr.length() > 0) {</span>
|
|
<span class="nc" id="L57"> JSONObject row = werkArr.getJSONObject(0);</span>
|
|
<span class="nc" id="L58"> WERK_NR = row.optString("ext_company_nr", null);</span>
|
|
<span class="nc" id="L59"> COMPANY_NO = row.optString("werk_nr", null);</span>
|
|
<span class="nc" id="L60"> CLIENT_NO = row.optString("client_nr", null);</span>
|
|
}
|
|
|
|
<span class="nc" id="L63"> boolean isMSSQL = "Microsoft SQL Server".equals(vendor);</span>
|
|
<span class="nc" id="L64"> boolean isOracle = "Oracle".equals(vendor);</span>
|
|
|
|
// 4) ZUERST den tran_idocstatus-Eintrag anlegen
|
|
<span class="nc bnc" id="L67" title="All 2 branches missed."> if (isMSSQL) {</span>
|
|
<span class="nc" id="L68"> String insertIdocstatusMSSQL = "INSERT INTO xtran.tran_idocstatus "</span>
|
|
+ "(ID, DATE_CREATION, ewstatus, errorcode, content_type, source) "
|
|
+ "VALUES ( (NEXT VALUE FOR xtran.seq_tranidocstatus), getdate(), 1, 0, 60, 0)";
|
|
<span class="nc" id="L71"> dbService.dbConnect(insertIdocstatusMSSQL);</span>
|
|
|
|
<span class="nc bnc" id="L73" title="All 2 branches missed."> } else if (isOracle) {</span>
|
|
<span class="nc" id="L74"> String insertIdocstatusOracle = "INSERT INTO tran.tran_idocstatus "</span>
|
|
+ "(ID, DATE_CREATION, ewstatus, errorcode, content_type, source) "
|
|
+ "VALUES ( TRAN.SEQ_TRANIDOCSTATUS.nextval, sysdate, 1, 0, 60, 0)";
|
|
<span class="nc" id="L77"> dbService.dbConnect(insertIdocstatusOracle);</span>
|
|
|
|
<span class="nc" id="L79"> } else {</span>
|
|
<span class="nc" id="L80"> System.out.println("DB-Vendor nicht implementiert: " + vendor);</span>
|
|
}
|
|
|
|
// 5) Für JEDES Element in "data" => Insert in cell, machine_group, station
|
|
<span class="nc bnc" id="L84" title="All 2 branches missed."> for (int i = 0; i < dataArray.length(); i++) {</span>
|
|
<span class="nc" id="L85"> JSONObject obj = dataArray.getJSONObject(i);</span>
|
|
|
|
<span class="nc" id="L87"> String lineID = obj.getString("line_nr");</span>
|
|
<span class="nc" id="L88"> String lineBez = obj.getString("line_bez");</span>
|
|
<span class="nc" id="L89"> String maGroupID = obj.getString("ma_grp_nr");</span>
|
|
<span class="nc" id="L90"> String maGroupBez = obj.getString("ma_grp_bez");</span>
|
|
<span class="nc" id="L91"> String kapID = obj.getString("kap_nr");</span>
|
|
<span class="nc" id="L92"> String kapBez = obj.getString("kap_bez");</span>
|
|
|
|
<span class="nc bnc" id="L94" title="All 2 branches missed."> if (isMSSQL) {</span>
|
|
// tran_cell
|
|
String insertCellMSSQL = "INSERT INTO xtran.tran_cell "
|
|
+ "(IDOC_ID, TRAN_ID, SOURCE, STATUS, CREATED, STAMP, CLIENT_NO, COMPANY_NO, PLANT_NO, CELL_NUMBER, CELL_DESC) "
|
|
+ "VALUES ( (SELECT MAX(id) FROM xtran.tran_idocstatus),"
|
|
+ " (NEXT VALUE FOR xtran.SEQ_TRAN_CELL),"
|
|
+ " 0,0, getdate(), getdate(),"
|
|
<span class="nc bnc" id="L101" title="All 4 branches missed."> + " '" + (CLIENT_NO != null ? CLIENT_NO : "") + "','" + (WERK_NR != null ? WERK_NR : "")</span>
|
|
<span class="nc bnc" id="L102" title="All 2 branches missed."> + "', '" + (COMPANY_NO != null ? COMPANY_NO : "") + "',"</span>
|
|
+ " '" + lineID + "', '" + lineBez + "')";
|
|
<span class="nc" id="L104"> dbService.dbConnect(insertCellMSSQL);</span>
|
|
|
|
// tran_machine_group
|
|
String insertMachineGroupMSSQL = "INSERT INTO xtran.tran_machine_group "
|
|
+ "(IDOC_ID, TRAN_ID, SOURCE, STATUS, CREATED, STAMP, CLIENT_NO, COMPANY_NO, PLANT_NO, "
|
|
+ " PARENT_CELL_NUMBER, MACHINE_GROUP_NUMBER, MACHINE_GROUP_DESC) "
|
|
+ "VALUES ( (SELECT MAX(id) FROM xtran.tran_idocstatus),"
|
|
+ " (NEXT VALUE FOR xtran.SEQ_TRAN_MACHINE_GROUP),"
|
|
+ " 0,0, getdate(), getdate(),"
|
|
<span class="nc bnc" id="L113" title="All 4 branches missed."> + " '" + (CLIENT_NO != null ? CLIENT_NO : "") + "','" + (WERK_NR != null ? WERK_NR : "")</span>
|
|
<span class="nc bnc" id="L114" title="All 2 branches missed."> + "', '" + (COMPANY_NO != null ? COMPANY_NO : "") + "',"</span>
|
|
+ " '" + lineID + "', '" + maGroupID + "', '" + maGroupBez + "')";
|
|
<span class="nc" id="L116"> dbService.dbConnect(insertMachineGroupMSSQL);</span>
|
|
|
|
// tran_station
|
|
String insertStationMSSQL = "INSERT INTO xtran.tran_station "
|
|
+ "(IDOC_ID, TRAN_ID, SOURCE, STATUS, CREATED, STAMP, CLIENT_NO, COMPANY_NO, PLANT_NO, "
|
|
+ " PARENT_MACHINE_GROUP_NUMBER, STATION_NUMBER, STATION_DESC, STATION_TYPE) "
|
|
+ "VALUES ( (SELECT MAX(id) FROM xtran.tran_idocstatus),"
|
|
+ " (NEXT VALUE FOR xtran.SEQ_TRAN_STATION),"
|
|
+ " 0,0, getdate(), getdate(),"
|
|
<span class="nc bnc" id="L125" title="All 4 branches missed."> + " '" + (CLIENT_NO != null ? CLIENT_NO : "") + "','" + (WERK_NR != null ? WERK_NR : "")</span>
|
|
<span class="nc bnc" id="L126" title="All 2 branches missed."> + "', '" + (COMPANY_NO != null ? COMPANY_NO : "") + "',"</span>
|
|
+ " '" + maGroupID + "', '" + kapID + "', '" + kapBez + "', 'B')";
|
|
<span class="nc" id="L128"> dbService.dbConnect(insertStationMSSQL);</span>
|
|
|
|
<span class="nc bnc" id="L130" title="All 2 branches missed."> } else if (isOracle) {</span>
|
|
// tran_cell
|
|
String insertCellOracle = "INSERT INTO tran.tran_cell "
|
|
+ "(IDOC_ID, TRAN_ID, SOURCE, STATUS, CREATED, STAMP, CLIENT_NO, COMPANY_NO, PLANT_NO, CELL_NUMBER, CELL_DESC) "
|
|
+ "VALUES ( (SELECT MAX(id) FROM tran.tran_idocstatus), "
|
|
+ " tran.seq_tran_cell.nextval, 0,0, sysdate, sysdate, "
|
|
<span class="nc bnc" id="L136" title="All 4 branches missed."> + " '" + (CLIENT_NO != null ? CLIENT_NO : "") + "','" + (WERK_NR != null ? WERK_NR : "")</span>
|
|
<span class="nc bnc" id="L137" title="All 2 branches missed."> + "', '" + (COMPANY_NO != null ? COMPANY_NO : "") + "',"</span>
|
|
+ " '" + lineID + "', '" + lineBez + "')";
|
|
<span class="nc" id="L139"> dbService.dbConnect(insertCellOracle);</span>
|
|
|
|
// tran_machine_group
|
|
String insertMachineGroupOracle = "INSERT INTO tran.tran_machine_group "
|
|
+ "(IDOC_ID, TRAN_ID, SOURCE, STATUS, CREATED, STAMP, CLIENT_NO, COMPANY_NO, PLANT_NO, "
|
|
+ " PARENT_CELL_NUMBER, MACHINE_GROUP_NUMBER, MACHINE_GROUP_DESC) "
|
|
+ "VALUES ( (SELECT MAX(id) FROM tran.tran_idocstatus), "
|
|
+ " tran.seq_tran_machine_group.nextval, 0,0, sysdate, sysdate, "
|
|
<span class="nc bnc" id="L147" title="All 4 branches missed."> + " '" + (CLIENT_NO != null ? CLIENT_NO : "") + "','" + (WERK_NR != null ? WERK_NR : "")</span>
|
|
<span class="nc bnc" id="L148" title="All 2 branches missed."> + "', '" + (COMPANY_NO != null ? COMPANY_NO : "") + "',"</span>
|
|
+ " '" + lineID + "', '" + maGroupID + "', '" + maGroupBez + "')";
|
|
<span class="nc" id="L150"> dbService.dbConnect(insertMachineGroupOracle);</span>
|
|
|
|
// tran_station
|
|
String insertStationOracle = "INSERT INTO tran.tran_station "
|
|
+ "(IDOC_ID, TRAN_ID, SOURCE, STATUS, CREATED, STAMP, CLIENT_NO, COMPANY_NO, PLANT_NO, "
|
|
+ " PARENT_MACHINE_GROUP_NUMBER, STATION_NUMBER, STATION_DESC, STATION_TYPE) "
|
|
+ "VALUES ( (SELECT MAX(id) FROM tran.tran_idocstatus), "
|
|
+ " tran.seq_tran_station.nextval, 0,0, sysdate, sysdate, "
|
|
<span class="nc bnc" id="L158" title="All 4 branches missed."> + " '" + (CLIENT_NO != null ? CLIENT_NO : "") + "','" + (WERK_NR != null ? WERK_NR : "")</span>
|
|
<span class="nc bnc" id="L159" title="All 2 branches missed."> + "', '" + (COMPANY_NO != null ? COMPANY_NO : "") + "',"</span>
|
|
+ " '" + maGroupID + "', '" + kapID + "', '" + kapBez + "', 'B')";
|
|
<span class="nc" id="L161"> dbService.dbConnect(insertStationOracle);</span>
|
|
|
|
<span class="nc" id="L163"> } else {</span>
|
|
<span class="nc" id="L164"> System.out.println("Anderer/nicht implementierter DB-Vendor: " + vendor);</span>
|
|
}
|
|
}
|
|
|
|
// 6) Erfolgreich fertig
|
|
<span class="nc" id="L169"> JSONObject response = new JSONObject();</span>
|
|
<span class="nc" id="L170"> response.put("status", "ok");</span>
|
|
<span class="nc" id="L171"> response.put("message", "Daten wurden erfolgreich verarbeitet.");</span>
|
|
<span class="nc" id="L172"> return Response.ok(response.toString()).build();</span>
|
|
|
|
<span class="nc" id="L174"> } catch (Exception e) {</span>
|
|
<span class="nc" id="L175"> e.printStackTrace();</span>
|
|
<span class="nc" id="L176"> JSONObject error = new JSONObject();</span>
|
|
<span class="nc" id="L177"> error.put("status", "error");</span>
|
|
<span class="nc" id="L178"> error.put("message", e.getMessage());</span>
|
|
<span class="nc" id="L179"> return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error.toString()).build();</span>
|
|
}
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.4.201905082037</span></div></body></html> |