BicepBuddyApp/src/main/java/User/UserController.java
@SuppressWarnings("unchecked")
	public void updateMatchedArrayState(User u) {
		JSONObject updateArrays = new JSONObject();
		
		// Create the Arrays
		JSONArray acceptedMatches = new JSONArray();
		JSONArray rejectedMatches = new JSONArray();
		JSONArray idleMatches = new JSONArray();
		JSONArray waitingMatches = new JSONArray();
		
		// Load the accept array
		List<Match> acceptM = u.getAccepted();
		for(int i = 0; i < acceptM.size(); i++) {
			String matchId = acceptM.get(i).getId();
			
			acceptedMatches.add(matchId);
		}
		
		// Load the reject array
		List<Match> rejectM = u.getRejected();
		for(int i = 0; i < rejectM.size(); i++) {
			String matchId = rejectM.get(i).getId();
			
			rejectedMatches.add(matchId);
		}
		
		// Load the idle array
		List<Match> idleM = u.getIdle();
		for(int i = 0; i < idleM.size(); i++) {
			String matchId = idleM.get(i).getId();
			
			idleMatches.add(matchId);
		}
		
		// Load the idle array
		List<Match> waitM = u.getWaiting();
		for(int i = 0; i < waitM.size(); i++) {
			String matchId = waitM.get(i).getId();
			
			waitingMatches.add(matchId);
		}
		
		// Add the Arrays to the JSON Object
		updateArrays.put("acceptedMatches", acceptedMatches);
		updateArrays.put("rejectedMatches", rejectedMatches);
		updateArrays.put("idleMatches", idleMatches);
		updateArrays.put("waitingMatches", waitingMatches);
		
		// Now that the JSON is done we want to open a Patch request to update the user
		
		// Open the Connection
		HttpPatch request = new HttpPatch(baseUrl + u.getId());
		
		try {
			// Set headers
			request.addHeader("content-type", "application/json");
			
			// Attach Body
			StringEntity params = new StringEntity(updateArrays.toJSONString());
			request.setEntity(params);
			
			// Execute the request
			HttpResponse response = httpClient.execute(request);
			
			// Get the Respose Back
			if(response.getStatusLine().getStatusCode() == 200) {
				// Success!
				System.out.println("User Arrays Updated!");
			} else {
				System.err.println("Failed to Update a User Arrays! Maybe invalid id?");
			}
			
			
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			request.releaseConnection();
		}
		
		
	}
/**
	 * Update matched array state to the database.
	 *
	 * @param u the u
	 */
Update matched array state to the database.
@param u the u
Update matched array state to the database . @param u the u
@SuppressWarnings("unchecked")
	public void updateMatchedArrayState(User u) {
		JSONObject updateArrays = new JSONObject();
		JSONArray acceptedMatches = new JSONArray();
		JSONArray rejectedMatches = new JSONArray();
		JSONArray idleMatches = new JSONArray();
		JSONArray waitingMatches = new JSONArray();
		List<Match> acceptM = u.getAccepted();
		for(int i = 0; i < acceptM.size(); i++) {
			String matchId = acceptM.get(i).getId();
			acceptedMatches.add(matchId);
		}
		List<Match> rejectM = u.getRejected();
		for(int i = 0; i < rejectM.size(); i++) {
			String matchId = rejectM.get(i).getId();
			rejectedMatches.add(matchId);
		}
		List<Match> idleM = u.getIdle();
		for(int i = 0; i < idleM.size(); i++) {
			String matchId = idleM.get(i).getId();
			idleMatches.add(matchId);
		}
		List<Match> waitM = u.getWaiting();
		for(int i = 0; i < waitM.size(); i++) {
			String matchId = waitM.get(i).getId();
			waitingMatches.add(matchId);
		}
		updateArrays.put("acceptedMatches", acceptedMatches);
		updateArrays.put("rejectedMatches", rejectedMatches);
		updateArrays.put("idleMatches", idleMatches);
		updateArrays.put("waitingMatches", waitingMatches);
		HttpPatch request = new HttpPatch(baseUrl + u.getId());
		try {
			request.addHeader("content-type", "application/json");
			StringEntity params = new StringEntity(updateArrays.toJSONString());
			request.setEntity(params);
			HttpResponse response = httpClient.execute(request);
			if(response.getStatusLine().getStatusCode() == 200) {
				System.out.println("User Arrays Updated!");
			} else {
				System.err.println("Failed to Update a User Arrays! Maybe invalid id?");
			}
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			request.releaseConnection();
		}
	}
@ SuppressWarnings ( "unchecked" ) public void updateMatchedArrayState ( User u ) { JSONObject updateArrays = new JSONObject ( ) ; JSONArray acceptedMatches = new JSONArray ( ) ; JSONArray rejectedMatches = new JSONArray ( ) ; JSONArray idleMatches = new JSONArray ( ) ; JSONArray waitingMatches = new JSONArray ( ) ; List < Match > acceptM = u . getAccepted ( ) ; for ( int i = 0 ; i < acceptM . size ( ) ; i ++ ) { String matchId = acceptM . get ( i ) . getId ( ) ; acceptedMatches . add ( matchId ) ; } List < Match > rejectM = u . getRejected ( ) ; for ( int i = 0 ; i < rejectM . size ( ) ; i ++ ) { String matchId = rejectM . get ( i ) . getId ( ) ; rejectedMatches . add ( matchId ) ; } List < Match > idleM = u . getIdle ( ) ; for ( int i = 0 ; i < idleM . size ( ) ; i ++ ) { String matchId = idleM . get ( i ) . getId ( ) ; idleMatches . add ( matchId ) ; } List < Match > waitM = u . getWaiting ( ) ; for ( int i = 0 ; i < waitM . size ( ) ; i ++ ) { String matchId = waitM . get ( i ) . getId ( ) ; waitingMatches . add ( matchId ) ; } updateArrays . put ( "acceptedMatches" , acceptedMatches ) ; updateArrays . put ( "rejectedMatches" , rejectedMatches ) ; updateArrays . put ( "idleMatches" , idleMatches ) ; updateArrays . put ( "waitingMatches" , waitingMatches ) ; HttpPatch request = new HttpPatch ( baseUrl + u . getId ( ) ) ; try { request . addHeader ( "content-type" , "application/json" ) ; StringEntity params = new StringEntity ( updateArrays . toJSONString ( ) ) ; request . setEntity ( params ) ; HttpResponse response = httpClient . execute ( request ) ; if ( response . getStatusLine ( ) . getStatusCode ( ) == 200 ) { System . out . println ( "User Arrays Updated!" ) ; } else { System . err . println ( "Failed to Update a User Arrays! Maybe invalid id?" ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { request . releaseConnection ( ) ; } }
Update matched array state to the database.
Update matched array state to the database .
// Create the Arrays // Load the accept array // Load the reject array // Load the idle array // Load the idle array // Add the Arrays to the JSON Object // Now that the JSON is done we want to open a Patch request to update the user // Open the Connection // Set headers // Attach Body // Execute the request // Get the Respose Back // Success!