use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision in project muikku by otavanopisto.
the class HtmlMaterialRevisionPropertyDAO method findByHtmlMaterialAndKeyRevisionLeAndMaxRevision.
public HtmlMaterialRevisionProperty findByHtmlMaterialAndKeyRevisionLeAndMaxRevision(HtmlMaterial htmlMaterial, String key, Long revisionLe) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<HtmlMaterialRevisionProperty> criteria = criteriaBuilder.createQuery(HtmlMaterialRevisionProperty.class);
Root<HtmlMaterialRevisionProperty> root = criteria.from(HtmlMaterialRevisionProperty.class);
Join<HtmlMaterialRevisionProperty, HtmlMaterialRevision> revisionJoin = root.join(HtmlMaterialRevisionProperty_.htmlMaterialRevision);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(HtmlMaterialRevisionProperty_.key), key), criteriaBuilder.equal(revisionJoin.get(HtmlMaterialRevision_.htmlMaterial), htmlMaterial), criteriaBuilder.lessThanOrEqualTo(revisionJoin.get(HtmlMaterialRevision_.revision), revisionLe)));
// TODO: This could be optimized
criteria.orderBy(criteriaBuilder.desc(revisionJoin.get(HtmlMaterialRevision_.revision)));
TypedQuery<HtmlMaterialRevisionProperty> query = entityManager.createQuery(criteria);
query.setMaxResults(1);
return getSingleResult(query);
}
use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision in project muikku by otavanopisto.
the class HtmlMaterialCleaner method patch.
public void patch(HtmlMaterial material, String newHtml) throws CoOpsUsageException, CoOpsInternalErrorException, WorkspaceMaterialContainsAnswersExeption {
CoOpsDiffAlgorithm algorithm = htmlMaterialController.findAlgorithm(COOPS_PATCH_ALGORITHM);
if (algorithm == null) {
throw new CoOpsUsageException("Algorithm is not supported by this server");
}
Long maxRevision = getMaterialRevision(material);
boolean published = material.getRevisionNumber().equals(maxRevision);
String oldHtml = htmlMaterialController.getRevisionHtml(material, maxRevision);
if (oldHtml == null) {
oldHtml = "";
}
String checksum = DigestUtils.md5Hex(newHtml);
String patch = createPatch(oldHtml, newHtml);
Long patchRevisionNumber = maxRevision + 1;
HtmlMaterialRevision htmlMaterialRevision = htmlMaterialController.createRevision(material, "dnm-cleaner", patchRevisionNumber, new Date(), patch, checksum);
if (published) {
htmlMaterialController.updateHtmlMaterialToRevision(material, newHtml, htmlMaterialRevision.getRevision(), false, false);
}
}
Aggregations