Skip to content

Commit

Permalink
Generated Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
penify-dev[bot] committed Nov 17, 2024
1 parent f7b0eed commit 2c895c0
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 0 deletions.
18 changes: 18 additions & 0 deletions backend/src/main/java/si/um/feri/measurements/AddTestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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.</p>
*
* @param ev the startup event that triggers this method
* @throws Throwable if an error occurs during the transaction or persistence operations
*
* <p>Exceptions that may be thrown include:</p>
* <ul>
* <li><strong>PersistenceException:</strong> If there is an error while persisting the products or measurements.</li>
* <li><strong>IllegalArgumentException:</strong> If the provided values for minimum or maximum measures are invalid.</li>
* <li><strong>TransactionException:</strong> If there is an issue with the transaction management.</li>
* </ul>
*/
public void onStart(@Observes StartupEvent ev) throws Throwable {
VertxContextSupport.subscribeAndAwait(() ->
Panache.withTransaction(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

@ApplicationScoped
public class MeasurementRepository implements PanacheRepository<Measurement> {
/**
* 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<List<Measurement>> findByCreatedGreaterThan(LocalDateTime created){
return find("created >= ?1", created).list();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RestResponse<PostMeasurementResponse>> addMeasurement(PostMeasurement m){
return productRepository.findById(Long.valueOf(m.id())).onItem().transformToUni(item -> {
log.info("id: "+item.getId());
Expand Down
80 changes: 80 additions & 0 deletions backend/src/main/java/si/um/feri/measurements/vao/Measurement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* <ul>
* <li>ID of the current object</li>
* <li>Formatted creation date using JSON date format</li>
* <li>ID of the associated product, or -1 if no product is associated</li>
* <li>Value of the measurement</li>
* <li>Status indicating if the measurement is valid</li>
* </ul>
*
* @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,
Expand All @@ -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;
}
Expand Down
82 changes: 82 additions & 0 deletions backend/src/main/java/si/um/feri/measurements/vao/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 2c895c0

Please sign in to comment.