Search in sources :

Example 1 with ContentOutput

use of io.clownfish.clownfish.datamodels.ContentOutput in project Clownfish by rawdog71.

the class GetDatalistHibernate 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) {
    DatalistOutput datalistoutput = new DatalistOutput();
    ArrayList<ContentOutput> outputlist = new ArrayList<>();
    String inst_apikey = "";
    String inst_name = "";
    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")) {
        name = "";
        parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("name") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
            name = values[0];
        });
        inst_name = name;
        CfList cflist = cflistService.findByName(inst_name);
        CfClass cfclass = cfclassService.findById(cflist.getClassref().getId());
        List<CfListcontent> listcontentList = cflistcontentService.findByListref(cflist.getId());
        List<CfClasscontent> classcontentList = new ArrayList<>();
        for (CfListcontent listcontent : listcontentList) {
            CfClasscontent classcontent = cfclasscontentService.findById(listcontent.getCfListcontentPK().getClasscontentref());
            if (null != classcontent) {
                classcontentList.add(classcontent);
            } else {
                LOGGER.warn("Classcontent does not exist: " + inst_name + " - " + listcontent.getCfListcontentPK().getClasscontentref());
            }
        }
        Session session_tables = HibernateUtil.getClasssessions().get("tables").getSessionFactory().openSession();
        // Session session = hibernateUtil.getSession_tables();
        for (CfClasscontent classcontent : classcontentList) {
            Query query = session_tables.createQuery("FROM " + cfclass.getName() + " c WHERE cf_contentref = " + classcontent.getId());
            Map content = (Map) query.getSingleResult();
            // List<CfAttributcontent> attributcontentList = cfattributcontentService.findByClasscontentref(classcontent);
            ContentOutput co = new ContentOutput();
            co.setIdentifier(classcontent.getName());
            co.setKeyvals(getContentMap(content));
            co.setKeywords(contentUtil.getContentOutputKeywords(classcontent, false));
            outputlist.add(co);
        }
        session_tables.close();
        datalistoutput.setCflist(cflist);
        datalistoutput.setOutputlist(outputlist);
        Gson gson = new Gson();
        String json = gson.toJson(datalistoutput);
        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 : DatalistOutput(io.clownfish.clownfish.datamodels.DatalistOutput) 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) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfClass(io.clownfish.clownfish.dbentities.CfClass) 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) ContentOutput(io.clownfish.clownfish.datamodels.ContentOutput) 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) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) BufferedReader(java.io.BufferedReader) CfList(io.clownfish.clownfish.dbentities.CfList) Query(org.hibernate.query.Query) CfClass(io.clownfish.clownfish.dbentities.CfClass) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfList(io.clownfish.clownfish.dbentities.CfList) DatalistOutput(io.clownfish.clownfish.datamodels.DatalistOutput) ContentOutput(io.clownfish.clownfish.datamodels.ContentOutput) HashMap(java.util.HashMap) Map(java.util.Map) Session(org.hibernate.Session) PrintWriter(java.io.PrintWriter)

Example 2 with ContentOutput

use of io.clownfish.clownfish.datamodels.ContentOutput in project Clownfish by rawdog71.

the class GetDatalistHibernate 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) {
    DatalistOutput datalistoutput = new DatalistOutput();
    ArrayList<ContentOutput> outputlist = new ArrayList<>();
    // HashMap<String, String> outputmap;
    String inst_name = "";
    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<>();
    apikey = gcp.getApikey();
    if (apikeyutil.checkApiKey(apikey, "RestService")) {
        name = "";
        name = gcp.getListname();
        inst_name = name;
        CfList cflist = cflistService.findByName(inst_name);
        List<CfListcontent> listcontentList = cflistcontentService.findByListref(cflist.getId());
        List<CfClasscontent> classcontentList = new ArrayList<>();
        for (CfListcontent listcontent : listcontentList) {
            CfClasscontent classcontent = cfclasscontentService.findById(listcontent.getCfListcontentPK().getClasscontentref());
            if (null != classcontent) {
                classcontentList.add(classcontent);
            } else {
                LOGGER.warn("Classcontent does not exist: " + inst_name + " - " + listcontent.getCfListcontentPK().getClasscontentref());
            }
        }
        for (CfClasscontent classcontent : classcontentList) {
            List<CfAttributcontent> attributcontentList = cfattributcontentService.findByClasscontentref(classcontent);
            ContentOutput co = new ContentOutput();
            co.setIdentifier(classcontent.getName());
            co.setKeyvals(contentUtil.getContentOutputKeyval(attributcontentList));
            co.setKeywords(contentUtil.getContentOutputKeywords(classcontent, false));
            outputlist.add(co);
        }
        datalistoutput.setCflist(cflist);
        datalistoutput.setOutputlist(outputlist);
        Gson gson = new Gson();
        String json = gson.toJson(datalistoutput);
        gcp.setJson(json);
        gcp.setReturncode("TRUE");
        return gcp;
    } else {
        gcp.setReturncode("FALSE");
        gcp.setJson("[]");
        return gcp;
    }
}
Also used : ArrayList(java.util.ArrayList) 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) DatalistOutput(io.clownfish.clownfish.datamodels.DatalistOutput) ContentOutput(io.clownfish.clownfish.datamodels.ContentOutput)

Example 3 with ContentOutput

use of io.clownfish.clownfish.datamodels.ContentOutput in project Clownfish by rawdog71.

the class GetDatalist 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) {
    DatalistOutput datalistoutput = new DatalistOutput();
    ArrayList<ContentOutput> outputlist = new ArrayList<>();
    String inst_apikey = "";
    String inst_name = "";
    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")) {
        name = "";
        parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("name") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
            name = values[0];
        });
        inst_name = name;
        CfList cflist = cflistService.findByName(inst_name);
        List<CfListcontent> listcontentList = cflistcontentService.findByListref(cflist.getId());
        List<CfClasscontent> classcontentList = new ArrayList<>();
        for (CfListcontent listcontent : listcontentList) {
            CfClasscontent classcontent = cfclasscontentService.findById(listcontent.getCfListcontentPK().getClasscontentref());
            if (null != classcontent) {
                classcontentList.add(classcontent);
            } else {
                LOGGER.warn("Classcontent does not exist: " + inst_name + " - " + listcontent.getCfListcontentPK().getClasscontentref());
            }
        }
        for (CfClasscontent classcontent : classcontentList) {
            List<CfAttributcontent> attributcontentList = cfattributcontentService.findByClasscontentref(classcontent);
            ContentOutput co = new ContentOutput();
            co.setIdentifier(classcontent.getName());
            co.setKeyvals(contentUtil.getContentOutputKeyval(attributcontentList));
            co.setKeywords(contentUtil.getContentOutputKeywords(classcontent, false));
            outputlist.add(co);
        }
        datalistoutput.setCflist(cflist);
        datalistoutput.setOutputlist(outputlist);
        Gson gson = new Gson();
        String json = gson.toJson(datalistoutput);
        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 : DatalistOutput(io.clownfish.clownfish.datamodels.DatalistOutput) 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) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) CfClasscontentKeywordService(io.clownfish.clownfish.serviceinterface.CfClasscontentKeywordService) CfAttributService(io.clownfish.clownfish.serviceinterface.CfAttributService) ContentOutput(io.clownfish.clownfish.datamodels.ContentOutput) CfListcontentService(io.clownfish.clownfish.serviceinterface.CfListcontentService) PrintWriter(java.io.PrintWriter) CfClasscontentService(io.clownfish.clownfish.serviceinterface.CfClasscontentService) 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) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) BufferedReader(java.io.BufferedReader) CfList(io.clownfish.clownfish.dbentities.CfList) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfList(io.clownfish.clownfish.dbentities.CfList) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) DatalistOutput(io.clownfish.clownfish.datamodels.DatalistOutput) ContentOutput(io.clownfish.clownfish.datamodels.ContentOutput) PrintWriter(java.io.PrintWriter)

Example 4 with ContentOutput

use of io.clownfish.clownfish.datamodels.ContentOutput in project Clownfish by rawdog71.

the class GetDatalist 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) {
    DatalistOutput datalistoutput = new DatalistOutput();
    ArrayList<ContentOutput> outputlist = new ArrayList<>();
    outputlist = new ArrayList<>();
    // outputmap = new HashMap<>();
    apikey = gcp.getApikey();
    if (apikeyutil.checkApiKey(apikey, "RestService")) {
        String inst_name = "";
        int range_start = 0;
        int range_end = 0;
        if ((null != gcp.getRange()) && (!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;
            }
        }
        name = "";
        name = gcp.getListname();
        inst_name = name;
        CfList cflist = cflistService.findByName(inst_name);
        List<CfListcontent> listcontentList = cflistcontentService.findByListref(cflist.getId());
        List<CfClasscontent> classcontentList = new ArrayList<>();
        for (CfListcontent listcontent : listcontentList) {
            CfClasscontent classcontent = cfclasscontentService.findById(listcontent.getCfListcontentPK().getClasscontentref());
            if (null != classcontent) {
                classcontentList.add(classcontent);
            } else {
                LOGGER.warn("Classcontent does not exist: " + inst_name + " - " + listcontent.getCfListcontentPK().getClasscontentref());
            }
        }
        for (CfClasscontent classcontent : classcontentList) {
            List<CfAttributcontent> attributcontentList = cfattributcontentService.findByClasscontentref(classcontent);
            ContentOutput co = new ContentOutput();
            co.setIdentifier(classcontent.getName());
            co.setKeyvals(contentUtil.getContentOutputKeyval(attributcontentList));
            co.setKeywords(contentUtil.getContentOutputKeywords(classcontent, false));
            outputlist.add(co);
        }
        datalistoutput.setCflist(cflist);
        datalistoutput.setOutputlist(outputlist);
        Gson gson = new Gson();
        String json = gson.toJson(datalistoutput);
        gcp.setJson(json);
        gcp.setReturncode("TRUE");
        return gcp;
    } else {
        gcp.setReturncode("FALSE");
        gcp.setJson("[]");
        return gcp;
    }
}
Also used : ArrayList(java.util.ArrayList) 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) DatalistOutput(io.clownfish.clownfish.datamodels.DatalistOutput) ContentOutput(io.clownfish.clownfish.datamodels.ContentOutput)

Aggregations

Gson (com.google.gson.Gson)4 ContentOutput (io.clownfish.clownfish.datamodels.ContentOutput)4 DatalistOutput (io.clownfish.clownfish.datamodels.DatalistOutput)4 CfAttributcontent (io.clownfish.clownfish.dbentities.CfAttributcontent)4 CfClasscontent (io.clownfish.clownfish.dbentities.CfClasscontent)4 CfList (io.clownfish.clownfish.dbentities.CfList)4 CfListcontent (io.clownfish.clownfish.dbentities.CfListcontent)4 ArrayList (java.util.ArrayList)4 GetContentParameter (io.clownfish.clownfish.datamodels.GetContentParameter)2 CfAttributService (io.clownfish.clownfish.serviceinterface.CfAttributService)2 CfAttributcontentService (io.clownfish.clownfish.serviceinterface.CfAttributcontentService)2 CfAttributetypeService (io.clownfish.clownfish.serviceinterface.CfAttributetypeService)2 CfClassService (io.clownfish.clownfish.serviceinterface.CfClassService)2 CfClasscontentKeywordService (io.clownfish.clownfish.serviceinterface.CfClasscontentKeywordService)2 CfClasscontentService (io.clownfish.clownfish.serviceinterface.CfClasscontentService)2 CfKeywordService (io.clownfish.clownfish.serviceinterface.CfKeywordService)2 CfListService (io.clownfish.clownfish.serviceinterface.CfListService)2 CfListcontentService (io.clownfish.clownfish.serviceinterface.CfListcontentService)2 ApiKeyUtil (io.clownfish.clownfish.utils.ApiKeyUtil)2 ContentUtil (io.clownfish.clownfish.utils.ContentUtil)2