src/com/company/Server/ReadWriteFiles.java
public void writeJSONFile(Client client) {
        try {
            this.jsonParser = new JSONParser();
            JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(file.getPath()));

            JSONArray listUsers = (JSONArray) obj.get("Registry");

            boolean found = false;
            JSONObject user;
            int i = 0;

            while (!found && i < listUsers.size()) {
                user = (JSONObject) listUsers.get(i);

                if (client.getId() == ((Long) user.get("id")).intValue()) {
                    found = true;
                    ((JSONObject) listUsers.get(i)).put("isInfected", client.isInfected());
                    ((JSONObject) listUsers.get(i)).put("isNotified", client.isNotified());
                }

                i++;
            }

            JSONArray county = (JSONArray) obj.get("Counties");
            JSONArray unregisteredUsers = (JSONArray) obj.get("UnregisteredUsers");

            if (unregisteredUsers == null) {
                unregisteredUsers = new JSONArray();
            }

            JSONObject objWrite = new JSONObject();

            objWrite.put("UnregisteredUsers", unregisteredUsers);
            objWrite.put("Registry", listUsers);
            objWrite.put("Counties", county);

            FileWriter fileWriter = new FileWriter(file.getPath());

            fileWriter.write(objWrite.toJSONString());

            fileWriter.close();

        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }
    }
/**
     * Method responsible for writing client information to a JSON file while the client is using the application
     *
     * @param client client object (model)
     */
Method responsible for writing client information to a JSON file while the client is using the application
@param client client object (model)
Method responsible for writing client information to a JSON file while the client is using the application @param client client object ( model )
public void writeJSONFile(Client client) {
        try {
            this.jsonParser = new JSONParser();
            JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(file.getPath()));
            JSONArray listUsers = (JSONArray) obj.get("Registry");
            boolean found = false;
            JSONObject user;
            int i = 0;
            while (!found && i < listUsers.size()) {
                user = (JSONObject) listUsers.get(i);
                if (client.getId() == ((Long) user.get("id")).intValue()) {
                    found = true;
                    ((JSONObject) listUsers.get(i)).put("isInfected", client.isInfected());
                    ((JSONObject) listUsers.get(i)).put("isNotified", client.isNotified());
                }
                i++;
            }
            JSONArray county = (JSONArray) obj.get("Counties");
            JSONArray unregisteredUsers = (JSONArray) obj.get("UnregisteredUsers");
            if (unregisteredUsers == null) {
                unregisteredUsers = new JSONArray();
            }
            JSONObject objWrite = new JSONObject();
            objWrite.put("UnregisteredUsers", unregisteredUsers);
            objWrite.put("Registry", listUsers);
            objWrite.put("Counties", county);
            FileWriter fileWriter = new FileWriter(file.getPath());
            fileWriter.write(objWrite.toJSONString());
            fileWriter.close();
        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }
    }
public void writeJSONFile ( Client client ) { try { this . jsonParser = new JSONParser ( ) ; JSONObject obj = ( JSONObject ) jsonParser . parse ( new FileReader ( file . getPath ( ) ) ) ; JSONArray listUsers = ( JSONArray ) obj . get ( "Registry" ) ; boolean found = false ; JSONObject user ; int i = 0 ; while ( ! found && i < listUsers . size ( ) ) { user = ( JSONObject ) listUsers . get ( i ) ; if ( client . getId ( ) == ( ( Long ) user . get ( "id" ) ) . intValue ( ) ) { found = true ; ( ( JSONObject ) listUsers . get ( i ) ) . put ( "isInfected" , client . isInfected ( ) ) ; ( ( JSONObject ) listUsers . get ( i ) ) . put ( "isNotified" , client . isNotified ( ) ) ; } i ++ ; } JSONArray county = ( JSONArray ) obj . get ( "Counties" ) ; JSONArray unregisteredUsers = ( JSONArray ) obj . get ( "UnregisteredUsers" ) ; if ( unregisteredUsers == null ) { unregisteredUsers = new JSONArray ( ) ; } JSONObject objWrite = new JSONObject ( ) ; objWrite . put ( "UnregisteredUsers" , unregisteredUsers ) ; objWrite . put ( "Registry" , listUsers ) ; objWrite . put ( "Counties" , county ) ; FileWriter fileWriter = new FileWriter ( file . getPath ( ) ) ; fileWriter . write ( objWrite . toJSONString ( ) ) ; fileWriter . close ( ) ; } catch ( IOException | ParseException e ) { e . printStackTrace ( ) ; } }
Method responsible for writing client information to a JSON file while the client is using the application
 @param client client object (model)
Method responsible for writing client information to a JSON file while the client is using the application @param client client object ( model )