Search in sources :

Example 1 with CfKeyword

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

the class RestKeyword method insertKeyword.

private RestKeywordParameter insertKeyword(RestKeywordParameter ikp) {
    try {
        String token = ikp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = ikp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                try {
                    CfKeyword keyword = cfkeywordService.findByName(ikp.getKeyword());
                    LOGGER.warn("Duplicate Keyword");
                    ikp.setReturncode("Duplicate Keyword");
                } catch (javax.persistence.NoResultException ex) {
                    CfKeyword newkeyword = new CfKeyword();
                    newkeyword.setName(ikp.getKeyword());
                    CfKeyword newkeyword2 = cfkeywordService.create(newkeyword);
                    ikp.setReturncode("OK");
                }
            } else {
                ikp.setReturncode("Wrong API KEY");
            }
        } else {
            ikp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        LOGGER.error("NoResultException");
        ikp.setReturncode("NoResultException");
    }
    return ikp;
}
Also used : CfKeyword(io.clownfish.clownfish.dbentities.CfKeyword)

Example 2 with CfKeyword

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

the class CfKeywordDAOImpl method findAll.

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

Example 3 with CfKeyword

use of io.clownfish.clownfish.dbentities.CfKeyword 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 4 with CfKeyword

use of io.clownfish.clownfish.dbentities.CfKeyword 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)

Example 5 with CfKeyword

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

the class GetKeywords 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")) {
                List<CfKeyword> keywordList = new ArrayList<>();
                keywordList = cfkeywordService.findAll();
                Gson gson = new Gson();
                String json = gson.toJson(keywordList);
                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 keywords");
        } catch (IOException ex1) {
            LOGGER.error(ex1.getMessage());
        }
    } catch (IOException ex) {
        LOGGER.error(ex.getMessage());
    }
}
Also used : CfKeyword(io.clownfish.clownfish.dbentities.CfKeyword) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

CfKeyword (io.clownfish.clownfish.dbentities.CfKeyword)22 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 CfAssetkeyword (io.clownfish.clownfish.dbentities.CfAssetkeyword)6 CfKeywordlistcontent (io.clownfish.clownfish.dbentities.CfKeywordlistcontent)5 HashMap (java.util.HashMap)5 Gson (com.google.gson.Gson)4 CfAsset (io.clownfish.clownfish.dbentities.CfAsset)4 PrintWriter (java.io.PrintWriter)4 TypedQuery (javax.persistence.TypedQuery)4 Session (org.hibernate.Session)4 CfClasscontentkeyword (io.clownfish.clownfish.dbentities.CfClasscontentkeyword)3 CfKeywordlist (io.clownfish.clownfish.dbentities.CfKeywordlist)3 ConstraintViolationException (jakarta.validation.ConstraintViolationException)3 CfAssetKeywordService (io.clownfish.clownfish.serviceinterface.CfAssetKeywordService)2 CfAssetService (io.clownfish.clownfish.serviceinterface.CfAssetService)2 CfKeywordService (io.clownfish.clownfish.serviceinterface.CfKeywordService)2 PropertyUtil (io.clownfish.clownfish.utils.PropertyUtil)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2