created paging for searchRegisteredRepositories - temporarily inactive
This commit is contained in:
parent
b533355c4f
commit
01ba340f47
|
@ -2,7 +2,6 @@ package eu.dnetlib.repo.manager.controllers;
|
|||
|
||||
import eu.dnetlib.repo.manager.service.PiWikService;
|
||||
import eu.dnetlib.repo.manager.service.RepositoryService;
|
||||
import eu.dnetlib.repo.manager.service.RepositoryServiceImpl;
|
||||
import io.micrometer.core.instrument.binder.jvm.DiskSpaceMetrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
|
||||
|
@ -13,7 +12,6 @@ import io.micrometer.prometheus.PrometheusConfig;
|
|||
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
||||
import io.prometheus.client.exporter.common.TextFormat;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.json.JSONException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
|
@ -43,6 +43,18 @@ public class Paging<T> {
|
|||
this.results = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static <K> Paging<K> of(Header header, List<K> results) {
|
||||
Paging<K> paging = new Paging<>();
|
||||
paging.setFrom(header.getPage() * header.getSize());
|
||||
paging.setTo(paging.getFrom() + header.getSize() - 1);
|
||||
if (paging.getTo() > header.getTotal()) {
|
||||
paging.setTo((int) header.getTotal() - 1);
|
||||
}
|
||||
paging.setTotal((int) header.getTotal());
|
||||
paging.setResults(results);
|
||||
return paging;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
@ -74,4 +86,4 @@ public class Paging<T> {
|
|||
public void setResults(List<T> results) {
|
||||
this.results = results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -277,7 +277,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
|
||||
LOGGER.debug("Searching registered repositories");
|
||||
|
||||
List<RepositorySnippet> resultSet = new ArrayList<>();
|
||||
Paging<RepositorySnippet> snippets = null;
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
|
||||
|
@ -290,15 +290,23 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|||
|
||||
try {
|
||||
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
||||
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
||||
if (rs == null) {
|
||||
LOGGER.error(String.format("DSM response is null : [url=%s]", uriComponents.toUri()));
|
||||
} else {
|
||||
JSONObject response = new JSONObject(rs);
|
||||
JSONArray jsonArray = (JSONArray) response.get("datasourceInfo");
|
||||
Header header = mapper.readValue(response.get("header").toString(), Header.class);
|
||||
snippets = Paging.of(header,
|
||||
mapper.readValue(
|
||||
String.valueOf(jsonArray),
|
||||
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
||||
}
|
||||
|
||||
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
||||
|
||||
return resultSet;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error searching registered datasources", e);
|
||||
throw e;
|
||||
}
|
||||
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue