73 lines
5.5 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>GetERPGroups.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">GetERPGroups.java</span></div><h1>GetERPGroups.java</h1><pre class="source lang-java linenums">package com.workbenchclassic;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
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;
@Path(&quot;/getERPGroups&quot;)
<span class="nc" id="L22">public class GetERPGroups {</span>
<span class="nc" id="L24"> private static final DBService DB_SERVICE = new DBService(&quot;dsMesMiiNJTA&quot;);</span>
<span class="nc" id="L25"> private static final ObjectMapper MAPPER = new ObjectMapper();</span>
<span class="nc" id="L26"> private static final Logger LOGGER = Logger.getLogger(GetERPGroups.class.getName());</span>
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getERPResponse(String jsonBody) {
String station;
try {
<span class="nc" id="L34"> JSONObject json = new JSONObject(jsonBody);</span>
<span class="nc" id="L35"> station = json.getString(&quot;station&quot;);</span>
<span class="nc" id="L36"> } catch (JSONException e) {</span>
<span class="nc" id="L37"> return Response.status(Response.Status.BAD_REQUEST)</span>
<span class="nc" id="L38"> .entity(&quot;{\&quot;error\&quot;:\&quot;Missing or invalid 'station' parameter\&quot;}&quot;)</span>
<span class="nc" id="L39"> .build();</span>
<span class="nc" id="L40"> }</span>
<span class="nc" id="L42"> String query = &quot;SELECT distinct egr.ERP_GRP_NR, egr.ERP_GRP_BEZ, k.KAP_NR from bde.ERP_GRP eg join bde.ERP_GRP_REF egr on eg.ERP_GRP_ID =egr.ERP_GRP_ID join bde.kast k on eg.KAP_ID = k.KAP_ID where k.WERK_ID in (select werk_id from bde.kast where kap_nr = '&quot;</span>
+ station + &quot;')order by egr.ERP_GRP_NR&quot;;
<span class="nc" id="L45"> LOGGER.log(Level.INFO, &quot;Executing SQL query with station: {0}&quot;, station);</span>
try {
<span class="nc" id="L48"> List&lt;Map&lt;String, Object&gt;&gt; rows = DB_SERVICE.dbConnectAndGetRows(query);</span>
<span class="nc" id="L49"> List&lt;Map&lt;String, Object&gt;&gt; orderedRows = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L51" title="All 2 branches missed."> for (Map&lt;String, Object&gt; row : rows) {</span>
<span class="nc" id="L52"> Map&lt;String, Object&gt; ordered = new LinkedHashMap&lt;&gt;();</span>
<span class="nc" id="L53"> ordered.put(&quot;erp_grp_nr&quot;, row.get(&quot;erp_grp_nr&quot;));</span>
<span class="nc" id="L54"> ordered.put(&quot;erp_grp_bez&quot;, row.get(&quot;erp_grp_bez&quot;));</span>
<span class="nc" id="L55"> ordered.put(&quot;kap_nr&quot;, row.get(&quot;kap_nr&quot;));</span>
<span class="nc" id="L56"> orderedRows.add(ordered);</span>
<span class="nc" id="L57"> }</span>
<span class="nc" id="L59"> return Response.ok(MAPPER.writeValueAsString(orderedRows)).build();</span>
<span class="nc" id="L60"> } catch (SQLException e) {</span>
<span class="nc" id="L61"> LOGGER.log(Level.SEVERE, &quot;Database error&quot;, e);</span>
<span class="nc" id="L62"> return Response.status(Response.Status.INTERNAL_SERVER_ERROR)</span>
<span class="nc" id="L63"> .entity(String.format(&quot;{\&quot;error\&quot;:\&quot;DB error: %s\&quot;}&quot;, e.getMessage()))</span>
<span class="nc" id="L64"> .build();</span>
<span class="nc" id="L65"> } catch (JsonProcessingException e) {</span>
<span class="nc" id="L66"> LOGGER.log(Level.SEVERE, &quot;JSON processing error&quot;, e);</span>
<span class="nc" id="L67"> return Response.status(Response.Status.INTERNAL_SERVER_ERROR)</span>
<span class="nc" id="L68"> .entity(String.format(&quot;{\&quot;error\&quot;:\&quot;JSON processing error: %s\&quot;}&quot;, e.getMessage()))</span>
<span class="nc" id="L69"> .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>