Fixes bug when ElasticSearch is down.
This commit is contained in:
parent
632577b171
commit
ab460fe5c4
|
@ -49,14 +49,22 @@ public class DatasetManager {
|
||||||
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
|
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
||||||
List<eu.eudat.elastic.entities.Dataset> datasets = apiContext.getOperationsContext().getDatasetRepository().exists() ?
|
List<eu.eudat.elastic.entities.Dataset> datasets;
|
||||||
|
try {
|
||||||
|
datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && apiContext.getOperationsContext().getDatasetRepository().exists() ?
|
||||||
apiContext.getOperationsContext().getDatasetRepository().query(datasetCriteria) : new LinkedList<>();
|
apiContext.getOperationsContext().getDatasetRepository().query(datasetCriteria) : new LinkedList<>();
|
||||||
|
}
|
||||||
|
catch (Exception ex){
|
||||||
|
datasets = null;
|
||||||
|
}
|
||||||
|
|
||||||
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||||
QueryableList<eu.eudat.data.entities.Dataset> items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
QueryableList<eu.eudat.data.entities.Dataset> items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));
|
||||||
if (datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()) {
|
if (datasets != null && datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()) {
|
||||||
if (!datasets.isEmpty())
|
if (!datasets.isEmpty()){
|
||||||
items.where((builder, root) -> root.get("id").in(datasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
||||||
|
items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
||||||
}
|
}
|
||||||
|
@ -81,14 +89,21 @@ public class DatasetManager {
|
||||||
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetPublicTableRequest datasetTableRequest, Principal principal) throws Exception {
|
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetPublicTableRequest datasetTableRequest, Principal principal) throws Exception {
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags());
|
||||||
List<eu.eudat.elastic.entities.Dataset> datasets = apiContext.getOperationsContext().getDatasetRepository().exists() ?
|
List<eu.eudat.elastic.entities.Dataset> datasets;
|
||||||
|
try{
|
||||||
|
datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && apiContext.getOperationsContext().getDatasetRepository().exists() ?
|
||||||
apiContext.getOperationsContext().getDatasetRepository().query(datasetCriteria) : new LinkedList<>();
|
apiContext.getOperationsContext().getDatasetRepository().query(datasetCriteria) : new LinkedList<>();
|
||||||
|
}
|
||||||
|
catch (Exception ex){
|
||||||
|
datasets = null;
|
||||||
|
}
|
||||||
datasetTableRequest.setQuery(apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)));
|
datasetTableRequest.setQuery(apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)));
|
||||||
QueryableList<Dataset> items = datasetTableRequest.applyCriteria();
|
QueryableList<Dataset> items = datasetTableRequest.applyCriteria();
|
||||||
if (datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()) {
|
if (datasets != null && datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()) {
|
||||||
if (!datasets.isEmpty())
|
if (!datasets.isEmpty()) {
|
||||||
items.where((builder, root) -> root.get("id").in(datasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
List<eu.eudat.elastic.entities.Dataset> finalDatasets = datasets;
|
||||||
|
items.where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()}));
|
||||||
}
|
}
|
||||||
|
@ -111,8 +126,14 @@ public class DatasetManager {
|
||||||
public DatasetWizardModel getSingle(DatasetDao datatasetRepository, DatasetRepository elasticDatasetRepository, String id) throws InstantiationException, IllegalAccessException, IOException {
|
public DatasetWizardModel getSingle(DatasetDao datatasetRepository, DatasetRepository elasticDatasetRepository, String id) throws InstantiationException, IllegalAccessException, IOException {
|
||||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||||
eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
||||||
eu.eudat.elastic.entities.Dataset datasetElastic = elasticDatasetRepository.exists() ?
|
eu.eudat.elastic.entities.Dataset datasetElastic;
|
||||||
|
try{
|
||||||
|
datasetElastic = elasticDatasetRepository.exists() ?
|
||||||
elasticDatasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
|
elasticDatasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
|
||||||
|
}
|
||||||
|
catch (Exception ex){
|
||||||
|
datasetElastic = new eu.eudat.elastic.entities.Dataset();
|
||||||
|
}
|
||||||
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
||||||
dataset.fromDataModel(datasetEntity);
|
dataset.fromDataModel(datasetEntity);
|
||||||
dataset.setTags(datasetElastic.getTags());
|
dataset.setTags(datasetElastic.getTags());
|
||||||
|
|
Loading…
Reference in New Issue