Adds a path to the request response table with the specified values

@param profileId ID of profile
@param clientUUID UUID of client
@param pathId ID of path
@throws Exception exception
510592
public void addPathToRequestResponseTable(int profileId, String clientUUID, int pathId) throws Exception {
        PreparedStatement statement = null;
        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection
                .prepareStatement("INSERT INTO " + Constants.DB_TABLE_REQUEST_RESPONSE +
                                      "(" + Constants.REQUEST_RESPONSE_PATH_ID + ","
                                      + Constants.GENERIC_PROFILE_ID + ","
                                      + Constants.GENERIC_CLIENT_UUID + ","
                                      + Constants.REQUEST_RESPONSE_REPEAT_NUMBER + ","
                                      + Constants.REQUEST_RESPONSE_RESPONSE_ENABLED + ","
                                      + Constants.REQUEST_RESPONSE_REQUEST_ENABLED + ","
                                      + Constants.REQUEST_RESPONSE_CUSTOM_RESPONSE + ","
                                      + Constants.REQUEST_RESPONSE_CUSTOM_REQUEST + ")"
                                      + " VALUES (?, ?, ?, ?, ?, ?, ?, ?);");
            statement.setInt(1, pathId);
            statement.setInt(2, profileId);
            statement.setString(3, clientUUID);
            statement.setInt(4, -1);
            statement.setInt(5, 0);
            statement.setInt(6, 0);
            statement.setString(7, "");
            statement.setString(8, "");
            statement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
    }
598857
@RequestMapping(value = "api/edit/disable", method = RequestMethod.POST)
    public
    @ResponseBody
    String disableResponses(Model model, int path_id, @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception {
        OverrideService.getInstance().disableAllOverrides(path_id, clientUUID);
        //TODO also need to disable custom override if there is one of those
        editService.removeCustomOverride(path_id, clientUUID);

        return null;
    }
1319039
public void cullHistory(final int profileId, final String clientUUID, final int limit) throws Exception {

        //Allow only 1 delete thread to run
        if (threadActive) {
            return;
        }

        threadActive = true;
        //Create a thread so proxy will continue to work during long delete
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                PreparedStatement statement = null;

                try (Connection sqlConnection = sqlService.getConnection()) {
                    String sqlQuery = "SELECT COUNT(" + Constants.GENERIC_ID + ") FROM " + Constants.DB_TABLE_HISTORY + " ";

                    // see if profileId is set or not (-1)
                    if (profileId != -1) {
                        sqlQuery += "WHERE " + Constants.GENERIC_PROFILE_ID + "=" + profileId + " ";
                    }

                    if (clientUUID != null && clientUUID.compareTo("") != 0) {
                        sqlQuery += "AND " + Constants.GENERIC_CLIENT_UUID + "='" + clientUUID + "' ";
                    }
                    sqlQuery += ";";

                    Statement query = sqlConnection.createStatement();
                    ResultSet results = query.executeQuery(sqlQuery);
                    if (results.next()) {
                        if (results.getInt("COUNT(" + Constants.GENERIC_ID + ")") < (limit + 10000)) {
                            return;
                        }
                    }
                    //Find the last item in the table
                    statement = sqlConnection.prepareStatement("SELECT " + Constants.GENERIC_ID + " FROM " + Constants.DB_TABLE_HISTORY +
                                                                   " WHERE " + Constants.CLIENT_CLIENT_UUID + " = \'" + clientUUID + "\'" +
                                                                   " AND " + Constants.CLIENT_PROFILE_ID + " = " + profileId +
                                                                   " ORDER BY " + Constants.GENERIC_ID + " ASC LIMIT 1");

                    ResultSet resultSet = statement.executeQuery();
                    if (resultSet.next()) {
                        int currentSpot = resultSet.getInt(Constants.GENERIC_ID) + 100;
                        int finalDelete = currentSpot + 10000;
                        //Delete 100 items at a time until 10000 are deleted
                        //Do this so table is unlocked frequently to allow other proxy items to access it
                        while (currentSpot < finalDelete) {
                            PreparedStatement deleteStatement = sqlConnection.prepareStatement("DELETE FROM " + Constants.DB_TABLE_HISTORY +
                                                                                                   " WHERE " + Constants.CLIENT_CLIENT_UUID + " = \'" + clientUUID + "\'" +
                                                                                                   " AND " + Constants.CLIENT_PROFILE_ID + " = " + profileId +
                                                                                                   " AND " + Constants.GENERIC_ID + " < " + currentSpot);
                            deleteStatement.executeUpdate();
                            currentSpot += 100;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        threadActive = false;
                        if (statement != null) {
                            statement.close();
                        }
                    } catch (Exception e) {
                    }
                }
            }
        });

        t1.start();
    }
