Search in sources :

Example 6 with MaterialMeta

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

the class MaterialMetaDAO method findByMaterialAndKey.

public MaterialMeta findByMaterialAndKey(Material material, MaterialMetaKey key) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<MaterialMeta> criteria = criteriaBuilder.createQuery(MaterialMeta.class);
    Root<MaterialMeta> root = criteria.from(MaterialMeta.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(MaterialMeta_.key), key), criteriaBuilder.equal(root.get(MaterialMeta_.material), material)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta)

Example 7 with MaterialMeta

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

the class MaterialMetaRESTService method updateMaterialMeta.

@PUT
@Path("/materials/{id}/meta/{KEY}")
@Produces(MediaType.APPLICATION_JSON)
@RESTPermitUnimplemented
public Response updateMaterialMeta(@PathParam("id") Long id, @PathParam("KEY") String key, fi.otavanopisto.muikku.plugins.material.rest.MaterialMeta payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.MANAGE_MATERIAL_META)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if (payload.getKey() != null && !StringUtils.equals(payload.getKey(), key)) {
        return Response.status(Status.BAD_REQUEST).entity("Can not update material meta key").build();
    }
    Material material = materialController.findMaterialById(id);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).entity("Material not found").build();
    }
    MaterialMetaKey materialMetaKey = materialController.findMaterialMetaKey(key);
    if (materialMetaKey == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid key").build();
    }
    MaterialMeta materialMeta = materialController.findMaterialMeta(material, materialMetaKey);
    if (materialMeta == null) {
        return Response.status(Status.BAD_REQUEST).entity("MaterialMeta not found").build();
    }
    return Response.ok(createRestModel(materialController.updateMaterialMeta(materialMeta, payload.getValue()))).build();
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) MaterialMetaKey(fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey) Material(fi.otavanopisto.muikku.plugins.material.model.Material) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) PUT(javax.ws.rs.PUT)

Example 8 with MaterialMeta

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

the class MaterialMetaRESTService method findMaterialMeta.

@GET
@Path("/materials/{id}/meta/{KEY}")
@Produces(MediaType.APPLICATION_JSON)
@RESTPermitUnimplemented
public Response findMaterialMeta(@PathParam("id") Long id, @PathParam("KEY") String key) {
    Material material = materialController.findMaterialById(id);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).entity("Material not found").build();
    }
    MaterialMetaKey materialMetaKey = materialController.findMaterialMetaKey(key);
    if (materialMetaKey == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid key").build();
    }
    MaterialMeta materialMeta = materialController.findMaterialMeta(material, materialMetaKey);
    if (materialMeta == null) {
        return Response.status(Status.NOT_FOUND).entity("Material meta not found").build();
    }
    return Response.ok(createRestModel(materialMeta)).build();
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) MaterialMetaKey(fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey) Material(fi.otavanopisto.muikku.plugins.material.model.Material) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Aggregations

MaterialMeta (fi.otavanopisto.muikku.plugins.material.model.MaterialMeta)8 Material (fi.otavanopisto.muikku.plugins.material.model.Material)3 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 MaterialMetaKey (fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey)2 MaterialProducer (fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 GET (javax.ws.rs.GET)2 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1 PUT (javax.ws.rs.PUT)1