Search in sources :

Example 1 with CommunicatorUserLabel

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel)

Example 2 with CommunicatorUserLabel

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;
}
Also used : CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel)

Example 3 with 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();
}
Also used : CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 4 with CommunicatorUserLabel

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();
}
Also used : CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 5 with CommunicatorUserLabel

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();
    }
}
Also used : CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Aggregations

CommunicatorUserLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel)9 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)7 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)7 Path (javax.ws.rs.Path)7 GET (javax.ws.rs.GET)3 DELETE (javax.ws.rs.DELETE)2 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)1 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)1 CommunicatorMessageIdLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1