1026749
public static Error get(final BandwidthClient client, final String id) throws Exception {
        final String errorsUri = client.getUserResourceInstanceUri(BandwidthConstants.ERRORS_URI_PATH, id);

        final JSONObject jsonObject = toJSONObject(client.get(errorsUri, null));
        return new Error(client, errorsUri, jsonObject);
    }
1369461
@Override
  public void doProfileUpdateAnswerEvent(ClientShSession session, ProfileUpdateRequest request, ProfileUpdateAnswer answer)
      throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
    // TODO Auto-generated method stub
  }
49032
public String getGroupIdsInPathProfile(int profileId, int pathId) {
        return (String) sqlService.getFromTable(Constants.PATH_PROFILE_GROUP_IDS, Constants.GENERIC_ID, pathId,
                                                Constants.DB_TABLE_PATH);
    }
612581
public void setClientID(String clientID) {
        if (clientID == null || clientID.isEmpty()) {
            this.clientID = DEFAULT_CLIENT_ID;
            return;
        }
        this.clientID = clientID;
    }
5872
@RequestMapping(value = "api/edit/activate", method = RequestMethod.POST)
    public
    @ResponseBody
    String activateProfile(Model model,
                           @RequestParam int profileId,
                           @RequestParam(defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception {
        clientService.updateActive(profileId, clientUUID, true);
        return null;
    }
821746
@Override
	public int countByUuid(String uuid) {
		FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;

		Object[] finderArgs = new Object[] { uuid };

		Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_COMMERCENOTIFICATIONATTACHMENT_WHERE);

			boolean bindUuid = false;

			if (uuid == null) {
				query.append(_FINDER_COLUMN_UUID_UUID_1);
			}
			else if (uuid.equals("")) {
				query.append(_FINDER_COLUMN_UUID_UUID_3);
			}
			else {
				bindUuid = true;

				query.append(_FINDER_COLUMN_UUID_UUID_2);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (bindUuid) {
					qPos.add(uuid);
				}

				count = (Long)q.uniqueResult();

				finderCache.putResult(finderPath, finderArgs, count);
			}
			catch (Exception e) {
				finderCache.removeResult(finderPath, finderArgs);

				throw processException(e);
			}
			finally {
				closeSession(session);
			}
		}

		return count.intValue();
	}
893488
public void updateClientId(String clientId) {
        if (configForVM != null) {
            configForVM.withClientId(clientId);
        } else {
            configForAppService.withClientId(clientId);
        }
    }
559599
public void setResponseEnabled(int pathId, boolean enabled, String clientUUID) throws Exception {
        PreparedStatement statement = null;
        int profileId = EditService.getProfileIdFromPathID(pathId);
        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement(
                "UPDATE " + Constants.DB_TABLE_REQUEST_RESPONSE +
                    " SET " + Constants.DB_TABLE_PATH_RESPONSE_ENABLED + "= ?" +
                    " WHERE " + Constants.GENERIC_PROFILE_ID + "= ?" +
                    " AND " + Constants.GENERIC_CLIENT_UUID + "= ?" +
                    " AND " + Constants.REQUEST_RESPONSE_PATH_ID + "= ?"
            );
            statement.setBoolean(1, enabled);
            statement.setInt(2, profileId);
            statement.setString(3, clientUUID);
            statement.setInt(4, pathId);
            statement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
    }
