use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty in project muikku by otavanopisto.
the class HtmlMaterialController method deleteRevision.
private void deleteRevision(HtmlMaterialRevision revision) {
List<HtmlMaterialRevisionExtensionProperty> extensionProperties = listRevisionExtensionProperties(revision);
List<HtmlMaterialRevisionProperty> properties = listRevisionProperties(revision);
for (HtmlMaterialRevisionExtensionProperty extensionProperty : extensionProperties) {
htmlMaterialRevisionExtensionPropertyDAO.delete(extensionProperty);
}
for (HtmlMaterialRevisionProperty property : properties) {
htmlMaterialRevisionPropertyDAO.delete(property);
}
htmlMaterialRevisionDAO.delete(revision);
}
use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty in project muikku by otavanopisto.
the class CoOpsApiImpl method fileUpdate.
public List<Patch> fileUpdate(String fileId, String sessionId, Long revisionNumber) throws CoOpsNotFoundException, CoOpsInternalErrorException, CoOpsUsageException, CoOpsForbiddenException {
CoOpsSession session = coOpsSessionController.findSessionBySessionId(sessionId);
if (session == null) {
throw new CoOpsUsageException("Invalid session id");
}
if (revisionNumber == null) {
throw new CoOpsUsageException("revisionNumber parameter is missing");
}
HtmlMaterial htmlMaterial = findFile(fileId);
if (htmlMaterial == null) {
throw new CoOpsNotFoundException();
}
List<Patch> updateResults = new ArrayList<>();
List<HtmlMaterialRevision> htmlMaterialRevisions = htmlMaterialController.listRevisionsAfter(htmlMaterial, revisionNumber);
if (!htmlMaterialRevisions.isEmpty()) {
for (HtmlMaterialRevision htmlMaterialRevision : htmlMaterialRevisions) {
String patch = htmlMaterialRevision.getData();
Map<String, String> properties = null;
Map<String, Object> extensions = null;
List<HtmlMaterialRevisionProperty> revisionProperties = htmlMaterialController.listRevisionProperties(htmlMaterialRevision);
if (revisionProperties.size() > 0) {
properties = new HashMap<>();
for (HtmlMaterialRevisionProperty revisionProperty : revisionProperties) {
properties.put(revisionProperty.getKey(), revisionProperty.getValue());
}
}
List<HtmlMaterialRevisionExtensionProperty> revisionExtensionProperties = htmlMaterialController.listRevisionExtensionProperties(htmlMaterialRevision);
if (revisionExtensionProperties.size() > 0) {
extensions = new HashMap<>();
for (HtmlMaterialRevisionExtensionProperty revisionExtensionProperty : revisionExtensionProperties) {
extensions.put(revisionExtensionProperty.getKey(), revisionExtensionProperty.getValue());
}
}
if (patch != null) {
updateResults.add(new Patch(htmlMaterialRevision.getSessionId(), htmlMaterialRevision.getRevision(), htmlMaterialRevision.getChecksum(), patch, properties, extensions));
} else {
updateResults.add(new Patch(htmlMaterialRevision.getSessionId(), htmlMaterialRevision.getRevision(), null, null, properties, extensions));
}
}
}
return updateResults;
}
use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty in project muikku by otavanopisto.
the class HtmlMaterialRevisionExtensionPropertyDAO method listByHtmlMaterialRevision.
public List<HtmlMaterialRevisionExtensionProperty> listByHtmlMaterialRevision(HtmlMaterialRevision htmlMaterialRevision) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<HtmlMaterialRevisionExtensionProperty> criteria = criteriaBuilder.createQuery(HtmlMaterialRevisionExtensionProperty.class);
Root<HtmlMaterialRevisionExtensionProperty> root = criteria.from(HtmlMaterialRevisionExtensionProperty.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(HtmlMaterialRevisionExtensionProperty_.htmlMaterialRevision), htmlMaterialRevision));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty in project muikku by otavanopisto.
the class HtmlMaterialRevisionExtensionPropertyDAO method create.
public HtmlMaterialRevisionExtensionProperty create(HtmlMaterialRevision htmlMaterialRevision, String key, String value) {
HtmlMaterialRevisionExtensionProperty htmlMaterialRevisionExtensionProperty = new HtmlMaterialRevisionExtensionProperty();
htmlMaterialRevisionExtensionProperty.setFileRevision(htmlMaterialRevision);
htmlMaterialRevisionExtensionProperty.setValue(value);
htmlMaterialRevisionExtensionProperty.setKey(key);
return persist(htmlMaterialRevisionExtensionProperty);
}
Aggregations