Search in sources :

Example 1 with CfAssetlist

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

the class CfAssetlistDAOImpl method findByName.

@Override
public CfAssetlist findByName(String name) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfAssetlist.findByName");
    query.setParameter("name", name);
    CfAssetlist cfassetlist = (CfAssetlist) query.getSingleResult();
    return cfassetlist;
}
Also used : TypedQuery(javax.persistence.TypedQuery) CfAssetlist(io.clownfish.clownfish.dbentities.CfAssetlist) Session(org.hibernate.Session)

Example 2 with CfAssetlist

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

the class ContentUtil method setAttributValue.

public CfAttributcontent setAttributValue(CfAttributcontent selectedAttribut, String editContent) {
    if (null == editContent) {
        editContent = "";
    }
    try {
        switch(selectedAttribut.getAttributref().getAttributetype().getName()) {
            case "boolean":
                selectedAttribut.setContentBoolean(Boolean.valueOf(editContent));
                break;
            case "string":
                if (editContent.length() > 255) {
                    editContent = editContent.substring(0, 255);
                }
                if (selectedAttribut.getAttributref().getIdentity() == true) {
                    List<CfClasscontent> classcontentlist2 = cfclasscontentService.findByClassref(selectedAttribut.getClasscontentref().getClassref());
                    boolean found = false;
                    for (CfClasscontent classcontent : classcontentlist2) {
                        try {
                            CfAttributcontent attributcontent = cfattributcontentService.findByAttributrefAndClasscontentref(selectedAttribut.getAttributref(), classcontent);
                            if (attributcontent.getContentString().compareToIgnoreCase(editContent) == 0) {
                                found = true;
                            }
                        } catch (javax.persistence.NoResultException | NullPointerException ex) {
                            LOGGER.error(ex.getMessage());
                        }
                    }
                    if (!found) {
                        selectedAttribut.setContentString(editContent);
                    }
                } else {
                    selectedAttribut.setContentString(editContent);
                }
                break;
            case "hashstring":
                String salt = PasswordUtil.getSalt(30);
                selectedAttribut.setContentString(PasswordUtil.generateSecurePassword(editContent, salt));
                selectedAttribut.setSalt(salt);
                break;
            case "integer":
                selectedAttribut.setContentInteger(BigInteger.valueOf(Long.parseLong(editContent)));
                break;
            case "real":
                selectedAttribut.setContentReal(Double.parseDouble(editContent));
                break;
            case "htmltext":
                selectedAttribut.setContentText(editContent);
                break;
            case "text":
                selectedAttribut.setContentText(editContent);
                break;
            case "markdown":
                selectedAttribut.setContentText(editContent);
                break;
            case "datetime":
                Date datum;
                DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withZone(DateTimeZone.forID("Europe/Berlin"));
                try {
                    datum = DateTime.parse(editContent, fmt).toDate();
                    selectedAttribut.setContentDate(datum);
                } catch (IllegalArgumentException ex) {
                    try {
                        fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(DateTimeZone.forID("Europe/Berlin"));
                        datum = DateTime.parse(editContent, fmt).toDate();
                        selectedAttribut.setContentDate(datum);
                    } catch (IllegalArgumentException ex2) {
                        fmt = DateTimeFormat.forPattern("dd.MM.yyyy HH:mm:ss").withZone(DateTimeZone.forID("Europe/Berlin"));
                        datum = DateTime.parse(editContent, fmt).toDate();
                        selectedAttribut.setContentDate(datum);
                    }
                }
                break;
            case "media":
                if (null != editContent) {
                    try {
                        CfAsset asset = cfassetService.findByName(editContent);
                        selectedAttribut.setContentInteger(BigInteger.valueOf(asset.getId()));
                    } catch (Exception ex) {
                        selectedAttribut.setContentInteger(null);
                        LOGGER.error("INSERTCONTENT: Media " + editContent + " not found!");
                    }
                } else {
                    selectedAttribut.setContentInteger(null);
                }
                break;
            case "classref":
                if (null != editContent) {
                    CfList list_ref = cflistService.findById(Long.parseLong(editContent));
                    selectedAttribut.setClasscontentlistref(list_ref);
                }
                break;
            case "assetref":
                if (null != editContent) {
                    CfAssetlist assetlist_ref = cfassetlistService.findById(Long.parseLong(editContent));
                    selectedAttribut.setAssetcontentlistref(assetlist_ref);
                }
                break;
        }
        selectedAttribut.setIndexed(false);
        return selectedAttribut;
    } catch (NullPointerException ex) {
        LOGGER.warn(ex.getMessage());
        return selectedAttribut;
    }
}
Also used : CfAssetlist(io.clownfish.clownfish.dbentities.CfAssetlist) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) Date(java.util.Date) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) CfAsset(io.clownfish.clownfish.dbentities.CfAsset) CfList(io.clownfish.clownfish.dbentities.CfList) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 3 with CfAssetlist

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

the class SiteUtil method getSiteAssetlibrary.

