use of io.clownfish.clownfish.dbentities.CfAttribut 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.CfAttribut in project Clownfish by rawdog71.
the class CfAttributDAOImpl method findByClassref.
@Override
public List<CfAttribut> findByClassref(CfClass classref) {
Session session = this.sessionFactory.getCurrentSession();
TypedQuery query = (TypedQuery) session.getNamedQuery("CfAttribut.findByClassref");
query.setParameter("classref", classref);
List<CfAttribut> cfattributlist = query.getResultList();
return cfattributlist;
}
use of io.clownfish.clownfish.dbentities.CfAttribut in project Clownfish by rawdog71.
the class ContentList method onCreateContent.
public void onCreateContent(ActionEvent actionEvent) {
try {
CfClasscontent newclasscontent = new CfClasscontent();
contentName = contentName.replaceAll("\\s+", "_");
newclasscontent.setName(contentName);
newclasscontent.setClassref(selectedClass);
cfclasscontentService.create(newclasscontent);
List<CfAttribut> attributlist = cfattributService.findByClassref(newclasscontent.getClassref());
attributlist.stream().forEach((attribut) -> {
if (attribut.getAutoincrementor() == true) {
List<CfClasscontent> classcontentlist2 = cfclasscontentService.findByClassref(newclasscontent.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));
cfattributcontentService.create(newcontent);
} else {
CfAttributcontent newcontent = new CfAttributcontent();
newcontent.setAttributref(attribut);
newcontent.setClasscontentref(newclasscontent);
cfattributcontentService.create(newcontent);
}
});
hibernateUtil.insertContent(newclasscontent);
classcontentlist.clear();
classcontentlist = cfclasscontentService.findByMaintenance(true);
FacesMessage message = new FacesMessage("Content created");
FacesContext.getCurrentInstance().addMessage(null, message);
} catch (ConstraintViolationException ex) {
LOGGER.error(ex.getMessage());
}
}
use of io.clownfish.clownfish.dbentities.CfAttribut in project Clownfish by rawdog71.
the class InsertContent method insertContent.
private RestContentParameter insertContent(RestContentParameter icp, HttpServletResponse response) throws IOException {
try {
String apikey = icp.getApikey();
if (apikeyutil.checkApiKey(apikey, "RestService")) {
CfClass clazz = cfclassService.findByName(icp.getClassname());
try {
CfClasscontent classcontent = cfclasscontentService.findByName(icp.getContentname());
response.getOutputStream().println("Duplicate Classcontent: " + icp.getContentname());
icp.setReturncode("NOK");
} catch (javax.persistence.NoResultException ex) {
try {
CfClasscontent newclasscontent = new CfClasscontent();
newclasscontent.setName(icp.getContentname());
newclasscontent.setClassref(clazz);
CfClasscontent newclasscontent2 = cfclasscontentService.create(newclasscontent);
hibernateUtil.insertContent(newclasscontent);
response.getOutputStream().println(newclasscontent.getName());
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));
cfattributcontentService.create(newcontent);
} else {
CfAttributcontent newcontent = new CfAttributcontent();
newcontent.setAttributref(attribut);
newcontent.setClasscontentref(newclasscontent);
newcontent = contentUtil.setAttributValue(newcontent, icp.getAttributmap().get(attribut.getName()));
cfattributcontentService.create(newcontent);
contentUtil.indexContent();
}
});
hibernateUtil.updateContent(newclasscontent);
} catch (IOException ex1) {
LOGGER.error(ex1.getMessage());
}
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
} else {
try {
response.getOutputStream().println("Wrong API KEY");
} catch (IOException ex1) {
LOGGER.error(ex1.getMessage());
}
}
} catch (javax.persistence.NoResultException ex) {
try {
response.getOutputStream().println("Class not found: " + icp.getClassname());
} catch (IOException ex1) {
LOGGER.error(ex1.getMessage());
}
}
return icp;
}
use of io.clownfish.clownfish.dbentities.CfAttribut in project Clownfish by rawdog71.
the class HibernateUtil method makePrimaryKey.
private static void makePrimaryKey(List<CfAttribut> attributlist, Element elementclass, int idcount) {
if (idcount == 1) {
for (CfAttribut attribut : attributlist) {
if (attribut.getIdentity()) {
Element elementproperty = elementclass.addElement("property");
elementproperty.addAttribute("name", attribut.getName());
elementproperty.addAttribute("column", attribut.getName() + "_");
elementproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName()));
elementproperty.addAttribute("index", "idx_" + attribut.getName());
}
}
} else {
for (CfAttribut attribut : attributlist) {
if (attribut.getIdentity()) {
Element elementkeyproperty = elementclass.addElement("property");
elementkeyproperty.addAttribute("name", attribut.getName());
elementkeyproperty.addAttribute("column", attribut.getName() + "_");
elementkeyproperty.addAttribute("type", getHibernateType(attribut.getAttributetype().getName()));
elementkeyproperty.addAttribute("index", "idx_" + attribut.getName());
}
}
}
}
Aggregations