Added controller for EntityDoi entity

This commit is contained in:
Thomas Georgios Giannos 2023-10-19 17:48:41 +03:00
parent 727702023f
commit 2a4e61f08f
3 changed files with 151 additions and 6 deletions

View File

@ -5,8 +5,19 @@ import gr.cite.tools.logging.EventId;
public class AuditableAction {
public static final EventId DescriptionTemplateType_Query = new EventId(1000, "DescriptionTemplateType_Query");
public static final EventId DescriptionTemplateType_Lookup = new EventId(1001, "DescriptionTemplateType_Lookup");
public static final EventId DescriptionTemplateType_Persist = new EventId(1002, "DescriptionTemplateType_Persist");
public static final EventId DescriptionTemplateType_Delete = new EventId(1003, "DescriptionTemplateType_Delete");
public static final EventId EntityDoi_Query = new EventId(2000, "EntityDoi_Query");
public static final EventId EntityDoi_Lookup = new EventId(2001, "EntityDoi_Lookup");
public static final EventId EntityDoi_Persist = new EventId(2002, "EntityDoi_Persist");
public static final EventId EntityDoi_Delete = new EventId(2003, "EntityDoi_Delete");
}

View File

@ -23,7 +23,6 @@ import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.transaction.annotation.Transactional;
@ -35,18 +34,23 @@ import java.util.*;
@RestController
@CrossOrigin
@RequestMapping(path = "api/description-template-type")
public class DescriptionTemplateTypeV2Controller {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeV2Controller.class));
public class DescriptionTemplateTypeController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeController.class));
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
@Autowired
public DescriptionTemplateTypeV2Controller(
public DescriptionTemplateTypeController(
BuilderFactory builderFactory,
AuditService auditService,
DescriptionTemplateTypeService descriptionTemplateTypeService,
@ -87,7 +91,8 @@ public class DescriptionTemplateTypeV2Controller {
DescriptionTemplateTypeQuery query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
DescriptionTemplateType model = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.DescriptionTemplateType_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),

View File

@ -0,0 +1,129 @@
package eu.eudat.controllers.v2;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.model.DescriptionTemplateType;
import eu.eudat.model.EntityDoi;
import eu.eudat.model.builder.EntityDoiBuilder;
import eu.eudat.model.censorship.EntityDoiCensor;
import eu.eudat.model.persist.EntityDoiPersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.query.EntityDoiQuery;
import eu.eudat.query.lookup.EntityDoiLookup;
import eu.eudat.service.EntityDoiService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException;
import java.util.*;
@RestController
@CrossOrigin
@RequestMapping(path = "api/entity-doi")
public class EntityDoiController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeController.class));
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final EntityDoiService entityDoiService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
public EntityDoiController(
BuilderFactory builderFactory,
AuditService auditService,
EntityDoiService entityDoiService,
CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource) {
this.builderFactory = builderFactory;
this.auditService = auditService;
this.entityDoiService = entityDoiService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
this.messageSource = messageSource;
}
@PostMapping("query")
public QueryResult<EntityDoi> Query(@RequestBody EntityDoiLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", EntityDoi.class.getSimpleName());
this.censorFactory.censor(EntityDoiCensor.class).censor(lookup.getProject(), null);
EntityDoiQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
List<EntityDoiEntity> data = query.collectAs(lookup.getProject());
List<EntityDoi> models = this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.EntityDoi_Query, "lookup", lookup);
return new QueryResult<>(models, count);
}
@GetMapping("{id}")
public EntityDoi Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + EntityDoi.class.getSimpleName()).And("id", id).And("fields", fieldSet));
this.censorFactory.censor(EntityDoiCensor.class).censor(fieldSet, null);
EntityDoiQuery query = this.queryFactory.query(EntityDoiQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
EntityDoi model = this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, EntityDoi.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.EntityDoi_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return model;
}
@PostMapping("persist")
@Transactional
public EntityDoi Persist(@MyValidate @RequestBody EntityDoiPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
EntityDoi persisted = this.entityDoiService.persist(model, fieldSet);
this.auditService.track(AuditableAction.EntityDoi_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return persisted;
}
@DeleteMapping("{id}")
@Transactional
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + EntityDoi.class.getSimpleName()).And("id", id));
this.entityDoiService.deleteAndSave(id);
this.auditService.track(AuditableAction.DescriptionTemplateType_Delete, "id", id);
}
}