Search in sources :

Example 1 with CommunicatorMessageSignature

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

the class CommunicatorRESTService method deleteUserMessageSignature.

@DELETE
@Path("/signatures/{SIGNATUREID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response deleteUserMessageSignature(@PathParam("SIGNATUREID") Long signatureId) throws AuthorizationException {
    CommunicatorMessageSignature messageSignature = communicatorController.getMessageSignature(signatureId);
    if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, messageSignature)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    communicatorController.deleteMessageSignature(messageSignature);
    return Response.noContent().build();
}
Also used : CommunicatorMessageSignature(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageSignature) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 2 with CommunicatorMessageSignature

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

the class CommunicatorRESTService method getUserMessageSignature.

@GET
@Path("/signatures/{SIGNATUREID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getUserMessageSignature(@PathParam("SIGNATUREID") Long signatureId) throws AuthorizationException {
    CommunicatorMessageSignature signature = communicatorController.getMessageSignature(signatureId);
    if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, signature)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CommunicatorMessageSignatureRESTModel result = new CommunicatorMessageSignatureRESTModel(signature.getId(), signature.getName(), signature.getSignature());
    return Response.ok(result).build();
}
Also used : CommunicatorMessageSignature(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageSignature) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 3 with CommunicatorMessageSignature

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

the class CommunicatorRESTService method createUserMessageSignature.

@POST
@Path("/signatures")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createUserMessageSignature(CommunicatorMessageSignatureRESTModel newSignature) throws AuthorizationException {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    CommunicatorMessageSignature messageSignature = communicatorController.createMessageSignature(newSignature.getName(), newSignature.getSignature(), userEntity);
    CommunicatorMessageSignatureRESTModel result = new CommunicatorMessageSignatureRESTModel(messageSignature.getId(), messageSignature.getName(), messageSignature.getSignature());
    return Response.ok(result).build();
}
Also used : CommunicatorMessageSignature(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageSignature) 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 CommunicatorMessageSignature

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

the class CommunicatorRESTService method listUserMessageSignatures.

@GET
@Path("/signatures")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserMessageSignatures() throws AuthorizationException {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    List<CommunicatorMessageSignature> signatures = communicatorController.listMessageSignatures(userEntity);
    List<CommunicatorMessageSignatureRESTModel> result = new ArrayList<CommunicatorMessageSignatureRESTModel>();
    for (CommunicatorMessageSignature signature : signatures) {
        result.add(new CommunicatorMessageSignatureRESTModel(signature.getId(), signature.getName(), signature.getSignature()));
    }
    return Response.ok(result).build();
}
Also used : CommunicatorMessageSignature(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageSignature) ArrayList(java.util.ArrayList) 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 CommunicatorMessageSignature

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

the class CommunicatorRESTService method editUserMessageSignature.

@PUT
@Path("/signatures/{SIGNATUREID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response editUserMessageSignature(@PathParam("SIGNATUREID") Long signatureId, CommunicatorMessageSignatureRESTModel signature) throws AuthorizationException {
    if (!signature.getId().equals(signatureId)) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Id is immutable").build();
    }
    CommunicatorMessageSignature messageSignature = communicatorController.getMessageSignature(signatureId);
    if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, messageSignature)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CommunicatorMessageSignature editMessageSignature = communicatorController.editMessageSignature(messageSignature, signature.getName(), signature.getSignature());
    CommunicatorMessageSignatureRESTModel result = new CommunicatorMessageSignatureRESTModel(editMessageSignature.getId(), editMessageSignature.getName(), editMessageSignature.getSignature());
    return Response.ok(result).build();
}
Also used : CommunicatorMessageSignature(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageSignature) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Aggregations

CommunicatorMessageSignature (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageSignature)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 ArrayList (java.util.ArrayList)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1