OrganizationJoinRequestServiceImpl extends BaseServiceImpl<OrganizationJoinRequest> implements OrganizationJoinRequestService { @Override public OrganizationJoinRequest create(Organization organization, Persona persona) { if (null == organization) { throw new IllegalArgumentException("Invalid organization (null)"); } if (null == persona) { throw new IllegalArgumentException("Invalid persona (null)"); } if (organization.getVisibility().equals(Visibility.PRIVATE)) { throw new IllegalArgumentException("This organization is private, users cannot apply to join."); } BoundStatement createStatement = stmtCreate.get(); OrganizationJoinRequest joinRequest = new OrganizationJoinRequest( organization, persona, JoinRequestStatus.PENDING ); Resource resource = resourceService.create(joinRequest.getId(), organization); resourceService.addRoleToPersona(resource, organization, superUser); bindBasicParameters(joinRequest, createStatement); createStatement.setUUID("organization", joinRequest.getOrganization().getIdAsUUID()); createStatement.setUUID("persona", joinRequest.getPersona().getIdAsUUID()); createStatement.setString("status", joinRequest.getStatus().name()); session.execute(createStatement); logger.joinRequestCreated( joinRequest.getPersona().getId(), joinRequest.getOrganization().getId(), joinRequest.getId() ); return joinRequest; }  @Override OrganizationJoinRequest getById(UUID uuid); @Override OrganizationJoinRequest create(Organization organization, Persona persona); @Override OrganizationJoinRequest accept(OrganizationJoinRequest request, Role role); @Override OrganizationJoinRequest reject(OrganizationJoinRequest request); @Override void remove(OrganizationJoinRequest request); @Override List<OrganizationJoinRequest> getPendingRequestsForOrganization(Organization organization); @Override List<OrganizationJoinRequest> getAllRequestsForOrganization(Organization organization); @Override List<OrganizationJoinRequest> getAllRequestsForPersona(Persona persona);  }
@Test(expected = IllegalArgumentException.class) public void createJoinRequestOnPrivateOrganization() { HawkularUser jdoe = userService.getOrCreateById(UUID.randomUUID().toString()); HawkularUser jsmith = userService.getOrCreateById(UUID.randomUUID().toString()); Organization acme = organizationService.createOrganization( UUID.randomUUID().toString(), "", Visibility.PRIVATE, jdoe ); joinRequestService.create(acme, jsmith); }
@Test public void createJoinRequestOnOrganization() { HawkularUser jdoe = userService.getOrCreateById(UUID.randomUUID().toString()); HawkularUser jsmith = userService.getOrCreateById(UUID.randomUUID().toString()); Organization acme = organizationService.createOrganization( UUID.randomUUID().toString(), "", Visibility.APPLY, jdoe ); joinRequestService.create(acme, jsmith); }