Search in sources :

Example 21 with CfClasscontent

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;
}
Also used : CfSitecontent(io.clownfish.clownfish.dbentities.CfSitecontent) ArrayList(java.util.ArrayList) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with CfClasscontent

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;
}
Also used : ArrayList(java.util.ArrayList) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with CfClasscontent

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;
}
Also used : CfList(io.clownfish.clownfish.dbentities.CfList) CfSitelist(io.clownfish.clownfish.dbentities.CfSitelist) ArrayList(java.util.ArrayList) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) LinkedHashMap(java.util.LinkedHashMap)

Example 24 with CfClasscontent

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());
        }
    }
}
Also used : Query(org.hibernate.query.Query) HashMap(java.util.HashMap) CfClass(io.clownfish.clownfish.dbentities.CfClass) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) Transaction(org.hibernate.Transaction) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with CfClasscontent

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;
    }
}
Also used : HashMap(java.util.HashMap) CfClass(io.clownfish.clownfish.dbentities.CfClass) ContentDataOutput(io.clownfish.clownfish.datamodels.ContentDataOutput) Gson(com.google.gson.Gson) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfList(io.clownfish.clownfish.dbentities.CfList) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent)

Aggregations

CfClasscontent (io.clownfish.clownfish.dbentities.CfClasscontent)45 CfAttributcontent (io.clownfish.clownfish.dbentities.CfAttributcontent)24 CfListcontent (io.clownfish.clownfish.dbentities.CfListcontent)22 CfList (io.clownfish.clownfish.dbentities.CfList)21 Map (java.util.Map)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 Gson (com.google.gson.Gson)13 CfClass (io.clownfish.clownfish.dbentities.CfClass)13 IOException (java.io.IOException)13 List (java.util.List)12 CfAttributService (io.clownfish.clownfish.serviceinterface.CfAttributService)9 CfAttributcontentService (io.clownfish.clownfish.serviceinterface.CfAttributcontentService)9 CfClassService (io.clownfish.clownfish.serviceinterface.CfClassService)9 CfClasscontentService (io.clownfish.clownfish.serviceinterface.CfClasscontentService)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 CfAttributetypeService (io.clownfish.clownfish.serviceinterface.CfAttributetypeService)8 CfListService (io.clownfish.clownfish.serviceinterface.CfListService)8 Session (org.hibernate.Session)8 Logger (org.slf4j.Logger)8