com.google.api.server.spi.response.BadRequestException Java Examples

The following examples show how to use com.google.api.server.spi.response.BadRequestException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TechnologyLinkServiceImpl.java    From tech-gallery with Apache License 2.0 6 votes vote down vote up
@Override
public TechnologyLink addLink(TechnologyLink link, User user)
    throws InternalServerErrorException, BadRequestException, NotFoundException {
  log.info("Starting creating Technology Link.");

  final Technology technology = link.getTechnology().get();

  validateUser(user);
  validateLink(link);
  validateTechnology(technology);

  final TechGalleryUser techUser = userService.getUserByGoogleId(user.getUserId());
  final TechnologyLink newLink = addNewLink(link, techUser, technology);

  // TODO: Adicionar contador de links na tecnologia
  // techService.addLinksCounter(technology);
  techService.audit(technology.getId(), user);

  followTechnology(technology, techUser);

  return newLink;
}
 
Example #2
Source File: WaxEndpoint.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new session from {@link WaxNewSessionRequest}.
 *
 * @return {@link WaxNewSessionResponse} with the created session id
 * @throws InternalServerErrorException if the session creation failed
 * @throws BadRequestException if the requested session name is bad
 */
@ApiMethod(
    name = "sessions.create",
    path = "newsession",
    httpMethod = HttpMethod.POST)
public WaxNewSessionResponse createSession(WaxNewSessionRequest request)
    throws InternalServerErrorException, BadRequestException {
  if (Strings.isNullOrEmpty(request.getSessionName())) {
    throw new BadRequestException("Name must be non-empty");
  }
  String sessionId =
      store.createSession(request.getSessionName(), request.getDurationInMillis());
  if (sessionId != null) {
    return new WaxNewSessionResponse(sessionId);
  }
  throw new InternalServerErrorException("Error while adding session");
}
 
Example #3
Source File: UserServiceTGImpl.java    From tech-gallery with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if user exists on provider, syncs with tech gallery's datastore. If
 * user exists, adds to TG's datastore (if not there). Returns the user.
 *
 * @param userLogin
 *          userLogin
 * @return the user saved on the datastore
 * @throws InternalServerErrorException
 *           in case something goes wrong
 * @throws NotFoundException
 *           in case the information are not founded
 * @throws BadRequestException
 *           in case a request with problem were made.
 * @return user sinchronized in provider.
 */
@Override
public TechGalleryUser getUserSyncedWithProvider(final String userLogin)
    throws NotFoundException, InternalServerErrorException, BadRequestException {
  TechGalleryUser tgUser = null;
  TechGalleryUser userResp = getUserFromProvider(userLogin);
  tgUser = userDao.findByEmail(getUserFromProvider(userLogin).getEmail());
  if (tgUser == null) {
    tgUser = new TechGalleryUser();
    tgUser.setEmail(userResp.getEmail());
    tgUser.setName(userResp.getName());
    tgUser = addUser(tgUser);
    // Key<TechGalleryUser> key = userDao.add(tgUser);
    // tgUser.setId(key.getId());
  }
  return tgUser;
}
 
Example #4
Source File: TechnologyLinkServiceImpl.java    From tech-gallery with Apache License 2.0 6 votes vote down vote up
@Override
public Response getLinksByTech(String techId, User user) throws InternalServerErrorException,
    BadRequestException, NotFoundException, OAuthRequestException {

  final Technology technology = techService.getTechnologyById(techId, user);

  validateUser(user);
  validateTechnology(technology);

  final List<TechnologyLink> linksByTech =
      technologyLinkDao.findAllByTechnology(technology);
  final TechnologyLinksTO response = new TechnologyLinksTO();
  response.setLinks(linksByTech);

  return response;
}
 
Example #5
Source File: ProjectServiceImpl.java    From tech-gallery with Apache License 2.0 6 votes vote down vote up
@Override
public Project addOrUpdateProject(Project project, User user)
        throws InternalServerErrorException, BadRequestException, NotFoundException {

    log.info("Starting creating or updating project");

    validateInputs(project, user);

    final Project newProject;

    if (projectDao.findById(project.getId()) != null) {
        projectDao.update(project);
        newProject = project;
    } else {
        newProject = addNewProject(project);
    }

    return newProject;
}
 
