diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/SwaggerController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/SwaggerController.java
index 985fbe66..c71ebffe 100644
--- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/SwaggerController.java
+++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/SwaggerController.java
@@ -1,16 +1,16 @@
package eu.dnetlib.is;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class SwaggerController {
- @GetMapping({
- "/doc", "/swagger"
+ @RequestMapping(value = {
+ "/docs", "swagger-ui.html", "swagger-ui/"
})
public String apiDoc() {
- return "redirect:swagger-ui/";
+ return "redirect:swagger-ui/index.html";
}
}
diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/AbstractResourceController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/AbstractResourceController.java
index 2e02de5e..f4b685d6 100644
--- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/AbstractResourceController.java
+++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/AbstractResourceController.java
@@ -11,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestParam;
import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.is.resource.model.SimpleResource;
@@ -23,25 +22,25 @@ public class AbstractResourceController extends AbstractDnetController {
@Autowired
protected SimpleResourceService service;
- @GetMapping("/")
- public List listResources(@RequestParam final String type) {
- return service.listResources(type);
+ @GetMapping("/{typeId}")
+ public List listResources(@PathVariable final String typeId) {
+ return service.listResources(typeId);
}
- @GetMapping("/{id}/metadata")
- public SimpleResource getMetadata(@PathVariable final String id) throws InformationServiceException {
- return service.getMetadata(id);
+ @GetMapping("/{resId}/metadata")
+ public SimpleResource getMetadata(@PathVariable final String resId) throws InformationServiceException {
+ return service.getMetadata(resId);
}
- @GetMapping("/{id}/content")
- public void getContent(@PathVariable final String id, final HttpServletResponse res) throws InformationServiceException {
- final String ctype = service.getContentType(id);
+ @GetMapping("/{resId}/content")
+ public void getContent(@PathVariable final String resId, final HttpServletResponse res) throws InformationServiceException {
+ final String ctype = service.getContentType(resId);
res.setCharacterEncoding(StandardCharsets.UTF_8.name());
res.setContentType(ctype);
final String content =
- ctype.equals(MediaType.APPLICATION_XML_VALUE) ? XmlIndenter.indent(service.getContent(id)) : service.getContent(id);
+ ctype.equals(MediaType.APPLICATION_XML_VALUE) ? XmlIndenter.indent(service.getContent(resId)) : service.getContent(resId);
try {
IOUtils.write(content, res.getOutputStream(), StandardCharsets.UTF_8.name());
diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourceAjaxController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourceAjaxController.java
index 4122a29f..4d8d6b2c 100644
--- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourceAjaxController.java
+++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourceAjaxController.java
@@ -32,28 +32,28 @@ public class ResourceAjaxController extends AbstractResourceController {
return service.saveNewResource(name, type, description, content);
}
- @DeleteMapping("/{id}")
- public void deleteResource(@PathVariable final String id) {
- service.deleteResource(id);
+ @DeleteMapping("/{resId}")
+ public void deleteResource(@PathVariable final String resId) {
+ service.deleteResource(resId);
}
- @PostMapping("/{id}/metadata")
- public void saveMetadata(@PathVariable final String id, @RequestBody final SimpleResource r) throws InformationServiceException {
- service.saveMetadata(id, r);
+ @PostMapping("/{resId}/metadata")
+ public void saveMetadata(@PathVariable final String resId, @RequestBody final SimpleResource r) throws InformationServiceException {
+ service.saveMetadata(resId, r);
}
- @PostMapping("/{id}/content")
- public void saveContent(@PathVariable final String id, @RequestParam final String content) throws InformationServiceException {
- service.saveContent(id, content);
+ @PostMapping("/{resId}/content")
+ public void saveContent(@PathVariable final String resId, @RequestParam final String content) throws InformationServiceException {
+ service.saveContent(resId, content);
}
- @PostMapping(value = "/{id}/file", consumes = {
+ @PostMapping(value = "/{resId}/file", consumes = {
MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE
})
- public void uploadContent(@PathVariable final String id, final HttpServletRequest request) throws InformationServiceException {
+ public void uploadContent(@PathVariable final String resId, final HttpServletRequest request) throws InformationServiceException {
try {
final String content = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
- service.saveContent(id, content);
+ service.saveContent(resId, content);
} catch (final IOException e) {
throw new InformationServiceException("Error processing input file", e);
}
diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourceApiController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourceApiController.java
index e3066961..4046f22b 100644
--- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourceApiController.java
+++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/resources/ResourceApiController.java
@@ -1,10 +1,65 @@
package eu.dnetlib.is.resources;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+import eu.dnetlib.is.resource.model.ResourceType;
+import eu.dnetlib.is.resource.repository.ResourceTypeRepository;
+
@RestController
@RequestMapping("/api/resources")
public class ResourceApiController extends AbstractResourceController {
+ @Autowired
+ private ResourceTypeRepository resourceTypeRepository;
+
+ @GetMapping("/")
+ private List types() {
+ return StreamSupport.stream(resourceTypeRepository.findAll().spliterator(), false)
+ .filter(rt -> rt.isSimple())
+ .map(rt -> new SimpleResourceType(rt))
+ .collect(Collectors.toList());
+ }
+
+ class SimpleResourceType {
+
+ private final String typeId;
+
+ private final String typeName;
+
+ private final String contentType;
+
+ private final long count;
+
+ public SimpleResourceType(final ResourceType rt) {
+ this.typeId = rt.getId();
+ this.typeName = rt.getName();
+ this.contentType = rt.getContentType();
+ this.count = rt.getCount();
+ }
+
+ public String getTypeId() {
+ return typeId;
+ }
+
+ public String getTypeName() {
+ return typeName;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+ }
+
}
diff --git a/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js b/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js
index 86807406..0b5c39cc 100644
--- a/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js
+++ b/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js
@@ -7,7 +7,7 @@ app.controller('resourcesController', function($scope, $http) {
$scope.type = typeId();
$scope.reload = function() {
- $http.get('./ajax/resources/?type=' + $scope.type + '&' + $.now()).then(function successCallback(res) {
+ $http.get('./ajax/resources/' + encodeURIComponent($scope.type) + '?' + $.now()).then(function successCallback(res) {
$scope.resources = res.data;
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
@@ -29,7 +29,7 @@ app.controller('resourcesController', function($scope, $http) {
$scope.prepareEditContent = function(r) {
$scope.tmpRes = angular.copy(r);
$scope.tmpContent = "loading...";
- $http.get('./ajax/resources/' + r.id + '/content?' + $.now()).then(function successCallback(res) {
+ $http.get('./ajax/resources/' + encodeURIComponent(r.id) + '/content?' + $.now()).then(function successCallback(res) {
if (res.data instanceof Object) {
$scope.tmpContent = JSON.stringify(res.data, null, "\t");
} else {
@@ -57,7 +57,7 @@ app.controller('resourcesController', function($scope, $http) {
$scope.saveMetadata = function(id, md) {
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
- $http.post('./ajax/resources/' + id + '/metadata?' + $.now(), md).then(function successCallback(res) {
+ $http.post('./ajax/resources/' + encodeURIComponent(id) + '/metadata?' + $.now(), md).then(function successCallback(res) {
alert("Resource saved");
$scope.reload();
}, function errorCallback(res) {
@@ -67,7 +67,7 @@ app.controller('resourcesController', function($scope, $http) {
$scope.saveContent = function(id, content) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
- $http.post('./ajax/resources/' + id + '/content?' + $.now(), $.param({
+ $http.post('./ajax/resources/' + encodeURIComponent(id) + '/content?' + $.now(), $.param({
'content' : content
})).then(function successCallback(res) {
alert("Resource saved");
diff --git a/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html b/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html
index a08ac0b0..9a5b8258 100644
--- a/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html
+++ b/apps/dnet-is-application/src/main/resources/templates/fragments/mainParts.html
@@ -59,7 +59,8 @@
Info
diff --git a/apps/dnet-is-application/src/main/resources/templates/simpleResources.html b/apps/dnet-is-application/src/main/resources/templates/simpleResources.html
index 4393f3a1..8a2b874c 100644
--- a/apps/dnet-is-application/src/main/resources/templates/simpleResources.html
+++ b/apps/dnet-is-application/src/main/resources/templates/simpleResources.html
@@ -38,7 +38,7 @@
- raw content
+ raw content