@QueryParam("userToken") String token,
@QueryParam("start") Integer start, @QueryParam("end") Integer end,
@QueryParam("filter") String jsonString) {
// TreeMap<String, String> filter) {
RestWrapper rw = new RestWrapper();
// ****************break out? ******************
String userId = null;
if (null != incomingUserId) {
// we have a userId check it....
// check that user is logged in etc...
LoginAnswer la = Dispatcher.getInstance().isActive(incomingUserId,
token);
// not active user
if (!LoginAnswer.ACTIVE.equals(la.getStatus())) {
return Response.status(Response.Status.UNAUTHORIZED).entity(rw)
.build();
}
userId = la.getUserId();
} else {
// no active user, return unauthorized.
return Response.status(Response.Status.UNAUTHORIZED).entity(rw)
.build();
}
// no access to service
if (!Dispatcher.getInstance().checkAccess(userId, "ADMIN_TEXTS_PAGE")) {
rw.setLinks(getLinks(""));
return Response.status(Response.Status.FORBIDDEN).entity(rw)
.build();
}
User user = Dispatcher.getInstance().getUser(userId);
rw.setSuccess(true);
rw.setLinks(getLinks(userId));
// **************** end break out? ******************
String freeText = null;
Date dateFrom = null;
Date dateTo = null;
Collection<String> lLangs = null;
Collection<String> lDocs = null;
// Integer noOfEntries = 0;
try {
Map<String, Object> json = null;
if (null != jsonString) {
json = jsonMapper.readValue(jsonString,
new TypeReference<Map<String, Object>>() {
});
}
if (null != json) {
// we may not have a filter...
@SuppressWarnings("unchecked")
Map<String, Object> filter = (Map<String, Object>) json
.get("filter");
freeText = (String) filter.get("freeText");
if (null != filter.get("dateFrom")
&& !"".equals((String) filter.get("dateFrom"))) {
dateFrom = Converter.stringToSqlDate((String) filter
.get("dateFrom"));
}
if (null != filter.get("dateTo")
&& !"".equals((String) filter.get("dateTo"))) {
dateTo = Converter.stringToSqlDate((String) filter
.get("dateTo"));
}
lLangs = (Collection<String>) filter.get("lLangs");
lDocs = (Collection<String>) filter.get("lDocs");
}
Collection<TextBean> col = TextFinder.specSearchStuffGrouped(user,
99999, "%" + freeText + "%", lLangs, lDocs, dateFrom,
dateTo);
// awa.setJson("{\"noOfEntries\":" + noOfEntries + "}");
// default to start 0, when just using the base url .../news
int pStart = null != start ? start : 0;
// default to end 10, when just using the base url .../news
int pEnd = null != end ? end : 10;
int i = 0;
Collection<String> services = Collections
.synchronizedList(new ArrayList<String>());
// Collection<News> nCol = Collections
// .synchronizedList(new ArrayList<News>());
Collection<RestWrapper> rwCol = new ArrayList<>();
TransportTextGrouped ttg = null;
TransportText transportText = null;
for (TextBean textBean : col) {
// TODO: optimize this by only getting the ones we want (limit
// in sql)
if (i >= pStart && i <= pEnd) {
ttg = new TransportTextGrouped();
ttg.setId(textBean.getId());
ttg.setDocument(textBean.getDocument());
Collection<TextBean> innerCol = TextFinder
.findByIdDocument(textBean.getId(),
textBean.getDocument());
Collection<TransportText> transportTextCol = new ArrayList<>();
for (TextBean textBeanInner : innerCol) {
// TODO: can I use beanPopulater here?
transportText = new TransportText();
transportText.setAutoid(textBeanInner.getAutoid());
transportText.setId(textBeanInner.getId());
transportText.setLanguageid(textBeanInner
.getLanguageid());
transportText.setText(textBeanInner.getText());
transportText.setDocument(textBeanInner.getDocument());
transportText
.setTscreated(textBeanInner.getTscreated());
transportText
.setTsupdated(textBeanInner.getTsupdated());
transportText
.setCreatedby(textBeanInner.getCreatedby());
transportText
.setUpdatedby(textBeanInner.getUpdatedby());
transportTextCol.add(transportText);
}
ttg.setTransportTextCol(transportTextCol);
// wrapp in RestWrapper
RestWrapper rwttg = new RestWrapper();
// TODO: needs both id and document
rwttg.setLinks(getLinksForObject(userId, ttg.getDocument(),
ttg.getId().toString()));
// rwNews.setData(newsBean);
rwttg.setData(ttg);
rwCol.add(rwttg);
}
i++;
}