Search in sources :

Example 1 with CfTemplate

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

the class CfTemplateDAOImpl method findById.

@Override
public CfTemplate findById(Long id) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfTemplate.findById");
    query.setParameter("id", id);
    CfTemplate cftemplate = (CfTemplate) query.getSingleResult();
    return cftemplate;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Session(org.hibernate.Session) CfTemplate(io.clownfish.clownfish.dbentities.CfTemplate)

Example 2 with CfTemplate

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

the class TemplateList method onCheckOut.

@Override
public void onCheckOut(ActionEvent actionEvent) {
    if (null != selectedTemplate) {
        boolean canCheckout = false;
        CfTemplate checktemplate = cftemplateService.findById(selectedTemplate.getId());
        BigInteger co = checktemplate.getCheckedoutby();
        if (null != co) {
            if (co.longValue() == 0) {
                canCheckout = true;
            }
        } else {
            canCheckout = true;
        }
        if (canCheckout) {
            selectedTemplate.setCheckedoutby(BigInteger.valueOf(loginbean.getCfuser().getId()));
            selectedTemplate.setContent(getContent());
            cftemplateService.edit(selectedTemplate);
            difference = templateUtility.hasDifference(selectedTemplate);
            checkedout = true;
            showDiff = false;
            FacesMessage message = new FacesMessage("Checked Out " + selectedTemplate.getName());
            FacesContext.getCurrentInstance().addMessage(null, message);
        } else {
            access = false;
            FacesMessage message = new FacesMessage("could not Checked Out " + selectedTemplate.getName());
            FacesContext.getCurrentInstance().addMessage(null, message);
        }
    }
}
Also used : BigInteger(java.math.BigInteger) FacesMessage(javax.faces.application.FacesMessage) CfTemplate(io.clownfish.clownfish.dbentities.CfTemplate)

Example 3 with CfTemplate

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

the class GetTemplates 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")) {
                CfTemplate template = null;
                List<CfTemplate> templateList = new ArrayList<>();
                String templateid = request.getParameter("id");
                if (templateid != null) {
                    template = cftemplateService.findById(Long.parseLong(templateid));
                    templateList.add(template);
                }
                String templatename = request.getParameter("name");
                if (templatename != null) {
                    template = cftemplateService.findByName(templatename);
                    templateList.clear();
                    templateList.add(template);
                }
                if ((null == templateid) && (null == templatename)) {
                    templateList = cftemplateService.findAll();
                }
                ArrayList<TemplateDataOutput> templatedataoutputList = new ArrayList<>();
                for (CfTemplate templateItem : templateList) {
                    TemplateDataOutput templatedataoutput = new TemplateDataOutput();
                    templatedataoutput.setTemplate(templateItem);
                    templatedataoutputList.add(templatedataoutput);
                }
                Gson gson = new Gson();
                String json = gson.toJson(templatedataoutputList);
                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 class");
        } catch (IOException ex1) {
            LOGGER.error(ex1.getMessage());
        }
    } catch (IOException ex) {
        LOGGER.error(ex.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) CfTemplate(io.clownfish.clownfish.dbentities.CfTemplate) TemplateDataOutput(io.clownfish.clownfish.datamodels.TemplateDataOutput) PrintWriter(java.io.PrintWriter)

Example 4 with CfTemplate

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

the class QuartzJob method callJob.

private void callJob(long siteref) {
    boolean canExecute = false;
    // 1 = Staging mode (fetch sourcecode from commited repository) <= default
    modus = STAGING;
    // read all System Properties of the property table
    propertymap = propertylist.fillPropertyMap();
    // clownfishutil = new ClownfishUtil();
    String sapSupportProp = propertymap.get("sap_support");
    if (sapSupportProp.compareToIgnoreCase("true") == 0) {
        sapSupport = true;
    }
    if (sapSupport) {
        sapc = new SAPConnection(SAPCONNECTION, "Clownfish5");
        rpytableread = new RPY_TABLE_READ(sapc);
    }
    // Freemarker Template
    freemarker.template.Template fmTemplate = null;
    Map fmRoot = null;
    // Velocity Template
    org.apache.velocity.VelocityContext velContext = null;
    org.apache.velocity.Template velTemplate = null;
    // fetch site by name or aliasname
    CfSite cfsite;
    cfsite = cfsiteService.findById(siteref);
    CfTemplate cftemplate = cftemplateService.findById(cfsite.getTemplateref().longValue());
    // fetch the dependend template
    switch(cftemplate.getScriptlanguage()) {
        case 0:
            try {
                // Freemarker Template
                fmRoot = new LinkedHashMap();
                freemarkerCfg = new freemarker.template.Configuration();
                freemarkerCfg.setDefaultEncoding("UTF-8");
                freemarkerCfg.setTemplateLoader(freemarkerTemplateloader);
                freemarkerCfg.setLocalizedLookup(false);
                freemarkerCfg.setLocale(Locale.GERMANY);
                fmTemplate = freemarkerCfg.getTemplate(cftemplate.getName());
                canExecute = true;
            } catch (MalformedTemplateNameException ex) {
                LOGGER.error(ex.getMessage());
            } catch (ParseException ex) {
                LOGGER.error(ex.getMessage());
            } catch (IOException ex) {
                LOGGER.error(ex.getMessage());
            }
            break;
        case 1:
            try {
                // Velocity Template
                velContext = new org.apache.velocity.VelocityContext();
                velTemplate = new org.apache.velocity.Template();
                org.apache.velocity.runtime.RuntimeServices runtimeServices = org.apache.velocity.runtime.RuntimeSingleton.getRuntimeServices();
                String templateContent;
                long currentTemplateVersion;
                try {
                    currentTemplateVersion = cftemplateversionService.findMaxVersion(cftemplate.getId());
                } catch (NullPointerException ex) {
                    currentTemplateVersion = 0;
                }
                templateContent = templateUtil.getVersion(cftemplate.getId(), currentTemplateVersion);
                templateContent = templateUtil.fetchIncludes(templateContent, modus);
                StringReader reader = new StringReader(templateContent);
                velTemplate.setRuntimeServices(runtimeServices);
                velTemplate.setData(runtimeServices.parse(reader, velTemplate));
                velTemplate.initDocument();
                canExecute = true;
            } catch (org.apache.velocity.runtime.parser.ParseException ex) {
                LOGGER.error(ex.getMessage());
            }
            break;
        default:
            canExecute = false;
            break;
    }
    if (canExecute) {
        // fetch the dependend datasources
        sitedatasourcelist = new ArrayList<>();
        sitedatasourcelist.addAll(cfsitedatasourceService.findBySiteref(cfsite.getId()));
        // Instantiate Template Beans
        EmailTemplateBean emailbean = new EmailTemplateBean();
        emailbean.init(propertymap, mailUtil, propertyUtil);
        if (sapSupport) {
            List<CfSitesaprfc> sitesaprfclist = new ArrayList<>();
            sitesaprfclist.addAll(cfsitesaprfcService.findBySiteref(cfsite.getId()));
            sapbean = new SAPTemplateBean();
            sapbean.init(sapc, sitesaprfclist, rpytableread, null);
        }
        NetworkTemplateBean networkbean = new NetworkTemplateBean();
        DatabaseTemplateBean databasebean = new DatabaseTemplateBean();
        databasebean.initjob(sitedatasourcelist, cfdatasourceService);
        ImportTemplateBean importBean = new ImportTemplateBean();
        importBean.initjob(sitedatasourcelist, cfdatasourceService);
        WebServiceTemplateBean webServiceBean = new WebServiceTemplateBean();
        PDFTemplateBean pdfBean = new PDFTemplateBean();
        pdfBean.initjob(pdfUtil);
        // write the output
        Writer out = new StringWriter();
        if (0 == cftemplate.getScriptlanguage()) {
            // Freemarker template
            if (null != fmRoot) {
                fmRoot.put("emailBean", emailbean);
                if (sapSupport) {
                    List<CfSitesaprfc> sitesaprfclist = new ArrayList<>();
                    sitesaprfclist.addAll(cfsitesaprfcService.findBySiteref(cfsite.getId()));
                    sapbean = new SAPTemplateBean();
                    sapbean.init(sapc, sitesaprfclist, rpytableread, null);
                    fmRoot.put("sapBean", sapbean);
                }
                fmRoot.put("databaseBean", databasebean);
                fmRoot.put("networkBean", networkbean);
                fmRoot.put("importBean", importBean);
                fmRoot.put("pdfBean", pdfBean);
                fmRoot.put("webserviceBean", webServiceBean);
                fmRoot.put("property", propertymap);
                for (Class tpbc : beanUtil.getLoadabletemplatebeans()) {
                    Constructor<?> ctor;
                    try {
                        ctor = tpbc.getConstructor();
                        Object object = ctor.newInstance(new Object[] {});
                        fmRoot.put(tpbc.getName().replaceAll("\\.", "_"), object);
                    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                        LOGGER.error(ex.getMessage());
                    }
                }
                try {
                    if (null != fmTemplate) {
                        freemarker.core.Environment env = fmTemplate.createProcessingEnvironment(fmRoot, out);
                        env.process();
                    }
                } catch (freemarker.template.TemplateException ex) {
                    LOGGER.error(ex.getMessage());
                } catch (IOException ex) {
                    LOGGER.error(ex.getMessage());
                }
            }
        } else {
            // Velocity template
            if (null != velContext) {
                velContext.put("emailBean", emailbean);
                if (sapSupport) {
                    List<CfSitesaprfc> sitesaprfclist = new ArrayList<>();
                    sitesaprfclist.addAll(cfsitesaprfcService.findBySiteref(cfsite.getId()));
                    sapbean = new SAPTemplateBean();
                    velContext.put("sapBean", sapbean);
                }
                velContext.put("databaseBean", databasebean);
                velContext.put("networkBean", networkbean);
                velContext.put("importBean", importBean);
                velContext.put("webserviceBean", webServiceBean);
                velContext.put("pdfBean", pdfBean);
                for (Class tpbc : beanUtil.getLoadabletemplatebeans()) {
                    Constructor<?> ctor;
                    try {
                        ctor = tpbc.getConstructor();
                        Object object = ctor.newInstance(new Object[] {});
                        velContext.put(tpbc.getName().replaceAll("\\.", "_"), object);
                    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                        LOGGER.error(ex.getMessage());
                    }
                }
                velContext.put("property", propertymap);
                if (null != velTemplate) {
                    velTemplate.merge(velContext, out);
                }
            }
        }
        LOGGER.info(out.toString());
    } else {
        LOGGER.info("CANNOT EXECUTE HTML TEMPLATE");
    }
}
Also used : ArrayList(java.util.ArrayList) CfTemplate(io.clownfish.clownfish.dbentities.CfTemplate) LinkedHashMap(java.util.LinkedHashMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MalformedTemplateNameException(freemarker.template.MalformedTemplateNameException) CfSitesaprfc(io.clownfish.clownfish.dbentities.CfSitesaprfc) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) SAPConnection(de.destrukt.sapconnection.SAPConnection) IOException(java.io.IOException) CfSite(io.clownfish.clownfish.dbentities.CfSite) RPY_TABLE_READ(io.clownfish.clownfish.sap.RPY_TABLE_READ) ParseException(freemarker.core.ParseException) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 5 with CfTemplate

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

the class SiteTreeBean method onSelect.

public void onSelect(NodeSelectEvent event) {
    selectedNode = event.getTreeNode();
    selectedSite = (CfSite) selectedNode.getData();
    classcontentlist = cfclasscontentService.findByMaintenance(true);
    if (null != selectedSite.getTemplateref()) {
        CfTemplate template = cftemplateService.findById(selectedSite.getTemplateref().longValue());
        int idx = templatelist.getTemplateListe().indexOf(template);
        selectedTemplate = templatelist.getTemplateListe().get(idx);
        iframeurl = selectedSite.getName() + "?preview=true";
        selectedDiv = null;
        showContent = false;
        showDatalist = false;
        showAsset = false;
        showAssetLibrary = false;
        showKeywordLibrary = false;
        if (template.isLayout()) {
            contenteditable = true;
            FacesMessage message = new FacesMessage("LAYOUT TEMPLATE");
            FacesContext.getCurrentInstance().addMessage(null, message);
            // List<CfLayoutcontent> layoutcontent = cflayoutcontentService.findBySiteref(selectedSite.getId());
            layout = new CfLayout(template.getName());
            Document doc = Jsoup.parse(template.getContent());
            Elements divs = doc.getElementsByAttribute("template");
            for (Element div : divs) {
                String contents = div.attr("contents");
                String datalists = div.attr("datalists");
                String assets = div.attr("assets");
                String assetlists = div.attr("assetlists");
                String keywordlists = div.attr("keywordlists");
                CfDiv cfdiv = new CfDiv();
                cfdiv.setId(div.attr("id"));
                cfdiv.setName(div.attr("template"));
                if (!contents.isEmpty()) {
                    cfdiv.getContentArray().addAll(ClownfishUtil.toList(contents.split(",")));
                }
                if (!datalists.isEmpty()) {
                    cfdiv.getContentlistArray().addAll(ClownfishUtil.toList(datalists.split(",")));
                }
                if (!assets.isEmpty()) {
                    cfdiv.getAssetArray().addAll(ClownfishUtil.toList(assets.split(",")));
                }
                if (!assetlists.isEmpty()) {
                    cfdiv.getAssetlistArray().addAll(ClownfishUtil.toList(assetlists.split(",")));
                }
                if (!keywordlists.isEmpty()) {
                    cfdiv.getKeywordlistArray().addAll(ClownfishUtil.toList(keywordlists.split(",")));
                }
                layout.getDivArray().put(div.attr("id"), cfdiv);
            }
        } else {
            contenteditable = false;
            selected_contentclass = null;
            selected_datalisttclass = null;
            selected_asset = null;
            selected_assetlist = null;
            selected_keywordlist = null;
        }
    } else {
        selectedTemplate = null;
    }
    if (null != selectedSite.getStylesheetref()) {
        CfStylesheet styleshet = cfstylesheetService.findById(selectedSite.getStylesheetref().longValue());
        int idx = stylesheetlist.getStylesheetListe().indexOf(styleshet);
        selectedStylesheet = stylesheetlist.getStylesheetListe().get(idx);
    } else {
        selectedStylesheet = null;
    }
    if (null != selectedSite.getJavascriptref()) {
        CfJavascript javascript = cfjavascriptService.findById(selectedSite.getJavascriptref().longValue());
        int idx = javascriptlist.getJavascriptListe().indexOf(javascript);
        selectedJavascript = javascriptlist.getJavascriptListe().get(idx);
    } else {
        selectedJavascript = null;
    }
    selectedDatasources.clear();
    List<CfSitedatasource> selectedSiteDatasources = cfsitedatasourceService.findBySiteref(selectedSite.getId());
    for (CfSitedatasource sitedatasource : selectedSiteDatasources) {
        CfDatasource ds = cfdatasourceService.findById(sitedatasource.getCfSitedatasourcePK().getDatasourceref());
        selectedDatasources.add(ds);
    }
    selectedContentlist.clear();
    List<CfSitelist> selectedSitecontentlist = cfsitelistService.findBySiteref(selectedSite.getId());
    for (CfSitelist sitelist : selectedSitecontentlist) {
        CfList cl = cflistService.findById(sitelist.getCfSitelistPK().getListref());
        selectedContentlist.add(cl);
    }
    selectedClasscontentlist.clear();
    List<CfSitecontent> selectedClasscontentliste = cfsitecontentService.findBySiteref(selectedSite.getId());
    for (CfSitecontent sitecontent : selectedClasscontentliste) {
        CfClasscontent cc = cfclasscontentService.findById(sitecontent.getCfSitecontentPK().getClasscontentref());
        selectedClasscontentlist.add(cc);
    }
    selectedAssetlist.clear();
    List<CfSiteassetlist> selectedAssetliste = cfsiteassetlistService.findBySiteref(selectedSite.getId());
    for (CfSiteassetlist siteassetlist : selectedAssetliste) {
        CfAssetlist csa = cfassetlistService.findById(siteassetlist.getCfSiteassetlistPK().getAssetlistref());
        selectedAssetlist.add(csa);
    }
    selectedKeywordlist.clear();
    List<CfSitekeywordlist> selectedKeywordliste = cfsitekeywordlistService.findBySiteref(selectedSite.getId());
    for (CfSitekeywordlist sitekeywordlist : selectedKeywordliste) {
        CfKeywordlist kwl = cfkeywordlistService.findById(sitekeywordlist.getCfSitekeywordlistPK().getKeywordlistref());
        selectedKeywordlist.add(kwl);
    }
    siteName = selectedSite.getName();
    siteTitle = selectedSite.getTitle();
    siteDescription = selectedSite.getDescription();
    sitejob = selectedSite.isJob();
    sitesearchrelevant = selectedSite.isSearchrelevant();
    sitemap = selectedSite.isSitemap();
    sitestatic = selectedSite.isStaticsite();
    aliaspath = selectedSite.getAliaspath();
    sitehtmlcompression = selectedSite.getHtmlcompression();
    characterEncoding = selectedSite.getCharacterencoding();
    contentType = selectedSite.getContenttype();
    locale = selectedSite.getLocale();
    saprfclist = cfsitesaprfcService.findBySiteref(selectedSite.getId());
    newButtonDisabled = true;
    FacesMessage message = new FacesMessage("Selected " + selectedSite.getName());
    FacesContext.getCurrentInstance().addMessage(null, message);
}
Also used : CfSitedatasource(io.clownfish.clownfish.dbentities.CfSitedatasource) Element(org.jsoup.nodes.Element) CfDatasource(io.clownfish.clownfish.dbentities.CfDatasource) CfSiteassetlist(io.clownfish.clownfish.dbentities.CfSiteassetlist) CfAssetlist(io.clownfish.clownfish.dbentities.CfAssetlist) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfTemplate(io.clownfish.clownfish.dbentities.CfTemplate) CfDiv(io.clownfish.clownfish.datamodels.CfDiv) CfSitekeywordlist(io.clownfish.clownfish.dbentities.CfSitekeywordlist) CfList(io.clownfish.clownfish.dbentities.CfList) CfJavascript(io.clownfish.clownfish.dbentities.CfJavascript) CfKeywordlist(io.clownfish.clownfish.dbentities.CfKeywordlist) CfLayout(io.clownfish.clownfish.datamodels.CfLayout) CfSitecontent(io.clownfish.clownfish.dbentities.CfSitecontent) CfSitelist(io.clownfish.clownfish.dbentities.CfSitelist) CfStylesheet(io.clownfish.clownfish.dbentities.CfStylesheet) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

CfTemplate (io.clownfish.clownfish.dbentities.CfTemplate)9 FacesMessage (javax.faces.application.FacesMessage)3 TypedQuery (javax.persistence.TypedQuery)3 Session (org.hibernate.Session)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Gson (com.google.gson.Gson)1 SAPConnection (de.destrukt.sapconnection.SAPConnection)1 ParseException (freemarker.core.ParseException)1 MalformedTemplateNameException (freemarker.template.MalformedTemplateNameException)1 CfDiv (io.clownfish.clownfish.datamodels.CfDiv)1 CfLayout (io.clownfish.clownfish.datamodels.CfLayout)1 TemplateDataOutput (io.clownfish.clownfish.datamodels.TemplateDataOutput)1 CfAssetlist (io.clownfish.clownfish.dbentities.CfAssetlist)1 CfClasscontent (io.clownfish.clownfish.dbentities.CfClasscontent)1 CfDatasource (io.clownfish.clownfish.dbentities.CfDatasource)1 CfJavascript (io.clownfish.clownfish.dbentities.CfJavascript)1 CfKeywordlist (io.clownfish.clownfish.dbentities.CfKeywordlist)1 CfList (io.clownfish.clownfish.dbentities.CfList)1 CfSite (io.clownfish.clownfish.dbentities.CfSite)1