use of io.clownfish.clownfish.datamodels.ContentOutput 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.datamodels.ContentOutput 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.datamodels.ContentOutput in project Clownfish by rawdog71.
the class GetDatalist 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);
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);
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.datamodels.ContentOutput 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;
}
}
Aggregations