use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class GetContentHibernate 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;
HashMap<String, String> outputmap;
ArrayList<ContentDataOutput> outputlist;
List<CfListcontent> listcontent = null;
int range_start;
int range_end;
outputlist = new ArrayList<>();
outputmap = new HashMap<>();
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 = getQuery(session_tables, searchmap, inst_klasse);
try {
List<Map> contentliste = (List<Map>) query.getResultList();
session_tables.close();
int listcounter = 0;
for (Map content : contentliste) {
CfClasscontent cfclasscontent = cfclasscontentService.findById((long) content.get("cf_contentref"));
if (null != cfclasscontent) {
if (!cfclasscontent.isScrapped()) {
listcounter++;
if (range_start > 0) {
if ((listcounter >= range_start) && (listcounter <= range_end)) {
ContentDataOutput contentdataoutput = new ContentDataOutput();
contentdataoutput.setContent(cfclasscontent);
contentdataoutput.setKeywords(getContentKeywords(cfclasscontent, true));
contentdataoutput.setKeyvals(getContentMap(content));
outputlist.add(contentdataoutput);
}
} else {
ContentDataOutput contentdataoutput = new ContentDataOutput();
contentdataoutput.setContent(cfclasscontent);
contentdataoutput.setKeywords(getContentKeywords(cfclasscontent, true));
contentdataoutput.setKeyvals(getContentMap(content));
outputlist.add(contentdataoutput);
}
}
}
}
outputmap.put("contentfound", "true");
} catch (NoResultException ex) {
session_tables.close();
outputmap.put("contentfound", "false");
}
Gson gson = new Gson();
String json = gson.toJson(outputlist);
response.setContentType("application/json;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.print(json);
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
} else {
Gson gson = new Gson();
String json = gson.toJson(outputlist);
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();
}
}
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class GetDatalist method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param gcp GetContentParameters
* @param response servlet response
* @return GetContentParameters
*/
protected GetContentParameter processRequest(GetContentParameter gcp, HttpServletResponse response) {
DatalistOutput datalistoutput = new DatalistOutput();
ArrayList<ContentOutput> outputlist = new ArrayList<>();
outputlist = new ArrayList<>();
// outputmap = new HashMap<>();
apikey = gcp.getApikey();
if (apikeyutil.checkApiKey(apikey, "RestService")) {
String inst_name = "";
int range_start = 0;
int range_end = 0;
if ((null != gcp.getRange()) && (!gcp.getRange().isEmpty())) {
if (gcp.getRange().contains("-")) {
String[] ranges = gcp.getRange().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(gcp.getRange());
range_end = range_start;
}
}
name = "";
name = gcp.getListname();
inst_name = name;
CfList cflist = cflistService.findByName(inst_name);
List<CfListcontent> listcontentList = cflistcontentService.findByListref(cflist.getId());
List<CfClasscontent> classcontentList = new ArrayList<>();
for (CfListcontent listcontent : listcontentList) {
CfClasscontent classcontent = cfclasscontentService.findById(listcontent.getCfListcontentPK().getClasscontentref());
if (null != classcontent) {
classcontentList.add(classcontent);
} else {
LOGGER.warn("Classcontent does not exist: " + inst_name + " - " + listcontent.getCfListcontentPK().getClasscontentref());
}
}
for (CfClasscontent classcontent : classcontentList) {
List<CfAttributcontent> attributcontentList = cfattributcontentService.findByClasscontentref(classcontent);
ContentOutput co = new ContentOutput();
co.setIdentifier(classcontent.getName());
co.setKeyvals(contentUtil.getContentOutputKeyval(attributcontentList));
co.setKeywords(contentUtil.getContentOutputKeywords(classcontent, false));
outputlist.add(co);
}
datalistoutput.setCflist(cflist);
datalistoutput.setOutputlist(outputlist);
Gson gson = new Gson();
String json = gson.toJson(datalistoutput);
gcp.setJson(json);
gcp.setReturncode("TRUE");
return gcp;
} else {
gcp.setReturncode("FALSE");
gcp.setJson("[]");
return gcp;
}
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class HibernateUtil method fillRelation.
private static void fillRelation(String classname, String attributname, Session session_tables, Session session_relations) {
CfClass cfclass = cfclassservice.findByName(classname);
List<CfClasscontent> classcontentlist = cfclasscontentService.findByClassref(cfclass);
Query q = session_relations.createSQLQuery("TRUNCATE TABLE usr_rel_" + classname + "_" + attributname);
Transaction txt = session_relations.beginTransaction();
int count = q.executeUpdate();
txt.commit();
for (CfClasscontent classcontent : classcontentlist) {
LOGGER.info("FILLRELATION:" + classname);
List<CfAttributcontent> attributcontentlist = cfattributcontentService.findByClasscontentref(classcontent);
for (CfAttributcontent attributcontent : attributcontentlist) {
if (0 == attributcontent.getAttributref().getName().compareToIgnoreCase(attributname)) {
CfList contentclassref = attributcontent.getClasscontentlistref();
if (null != contentclassref) {
// System.out.println(contentclassref.getName());
List<CfListcontent> listcontentlist = cflistcontentService.findByListref(contentclassref.getId());
for (CfListcontent listcontent : listcontentlist) {
Map content = (Map) session_tables.createQuery("FROM " + classname + " c WHERE c.cf_contentref = " + classcontent.getId()).getSingleResult();
Map referenz = (Map) session_tables.createQuery("FROM " + attributcontent.getAttributref().getRelationref().getName() + " c WHERE c.cf_contentref = " + listcontent.getCfListcontentPK().getClasscontentref()).getSingleResult();
Map entity = new HashMap();
Map id = new HashMap();
id.put(classname + "_ref", classcontent.getId());
id.put(attributname + "_ref", listcontent.getCfListcontentPK().getClasscontentref());
entity.put("id_", id);
entity.put(classname + "_usr_ref", content.get("cf_id"));
entity.put(attributname + "_usr_ref", referenz.get("cf_id"));
try {
Transaction tx = session_relations.beginTransaction();
session_relations.save(classname + "_" + attributname, entity);
tx.commit();
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
}
}
}
}
}
}
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class SiteUtil method getSitelist_list.
public Map getSitelist_list(List<CfList> sitelist, Map sitecontentmap) {
if (!sitelist.isEmpty()) {
for (CfList cflist : sitelist) {
Map listcontentmap = new LinkedHashMap();
List<CfListcontent> contentlist = cflistcontentService.findByListref(cflist.getId());
for (CfListcontent listcontent : contentlist) {
CfClasscontent classcontent = cfclasscontentService.findById(listcontent.getCfListcontentPK().getClasscontentref());
cfclassService.findById(classcontent.getClassref().getId());
List<CfAttributcontent> attributcontentlist = new ArrayList<>();
attributcontentlist.addAll(cfattributcontentService.findByClasscontentref(classcontent));
if (0 == useHibernate) {
listcontentmap.put(classcontent.getName(), classutil.getattributmap(classcontent));
} else {
listcontentmap.put(classcontent.getName(), hibernateutil.getContent(classcontent.getClassref().getName(), classcontent.getId()));
}
}
sitecontentmap.put(cflist.getName(), listcontentmap);
}
}
return sitecontentmap;
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class DataList method onCreateContent.
public void onCreateContent(ActionEvent actionEvent) {
try {
contentName = contentName.trim().replaceAll("\\s+", "_");
cflistService.findByName(contentName);
} catch (NoResultException ex) {
CfList newlistcontent = new CfList();
newlistcontent.setName(contentName);
newlistcontent.setClassref(selectedClass);
cflistService.create(newlistcontent);
onRefreshAll();
} catch (ConstraintViolationException ex) {
LOGGER.error(ex.getMessage());
}
}
Aggregations