use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class CfListDAOImpl method findById.
@Override
public CfList findById(Long id) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfList.findById");
query.setParameter("id", id);
CfList cflist = (CfList) query.getSingleResult();
return cflist;
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class CfListDAOImpl method findAll.
@Override
public List<CfList> findAll() {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfList.findAll");
List<CfList> cfcontentlist = query.getResultList();
return cfcontentlist;
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class CfListDAOImpl method findByName.
@Override
public CfList findByName(String name) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfList.findByName");
query.setParameter("name", name);
CfList cflist = (CfList) query.getSingleResult();
return cflist;
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class ConsistencyUtil method checkConsistency.
public void checkConsistency() {
LOGGER.info("CONSISTENCY CHECK ListContent - START");
List<CfListcontent> listcontentList = cflistcontentservice.findAll();
for (CfListcontent listcontent : listcontentList) {
// Check Classcontent
try {
CfClasscontent cc = cfclasscontentservice.findById(listcontent.getCfListcontentPK().getClasscontentref());
} catch (Exception ex) {
LOGGER.warn("Classcontent does not exist: " + listcontent.getCfListcontentPK().getClasscontentref());
cflistcontentservice.delete(listcontent);
}
// Check List
try {
CfList l = cflistservice.findById(listcontent.getCfListcontentPK().getListref());
} catch (Exception ex) {
LOGGER.warn("List does not exist: " + listcontent.getCfListcontentPK().getListref());
cflistcontentservice.delete(listcontent);
}
}
LOGGER.info("CONSISTENCY CHECK ListContent - END");
LOGGER.info("CONSISTENCY CHECK AttributContent - START");
List<CfClasscontent> classcontentlist = cfclasscontentservice.findAll();
if (!classcontentlist.isEmpty()) {
long lastId = classcontentlist.get(classcontentlist.size() - 1).getId();
for (long i = 0; i <= lastId; i++) {
try {
CfClasscontent cc = cfclasscontentservice.findById(i);
} catch (Exception ex) {
CfClasscontent cc = new CfClasscontent();
cc.setId(i);
// System.out.println(i);
try {
List<CfAttributcontent> aclist = cfattributcontentservice.findByClasscontentref(cc);
} catch (Exception ex2) {
cfattributcontentservice.delete(i);
}
}
}
}
List<CfList> list = cflistservice.findAll();
if (!list.isEmpty()) {
long lastlistId = list.get(list.size() - 1).getId();
for (long i = 0; i <= lastlistId; i++) {
try {
CfList l = cflistservice.findById(i);
} catch (Exception ex) {
CfList cl = new CfList();
cl.setId(i);
// System.out.println(i);
try {
List<CfAttributcontent> aclist = cfattributcontentservice.findByContentclassRef(cl);
} catch (Exception ex2) {
// System.out.println(i);
cfattributcontentservice.updateContentref(i);
}
}
}
}
LOGGER.info("CONSISTENCY CHECK AttributContent - END");
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class GetContentCountHibernate method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) {
String inst_klasse;
String inst_identifier;
String inst_datalist;
String inst_range;
String inst_apikey = "";
HashMap<String, String> searchmap;
ArrayList<String> searchkeywords;
List<CfListcontent> listcontent = null;
int range_start;
int range_end;
Map<String, String[]> parameters = request.getParameterMap();
parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("apikey") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
apikey = values[0];
});
inst_apikey = apikey;
if (apikeyutil.checkApiKey(inst_apikey, "RestService")) {
klasse = "";
parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("class") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
klasse = values[0];
});
inst_klasse = klasse;
identifier = "";
parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("identifier") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
identifier = values[0];
});
inst_identifier = identifier;
datalist = "";
parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("datalist") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
datalist = values[0];
});
inst_datalist = datalist;
range = "";
parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("range") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
range = values[0];
});
inst_range = range;
range_start = 0;
range_end = 0;
if (!inst_klasse.isEmpty()) {
if (!inst_range.isEmpty()) {
if (inst_range.contains("-")) {
String[] ranges = inst_range.split("-");
range_start = Integer.parseInt(ranges[0]);
range_end = Integer.parseInt(ranges[1]);
if (range_start > range_end) {
int dummy = range_start;
range_start = range_end;
range_end = dummy;
}
} else {
range_start = Integer.parseInt(inst_range);
range_end = range_start;
}
}
listcontent = null;
if (!inst_datalist.isEmpty()) {
CfList dataList = cflistService.findByName(inst_datalist);
listcontent = cflistcontentService.findByListref(dataList.getId());
}
searchmap = new HashMap<>();
parameters.keySet().stream().filter((paramname) -> (paramname.startsWith("search$"))).forEach((paramname) -> {
String[] keys = paramname.split("\\$");
int counter = 0;
for (String key : keys) {
if ((counter > 0) && ((counter % 2) == 0)) {
searchmap.put(keys[counter - 1] + "_" + counter, keys[counter]);
}
counter++;
}
});
searchkeywords = new ArrayList<>();
parameters.keySet().stream().filter((paramname) -> (paramname.startsWith("keywords"))).forEach((paramname) -> {
String[] keys = paramname.split("\\$");
int counter = 0;
for (String key : keys) {
if (counter > 0) {
searchkeywords.add(key);
}
counter++;
}
});
Session session_tables = HibernateUtil.getClasssessions().get("tables").getSessionFactory().openSession();
Query query = null;
if (!searchmap.isEmpty()) {
String whereclause = " WHERE ";
for (String searchcontent : searchmap.keySet()) {
String searchcontentval = searchcontent.substring(0, searchcontent.length() - 2);
String searchvalue = searchmap.get(searchcontent);
SearchValues sv = getSearchValues(searchvalue);
switch(sv.getComparartor()) {
case "eq":
whereclause += searchcontentval + " = '" + sv.getSearchvalue() + "' AND ";
break;
case "sw":
whereclause += searchcontentval + " LIKE '" + sv.getSearchvalue() + "%' AND ";
break;
case "ew":
whereclause += searchcontentval + " LIKE '%" + sv.getSearchvalue() + "' AND ";
break;
case "co":
whereclause += searchcontentval + " LIKE '%" + sv.getSearchvalue() + "%' AND ";
break;
case "gt":
whereclause += searchcontentval + " > '" + sv.getSearchvalue() + "' AND ";
break;
case "lt":
whereclause += searchcontentval + " < '" + sv.getSearchvalue() + "' AND ";
break;
case "ne":
whereclause += searchcontentval + " <> '" + sv.getSearchvalue() + "' AND ";
break;
}
}
whereclause = whereclause.substring(0, whereclause.length() - 5);
query = session_tables.createQuery("FROM " + inst_klasse + " c " + whereclause);
} else {
query = session_tables.createQuery("FROM " + inst_klasse + " c ");
}
int listcounter = 0;
try {
List<Map> contentliste = (List<Map>) query.getResultList();
session_tables.close();
for (Map content : contentliste) {
CfClasscontent cfclasscontent = cfclasscontentService.findById((long) content.get("cf_contentref"));
if (null != cfclasscontent) {
if (!cfclasscontent.isScrapped()) {
listcounter++;
}
}
}
} catch (NoResultException ex) {
session_tables.close();
}
HashMap count = new HashMap();
count.put("count", listcounter);
Gson gson = new Gson();
String json = gson.toJson(count);
response.setContentType("application/json;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.print(json);
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
} else {
HashMap count = new HashMap();
count.put("count", 0);
Gson gson = new Gson();
String json = gson.toJson(count);
response.setContentType("application/json;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.print(json);
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
}
} else {
PrintWriter out = null;
try {
out = response.getWriter();
out.print("Wrong API KEY");
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
} finally {
out.close();
}
}
}
Aggregations