use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class RestDatalist method deleteDatalist.
private RestDatalistParameter deleteDatalist(RestDatalistParameter idp) {
try {
String token = idp.getToken();
if (authtokenlist.checkValidToken(token)) {
String apikey = idp.getApikey();
if (apikeyutil.checkApiKey(apikey, "RestService")) {
try {
CfList list = cflistService.findByName(idp.getListname());
List<CfListcontent> listcontentList = cflistcontentService.findByListref(list.getId());
for (CfListcontent listcontent : listcontentList) {
cflistcontentService.delete(listcontent);
}
cflistService.delete(list);
idp.setReturncode("OK");
} catch (javax.persistence.NoResultException ex) {
idp.setReturncode("Datalist not found");
}
} else {
idp.setReturncode("Wrong API KEY");
}
} else {
idp.setReturncode("Invalid token");
}
} catch (javax.persistence.NoResultException ex) {
idp.setReturncode("NoResultException");
}
return idp;
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class CfListDAOImpl method findByMaintenance.
@Override
public List<CfList> findByMaintenance(boolean b) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfList.findByMaintenance");
query.setParameter("maintenance", b);
List<CfList> cfcontentlist = query.getResultList();
return cfcontentlist;
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class CfListDAOImpl method findByClassref.
@Override
public List<CfList> findByClassref(CfClass ref) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfList.findByClassref");
query.setParameter("classref", ref);
List<CfList> cfcontentlist = query.getResultList();
return cfcontentlist;
}
use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.
the class SiteTreeBean method onSelectLayoutDatalist.
/**
* Selects a Datalist
* @param event
*/
public void onSelectLayoutDatalist(SelectEvent event) {
CfList selected_datalist = (CfList) event.getObject();
previewDatalistOutput = "";
for (CfListcontent datalistcontent : cflistcontentService.findByListref(selected_datalist.getId())) {
CfClasscontent cc = cfclasscontentService.findById(datalistcontent.getCfListcontentPK().getClasscontentref());
String template = templateUtility.getVersion(cc.getClassref().getTemplateref().getId(), cftemplateversionService.findMaxVersion(cc.getClassref().getTemplateref().getId()));
if (null != cc) {
attributcontentlist = cfattributcontentService.findByClasscontentref(cc);
// String output = cc.getClassref().getTemplateref().getContent();
for (CfAttributcontent attributcontent : attributcontentlist) {
template = template.replaceAll("#" + attributcontent.getAttributref().getName() + "#", attributcontent.toString());
}
previewDatalistOutput += template;
}
}
}
use of io.clownfish.clownfish.dbentities.CfList 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();
}
}
}
Aggregations