First designs for ui

This commit is contained in:
verboomp
2026-01-27 09:57:53 +01:00
parent f48bfe2107
commit 3d456128b1
16 changed files with 487 additions and 155 deletions

View File

@@ -1,12 +1,17 @@
package marketing.heyday.hartmann.fotodocumentation.core.service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBContext;
import jakarta.ejb.SessionContext;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import marketing.heyday.hartmann.fotodocumentation.core.query.QueryService;
import marketing.heyday.hartmann.fotodocumentation.core.utils.StorageUtils.StorageState;
/**
*
@@ -19,7 +24,8 @@ import marketing.heyday.hartmann.fotodocumentation.core.query.QueryService;
*/
public abstract class AbstractService {
private static final Log LOG = LogFactory.getLog(AbstractService.class);
@Resource
protected EJBContext ejbContext;
@@ -31,5 +37,17 @@ public abstract class AbstractService {
@EJB
protected QueryService queryService;
protected <T> StorageState delete(Class<T> type, Long id) {
try {
T entity = entityManager.getReference(type, id);
entityManager.remove(entity);
entityManager.flush();
return StorageState.OK;
} catch (EntityNotFoundException e) {
LOG.warn("Failed to delete entity " + type + " not found " + id, e);
ejbContext.setRollbackOnly();
return StorageState.NOT_FOUND;
}
}
}

View File

@@ -4,7 +4,7 @@ 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;
import marketing.heyday.hartmann.fotodocumentation.core.utils.StorageUtils.StorageState;
/**
*
@@ -20,12 +20,7 @@ import marketing.heyday.hartmann.fotodocumentation.rest.vo.PictureValue;
@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);
public StorageState delete(Long id) {
return super.delete(Picture.class, id);
}
}

View File

@@ -0,0 +1,23 @@
package marketing.heyday.hartmann.fotodocumentation.core.utils;
/**
*
* <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: 27 Jan 2026
*/
public class StorageUtils {
public enum StorageState {
OK,
DUPLICATE,
FORBIDDEN,
NOT_FOUND,
ERROR,
;
}
}

View File

@@ -1,25 +1,20 @@
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.DELETE;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.ResponseBuilder;
import jakarta.ws.rs.core.Response.Status;
import marketing.heyday.hartmann.fotodocumentation.core.service.PictureService;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.PictureValue;
import marketing.heyday.hartmann.fotodocumentation.core.utils.StorageUtils.StorageState;
/**
*
@@ -38,15 +33,25 @@ public class PictureResource {
@EJB
private PictureService pictureService;
@GZIP
@GET
@DELETE
@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();
@Operation(summary = "Delete picture from database")
@ApiResponse(responseCode = "200", description = "Task successfully deleted")
@ApiResponse(responseCode = "404", description = "Task not found")
@ApiResponse(responseCode = "403", description = "Insufficient permissions")
public Response doDelete(@PathParam("id") Long id) {
LOG.debug("Delete picture with id " + id);
var state = pictureService.delete(id);
return deleteResponse(state).build();
}
protected ResponseBuilder deleteResponse(StorageState state) {
return switch(state) {
case OK -> Response.status(Status.OK);
case DUPLICATE -> Response.status(Status.CONFLICT);
case NOT_FOUND -> Response.status(Status.NOT_FOUND);
case FORBIDDEN -> Response.status(Status.FORBIDDEN);
default -> Response.status(Status.INTERNAL_SERVER_ERROR);
};
}
}