@ApiOperation( value = "Removing multiple Projects", notes = "In the Request Body pass a list of project ids that have to be deleted") @RequestMapping( value = "/multipledelete", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.NO_CONTENT) public void multipleDelete(@RequestBody @Valid List<String> ids) throws NotAllowedException, NotFoundException, EntityInUseException, BadRequestException { if (utils.isAdmin()) { for (String id : ids) { projectManagement.delete(projectManagement.query(id)); } } else { throw new NotAllowedException("Forbidden to delete projects " + ids); } }
if (projectIsNecessary(request) && !projectManagement.exist(projectId)) { throw new NotFoundException("Project with id '" + projectId + "' was not found"); String pjName = projectManagement.query(projectId).getName(); log.trace(role.getProject() + " == " + pjName); if (role.getProject().equals(pjName)) { Iterable<Project> userProjects = projectManagement.query(baseUser); if (userProjects.iterator().hasNext()) { return checkAuthorization(
/** * Returns the list of the Projects available * * @return List<Project>: The list of Projects available */ @ApiOperation(value = "Retrieve all Projects", notes = "Returns all the created projects") @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Set<Project> findAll() throws NotFoundException { log.trace("Finding all Projects"); Set<Project> projects = new HashSet<>(); if (utils.isAdmin()) { for (Project project : projectManagement.query()) { projects.add(project); } } else { for (Project project : projectManagement.query(utils.getCurrentUser())) { projects.add(project); } } return projects; }
/** * Updates the Project * * @param new_project : The Project to be updated * @return Project The Project updated */ @ApiOperation( value = "Update a Project", notes = "The Request Body holds the Project as JSON that will be updated.") @RequestMapping( value = "{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public Project update(@RequestBody @Valid Project new_project) throws NotFoundException, NotAllowedException { if (utils.isAdmin()) { return projectManagement.update(new_project); } else { throw new NotAllowedException("Forbidden to update project " + new_project.getName()); } } }
/** * Adds a new Project to the Projects repository * * @param project * @return project */ @ApiOperation( value = "Adding a Project", notes = "Project data has to be passed as JSON in the Request Body.") @RequestMapping( method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public Project create(@RequestBody @Valid Project project) throws NotAllowedException, NotFoundException { log.info("Adding Project: " + project.getName()); if (utils.isAdmin()) { return projectManagement.add(project); } else { throw new NotAllowedException("Forbidden to create project " + project.getName()); } }
Project project = projectManagement.queryByName(role.getProject()); if (project == null) { throw new BadRequestException("Not found project " + role.getProject());
/** * Returns the Project selected by id * * @param id : The id of the Project * @return Project: The Project selected */ @ApiOperation(value = "Retrieve a Project", notes = "Pass the id of the project in the URL") @RequestMapping(value = "{id}", method = RequestMethod.GET) public Project findById(@PathVariable("id") String id) throws NotFoundException, NotAllowedException { log.trace("Finding Project with id " + id); Project project = projectManagement.query(id); if (project == null) { throw new NotFoundException("Not found project " + id); } log.trace("Found Project: " + project); if (utils.isAdmin()) { return project; } else { for (Role role : utils.getCurrentUser().getRoles()) { if (role.getProject().equals(project.getName())) { return project; } } } throw new NotAllowedException("Forbidden to access project " + id); }
/** * Removes the Project from the Projects repository * * @param id : the id of project to be removed */ @ApiOperation( value = "Remove a Project", notes = "Specify the id of the project that will be deleted in the URL") @RequestMapping(value = "{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) public void delete(@PathVariable("id") String id) throws NotAllowedException, NotFoundException, EntityInUseException, BadRequestException { log.info("Removing Project with id " + id); if (utils.isAdmin()) { projectManagement.delete(projectManagement.query(id)); } else { throw new NotAllowedException("Forbidden to delete project " + id); } }