Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
admin
0711111111
Binary file not shown.
61 changes: 48 additions & 13 deletions clean_code_projects/_2_project_requirements_design_patterns/pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>clean_code_projects</artifactId>
<groupId>brevity</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>_2_design_patterns_project</artifactId>


<groupId>org.openjfx</groupId>
<artifactId>ProiectAdevarat</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15.0.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>org.openjfx.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module org.openjfx {
requires javafx.controls;
requires javafx.fxml;

opens org.openjfx to javafx.fxml;
exports org.openjfx;
exports org.openjfx.controller;
exports org.openjfx.service;
exports org.openjfx.dao;
exports org.openjfx.model;
opens org.openjfx.controller to javafx.fxml;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.openjfx;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.openjfx.util.InitApplication;

import java.io.IOException;

public class App extends Application {

private static Scene scene;
private static Stage stage;

@Override
public void start(Stage stage) throws IOException {
App.stage = stage;
scene = new Scene(loadFXML("login"), 360, 500);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
}

public static void setRoot(String fxml, int width, int height) throws IOException {
scene.setRoot(loadFXML(fxml));
stage.setHeight(height);
stage.setWidth(width);
}

private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
return fxmlLoader.load();
}

public static void main(String[] args) throws IOException {
InitApplication.initAdminCredentials();
InitApplication.deserializeInitialTenants();
InitApplication.loadTenantCredentials();
launch();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package org.openjfx.controller;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import org.openjfx.App;
import org.openjfx.model.BillTypes;
import org.openjfx.model.Person;
import org.openjfx.model.Tenant;
import org.openjfx.service.LoginService;
import org.openjfx.service.PersonService;
import org.openjfx.service.TenantService;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.util.ResourceBundle;

public class AdministratorController implements Initializable {

private TenantService tenantService;
private PersonService personService;
public TableColumn<Person, String> userName;
public TableColumn<Person, Integer> phoneNumber;
private final ObservableList<Tenant> dataList = FXCollections.observableArrayList();
private final ObservableList<String> comboBoxTopics = FXCollections.observableArrayList();
private final ObservableList<String> comboBoxTypes = FXCollections.observableArrayList();
private final File personsFile = new File("persons.txt");

@FXML
public ComboBox<String> typesCombobox;
@FXML
public TextField notifyTextField;
@FXML
public Button notifyButton;
@FXML
public TextField filterField;
@FXML
public TableView<Tenant> tableview;
@FXML
public ComboBox<String> comboBox;
@FXML
public Button addTenant;
@FXML
public Button deleteTenant;
@FXML
public TextField userNameTenant;
@FXML
public TextField phoneNumberTenant;

public void initTable() {
userName.setCellValueFactory(new PropertyValueFactory<>("userName"));
phoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
dataList.addAll(tenantService.selectAll());
}

public void constructSearchEngine() throws IOException {
FilteredList<Tenant> filteredData = new FilteredList<>(dataList, b -> true);
initTable();
tableview.setItems(filteredData);
comboBoxTopics.addAll("userName", "phoneNumber");
comboBox.setItems(comboBoxTopics);
filterField.textProperty().addListener((observable, oldValue, newValue) -> filteredData.setPredicate(person -> {
if (newValue == null || newValue.isEmpty()) {
return true;
}
String comboBoxValue = comboBox.getValue();
String lowerCaseFilter = newValue.toLowerCase();
switch (comboBoxValue) {
case "userName": {
return person.getUserName().toLowerCase().contains(lowerCaseFilter);
}
case "phoneNumber": {
return String.valueOf(person.getPhoneNumber()).toLowerCase().contains(lowerCaseFilter);
}
default: {
break;
}
}
return false;
}));
SortedList<Tenant> sortedData = new SortedList<>(filteredData);
sortedData.comparatorProperty().bind(tableview.comparatorProperty());
tableview.setItems(sortedData);
tableview.getItems().forEach(System.out::println);
int isOk = 1;
}

public void initBillTypeCombobox() {
for (BillTypes value : BillTypes.values()) {
comboBoxTypes.add(value.toString());
}
typesCombobox.setItems(comboBoxTypes);
}

public void addTenant() throws IOException {
Tenant toBeAdded = new Tenant(userNameTenant.getText(), Integer.parseInt(phoneNumberTenant.getText()));
personService.insert(toBeAdded);
tenantService.insert(toBeAdded);
FileOutputStream fileOutputStream = new FileOutputStream(personsFile);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
for (Tenant tenant : tenantService.selectAll()) {
objectOutputStream.writeObject(tenant);
}
fileOutputStream.close();
}

public void deleteTenant() throws IOException {
Tenant toBeDeleted = new Tenant(userNameTenant.getText(), Integer.parseInt(phoneNumberTenant.getText()));
personService.delete(toBeDeleted);
tenantService.delete(toBeDeleted);
FileOutputStream fileOutputStream = new FileOutputStream(personsFile);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
for (Tenant tenant : tenantService.selectAll()) {
objectOutputStream.writeObject(tenant);
}
}

@Override
public void initialize(URL location, ResourceBundle resources) {
setLoginService(LoginService.getInstance());
setTenantService(TenantService.getInstance());
setPersonService(PersonService.getInstance());
initBillTypeCombobox();
try {
constructSearchEngine();
} catch (IOException e) {
e.printStackTrace();
}
}

public void setLoginService(LoginService loginService) {
}

public void setTenantService(TenantService tenantService) {
this.tenantService = tenantService;
}

public void setPersonService(PersonService personService) {
this.personService = personService;
}

public void sendNotificationsToTenant() {
for (Tenant tenant : tenantService.selectAll()) {
tenantService.notifyMe(notifyTextField.getText(), tenant, typesCombobox.getValue());
}
}

public void logout(ActionEvent actionEvent) throws IOException {
App.setRoot("login", 360, 500);
}

public void showPayedBills() throws IOException {
App.setRoot("paidBills", 700, 540);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.openjfx.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import org.openjfx.App;
import org.openjfx.model.Person;
import org.openjfx.service.LoginService;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class LoginController implements Initializable {

private LoginService loginService;

@FXML
public TextField userTextField;
@FXML
public TextField phoneNumberTextField;
@FXML
public Label errorLabel;

@Override
public void initialize(URL location, ResourceBundle resources) {
errorLabel.setVisible(false);
setLoginService(LoginService.getInstance());

}

public int login() throws IOException {

int idGrasper = 0;
if (checkIfFieldIsEmpty()) {
errorLabel.setText(" Some fields are let empty");
errorLabel.setVisible(true);
} else {
Person formUser = new Person(userTextField.getText(), Integer.parseInt(phoneNumberTextField.getText()));
String option = loginService.logIn(formUser);
if (option != null) {
idGrasper = loginService.getIdGrasper();
if (option.equals("TENANT")) {
App.setRoot("tenant", 800, 500);
} else
App.setRoot("administrator", 800, 520);
} else {
errorLabel.setText(" User does not exist");
errorLabel.setVisible(true);
}
}
return idGrasper;
}

public boolean checkIfFieldIsEmpty() {
return userTextField.getText().isBlank() || phoneNumberTextField.getText().isBlank();
}

public void register() throws IOException {
App.setRoot("register", 360, 500);
}

public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}
}
Loading