2024-02-22 18:01:23 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import eu.eudat.audit.AuditableAction;
|
|
|
|
import eu.eudat.authorization.AuthorizationFlags;
|
|
|
|
import eu.eudat.data.PrefillingSourceEntity;
|
2024-02-29 10:46:59 +01:00
|
|
|
import eu.eudat.model.Description;
|
|
|
|
import eu.eudat.model.Prefilling;
|
2024-02-22 18:01:23 +01:00
|
|
|
import eu.eudat.model.PrefillingSource;
|
|
|
|
import eu.eudat.model.builder.PrefillingSourceBuilder;
|
2024-02-29 10:46:59 +01:00
|
|
|
import eu.eudat.model.censorship.DescriptionCensor;
|
2024-03-05 12:41:58 +01:00
|
|
|
import eu.eudat.model.censorship.PrefillingCensor;
|
2024-02-22 18:01:23 +01:00
|
|
|
import eu.eudat.model.censorship.PrefillingSourceCensor;
|
2024-03-05 12:41:58 +01:00
|
|
|
import eu.eudat.model.persist.PrefillingSearchRequest;
|
2024-02-29 10:46:59 +01:00
|
|
|
import eu.eudat.model.persist.DescriptionProfilingRequest;
|
2024-02-22 18:01:23 +01:00
|
|
|
import eu.eudat.model.persist.PrefillingSourcePersist;
|
|
|
|
import eu.eudat.model.result.QueryResult;
|
|
|
|
import eu.eudat.query.PrefillingSourceQuery;
|
|
|
|
import eu.eudat.query.lookup.PrefillingSourceLookup;
|
|
|
|
import eu.eudat.service.prefillingsource.PrefillingSourceService;
|
|
|
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
|
|
|
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.ValidationFilterAnnotation;
|
|
|
|
import jakarta.transaction.Transactional;
|
|
|
|
import jakarta.xml.bind.JAXBException;
|
|
|
|
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.web.bind.annotation.*;
|
2024-02-29 10:46:59 +01:00
|
|
|
import org.xml.sax.SAXException;
|
2024-02-22 18:01:23 +01:00
|
|
|
|
|
|
|
import javax.management.InvalidApplicationException;
|
2024-02-29 10:46:59 +01:00
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
import java.io.IOException;
|
2024-02-22 18:01:23 +01:00
|
|
|
import java.util.AbstractMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping(path = {"api/prefilling-source"})
|
|
|
|
public class PrefillingSourceController {
|
|
|
|
|
|
|
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PrefillingSourceController.class));
|
|
|
|
|
|
|
|
private final BuilderFactory builderFactory;
|
|
|
|
|
|
|
|
private final AuditService auditService;
|
|
|
|
|
|
|
|
private final CensorFactory censorFactory;
|
|
|
|
|
|
|
|
private final QueryFactory queryFactory;
|
|
|
|
|
|
|
|
private final MessageSource messageSource;
|
|
|
|
|
|
|
|
private final AuthorizationService authorizationService;
|
|
|
|
|
|
|
|
private final PrefillingSourceService prefillingSourceService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public PrefillingSourceController(
|
|
|
|
BuilderFactory builderFactory,
|
|
|
|
AuditService auditService,
|
|
|
|
CensorFactory censorFactory,
|
|
|
|
QueryFactory queryFactory,
|
|
|
|
MessageSource messageSource, AuthorizationService authorizationService, PrefillingSourceService prefillingSourceService) {
|
|
|
|
this.builderFactory = builderFactory;
|
|
|
|
this.auditService = auditService;
|
|
|
|
this.censorFactory = censorFactory;
|
|
|
|
this.queryFactory = queryFactory;
|
|
|
|
this.messageSource = messageSource;
|
|
|
|
this.authorizationService = authorizationService;
|
|
|
|
this.prefillingSourceService = prefillingSourceService;
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("query")
|
|
|
|
public QueryResult<PrefillingSource> query(@RequestBody PrefillingSourceLookup lookup) throws MyApplicationException, MyForbiddenException {
|
|
|
|
logger.debug("querying {}", PrefillingSource.class.getSimpleName());
|
|
|
|
|
|
|
|
this.censorFactory.censor(PrefillingSourceCensor.class).censor(lookup.getProject(), null);
|
|
|
|
|
2024-03-12 17:27:16 +01:00
|
|
|
PrefillingSourceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission);
|
2024-02-22 18:01:23 +01:00
|
|
|
List<PrefillingSourceEntity> data = query.collectAs(lookup.getProject());
|
2024-03-12 17:27:16 +01:00
|
|
|
List<PrefillingSource> models = this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data);
|
2024-02-22 18:01:23 +01:00
|
|
|
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
|
|
|
|
|
|
|
|
this.auditService.track(AuditableAction.PrefillingSource_Query, "lookup", lookup);
|
|
|
|
|
|
|
|
return new QueryResult<>(models, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("{id}")
|
|
|
|
public PrefillingSource get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
|
|
|
|
logger.debug(new MapLogEntry("retrieving" + PrefillingSource.class.getSimpleName()).And("id", id).And("fields", fieldSet));
|
|
|
|
|
|
|
|
this.censorFactory.censor(PrefillingSourceCensor.class).censor(fieldSet, null);
|
|
|
|
|
2024-03-12 17:27:16 +01:00
|
|
|
PrefillingSourceQuery query = this.queryFactory.query(PrefillingSourceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id);
|
|
|
|
PrefillingSource model = this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet));
|
2024-02-22 18:01:23 +01:00
|
|
|
if (model == null)
|
|
|
|
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
|
|
|
|
|
|
|
this.auditService.track(AuditableAction.PrefillingSource_Lookup, Map.ofEntries(
|
|
|
|
new AbstractMap.SimpleEntry<String, Object>("id", id),
|
|
|
|
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
|
|
|
));
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("persist")
|
|
|
|
@Transactional
|
|
|
|
@ValidationFilterAnnotation(validator = PrefillingSourcePersist.PrefillingSourcePersistValidator.ValidatorName, argumentName = "model")
|
|
|
|
public PrefillingSource persist(@RequestBody PrefillingSourcePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException {
|
|
|
|
logger.debug(new MapLogEntry("persisting" + PrefillingSource.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
|
|
|
|
this.censorFactory.censor(PrefillingSourceCensor.class).censor(fieldSet, null);
|
|
|
|
|
|
|
|
PrefillingSource persisted = this.prefillingSourceService.persist(model, fieldSet);
|
|
|
|
|
|
|
|
this.auditService.track(AuditableAction.PrefillingSource_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" + PrefillingSource.class.getSimpleName()).And("id", id));
|
|
|
|
|
|
|
|
this.prefillingSourceService.deleteAndSave(id);
|
|
|
|
|
|
|
|
this.auditService.track(AuditableAction.PrefillingSource_Delete, "id", id);
|
|
|
|
}
|
|
|
|
|
2024-03-05 12:41:58 +01:00
|
|
|
@PostMapping("search")
|
|
|
|
@ValidationFilterAnnotation(validator = PrefillingSearchRequest.PrefillingSearchRequestValidator.ValidatorName, argumentName = "model")
|
|
|
|
public List<Prefilling> search(@RequestBody PrefillingSearchRequest model) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
|
|
|
|
logger.debug(new MapLogEntry("searching" + Prefilling.class.getSimpleName()).And("model", model));
|
2024-02-29 10:46:59 +01:00
|
|
|
|
2024-03-05 12:41:58 +01:00
|
|
|
this.censorFactory.censor(PrefillingCensor.class).censor(null, null);
|
2024-02-29 10:46:59 +01:00
|
|
|
|
2024-03-05 12:41:58 +01:00
|
|
|
List<Prefilling> item = this.prefillingSourceService.searchPrefillings(model);
|
2024-02-29 10:46:59 +01:00
|
|
|
|
2024-03-01 17:45:32 +01:00
|
|
|
this.auditService.track(AuditableAction.PrefillingSource_Generate, Map.ofEntries(
|
2024-02-29 10:46:59 +01:00
|
|
|
new AbstractMap.SimpleEntry<String, Object>("model", model)
|
|
|
|
));
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2024-03-05 12:41:58 +01:00
|
|
|
@PostMapping("generate")
|
|
|
|
@ValidationFilterAnnotation(validator = DescriptionProfilingRequest.DescriptionProfilingRequestValidator.ValidatorName, argumentName = "model")
|
2024-04-01 17:36:03 +02:00
|
|
|
public Description generate(@RequestBody DescriptionProfilingRequest model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
|
2024-02-29 10:46:59 +01:00
|
|
|
logger.debug(new MapLogEntry("persisting" + Prefilling.class.getSimpleName()).And("model", model));
|
|
|
|
|
2024-03-05 12:41:58 +01:00
|
|
|
this.censorFactory.censor(DescriptionCensor.class).censor(fieldSet, null);
|
2024-02-29 10:46:59 +01:00
|
|
|
|
2024-03-05 12:41:58 +01:00
|
|
|
Description item = this.prefillingSourceService.getPrefilledDescription(model, fieldSet);
|
2024-02-29 10:46:59 +01:00
|
|
|
|
2024-03-05 12:41:58 +01:00
|
|
|
this.auditService.track(AuditableAction.PrefillingSource_Generate, Map.ofEntries(
|
2024-02-29 10:46:59 +01:00
|
|
|
new AbstractMap.SimpleEntry<String, Object>("model", model)
|
|
|
|
));
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2024-02-22 18:01:23 +01:00
|
|
|
}
|