Example #6
Source File: TechnologyFollowersServiceImpl.java    From tech-gallery with Apache License 2.0 6 votes vote down vote up
@Override
public void update(TechnologyFollowers technologyFollowers) throws BadRequestException {
  if (technologyFollowers != null) {
    if (technologyFollowers.getTechnology() == null) {
      throw new BadRequestException(ValidationMessageEnums.TECHNOLOGY_ID_CANNOT_BLANK.message());
    }
    if (technologyFollowers.getFollowers() == null
        || technologyFollowers.getFollowers().isEmpty()) {
      throw new BadRequestException(ValidationMessageEnums.FOLLOWERS_CANNOT_EMPTY.message());
    }
    if (technologyFollowers.getId() != null
        && followersDao.findById(technologyFollowers.getId()) != null) {
      followersDao.update(technologyFollowers);
    } else {
      followersDao.add(technologyFollowers);
    }
  }
}
 
Example #7
Source File: TechnologyRecommendationServiceImpl.java    From tech-gallery with Apache License 2.0 6 votes vote down vote up
@Override
public List<Response> getRecommendations(String technologyId, User user)
    throws BadRequestException, InternalServerErrorException {
  Technology technology;
  try {
    technology = technologyService.getTechnologyById(technologyId, user);
  } catch (final NotFoundException e) {
    return null;
  }
  final List<TechnologyRecommendation> recommendations =
      technologyRecommendationDAO.findAllActivesByTechnology(technology);
  final List<Response> recommendationTOs = new ArrayList<Response>();
  for (final TechnologyRecommendation recommendation : recommendations) {
    recommendationTOs.add(techRecTransformer.transformTo(recommendation));
  }
  return recommendationTOs;

}
 
Example #8
Source File: TechnologyFollowersServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
@Override
public TechnologyFollowers getTechnologyFollowersByTechnology(final Technology technology)
    throws BadRequestException {
  if (technology == null) {
    throw new BadRequestException(ValidationMessageEnums.NO_TECHNOLOGY_WAS_FOUND.message());
  } else {
    return followersDao.findByTechnology(technology);
  }
}
 
Example #9
Source File: TechnologyLinkServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * @throws NotFoundException in case the information are not founded
 * @throws BadRequestException in case a request with problem were made.
 */
private void validateLink(Long linkId) throws BadRequestException, NotFoundException {

  log.info("Validating the link");

  if (linkId == null) {
    throw new BadRequestException(ValidationMessageEnums.LINK_ID_CANNOT_BLANK.message());
  }

  final TechnologyLink link = technologyLinkDao.findById(linkId);
  if (link == null) {
    throw new NotFoundException(ValidationMessageEnums.LINK_NOT_EXIST.message());
  }
}
 
Example #10
Source File: UserEndpoint.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
@ApiMethod(name = "saveUserPreference", path = "users/savePreference", httpMethod = "post")
public TechGalleryUser saveUserPreference(
        @Named("postGooglePlusPreference") Boolean postGooglePlusPreference, User user)
        throws NotFoundException, BadRequestException, InternalServerErrorException, IOException,
        OAuthRequestException {
    return service.saveUserPreference(postGooglePlusPreference, user);
}
 
Example #11
Source File: SkillServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
@Override
public Skill getUserSkill(String techId, User user) throws BadRequestException,
    OAuthRequestException, NotFoundException, InternalServerErrorException {
  // user google id
  String googleId;
  // user from techgallery datastore
  TechGalleryUser tgUser;
  // User from endpoint can't be null
  if (user == null) {
    throw new OAuthRequestException(i18n.t("OAuth error, null user reference!"));
  } else {
    googleId = user.getUserId();
  }

  // TechGalleryUser can't be null and must exists on datastore
  if (googleId == null || googleId.equals("")) {
    throw new BadRequestException(i18n.t("Current user was not found!"));
  } else {
    // get the TechGalleryUser from datastore or PEOPLE API
    tgUser = userService.getUserByGoogleId(googleId);
    if (tgUser == null) {
      throw new BadRequestException(i18n.t("Endorser user do not exists on datastore!"));
    }
  }

  // Technology can't be null
  final Technology technology = techService.getTechnologyById(techId, user);
  if (technology == null) {
    throw new BadRequestException(i18n.t("Technology do not exists!"));
  }
  final Skill userSkill = skillDao.findByUserAndTechnology(tgUser, technology);
  if (userSkill == null) {
    throw new NotFoundException(i18n.t("User skill do not exist!"));
  } else {
    return userSkill;
  }
}
 
Example #12
Source File: TechnologyServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
@Override
public Technology deleteTechnology(String technologyId, User user)
        throws InternalServerErrorException, BadRequestException, NotFoundException, OAuthRequestException {
    validateUser(user);
    Technology technology = technologyDAO.findById(technologyId);
    if (technology == null) {
        throw new NotFoundException(ValidationMessageEnums.NO_TECHNOLOGY_WAS_FOUND.message());
    }
    technology.setActive(Boolean.FALSE);
    technology.setLastActivity(new Date());
    technology.setLastActivityUser(user.getEmail());
    technologyDAO.update(technology);
    return technology;
}
 
