use of org.pentaho.di.www.exception.DuplicateKeyException in project pentaho-kettle by pentaho.
the class GetJobStatusServletTest method doGetConflictingJobNamesUseHTMLTest.
@Test
public void doGetConflictingJobNamesUseHTMLTest() throws Exception {
KettleLogStore.init();
CarteStatusCache cacheMock = mock(CarteStatusCache.class);
getJobStatusServlet.cache = cacheMock;
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
when(mockHttpServletRequest.getContextPath()).thenReturn(GetJobStatusServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter("id")).thenReturn(null);
when(mockHttpServletRequest.getParameter("name")).thenReturn("dummy_job");
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
when(mockJobMap.getUniqueCarteObjectEntry(any())).thenThrow(new DuplicateKeyException());
getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_OK);
verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_CONFLICT);
}
use of org.pentaho.di.www.exception.DuplicateKeyException in project pentaho-kettle by pentaho.
the class GetJobStatusServletTest method doGetConflictingJobNamesUseXMLTest.
@Test
public void doGetConflictingJobNamesUseXMLTest() throws Exception {
KettleLogStore.init();
CarteStatusCache cacheMock = mock(CarteStatusCache.class);
getJobStatusServlet.cache = cacheMock;
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
when(mockHttpServletRequest.getContextPath()).thenReturn(GetJobStatusServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter("id")).thenReturn(null);
when(mockHttpServletRequest.getParameter("name")).thenReturn("dummy_job");
when(mockHttpServletRequest.getParameter("xml")).thenReturn("Y");
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
when(mockJobMap.getUniqueCarteObjectEntry(any())).thenThrow(new DuplicateKeyException());
getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_OK);
verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_CONFLICT);
}
use of org.pentaho.di.www.exception.DuplicateKeyException in project pentaho-kettle by pentaho.
the class GetJobImageServlet method doGet.
/**
*<div id="mindtouch">
* <h1>/kettle/jobImage</h1>
* <a name="GET"></a>
* <h2>GET</h2>
* <p>Generates and returns image of the specified job.
* Generates PNG image of the specified job currently present on Carte server. Job name and Carte job ID (optional)
* is used for specifying job to get information for. Response is binary of the PNG image.</p>
*
* <p><b>Example Request:</b><br />
* <pre function="syntax.xml">
* GET /kettle/jobImage?name=dummy_job
* </pre>
*
* </p>
* <h3>Parameters</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>name</th>
* <th>description</th>
* <th>type</th>
* </tr>
* <tr>
* <td>name</td>
* <td>Name of the job to be used for image generation.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>id</td>
* <td>Carte id of the job to be used for image generation.</td>
* <td>query, optional</td>
* </tr>
* </tbody>
* </table>
*
* <h3>Response Body</h3>
*
* <table class="pentaho-table">
* <tbody>
* <tr>
* <td align="right">binary streak:</td>
* <td>image</td>
* </tr>
* <tr>
* <td align="right">media types:</td>
* <td>image/png</td>
* </tr>
* </tbody>
* </table>
* <p>A binary PNG image or empty response if no job is found.</p>
*
* <h3>Status Codes</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>code</th>
* <th>description</th>
* </tr>
* <tr>
* <td>200</td>
* <td>Request was processed.</td>
* </tr>
* <tr>
* <td>500</td>
* <td>Internal server error occurs during request processing.</td>
* </tr>
* </tbody>
*</table>
*</div>
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "GetJobImageServlet.Log.JobImageRequested"));
}
String jobName = request.getParameter("name");
String id = request.getParameter("id");
boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
// ID is optional...
//
Job job;
CarteObjectEntry entry;
if (Utils.isEmpty(id)) {
try {
entry = getJobMap().getUniqueCarteObjectEntry(jobName);
} catch (DuplicateKeyException e) {
buildDuplicateResponse(response, jobName, useXML);
return;
}
if (entry == null) {
job = null;
} else {
id = entry.getId();
job = getJobMap().getJob(entry);
}
} else {
// Take the ID into account!
//
entry = new CarteObjectEntry(jobName, id);
job = getJobMap().getJob(entry);
}
try {
if (job != null) {
buildOkResponse(response, job);
} else {
buildNotFoundResponse(response, jobName, id, useXML);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.pentaho.di.www.exception.DuplicateKeyException in project pentaho-kettle by pentaho.
the class JobMap method getUniqueCarteObjectEntry.
public synchronized CarteObjectEntry getUniqueCarteObjectEntry(String jobName) throws DuplicateKeyException {
CarteObjectEntry entry = null;
boolean unique = true;
for (CarteObjectEntry key : jobMap.keySet()) {
if (unique && key.getName().equals(jobName)) {
unique = false;
entry = key;
} else if (!unique && key.getName().equals(jobName)) {
throw new DuplicateKeyException();
}
}
return entry;
}
Aggregations