Commit 3374daa7 authored by Aleksandr Ivanov's avatar Aleksandr Ivanov

fixed

parent 45fd8bc2
......@@ -541,4 +541,19 @@ public class InfoSystem {
}
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InfoSystem that = (InfoSystem) o;
return id != null ? id.equals(that.id) : that.id == null;
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
}
......@@ -18,6 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import static ee.ria.riha.conf.ApplicationProperties.API_V1_PREFIX;
import static java.util.stream.Collectors.toList;
......@@ -53,6 +56,46 @@ public class InfoSystemController {
infoSystemService.list(pageable, filterable),
infoSystemModelMapper));
}
@GetMapping("/autocomplete")
@ApiOperation("List all existing information systems for autocomplete")
@ApiPageableAndFilterableParams
public ResponseEntity autocomplete(Pageable pageable, Filterable filterable) {
// search for exact matches
PagedResponse<InfoSystem> exactMatches = infoSystemService.list(pageable, createExactMatchFilterFromILikeFilter(filterable));
if (exactMatches != null && exactMatches.getTotalElements() >= pageable.getPageSize()) {
// there are more exact matches than requested.
return ResponseEntity.ok(createPagedModel(exactMatches, infoSystemModelMapper));
} else if (exactMatches != null && exactMatches.getTotalElements() < pageable.getPageSize()) {
// there are some exact matches, need to fetch fuzzy matches
LinkedHashSet<InfoSystem> joinedList = new LinkedHashSet<>(exactMatches.getContent());
PagedResponse<InfoSystem> fuzzyMatches = infoSystemService.list(pageable, filterable);
if (fuzzyMatches != null && fuzzyMatches.getContent() != null) {
joinedList.addAll(fuzzyMatches.getContent());
}
return ResponseEntity.ok(createPagedModel(
new PagedResponse<>(
pageable,
joinedList.size(),
new ArrayList<>(joinedList)),
infoSystemModelMapper));
} else {
return ResponseEntity.ok(
createPagedModel(
infoSystemService.list(pageable, filterable),
infoSystemModelMapper));
}
}
private Filterable createExactMatchFilterFromILikeFilter(Filterable filterable) {
return new FilterRequest(
filterable.getFilter().replaceAll("%", ""),
filterable.getSort(),
filterable.getFields());
}
@GetMapping(path = "/data-objects")
@ApiOperation("List all existing information systems data objects")
......
......@@ -26,7 +26,7 @@
<option *ngFor="let type of generalHelperService.toArray(classifiers.relation_type)" [value]="type.code" selected>{{ type.value }}</option>
</select>
</div>
<div class="form-group row">
<div class="form-group row margin-top-90">
<div class="col-12">
<button class="btn btn-success pull-right" (click)="addRelation(addForm)"><i class="fa fa-plus fa-fw" aria-hidden="true"></i>&nbsp;Salvesta seos</button>
</div>
......
......@@ -7,7 +7,6 @@ import {HttpClient, HttpParams} from '@angular/common/http';
import {System} from "../models/system";
import {SystemIssue} from "../models/system-issue";
import {SystemRelation} from "../models/system-relation";
import {SystemIssueReply} from "../models/system-issue-reply";
import {environment} from "../../environments/environment";
@Injectable()
......@@ -198,7 +197,7 @@ export class SystemsService {
params = params.set('size', '10');
const urlToUse = url || this.systemsUrl;
const urlToUse = url || (this.systemsUrl + "/autocomplete");
return this.http.get<any>(urlToUse, {
params: params
......
......@@ -22,3 +22,7 @@
.margin-right-20 {
margin-right: 20px;
}
.margin-top-90 {
margin-top: 90px;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment