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