Example #13
Source File: SkillServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * Validate inputs of SkillResponse.
 *
 * @param skill inputs to be validate
 * @param user info about user from google
 *
 * @throws BadRequestException for the validations.
 * @throws InternalServerErrorException in case something goes wrong
 * @throws NotFoundException in case the information are not founded
 */
private void validateInputs(Skill skill, User user)
    throws BadRequestException, NotFoundException, InternalServerErrorException {

  log.info("Validating inputs of skill");

  if (user == null || user.getUserId() == null || user.getUserId().isEmpty()) {
    throw new BadRequestException(ValidationMessageEnums.USER_GOOGLE_ENDPOINT_NULL.message());
  }

  final TechGalleryUser techUser = userService.getUserByGoogleId(user.getUserId());
  if (techUser == null) {
    throw new BadRequestException(ValidationMessageEnums.USER_NOT_EXIST.message());
  }

  if (skill == null) {
    throw new BadRequestException(ValidationMessageEnums.SKILL_CANNOT_BLANK.message());
  }

  if (skill.getValue() == null || skill.getValue() < 0 || skill.getValue() > 5) {
    throw new BadRequestException(ValidationMessageEnums.SKILL_RANGE.message());
  }

  if (skill.getTechnology() == null) {
    throw new BadRequestException(ValidationMessageEnums.TECHNOLOGY_ID_CANNOT_BLANK.message());
  }

}
 
Example #14
Source File: TechnologyEndpoint.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * Endpoint for getting a list of Technologies.
 *
 * @return list of technologies
 * @throws InternalServerErrorException in case something goes wrong
 * @throws NotFoundException in case the information are not founded
 * @throws BadRequestException in case a request with problem were made.
 */
@ApiMethod(name = "getTechnologies", path = "technology", httpMethod = "get")
public Response getTechnologies(User user)
    throws InternalServerErrorException, NotFoundException, BadRequestException {
  if(user == null)
    log.info("User is null");
  else
    log.info("User is: " + user.getEmail());
  return service.getTechnologies(user);
}
 
Example #15
Source File: TechnologyRecommendationServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
@Override
public TechnologyRecommendation addRecommendation(TechnologyRecommendation recommendation,
    User user) throws BadRequestException {
  try {
    final TechGalleryUser tgUser = userService.getUserByEmail(user.getEmail());
    recommendation.setRecommender(Ref.create(tgUser));
    return addNewRecommendation(recommendation, tgUser);
  } catch (final NotFoundException e) {
    throw new BadRequestException(ValidationMessageEnums.USER_NOT_EXIST.message());
  }
}
 
Example #16
Source File: TechnologyRecommendationServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * Validation for User.
 *
 * @author <a href="mailto:[email protected]"> João Felipe de Medeiros Moreira </a>
 * @since 28/09/2015
 *
 * @param user to be validated
 * @param techUser to be validated
 *
 * @throws BadRequestException in case the params are not correct
 * @throws InternalServerErrorException in case of internal error
 */
private void validateUser(User user, TechGalleryUser techUser)
    throws BadRequestException, InternalServerErrorException {
  log.info("Validating user to recommend");

  if (user == null || user.getUserId() == null || user.getUserId().isEmpty()) {
    throw new BadRequestException(ValidationMessageEnums.USER_GOOGLE_ENDPOINT_NULL.message());
  }

  if (techUser == null) {
    throw new BadRequestException(ValidationMessageEnums.USER_NOT_EXIST.message());
  }
}
 
Example #17
Source File: UserServiceTGImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * Updates a user, with validation.
 *
 * @throws BadRequestException
 *           in case of a missing parameter
 * @return the updated user
 */
@Override
public TechGalleryUser updateUser(final TechGalleryUser user) throws BadRequestException {
  if (!userDataIsValid(user) && user.getId() != null) {
    throw new BadRequestException(i18n.t("User's email cannot be blank."));
  } else {
    userDao.update(user);
    return user;
  }
}
 
Example #18
Source File: TechnologyFollowersServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
private TechnologyFollowers unfollow(TechnologyFollowers technologyFollowers,
    TechGalleryUser techUser, Technology technology) throws BadRequestException {
  technologyFollowers.getFollowers().remove(Ref.create(techUser));
  techUser.getFollowedTechnologyIds().remove(technology.getId());
  if (technologyFollowers.getFollowers().isEmpty()) {
    followersDao.delete(technologyFollowers);
    return null;
  }
  return technologyFollowers;
}
 
