Search in sources :

Example 1 with CfClasscontent

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

the class RestContent method commitContent.

private RestContentParameterExt commitContent(RestContentParameterExt icp) {
    try {
        String token = icp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = icp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                try {
                    CfClasscontent classcontent = cfclasscontentService.findByName(icp.getContentname().trim().replaceAll("\\s+", "_"));
                    if (contentUtil.hasDifference(classcontent)) {
                        try {
                            String content = getContent(classcontent);
                            byte[] output = CompressionUtils.compress(content.getBytes("UTF-8"));
                            try {
                                long maxversion = cfcontentversionService.findMaxVersion(classcontent.getId());
                                contentUtil.setCurrentVersion(maxversion + 1);
                                writeVersion(classcontent.getId(), contentUtil.getCurrentVersion(), output, icp.getUserid());
                                icp.setReturncode("OK");
                            // difference = contentUtil.hasDifference(classcontent);
                            // contentversionMax = contentUtil.getCurrentVersion();
                            // this.selectedcontentversion = this.contentversionMax;
                            } catch (NullPointerException npe) {
                                writeVersion(classcontent.getId(), 1, output, icp.getUserid());
                                contentUtil.setCurrentVersion(1);
                                // difference = contentUtil.hasDifference(classcontent);
                                icp.setReturncode("OK");
                            }
                        } catch (IOException ex) {
                            icp.setReturncode(ex.getMessage());
                            LOGGER.error(ex.getMessage());
                        }
                    } else {
                        icp.setReturncode("Cannot commit");
                    }
                } catch (javax.persistence.NoResultException ex) {
                    icp.setReturncode("Classcontent not found");
                }
            } else {
                icp.setReturncode("Wrong API KEY");
            }
        } else {
            icp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        LOGGER.error("NoResultException");
        icp.setReturncode("NoResultException");
    }
    return icp;
}
Also used : IOException(java.io.IOException) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent)

Example 2 with CfClasscontent

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

the class RestContent method insertContent.

