server finally works. only thing left is to write queries from the client
This commit is contained in:
@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* The ClientConnect class represents a graphical user interface (GUI) frame for capturing
|
||||
@@ -41,7 +42,26 @@ public class ClientConnect extends JFrame {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
logger.info("Triggered a Connection request.");
|
||||
// Connection logic would go here (e.g., retrieve values and initiate connection)
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
private String getSanitizedText(JTextField textField) {
|
||||
// Get the text from the JTextField and trim leading/trailing whitespace
|
||||
String sanitizedText = textField.getText().trim();
|
||||
|
||||
// Remove unwanted characters (single quotes, double quotes, non-alphanumeric characters)
|
||||
sanitizedText = sanitizedText.replaceAll("[^a-zA-Z0-9]", ""); // Remove all non-alphanumeric characters
|
||||
|
||||
// Optionally, remove single quotes and double quotes
|
||||
sanitizedText = sanitizedText.replaceAll("[\'\"]", "");
|
||||
|
||||
// If the text is empty after sanitization, set a default value
|
||||
if (sanitizedText.isEmpty()) {
|
||||
sanitizedText = "default"; // or you can return an empty string, or throw an exception, depending on the case
|
||||
}
|
||||
|
||||
return sanitizedText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,47 +73,59 @@ public class ServerDaemon implements Runnable {
|
||||
* @param path The root path to initialize.
|
||||
* @return True if initialization is successful, false otherwise.
|
||||
*/
|
||||
|
||||
private boolean initRootPath(Path path) {
|
||||
// Create the lock file
|
||||
String lockFile = "lock.lock"; // Set your desired file name
|
||||
Path fullPath = path.resolve(lockFile); // Combine the base path and file name
|
||||
|
||||
// Combine the base path and file name
|
||||
Path fullPath = path.resolve(lockFile);
|
||||
|
||||
// Create the file
|
||||
File file = fullPath.toFile();
|
||||
|
||||
try {
|
||||
// Create the parent directories if they don't exist
|
||||
file.getParentFile().mkdirs();
|
||||
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
|
||||
logger.error("Failed to create directories for lock file.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the file
|
||||
if (file.createNewFile()) {
|
||||
logger.info("File created: " + file.getName());
|
||||
// Create the lock file if it doesn't already exist
|
||||
if (!file.exists()) {
|
||||
if (file.createNewFile()) {
|
||||
logger.info("Lock file created: " + file.getName());
|
||||
|
||||
// Write a random byte to the file
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
Random random = new Random();
|
||||
byte randomByte = (byte) random.nextInt(256); // Generate random byte
|
||||
fos.write(randomByte);
|
||||
logger.info("Random byte written to file.");
|
||||
// Write a random byte to the file
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
Random random = new Random();
|
||||
byte randomByte = (byte) random.nextInt(256); // Generate random byte
|
||||
fos.write(randomByte);
|
||||
logger.info("Random byte written to lock file.");
|
||||
}
|
||||
} else {
|
||||
logger.error("Failed to create lock file.");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
System.out.println("File already exists.");
|
||||
logger.info("Lock file already exists.");
|
||||
}
|
||||
|
||||
// Create the patient directory
|
||||
String patientEhrs = "patients/";
|
||||
Path patientPath = path.resolve(patientEhrs);
|
||||
File dir = patientPath.toFile();
|
||||
|
||||
if (!dir.exists() && !dir.mkdirs()) {
|
||||
logger.error("Failed to create patient directory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.err.println("An error occurred: " + e.getMessage());
|
||||
logger.error("An error occurred during lock file creation: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create patient directory
|
||||
String patientEhrs = "patients/";
|
||||
Path patientPath = path.resolve(patientEhrs);
|
||||
File dir = patientPath.toFile();
|
||||
dir.mkdir();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the root path has already been initialized by checking if the lock file exists.
|
||||
*
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user