128 lines
5.9 KiB
Java
128 lines
5.9 KiB
Java
package eu.eudat.controllers.v2;
|
|
|
|
import eu.eudat.audit.AuditableAction;
|
|
import eu.eudat.authorization.AuthorizationFlags;
|
|
import eu.eudat.data.DmpBlueprintEntity;
|
|
import eu.eudat.model.DmpBlueprint;
|
|
import eu.eudat.model.builder.DmpBlueprintBuilder;
|
|
import eu.eudat.model.censorship.DmpBlueprintCensor;
|
|
import eu.eudat.model.result.QueryResult;
|
|
import eu.eudat.query.DmpBlueprintQuery;
|
|
import eu.eudat.query.lookup.DmpBlueprintLookup;
|
|
import eu.eudat.service.dmpblueprint.DmpBlueprintService;
|
|
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 jakarta.transaction.Transactional;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.context.MessageSource;
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.management.InvalidApplicationException;
|
|
import java.util.*;
|
|
|
|
@RestController
|
|
@RequestMapping(path = "api/dmp-blueprint")
|
|
public class DmpBlueprintController {
|
|
|
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintController.class));
|
|
|
|
private final BuilderFactory builderFactory;
|
|
|
|
private final AuditService auditService;
|
|
|
|
private final DmpBlueprintService dmpBlueprintService;
|
|
|
|
private final CensorFactory censorFactory;
|
|
|
|
private final QueryFactory queryFactory;
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
public DmpBlueprintController(
|
|
BuilderFactory builderFactory,
|
|
AuditService auditService,
|
|
DmpBlueprintService dmpBlueprintService,
|
|
CensorFactory censorFactory,
|
|
QueryFactory queryFactory,
|
|
MessageSource messageSource) {
|
|
this.builderFactory = builderFactory;
|
|
this.auditService = auditService;
|
|
this.dmpBlueprintService = dmpBlueprintService;
|
|
this.censorFactory = censorFactory;
|
|
this.queryFactory = queryFactory;
|
|
this.messageSource = messageSource;
|
|
}
|
|
|
|
@PostMapping("query")
|
|
public QueryResult<DmpBlueprint> Query(@RequestBody DmpBlueprintLookup lookup) throws MyApplicationException, MyForbiddenException {
|
|
logger.debug("querying {}", DmpBlueprint.class.getSimpleName());
|
|
|
|
this.censorFactory.censor(DmpBlueprintCensor.class).censor(lookup.getProject(), null);
|
|
|
|
DmpBlueprintQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
|
|
|
|
List<DmpBlueprintEntity> data = query.collectAs(lookup.getProject());
|
|
List<DmpBlueprint> models = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data);
|
|
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
|
|
|
|
this.auditService.track(AuditableAction.DmpBlueprint_Query, "lookup", lookup);
|
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
|
|
|
return new QueryResult<>(models, count);
|
|
}
|
|
|
|
@GetMapping("{id}")
|
|
public DmpBlueprint Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
|
|
logger.debug(new MapLogEntry("retrieving" + DmpBlueprint.class.getSimpleName()).And("id", id).And("fields", fieldSet));
|
|
|
|
this.censorFactory.censor(DmpBlueprintCensor.class).censor(fieldSet, null);
|
|
|
|
DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
|
|
DmpBlueprint model = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
|
|
if (model == null)
|
|
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
|
|
|
this.auditService.track(AuditableAction.DmpBlueprint_Lookup, Map.ofEntries(
|
|
new AbstractMap.SimpleEntry<String, Object>("id", id),
|
|
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
|
));
|
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
|
|
|
return model;
|
|
}
|
|
|
|
// @PostMapping("persist")
|
|
// @Transactional
|
|
// public DmpBlueprint Persist(@MyValidate @RequestBody DmpBlueprintPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
|
|
// logger.debug(new MapLogEntry("persisting" + DmpBlueprint.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
|
|
// DmpBlueprint persisted = this.dmpBlueprintService.persist(model, fieldSet);
|
|
//
|
|
// this.auditService.track(AuditableAction.DmpBlueprint_Persist, Map.ofEntries(
|
|
// new AbstractMap.SimpleEntry<String, Object>("model", model),
|
|
// new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
|
// ));
|
|
// //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
|
// return persisted;
|
|
// }
|
|
|
|
@DeleteMapping("{id}")
|
|
@Transactional
|
|
public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
|
|
logger.debug(new MapLogEntry("retrieving" + DmpBlueprint.class.getSimpleName()).And("id", id));
|
|
|
|
this.dmpBlueprintService.deleteAndSave(id);
|
|
|
|
this.auditService.track(AuditableAction.DmpBlueprint_Delete, "id", id);
|
|
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
|
}
|
|
}
|