use of fi.otavanopisto.muikku.plugins.material.coops.CoOpsDiffAlgorithm in project muikku by otavanopisto.
the class HtmlMaterialController method getAlgorithmMap.
private Map<String, CoOpsDiffAlgorithm> getAlgorithmMap() {
Map<String, CoOpsDiffAlgorithm> result = new HashMap<>();
Iterator<CoOpsDiffAlgorithm> iterator = this.algorithms.iterator();
while (iterator.hasNext()) {
CoOpsDiffAlgorithm algorithm = iterator.next();
result.put(algorithm.getName(), algorithm);
}
return result;
}
use of fi.otavanopisto.muikku.plugins.material.coops.CoOpsDiffAlgorithm in project muikku by otavanopisto.
the class HtmlMaterialController method getRevisionHtml.
public String getRevisionHtml(HtmlMaterial htmlMaterial, long revision) throws CoOpsInternalErrorException {
String result = htmlMaterial.getHtml();
if (result == null) {
result = "";
}
long baselineRevision = htmlMaterial.getRevisionNumber();
CoOpsDiffAlgorithm algorithm = findAlgorithm("dmp");
if (revision < baselineRevision) {
List<HtmlMaterialRevision> revisions = htmlMaterialRevisionDAO.listByFileAndRevisionGeAndRevisonLtOrderedByRevision(htmlMaterial, revision, baselineRevision);
for (int i = revisions.size() - 1; i >= 0; i--) {
HtmlMaterialRevision patchingRevision = revisions.get(i);
try {
if (patchingRevision.getData() != null) {
result = algorithm.unpatch(result, patchingRevision.getData());
}
} catch (CoOpsConflictException e) {
throw new CoOpsInternalErrorException("Patch failed when building material revision number " + revision);
}
}
} else {
List<HtmlMaterialRevision> revisions = htmlMaterialRevisionDAO.listByFileAndRevisionGtAndRevisonLeOrderedByRevision(htmlMaterial, baselineRevision, revision);
for (HtmlMaterialRevision patchingRevision : revisions) {
try {
if (patchingRevision.getData() != null) {
result = algorithm.patch(result, patchingRevision.getData());
}
} catch (CoOpsConflictException e) {
throw new CoOpsInternalErrorException("Patch failed when building material revision number " + revision);
}
}
}
return result;
}
use of fi.otavanopisto.muikku.plugins.material.coops.CoOpsDiffAlgorithm 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