rw.setSuccess(true);
rw.setLinks(getLinks(userId));
// **************** end break out? ******************
AjaxWidgetAnswer awa = new AjaxWidgetAnswer();
rw.setData(awa);
// add default answer text, listboxtexts, guisettings, containers
try {
addDefaultAnswer(user, awr, awa);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String freeText = null;
Date dateFrom = null;
Date dateTo = null;
Collection<String> lLangs = null;
Collection<String> lDocs = null;
try {
Map<String, Object> filter = getFilterMap(userId, awr);
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"));
}
// noOfEntries = NewsFinder.findAllLastFirst(user.getGroupid(),
// freeText, dateFrom, dateTo).size();
// TODO: make better search with dates, languages, documents, etc...
lLangs = (Collection<String>) filter.get("lLangs");
lDocs = (Collection<String>) filter.get("lDocs");
Collection<TextBean> col = TextFinder.specSearchStuffGrouped(user,
99999, "%" + freeText + "%", lLangs, lDocs, dateFrom,
dateTo);
// noOfEntries = col.size();
awa.setStatus(AjaxWidgetAnswer.STATUS_FETCHED);
// awa.setJson("{\"noOfEntries\":" + noOfEntries + "}");
int pStart = 0;
int pEnd = 7;
int i = 0;
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) {
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++;
}
// test of map of stuff before jsoning it....
TreeMap<String, Object> tr = new TreeMap<>();
tr.put("noOfEntries", col.size());
tr.put("rwCol", rwCol);
// languages
Collection<LanguageBean> langCol = null;
langCol = LanguageFinderBase.findAll();
Collection<String> langCol2 = new ArrayList<String>();
for (LanguageBean langBean : langCol) {
langCol2.add(langBean.getLanguageid());
}
tr.put("languages", langCol2);
// documents
Collection<DocumentorderBean> docCol = null;
docCol = DocumentorderFinder.findAll();
Collection<String> docCol2 = new ArrayList<String>();
for (DocumentorderBean docordBean : docCol) {
docCol2.add(docordBean.getDocument());
}
tr.put("documents", docCol2);
// awa.setJson(jsonMapper.writeValueAsString(colRW));
awa.setJson(jsonMapper.writeValueAsString(tr));
} catch (Exception e) {
log.log(Level.ERROR, "getNewsMetaData: ", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(rw).build();
}