use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.
the class ContentList method onCreateContent.
public void onCreateContent(ActionEvent actionEvent) {
try {
CfClasscontent newclasscontent = new CfClasscontent();
contentName = contentName.replaceAll("\\s+", "_");
newclasscontent.setName(contentName);
newclasscontent.setClassref(selectedClass);
cfclasscontentService.create(newclasscontent);
List<CfAttribut> attributlist = cfattributService.findByClassref(newclasscontent.getClassref());
attributlist.stream().forEach((attribut) -> {
if (attribut.getAutoincrementor() == true) {
List<CfClasscontent> classcontentlist2 = cfclasscontentService.findByClassref(newclasscontent.getClassref());
long max = 0;
int last = classcontentlist2.size();
if (1 == last) {
max = 0;
} else {
CfClasscontent classcontent = classcontentlist2.get(last - 2);
CfAttributcontent attributcontent = cfattributcontentService.findByAttributrefAndClasscontentref(attribut, classcontent);
if (attributcontent.getContentInteger().longValue() > max) {
max = attributcontent.getContentInteger().longValue();
}
}
CfAttributcontent newcontent = new CfAttributcontent();
newcontent.setAttributref(attribut);
newcontent.setClasscontentref(newclasscontent);
newcontent.setContentInteger(BigInteger.valueOf(max + 1));
cfattributcontentService.create(newcontent);
} else {
CfAttributcontent newcontent = new CfAttributcontent();
newcontent.setAttributref(attribut);
newcontent.setClasscontentref(newclasscontent);
cfattributcontentService.create(newcontent);
}
});
hibernateUtil.insertContent(newclasscontent);
classcontentlist.clear();
classcontentlist = cfclasscontentService.findByMaintenance(true);
FacesMessage message = new FacesMessage("Content created");
FacesContext.getCurrentInstance().addMessage(null, message);
} catch (ConstraintViolationException ex) {
LOGGER.error(ex.getMessage());
}
}
use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.
the class DataList method onSelect.
public void onSelect(SelectEvent event) {
selectedList = (CfList) event.getObject();
contentName = selectedList.getName();
selectedClass = selectedList.getClassref();
newContentButtonDisabled = true;
filteredclasscontentlist = cfclasscontentService.findByClassref(selectedList.getClassref());
List<CfListcontent> selectedcontent = cflistcontentService.findByListref(selectedList.getId());
selectedListcontent.clear();
if (!selectedcontent.isEmpty()) {
for (CfListcontent listcontent : selectedcontent) {
CfClasscontent selectedContent = cfclasscontentService.findById(listcontent.getCfListcontentPK().getClasscontentref());
if (null != selectedContent) {
if (!selectedContent.isScrapped()) {
selectedListcontent.add(selectedContent);
}
}
}
}
}
use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.
the class GetDatalistHibernate 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) {
DatalistOutput datalistoutput = new DatalistOutput();
ArrayList<ContentOutput> outputlist = new ArrayList<>();
String inst_apikey = "";
String inst_name = "";
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")) {
name = "";
parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("name") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
name = values[0];
});
inst_name = name;
CfList cflist = cflistService.findByName(inst_name);
CfClass cfclass = cfclassService.findById(cflist.getClassref().getId());
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());
}
}
Session session_tables = HibernateUtil.getClasssessions().get("tables").getSessionFactory().openSession();
// Session session = hibernateUtil.getSession_tables();
for (CfClasscontent classcontent : classcontentList) {
Query query = session_tables.createQuery("FROM " + cfclass.getName() + " c WHERE cf_contentref = " + classcontent.getId());
Map content = (Map) query.getSingleResult();
// List<CfAttributcontent> attributcontentList = cfattributcontentService.findByClasscontentref(classcontent);
ContentOutput co = new ContentOutput();
co.setIdentifier(classcontent.getName());
co.setKeyvals(getContentMap(content));
co.setKeywords(contentUtil.getContentOutputKeywords(classcontent, false));
outputlist.add(co);
}
session_tables.close();
datalistoutput.setCflist(cflist);
datalistoutput.setOutputlist(outputlist);
Gson gson = new Gson();
String json = gson.toJson(datalistoutput);
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.CfClasscontent in project Clownfish by rawdog71.
the class GetDatalistHibernate 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<>();
// HashMap<String, String> outputmap;
String inst_name = "";
int range_start = 0;
int range_end = 0;
if (!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;
}
}
outputlist = new ArrayList<>();
// outputmap = new HashMap<>();
apikey = gcp.getApikey();
if (apikeyutil.checkApiKey(apikey, "RestService")) {
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.CfClasscontent in project Clownfish by rawdog71.
the class GetContentCountHibernate 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) {
String inst_klasse;
String inst_identifier;
String inst_datalist;
String inst_apikey = "";
HashMap<String, String> searchmap;
ArrayList<String> searchkeywords;
List<CfListcontent> listcontent = null;
int range_start = 0;
int range_end = 0;
if (!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;
}
}
inst_apikey = gcp.getApikey();
if (apikeyutil.checkApiKey(inst_apikey, "RestService")) {
inst_klasse = gcp.getClassname();
inst_identifier = gcp.getIdentifier();
if (null == inst_identifier) {
inst_identifier = "";
}
inst_datalist = gcp.getListname();
listcontent = null;
if ((null != inst_datalist) && (!inst_datalist.isEmpty())) {
CfList dataList = cflistService.findByName(inst_datalist);
listcontent = cflistcontentService.findByListref(dataList.getId());
}
searchmap = new HashMap<>();
String searches = gcp.getSearches();
if (null != searches) {
String[] keys = searches.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<>();
String keywordlist = gcp.getKeywords();
if (null != keywordlist) {
String[] keys = keywordlist.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 ");
}
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++;
}
}
}
HashMap count = new HashMap();
count.put("count", listcounter);
Gson gson = new Gson();
String json = gson.toJson(count);
gcp.setJson(json);
gcp.setReturncode("TRUE");
return gcp;
} else {
gcp.setReturncode("FALSE");
gcp.setJson("[]");
return gcp;
}
}
Aggregations