Search in sources :

Example 1 with CommunicatorMessageTemplate

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate in project muikku by otavanopisto.

the class CommunicatorMessageTemplateDAO method listByUser.

public List<CommunicatorMessageTemplate> listByUser(UserEntity user) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CommunicatorMessageTemplate> criteria = criteriaBuilder.createQuery(CommunicatorMessageTemplate.class);
    Root<CommunicatorMessageTemplate> root = criteria.from(CommunicatorMessageTemplate.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(CommunicatorMessageTemplate_.user), user.getId()));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CommunicatorMessageTemplate(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate)

Example 2 with CommunicatorMessageTemplate

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate in project muikku by otavanopisto.

the class CommunicatorMessageTemplateDAO method create.

public CommunicatorMessageTemplate create(String name, String content, UserEntity user) {
    CommunicatorMessageTemplate messageTemplate = new CommunicatorMessageTemplate();
    messageTemplate.setName(name);
    messageTemplate.setContent(content);
    messageTemplate.setUser(user.getId());
    getEntityManager().persist(messageTemplate);
    return messageTemplate;
}
Also used : CommunicatorMessageTemplate(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate)

Example 3 with CommunicatorMessageTemplate

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate in project muikku by otavanopisto.

the class CommunicatorRESTService method deleteUserMessageTemplate.

@DELETE
@Path("/templates/{TEMPLATEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response deleteUserMessageTemplate(@PathParam("TEMPLATEID") Long templateId) throws AuthorizationException {
    CommunicatorMessageTemplate messageTemplate = communicatorController.getMessageTemplate(templateId);
    if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, messageTemplate)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    communicatorController.deleteMessageTemplate(messageTemplate);
    return Response.noContent().build();
}
Also used : CommunicatorMessageTemplate(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 4 with CommunicatorMessageTemplate

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate in project muikku by otavanopisto.

the class CommunicatorRESTService method editUserMessageTemplate.

@POST
@Path("/templates/{TEMPLATEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response editUserMessageTemplate(@PathParam("TEMPLATEID") Long templateId, CommunicatorMessageTemplateRESTModel template) throws AuthorizationException {
    if (!template.getId().equals(templateId)) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Id is immutable").build();
    }
    CommunicatorMessageTemplate messageTemplate = communicatorController.getMessageTemplate(templateId);
    if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, messageTemplate)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CommunicatorMessageTemplate editMessageTemplate = communicatorController.editMessageTemplate(messageTemplate, template.getName(), template.getContent());
    CommunicatorMessageTemplateRESTModel result = new CommunicatorMessageTemplateRESTModel(editMessageTemplate.getId(), editMessageTemplate.getName(), editMessageTemplate.getContent());
    return Response.ok(result).build();
}
Also used : CommunicatorMessageTemplate(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 5 with CommunicatorMessageTemplate

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate in project muikku by otavanopisto.

the class CommunicatorRESTService method getUserMessageTemplate.

@GET
@Path("/templates/{TEMPLATEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getUserMessageTemplate(@PathParam("TEMPLATEID") Long templateId) throws AuthorizationException {
    CommunicatorMessageTemplate template = communicatorController.getMessageTemplate(templateId);
    if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, template)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CommunicatorMessageTemplateRESTModel result = new CommunicatorMessageTemplateRESTModel(template.getId(), template.getName(), template.getContent());
    return Response.ok(result).build();
}
Also used : CommunicatorMessageTemplate(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

CommunicatorMessageTemplate (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageTemplate)7 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)5 Path (javax.ws.rs.Path)5 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 ArrayList (java.util.ArrayList)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 DELETE (javax.ws.rs.DELETE)1