use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.
the class SiteUtil method getSitecontentmapList.
public Map getSitecontentmapList(List<CfSitecontent> sitecontentlist) {
Map sitecontentmapdummy = new LinkedHashMap();
for (CfSitecontent sitecontent : sitecontentlist) {
CfClasscontent classcontent = cfclasscontentService.findById(sitecontent.getCfSitecontentPK().getClasscontentref());
if (null != classcontent) {
List<CfAttributcontent> attributcontentlist = new ArrayList<>();
attributcontentlist.addAll(cfattributcontentService.findByClasscontentref(classcontent));
if (0 == useHibernate) {
sitecontentmapdummy.put(classcontent.getName(), classutil.getattributmap(classcontent));
} else {
sitecontentmapdummy.put(classcontent.getName(), hibernateutil.getContent(classcontent.getClassref().getName(), classcontent.getId()));
}
} else {
LOGGER.warn("CLASSCONTENT NOT FOUND (deleted or on scrapyard): " + sitecontent.getCfSitecontentPK().getClasscontentref());
}
}
return sitecontentmapdummy;
}
use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.
the class SiteUtil method getClasscontentmapList.
public Map getClasscontentmapList(List<CfClasscontent> classcontentlist) {
Map sitecontentmapdummy = new LinkedHashMap();
for (CfClasscontent classcontent : classcontentlist) {
if (null != classcontent) {
List<CfAttributcontent> attributcontentlist = new ArrayList<>();
attributcontentlist.addAll(cfattributcontentService.findByClasscontentref(classcontent));
if (0 == useHibernate) {
sitecontentmapdummy.put(classcontent.getName(), classutil.getattributmap(classcontent));
} else {
sitecontentmapdummy.put(classcontent.getName(), hibernateutil.getContent(classcontent.getClassref().getName(), classcontent.getId()));
}
} else {
LOGGER.warn("CLASSCONTENT NOT FOUND (deleted or on scrapyard): " + classcontent.getId());
}
}
return sitecontentmapdummy;
}
use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.
the class SiteUtil method getSitelist_list.
public Map getSitelist_list(CfSite cfsite, Map sitecontentmap) {
List<CfSitelist> sitelist_list = new ArrayList<>();
sitelist_list.addAll(cfsitelistService.findBySiteref(cfsite.getId()));
if (!sitelist_list.isEmpty()) {
for (CfSitelist sitelist : sitelist_list) {
CfList cflist = cflistService.findById(sitelist.getCfSitelistPK().getListref());
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.CfClasscontent in project Clownfish by rawdog71.
the class HibernateUtil method fillTable.
private static void fillTable(String classname, Session session) {
CfClass cfclass = cfclassservice.findByName(classname);
List<CfClasscontent> classcontentlist = cfclasscontentService.findByClassref(cfclass);
Query q = session.createSQLQuery("TRUNCATE TABLE usr_" + classname);
Transaction txt = session.beginTransaction();
int count = q.executeUpdate();
txt.commit();
for (CfClasscontent classcontent : classcontentlist) {
LOGGER.info("FILLTABLE:" + classname);
List<CfAttributcontent> attributcontentlist = cfattributcontentService.findByClasscontentref(classcontent);
Map entity = fillEntity(new HashMap(), classcontent, attributcontentlist);
try {
Transaction tx = session.beginTransaction();
session.save(classname, entity);
tx.commit();
} catch (org.hibernate.id.IdentifierGenerationException ex) {
LOGGER.warn("NOT SAVED:" + classcontent.getName());
}
}
}
use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.
the class GetContent 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;
HashMap<String, String> outputmap;
ArrayList<ContentDataOutput> outputlist;
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;
}
}
outputlist = new ArrayList<>();
outputmap = new HashMap<>();
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], 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++;
}
}
CfClass cfclass = cfclassService.findByName(inst_klasse);
List<CfClasscontent> classcontentList = cfclasscontentService.findByClassref(cfclass);
boolean found = false;
int listcounter = 0;
for (CfClasscontent classcontent : classcontentList) {
boolean inList = true;
// Check if identifier is set and matches classcontent
if ((!inst_identifier.isEmpty()) && (0 != inst_identifier.compareToIgnoreCase(classcontent.getName()))) {
inList = false;
}
// Check if content is in datalist
if (null != listcontent) {
boolean foundinlist = false;
for (CfListcontent lc : listcontent) {
if (lc.getCfListcontentPK().getClasscontentref() == classcontent.getId()) {
foundinlist = true;
break;
}
}
inList = foundinlist;
}
if (inList) {
boolean putToList = true;
List<CfAttributcontent> attributcontentList = cfattributcontentService.findByClasscontentref(classcontent);
ArrayList<HashMap> keyvals = contentUtil.getContentOutputKeyval(attributcontentList);
ArrayList<String> keywords = contentUtil.getContentOutputKeywords(classcontent, true);
if (!searchmap.isEmpty()) {
for (String searchcontent : searchmap.keySet()) {
String searchvalue = searchmap.get(searchcontent);
SearchValues sv = getSearchValues(searchvalue);
if (!compareAttribut(keyvals, sv, searchcontent)) {
putToList = false;
break;
}
}
}
// Check the keyword filter (at least one keyword must be found (OR))
if (!searchkeywords.isEmpty()) {
boolean dummyfound = false;
for (String keyword : searchkeywords) {
if (keywords.contains(keyword.toLowerCase())) {
dummyfound = true;
}
}
putToList = dummyfound;
}
if (putToList) {
found = true;
listcounter++;
if (range_start > 0) {
if ((listcounter >= range_start) && (listcounter <= range_end)) {
ContentDataOutput contentdataoutput = new ContentDataOutput();
contentdataoutput.setContent(classcontent);
contentdataoutput.setKeywords(keywords);
contentdataoutput.setKeyvals(keyvals);
outputlist.add(contentdataoutput);
// System.out.println(inst_klasse + " - " + listcounter);
}
} else {
ContentDataOutput contentdataoutput = new ContentDataOutput();
contentdataoutput.setContent(classcontent);
contentdataoutput.setKeywords(keywords);
contentdataoutput.setKeyvals(keyvals);
outputlist.add(contentdataoutput);
// System.out.println(inst_klasse + " - " + listcounter);
}
}
}
}
if (!found) {
outputmap.put("contentfound", "false");
}
Gson gson = new Gson();
String json = gson.toJson(outputlist);
gcp.setJson(json);
gcp.setReturncode("TRUE");
return gcp;
} else {
gcp.setReturncode("FALSE");
gcp.setJson("[]");
return gcp;
}
}
Aggregations