Search in sources :

Example 1 with NotFoundException

use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.

the class ProjectController method giveBadge.

// TODO: Replace explicit user{id} with AuthN user id.
@CrossOrigin
@RequestMapping(value = "/{id}/users/{userId}/badge", method = RequestMethod.POST)
@ApiOperation(value = "Give out badge for a volunteer")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of project or user invalid") })
public Badge giveBadge(@ApiParam(value = "ID of user", required = true) @PathVariable("userId") Integer userId, @ApiParam(value = "ID of project", required = true) @PathVariable("id") Integer projectId) {
    System.out.println("************** ProjectController.giveBadge()" + ": userId=" + userId + "; projectId=" + projectId + " **************");
    Badge badge = null;
    try {
        badge = badgeService.saveBadge(userId, projectId);
    } catch (NullPointerException e) {
        throw new NotFoundException("ID of project or user invalid");
    } catch (Exception e) {
        throw e;
    }
    return badge;
}
Also used : NotFoundException(org.c4sg.exception.NotFoundException) Badge(org.c4sg.entity.Badge) NotFoundException(org.c4sg.exception.NotFoundException) UserProjectException(org.c4sg.exception.UserProjectException) ProjectServiceException(org.c4sg.exception.ProjectServiceException) BadRequestException(org.c4sg.exception.BadRequestException)

Example 2 with NotFoundException

use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.

the class OrganizationController method getOrganizationsByUser.

@CrossOrigin
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
@ApiOperation(value = "Find organizations by user id", notes = "Returns a collection of organizations")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of user invalid") })
public List<OrganizationDTO> getOrganizationsByUser(@ApiParam(value = "userId of organizations to return", required = true) @PathVariable("id") Integer id) {
    System.out.println("************** OrganizationController.getOrganizationsByUser()" + ": id=" + id + " **************");
    List<OrganizationDTO> organizations = null;
    try {
        organizations = organizationService.findByUser(id);
    } catch (Exception e) {
        throw new NotFoundException("ID of user invalid");
    }
    return organizations;
}
Also used : NotFoundException(org.c4sg.exception.NotFoundException) CreateOrganizationDTO(org.c4sg.dto.CreateOrganizationDTO) OrganizationDTO(org.c4sg.dto.OrganizationDTO) NotFoundException(org.c4sg.exception.NotFoundException) UserOrganizationException(org.c4sg.exception.UserOrganizationException) BadRequestException(org.c4sg.exception.BadRequestException) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with NotFoundException

use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.

the class ProjectController method createUserProject.

@CrossOrigin
@RequestMapping(value = "/{id}/users/{userId}", method = RequestMethod.POST)
@ApiOperation(value = "Create a relation between user and project")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of project or user invalid") })
public //TODO: Replace explicit user{id} with AuthN user id.
ResponseEntity<?> createUserProject(@ApiParam(value = "ID of user", required = true) @PathVariable("userId") Integer userId, @ApiParam(value = "ID of project", required = true) @PathVariable("id") Integer projectId, @ApiParam(value = "User project status, A-Applied, B-Bookmarked", allowableValues = "A, B", required = true) @RequestParam("userProjectStatus") String userProjectStatus) {
    try {
        projectService.saveUserProject(userId, projectId, userProjectStatus);
        URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}/users/{userId}").buildAndExpand(projectId, userId, userProjectStatus).toUri();
        return ResponseEntity.created(location).build();
    } catch (NullPointerException e) {
        throw new NotFoundException("ID of project or user invalid");
    } catch (UserProjectException | BadRequestException e) {
        throw e;
    }
}
Also used : NotFoundException(org.c4sg.exception.NotFoundException) BadRequestException(org.c4sg.exception.BadRequestException) URI(java.net.URI) UserProjectException(org.c4sg.exception.UserProjectException)

Example 4 with NotFoundException

use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.

the class UserController method createUser.

@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "Add a new user")
public UserDTO createUser(@ApiParam(value = "User object to return", required = true) @RequestBody CreateUserDTO createUserDTO) {
    //calculate lat and long
    try {
        UserDTO userDTO = userService.createUser(createUserDTO);
        GeoCodeUtil geoCodeUtil = new GeoCodeUtil(userDTO);
        Map<String, BigDecimal> geoCode = geoCodeUtil.getGeoCode();
        userDTO.setLatitude(geoCode.get("lat"));
        userDTO.setLongitude(geoCode.get("lon"));
        return userService.saveUser(userDTO);
    } catch (Exception e) {
        throw new NotFoundException("Error getting geocode");
    }
}
Also used : GeoCodeUtil(org.c4sg.util.GeoCodeUtil) CreateUserDTO(org.c4sg.dto.CreateUserDTO) UserDTO(org.c4sg.dto.UserDTO) NotFoundException(org.c4sg.exception.NotFoundException) BigDecimal(java.math.BigDecimal) NotFoundException(org.c4sg.exception.NotFoundException) IOException(java.io.IOException)

Example 5 with NotFoundException

use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.

the class UserServiceImpl method saveUser.

@Override
public UserDTO saveUser(UserDTO userDTO) {
    User user = userMapper.getUserEntityFromDto(userDTO);
    try {
        Map<String, BigDecimal> geoCode = geocodeService.getGeoCode(user.getState(), user.getCountry());
        user.setLatitude(geoCode.get("lat"));
        user.setLongitude(geoCode.get("lng"));
    } catch (Exception e) {
        throw new NotFoundException("Error getting geocode");
    }
    return userMapper.getUserDtoFromEntity(userDAO.save(user));
}
Also used : User(org.c4sg.entity.User) NotFoundException(org.c4sg.exception.NotFoundException) BigDecimal(java.math.BigDecimal) NotFoundException(org.c4sg.exception.NotFoundException) UserServiceException(org.c4sg.exception.UserServiceException)

Aggregations

NotFoundException (org.c4sg.exception.NotFoundException)6 BadRequestException (org.c4sg.exception.BadRequestException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)2 UserOrganizationException (org.c4sg.exception.UserOrganizationException)2 UserProjectException (org.c4sg.exception.UserProjectException)2 CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 IOException (java.io.IOException)1 CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)1 CreateUserDTO (org.c4sg.dto.CreateUserDTO)1 OrganizationDTO (org.c4sg.dto.OrganizationDTO)1 UserDTO (org.c4sg.dto.UserDTO)1 Badge (org.c4sg.entity.Badge)1 User (org.c4sg.entity.User)1 ProjectServiceException (org.c4sg.exception.ProjectServiceException)1 UserServiceException (org.c4sg.exception.UserServiceException)1 GeoCodeUtil (org.c4sg.util.GeoCodeUtil)1