private RestContentParameter insertContent(RestContentParameter icp) {
    try {
        String token = icp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = icp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                CfClass clazz = cfclassService.findByName(icp.getClassname());
                try {
                    CfClasscontent classcontent = cfclasscontentService.findByName(icp.getContentname().trim().replaceAll("\\s+", "_"));
                    LOGGER.warn("Duplicate Classcontent");
                    icp.setReturncode("Duplicate Classcontent");
                } catch (javax.persistence.NoResultException ex) {
                    CfClasscontent newclasscontent = new CfClasscontent();
                    newclasscontent.setName(icp.getContentname().trim().replaceAll("\\s+", "_"));
                    newclasscontent.setClassref(clazz);
                    CfClasscontent newclasscontent2 = cfclasscontentService.create(newclasscontent);
                    hibernateUtil.insertContent(newclasscontent);
                    List<CfAttribut> attributlist = cfattributService.findByClassref(newclasscontent2.getClassref());
                    attributlist.stream().forEach((attribut) -> {
                        if (attribut.getAutoincrementor() == true) {
                            List<CfClasscontent> classcontentlist2 = cfclasscontentService.findByClassref(newclasscontent2.getClassref());
                            long max = 0;
                            int last = classcontentlist2.size();
                            if (1 == last) {
                                max = 0;
                            } else {
                                CfClasscontent classcontent = classcontentlist2.get(last - 2);
                                CfAttributcontent attributcontent = cfattributcontentService.findByAttributrefAndClasscontentref(attribut, classcontent);
                                if (attributcontent.getContentInteger().longValue() > max) {
                                    max = attributcontent.getContentInteger().longValue();
                                }
                            }
                            CfAttributcontent newcontent = new CfAttributcontent();
                            newcontent.setAttributref(attribut);
                            newcontent.setClasscontentref(newclasscontent);
                            newcontent.setContentInteger(BigInteger.valueOf(max + 1));
                            CfAttributcontent newcontent2 = cfattributcontentService.create(newcontent);
                            icp.getAttributmap().put(attribut.getName(), newcontent2.getContentInteger().toString());
                            icp.setReturncode("OK");
                        } else {
                            CfAttributcontent newcontent = new CfAttributcontent();
                            newcontent.setAttributref(attribut);
                            newcontent.setClasscontentref(newclasscontent);
                            newcontent = contentUtil.setAttributValue(newcontent, icp.getAttributmap().get(attribut.getName()));
                            cfattributcontentService.create(newcontent);
                            if (icp.isIndexing()) {
                                contentUtil.indexContent();
                            }
                            icp.setReturncode("OK");
                        }
                    });
                    hibernateUtil.updateContent(newclasscontent);
                }
            } else {
                icp.setReturncode("Wrong API KEY");
            }
        } else {
            icp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        LOGGER.error("NoResultException");
        icp.setReturncode("NoResultException");
    }
    return icp;
}
Also used : CfContentversion(io.clownfish.clownfish.dbentities.CfContentversion) CfListService(io.clownfish.clownfish.serviceinterface.CfListService) CfSitecontent(io.clownfish.clownfish.dbentities.CfSitecontent) CfContentversionService(io.clownfish.clownfish.serviceinterface.CfContentversionService) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) AuthTokenList(io.clownfish.clownfish.datamodels.AuthTokenList) ContentUtil(io.clownfish.clownfish.utils.ContentUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) RestContentParameterExt(io.clownfish.clownfish.datamodels.RestContentParameterExt) ClassUtil(io.clownfish.clownfish.utils.ClassUtil) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) RestContentParameter(io.clownfish.clownfish.datamodels.RestContentParameter) CfClass(io.clownfish.clownfish.dbentities.CfClass) RequestBody(org.springframework.web.bind.annotation.RequestBody) CfClassService(io.clownfish.clownfish.serviceinterface.CfClassService) CfAttributcontentService(io.clownfish.clownfish.serviceinterface.CfAttributcontentService) CfSitecontentService(io.clownfish.clownfish.serviceinterface.CfSitecontentService) CompressionUtils(io.clownfish.clownfish.utils.CompressionUtils) CfClasscontentKeywordService(io.clownfish.clownfish.serviceinterface.CfClasscontentKeywordService) BigInteger(java.math.BigInteger) CfAttributService(io.clownfish.clownfish.serviceinterface.CfAttributService) CfListcontentService(io.clownfish.clownfish.serviceinterface.CfListcontentService) CfClasscontentService(io.clownfish.clownfish.serviceinterface.CfClasscontentService) PostMapping(org.springframework.web.bind.annotation.PostMapping) HibernateUtil(io.clownfish.clownfish.utils.HibernateUtil) Logger(org.slf4j.Logger) CfAttribut(io.clownfish.clownfish.dbentities.CfAttribut) CfAttributetypeService(io.clownfish.clownfish.serviceinterface.CfAttributetypeService) IOException(java.io.IOException) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) RestController(org.springframework.web.bind.annotation.RestController) ApiKeyUtil(io.clownfish.clownfish.utils.ApiKeyUtil) List(java.util.List) CfClasscontentkeyword(io.clownfish.clownfish.dbentities.CfClasscontentkeyword) CfAssetService(io.clownfish.clownfish.serviceinterface.CfAssetService) CfContentversionPK(io.clownfish.clownfish.dbentities.CfContentversionPK) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) CfClass(io.clownfish.clownfish.dbentities.CfClass) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) AuthTokenList(io.clownfish.clownfish.datamodels.AuthTokenList) List(java.util.List) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent)

Example 3 with CfClasscontent

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

the class RestContent method deleteContent.

private RestContentParameter deleteContent(RestContentParameter ucp) {
    try {
        String token = ucp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = ucp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                CfClass clazz = cfclassService.findByName(ucp.getClassname());
                try {
                    CfClasscontent classcontent = cfclasscontentService.findByName(ucp.getContentname());
                    classcontent.setScrapped(true);
                    cfclasscontentService.edit(classcontent);
                    ucp.setReturncode("OK");
                    hibernateUtil.updateContent(classcontent);
                } catch (javax.persistence.NoResultException ex) {
                    ucp.setReturncode("Classcontent not found");
                }
            } else {
                ucp.setReturncode("Wrong API KEY");
            }
        } else {
            ucp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        ucp.setReturncode("NoResultException");
    }
    return ucp;
}
Also used : CfClass(io.clownfish.clownfish.dbentities.CfClass) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent)

