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;
}
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;
}
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);
}
}
}
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());
}
}
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());
}
}
Aggregations