diff --git a/backend/src/main/java/si/um/feri/measurements/AddTestData.java b/backend/src/main/java/si/um/feri/measurements/AddTestData.java
index bb540b3..65f60ed 100644
--- a/backend/src/main/java/si/um/feri/measurements/AddTestData.java
+++ b/backend/src/main/java/si/um/feri/measurements/AddTestData.java
@@ -20,6 +20,24 @@ public class AddTestData {
@Inject
MeasurementRepository measurementRepository;
+ /**
+ * This method is invoked during the startup event of the application.
+ * It initializes the database with predefined products and their associated measurements.
+ *
+ *
This method subscribes to the startup event and executes a transaction that
+ * creates and persists two products: "Milka Classic" and "Chicken Breasts",
+ * along with their respective measurements.
+ *
+ * @param ev the startup event that triggers this method
+ * @throws Throwable if an error occurs during the transaction or persistence operations
+ *
+ * Exceptions that may be thrown include:
+ *
+ * - PersistenceException: If there is an error while persisting the products or measurements.
+ * - IllegalArgumentException: If the provided values for minimum or maximum measures are invalid.
+ * - TransactionException: If there is an issue with the transaction management.
+ *
+ */
public void onStart(@Observes StartupEvent ev) throws Throwable {
VertxContextSupport.subscribeAndAwait(() ->
Panache.withTransaction(() -> {
diff --git a/backend/src/main/java/si/um/feri/measurements/GreetingResource.java b/backend/src/main/java/si/um/feri/measurements/GreetingResource.java
index 0cf621d..371f20d 100644
--- a/backend/src/main/java/si/um/feri/measurements/GreetingResource.java
+++ b/backend/src/main/java/si/um/feri/measurements/GreetingResource.java
@@ -10,6 +10,16 @@ public class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
+ /**
+ * Returns a greeting message.
+ *
+ * This method generates a simple greeting string that can be used in various contexts
+ * where a friendly message is required.
+ *
+ * @return a String containing the greeting message "Hello from RESTEasy Reactive".
+ *
+ * @throws NullPointerException if the greeting message cannot be generated (not applicable in this case).
+ */
public String hello() {
return "Hello from RESTEasy Reactive";
}
diff --git a/backend/src/main/java/si/um/feri/measurements/dao/MeasurementRepository.java b/backend/src/main/java/si/um/feri/measurements/dao/MeasurementRepository.java
index b229536..693265d 100644
--- a/backend/src/main/java/si/um/feri/measurements/dao/MeasurementRepository.java
+++ b/backend/src/main/java/si/um/feri/measurements/dao/MeasurementRepository.java
@@ -10,6 +10,14 @@
@ApplicationScoped
public class MeasurementRepository implements PanacheRepository {
+ /**
+ * Retrieves a list of {@link Measurement} objects that were created after the specified date and time.
+ *
+ * @param created the date and time to compare against; only measurements created after this time will be included
+ * @return a {@link Uni} containing a list of {@link Measurement} objects that match the criteria
+ * @throws IllegalArgumentException if the provided {@code created} parameter is null
+ * @throws SomeDatabaseException if there is an error while querying the database
+ */
public Uni> findByCreatedGreaterThan(LocalDateTime created){
return find("created >= ?1", created).list();
}
diff --git a/backend/src/main/java/si/um/feri/measurements/rest/MeasurementController.java b/backend/src/main/java/si/um/feri/measurements/rest/MeasurementController.java
index 19a51c3..a392844 100644
--- a/backend/src/main/java/si/um/feri/measurements/rest/MeasurementController.java
+++ b/backend/src/main/java/si/um/feri/measurements/rest/MeasurementController.java
@@ -27,6 +27,28 @@ public class MeasurementController {
boolean ok = true;
@POST
+ /**
+ * Adds a measurement for a given product.
+ *
+ * This method retrieves a product by its ID from the repository, creates a new
+ * Measurement object based on the provided PostMeasurement data, and checks
+ * if the average temperature is within the acceptable range defined by the
+ * product's minimum and maximum measurements. If the average temperature
+ * is outside this range, it logs an appropriate message indicating that
+ * action is needed.
+ *
+ * The method persists the Measurement object to the database and returns
+ * a response indicating whether the operation was successful or not.
+ *
+ * @param m the PostMeasurement object containing measurement data
+ * @return a Uni containing a RestResponse with the result of the operation
+ * and a message indicating success or failure
+ *
+ * @throws IllegalArgumentException if the provided PostMeasurement object
+ * contains invalid data (e.g., null values)
+ * @throws NoSuchElementException if no product is found with the given ID
+ * @throws PersistenceException if there is an error persisting the measurement
+ */
public Uni> addMeasurement(PostMeasurement m){
return productRepository.findById(Long.valueOf(m.id())).onItem().transformToUni(item -> {
log.info("id: "+item.getId());
diff --git a/backend/src/main/java/si/um/feri/measurements/vao/Measurement.java b/backend/src/main/java/si/um/feri/measurements/vao/Measurement.java
index 5b76f01..b15b1ce 100644
--- a/backend/src/main/java/si/um/feri/measurements/vao/Measurement.java
+++ b/backend/src/main/java/si/um/feri/measurements/vao/Measurement.java
@@ -17,6 +17,23 @@ public Measurement() {
}
+ /**
+ * Converts the current object to a Data Transfer Object (DTO) representation.
+ *
+ * This method creates a new instance of {@link si.um.feri.measurements.dto.Measurement}
+ * using the properties of the current object. The created DTO includes the following fields:
+ *
+ * - ID of the current object
+ * - Formatted creation date using JSON date format
+ * - ID of the associated product, or -1 if no product is associated
+ * - Value of the measurement
+ * - Status indicating if the measurement is valid
+ *
+ *
+ * @return a {@link si.um.feri.measurements.dto.Measurement} object representing this measurement.
+ *
+ * @throws NullPointerException if the creation date is null or if the product is null and cannot be processed.
+ */
public si.um.feri.measurements.dto.Measurement toDto() {
return new si.um.feri.measurements.dto.Measurement(
id,
@@ -41,42 +58,105 @@ public si.um.feri.measurements.dto.Measurement toDto() {
@ManyToOne
private Product product;
+ /**
+ * Retrieves the unique identifier associated with this instance.
+ *
+ * @return the unique identifier (ID) as a {@link Long} object.
+ *
+ * @throws NullPointerException if the ID has not been initialized and is null.
+ */
public Long getId() {
return id;
}
+ /**
+ * Sets the identifier for this object.
+ *
+ * @param id the identifier to set, which can be null
+ * @throws IllegalArgumentException if the id is negative
+ */
public void setId(Long id) {
this.id = id;
}
+ /**
+ * Retrieves the current value.
+ *
+ * @return the current value as a double.
+ * @throws IllegalStateException if the value has not been initialized.
+ */
public double getValue() {
return value;
}
+ /**
+ * Sets the value of this object to the specified double value.
+ *
+ * @param value the new value to be set
+ * @throws IllegalArgumentException if the value is not valid (e.g., if it is NaN or infinite)
+ */
public void setValue(double value) {
this.value = value;
}
+ /**
+ * Retrieves the creation date and time of the object.
+ *
+ * @return a {@link LocalDateTime} object representing the creation date and time.
+ *
+ * @throws NullPointerException if the creation date and time has not been initialized.
+ */
public LocalDateTime getCreated() {
return created;
}
+ /**
+ * Sets the creation timestamp for this object.
+ *
+ * @param created the LocalDateTime representing the creation time
+ * @throws IllegalArgumentException if the created parameter is null
+ */
public void setCreated(LocalDateTime created) {
this.created = created;
}
+ /**
+ * Checks if the current state is acceptable.
+ *
+ * @return {@code true} if the state is acceptable; {@code false} otherwise.
+ *
+ * @throws IllegalStateException if the method is called when the object is in an invalid state.
+ */
public boolean isOk() {
return isOk;
}
+ /**
+ * Sets the value of the 'isOk' property.
+ *
+ * @param ok a boolean value indicating the new state of 'isOk'.
+ * @throws IllegalArgumentException if the provided value is not valid (e.g., if additional validation rules are applied).
+ */
public void setOk(boolean ok) {
isOk = ok;
}
+ /**
+ * Retrieves the product associated with this instance.
+ *
+ * @return the {@link Product} object representing the product.
+ * @throws IllegalStateException if the product has not been initialized or is null.
+ */
public Product getProduct() {
return product;
}
+ /**
+ * Sets the product for this instance.
+ *
+ * @param product the Product object to be set
+ * @throws IllegalArgumentException if the provided product is null
+ */
public void setProduct(Product product) {
this.product = product;
}
diff --git a/backend/src/main/java/si/um/feri/measurements/vao/Product.java b/backend/src/main/java/si/um/feri/measurements/vao/Product.java
index cca7cd5..5666ce7 100644
--- a/backend/src/main/java/si/um/feri/measurements/vao/Product.java
+++ b/backend/src/main/java/si/um/feri/measurements/vao/Product.java
@@ -20,12 +20,32 @@ public Product() {
}
+ /**
+ * Updates the current product instance with the values from the provided Product DTO.
+ *
+ * This method sets the name, maximum measurement, and minimum measurement of the
+ * current product based on the data from the specified Product DTO.
+ *
+ * @param dto the Product DTO containing the new values for the product
+ * @throws NullPointerException if the provided dto is null
+ * @throws IllegalArgumentException if any of the values in dto are invalid (e.g.,
+ * maxMeasure is less than minMeasure)
+ */
public void updateFrom(si.um.feri.measurements.dto.Product dto) {
setName(dto.name());
setMaxMeasure(dto.maxMeasure());
setMinMeasure(dto.minMeasure());
}
+ /**
+ * Converts the current object to a Data Transfer Object (DTO) of type {@link si.um.feri.measurements.dto.Product}.
+ *
+ * @return a {@link si.um.feri.measurements.dto.Product} instance containing the id, name,
+ * maximum measurement, and minimum measurement of the current object.
+ *
+ * @throws IllegalStateException if the object is in an invalid state for conversion,
+ * such as if the maximum measurement is less than the minimum measurement.
+ */
public si.um.feri.measurements.dto.Product toDto() {
return new si.um.feri.measurements.dto.Product(
getId(),
@@ -46,42 +66,104 @@ public si.um.feri.measurements.dto.Product toDto() {
protected double minMeasure;
+ /**
+ * Retrieves the unique identifier associated with this object.
+ *
+ * @return the unique identifier (ID) as a {@code Long} object.
+ * Returns {@code null} if the ID has not been set.
+ *
+ * @throws IllegalStateException if the ID is not initialized and cannot be retrieved.
+ */
public Long getId() {
return id;
}
+ /**
+ * Sets the identifier for this object.
+ *
+ * @param id the identifier to set, which can be null.
+ * @throws IllegalArgumentException if the id is negative.
+ */
public void setId(Long id) {
this.id = id;
}
+ /**
+ * Retrieves the name associated with this object.
+ *
+ * @return the name as a {@code String}.
+ * @throws NullPointerException if the name is null.
+ */
public String getName() {
return name;
}
+ /**
+ * Sets the name of the object.
+ *
+ * @param name the name to be set; must not be null or empty
+ * @throws IllegalArgumentException if the provided name is null or empty
+ */
public void setName(String name) {
this.name = name;
}
+ /**
+ * Retrieves the creation date and time of the object.
+ *
+ * @return a {@link LocalDateTime} representing the creation date and time.
+ * @throws IllegalStateException if the creation date and time is not set.
+ */
public LocalDateTime getCreated() {
return created;
}
+ /**
+ * Sets the creation date and time.
+ *
+ * @param created the LocalDateTime representing the creation date and time
+ * @throws IllegalArgumentException if the created parameter is null
+ */
public void setCreated(LocalDateTime created) {
this.created = created;
}
+ /**
+ * Retrieves the maximum measurement value.
+ *
+ * @return the maximum measurement as a double.
+ * @throws IllegalStateException if the maximum measurement has not been initialized.
+ */
public double getMaxMeasure() {
return maxMeasure;
}
+ /**
+ * Sets the maximum measurement value.
+ *
+ * @param maxMeasure the maximum measurement value to set
+ * @throws IllegalArgumentException if maxMeasure is negative
+ */
public void setMaxMeasure(double maxMeasure) {
this.maxMeasure = maxMeasure;
}
+ /**
+ * Retrieves the minimum measurement value.
+ *
+ * @return the minimum measurement as a double.
+ * @throws IllegalStateException if the minimum measurement has not been initialized.
+ */
public double getMinMeasure() {
return minMeasure;
}
+ /**
+ * Sets the minimum measurement value.
+ *
+ * @param minMeasure the minimum measurement value to set
+ * @throws IllegalArgumentException if minMeasure is less than zero
+ */
public void setMinMeasure(double minMeasure) {
this.minMeasure = minMeasure;
}
diff --git a/backend/src/test/java/si/um/feri/measurements/GreetingResourceTest.java b/backend/src/test/java/si/um/feri/measurements/GreetingResourceTest.java
index 0582a1b..975c5b4 100644
--- a/backend/src/test/java/si/um/feri/measurements/GreetingResourceTest.java
+++ b/backend/src/test/java/si/um/feri/measurements/GreetingResourceTest.java
@@ -9,6 +9,16 @@
@QuarkusTest
class GreetingResourceTest {
@Test
+ /**
+ * Tests the "/hello" endpoint of the RESTEasy Reactive application.
+ *
+ * This method sends a GET request to the "/hello" endpoint and verifies that
+ * the response status code is 200 (OK) and that the response body matches
+ * the expected string "Hello from RESTEasy Reactive".
+ *
+ * @throws AssertionError if the response status code is not 200 or if the
+ * response body does not match the expected value.
+ */
void testHelloEndpoint() {
given()
.when().get("/hello")