604637
public String getCustomData(int pathId, String clientUUID, String type) throws Exception {
        PreparedStatement statement = null;
        ResultSet results = null;
        String data = "";

        try (Connection sqlConnection = sqlService.getConnection()) {
            String queryString = "SELECT " + type + " FROM " + Constants.DB_TABLE_REQUEST_RESPONSE +
                " WHERE " + Constants.REQUEST_RESPONSE_PATH_ID + " = ? " +
                " AND " + Constants.GENERIC_CLIENT_UUID + " = ?";
            statement = sqlConnection.prepareStatement(queryString);
            statement.setInt(1, pathId);
            statement.setString(2, clientUUID);

            results = statement.executeQuery();
            if (results.next()) {
                data = results.getString(type);
            }
            results.close();
            statement.close();
        } catch (Exception e) {

        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        return data;
    }
1224911
public static String getClientIdFromAuthenticatedProfile(final CommonProfile profile) {
        if (profile.containsAttribute(OAuth20Constants.CLIENT_ID)) {
            val attribute = profile.getAttribute(OAuth20Constants.CLIENT_ID);
            return CollectionUtils.toCollection(attribute, ArrayList.class).get(0).toString();
        }
        return null;
    }
418254
public String getUserResourceInstanceUri(final String path, final String instanceId){
        if(StringUtils.isEmpty(path) || StringUtils.isEmpty(instanceId)) {
            throw new IllegalArgumentException("Path and Instance Id cannot be null");
        }
        return getUserResourceUri(path) + "/" + instanceId;
    }
241312
public void setPath(int pathId, String path) {
        PreparedStatement statement = null;
        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement(
                "UPDATE " + Constants.DB_TABLE_PATH +
                    " SET " + Constants.PATH_PROFILE_ACTUAL_PATH + " = ? " +
                    " WHERE " + Constants.GENERIC_ID + " = ?"
            );
            statement.setString(1, path);
            statement.setInt(2, pathId);
            statement.executeUpdate();
            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
    }
863421
public int addServerGroup(String groupName, int profileId) throws Exception {
        int groupId = -1;
        PreparedStatement statement = null;
        ResultSet results = null;

        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement("INSERT INTO " + Constants.DB_TABLE_SERVER_GROUPS
                                                           + "(" + Constants.GENERIC_NAME + "," +
                                                           Constants.GENERIC_PROFILE_ID + ")"
                                                           + " VALUES (?, ?);", PreparedStatement.RETURN_GENERATED_KEYS);
            statement.setString(1, groupName);
            statement.setInt(2, profileId);
            statement.executeUpdate();

            results = statement.getGeneratedKeys();

            if (results.next()) {
                groupId = results.getInt(1);
            } else {
                // something went wrong
                throw new Exception("Could not add group");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        return groupId;
    }
1043280
@RequestMapping(value = "/api/profile/{profileIdentifier}/clients/delete", method = RequestMethod.POST)
    public
    @ResponseBody
    HashMap<String, Object> deleteClient(Model model,
                                         @RequestParam("profileIdentifier") String profileIdentifier,
                                         @RequestParam("clientUUID") String[] clientUUID) throws Exception {

        logger.info("Attempting to remove clients from the profile: ", profileIdentifier);
        logger.info("Attempting to remove the following clients: {}", Arrays.toString(clientUUID));

        HashMap<String, Object> valueHash = new HashMap<String, Object>();
        Integer profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);

        for( int i = 0; i < clientUUID.length; i++ )
        {
            if (clientUUID[i].compareTo(Constants.PROFILE_CLIENT_DEFAULT_ID) == 0)
                throw new Exception("Default client cannot be deleted");

            clientService.remove(profileId, clientUUID[i]);
        }

        valueHash.put("clients", clientService.findAllClients(profileId));
        return valueHash;
    }