Search in sources :

Example 1 with CfKeywordlistcontent

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

the class CfKeywordlistcontentDAOImpl method findAll.

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

Example 2 with CfKeywordlistcontent

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

the class CfKeywordlistcontentDAOImpl method findByKeywordlistref.

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

Example 3 with CfKeywordlistcontent

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

the class CfKeywordlistcontentDAOImpl method findByKeywordref.

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

Example 4 with CfKeywordlistcontent

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

the class KeywordContentList method onSelect.

public void onSelect(SelectEvent event) {
    selectedKeywordlist = (CfKeywordlist) event.getObject();
    filteredKeywordcontent = cfkeywordService.findAll();
    List<CfKeywordlistcontent> selectedkeywordlist = cfkeywordlistcontentService.findByKeywordlistref(selectedKeywordlist.getId());
    selectedKeywordcontent.clear();
    if (!selectedkeywordlist.isEmpty()) {
        for (CfKeywordlistcontent keywordcontent : selectedkeywordlist) {
            CfKeyword selectedKeyword = cfkeywordService.findById(keywordcontent.getCfKeywordlistcontentPK().getKeywordref());
            selectedKeywordcontent.add(selectedKeyword);
        }
    }
}
Also used : CfKeywordlistcontent(io.clownfish.clownfish.dbentities.CfKeywordlistcontent) CfKeyword(io.clownfish.clownfish.dbentities.CfKeyword)

Example 5 with CfKeywordlistcontent

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

the class GetKeywordLibraries method doGet.

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
    try {
        String token = request.getParameter("token");
        if (authtokenlist.checkValidToken(token)) {
            String apikey = request.getParameter("apikey");
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                CfKeywordlist keywordlist = null;
                List<CfKeywordlist> keywordlistList = new ArrayList<>();
                String keywordlistid = request.getParameter("id");
                if (keywordlistid != null) {
                    keywordlist = cfkeywordlistService.findById(Long.parseLong(keywordlistid));
                    keywordlistList.add(keywordlist);
                }
                String keywordlistname = request.getParameter("name");
                if (keywordlistname != null) {
                    keywordlist = cfkeywordlistService.findByName(keywordlistname);
                    keywordlistList.clear();
                    keywordlistList.add(keywordlist);
                }
                if ((null == keywordlistid) && (null == keywordlistname)) {
                    keywordlistList = cfkeywordlistService.findAll();
                }
                ArrayList<RestKeywordListOutput> keywordlistoutputList = new ArrayList<>();
                for (CfKeywordlist keywordlistItem : keywordlistList) {
                    List<CfKeyword> keywordList = new ArrayList<>();
                    List<CfKeywordlistcontent> keywordlistcontentList = cfkeywordlistcontentService.findByKeywordlistref(keywordlistItem.getId());
                    for (CfKeywordlistcontent keywordlistcontent : keywordlistcontentList) {
                        keywordList.add(cfkeywordService.findById(keywordlistcontent.getCfKeywordlistcontentPK().getKeywordref()));
                    }
                    RestKeywordListOutput keywordlistoutput = new RestKeywordListOutput();
                    keywordlistoutput.setKeywordlist(keywordlistItem);
                    keywordlistoutput.setKeywords(keywordList);
                    keywordlistoutputList.add(keywordlistoutput);
                }
                Gson gson = new Gson();
                String json = gson.toJson(keywordlistoutputList);
                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 = response.getWriter();
                out.print("Wrong API KEY");
            }
        } else {
            PrintWriter out = response.getWriter();
            out.print("Invalid Token");
        }
    } catch (javax.persistence.NoResultException | java.lang.IllegalArgumentException ex) {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            out.print("No keyword lists");
        } catch (IOException ex1) {
            LOGGER.error(ex1.getMessage());
        }
    } catch (IOException ex) {
        LOGGER.error(ex.getMessage());
    }
}
Also used : CfKeywordlist(io.clownfish.clownfish.dbentities.CfKeywordlist) CfKeywordlistcontent(io.clownfish.clownfish.dbentities.CfKeywordlistcontent) ArrayList(java.util.ArrayList) CfKeyword(io.clownfish.clownfish.dbentities.CfKeyword) Gson(com.google.gson.Gson) IOException(java.io.IOException) RestKeywordListOutput(io.clownfish.clownfish.datamodels.RestKeywordListOutput) PrintWriter(java.io.PrintWriter)

Aggregations

CfKeywordlistcontent (io.clownfish.clownfish.dbentities.CfKeywordlistcontent)12 CfKeyword (io.clownfish.clownfish.dbentities.CfKeyword)5 CfKeywordlist (io.clownfish.clownfish.dbentities.CfKeywordlist)4 TypedQuery (javax.persistence.TypedQuery)4 Session (org.hibernate.Session)4 ArrayList (java.util.ArrayList)3 CfKeywordlistcontentPK (io.clownfish.clownfish.dbentities.CfKeywordlistcontentPK)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Gson (com.google.gson.Gson)1 RestKeywordListOutput (io.clownfish.clownfish.datamodels.RestKeywordListOutput)1 CfSitekeywordlist (io.clownfish.clownfish.dbentities.CfSitekeywordlist)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1