Package com.groupon.odo.proxylib.models

Examples of com.groupon.odo.proxylib.models.Profile


            results = queryStatement.executeQuery();

            while (results.next()) {
                profileId = results.getInt(Constants.GENERIC_PROFILE_ID);

                Profile profile = ProfileService.getInstance().findProfile(profileId);
               
                returnProfiles.add(profile);
            }
        } catch (SQLException e) {
            throw e;
View Full Code Here


    @Before
    public void setup() throws Exception {
        try {
            resetDatabase();
            Profile profile = ProfileService.getInstance().add("Consumer API");
            int id = profile.getId();
            int pathId = PathOverrideService.getInstance().addPathnameToProfile(id, "Global", "/");
            PathOverrideService.getInstance().addPathToRequestResponseTable(id, "-1", pathId);

        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

    /**
     * This is the profiles page. this is the 'regular' page when the url is typed in
     */
    @RequestMapping(value = "/profiles", method = RequestMethod.GET)
    public String list(Model model) {
        Profile profiles = new Profile();
        model.addAttribute("addNewProfile", profiles);
        model.addAttribute("version", Constants.VERSION);
        logger.info("Loading initial page");

        return "profiles";
View Full Code Here

    @Before
    public void setup() throws Exception {
        try {
            resetDatabase();
            Profile profile = ProfileService.getInstance().add("Consumer API");
            int id = profile.getId();
            int pathId = PathOverrideService.getInstance().addPathnameToProfile(id, "Global", "/");
            PathOverrideService.getInstance().addPathToRequestResponseTable(id, "-1", pathId);
            client = new Client("Consumer API", false);
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

     * @param profileId
     * @return
     * @throws Exception
     */
    public Profile findProfile(int profileId) throws Exception {
        Profile profile = null;
        PreparedStatement statement = null;
        ResultSet results = null;

        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement(
View Full Code Here

     * @param result
     * @return
     * @throws Exception
     */
    private Profile getProfileFromResultSet(ResultSet result) throws Exception {
        Profile profile = new Profile();
        profile.setId(result.getInt(Constants.GENERIC_ID));
        Clob clobProfileName = result.getClob(Constants.PROFILE_PROFILE_NAME);
        String profileName = clobProfileName.getSubString(1, (int) clobProfileName.length());
        profile.setName(profileName);
        return profile;
    }
View Full Code Here

     * @param profileName
     * @return
     * @throws Exception
     */
    public Profile add(String profileName) throws Exception {
        Profile profile = new Profile();
        int id = -1;
        PreparedStatement statement = null;
        ResultSet results = null;

        try (Connection sqlConnection = sqlService.getConnection()) {
            Clob clobProfileName = sqlService.toClob(profileName, sqlConnection);

            statement = sqlConnection.prepareStatement(
                    "INSERT INTO " + Constants.DB_TABLE_PROFILE
                            + "(" + Constants.PROFILE_PROFILE_NAME + ") " +
                            " VALUES (?)", PreparedStatement.RETURN_GENERATED_KEYS
            );

            statement.setClob(1, clobProfileName);
            statement.executeUpdate();
            results = statement.getGeneratedKeys();
            if (results.next()) {
                id = results.getInt(1);
            } else {
                // something went wrong
                throw new Exception("Could not add client");
            }
            results.close();
            statement.close();

            statement = sqlConnection.prepareStatement("INSERT INTO " + Constants.DB_TABLE_CLIENT +
                    "(" + Constants.CLIENT_CLIENT_UUID + "," + Constants.CLIENT_IS_ACTIVE + ","
                    + Constants.CLIENT_PROFILE_ID + ") " +
                    " VALUES (?, ?, ?)");
            statement.setString(1, Constants.PROFILE_CLIENT_DEFAULT_ID);
            statement.setBoolean(2, false);
            statement.setInt(3, id);
            statement.executeUpdate();

            profile.setName(profileName);
            profile.setId(id);
        } catch (SQLException e) {
            throw e;
        } finally {
            try {
                if (results != null) results.close();
View Full Code Here

        Client client = null;
        ArrayList<Integer> pathsToCopy = new ArrayList<Integer>();
        String clientUUID = getUniqueClientUUID();

        // get profile for profileId
        Profile profile = ProfileService.getInstance().findProfile(profileId);
        PreparedStatement statement = null;
        ResultSet rs = null;

        try (Connection sqlConnection = sqlService.getConnection()) {
           
            // get the current count of clients
            statement = sqlConnection.prepareStatement("SELECT COUNT(" + Constants.GENERIC_ID + ") FROM " +
                                  Constants.DB_TABLE_CLIENT + " WHERE " + Constants.GENERIC_PROFILE_ID + "=?");
            statement.setInt(1, profileId);
            int clientCount = -1;
            rs = statement.executeQuery();
            if (rs.next()) {
              clientCount = rs.getInt(1);
            }
            statement.close();
            rs.close();

            // check count
            if (clientCount == -1) {
              throw new Exception("Error querying clients for profileId=" + profileId);
            }
            if (clientCount >= Constants.CLIENT_CLIENTS_PER_PROFILE_LIMIT) {
              throw new Exception("Profile(" + profileId + ") already contains 50 clients.  Please remove clients before adding new ones.");
            }
           
            statement = sqlConnection.prepareStatement(
                    "INSERT INTO " + Constants.DB_TABLE_CLIENT +
                            " (" + Constants.CLIENT_CLIENT_UUID + ", " +
                            Constants.CLIENT_IS_ACTIVE + ", " +
                            Constants.CLIENT_PROFILE_ID + ")" +
                            " VALUES (?, ?, ?)", Statement.RETURN_GENERATED_KEYS
            );
            statement.setString(1, clientUUID);
            statement.setBoolean(2, false);
            statement.setInt(3, profile.getId());
            statement.executeUpdate();
            rs = statement.getGeneratedKeys();
            int clientId = -1;
            if (rs.next()) {
                clientId = rs.getInt(1);
            } else {
                // something went wrong
                throw new Exception("Could not add client");
            }
            rs.close();
            statement.close();

            // adding entries into request response table for this new client for every path
            // basically a copy of what happens when a path gets created
            statement = sqlConnection.prepareStatement(
                    "SELECT * FROM " + Constants.DB_TABLE_REQUEST_RESPONSE +
                            " WHERE " + Constants.GENERIC_PROFILE_ID + " = ?" +
                            " AND " + Constants.GENERIC_CLIENT_UUID + " = ?"
            );
            statement.setInt(1, profile.getId());
            statement.setString(2, Constants.PROFILE_CLIENT_DEFAULT_ID);
            rs = statement.executeQuery();
            while (rs.next()) {
                // collect up the pathIds we need to copy
                pathsToCopy.add(rs.getInt(Constants.REQUEST_RESPONSE_PATH_ID));
            }
            client = new Client();
            client.setIsActive(false);
            client.setUUID(clientUUID);
            client.setId(clientId);
            client.setProfile(profile);
        } catch (SQLException e) {
            throw e;
        } finally {
            try {
                if (rs != null) rs.close();
            } catch (Exception e) {
            }
            try {
                if (statement != null) statement.close();
            } catch (Exception e) {
            }
        }

        // add all of the request response items
        for (Integer pathId : pathsToCopy) {
            PathOverrideService.getInstance().addPathToRequestResponseTable(profile.getId(), client.getUUID(), pathId);
        }

        return client;
    }
View Full Code Here

TOP

Related Classes of com.groupon.odo.proxylib.models.Profile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.