elastic changes

This commit is contained in:
Efstratios Giannopoulos 2024-01-09 16:02:12 +02:00
parent 1f92872158
commit 59aae92a0e
6 changed files with 88 additions and 56 deletions

View File

@ -17,12 +17,12 @@ import java.util.UUID;
public interface DescriptionService {
Description persist(DescriptionPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException;
Description persistStatus(DescriptionStatusPersist model, FieldSet fields);
Description persist(DescriptionPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException;
Description persistStatus(DescriptionStatusPersist model, FieldSet fields) throws IOException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException, IOException;
void clone(UUID dmpId, UUID descriptionId) throws InvalidApplicationException;
void clone(UUID dmpId, UUID descriptionId) throws InvalidApplicationException, IOException;
ResponseEntity<byte[]> export(UUID id, String exportType) throws InvalidApplicationException, IOException;

View File

@ -37,6 +37,7 @@ import eu.eudat.model.persist.descriptionproperties.FieldPersist;
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
import eu.eudat.query.*;
import eu.eudat.service.elastic.ElasticService;
import eu.eudat.service.transformer.FileTransformerService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
@ -103,6 +104,8 @@ public class DescriptionServiceImpl implements DescriptionService {
private final NotificationProperties notificationProperties;
private final ElasticService elasticService;
@Autowired
public DescriptionServiceImpl(
@ -117,7 +120,7 @@ public class DescriptionServiceImpl implements DescriptionService {
QueryFactory queryFactory,
JsonHandlingService jsonHandlingService,
UserScope userScope,
XmlHandlingService xmlHandlingService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService) {
XmlHandlingService xmlHandlingService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
@ -133,12 +136,13 @@ public class DescriptionServiceImpl implements DescriptionService {
this.eventHandler = eventHandler;
this.notificationProperties = notificationProperties;
this.fileTransformerService = fileTransformerService;
this.elasticService = elasticService;
}
//region Persist
@Override
public Description persist(DescriptionPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
public Description persist(DescriptionPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException {
logger.debug(new MapLogEntry("persisting data dmp").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.EditDescription);
@ -195,6 +199,8 @@ public class DescriptionServiceImpl implements DescriptionService {
//this.deleteOldFilesAndAddNew(datasetWizardModel, userInfo); //TODO
this.eventBroker.emit(new DescriptionTouchedEvent(data.getId()));
this.elasticService.persistDescription(data);
return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Description._id), data);
}
@ -316,7 +322,7 @@ public class DescriptionServiceImpl implements DescriptionService {
}
@Override
public Description persistStatus(DescriptionStatusPersist model, FieldSet fields) {
public Description persistStatus(DescriptionStatusPersist model, FieldSet fields) throws IOException {
logger.debug(new MapLogEntry("persisting data dmp").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.EditDescription);
@ -337,6 +343,7 @@ public class DescriptionServiceImpl implements DescriptionService {
this.entityManager.flush();
this.elasticService.persistDescription(data);
this.eventBroker.emit(new DescriptionTouchedEvent(data.getId()));
}
return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Description._id), data);
@ -517,7 +524,7 @@ public class DescriptionServiceImpl implements DescriptionService {
//region clone
@Override
public void clone(UUID dmpId, UUID descriptionId) throws InvalidApplicationException {
public void clone(UUID dmpId, UUID descriptionId) throws InvalidApplicationException, IOException {
logger.debug("cloning description: {} with dmp: {}", descriptionId, dmpId);
this.authorizationService.authorizeForce(Permission.CloneDescription);
@ -576,6 +583,8 @@ public class DescriptionServiceImpl implements DescriptionService {
this.entityManager.flush();
this.elasticService.persistDescription(newDescription);
}
//endregion

View File

@ -23,21 +23,21 @@ import java.util.UUID;
public interface DmpService {
Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException;
Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException, IOException;
Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, TransformerException;
Dmp buildClone(CloneDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException;
Dmp buildClone(CloneDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, IOException;
List<DmpUser> assignUsers(UUID dmp, List<DmpUserPersist> model, FieldSet fields) throws InvalidApplicationException;
Dmp removeUser(DmpUserRemovePersist model, FieldSet fields) throws InvalidApplicationException;
List<DmpUser> assignUsers(UUID dmp, List<DmpUserPersist> model, FieldSet fields) throws InvalidApplicationException, IOException;
Dmp removeUser(DmpUserRemovePersist model, FieldSet fields) throws InvalidApplicationException, IOException;
ResponseEntity<byte[]> export(UUID id, String exportType) throws InvalidApplicationException, IOException;
void inviteUsers(UUID id, DmpUserInvitePersist model) throws InvalidApplicationException, JAXBException;
void inviteUsers(UUID id, DmpUserInvitePersist model) throws InvalidApplicationException, JAXBException, IOException;
void dmpInvitationAccept(String token) throws InvalidApplicationException;
void dmpInvitationAccept(String token) throws InvalidApplicationException, IOException;
}

View File

@ -42,6 +42,7 @@ import eu.eudat.model.persist.referencedefinition.FieldPersist;
import eu.eudat.query.*;
import eu.eudat.service.actionconfirmation.ActionConfirmationService;
import eu.eudat.service.description.DescriptionService;
import eu.eudat.service.elastic.ElasticService;
import eu.eudat.service.transformer.FileTransformerService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
@ -117,6 +118,8 @@ public class DmpServiceImpl implements DmpService {
private final ValidatorFactory validatorFactory;
private final ElasticService elasticService;
@Autowired
public DmpServiceImpl(
EntityManager entityManager,
@ -129,7 +132,7 @@ public class DmpServiceImpl implements DmpService {
MessageSource messageSource,
XmlHandlingService xmlHandlingService,
JsonHandlingService jsonHandlingService,
UserScope userScope, EventBroker eventBroker, DescriptionService descriptionService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, ActionConfirmationService actionConfirmationService, FileTransformerService fileTransformerService, ValidatorFactory validatorFactory) {
UserScope userScope, EventBroker eventBroker, DescriptionService descriptionService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, ActionConfirmationService actionConfirmationService, FileTransformerService fileTransformerService, ValidatorFactory validatorFactory, ElasticService elasticService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
@ -148,9 +151,10 @@ public class DmpServiceImpl implements DmpService {
this.notificationProperties = notificationProperties;
this.actionConfirmationService = actionConfirmationService;
this.validatorFactory = validatorFactory;
this.elasticService = elasticService;
}
public Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
public Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException {
this.authorizationService.authorizeForce(Permission.EditDmp);
DmpEntity data = this.patchAndSave(model);
@ -163,6 +167,8 @@ public class DmpServiceImpl implements DmpService {
this.sendNotification(data);
this.elasticService.persistDmp(data);
return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data);
}
@ -229,7 +235,7 @@ public class DmpServiceImpl implements DmpService {
}
@Override
public Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
public Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, IOException, TransformerException {
this.authorizationService.authorizeForce(Permission.CreateNewVersionDmp);
DmpEntity oldDmpEntity = this.entityManager.find(DmpEntity.class, model.getId());
@ -321,11 +327,16 @@ public class DmpServiceImpl implements DmpService {
this.entityManager.flush();
this.elasticService.persistDmp(oldDmpEntity);
this.elasticService.persistDmp(newDmp);
return this.builderFactory.builder(DmpBuilder.class).build(BaseFieldSet.build(fields, Dmp._id), newDmp);
}
@Override
public Dmp buildClone(CloneDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException {
public Dmp buildClone(CloneDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, IOException {
this.authorizationService.authorizeForce(Permission.CloneDmp);
DmpEntity existingDmpEntity = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(model.getId()).firstAs(fields);
@ -400,26 +411,32 @@ public class DmpServiceImpl implements DmpService {
this.entityManager.flush();
this.elasticService.persistDmp(newDmp);
DmpEntity resultingDmpEntity = this.queryFactory.query(DmpQuery.class).ids(newDmp.getId()).firstAs(fields);
return this.builderFactory.builder(DmpBuilder.class).build(fields, resultingDmpEntity);
}
@Override
public List<DmpUser> assignUsers(UUID dmp, List<DmpUserPersist> model, FieldSet fieldSet) throws InvalidApplicationException {
public List<DmpUser> assignUsers(UUID dmpId, List<DmpUserPersist> model, FieldSet fieldSet) throws InvalidApplicationException, IOException {
this.authorizationService.authorizeForce(Permission.AssignDmpUsers);
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, dmpId);
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
List<DmpUserEntity> existingUsers = this.queryFactory.query(DmpUserQuery.class)
.dmpIds(dmp)
.dmpIds(dmpId)
.isActives(IsActive.Active)
.collect();
List<UUID> updatedCreatedIds = new ArrayList<>();
for (DmpUserPersist dmpUser : model) {
DmpUserEntity dmpUserEntity = existingUsers.stream().filter(x-> x.getDmpId().equals(dmp) && x.getUserId().equals(dmpUser.getUser()) && x.getRole().equals(dmpUser.getRole())).findFirst().orElse(null);
DmpUserEntity dmpUserEntity = existingUsers.stream().filter(x-> x.getDmpId().equals(dmpId) && x.getUserId().equals(dmpUser.getUser()) && x.getRole().equals(dmpUser.getRole())).findFirst().orElse(null);
if (dmpUserEntity == null){
dmpUserEntity = new DmpUserEntity();
dmpUserEntity.setId(UUID.randomUUID());
dmpUserEntity.setDmpId(dmp);
dmpUserEntity.setDmpId(dmpId);
dmpUserEntity.setUserId(dmpUser.getUser());
dmpUserEntity.setRole(dmpUser.getRole());
dmpUserEntity.setCreatedAt(Instant.now());
@ -436,14 +453,16 @@ public class DmpServiceImpl implements DmpService {
this.entityManager.flush();
List<DmpUserEntity> persisted = this.queryFactory.query(DmpUserQuery.class)
.dmpIds(dmp)
.dmpIds(dmpId)
.isActives(IsActive.Active)
.collect();
this.elasticService.persistDmp(dmpEntity);
return this.builderFactory.builder(DmpUserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fieldSet, DmpUser._id, DmpUser._hash), persisted);
}
@Override
public Dmp removeUser(DmpUserRemovePersist model, FieldSet fields) throws InvalidApplicationException {
public Dmp removeUser(DmpUserRemovePersist model, FieldSet fields) throws InvalidApplicationException, IOException {
this.authorizationService.authorizeForce(Permission.AssignDmpUsers);
DmpEntity data = this.entityManager.find(DmpEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
@ -456,6 +475,10 @@ public class DmpServiceImpl implements DmpService {
this.entityManager.flush();
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, model.getDmpId());
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.elasticService.persistDmp(dmpEntity);
return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data);
}
@ -688,7 +711,7 @@ public class DmpServiceImpl implements DmpService {
}
// invites
public void inviteUsers(UUID id, DmpUserInvitePersist model) throws InvalidApplicationException, JAXBException {
public void inviteUsers(UUID id, DmpUserInvitePersist model) throws InvalidApplicationException, JAXBException, IOException {
this.authorizationService.authorizeForce(Permission.InviteDmpUsers);
@ -774,7 +797,7 @@ public class DmpServiceImpl implements DmpService {
}
public void dmpInvitationAccept(String token) throws InvalidApplicationException {
public void dmpInvitationAccept(String token) throws InvalidApplicationException, IOException {
ActionConfirmationEntity action = this.queryFactory.query(ActionConfirmationQuery.class).tokens(token).types(ActionConfirmationType.DmpInvitation).isActive(IsActive.Active).first();
if (action == null){

View File

@ -149,7 +149,7 @@ public class DescriptionController {
@PostMapping("persist")
@Transactional
@ValidationFilterAnnotation(validator = DescriptionPersist.DescriptionPersistValidator.ValidatorName, argumentName = "model")
public Description persist(@RequestBody DescriptionPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
public Description persist(@RequestBody DescriptionPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException {
logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Description persisted = this.descriptionService.persist(model, fieldSet);
@ -164,7 +164,7 @@ public class DescriptionController {
@PostMapping("persist-status")
@Transactional
@ValidationFilterAnnotation(validator = DescriptionStatusPersist.DescriptionStatusPersistValidator.ValidatorName, argumentName = "model")
public Description persistStatus(@RequestBody DescriptionStatusPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
public Description persistStatus(@RequestBody DescriptionStatusPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, IOException {
logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Description persisted = this.descriptionService.persistStatus(model, fieldSet);

View File

@ -134,7 +134,7 @@ public class DmpController {
@PostMapping("persist")
@Transactional
@ValidationFilterAnnotation(validator = DmpPersist.DmpPersistValidator.ValidatorName, argumentName = "model")
public Dmp Persist(@RequestBody DmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
public Dmp Persist(@RequestBody DmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, IOException {
logger.debug(new MapLogEntry("persisting" + Dmp.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Dmp persisted = this.dmpService.persist(model, fieldSet);
@ -160,7 +160,7 @@ public class DmpController {
@PostMapping("clone")
@Transactional
@ValidationFilterAnnotation(validator = CloneDmpPersist.CloneDmpPersistValidator.ValidatorName, argumentName = "model")
public Dmp buildClone(@RequestBody CloneDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
public Dmp buildClone(@RequestBody CloneDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, IOException {
logger.debug(new MapLogEntry("clone" + Dmp.class.getSimpleName()).And("model", model).And("fields", fieldSet));
this.censorFactory.censor(DmpCensor.class).censor(fieldSet, null);
@ -178,7 +178,7 @@ public class DmpController {
@PostMapping("new-version")
@Transactional
@ValidationFilterAnnotation(validator = NewVersionDmpPersist.NewVersionDmpPersistValidator.ValidatorName, argumentName = "model")
public Dmp createNewVersion(@RequestBody NewVersionDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, JsonProcessingException, TransformerException, InvalidApplicationException, ParserConfigurationException {
public Dmp createNewVersion(@RequestBody NewVersionDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, IOException, TransformerException, InvalidApplicationException, ParserConfigurationException {
logger.debug(new MapLogEntry("persisting" + NewVersionDmpPersist.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Dmp persisted = this.dmpService.createNewVersion(model, fieldSet);
@ -194,7 +194,7 @@ public class DmpController {
@PostMapping("{id}/assign-users")
@Transactional
@ValidationFilterAnnotation(validator = DmpUserPersist.DmpUserPersistValidator.ValidatorName, argumentName = "model")
public QueryResult<DmpUser> assignUsers(@PathVariable("id") UUID id, @RequestBody List<DmpUserPersist> model, FieldSet fieldSet) throws InvalidApplicationException {
public QueryResult<DmpUser> assignUsers(@PathVariable("id") UUID id, @RequestBody List<DmpUserPersist> model, FieldSet fieldSet) throws InvalidApplicationException, IOException {
logger.debug(new MapLogEntry("assigning users to dmp").And("model", model).And("fieldSet", fieldSet));
List<DmpUser> persisted = this.dmpService.assignUsers(id, model, fieldSet);
@ -210,7 +210,7 @@ public class DmpController {
@PostMapping("remove-user")
@Transactional
@ValidationFilterAnnotation(validator = DmpUserRemovePersist.DmpUserRemovePersistValidator.ValidatorName, argumentName = "model")
public QueryResult<Dmp> removeUser(@RequestBody DmpUserRemovePersist model, FieldSet fieldSet) throws InvalidApplicationException {
public QueryResult<Dmp> removeUser(@RequestBody DmpUserRemovePersist model, FieldSet fieldSet) throws InvalidApplicationException, IOException {
logger.debug(new MapLogEntry("remove user from dmp").And("model", model).And("fieldSet", fieldSet));
Dmp persisted = this.dmpService.removeUser(model, fieldSet);
@ -233,7 +233,7 @@ public class DmpController {
@PostMapping("{id}/invite-users")
@Transactional
@ValidationFilterAnnotation(validator = DmpUserInvitePersist.DmpUserInvitePersistValidator.ValidatorName, argumentName = "model")
public ResponseEntity<ResponseItem<String>> inviteUsers(@PathVariable("id") UUID id, @RequestBody DmpUserInvitePersist model) throws InvalidApplicationException, JAXBException {
public ResponseEntity<ResponseItem<String>> inviteUsers(@PathVariable("id") UUID id, @RequestBody DmpUserInvitePersist model) throws InvalidApplicationException, JAXBException, IOException {
logger.debug(new MapLogEntry("inviting users to dmp").And("model", model));
this.dmpService.inviteUsers(id, model);
@ -247,7 +247,7 @@ public class DmpController {
@GetMapping("{id}/token/{token}/invite-accept")
@Transactional
public ResponseEntity<ResponseItem<String>> acceptInvitation(@PathVariable("id") UUID id, @PathVariable("token") String token) throws InvalidApplicationException, JAXBException {
public ResponseEntity<ResponseItem<String>> acceptInvitation(@PathVariable("id") UUID id, @PathVariable("token") String token) throws InvalidApplicationException, JAXBException, IOException {
logger.debug(new MapLogEntry("inviting users to dmp").And("id", id));
this.dmpService.dmpInvitationAccept(token);