Example 4 with CfClasscontent

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

the class RestContent method destroyContent.

private RestContentParameter destroyContent(RestContentParameter ucp) {
    try {
        String token = ucp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = ucp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                CfClass clazz = cfclassService.findByName(ucp.getClassname());
                try {
                    CfClasscontent classcontent = cfclasscontentService.findByName(ucp.getContentname());
                    // Delete corresponding attributcontent entries
                    List<CfAttributcontent> attributcontentlistdummy = cfattributcontentService.findByClasscontentref(classcontent);
                    for (CfAttributcontent attributcontent : attributcontentlistdummy) {
                        cfattributcontentService.delete(attributcontent);
                    }
                    // Delete corresponding listcontent entries
                    List<CfListcontent> selectedcontent = cflistcontentService.findByClasscontentref(classcontent.getId());
                    for (CfListcontent listcontent : selectedcontent) {
                        cflistcontentService.delete(listcontent);
                    }
                    // Delete corresponding keywordcontent entries
                    List<CfClasscontentkeyword> keywordcontentdummy = cfclasscontentkeywordService.findByClassContentRef(classcontent.getId());
                    for (CfClasscontentkeyword keywordcontent : keywordcontentdummy) {
                        cfclasscontentkeywordService.delete(keywordcontent);
                    }
                    // Delete corresponding sitecontent entries
                    List<CfSitecontent> sitecontentdummy = cfsitecontentService.findByClasscontentref(classcontent.getId());
                    for (CfSitecontent sitecontent : sitecontentdummy) {
                        cfsitecontentService.delete(sitecontent);
                    }
                    cfclasscontentService.delete(classcontent);
                    try {
                        hibernateUtil.deleteContent(classcontent);
                    } catch (javax.persistence.NoResultException ex) {
                        LOGGER.warn(ex.getMessage());
                    }
                    ucp.setReturncode("OK");
                } catch (javax.persistence.NoResultException ex) {
                    ucp.setReturncode("Classcontent not found");
                }
            } else {
                ucp.setReturncode("Wrong API KEY");
            }
        } else {
            ucp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        ucp.setReturncode("NoResultException");
    }
    return ucp;
}
Also used : CfClasscontentkeyword(io.clownfish.clownfish.dbentities.CfClasscontentkeyword) CfClass(io.clownfish.clownfish.dbentities.CfClass) CfSitecontent(io.clownfish.clownfish.dbentities.CfSitecontent) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent)

Example 5 with CfClasscontent

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

the class CfClasscontentDAOImpl method findByName.

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

Aggregations

CfClasscontent (io.clownfish.clownfish.dbentities.CfClasscontent)45 CfAttributcontent (io.clownfish.clownfish.dbentities.CfAttributcontent)24 CfListcontent (io.clownfish.clownfish.dbentities.CfListcontent)22 CfList (io.clownfish.clownfish.dbentities.CfList)21 Map (java.util.Map)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 Gson (com.google.gson.Gson)13 CfClass (io.clownfish.clownfish.dbentities.CfClass)13 IOException (java.io.IOException)13 List (java.util.List)12 CfAttributService (io.clownfish.clownfish.serviceinterface.CfAttributService)9 CfAttributcontentService (io.clownfish.clownfish.serviceinterface.CfAttributcontentService)9 CfClassService (io.clownfish.clownfish.serviceinterface.CfClassService)9 CfClasscontentService (io.clownfish.clownfish.serviceinterface.CfClasscontentService)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 CfAttributetypeService (io.clownfish.clownfish.serviceinterface.CfAttributetypeService)8 CfListService (io.clownfish.clownfish.serviceinterface.CfListService)8 Session (org.hibernate.Session)8 Logger (org.slf4j.Logger)8