browse queries
This commit is contained in:
parent
413d06ad7c
commit
7907b61167
|
@ -39,6 +39,12 @@ public class MainController {
|
|||
map.addAttribute("browsableFields", DsmBrowsableFields.values());
|
||||
}
|
||||
|
||||
@GetMapping("/resultsDsApi")
|
||||
public void resultsDsApi(@RequestParam(required = false, defaultValue = "") final String field, @RequestParam final String value, final ModelMap map) {
|
||||
map.addAttribute("field", field);
|
||||
map.addAttribute("value", value);
|
||||
}
|
||||
|
||||
@GetMapping("/resources")
|
||||
public String listResources(@RequestParam final String type, final ModelMap map) {
|
||||
|
||||
|
|
|
@ -6,9 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
||||
import eu.dnetlib.data.openaire.dsm.model.Datasource;
|
||||
import eu.dnetlib.openaire.dsm.domain.BrowseTerm;
|
||||
import eu.dnetlib.openaire.dsm.utils.DsmBrowsableFields;
|
||||
|
||||
|
@ -23,4 +25,15 @@ public class DsmAjaxController extends AbstractDnetController {
|
|||
public List<BrowseTerm> browse(@PathVariable final String field) {
|
||||
return dsmService.browseTerm(DsmBrowsableFields.valueOf(field));
|
||||
}
|
||||
|
||||
@GetMapping("/searchByField/{field}")
|
||||
public List<Datasource> searchByField(@PathVariable final String field, @RequestParam final String value) {
|
||||
return dsmService.searchByField(DsmBrowsableFields.valueOf(field), value);
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
public List<Datasource> search(@RequestParam final String value) {
|
||||
return dsmService.search(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -444,7 +444,17 @@ public class DsmService {
|
|||
|
||||
@Transactional
|
||||
public List<BrowseTerm> browseTerm(final DsmBrowsableFields f) {
|
||||
return jdbcTemplate.query(f.sql, new BeanPropertyRowMapper<>(BrowseTerm.class));
|
||||
return jdbcTemplate.query(f.browseSql, new BeanPropertyRowMapper<>(BrowseTerm.class));
|
||||
}
|
||||
|
||||
public List<Datasource> searchByField(final DsmBrowsableFields valueOf, final String value) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Datasource> search(final String value) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,32 +1,31 @@
|
|||
package eu.dnetlib.openaire.dsm.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
public enum DsmBrowsableFields {
|
||||
|
||||
type("Datasource typologies",
|
||||
"select d.eosc_datasource_type as term, d.eosc_datasource_type as name, count(*) as total from dsm_api a left outer join dsm_services d on (a.service = d.id) group by d.eosc_datasource_type order by total desc"),
|
||||
|
||||
country("Countries",
|
||||
"select o.country as term, o.country as name, count(*) as total from dsm_api a left outer join dsm_services d on (a.service = d.id) left outer join dsm_service_organization dao on (d.id = dao.service) left outer join dsm_organizations o on (dao.organization = o.id) group by o.country order by total desc"),
|
||||
|
||||
compliance("Compatibility levels",
|
||||
"select coalesce(a.compatibility_override, a.compatibility) as term, coalesce(a.compatibility_override, a.compatibility) as name, count(*) as total from dsm_api a group by coalesce(a.compatibility_override, a.compatibility) order by total desc"),
|
||||
|
||||
protocol("API protocols", "select a.protocol as term, a.protocol as name, count(*) as total from dsm_api a group by a.protocol order by total desc"),
|
||||
|
||||
active("API activation",
|
||||
"select a.active as term, case when a.active is null then 'UNKNOWN' when a.active then 'active' else 'not active' end as name, count(*) as total from dsm_api a group by a.active order by total desc"),
|
||||
|
||||
consenttermsofuse("Consent terms of use",
|
||||
"select d.consenttermsofuse as term, case when d.consenttermsofuse is null then 'UNKNOWN' when d.consenttermsofuse then 'YES' else 'NO' end as name, count(*) as total from dsm_api a left outer join dsm_services d on (a.service = d.id) group by d.consenttermsofuse order by total desc"),
|
||||
|
||||
fulltextdownload("Fulltext download",
|
||||
"select d.fulltextdownload as term, case when d.fulltextdownload is null then 'UNKNOWN' when d.fulltextdownload then 'Available' else 'Not available' end as name, count(*) as total from dsm_api a left outer join dsm_services d on (a.service = d.id) group by d.fulltextdownload order by total desc");
|
||||
type("Datasource typologies", "browseType.sql", "searchByType.sql"),
|
||||
country("Countries", "browseCountry.sql", "searchByCountry.sql"),
|
||||
compliance("Compatibility levels", "browseCompliance.sql", "searchByCompliance.sql"),
|
||||
protocol("API protocols", "browseProtocol.sql", "searchByProtocol.sql"),
|
||||
active("API activation", "browseActive.sql", "searchByActive.sql"),
|
||||
consenttermsofuse("Consent terms of use", "browseConsentTermOfUse.sql", "searchByConsentTermOfUse.sql"),
|
||||
fulltextdownload("Fulltext download", "browseFulltextDownload.sql", "searchByFulltextDownload.sql");
|
||||
|
||||
public final String desc;
|
||||
public final String sql;
|
||||
public final String browseSql;
|
||||
public final String searchSql;
|
||||
|
||||
private DsmBrowsableFields(final String desc, final String sql) {
|
||||
private DsmBrowsableFields(final String desc, final String browseSqlFile, final String searchSqlFile) {
|
||||
this.desc = desc;
|
||||
this.sql = sql;
|
||||
try {
|
||||
this.browseSql = IOUtils.toString(getClass().getResourceAsStream("/sql/dsm/ui/" + browseSqlFile), StandardCharsets.UTF_8.name());
|
||||
this.searchSql = IOUtils.toString(getClass().getResourceAsStream("/sql/dsm/ui/" + searchSqlFile), StandardCharsets.UTF_8.name());
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
select
|
||||
a.active as term,
|
||||
case when a.active is null then 'UNKNOWN' when a.active then 'active' else 'not active' end as name,
|
||||
count(*) as total
|
||||
from dsm_api a
|
||||
group by a.active
|
||||
order by total desc;
|
|
@ -0,0 +1,7 @@
|
|||
select
|
||||
coalesce(a.compatibility_override, a.compatibility) as term,
|
||||
coalesce(a.compatibility_override, a.compatibility) as name,
|
||||
count(*) as total
|
||||
from dsm_api a
|
||||
group by coalesce(a.compatibility_override, a.compatibility)
|
||||
order by total desc;
|
|
@ -0,0 +1,10 @@
|
|||
select
|
||||
d.consenttermsofuse as term,
|
||||
case when d.consenttermsofuse is null then 'UNKNOWN' when d.consenttermsofuse then 'YES' else 'NO' end as name,
|
||||
count(*) as total
|
||||
from
|
||||
dsm_api a
|
||||
left outer join dsm_services d on (a.service = d.id)
|
||||
group by d.consenttermsofuse
|
||||
order by total desc;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
select
|
||||
o.country as term,
|
||||
o.country as name,
|
||||
count(*) as total
|
||||
from
|
||||
dsm_api a
|
||||
left outer join dsm_services d on (a.service = d.id)
|
||||
left outer join dsm_service_organization dao on (d.id = dao.service)
|
||||
left outer join dsm_organizations o on (dao.organization = o.id)
|
||||
group by o.country
|
||||
order by total desc;
|
|
@ -0,0 +1,9 @@
|
|||
select
|
||||
d.fulltextdownload as term,
|
||||
case when d.fulltextdownload is null then 'UNKNOWN' when d.fulltextdownload then 'Available' else 'Not available' end as name,
|
||||
count(*) as total
|
||||
from
|
||||
dsm_api a
|
||||
left outer join dsm_services d on (a.service = d.id)
|
||||
group by d.fulltextdownload
|
||||
order by total desc;
|
|
@ -0,0 +1,7 @@
|
|||
select
|
||||
a.protocol as term,
|
||||
a.protocol as name,
|
||||
count(*) as total
|
||||
from dsm_api a
|
||||
group by a.protocol
|
||||
order by total desc;
|
|
@ -0,0 +1,9 @@
|
|||
select
|
||||
d.eosc_datasource_type as term,
|
||||
d.eosc_datasource_type as name,
|
||||
count(*) as total
|
||||
from
|
||||
dsm_api a
|
||||
left outer join dsm_services d on (a.service = d.id)
|
||||
group by d.eosc_datasource_type
|
||||
order by total desc;
|
|
@ -29,7 +29,7 @@
|
|||
<a class="nav-link" href="./main">Home <span class="sr-only">(current)</span></a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="javascript:void(0)" data-toggle="dropdown">DataSource Management</a>
|
||||
<a class="nav-link dropdown-toggle" href="javascript:void(0)" data-toggle="dropdown">Datasources</a>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="./searchDsApi">Overview</a>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader('Datasources')"></head>
|
||||
|
||||
<script th:inline="javascript">
|
||||
/*<![CDATA[*/
|
||||
function getField() { return /*[[${field}]]*/ ''; }
|
||||
function getValue() { return /*[[${value}]]*/ ''; }
|
||||
/*]]>*/
|
||||
</script>
|
||||
|
||||
<body ng-app="dsmResultsApp" ng-controller="dsmResultsController">
|
||||
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu('Datasources')"></nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row mt-5">
|
||||
<div class="col">
|
||||
{{results}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<th:block th:replace="fragments/mainParts.html :: scripts"></th:block>
|
||||
|
||||
<script>
|
||||
var app = angular.module('dsmResultsApp', []);
|
||||
|
||||
app.controller('dsmResultsController', function($scope, $http) {
|
||||
$scope.field = getField();
|
||||
$scope.value = getValue();
|
||||
$scope.results = [];
|
||||
|
||||
var url = './ajax/dsm/';
|
||||
if ($scope.field) { url += 'searchByField/' + encodeURIComponent($scope.field); }
|
||||
else { url += 'search?' }
|
||||
url += '?value=' + encodeURIComponent($scope.value) + '&' + $.now();
|
||||
|
||||
$http.get(url).then(function successCallback(res) {
|
||||
$scope.results = res.data;
|
||||
}, function errorCallback(res) {
|
||||
alert('ERROR: ' + res.data.message);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
|
@ -1,11 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader('DataSource API Management')"></head>
|
||||
<head th:replace="fragments/mainParts.html :: htmlHeader('Datasources')"></head>
|
||||
|
||||
<body ng-app="dsmSearchApp" ng-controller="dsmSearchController">
|
||||
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu('DataSource API Management')"></nav>
|
||||
<nav th:replace="fragments/mainParts.html :: mainMenu('Datasources')"></nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row mt-5">
|
||||
|
@ -14,7 +14,7 @@
|
|||
<div class="input-group">
|
||||
<input type="text" class="form-control" ng-model="textApiSearch" placeholder="Search..."/>
|
||||
<span class="input-group-append">
|
||||
<button type="submit" class="btn btn-primary" ng-click="searchApis(textApiSearch)">Search</button>
|
||||
<button type="submit" class="btn btn-primary" ng-click="search('', textApiSearch)">Search</button>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -70,7 +70,7 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="row in browseData | orderBy:sortType:sortReverse | filter:filterBrowseData">
|
||||
<th><a href="javascript:void(0)" ng-click="searchByField(browseTermId, row.term)">{{row.name}}</a></td>
|
||||
<th><a href="javascript:void(0)" ng-click="search(browseFieldId, row.term)">{{row.name}}</a></td>
|
||||
<td class="text-right">{{row.total}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -106,8 +106,11 @@
|
|||
});
|
||||
}
|
||||
|
||||
$scope.searchByField = function(id, value) {
|
||||
alert("Search....TODO");
|
||||
$scope.search = function(field, value) {
|
||||
var url = "resultsDsApi?"
|
||||
if (field) { url += "field=" + encodeURIComponent(field) + "&" }
|
||||
url += "value=" + encodeURIComponent(value)
|
||||
location.href = url;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue