Search in sources :

Example 1 with CfList

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

the class RestDatalist method deleteDatalist.

private RestDatalistParameter deleteDatalist(RestDatalistParameter idp) {
    try {
        String token = idp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = idp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                try {
                    CfList list = cflistService.findByName(idp.getListname());
                    List<CfListcontent> listcontentList = cflistcontentService.findByListref(list.getId());
                    for (CfListcontent listcontent : listcontentList) {
                        cflistcontentService.delete(listcontent);
                    }
                    cflistService.delete(list);
                    idp.setReturncode("OK");
                } catch (javax.persistence.NoResultException ex) {
                    idp.setReturncode("Datalist not found");
                }
            } else {
                idp.setReturncode("Wrong API KEY");
            }
        } else {
            idp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        idp.setReturncode("NoResultException");
    }
    return idp;
}
Also used : CfList(io.clownfish.clownfish.dbentities.CfList) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent)

Example 2 with CfList

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

the class CfListDAOImpl method findByMaintenance.

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

Example 3 with CfList

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

the class CfListDAOImpl method findByClassref.

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

Example 4 with CfList

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

the class SiteTreeBean method onSelectLayoutDatalist.

/**
 * Selects a Datalist
 * @param event
 */
public void onSelectLayoutDatalist(SelectEvent event) {
    CfList selected_datalist = (CfList) event.getObject();
    previewDatalistOutput = "";
    for (CfListcontent datalistcontent : cflistcontentService.findByListref(selected_datalist.getId())) {
        CfClasscontent cc = cfclasscontentService.findById(datalistcontent.getCfListcontentPK().getClasscontentref());
        String template = templateUtility.getVersion(cc.getClassref().getTemplateref().getId(), cftemplateversionService.findMaxVersion(cc.getClassref().getTemplateref().getId()));
        if (null != cc) {
            attributcontentlist = cfattributcontentService.findByClasscontentref(cc);
            // String output = cc.getClassref().getTemplateref().getContent();
            for (CfAttributcontent attributcontent : attributcontentlist) {
                template = template.replaceAll("#" + attributcontent.getAttributref().getName() + "#", attributcontent.toString());
            }
            previewDatalistOutput += template;
        }
    }
}
Also used : CfList(io.clownfish.clownfish.dbentities.CfList) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent)

Example 5 with CfList

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

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