Search in sources :

Example 16 with CfList

use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.

the class CfListDAOImpl method findById.

@Override
public CfList findById(Long id) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfList.findById");
    query.setParameter("id", id);
    CfList cflist = (CfList) query.getSingleResult();
    return cflist;
}
Also used : TypedQuery(javax.persistence.TypedQuery) CfList(io.clownfish.clownfish.dbentities.CfList) Session(org.hibernate.Session)

Example 17 with CfList

use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.

the class CfListDAOImpl method findAll.

@Override
public List<CfList> findAll() {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfList.findAll");
    List<CfList> cfcontentlist = query.getResultList();
    return cfcontentlist;
}
Also used : TypedQuery(javax.persistence.TypedQuery) CfList(io.clownfish.clownfish.dbentities.CfList) Session(org.hibernate.Session)

Example 18 with CfList

use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.

the class CfListDAOImpl method findByName.

@Override
public CfList findByName(String name) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfList.findByName");
    query.setParameter("name", name);
    CfList cflist = (CfList) query.getSingleResult();
    return cflist;
}
Also used : TypedQuery(javax.persistence.TypedQuery) CfList(io.clownfish.clownfish.dbentities.CfList) Session(org.hibernate.Session)

Example 19 with CfList

use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.

the class ConsistencyUtil method checkConsistency.

public void checkConsistency() {
    LOGGER.info("CONSISTENCY CHECK ListContent - START");
    List<CfListcontent> listcontentList = cflistcontentservice.findAll();
    for (CfListcontent listcontent : listcontentList) {
        // Check Classcontent
        try {
            CfClasscontent cc = cfclasscontentservice.findById(listcontent.getCfListcontentPK().getClasscontentref());
        } catch (Exception ex) {
            LOGGER.warn("Classcontent does not exist: " + listcontent.getCfListcontentPK().getClasscontentref());
            cflistcontentservice.delete(listcontent);
        }
        // Check List
        try {
            CfList l = cflistservice.findById(listcontent.getCfListcontentPK().getListref());
        } catch (Exception ex) {
            LOGGER.warn("List does not exist: " + listcontent.getCfListcontentPK().getListref());
            cflistcontentservice.delete(listcontent);
        }
    }
    LOGGER.info("CONSISTENCY CHECK ListContent - END");
    LOGGER.info("CONSISTENCY CHECK AttributContent - START");
    List<CfClasscontent> classcontentlist = cfclasscontentservice.findAll();
    if (!classcontentlist.isEmpty()) {
        long lastId = classcontentlist.get(classcontentlist.size() - 1).getId();
        for (long i = 0; i <= lastId; i++) {
            try {
                CfClasscontent cc = cfclasscontentservice.findById(i);
            } catch (Exception ex) {
                CfClasscontent cc = new CfClasscontent();
                cc.setId(i);
                // System.out.println(i);
                try {
                    List<CfAttributcontent> aclist = cfattributcontentservice.findByClasscontentref(cc);
                } catch (Exception ex2) {
                    cfattributcontentservice.delete(i);
                }
            }
        }
    }
    List<CfList> list = cflistservice.findAll();
    if (!list.isEmpty()) {
        long lastlistId = list.get(list.size() - 1).getId();
        for (long i = 0; i <= lastlistId; i++) {
            try {
                CfList l = cflistservice.findById(i);
            } catch (Exception ex) {
                CfList cl = new CfList();
                cl.setId(i);
                // System.out.println(i);
                try {
                    List<CfAttributcontent> aclist = cfattributcontentservice.findByContentclassRef(cl);
                } catch (Exception ex2) {
                    // System.out.println(i);
                    cfattributcontentservice.updateContentref(i);
                }
            }
        }
    }
    LOGGER.info("CONSISTENCY CHECK AttributContent - END");
}
Also used : CfList(io.clownfish.clownfish.dbentities.CfList) List(java.util.List) CfList(io.clownfish.clownfish.dbentities.CfList) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent)

Example 20 with CfList

use of io.clownfish.clownfish.dbentities.CfList in project Clownfish by rawdog71.

