use of io.clownfish.clownfish.dbentities.CfClass 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;
}
use of io.clownfish.clownfish.dbentities.CfClass 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;
}
use of io.clownfish.clownfish.dbentities.CfClass 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;
}
use of io.clownfish.clownfish.dbentities.CfClass in project Clownfish by rawdog71.
the class CfClassDAOImpl method findById.
@Override
public CfClass findById(Long id) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfClass.findById");
query.setParameter("id", id);
CfClass cfclass = (CfClass) query.getSingleResult();
return cfclass;
}
use of io.clownfish.clownfish.dbentities.CfClass in project Clownfish by rawdog71.
the class SiteTreeBean method onChangeLayoutContent.
public void onChangeLayoutContent() {
if (null != selected_contentclass) {
current_layoutcontent = null;
showContent = true;
showDatalist = false;
showAsset = false;
showAssetLibrary = false;
showKeywordLibrary = false;
String[] contentinfos = selected_contentclass.split(":");
String contentclass = contentinfos[0];
CfClass selectedclass = cfclassService.findByName(contentclass);
int lfdnr = Integer.parseInt(contentinfos[1]);
List<CfLayoutcontent> layoutcontentlist = cflayoutcontentService.findBySiterefAndTemplaterefAndContenttype(selectedSite.getId(), selectedDivTemplate.getId(), "C");
long classcontentref = 0;
for (CfLayoutcontent layoutcontent : layoutcontentlist) {
if (layoutcontent.getCfLayoutcontentPK().getLfdnr() == lfdnr) {
classcontentref = layoutcontent.getPreview_contentref().longValue();
current_layoutcontent = layoutcontent;
}
}
if (0 != classcontentref) {
current_classcontent = cfclasscontentService.findById(classcontentref);
}
current_classcontentlist = cfclasscontentService.findByClassref(selectedclass);
selected_datalisttclass = null;
selected_asset = null;
selected_assetlist = null;
selected_keywordlist = null;
}
}
Aggregations