87 lines
6.1 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>GetStationConfig.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> &gt; <a href="index.source.html" class="el_package">com.workbenchclassic</a> &gt; <span class="el_source">GetStationConfig.java</span></div><h1>GetStationConfig.java</h1><pre class="source lang-java linenums">package com.workbenchclassic;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
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;
import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.reflect.Method;
@Path(&quot;/getStationConfig&quot;)
<span class="nc" id="L21">public class GetStationConfig { // Klassenname geändert</span>
<span class="nc" id="L23"> private static final DBService DB_SERVICE = new DBService(&quot;dsMesMiiNJTA&quot;);</span>
<span class="nc" id="L24"> private static final ObjectMapper MAPPER = new ObjectMapper();</span>
<span class="nc" id="L25"> private static final Logger LOGGER = Logger.getLogger(DBService.class.getName());</span>
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getUserResponse(String jsonBody) {
String station;
try {
<span class="nc" id="L33"> JSONObject json = new JSONObject(jsonBody);</span>
<span class="nc" id="L34"> station = json.getString(&quot;station&quot;);</span>
<span class="nc" id="L35"> } catch (JSONException e) {</span>
<span class="nc" id="L36"> return Response.status(Response.Status.BAD_REQUEST)</span>
<span class="nc" id="L37"> .entity(&quot;{\&quot;error\&quot;:\&quot;Missing or invalid 'station' parameter\&quot;}&quot;)</span>
<span class="nc" id="L38"> .build();</span>
<span class="nc" id="L39"> }</span>
<span class="nc" id="L41"> String query = &quot;select code_nr , code_wert, btk.stamp as timestamp, bde_userid as changedBy from bde.txt_konfig btk join bde.pers_stamm bps on bps.pers_id=btk.user_id where code in (select kap_id from bde.kast where KAP_NR = '&quot;</span>
+ station + &quot;')&quot;;
// LOGGER.log(Level.INFO, &quot;Executing SQL query: {0}&quot;, query);
try {
<span class="nc" id="L46"> List&lt;Map&lt;String, Object&gt;&gt; rows = DB_SERVICE.dbConnectAndGetRows(query);</span>
<span class="nc bnc" id="L48" title="All 2 branches missed."> for (Map&lt;String, Object&gt; row : rows) {</span>
<span class="nc" id="L49"> Object tsVal = row.get(&quot;timestamp&quot;);</span>
<span class="nc bnc" id="L50" title="All 2 branches missed."> if (tsVal != null) {</span>
<span class="nc" id="L51"> row.put(&quot;timestamp&quot;, convertTimestamp(tsVal));</span>
}
<span class="nc" id="L53"> }</span>
// Vorbereitetes Statement nutzen
//
<span class="nc" id="L57"> return Response.ok(MAPPER.writeValueAsString(rows)).build();</span>
<span class="nc" id="L58"> } catch (SQLException e) {</span>
<span class="nc" id="L59"> LOGGER.log(Level.SEVERE, &quot;Database error&quot;, e);</span>
<span class="nc" id="L60"> return Response.status(Response.Status.INTERNAL_SERVER_ERROR)</span>
<span class="nc" id="L61"> .entity(String.format(&quot;{\&quot;error\&quot;:\&quot;DB error: %s\&quot;}&quot;, e.getMessage()))</span>
<span class="nc" id="L62"> .build();</span>
<span class="nc" id="L63"> } catch (JsonProcessingException e) {</span>
<span class="nc" id="L64"> LOGGER.log(Level.SEVERE, &quot;JSON processing error&quot;, e);</span>
<span class="nc" id="L65"> return Response.status(Response.Status.INTERNAL_SERVER_ERROR)</span>
<span class="nc" id="L66"> .entity(String.format(&quot;{\&quot;error\&quot;:\&quot;JSON processing error: %s\&quot;}&quot;, e.getMessage()))</span>
<span class="nc" id="L67"> .build();</span>
}
}
private Object convertTimestamp(Object val) {
<span class="nc bnc" id="L72" title="All 4 branches missed."> if (val != null &amp;&amp; &quot;oracle.sql.TIMESTAMP&quot;.equals(val.getClass().getName())) {</span>
try {
<span class="nc" id="L74"> Method m = val.getClass().getMethod(&quot;timestampValue&quot;);</span>
<span class="nc" id="L75"> return m.invoke(val); // returns a java.sql.Timestamp</span>
<span class="nc" id="L76"> } catch (ReflectiveOperationException e) {</span>
<span class="nc" id="L77"> throw new RuntimeException(&quot;Error converting oracle.sql.TIMESTAMP via reflection&quot;, e);</span>
}
<span class="nc bnc" id="L79" title="All 2 branches missed."> } else if (val instanceof java.sql.Timestamp) {</span>
<span class="nc" id="L80"> return val;</span>
} else {
<span class="nc" id="L82"> return val;</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>