Class PrivateRestService
Object
PrivateRestService
@DeclareRoles("player")
@RolesAllowed("player")
@Path("/private")
public class PrivateRestService
extends Object
Contains all rest calls that are available to a specific character, with
authentication and authorization. You can find them at
/karchangame/resources/private.
- Author:
- maartenl
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates that only 20 mails may be retrieved per time (basically a page).static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionResponsecreateMailItem(String name, long id, int itemDefinitionId) Creates an itemDefinitionId instance (and, if required, an itemDefinitionId definition) representing an in-game version of a single mail based by id.protected ResponseResponseDeletes a character, permanently.ResponsedeleteFamilyvalues(String name, String toname) Deletes some family values from your family tree.ResponsedeleteMail(String name, long id) Deletes a single mail based by id.ResponsedeletePerson(HttpServletRequest requestContext, String name) Deletes an entire character.getCharacterSheet(String name) Gets your current character info.protected EntityManagerReturns the entity manager of JPA.getMailInfo(String name, long id) Returns a single mail based by id.hasNewMail(String name) Returns a boolean, indicating if you have new mail.Returns a List of your mail, with a maximum of 20 mails and an offset for paging.listSentMail(String name, Integer offset) Returns a List of mails you sent, with a maximum of 20 mails and an offset for paging.voidnewMail(PrivateMail newMail, String name) ResponsenewMailRest(String json, String name) Send a new mail.ResponseresetPassword(String name, String json) Resets your current passwordvoidsetLogService(LogService logService) voidsetPlayerAuthenticationService(PlayerAuthenticationService playerAuthenticationService) ResponseupdateCharacterSheet(String name, PrivatePerson cinfo) Adds or updates your current character info.ResponseupdateFamilyvalues(String name, String toname, Integer description) Add or updates some family values from your family tree.
-
Field Details
-
PASSWORDS_DO_NOT_MATCH
- See Also:
-
MAX_MAILS
public static final int MAX_MAILSIndicates that only 20 mails may be retrieved per time (basically a page).- See Also:
-
-
Constructor Details
-
PrivateRestService
public PrivateRestService()
-
-
Method Details
-
getPrivateService
-
getEntityManager
protected EntityManager getEntityManager()Returns the entity manager of JPA. This is defined in build/web/WEB-INF/classes/META-INF/persistence.xml.- Returns:
- EntityManager
-
getPublicService
-
listMail
@GET @Path("{name}/mail") @Produces("application/json") public List<PrivateMail> listMail(@PathParam("name") String name, @QueryParam("offset") Integer offset) Returns a List of your mail, with a maximum of 20 mails and an offset for paging.- Parameters:
name- the name of the useroffset- the offset, default is 0 if not provided.- Returns:
- a List of (max 20 by default) mails.
- Throws:
WebApplicationException-- UNAUTHORIZED, if the authorisation failed.
- BAD_REQUEST if an unexpected exception crops up.
- See Also:
-
listSentMail
@GET @Path("{name}/sentmail") @Produces("application/json") public List<PrivateMail> listSentMail(@PathParam("name") String name, @QueryParam("offset") Integer offset) Returns a List of mails you sent, with a maximum of 20 mails and an offset for paging.- Parameters:
name- the name of the useroffset- the offset, default is 0 if not provided.- Returns:
- a List of (max 20 by default) mails.
- Throws:
WebApplicationException-- UNAUTHORIZED, if the authorisation failed.
- BAD_REQUEST if an unexpected exception crops up.
- See Also:
-
hasNewMail
@GET @Path("{name}/newmail") @Consumes("application/json") public String hasNewMail(@PathParam("name") String name) Returns a boolean, indicating if you have new mail. (i.e. mail since you last checked)- Parameters:
name- the name of the user- Returns:
- Response.ok if everything is okay.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
newMailRest
@POST @Path("{name}/mail") @Consumes("application/json") public Response newMailRest(String json, @PathParam("name") String name) Send a new mail.- Parameters:
json- json representation of a new mail object received from the client. Sending to user "deputies" allows for a mail to be sent to all current active deputies.name- the name of the person logged in/sending mail- Returns:
- Response.ok if everything's okay.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
newMail
-
getMailInfo
@GET @Path("{name}/mail/{id}") @Produces("application/json") public PrivateMail getMailInfo(@PathParam("name") String name, @PathParam("id") long id) Returns a single mail based by id. Can only retrieve mail destined for the user requesting the mail.- Parameters:
name- the name of the userid- the id of the mail to get- Returns:
- A specific mail.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
createMailItem
@GET @Path("{name}/mail/{id}/createMailItem/{item}") @Consumes("application/json") public Response createMailItem(@PathParam("name") String name, @PathParam("id") long id, @PathParam("item") int itemDefinitionId) Creates an itemDefinitionId instance (and, if required, an itemDefinitionId definition) representing an in-game version of a single mail based by id.- Parameters:
name- the name of the userid- the id of the mail to getitemDefinitionId- the kind of itemDefinitionId that is to be made. It may be null, if there already is attached a item definition to the mail.- Returns:
- Response.ok if everything is fine.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.- See Also:
-
createResponse
protected Response createResponse() -
deleteMail
@DELETE @Path("{name}/mail/{id}") @Consumes("application/json") public Response deleteMail(@PathParam("name") String name, @PathParam("id") long id) Deletes a single mail based by id.- Parameters:
name- the name of the userid- the id of the mail to delete- Returns:
- Response.ok() if all is well.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
deletePerson
@DELETE @Path("{name}") @Consumes("application/json") public Response deletePerson(@Context HttpServletRequest requestContext, @PathParam("name") String name) Deletes an entire character.- Parameters:
requestContext- the context to log the player off who just deleted his entire character.name- the name of the user- Returns:
- Response.ok() if all is well.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
updateCharacterSheet
@PUT @Path("{name}/charactersheet") @Consumes("application/json") public Response updateCharacterSheet(@PathParam("name") String name, PrivatePerson cinfo) Adds or updates your current character info.- Parameters:
name- the name of the usercinfo- the object containing the new stuff to update.- Returns:
- Response.ok if everything is okay.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
resetPassword
@PUT @Path("{name}/resetPassword") @Consumes("application/json") public Response resetPassword(@PathParam("name") String name, String json) Resets your current password- Parameters:
name- the name of the userjson- the object containing the new stuff to update.- Returns:
- Response.ok if everything is okay.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
delete
@DELETE @Path("{name}") @Produces("application/json") public Response delete(@PathParam("name") String name) Deletes a character, permanently. Use with extreme caution.- Parameters:
name- the name of the user- Returns:
- Response.ok
- Throws:
WebApplicationException- BAD_REQUEST if an unexpected exception crops up.
-
getCharacterSheet
@GET @Path("{name}/charactersheet") @Produces("application/json") public PrivatePerson getCharacterSheet(@PathParam("name") String name) Gets your current character info.- Parameters:
name- the name of the user- Returns:
- Response.ok if everything is okay.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
updateFamilyvalues
@PUT @Path("{name}/charactersheet/familyvalues/{toname}/{description}") @Consumes("application/json") public Response updateFamilyvalues(@PathParam("name") String name, @PathParam("toname") String toname, @PathParam("description") Integer description) Add or updates some family values from your family tree.- Parameters:
name- the name of the usertoname- the name of the user you are related todescription- the description of the family relation, for example "mother".- Returns:
- Response.ok if everything's okay.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
deleteFamilyvalues
@DELETE @Path("{name}/charactersheet/familyvalues/{toname}") @Consumes("application/json") public Response deleteFamilyvalues(@PathParam("name") String name, @PathParam("toname") String toname) Deletes some family values from your family tree.- Parameters:
name- the name of the usertoname- the name of the user you are related to- Returns:
- Response.ok if everything is okay.
- Throws:
WebApplicationException- UNAUTHORIZED, if the authorisation failed. BAD_REQUEST if an unexpected exception crops up.
-
setLogService
-
setPlayerAuthenticationService
-