Example #19
Source File: SkillServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
@Override
public List<Skill> getSkillsByTech(Technology technology) throws BadRequestException {
  if (technology == null) {
    throw new BadRequestException(ValidationMessageEnums.TECHNOLOGY_NOT_EXIST.message());
  }
  return skillDao.findByTechnology(technology);
}
 
Example #20
Source File: TechnologyCommentServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * Validate inputs of TechnologyCommentTO.
 *
 * @param comment inputs to be validate
 * @throws BadRequestException .
 */
private void validateComment(TechnologyComment comment) throws BadRequestException {

  log.info("Validating the comment");

  if (comment == null || comment.getComment() == null || comment.getComment().isEmpty()) {
    throw new BadRequestException(ValidationMessageEnums.COMMENT_CANNOT_BLANK.message());
  }

  if (comment.getComment().length() > 500) {
    throw new BadRequestException(ValidationMessageEnums.COMMENT_MUST_BE_LESSER.message());
  }
}
 
Example #21
Source File: TechnologyCommentServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * Validate comment of TechnologyCommentTO.
 *
 * @param comment id to be validate
 *
 * @throws NotFoundException in case the information are not founded
 * @throws BadRequestException in case a request with problem were made.
 */
private void validateComment(Long commentId) throws BadRequestException, NotFoundException {

  log.info("Validating the comment");

  if (commentId == null) {
    throw new BadRequestException(ValidationMessageEnums.COMMENT_ID_CANNOT_BLANK.message());
  }

  final TechnologyComment comment = technologyCommentDao.findById(commentId);
  if (comment == null) {
    throw new NotFoundException(ValidationMessageEnums.COMMENT_NOT_EXIST.message());
  }
}
 
Example #22
Source File: UserServiceTGImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * GET Calls the provider API passing a login to obtain user information.
 *
 * @param userLogin
 *          the user login to pass to the provider API
 * @throws NotFoundException
 *           in case the user is not found on provider
 * @throws BadRequestException
 *           in case of JSON or URL error
 * @throws InternalServerErrorException
 *           if any IO exceptions occur
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public TechGalleryUser getUserFromProvider(final String userLogin)
    throws NotFoundException, BadRequestException, InternalServerErrorException {

  TechGalleryUser tgUser = new TechGalleryUser();
  Map<String, Object> providerResponse = peopleApiConnect(userLogin, PEOPLE_ENDPOINT_PROFILE);
  HashMap<String, Object> userData = (LinkedHashMap) providerResponse.get("personal_info");
  tgUser.setEmail((String) userData.get("email"));
  tgUser.setName((String) userData.get("name"));
  return tgUser;
}
 
Example #23
Source File: TechnologyCommentServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 * Validate comment of TechnologyCommentTO.
 *
 * @param comment inputs to be validate
 * @throws BadRequestException in case a request with problem were made.
 * @throws InternalServerErrorException in case something goes wrong
 * @throws NotFoundException in case the information are not founded
 */
private void validateDeletion(Long commentId, User user)
    throws BadRequestException, NotFoundException, InternalServerErrorException {

  log.info("Validating the deletion");

  validateComment(commentId);
  validateUser(user);

  final TechnologyComment comment = technologyCommentDao.findById(commentId);
  final TechGalleryUser techUser = userService.getUserByGoogleId(user.getUserId());
  if (!comment.getAuthor().get().equals(techUser)) {
    throw new BadRequestException(ValidationMessageEnums.COMMENT_AUTHOR_ERROR.message());
  }
}
 
Example #24
Source File: UserProfileServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
@Override
public UserProfile addItem(Technology technology, User user)
    throws NotFoundException, BadRequestException, InternalServerErrorException {
  TechGalleryUser owner = UserServiceTGImpl.getInstance().getUserByEmail(user.getEmail());
  UserProfile profile = findUserProfileByOwner(owner);
  technology = TechnologyServiceImpl.getInstance().getTechnologyById(technology.getId(), user);
  UserProfileItem newItem = new UserProfileItem(technology);
  profile.addItem(UserProfile.POSITIVE_RECOMMENDATION, Key.create(technology), newItem);
  profile.addItem(UserProfile.NEGATIVE_RECOMMENDATION, Key.create(technology), newItem);
  profile.addItem(UserProfile.OTHER, Key.create(technology), newItem);
  UserProfileDaoImpl.getInstance().add(profile);
  return profile;
}
 
