Search in sources :

Example 1 with HtmlMaterialRevisionProperty

use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty 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);
}
Also used : HtmlMaterialRevisionExtensionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty) HtmlMaterialRevisionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)

Example 2 with HtmlMaterialRevisionProperty

use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty 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;
}
Also used : CoOpsUsageException(fi.foyt.coops.CoOpsUsageException) CoOpsSession(fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession) ArrayList(java.util.ArrayList) HtmlMaterialRevisionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty) HtmlMaterialRevision(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision) CoOpsNotFoundException(fi.foyt.coops.CoOpsNotFoundException) HtmlMaterialRevisionExtensionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) Patch(fi.foyt.coops.model.Patch)

Example 3 with HtmlMaterialRevisionProperty

use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty in project muikku by otavanopisto.

the class HtmlMaterialRevisionPropertyDAO method listByHtmlMaterialRevision.

public List<HtmlMaterialRevisionProperty> listByHtmlMaterialRevision(HtmlMaterialRevision htmlMaterialRevision) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<HtmlMaterialRevisionProperty> criteria = criteriaBuilder.createQuery(HtmlMaterialRevisionProperty.class);
    Root<HtmlMaterialRevisionProperty> root = criteria.from(HtmlMaterialRevisionProperty.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(HtmlMaterialRevisionProperty_.htmlMaterialRevision), htmlMaterialRevision));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) HtmlMaterialRevisionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)

Example 4 with HtmlMaterialRevisionProperty

use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty in project muikku by otavanopisto.

the class HtmlMaterialRevisionPropertyDAO method findByHtmlMaterialAndKeyMaxRevision.

public HtmlMaterialRevisionProperty findByHtmlMaterialAndKeyMaxRevision(HtmlMaterial htmlMaterial, String key) {
    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)));
    // 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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) HtmlMaterialRevision(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision) HtmlMaterialRevisionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)

Example 5 with HtmlMaterialRevisionProperty

use of fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty in project muikku by otavanopisto.

the class HtmlMaterialRevisionPropertyDAO method listKeysByHtmlMaterial.

public List<String> listKeysByHtmlMaterial(HtmlMaterial htmlMaterial) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = criteriaBuilder.createQuery(String.class);
    Root<HtmlMaterialRevisionProperty> root = criteria.from(HtmlMaterialRevisionProperty.class);
    Join<HtmlMaterialRevisionProperty, HtmlMaterialRevision> revisionJoin = root.join(HtmlMaterialRevisionProperty_.htmlMaterialRevision);
    criteria.select(root.get(HtmlMaterialRevisionProperty_.key)).distinct(true);
    criteria.where(criteriaBuilder.equal(revisionJoin.get(HtmlMaterialRevision_.htmlMaterial), htmlMaterial));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) HtmlMaterialRevision(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision) HtmlMaterialRevisionProperty(fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)

Aggregations

HtmlMaterialRevisionProperty (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionProperty)7 HtmlMaterialRevision (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision)4 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 HtmlMaterialRevisionExtensionProperty (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevisionExtensionProperty)2 CoOpsNotFoundException (fi.foyt.coops.CoOpsNotFoundException)1 CoOpsUsageException (fi.foyt.coops.CoOpsUsageException)1 Patch (fi.foyt.coops.model.Patch)1 CoOpsSession (fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1 ArrayList (java.util.ArrayList)1