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));
}
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();
}
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();
}
Aggregations