Example #25
Source File: TechnologyLinkServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
/**
 */
private void validateLink(TechnologyLink link) throws BadRequestException {

  log.info("Validating the link");

  if (link == null || link.getDescription() == null || link.getDescription().isEmpty()) {
    throw new BadRequestException(ValidationMessageEnums.DESCRIPTION_CANNOT_BLANK.message());
  }

  if (link == null || link.getLink() == null || link.getLink().isEmpty()) {
    throw new BadRequestException(ValidationMessageEnums.LINK_CANNOT_BLANK.message());
  }

  if (link.getDescription().length() > 100) {
    throw new BadRequestException(ValidationMessageEnums.DESCRIPTION_MUST_BE_LESSER.message());
  }

  if (link != null && link.getLink() != null && !link.getLink().isEmpty()) {
    Pattern p = Pattern
      .compile("(@)?(href=')?(HREF=')?(HREF=\")?(href=\")?(http://|https://)?[a-zA-Z_0-9\\-]+(\\.\\w[a-zA-Z_0-9\\-]+)+(/[#&\\n\\-=?\\+\\%/\\.\\w]+)?");

    Matcher m = p.matcher(link.getLink());

    if( !m.matches() ) {
      throw new BadRequestException(ValidationMessageEnums.LINK_MUST_BE_VALID.message());
    }
  }
}
 
Example #26
Source File: TechnologyServiceImpl.java    From tech-gallery with Apache License 2.0 5 votes vote down vote up
@Override
public Response findTechnologiesByFilter(TechnologyFilter techFilter, User user)
        throws InternalServerErrorException, NotFoundException, BadRequestException {

    validateUser(user);
    TechGalleryUser techUser = userService.getUserByEmail(user.getEmail());
    if (techFilter.getRecommendationIs() != null
            && techFilter.getRecommendationIs().equals(RecommendationEnums.UNINFORMED.message())) {
        techFilter.setRecommendationIs("");
    }
    List<Technology> completeList = technologyDAO.findAllActives();
    completeList = filterByLastActivityDate(techFilter, completeList);

    List<Technology> filteredList = new ArrayList<>();
    if (StringUtils.isBlank(techFilter.getTitleContains()) && techFilter.getRecommendationIs() == null) {
        filteredList.addAll(completeList);
    } else {
        verifyFilters(techFilter, completeList, filteredList, techUser.getProject());
    }

    if (filteredList.isEmpty()) {
        return new TechnologiesResponse();
    } else {
        if (techFilter.getOrderOptionIs() != null && !techFilter.getOrderOptionIs().isEmpty()) {
            if(techFilter.getOrderOptionIs().equals("Projeto")){
                filteredList = Technology.sortTechnologies(filteredList, techUser.getProject());
            } else {
                filteredList = Technology.sortTechnologies(filteredList,
                        TechnologyOrderOptionEnum.fromString(techFilter.getOrderOptionIs()));
            }
        } else {
            Technology.sortTechnologiesDefault(filteredList);
        }
        TechnologiesResponse response = new TechnologiesResponse();
        response.setTechnologies(filteredList);
        return response;
    }
}
 
Example #27
Source File: TechnologyRecommendationServiceImpl.java    From tech-gallery with Apache License 2.0 4 votes vote down vote up
@Override
public List<Response> getRecommendationsDownByTechnologyAndUser(String technologyId, User user)
    throws BadRequestException, InternalServerErrorException {
  return getRecommendationsByTechnologyUserAndScore(technologyId, user, false);
}
 
Example #28
Source File: TechnologyRecommendationEndpoint.java    From tech-gallery with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "getTechnologyRecommendations", path = "technology-recommendations", httpMethod = "get")
public List<Response> getTechRecommendations(@Named("id") String technologyId, User user)
    throws InternalServerErrorException, BadRequestException, NotFoundException, OAuthRequestException {
  return service.getRecommendations(technologyId, user);
}
 
Example #29
Source File: ProjectEndpoint.java    From tech-gallery with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "deleteProject", path = "project", httpMethod = "delete")
public void deleteProject(@Named("id") Long projId, User user)
        throws InternalServerErrorException, BadRequestException, NotFoundException, OAuthRequestException {
    service.deleteProject(projId, user);
}
 
Example #30
Source File: TechnologyRecommendationEndpoint.java    From tech-gallery with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "deleteRecommendById", path = "technology-delete-recommendation", httpMethod = "get")
public Response deleteTechRecommendById(@Named("recommendId") Long recommendId, User user)
    throws BadRequestException, NotFoundException, InternalServerErrorException {
  return service.deleteRecommendById(recommendId, user);
}