Skip to content

Commit

Permalink
Fix bugs and inconsistencies in GUI 3.0 (frankframework#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsm5 authored Mar 11, 2020
1 parent 2cf862d commit d631352
Show file tree
Hide file tree
Showing 26 changed files with 623 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
*/
public interface IMessageBrowser extends IXAEnabled {

enum SortOrder { NONE, ASC, DESC };

/**
* Gets an enumeration of messages. This includes setting up connections, sessions etc.
*/
IMessageBrowsingIterator getIterator() throws ListenerException;
IMessageBrowsingIterator getIterator(Date startTime, Date endTime, boolean forceDescending) throws ListenerException;
IMessageBrowsingIterator getIterator(Date startTime, Date endTime, SortOrder order) throws ListenerException;

/**
* Retrieves the message context as an iteratorItem.
* The result can be used in the methods above that use an iteratorItem as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.configuration.ConfigurationWarnings;
import nl.nn.adapterframework.core.IMessageBrowser;
import nl.nn.adapterframework.core.IMessageBrowsingIterator;
import nl.nn.adapterframework.core.IMessageBrowsingIteratorItem;
import nl.nn.adapterframework.core.ITransactionalStorage;
Expand Down Expand Up @@ -507,19 +508,22 @@ private String getListClause() {
","+getCommentField()+ " FROM "+getPrefix()+getTableName();
}

private String getSelectListQuery(IDbmsSupport dbmsSupport, Date startTime, Date endTime, boolean forceDescending) {
private String getSelectListQuery(IDbmsSupport dbmsSupport, Date startTime, Date endTime, IMessageBrowser.SortOrder order) {
String whereClause=null;
if (startTime!=null) {
whereClause=getDateField()+">=?";
}
if (endTime!=null) {
whereClause=Misc.concatStrings(whereClause, " AND ", getDateField()+"<?");
}
if(order.equals(SortOrder.NONE)) { //If no order has been set, use the default (DESC for messages and ASC for errors)
order = SortOrder.valueOf(getOrder());
}

return "SELECT "+provideIndexHintAfterFirstKeyword(dbmsSupport)+provideFirstRowsHintAfterFirstKeyword(dbmsSupport)+ getListClause()+ getWhereClause(whereClause,false)+
" ORDER BY "+getDateField()+(forceDescending?" DESC ":" "+getOrder()+" ")+provideTrailingFirstRowsHint(dbmsSupport);
" ORDER BY "+getDateField()+(" "+order.name()+" ")+provideTrailingFirstRowsHint(dbmsSupport);
}



private String documentQuery(String name, String query, String purpose) {
return "\n"+name+(purpose!=null?"\n"+purpose:"")+"\n"+query+"\n";
}
Expand Down Expand Up @@ -1022,24 +1026,19 @@ public void close() throws ListenerException {

@Override
public IMessageBrowsingIterator getIterator() throws ListenerException {
return getIterator(null,null,false);
return getIterator(null,null, SortOrder.NONE);
}

@Override
public IMessageBrowsingIterator getIterator(Date startTime, Date endTime, boolean forceDescending) throws ListenerException {
public IMessageBrowsingIterator getIterator(Date startTime, Date endTime, SortOrder order) throws ListenerException {
Connection conn;
try {
conn = getConnection();
} catch (JdbcException e) {
throw new ListenerException(e);
}
try {
String query;
if (startTime==null && endTime==null) {
query=selectListQuery;
} else {
query=getSelectListQuery(getDbmsSupport(), startTime, endTime, forceDescending);
}
String query = getSelectListQuery(getDbmsSupport(), startTime, endTime, order);
if (log.isDebugEnabled()) {
log.debug("preparing selectListQuery ["+query+"]");
}
Expand Down Expand Up @@ -1633,10 +1632,10 @@ public String getOrder() {
return order;
} else {
if (type.equalsIgnoreCase(TYPE_MESSAGELOG_PIPE) || type.equalsIgnoreCase(TYPE_MESSAGELOG_RECEIVER)) {
return messagesOrder;
return messagesOrder; //Defaults to DESC
} else {
if (type.equalsIgnoreCase(TYPE_ERRORSTORAGE)) {
return errorsOrder;
return errorsOrder; //Defaults to ASC
} else {
return order;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public IMessageBrowsingIterator getIterator() throws ListenerException {
}

@Override
public IMessageBrowsingIterator getIterator(Date startTime, Date endTime, boolean forceDescending) throws ListenerException {
public IMessageBrowsingIterator getIterator(Date startTime, Date endTime, SortOrder order) throws ListenerException {
String selector=getSelector();
if (startTime!=null) {
selector=Misc.concatStrings(selector, " AND ", "JMSTimestamp >= "+DateUtils.format(startTime));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,17 @@ private void processRawMessage(IListener origin, Object rawMessage, Map threadCo
if (threadContext==null) {
threadContext = new HashMap();
}

String message = origin.getStringFromRawMessage(rawMessage, threadContext);
String technicalCorrelationId = origin.getIdFromRawMessage(rawMessage, threadContext);

String message = null;
String technicalCorrelationId = null;
if(rawMessage instanceof MessageWrapper) { //somehow messages wrapped in MessageWrapper are in the ITransactionalStorage
MessageWrapper wrapper = (MessageWrapper) rawMessage;
message = wrapper.getText();
technicalCorrelationId = wrapper.getId();
} else {
message = origin.getStringFromRawMessage(rawMessage, threadContext);
technicalCorrelationId = origin.getIdFromRawMessage(rawMessage, threadContext);
}
String messageId = (String)threadContext.get("id");
processMessageInAdapter(origin, rawMessage, message, messageId, technicalCorrelationId, threadContext, waitingDuration, manualRetry);
}
Expand Down Expand Up @@ -1220,7 +1228,11 @@ private String processMessageInAdapter(IListener origin, Object rawMessage, Stri
} else {
afterMessageProcessedMap=pipelineSession;
}
origin.afterMessageProcessed(pipeLineResult,rawMessage, afterMessageProcessedMap);
if(rawMessage instanceof MessageWrapper) { //somehow messages wrapped in MessageWrapper are in the ITransactionalStorage
log.warn("Unable to post process messageId ["+messageId+"] cid ["+technicalCorrelationId+"]");
} else {
origin.afterMessageProcessed(pipeLineResult,rawMessage, afterMessageProcessedMap);
}
} finally {
long finishProcessingTimestamp = System.currentTimeMillis();
finishProcessingMessage(finishProcessingTimestamp-startProcessingTimestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import nl.nn.adapterframework.core.Adapter;
import nl.nn.adapterframework.core.IListener;
import nl.nn.adapterframework.core.IMessageBrowser;
import nl.nn.adapterframework.core.IMessageBrowser.SortOrder;
import nl.nn.adapterframework.core.IMessageBrowsingIterator;
import nl.nn.adapterframework.core.IMessageBrowsingIteratorItem;
import nl.nn.adapterframework.core.ITransactionalStorage;
Expand Down Expand Up @@ -218,7 +219,7 @@ public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServ
FileViewerServlet.showReaderContents(new StringReader(msg),"msg"+messageId,type,response,"message ["+messageId+"]");
return null;
} else {
IMessageBrowsingIterator mbi=mb.getIterator(startDate,endDate,"true".equals(forceDescStr));
IMessageBrowsingIterator mbi=mb.getIterator(startDate, endDate, SortOrder.NONE);
try {
XmlBuilder messages=new XmlBuilder("messages");
messages.addAttribute("storageType",storageType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ public Response execute(LinkedHashMap<String, Object> json) throws ApiException

DirectQuerySender qs;
try {
qs = (DirectQuerySender) getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
qs = getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
} catch (Exception e) {
log.error(e);
throw new ApiException("An error occured on creating or closing the connection!", 500);
throw new ApiException("An error occured on creating or closing the connection!", e);
}

try {
Expand All @@ -132,7 +131,7 @@ public Response execute(LinkedHashMap<String, Object> json) throws ApiException
if (!rs.isBeforeFirst()) {
rs = qs.getConnection().getMetaData().getColumns(null, null, tableName.toUpperCase(), null);
}

String fielddefinition = "<fielddefinition>";
while(rs.next()) {
String field = "<field name=\""
Expand Down Expand Up @@ -183,7 +182,7 @@ public Response execute(LinkedHashMap<String, Object> json) throws ApiException
//error("errors.generic","This function only supports oracle databases",null);
//}
} catch (Throwable t) {
throw new ApiException("An error occured on executing jdbc query: "+t.toString(), 400);
throw new ApiException("An error occured on executing jdbc query ["+query+"]", t);
} finally {
qs.close();
}
Expand All @@ -193,7 +192,7 @@ public Response execute(LinkedHashMap<String, Object> json) throws ApiException
resultMap = XmlQueryResult2Map(result);
}
if(resultMap == null)
throw new ApiException("Invalid query result.", 400);
throw new ApiException("Invalid query result [null].", 400);

Map<String, Object> resultObject = new HashMap<String, Object>();
resultObject.put("table", tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ public Response execute(LinkedHashMap<String, Object> json) throws ApiException
try {
qs = (DirectQuerySender) getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
} catch (Exception e) {
log.error(e);
throw new ApiException("An error occured on creating or closing the connection!", 500);
throw new ApiException("An error occured on creating or closing the connection", e);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

Expand Down Expand Up @@ -72,6 +74,7 @@
@Path("/")
public class ServerStatistics extends Base {
@Context ServletConfig servletConfig;
@Context Request request;
private static final int MAX_MESSAGE_SIZE = AppConstants.getInstance().getInt("adapter.message.max.size", 0);

@GET
Expand Down Expand Up @@ -226,7 +229,21 @@ public Response getServerConfiguration() throws ApiException {
if(messages.size() > 0)
returnMap.put("messages", messages);

return Response.status(Response.Status.CREATED).entity(returnMap).build();
Response.ResponseBuilder response = null;

//Calculate the ETag on last modified date of user resource
EntityTag etag = new EntityTag(returnMap.hashCode() + "");

//Verify if it matched with etag available in http request
response = request.evaluatePreconditions(etag);

//If ETag matches the response will be non-null;
if (response != null) {
return response.tag(etag).build();
}

response = Response.status(Response.Status.OK).entity(returnMap).tag(etag);
return response.build();
}

private List<Object> mapMessageKeeperMessages(MessageKeeper messageKeeper) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016-2017, 2019 Integration Partners B.V.
Copyright 2016-2020 Integration Partners B.V.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,11 +15,12 @@
*/
package nl.nn.adapterframework.webcontrol.api;

import java.text.DecimalFormat;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -51,10 +52,6 @@
@Path("/")
public final class ShowAdapterStatistics extends Base {

private DecimalFormat countFormat=new DecimalFormat(ItemList.PRINT_FORMAT_COUNT);
private DecimalFormat timeFormat=new DecimalFormat(ItemList.PRINT_FORMAT_TIME);
private DecimalFormat percentageFormat=new DecimalFormat(ItemList.PRINT_FORMAT_PERC);

@GET
@RolesAllowed({"IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester"})
@Path("/adapters/{adapterName}/statistics")
Expand Down Expand Up @@ -133,7 +130,7 @@ public Response getStatistics(@PathParam("adapterName") String adapterName) thro
statisticsMap.put("receivers", receivers);

Map<String, Object> tmp = new HashMap<String, Object>();
StatisticsKeeperToXml handler = new StatisticsKeeperToXml(tmp);
StatisticsKeeperToMap handler = new StatisticsKeeperToMap(tmp);
handler.configure();
Object handle = handler.start(null, null, null);
try {
Expand All @@ -149,54 +146,65 @@ public Response getStatistics(@PathParam("adapterName") String adapterName) thro
return Response.status(Response.Status.CREATED).entity(statisticsMap).build();
}

private class StatisticsKeeperToXml implements StatisticsKeeperIterationHandler {
private class StatisticsKeeperToMap implements StatisticsKeeperIterationHandler {

private Object parent;

public StatisticsKeeperToXml(Object parent) {
public StatisticsKeeperToMap(Object parent) {
super();
this.parent=parent;
}

@Override
public void configure() {
}

@Override
public Object start(Date now, Date mainMark, Date detailMark) {
return parent;
}

@Override
public void end(Object data) {
}

@Override
@SuppressWarnings("unchecked")
public void handleStatisticsKeeper(Object data, StatisticsKeeper sk) {
if(sk == null) return;

((Map<String, Object>) data).put(sk.getName(), statisticsKeeperToMapBuilder(sk));
((List<Object>) data).add(statisticsKeeperToMapBuilder(sk));
}

public void handleScalar(Object data, String scalarName, long value){
handleScalar(data,scalarName,""+value);
@Override
public void handleScalar(Object data, String scalarName, long value) {
handleScalar(data, scalarName, ""+value);
}
public void handleScalar(Object data, String scalarName, Date value){

@Override
public void handleScalar(Object data, String scalarName, Date value) {
String result;
if (value!=null) {
result = DateUtils.format(value, DateUtils.FORMAT_FULL_GENERIC);
} else {
result = "-";
}
handleScalar(data,scalarName,result);
handleScalar(data, scalarName, result);
}

public void handleScalar(Object data, String scalarName, String value) {
//Not applicable for HashMaps...
}

@Override
@SuppressWarnings("unchecked")
public Object openGroup(Object parentData, String name, String type) {
Map<String, Object> o = new HashMap<String, Object>();
List<Object> o = new LinkedList<Object>();
((Map<String, Object>) parentData).put(type, o);
return o;
}

@Override
public void closeGroup(Object data) {
}
}
Expand All @@ -207,29 +215,28 @@ protected Map<String, Object> statisticsKeeperToMapBuilder(StatisticsKeeper sk)
}

Map<String, Object> tmp = new HashMap<String, Object>();
tmp.put("name", sk.getName());
for (int i=0; i<sk.getItemCount(); i++) {
Object item = sk.getItemValue(i);
String key = sk.getItemName(i).replace("< ", "");
if (item==null) {
tmp.put(key, ItemList.ITEM_VALUE_NAN);
tmp.put(key, null);
} else {
String value = "";
switch (sk.getItemType(i)) {
case ItemList.ITEM_TYPE_INTEGER:
if (countFormat==null) {
value = ""+ (Long)item;
case ItemList.ITEM_TYPE_INTEGER:
tmp.put(key, item);
break;
case ItemList.ITEM_TYPE_TIME:
if(item instanceof Long) {
tmp.put(key, item);
} else {
value = countFormat.format((Long)item);
tmp.put(key, new BigDecimal((Double) item).setScale(1, BigDecimal.ROUND_HALF_EVEN));
}
break;
case ItemList.ITEM_TYPE_TIME:
value = timeFormat.format(item);
break;
case ItemList.ITEM_TYPE_FRACTION:
value = percentageFormat.format(((Double)item).doubleValue()*100)+ "%";
tmp.put(key, new BigDecimal(((Double) item).doubleValue()*100).setScale(1, BigDecimal.ROUND_HALF_EVEN));
break;
}
tmp.put(key, value);
}
}
return tmp;
Expand Down
Loading

0 comments on commit d631352

Please sign in to comment.