@Test public void testReadOnlySpace() throws Exception { assertEquals(0, this.spaceRepository.count()); final Tenant d_tenant = this.createDefaultTenant(); final Space d_space = this.createSpace(d_tenant, TEST_DEFAULT_SPACE, true); assertEquals(1, this.spaceRepository.count()); d_space.setReadOnly(true); MockHttpServletRequestBuilder post_builder = put("/spaces/" + d_space.getSpaceToken()) .content(JacksonUtil.asJsonString(d_space)) .contentType(MediaType.APPLICATION_JSON) .header(Constants.HTTP_TENANT_HEADER, d_tenant.getTenantToken()) .accept(MediaType.APPLICATION_JSON); mockMvc .perform(post_builder) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$.default", is(true))) .andExpect(jsonPath("$.spaceName", is(TEST_DEFAULT_SPACE))); d_space.setReadOnly(false); post_builder = put("/spaces/" + d_space.getSpaceToken()) .content(JacksonUtil.asJsonString(d_space)) .contentType(MediaType.APPLICATION_JSON) .header(Constants.HTTP_TENANT_HEADER, d_tenant.getTenantToken()) .accept(MediaType.APPLICATION_JSON); mockMvc.perform(post_builder).andExpect(status().isBadRequest()); }
@RequestMapping( value = "", method = RequestMethod.POST, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) public ResponseEntity<Space> createSpace( @RequestBody Space space, @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false) String tenant) { final StopWatch sw = new StopWatch( "Create space [" + (space == null ? null : space.getSpaceName()) + "] " + "for tenant token [" + tenant + "] ") .start(); try { if (space == null) { log.error("No space submitted"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (!space.hasNameAndDescription()) { log.error("Work spaces require a name and description"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (space.isReadOnly()) { log.error("Work spaces cannot be created with read-only set to true"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } Tenant t = null; try { t = this.tenantRepository.getTenant(tenant); } catch (EntityNotFoundException enfe) { log.error("Tenant [" + tenant + "] not found"); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } catch (Exception e) { log.error("Error retrieving tenant [" + tenant + "]: " + e); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } if (space.isDefault() && this.spaceRepository.findDefault(t.getTenantToken()) != null) { log.error( "A default space for the given tenant already exists, adjust the configuration" + " accordingly"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } space.setTenant(t); space.setSpaceToken(TokenUtil.generateToken()); this.spaceRepository.customSave(space); sw.stop(); return new ResponseEntity<Space>(space, HttpStatus.CREATED); } catch (Exception enfe) { sw.stop(enfe); return new ResponseEntity<Space>(HttpStatus.INTERNAL_SERVER_ERROR); } }
SpaceController { @RequestMapping( value = "", method = RequestMethod.POST, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) public ResponseEntity<Space> createSpace( @RequestBody Space space, @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false) String tenant) { final StopWatch sw = new StopWatch( "Create space [" + (space == null ? null : space.getSpaceName()) + "] " + "for tenant token [" + tenant + "] ") .start(); try { if (space == null) { log.error("No space submitted"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (!space.hasNameAndDescription()) { log.error("Work spaces require a name and description"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (space.isReadOnly()) { log.error("Work spaces cannot be created with read-only set to true"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } Tenant t = null; try { t = this.tenantRepository.getTenant(tenant); } catch (EntityNotFoundException enfe) { log.error("Tenant [" + tenant + "] not found"); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } catch (Exception e) { log.error("Error retrieving tenant [" + tenant + "]: " + e); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } if (space.isDefault() && this.spaceRepository.findDefault(t.getTenantToken()) != null) { log.error( "A default space for the given tenant already exists, adjust the configuration" + " accordingly"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } space.setTenant(t); space.setSpaceToken(TokenUtil.generateToken()); this.spaceRepository.customSave(space); sw.stop(); return new ResponseEntity<Space>(space, HttpStatus.CREATED); } catch (Exception enfe) { sw.stop(enfe); return new ResponseEntity<Space>(HttpStatus.INTERNAL_SERVER_ERROR); } } }
SpaceController { @RequestMapping( value = "", method = RequestMethod.POST, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) public ResponseEntity<Space> createSpace( @RequestBody Space space, @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false) String tenant) { final StopWatch sw = new StopWatch( "Create space [" + (space == null ? null : space.getSpaceName()) + "] " + "for tenant token [" + tenant + "] ") .start(); try { if (space == null) { log.error("No space submitted"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (!space.hasNameAndDescription()) { log.error("Work spaces require a name and description"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (space.isReadOnly()) { log.error("Work spaces cannot be created with read-only set to true"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } Tenant t = null; try { t = this.tenantRepository.getTenant(tenant); } catch (EntityNotFoundException enfe) { log.error("Tenant [" + tenant + "] not found"); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } catch (Exception e) { log.error("Error retrieving tenant [" + tenant + "]: " + e); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } if (space.isDefault() && this.spaceRepository.findDefault(t.getTenantToken()) != null) { log.error( "A default space for the given tenant already exists, adjust the configuration" + " accordingly"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } space.setTenant(t); space.setSpaceToken(TokenUtil.generateToken()); this.spaceRepository.customSave(space); sw.stop(); return new ResponseEntity<Space>(space, HttpStatus.CREATED); } catch (Exception enfe) { sw.stop(enfe); return new ResponseEntity<Space>(HttpStatus.INTERNAL_SERVER_ERROR); } } @Autowired  SpaceController(
      TenantRepository tenantRepository,
      SpaceRepository spaceRepository,
      ApplicationRepository appRepository,
      ApplicationExporter appExporter,
      Filter cacheFilter); }
SpaceController { @RequestMapping( value = "", method = RequestMethod.POST, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) public ResponseEntity<Space> createSpace( @RequestBody Space space, @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false) String tenant) { final StopWatch sw = new StopWatch( "Create space [" + (space == null ? null : space.getSpaceName()) + "] " + "for tenant token [" + tenant + "] ") .start(); try { if (space == null) { log.error("No space submitted"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (!space.hasNameAndDescription()) { log.error("Work spaces require a name and description"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (space.isReadOnly()) { log.error("Work spaces cannot be created with read-only set to true"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } Tenant t = null; try { t = this.tenantRepository.getTenant(tenant); } catch (EntityNotFoundException enfe) { log.error("Tenant [" + tenant + "] not found"); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } catch (Exception e) { log.error("Error retrieving tenant [" + tenant + "]: " + e); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } if (space.isDefault() && this.spaceRepository.findDefault(t.getTenantToken()) != null) { log.error( "A default space for the given tenant already exists, adjust the configuration" + " accordingly"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } space.setTenant(t); space.setSpaceToken(TokenUtil.generateToken()); this.spaceRepository.customSave(space); sw.stop(); return new ResponseEntity<Space>(space, HttpStatus.CREATED); } catch (Exception enfe) { sw.stop(enfe); return new ResponseEntity<Space>(HttpStatus.INTERNAL_SERVER_ERROR); } } @Autowired  SpaceController(
      TenantRepository tenantRepository,
      SpaceRepository spaceRepository,
      ApplicationRepository appRepository,
      ApplicationExporter appExporter,
      Filter cacheFilter); @RequestMapping( value = "", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) ResponseEntity<Collection<Space>> getAllSpaces(
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping( value = "default", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) ResponseEntity<Space> getDefaultSpace(
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping( value = "search", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) ResponseEntity<List<Space>> searchSpaces(
      @RequestParam(value = "propertyName", required = true) String propertyName,
      @RequestParam(value = "mode", required = false, defaultValue = "EQUALS") ComparisonMode mode,
      @RequestParam(value = "caseSensitivity", required = false, defaultValue = "CASE_SENSITIVE")
          CaseSensitivity caseSensitivity,
      @RequestParam(value = "value", required = true) String[] value,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}", method = RequestMethod.OPTIONS) ResponseEntity<Space> isSpaceExisting(
      @PathVariable String token,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}", method = RequestMethod.GET) ResponseEntity<Space> getSpace(
      @PathVariable String token,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping( value = "", method = RequestMethod.POST, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) ResponseEntity<Space> createSpace(
      @RequestBody Space space,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping( value = "/{token:.+}", method = RequestMethod.PUT, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) ResponseEntity<Space> modifySpace(
      @PathVariable String token,
      @RequestBody Space new_space,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}", method = RequestMethod.POST) ResponseEntity<Space> cleanSpace(
      @PathVariable String token,
      @RequestParam(value = "clean", required = true) Boolean clean,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}", method = RequestMethod.DELETE) ResponseEntity<Space> deleteSpace(
      @PathVariable String token,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}/apps", method = RequestMethod.GET) void getApplications(
      @PathVariable String token,
      @RequestParam(value = "includeSpaceProperties", required = false, defaultValue = "")
          final String[] includeSpaceProperties,
      @RequestParam(value = "includeGoalConfiguration", required = false, defaultValue = "")
          final String[] includeGoalConfiguration,
      @RequestParam(value = "includeGoalSystemInfo", required = false, defaultValue = "")
          final String[] includeGoalSystemInfo,
      @RequestParam(value = "includeBugs", required = false, defaultValue = "false")
          final String includeBugs,
      @RequestParam(value = "includeExemptions", required = false, defaultValue = "false")
          final String includeExemptions,
      @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false) final String tenant,
      HttpServletRequest request,
      HttpServletResponse response); }
SpaceController { @RequestMapping( value = "", method = RequestMethod.POST, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) public ResponseEntity<Space> createSpace( @RequestBody Space space, @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false) String tenant) { final StopWatch sw = new StopWatch( "Create space [" + (space == null ? null : space.getSpaceName()) + "] " + "for tenant token [" + tenant + "] ") .start(); try { if (space == null) { log.error("No space submitted"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (!space.hasNameAndDescription()) { log.error("Work spaces require a name and description"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } else if (space.isReadOnly()) { log.error("Work spaces cannot be created with read-only set to true"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } Tenant t = null; try { t = this.tenantRepository.getTenant(tenant); } catch (EntityNotFoundException enfe) { log.error("Tenant [" + tenant + "] not found"); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } catch (Exception e) { log.error("Error retrieving tenant [" + tenant + "]: " + e); return new ResponseEntity<Space>(HttpStatus.NOT_FOUND); } if (space.isDefault() && this.spaceRepository.findDefault(t.getTenantToken()) != null) { log.error( "A default space for the given tenant already exists, adjust the configuration" + " accordingly"); return new ResponseEntity<Space>(HttpStatus.BAD_REQUEST); } space.setTenant(t); space.setSpaceToken(TokenUtil.generateToken()); this.spaceRepository.customSave(space); sw.stop(); return new ResponseEntity<Space>(space, HttpStatus.CREATED); } catch (Exception enfe) { sw.stop(enfe); return new ResponseEntity<Space>(HttpStatus.INTERNAL_SERVER_ERROR); } } @Autowired  SpaceController(
      TenantRepository tenantRepository,
      SpaceRepository spaceRepository,
      ApplicationRepository appRepository,
      ApplicationExporter appExporter,
      Filter cacheFilter); @RequestMapping( value = "", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) ResponseEntity<Collection<Space>> getAllSpaces(
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping( value = "default", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) ResponseEntity<Space> getDefaultSpace(
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping( value = "search", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) ResponseEntity<List<Space>> searchSpaces(
      @RequestParam(value = "propertyName", required = true) String propertyName,
      @RequestParam(value = "mode", required = false, defaultValue = "EQUALS") ComparisonMode mode,
      @RequestParam(value = "caseSensitivity", required = false, defaultValue = "CASE_SENSITIVE")
          CaseSensitivity caseSensitivity,
      @RequestParam(value = "value", required = true) String[] value,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}", method = RequestMethod.OPTIONS) ResponseEntity<Space> isSpaceExisting(
      @PathVariable String token,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}", method = RequestMethod.GET) ResponseEntity<Space> getSpace(
      @PathVariable String token,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping( value = "", method = RequestMethod.POST, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) ResponseEntity<Space> createSpace(
      @RequestBody Space space,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping( value = "/{token:.+}", method = RequestMethod.PUT, consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"}) ResponseEntity<Space> modifySpace(
      @PathVariable String token,
      @RequestBody Space new_space,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}", method = RequestMethod.POST) ResponseEntity<Space> cleanSpace(
      @PathVariable String token,
      @RequestParam(value = "clean", required = true) Boolean clean,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}", method = RequestMethod.DELETE) ResponseEntity<Space> deleteSpace(
      @PathVariable String token,
      @ApiIgnore @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false)
          String tenant); @RequestMapping(value = "/{token:.+}/apps", method = RequestMethod.GET) void getApplications(
      @PathVariable String token,
      @RequestParam(value = "includeSpaceProperties", required = false, defaultValue = "")
          final String[] includeSpaceProperties,
      @RequestParam(value = "includeGoalConfiguration", required = false, defaultValue = "")
          final String[] includeGoalConfiguration,
      @RequestParam(value = "includeGoalSystemInfo", required = false, defaultValue = "")
          final String[] includeGoalSystemInfo,
      @RequestParam(value = "includeBugs", required = false, defaultValue = "false")
          final String includeBugs,
      @RequestParam(value = "includeExemptions", required = false, defaultValue = "false")
          final String includeExemptions,
      @RequestHeader(value = Constants.HTTP_TENANT_HEADER, required = false) final String tenant,
      HttpServletRequest request,
      HttpServletResponse response);  }