Add description support for asset properties and update related models

This commit is contained in:
2025-06-08 14:47:13 +02:00
parent a490b2a306
commit c8829c5f7c
10 changed files with 94 additions and 26 deletions

View File

@@ -45,6 +45,8 @@ public class AssetProperty {
private final boolean inputList;
/// Whether the property should be hidden in the overview.
private final boolean hideInOverview;
/// A description of the property, if any.
private final String description;
/**
* Enum representing the possible types of asset properties.
@@ -90,6 +92,7 @@ public class AssetProperty {
.required(annotation.required())
.inputList(property.isAnnotationPresent(InputList.class))
.hideInOverview(property.isAnnotationPresent(HideInOverview.class))
.description(property.isAnnotationPresent(Description.class) ? property.getAnnotation(Description.class).value() : "")
.setter((obj, value) -> {
try {
property.setAccessible(true);

View File

@@ -0,0 +1,20 @@
package be.seeseepuff.pcinv.meta;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to provide a description for an asset.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Description {
/**
* The description of the asset.
*
* @return The description text.
*/
String value() default "";
}

View File

@@ -0,0 +1,48 @@
package be.seeseepuff.pcinv.models;
import be.seeseepuff.pcinv.meta.*;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
/**
* Represents a RAM DIMM or similar memory asset in the inventory system.
*/
@Getter
@Setter
@Entity
@AssetInfo(
displayName = "Display Adapter",
pluralName = "Display Adapters",
type = "GPU"
)
@Table(name = "gpu_assets")
public class DisplayAdapterAsset implements Asset
{
@Id
@GeneratedValue
private long id;
/// The generic asset associated with this RAM.
@OneToOne(orphanRemoval = true)
private GenericAsset asset;
@Property("VRAM Capacity")
@Capacity
private Long vramCapacity;
@Description("The type of interface. E.g.: AGP, PCIe, ISA-8, etc...")
@Property("Interface")
@InputList
private String interfaceType;
@Description("The highest version of DirectX supported by this display adapter.")
@Property("DirectX Version")
@InputList
private String directXVersion;
@Description("The highest version of OpenGL supported by this display adapter.")
@Property("OpenGL Version")
@InputList
private String openGLVersion;
}

View File

@@ -1,9 +1,6 @@
package be.seeseepuff.pcinv.models;
import be.seeseepuff.pcinv.meta.AssetInfo;
import be.seeseepuff.pcinv.meta.InputList;
import be.seeseepuff.pcinv.meta.HideInOverview;
import be.seeseepuff.pcinv.meta.Property;
import be.seeseepuff.pcinv.meta.*;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
@@ -33,30 +30,26 @@ public class GenericAsset
/// The QR code attached to the asset, used for identification.
@Property(value = "QR", required = true)
@Description("The QR code attached to the asset, used for identification.")
private long qr;
/// The type of asset
private String type;
/// The brand of the asset.
@Property("Brand")
@InputList
private String brand;
/// The model of the asset
@Property("Model")
private String model;
/// The asset's serial number.
@Property("Serial Number")
private String serialNumber;
/// A description of the asset, providing additional details.
@Property("Description")
@HideInOverview
private String description;
/// The state of the asset, indicating its condition.
@Property("Condition")
private AssetCondition condition;
}

View File

@@ -1,9 +1,6 @@
package be.seeseepuff.pcinv.models;
import be.seeseepuff.pcinv.meta.AssetInfo;
import be.seeseepuff.pcinv.meta.Capacity;
import be.seeseepuff.pcinv.meta.InputList;
import be.seeseepuff.pcinv.meta.Property;
import be.seeseepuff.pcinv.meta.*;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
@@ -26,21 +23,19 @@ public class HddAsset implements Asset
@GeneratedValue
private long id;
/// The generic asset associated with this HDD.
@OneToOne(orphanRemoval = true)
private GenericAsset asset;
/// The capacity of the drive in bytes.
@Property("Capacity")
@Capacity(si = true, iec = true)
private Long capacity;
/// The drive's interface type, such as SATA, IDE, ISA-16, ...
@Description("The drive's interface type, such as SATA, IDE, ISA-16, ...")
@Property("Interface Type")
@InputList
private String interfaceType;
/// The drive's form factor, such as 2.5", 3.5", etc.
@Description("The drive's form factor, such as 2.5\", 3.5\", etc.")
@Property("Form Factor")
@InputList
private String formFactor;

View File

@@ -1,8 +1,6 @@
package be.seeseepuff.pcinv.models;
import be.seeseepuff.pcinv.meta.AssetInfo;
import be.seeseepuff.pcinv.meta.Capacity;
import be.seeseepuff.pcinv.meta.Property;
import be.seeseepuff.pcinv.meta.*;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
@@ -25,16 +23,15 @@ public class RamAsset implements Asset
@GeneratedValue
private long id;
/// The generic asset associated with this RAM.
@OneToOne(orphanRemoval = true)
private GenericAsset asset;
/// The capacity of the RAM in bytes.
@Property("Capacity")
@Capacity
private Long capacity;
/// The type of memory. E.g.: DDR2, SDRAM, ISA-8, etc...
@Description("The type of memory. E.g.: DDR2, SDRAM, ISA-8, etc...")
@Property("Type")
@InputList
private String type;
}

View File

@@ -0,0 +1,12 @@
package be.seeseepuff.pcinv.repositories;
import be.seeseepuff.pcinv.models.DisplayAdapterAsset;
import org.springframework.data.jpa.repository.JpaRepository;
@SuppressWarnings("unused")
public interface DisplayAdapterRepository extends JpaRepository<DisplayAdapterAsset, Long>, AssetRepository<DisplayAdapterAsset> {
@Override
default Class<DisplayAdapterAsset> getAssetType() {
return DisplayAdapterAsset.class;
}
}

View File

@@ -4,7 +4,7 @@ import be.seeseepuff.pcinv.models.HddAsset;
import org.springframework.data.jpa.repository.JpaRepository;
@SuppressWarnings("unused")
public interface HddAssetRepository extends JpaRepository<HddAsset, Long>, AssetRepository<HddAsset> {
public interface HddRepository extends JpaRepository<HddAsset, Long>, AssetRepository<HddAsset> {
@Override
default Class<HddAsset> getAssetType() {
return HddAsset.class;

View File

@@ -4,7 +4,7 @@ import be.seeseepuff.pcinv.models.RamAsset;
import org.springframework.data.jpa.repository.JpaRepository;
@SuppressWarnings("unused")
public interface RamAssetRepository extends JpaRepository<RamAsset, Long>, AssetRepository<RamAsset> {
public interface RamRepository extends JpaRepository<RamAsset, Long>, AssetRepository<RamAsset> {
@Override
default Class<RamAsset> getAssetType() {
return RamAsset.class;

View File

@@ -6,7 +6,7 @@
<h2 th:text="${d.displayName}"></h2>
<table border="1" cellpadding="4">
<tr th:each="p : ${d.getProperties()}">
<td bgcolor="#d3d3d3"><b><label th:text="${p.displayName}" th:for="${d.asString(p)}"></label></b></td>
<td bgcolor="#d3d3d3"><b><label th:text="${p.displayName}" th:for="${d.asString(p)}" th:title="${p.description}"></label></b></td>
<td th:switch="${p.type.nameOrEnum()}">
<span th:case="STRING">
<select th:if="${p.inputList}" th:id="${d.asString(p)+'-list'}" th:name="${d.asString(p)+'-list'}">