public Map getSiteAssetlibrary(CfSite cfsite, Map sitecontentmap) {
    List<CfSiteassetlist> siteassetlibrary = new ArrayList<>();
    siteassetlibrary.addAll(cfsiteassetlistService.findBySiteref(cfsite.getId()));
    HashMap<String, ArrayList> assetlibraryMap = new HashMap<>();
    for (CfSiteassetlist siteassetlist : siteassetlibrary) {
        CfAssetlist cfassetlist = cfassetlistService.findById(siteassetlist.getCfSiteassetlistPK().getAssetlistref());
        List<CfAssetlistcontent> assetlist = new ArrayList<>();
        assetlist.addAll(cfassetlistcontentService.findByAssetlistref(cfassetlist.getId()));
        ArrayList<CfAsset> dummyassetlist = new ArrayList<>();
        for (CfAssetlistcontent assetcontent : assetlist) {
            CfAsset asset = cfassetService.findById(assetcontent.getCfAssetlistcontentPK().getAssetref());
            if (null != asset) {
                dummyassetlist.add(asset);
            } else {
                LOGGER.warn("ASSET NOT FOUND (deleted or on scrapyard): " + assetcontent.getCfAssetlistcontentPK().getAssetref());
            }
        }
        assetlibraryMap.put(cfassetlist.getName(), dummyassetlist);
    }
    sitecontentmap.put("AssetLibrary", assetlibraryMap);
    return sitecontentmap;
}
Also used : CfAsset(io.clownfish.clownfish.dbentities.CfAsset) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) CfSiteassetlist(io.clownfish.clownfish.dbentities.CfSiteassetlist) CfAssetlist(io.clownfish.clownfish.dbentities.CfAssetlist) CfAssetlistcontent(io.clownfish.clownfish.dbentities.CfAssetlistcontent)

Example 4 with CfAssetlist

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

the class ClassUtil method jsonImport.

public List<CfAttributcontent> jsonImport(String jsoncontent) {
    ArrayList<CfAttributcontent> attributcontentlist = new ArrayList<>();
    Gson gson = new Gson();
    RestContentParameter contentparameter = gson.fromJson(jsoncontent, RestContentParameter.class);
    CfClass clazz = cfclassService.findByName(contentparameter.getClassname());
    List<CfAttribut> attributlist = cfattributService.findByClassref(clazz);
    for (String key : contentparameter.getAttributmap().keySet()) {
        CfAttribut attribut = getAttributFromAttributlist(attributlist, key);
        CfAttributcontent attributcontent = new CfAttributcontent();
        attributcontent.setAttributref(attribut);
        switch(attribut.getAttributetype().getName()) {
            case "boolean":
                attributcontent.setContentBoolean(true);
                break;
            case "string":
            case "hashstring":
                attributcontent.setContentString(contentparameter.getAttributmap().get(key));
                break;
            case "integer":
                attributcontent.setContentInteger(BigInteger.valueOf(Long.parseLong(contentparameter.getAttributmap().get(key))));
                break;
            case "real":
                attributcontent.setContentReal(Double.parseDouble(contentparameter.getAttributmap().get(key)));
                break;
            case "htmltext":
            case "text":
            case "markdown":
                attributcontent.setContentText(contentparameter.getAttributmap().get(key));
                break;
            case "datetime":
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.GERMAN);
                Date date;
                try {
                    date = formatter.parse(contentparameter.getAttributmap().get(key));
                    attributcontent.setContentDate(date);
                } catch (ParseException ex) {
                    java.util.logging.Logger.getLogger(ClassUtil.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;
            case "media":
                CfAsset asset = cfassetService.findByName(contentparameter.getAttributmap().get(key));
                attributcontent.setContentInteger(BigInteger.valueOf(asset.getId()));
                break;
            case "classref":
                try {
                    CfList list = cflistService.findByName(contentparameter.getAttributmap().get(key));
                    attributcontent.setClasscontentlistref(list);
                } catch (Exception ex) {
                    attributcontent.setClasscontentlistref(null);
                }
                break;
            case "assetref":
                try {
                    CfAssetlist assetlist = cfassetlistService.findByName(contentparameter.getAttributmap().get(key));
                    attributcontent.setAssetcontentlistref(assetlist);
                } catch (Exception ex) {
                    attributcontent.setAssetcontentlistref(null);
                }
                break;
        }
        attributcontentlist.add(attributcontent);
    }
    return attributcontentlist;
}
Also used : CfClass(io.clownfish.clownfish.dbentities.CfClass) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) CfAttribut(io.clownfish.clownfish.dbentities.CfAttribut) CfAssetlist(io.clownfish.clownfish.dbentities.CfAssetlist) Date(java.util.Date) ParseException(java.text.ParseException) IOException(java.io.IOException) CfAsset(io.clownfish.clownfish.dbentities.CfAsset) CfList(io.clownfish.clownfish.dbentities.CfList) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) RestContentParameter(io.clownfish.clownfish.datamodels.RestContentParameter) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with CfAssetlist

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

CfAssetlist (io.clownfish.clownfish.dbentities.CfAssetlist)17 CfAsset (io.clownfish.clownfish.dbentities.CfAsset)8 CfAssetlistcontent (io.clownfish.clownfish.dbentities.CfAssetlistcontent)8 ArrayList (java.util.ArrayList)5 CfList (io.clownfish.clownfish.dbentities.CfList)4 IOException (java.io.IOException)4 Gson (com.google.gson.Gson)3 CfClasscontent (io.clownfish.clownfish.dbentities.CfClasscontent)3 CfSiteassetlist (io.clownfish.clownfish.dbentities.CfSiteassetlist)3 HashMap (java.util.HashMap)3 TypedQuery (javax.persistence.TypedQuery)3 Session (org.hibernate.Session)3 CfAttributcontent (io.clownfish.clownfish.dbentities.CfAttributcontent)2 CfDatasource (io.clownfish.clownfish.dbentities.CfDatasource)2 CfKeywordlist (io.clownfish.clownfish.dbentities.CfKeywordlist)2 CfSitecontent (io.clownfish.clownfish.dbentities.CfSitecontent)2 CfSitedatasource (io.clownfish.clownfish.dbentities.CfSitedatasource)2 CfSitekeywordlist (io.clownfish.clownfish.dbentities.CfSitekeywordlist)2 CfSitelist (io.clownfish.clownfish.dbentities.CfSitelist)2 PrintWriter (java.io.PrintWriter)2