Java源码示例:com.google.api.server.spi.response.BadRequestException

示例1
@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;
}
 
示例2
/**
 * 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");
}
 
示例3
@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;
}
 
示例4
/**
 * 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;
}
 
示例5
@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;
}
 
示例6
@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);
    }
  }
}
 
示例7
@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;

}
 
示例8
/**
 * @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());
  }
}
 
示例9
@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;
    }
}
 
示例10
@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;
  }
}
 
示例11
@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);
}
 
示例12
@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;
}
 
示例13
/**
 * 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());
  }

}
 
示例14
/**
 * 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);
}
 
示例15
@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());
  }
}
 
示例16
/**
 * 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());
  }
}
 
示例17
/**
 * 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;
  }
}
 
示例18
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;
}
 
示例19
@Override
public List<Skill> getSkillsByTech(Technology technology) throws BadRequestException {
  if (technology == null) {
    throw new BadRequestException(ValidationMessageEnums.TECHNOLOGY_NOT_EXIST.message());
  }
  return skillDao.findByTechnology(technology);
}
 
示例20
/**
 * 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());
  }
}
 
示例21
/**
 * 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());
  }
}
 
示例22
/**
 * 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;
}
 
示例23
/**
 * 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());
  }
}
 
示例24
@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;
}
 
示例25
/**
 */
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());
    }
  }
}
 
示例26
@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);
  }
}
 
示例27
protected Object[] deserializeParams(JsonNode node) throws IOException, IllegalAccessException,
    InvocationTargetException, NoSuchMethodException, ServiceException {
  EndpointMethod method = getMethod();
  Class<?>[] paramClasses = method.getParameterClasses();
  TypeToken<?>[] paramTypes = method.getParameterTypes();
  Object[] params = new Object[paramClasses.length];
  List<String> parameterNames = getParameterNames(method);
  for (int i = 0; i < paramClasses.length; i++) {
    TypeToken<?> type = paramTypes[i];
    Class<?> clazz = paramClasses[i];
    if (User.class.isAssignableFrom(clazz)) {
      // User type parameter requires no Named annotation (ignored if present)
      User user = getUser();
      if (user == null && methodConfig != null
          && methodConfig.getAuthLevel() == AuthLevel.REQUIRED) {
        throw new UnauthorizedException("Valid user credentials are required.");
      }
      if (user == null || clazz.isAssignableFrom(user.getClass())) {
        params[i] = user;
        logger.atFine().log("deserialize: User injected into param[%d]", i);
      } else {
        logger.atWarning().log(
            "deserialize: User object of type %s is not assignable to %s. User will be null.",
            user.getClass().getName(), clazz.getName());
      }
    } else if (APPENGINE_USER_CLASS_NAME.equals(clazz.getName())) {
      // User type parameter requires no Named annotation (ignored if present)
      com.google.appengine.api.users.User appEngineUser = getAppEngineUser();
      if (appEngineUser == null && methodConfig != null
          && methodConfig.getAuthLevel() == AuthLevel.REQUIRED) {
        throw new UnauthorizedException("Valid user credentials are required.");
      }
      params[i] = appEngineUser;
      logger.atFine().log("deserialize: App Engine User injected into param[%d]", i);
    } else if (clazz == HttpServletRequest.class) {
      // HttpServletRequest type parameter requires no Named annotation (ignored if present)
      params[i] = endpointsContext.getRequest();
      logger.atFine().log("deserialize: HttpServletRequest injected into param[%d]", i);
    } else if (clazz == ServletContext.class) {
      // ServletContext type parameter requires no Named annotation (ignored if present)
      params[i] = servletContext;
      logger.atFine().log("deserialize: ServletContext %s injected into param[%d]",
          params[i], i);
    } else {
      String name = parameterNames.get(i);
      if (Strings.isNullOrEmpty(name)) {
        params[i] = (node == null) ? null : objectReader.forType(clazz).readValue(node);
        logger.atFine().log("deserialize: %s %s injected into unnamed param[%d]",
            clazz, params[i], i);
      } else if (StandardParameters.isStandardParamName(name)) {
        params[i] = getStandardParamValue(node, name);
      } else {
        JsonNode nodeValue = node.get(name);
        if (nodeValue == null) {
          params[i] = null;
        } else {
          // Check for collection type
          if (Collection.class.isAssignableFrom(clazz)
              && type.getType() instanceof ParameterizedType) {
            params[i] =
                deserializeCollection(clazz, (ParameterizedType) type.getType(), nodeValue);
          } else {
            params[i] = objectReader.forType(clazz).readValue(nodeValue);
          }
        }
        if (params[i] == null && isRequiredParameter(method, i)) {
          throw new BadRequestException("null value for parameter '" + name + "' not allowed");
        }
        logger.atFine().log("deserialize: %s %s injected into param[%d] named {%s}",
            clazz, params[i], i, name);
      }
    }
  }
  return params;
}
 
