Fix issue with elasticsearch inconsistencies

This commit is contained in:
George Kalampokis 2021-11-23 14:05:57 +02:00
parent e8d71a8f66
commit e546362f58
4 changed files with 44 additions and 11 deletions

View File

@ -39,11 +39,11 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.persistence.NoResultException;
import javax.transaction.Transactional;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -121,7 +121,7 @@ public class Datasets extends BaseController {
// }
}
@javax.transaction.Transactional
@Transactional
@RequestMapping(method = RequestMethod.GET, value = {"{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException {
@ -246,7 +246,7 @@ public class Datasets extends BaseController {
* Data Management
* */
@javax.transaction.Transactional
@Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DatasetWizardModel>> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) throws Exception {
@ -262,7 +262,7 @@ public class Datasets extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message(this.getApiContext().getHelpersService().getMessageSource().getMessage("dataset.public", new Object[]{}, locale)));
}
@javax.transaction.Transactional
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Dataset>> delete(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
@ -270,7 +270,7 @@ public class Datasets extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Deleted"));
}
@javax.transaction.Transactional
@Transactional
@RequestMapping(method = RequestMethod.GET, value = {"/{id}/unlock"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Dataset>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
@ -318,7 +318,7 @@ public class Datasets extends BaseController {
* Data Index
* */
@javax.transaction.Transactional
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/index"})
public @ResponseBody
ResponseEntity<ResponseItem<Dataset>> generateIndex(Principal principal) throws Exception {
@ -326,7 +326,7 @@ public class Datasets extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Generated").payload(null));
}
@javax.transaction.Transactional
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"/index"})
public @ResponseBody
ResponseEntity<ResponseItem<Dataset>> clearIndex(Principal principal) throws Exception {

View File

@ -599,6 +599,9 @@ public class DataManagementPlanManager {
datasets.add(dataset);
}
UUID dmpId = result.getId();
result.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.updateIndex(result);
return result;
@ -710,6 +713,8 @@ public class DataManagementPlanManager {
DatasetCriteria criteria1 = new DatasetCriteria();
criteria1.setDmpIds(Collections.singletonList(newDmp.getId()));
newDmp.setDataset(new HashSet<>(databaseRepository.getDatasetDao().getWithCriteria(criteria1).toList()));
UUID dmpId = newDmp.getId();
newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.updateIndex(newDmp);
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
@ -740,12 +745,16 @@ public class DataManagementPlanManager {
}
oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
UUID dmpId = oldDmp.getId();
oldDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.updateIndex(oldDmp);
DataManagementPlanCriteria criteria1 = new DataManagementPlanCriteria();
criteria1.setAllVersions(true);
criteria1.setGroupIds(Collections.singletonList(oldDmp.getGroupId()));
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria1).toList().forEach(dmp -> {
try {
UUID tdmpId = dmp.getId();
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tdmpId)).toList()));
this.updateIndex(dmp);
} catch (IOException e) {
logger.error(e.getMessage(), e);
@ -757,6 +766,7 @@ public class DataManagementPlanManager {
if (elastic != null) {
tags = elastic.getTags();
}
dataset.setDmp(dmp);
this.datasetManager.updateTags(dataset, tags);
} catch (Exception e) {
logger.error(e.getMessage(), e);
@ -891,7 +901,8 @@ public class DataManagementPlanManager {
if (elastic != null) {
tags = elastic.getTags();
}
UUID dmpId = tempDataset.getDmp().getId();
tempDataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.datasetManager.updateTags(tempDataset, tags);
} catch (Exception e) {
logger.error(e.getMessage(), e);
@ -1008,6 +1019,8 @@ public class DataManagementPlanManager {
throw new Exception("DMP is not finalized");
dmp.setPublic(true);
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
UUID dmpId = dmp.getId();
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.updateIndex(dmp);
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.PUBLISHED);
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
@ -1021,6 +1034,8 @@ public class DataManagementPlanManager {
if (elastic != null) {
tags = elastic.getTags();
}
UUID tmdmpId = dataset.getDmp().getId();
dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tmdmpId)).toList()));
this.datasetManager.updateTags(dataset, tags);
metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.PUBLISHED);
} catch (Exception e) {
@ -1106,6 +1121,8 @@ public class DataManagementPlanManager {
}
dmp.setStatus(DMP.DMPStatus.FINALISED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
UUID dmpId = dmp.getId();
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.updateIndex(dmp);
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
sendNotification(dmp, user, NotificationType.DMP_FINALISED);
@ -1124,6 +1141,8 @@ public class DataManagementPlanManager {
throw new Exception("DMP is already Active");
dmp.setStatus(DMP.DMPStatus.ACTIVE.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
UUID dmpId = dmp.getId();
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.updateIndex(dmp);
metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.FINALIZED);
metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
@ -1733,6 +1752,8 @@ public class DataManagementPlanManager {
databaseRepository.getDmpDao().createOrUpdate(dmp);
assignUser(dmp, me);
if (this.apiContext.getOperationsContext().getElasticRepository().getDmpRepository().getClient() != null) {
UUID dmpId = dmp.getId();
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.updateIndex(dmp);
}
dmp.getDataset().forEach(dataset -> {
@ -1755,13 +1776,13 @@ public class DataManagementPlanManager {
try {
List<Tag> tags = new ArrayList<>();
eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString());
DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset);
if (elastic != null) {
tags = elastic.getTags();
DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset);
datasetWizardModel.setTags(tags);
datasetManager.getTagsFromProfile(datasetWizardModel, dataset);
datasetManager.updateTags(dataset, datasetWizardModel.getTags());
}
datasetManager.getTagsFromProfile(datasetWizardModel, dataset);
datasetManager.updateTags(dataset, datasetWizardModel.getTags());
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
@ -1824,6 +1845,9 @@ public class DataManagementPlanManager {
try {
if (dmp.getUsers() != null) {
logger.info(dmp.getUsers().toString());
} else {
UUID dmpId = dmp.getId();
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
}
this.updateIndex(dmp);
} catch (IOException e) {
@ -1841,6 +1865,8 @@ public class DataManagementPlanManager {
if (elastic != null) {
tags = elastic.getTags();
}
UUID dmpId = dataset.getDmp().getId();
dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.datasetManager.updateTags(dataset, tags);
} catch (Exception e) {
logger.error(e.getMessage(), e);
@ -1861,6 +1887,8 @@ public class DataManagementPlanManager {
List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable().toList();
dmps.forEach(dmp -> {
try {
UUID dmpId = dmp.getId();
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
this.updateIndex(dmp);
} catch (IOException e) {
logger.error(e.getMessage(), e);

View File

@ -598,6 +598,8 @@ public class DatasetManager {
}
dataset1.setProfile(this.apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(datasetWizardModel.getProfile().getId()));
// datasetWizardModel.setDatasetProfileDefinition(getPagedProfile(datasetWizardModel, dataset1));
UUID dmpId = dataset1.getDmp().getId();
dataset1.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
updateTags(dataset1, datasetWizardModel.getTags());
if (sendNotification) {
if (dataset1.getStatus() != Dataset.Status.FINALISED.getValue()) {
@ -1014,6 +1016,8 @@ public class DatasetManager {
datasetEntities.forEach(datasetEntity -> {
try {
eu.eudat.elastic.entities.Dataset dataset = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(datasetEntity.getId().toString());
UUID dmpId = datasetEntity.getDmp().getId();
datasetEntity.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
updateTags(datasetEntity, dataset != null ? dataset.getTags() : null);
} catch (Exception e) {
logger.error(e.getMessage(), e);

View File

@ -67,6 +67,7 @@ public class DmpMapper {
if (dataset1 != null) {
tags = dataset1.getTags();
}
dataset.setDmp(dmp);
return datasetMapper.toElastic(dataset, tags);
} catch (Exception e) {
logger.error(e.getMessage(), e);