/** Test of createUser method, of class UserDao. */ @Ignore public void testCreateUser() { System.out.println("createUser"); User u = null; UserDao instance = new UserDaoImpl(); String expResult = ""; String result = instance.createUser(u); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
@POST public Response createUser( @QueryParam(ACCESS_TOKEN_QPARAM) final String accessToken, final com.campusconnect.neo4j.types.web.User userPayload) throws URISyntaxException { StringBuffer validateUserDataMessage = Validator.validateUserObject(userPayload); if (null != validateUserDataMessage) { throw new InvalidInputDataException(INVALId_ARGMENTS, validateUserDataMessage.toString()); } User user = mapUserWebToNeo4j(userPayload); if (user.getEmail() != null) { User existingUser = userDao.getUserByEmail(user.getEmail()); if (null != existingUser) { if (existingUser.getFbId() == null && user.getFbId() != null) { existingUser.setFbId(user.getFbId()); existingUser = userDao.updateUser(existingUser.getId(), existingUser); } if (existingUser.getGoogleId() == null && user.getGoogleId() != null) { existingUser.setGoogleId(user.getGoogleId()); existingUser = userDao.updateUser(existingUser.getId(), existingUser); } com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser); return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build(); } } if (user.getFbId() != null) { User existingUser = userDao.getUserByFbId(user.getFbId()); if (null != existingUser) { com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser); return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build(); } } if (user.getGoogleId() != null) { User existingUser = userDao.getUserByGoogleId(user.getGoogleId()); if (null != existingUser) { com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser); return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build(); } } addPropertiesForCreate(user); User createdUser = userDao.createUser(user, accessToken); com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(createdUser); return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build(); }
@Transactional public boolean createUser(final String username, final String password, final String email) { User user = new User(); user.setUsername(username); user.setHash(hashPassword(password)); user.setEmail(email); // todo - create user, remove empty strings check try { return userDao.createUser(user); } catch (Throwable t) { LOGGER.warn("Exception occurred while creating new user, error: " + t); return false; } }