use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel in project muikku by otavanopisto.
the class CommunicatorUserLabelDAO method listByUser.
public List<CommunicatorUserLabel> listByUser(UserEntity userEntity) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<CommunicatorUserLabel> criteria = criteriaBuilder.createQuery(CommunicatorUserLabel.class);
Root<CommunicatorUserLabel> root = criteria.from(CommunicatorUserLabel.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(CommunicatorUserLabel_.userEntity), userEntity.getId()));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel in project muikku by otavanopisto.
the class CommunicatorUserLabelDAO method create.
public CommunicatorUserLabel create(String name, Long color, UserEntity userEntity) {
CommunicatorUserLabel communicatorUserLabel = new CommunicatorUserLabel();
communicatorUserLabel.setName(name);
communicatorUserLabel.setColor(color);
communicatorUserLabel.setUserEntity(userEntity.getId());
getEntityManager().persist(communicatorUserLabel);
return communicatorUserLabel;
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel in project muikku by otavanopisto.
the class CommunicatorLabelRESTService method createUserLabel.
@POST
@Path("/userLabels")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createUserLabel(CommunicatorUserLabelRESTModel newUserLabel) throws AuthorizationException {
UserEntity userEntity = sessionController.getLoggedUserEntity();
// Creates only labels for logged user so we can consider this safe
CommunicatorUserLabel userLabel = communicatorController.createUserLabel(newUserLabel.getName(), newUserLabel.getColor(), userEntity);
return Response.ok(restModels.restUserLabel(userLabel)).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel in project muikku by otavanopisto.
the class CommunicatorLabelRESTService method listUserLabels.
@GET
@Path("/userLabels")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserLabels() throws AuthorizationException {
UserEntity userEntity = sessionController.getLoggedUserEntity();
// Lists only labels of logged user so we can consider this safe
List<CommunicatorUserLabel> userLabels = communicatorController.listUserLabelsByUserEntity(userEntity);
return Response.ok(restModels.restUserLabel(userLabels)).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel in project muikku by otavanopisto.
the class CommunicatorLabelRESTService method editUserLabel.
@PUT
@Path("/userLabels/{USERLABELID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response editUserLabel(@PathParam("USERLABELID") Long userLabelId, CommunicatorUserLabelRESTModel updatedUserLabel) throws AuthorizationException {
if (!updatedUserLabel.getId().equals(userLabelId)) {
return Response.status(Response.Status.BAD_REQUEST).entity("Id is immutable").build();
}
UserEntity userEntity = sessionController.getLoggedUserEntity();
CommunicatorUserLabel userLabel = communicatorController.findUserLabelById(userLabelId);
if ((userLabel != null) && canAccessLabel(userEntity, userLabel)) {
CommunicatorUserLabel editedUserLabel = communicatorController.updateUserLabel(userLabel, updatedUserLabel.getName(), updatedUserLabel.getColor());
return Response.ok(restModels.restUserLabel(editedUserLabel)).build();
} else {
return Response.status(Status.NOT_FOUND).build();
}
}
Aggregations