First designs for ui

This commit is contained in:
verboomp
2026-01-23 15:09:34 +01:00
parent b3de3eec8c
commit f48bfe2107
41 changed files with 1727 additions and 412 deletions

View File

@@ -39,6 +39,9 @@ public class Picture extends AbstractDateEntity {
@Basic(fetch = FetchType.LAZY)
private String comment;
private String category;
@Column(name = "image")
@Basic(fetch = FetchType.LAZY)
@@ -79,6 +82,16 @@ public class Picture extends AbstractDateEntity {
public void setComment(String comment) {
this.comment = comment;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getImage() {
return image;
@@ -121,12 +134,17 @@ public class Picture extends AbstractDateEntity {
instance.setPictureDate(pictureDate);
return this;
}
public Builder comment(String comment) {
instance.setComment(comment);
return this;
}
public Builder category(String category) {
instance.setCategory(category);
return this;
}
public Builder image(String image) {
instance.setImage(image);
return this;

View File

@@ -3,14 +3,21 @@ package marketing.heyday.hartmann.fotodocumentation.core.service;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import jakarta.annotation.security.PermitAll;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import marketing.heyday.hartmann.fotodocumentation.core.model.Customer;
import marketing.heyday.hartmann.fotodocumentation.core.model.Picture;
import marketing.heyday.hartmann.fotodocumentation.core.query.Param;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerListValue;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerPictureValue;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerValue;
/**
*
@@ -30,8 +37,12 @@ public class CustomerPictureService extends AbstractService {
Optional<Customer> customerOpt = queryService.callNamedQuerySingleResult(Customer.FIND_BY_NUMBER, new Param(Customer.PARAM_NUMBER, customerPictureValue.customerNumber()));
Customer customer = customerOpt.orElseGet(() -> new Customer.Builder().customerNumber(customerPictureValue.customerNumber()).name(customerPictureValue.pharmacyName()).build());
customer = entityManager.merge(customer);
Picture picture = new Picture.Builder().customer(customer).username(customerPictureValue.username()).comment(customerPictureValue.comment()).image(customerPictureValue.base64String()).pictureDate(customerPictureValue.date()).build();
Picture picture = new Picture.Builder().customer(customer).username(customerPictureValue.username())
.category(customerPictureValue.category())
.comment(customerPictureValue.comment())
.image(customerPictureValue.base64String())
.pictureDate(customerPictureValue.date()).build();
customer.getPictures().add(picture);
entityManager.persist(picture);
@@ -39,10 +50,42 @@ public class CustomerPictureService extends AbstractService {
return true;
}
public List<CustomerListValue> getAll(String query) {
// query = search for name, number and date
public List<CustomerListValue> getAll(String queryStr, String startsWith) {
// FIXME: do query
List<Customer> customers = queryService.callNamedQueryList(Customer.FIND_ALL);
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Customer> criteriaQuery = builder.createQuery(Customer.class);
Root<Customer> customerRoot = criteriaQuery.from(Customer.class);
criteriaQuery = criteriaQuery.select(customerRoot);
if (StringUtils.isNotBlank(startsWith)) {
String param = startsWith.toLowerCase() + "%";
criteriaQuery = criteriaQuery.where(builder.like(builder.lower(customerRoot.get("name")), param));
}
if (StringUtils.isNotBlank(queryStr)) {
String param = "%" + StringUtils.trimToEmpty(queryStr).toLowerCase() + "%";
var predicateName = builder.like(builder.lower(customerRoot.get("name")), param);
var predicateNr = builder.like(builder.lower(customerRoot.get("customerNumber")), param);
var predicate = builder.or(predicateName, predicateNr);
criteriaQuery = criteriaQuery.where(predicate);
}
TypedQuery<Customer> typedQuery = entityManager.createQuery(criteriaQuery);
List<Customer> customers = typedQuery.getResultList();
customers.forEach(c -> c.getPictures().size());
return customers.parallelStream().map(CustomerListValue::builder).toList();
}
public CustomerValue get(Long id) {
Customer customer = entityManager.find(Customer.class, id);
if (customer == null) {
return null;
}
return CustomerValue.builder(customer);
}
}

View File

@@ -0,0 +1,31 @@
package marketing.heyday.hartmann.fotodocumentation.core.service;
import jakarta.annotation.security.PermitAll;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import marketing.heyday.hartmann.fotodocumentation.core.model.Picture;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.PictureValue;
/**
*
* <p>Copyright: Copyright (c) 2024</p>
* <p>Company: heyday Marketing GmbH</p>
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
* @version 1.0
*
* created: 19 Jan 2026
*/
@Stateless
@LocalBean
@PermitAll
public class PictureService extends AbstractService {
public PictureValue get(Long id) {
Picture picture = entityManager.find(Picture.class, id);
if (picture == null) {
return null;
}
return PictureValue.builder(picture);
}
}

View File

@@ -13,14 +13,11 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.ejb.EJB;
import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;
import marketing.heyday.hartmann.fotodocumentation.core.service.CustomerPictureService;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerListValue;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerValue;
/**
*
@@ -42,12 +39,24 @@ public class CustomerResource {
@GZIP
@GET
@Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(JSON_OUT)
@Operation(summary = "Get customer list")
@ApiResponse(responseCode = "200", description = "Successfully retrieved customer list", content = @Content(mediaType = JSON_OUT, array = @ArraySchema(schema = @Schema(implementation = CustomerListValue.class))))
public Response doAddCustomerPicture(@QueryParam("query") String query) {
LOG.debug("Query customers for query " + query);
var retVal = customerPictureService.getAll(query);
public Response doGetCustomerList(@QueryParam("query") String query, @QueryParam("startsWith") String startsWith) {
LOG.debug("Query customers for query " + query + " startsWith: " + startsWith);
var retVal = customerPictureService.getAll(query, startsWith);
return Response.ok().entity(retVal).build();
}
@GZIP
@GET
@Path("{id}")
@Produces(JSON_OUT)
@Operation(summary = "Get customer value")
@ApiResponse(responseCode = "200", description = "Successfully retrieved customer value", content = @Content(mediaType = JSON_OUT, array = @ArraySchema(schema = @Schema(implementation = CustomerValue.class))))
public Response doGetDetailCustomer(@PathParam("id") Long id) {
LOG.debug("Get Customer details for id " + id);
var retVal = customerPictureService.get(id);
return Response.ok().entity(retVal).build();
}
}

View File

@@ -0,0 +1,52 @@
package marketing.heyday.hartmann.fotodocumentation.rest;
import static marketing.heyday.hartmann.fotodocumentation.rest.jackson.ApplicationConfigApi.JSON_OUT;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.resteasy.annotations.GZIP;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.ejb.EJB;
import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Response;
import marketing.heyday.hartmann.fotodocumentation.core.service.PictureService;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.PictureValue;
/**
*
* <p>Copyright: Copyright (c) 2024</p>
* <p>Company: heyday Marketing GmbH</p>
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
* @version 1.0
*
* created: 21 Jan 2026
*/
@RequestScoped
@Path("picture")
public class PictureResource {
private static final Log LOG = LogFactory.getLog(PictureResource.class);
@EJB
private PictureService pictureService;
@GZIP
@GET
@Path("{id}")
@Produces(JSON_OUT)
@Operation(summary = "Get picture value")
@ApiResponse(responseCode = "200", description = "Successfully retrieved picture value", content = @Content(mediaType = JSON_OUT, array = @ArraySchema(schema = @Schema(implementation = PictureValue.class))))
public Response doGetDetailCustomer(@PathParam("id") Long id) {
LOG.debug("Get Picture details for id " + id);
var retVal = pictureService.get(id);
return Response.ok().entity(retVal).build();
}
}

View File

@@ -14,10 +14,7 @@ import io.swagger.v3.oas.annotations.servers.Server;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.MediaType;
import marketing.heyday.hartmann.fotodocumentation.rest.CustomerPictureResource;
import marketing.heyday.hartmann.fotodocumentation.rest.CustomerResource;
import marketing.heyday.hartmann.fotodocumentation.rest.LoginResource;
import marketing.heyday.hartmann.fotodocumentation.rest.MonitoringResource;
import marketing.heyday.hartmann.fotodocumentation.rest.*;
/**
*
@@ -48,6 +45,7 @@ public class ApplicationConfigApi extends Application {
retVal.add(MonitoringResource.class);
retVal.add(CustomerPictureResource.class);
retVal.add(CustomerResource.class);
retVal.add(PictureResource.class);
LOG.info("returning rest api classes " + retVal);
return retVal;
}

View File

@@ -1,6 +1,10 @@
package marketing.heyday.hartmann.fotodocumentation.rest.vo;
import java.util.Date;
import io.swagger.v3.oas.annotations.media.Schema;
import marketing.heyday.hartmann.fotodocumentation.core.model.Customer;
import marketing.heyday.hartmann.fotodocumentation.core.model.Picture;
/**
*
@@ -12,12 +16,14 @@ import marketing.heyday.hartmann.fotodocumentation.core.model.Customer;
* created: 19 Jan 2026
*/
public record CustomerListValue(String name, String customerNumber, int amountOfPicture) {
@Schema(name = "CustomerList")
public record CustomerListValue(Long id, String name, String customerNumber, Date lastUpdateDate) {
public static CustomerListValue builder(Customer customer) {
if (customer == null) {
return null;
}
return new CustomerListValue(customer.getName(), customer.getCustomerNumber(), customer.getPictures().size());
Date date = customer.getPictures().stream().map(Picture::getPictureDate).sorted((p1, p2) -> p2.compareTo(p1)).findFirst().orElse(null);
return new CustomerListValue(customer.getCustomerId(), customer.getName(), customer.getCustomerNumber(), date);
}
}

View File

@@ -2,6 +2,8 @@ package marketing.heyday.hartmann.fotodocumentation.rest.vo;
import java.util.Date;
import io.swagger.v3.oas.annotations.media.Schema;
/**
*
* <p>Copyright: Copyright (c) 2024</p>
@@ -11,7 +13,7 @@ import java.util.Date;
*
* created: 19 Jan 2026
*/
public record CustomerPictureValue(String username, String pharmacyName, String customerNumber, Date date, String comment, String base64String) {
@Schema(name = "CustomerPictureUpload")
public record CustomerPictureValue(String username, String pharmacyName, String customerNumber, Date date, String comment, String category, String base64String) {
}

View File

@@ -0,0 +1,27 @@
package marketing.heyday.hartmann.fotodocumentation.rest.vo;
import java.util.List;
import io.swagger.v3.oas.annotations.media.Schema;
import marketing.heyday.hartmann.fotodocumentation.core.model.Customer;
/**
*
* <p>Copyright: Copyright (c) 2024</p>
* <p>Company: heyday Marketing GmbH</p>
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
* @version 1.0
*
* created: 22 Jan 2026
*/
@Schema(name = "Customer")
public record CustomerValue(Long id, String name, String customerNumber, List<PictureValue> pictures) {
public static CustomerValue builder(Customer customer) {
if (customer == null) {
return null;
}
List<PictureValue> pictures = customer.getPictures().parallelStream().map(PictureValue::builder).filter(p -> p != null).toList();
return new CustomerValue(customer.getCustomerId(), customer.getName(), customer.getCustomerNumber(), pictures);
}
}

View File

@@ -0,0 +1,27 @@
package marketing.heyday.hartmann.fotodocumentation.rest.vo;
import java.util.Date;
import io.swagger.v3.oas.annotations.media.Schema;
import marketing.heyday.hartmann.fotodocumentation.core.model.Picture;
/**
*
* <p>Copyright: Copyright (c) 2024</p>
* <p>Company: heyday Marketing GmbH</p>
* @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
* @version 1.0
*
* created: 22 Jan 2026
*/
@Schema(name = "Picture")
public record PictureValue(Long id, String comment, String category, String image, Date pictureDate, String username) {
public static PictureValue builder(Picture picture) {
if (picture == null) {
return null;
}
return new PictureValue(picture.getPictureId(), picture.getComment(), picture.getCategory(), picture.getImage(), picture.getPictureDate(), picture.getUsername());
}
}

View File

@@ -0,0 +1,4 @@
-- picture
alter table picture add column category varchar(250);