the class GetContentCountHibernate 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) {
    String inst_klasse;
    String inst_identifier;
    String inst_datalist;
    String inst_range;
    String inst_apikey = "";
    HashMap<String, String> searchmap;
    ArrayList<String> searchkeywords;
    List<CfListcontent> listcontent = null;
    int range_start;
    int range_end;
    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")) {
        klasse = "";
        parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("class") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
            klasse = values[0];
        });
        inst_klasse = klasse;
        identifier = "";
        parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("identifier") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
            identifier = values[0];
        });
        inst_identifier = identifier;
        datalist = "";
        parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("datalist") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
            datalist = values[0];
        });
        inst_datalist = datalist;
        range = "";
        parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("range") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
            range = values[0];
        });
        inst_range = range;
        range_start = 0;
        range_end = 0;
        if (!inst_klasse.isEmpty()) {
            if (!inst_range.isEmpty()) {
                if (inst_range.contains("-")) {
                    String[] ranges = inst_range.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(inst_range);
                    range_end = range_start;
                }
            }
            listcontent = null;
            if (!inst_datalist.isEmpty()) {
                CfList dataList = cflistService.findByName(inst_datalist);
                listcontent = cflistcontentService.findByListref(dataList.getId());
            }
            searchmap = new HashMap<>();
            parameters.keySet().stream().filter((paramname) -> (paramname.startsWith("search$"))).forEach((paramname) -> {
                String[] keys = paramname.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<>();
            parameters.keySet().stream().filter((paramname) -> (paramname.startsWith("keywords"))).forEach((paramname) -> {
                String[] keys = paramname.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 ");
            }
            int listcounter = 0;
            try {
                List<Map> contentliste = (List<Map>) query.getResultList();
                session_tables.close();
                for (Map content : contentliste) {
                    CfClasscontent cfclasscontent = cfclasscontentService.findById((long) content.get("cf_contentref"));
                    if (null != cfclasscontent) {
                        if (!cfclasscontent.isScrapped()) {
                            listcounter++;
                        }
                    }
                }
            } catch (NoResultException ex) {
                session_tables.close();
            }
            HashMap count = new HashMap();
            count.put("count", listcounter);
            Gson gson = new Gson();
            String json = gson.toJson(count);
            response.setContentType("application/json;charset=UTF-8");
            try (PrintWriter out = response.getWriter()) {
                out.print(json);
            } catch (IOException ex) {
                LOGGER.error(ex.getMessage());
            }
        } else {
            HashMap count = new HashMap();
            count.put("count", 0);
            Gson gson = new Gson();
            String json = gson.toJson(count);
            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();
        }
    }
}
Also used : CfKeywordService(io.clownfish.clownfish.serviceinterface.CfKeywordService) CfListService(io.clownfish.clownfish.serviceinterface.CfListService) Setter(lombok.Setter) Getter(lombok.Getter) ServletException(javax.servlet.ServletException) LoggerFactory(org.slf4j.LoggerFactory) ContentUtil(io.clownfish.clownfish.utils.ContentUtil) NoResultException(javax.persistence.NoResultException) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) CfClassService(io.clownfish.clownfish.serviceinterface.CfClassService) CfAttributcontentService(io.clownfish.clownfish.serviceinterface.CfAttributcontentService) Gson(com.google.gson.Gson) Map(java.util.Map) Query(org.hibernate.query.Query) CfClasscontentKeywordService(io.clownfish.clownfish.serviceinterface.CfClasscontentKeywordService) CfAttributService(io.clownfish.clownfish.serviceinterface.CfAttributService) CfListcontentService(io.clownfish.clownfish.serviceinterface.CfListcontentService) PrintWriter(java.io.PrintWriter) CfClasscontentService(io.clownfish.clownfish.serviceinterface.CfClasscontentService) HibernateUtil(io.clownfish.clownfish.utils.HibernateUtil) Logger(org.slf4j.Logger) HttpServlet(javax.servlet.http.HttpServlet) CfAttributetypeService(io.clownfish.clownfish.serviceinterface.CfAttributetypeService) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) GetContentParameter(io.clownfish.clownfish.datamodels.GetContentParameter) WebServlet(javax.servlet.annotation.WebServlet) ApiKeyUtil(io.clownfish.clownfish.utils.ApiKeyUtil) List(java.util.List) Component(org.springframework.stereotype.Component) BufferedReader(java.io.BufferedReader) CfList(io.clownfish.clownfish.dbentities.CfList) Query(org.hibernate.query.Query) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) NoResultException(javax.persistence.NoResultException) IOException(java.io.IOException) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfList(io.clownfish.clownfish.dbentities.CfList) ArrayList(java.util.ArrayList) List(java.util.List) CfList(io.clownfish.clownfish.dbentities.CfList) HashMap(java.util.HashMap) Map(java.util.Map) Session(org.hibernate.Session) PrintWriter(java.io.PrintWriter)

Aggregations

CfList (io.clownfish.clownfish.dbentities.CfList)29 CfClasscontent (io.clownfish.clownfish.dbentities.CfClasscontent)20 CfListcontent (io.clownfish.clownfish.dbentities.CfListcontent)18 CfAttributcontent (io.clownfish.clownfish.dbentities.CfAttributcontent)12 ArrayList (java.util.ArrayList)12 Gson (com.google.gson.Gson)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 Session (org.hibernate.Session)10 List (java.util.List)8 IOException (java.io.IOException)7 CfClass (io.clownfish.clownfish.dbentities.CfClass)6 Query (org.hibernate.query.Query)6 GetContentParameter (io.clownfish.clownfish.datamodels.GetContentParameter)5 CfAttributService (io.clownfish.clownfish.serviceinterface.CfAttributService)5 CfAttributcontentService (io.clownfish.clownfish.serviceinterface.CfAttributcontentService)5 CfAttributetypeService (io.clownfish.clownfish.serviceinterface.CfAttributetypeService)5 CfClassService (io.clownfish.clownfish.serviceinterface.CfClassService)5 CfClasscontentKeywordService (io.clownfish.clownfish.serviceinterface.CfClasscontentKeywordService)5 CfClasscontentService (io.clownfish.clownfish.serviceinterface.CfClasscontentService)5