示例28
@ApiMethod(name = "getRecommendationsUp", path = "technology-recommendations-up", httpMethod = "get")
public List<Response> getTechRecommendationsUp(@Named("id") String technologyId, User user)
    throws InternalServerErrorException, BadRequestException, NotFoundException, OAuthRequestException {
  return service.getRecommendationsUpByTechnologyAndUser(technologyId, user);
}
 
示例29
/**
 * POST for adding a endorsement. TODO: Refactor - Extract Method
 *
 * @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.
 * @throws OAuthRequestException in case of authentication problem
 */
@Override
public Endorsement addOrUpdateEndorsement(EndorsementResponse endorsement, User user)
    throws InternalServerErrorException, BadRequestException, NotFoundException,
    OAuthRequestException {
  // endorser user google id
  String googleId;
  // endorser user from techgallery datastore
  TechGalleryUser tgEndorserUser;
  // endorsed user from techgallery datastore
  TechGalleryUser tgEndorsedUser;
  // endorsed email
  String endorsedEmail;
  // technology from techgallery datastore
  Technology technology;

  // User from endpoint (endorser) 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 NotFoundException(i18n.t("Current user was not found!"));
  } else {
    // get the TechGalleryUser from datastore
    tgEndorserUser = userDao.findByGoogleId(googleId);
    if (tgEndorserUser == null) {
      throw new BadRequestException(i18n.t("Endorser user do not exists on datastore!"));
    }
    tgEndorserUser.setGoogleId(googleId);
  }

  // endorsed email can't be null.
  endorsedEmail = endorsement.getEndorsed();
  if (endorsedEmail == null || endorsedEmail.equals("")) {
    throw new BadRequestException(i18n.t("Endorsed email was not especified!"));
  } else {
    // get user from PEOPLE
    tgEndorsedUser = userService.getUserSyncedWithProvider(endorsedEmail);
    if (tgEndorsedUser == null) {
      throw new BadRequestException(i18n.t("Endorsed email was not found on PEOPLE!"));
    }
  }

  // technology id can't be null and must exists on datastore
  final String technologyId = endorsement.getTechnology();
  if (technologyId == null || technologyId.equals("")) {
    throw new BadRequestException(i18n.t("Technology was not especified!"));
  } else {
    technology = techDao.findById(technologyId);
    if (technology == null) {
      throw new BadRequestException(i18n.t("Technology do not exists!"));
    }
  }

  // final checks and persist
  // user cannot endorse itself
  if (tgEndorserUser.getId().equals(tgEndorsedUser.getId())) {
    throw new BadRequestException(i18n.t("You cannot endorse yourself!"));
  }
  // user cannot endorse the same people twice
  if (endorsementDao.findActivesByUsers(tgEndorserUser, tgEndorsedUser, technology).size() > 0) {
    throw new BadRequestException(i18n.t("You already endorsed this user for this technology"));
  }
  // create endorsement and save it
  final Endorsement entity = new Endorsement();
  entity.setEndorser(Ref.create(tgEndorserUser));
  entity.setEndorsed(Ref.create(tgEndorsedUser));
  entity.setTimestamp(new Date());
  entity.setTechnology(Ref.create(technology));
  entity.setActive(true);
  endorsementDao.add(entity);
  userProfileService.handleEndorsement(entity);
  return getEndorsement(entity.getId());
}
 
示例30
@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);
}