Search in sources :

Example 1 with MaterialMeta

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

the class MaterialMetaRESTService method listMaterialMetas.

@GET
@Path("/materials/{id}/meta/")
@Produces(MediaType.APPLICATION_JSON)
@RESTPermitUnimplemented
public Response listMaterialMetas(@PathParam("id") Long id) {
    Material material = materialController.findMaterialById(id);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).entity("Material not found").build();
    }
    List<MaterialMeta> metas = materialController.listMaterialMetas(material);
    if (metas.isEmpty()) {
        return Response.noContent().build();
    }
    return Response.ok(createRestModel(metas.toArray(new MaterialMeta[0]))).build();
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) 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)

Example 2 with MaterialMeta

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

the class BinaryMaterialCloneOperation method clone.

@Override
public BinaryMaterial clone(BinaryMaterial material) {
    BinaryMaterial clonedMaterial = binaryMaterialController.createBinaryMaterial(material.getTitle(), material.getContentType(), material.getContent(), material, material.getLicense(), material.getViewRestrict());
    List<MaterialMeta> materialMetas = materialController.listMaterialMetas(material);
    for (MaterialMeta materialMeta : materialMetas) {
        materialController.createMaterialMeta(clonedMaterial, materialMeta.getKey(), materialMeta.getValue());
    }
    List<MaterialProducer> materialProducers = materialController.listMaterialProducers(material);
    for (MaterialProducer materialProducer : materialProducers) {
        materialController.createMaterialProducer(clonedMaterial, materialProducer.getName());
    }
    return clonedMaterial;
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)

Example 3 with MaterialMeta

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

the class HtmlMaterialCloneOperation method clone.

@Override
public HtmlMaterial clone(HtmlMaterial material) {
    HtmlMaterial clonedMaterial = htmlMaterialController.createHtmlMaterial(material.getTitle(), material.getHtml(), material.getContentType(), new Long(0), material, material.getLicense(), material.getViewRestrict());
    List<MaterialMeta> materialMetas = materialController.listMaterialMetas(material);
    for (MaterialMeta materialMeta : materialMetas) {
        materialController.createMaterialMeta(clonedMaterial, materialMeta.getKey(), materialMeta.getValue());
    }
    List<MaterialProducer> materialProducers = materialController.listMaterialProducers(material);
    for (MaterialProducer materialProducer : materialProducers) {
        materialController.createMaterialProducer(clonedMaterial, materialProducer.getName());
    }
    return clonedMaterial;
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) MaterialProducer(fi.otavanopisto.muikku.plugins.material.model.MaterialProducer)

Example 4 with MaterialMeta

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

the class MaterialMetaDAO method create.

public MaterialMeta create(Material material, MaterialMetaKey key, String value) {
    MaterialMeta materialMeta = new MaterialMeta();
    materialMeta.setKey(key);
    materialMeta.setMaterial(material);
    materialMeta.setValue(value);
    return persist(materialMeta);
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta)

Example 5 with MaterialMeta

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

the class MaterialMetaDAO method listByMaterial.

public List<MaterialMeta> listByMaterial(Material material) {
    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.equal(root.get(MaterialMeta_.material), material));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta)

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