@Test public void testSendEmailServiceActive() { when(mock.isActive()).thenReturn(true); Response result = resource.postEmail(Application.Name.valueOf("a1"), Username.valueOf("u1"), EmailLinksList.newInstance().build()); assertThat(result.getEntity(), is("An email has been sent to the administrators of a1 to ask for access for user u1 with links ")); assertThat(result.getStatus(), is(HttpStatus.OK_200)); }
@POST @Path("/applications/{applicationName}/users/{user}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Sends email to administrators of the specified application requesting access for a user", httpMethod = "POST", produces = "application/json", protocols = "https") @Timed public Response postEmail( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("user") @ApiParam(value = "Requesting user ID") final UserInfo.Username user, @ApiParam(name = "clickableAccessEmailLinks", value = "Clickable Access Email Links") final EmailLinksList emails) { try { String message; if (emailService.isActive()) { emailService.sendEmailForUserPermission(applicationName, user, emails); message = "An email has been sent to the administrators of " + applicationName + " to ask for access for user " + user + " with links " + emails.toString(); return httpHeader.headers().entity(message).build(); } else { LOGGER.warn("User tried to send an email via API-call, but the service is not active."); message = "The email service is not activated at the moment."; } return httpHeader.headers(SERVICE_UNAVAILABLE).entity(message).build(); } catch (Exception exception) { LOGGER.error("postEmail failed for applicationName={}, user={}, emails={} with error:", applicationName, user, emails, exception); throw exception; } }
EmailResource { @POST @Path("/applications/{applicationName}/users/{user}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Sends email to administrators of the specified application requesting access for a user", httpMethod = "POST", produces = "application/json", protocols = "https") @Timed public Response postEmail( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("user") @ApiParam(value = "Requesting user ID") final UserInfo.Username user, @ApiParam(name = "clickableAccessEmailLinks", value = "Clickable Access Email Links") final EmailLinksList emails) { try { String message; if (emailService.isActive()) { emailService.sendEmailForUserPermission(applicationName, user, emails); message = "An email has been sent to the administrators of " + applicationName + " to ask for access for user " + user + " with links " + emails.toString(); return httpHeader.headers().entity(message).build(); } else { LOGGER.warn("User tried to send an email via API-call, but the service is not active."); message = "The email service is not activated at the moment."; } return httpHeader.headers(SERVICE_UNAVAILABLE).entity(message).build(); } catch (Exception exception) { LOGGER.error("postEmail failed for applicationName={}, user={}, emails={} with error:", applicationName, user, emails, exception); throw exception; } } }
EmailResource { @POST @Path("/applications/{applicationName}/users/{user}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Sends email to administrators of the specified application requesting access for a user", httpMethod = "POST", produces = "application/json", protocols = "https") @Timed public Response postEmail( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("user") @ApiParam(value = "Requesting user ID") final UserInfo.Username user, @ApiParam(name = "clickableAccessEmailLinks", value = "Clickable Access Email Links") final EmailLinksList emails) { try { String message; if (emailService.isActive()) { emailService.sendEmailForUserPermission(applicationName, user, emails); message = "An email has been sent to the administrators of " + applicationName + " to ask for access for user " + user + " with links " + emails.toString(); return httpHeader.headers().entity(message).build(); } else { LOGGER.warn("User tried to send an email via API-call, but the service is not active."); message = "The email service is not activated at the moment."; } return httpHeader.headers(SERVICE_UNAVAILABLE).entity(message).build(); } catch (Exception exception) { LOGGER.error("postEmail failed for applicationName={}, user={}, emails={} with error:", applicationName, user, emails, exception); throw exception; } } @Inject  EmailResource(final EmailService emailService, final HttpHeader httpHeader); }
EmailResource { @POST @Path("/applications/{applicationName}/users/{user}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Sends email to administrators of the specified application requesting access for a user", httpMethod = "POST", produces = "application/json", protocols = "https") @Timed public Response postEmail( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("user") @ApiParam(value = "Requesting user ID") final UserInfo.Username user, @ApiParam(name = "clickableAccessEmailLinks", value = "Clickable Access Email Links") final EmailLinksList emails) { try { String message; if (emailService.isActive()) { emailService.sendEmailForUserPermission(applicationName, user, emails); message = "An email has been sent to the administrators of " + applicationName + " to ask for access for user " + user + " with links " + emails.toString(); return httpHeader.headers().entity(message).build(); } else { LOGGER.warn("User tried to send an email via API-call, but the service is not active."); message = "The email service is not activated at the moment."; } return httpHeader.headers(SERVICE_UNAVAILABLE).entity(message).build(); } catch (Exception exception) { LOGGER.error("postEmail failed for applicationName={}, user={}, emails={} with error:", applicationName, user, emails, exception); throw exception; } } @Inject  EmailResource(final EmailService emailService, final HttpHeader httpHeader); @POST @Path("/applications/{applicationName}/users/{user}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Sends email to administrators of the specified application requesting access for a user", httpMethod = "POST", produces = "application/json", protocols = "https") @Timed Response postEmail(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @PathParam("user")
            @ApiParam(value = "Requesting user ID")
            final UserInfo.Username user,

            @ApiParam(name = "clickableAccessEmailLinks", value = "Clickable Access Email Links")
            final EmailLinksList emails); }
EmailResource { @POST @Path("/applications/{applicationName}/users/{user}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Sends email to administrators of the specified application requesting access for a user", httpMethod = "POST", produces = "application/json", protocols = "https") @Timed public Response postEmail( @PathParam("applicationName") @ApiParam(value = "Application Name") final Application.Name applicationName, @PathParam("user") @ApiParam(value = "Requesting user ID") final UserInfo.Username user, @ApiParam(name = "clickableAccessEmailLinks", value = "Clickable Access Email Links") final EmailLinksList emails) { try { String message; if (emailService.isActive()) { emailService.sendEmailForUserPermission(applicationName, user, emails); message = "An email has been sent to the administrators of " + applicationName + " to ask for access for user " + user + " with links " + emails.toString(); return httpHeader.headers().entity(message).build(); } else { LOGGER.warn("User tried to send an email via API-call, but the service is not active."); message = "The email service is not activated at the moment."; } return httpHeader.headers(SERVICE_UNAVAILABLE).entity(message).build(); } catch (Exception exception) { LOGGER.error("postEmail failed for applicationName={}, user={}, emails={} with error:", applicationName, user, emails, exception); throw exception; } } @Inject  EmailResource(final EmailService emailService, final HttpHeader httpHeader); @POST @Path("/applications/{applicationName}/users/{user}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Sends email to administrators of the specified application requesting access for a user", httpMethod = "POST", produces = "application/json", protocols = "https") @Timed Response postEmail(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @PathParam("user")
            @ApiParam(value = "Requesting user ID")
            final UserInfo.Username user,

            @ApiParam(name = "clickableAccessEmailLinks", value = "Clickable Access Email Links")
            final EmailLinksList emails);  }