Updated resource description.
Change-Id: I49bc9fa3e16dbbbbfbe31985dd5c87154e7e1652
diff --git a/src/main/java/de/ids_mannheim/korap/dto/ResourceDto.java b/src/main/java/de/ids_mannheim/korap/dto/ResourceDto.java
index 3a14423..acf2001 100644
--- a/src/main/java/de/ids_mannheim/korap/dto/ResourceDto.java
+++ b/src/main/java/de/ids_mannheim/korap/dto/ResourceDto.java
@@ -1,11 +1,13 @@
package de.ids_mannheim.korap.dto;
+import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
-/** Data transfer object for resource description (e.g. for KorapSRU).
+/**
+ * Data transfer object for resource description (e.g. for KorapSRU).
*
* @author margaretha
*
@@ -15,18 +17,16 @@
public class ResourceDto {
private String resourceId;
- private String germanTitle;
- private String englishTitle;
+ private Map<String, String> titles;
private String description;
+ private String[] languages;
private Map<Integer, String> layers;
- private Map<String, String> languages;
@Override
public String toString () {
- return "resourceId= " + resourceId + ", germanTitle= " + germanTitle
- + ", englishTitle= " + englishTitle + ", description= "
- + description + ", languages= " + languages + ", layers= "
- + layers;
+ return "resourceId= " + resourceId + ", description= " + description
+ + ", titles= " + titles + ", languages= " + languages
+ + ", layers= " + layers;
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/dto/converter/ResourceConverter.java b/src/main/java/de/ids_mannheim/korap/dto/converter/ResourceConverter.java
index f79119d..03f00b3 100644
--- a/src/main/java/de/ids_mannheim/korap/dto/converter/ResourceConverter.java
+++ b/src/main/java/de/ids_mannheim/korap/dto/converter/ResourceConverter.java
@@ -17,19 +17,18 @@
public List<ResourceDto> convertToResourcesDto (List<Resource> resources) {
List<ResourceDto> resourceDtoList = new ArrayList<ResourceDto>(resources.size());
ResourceDto dto;
- Map<String, String> languages;
+ Map<String, String> titles;
HashMap<Integer, String> layers;
for (Resource r: resources){
dto = new ResourceDto();
dto.setDescription(r.getEnglishDescription());
- dto.setEnglishTitle(r.getEnglishTitle());
- dto.setGermanTitle(r.getGermanTitle());
dto.setResourceId(r.getId());
+ dto.setLanguages(new String[]{"deu"});
- languages = new HashMap<String, String>();
- languages.put("en", r.getEnglishTitle());
- languages.put("de", r.getGermanTitle());
- dto.setLanguages(languages);
+ titles = new HashMap<String, String>();
+ titles.put("en", r.getEnglishTitle());
+ titles.put("de", r.getGermanTitle());
+ dto.setTitles(titles);
layers = new HashMap<Integer, String>();
String foundry, layer, code;
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/AnnotationService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/AnnotationService.java
index 917baa4..102ed8b 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/AnnotationService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/AnnotationService.java
@@ -25,6 +25,7 @@
import de.ids_mannheim.korap.dto.LayerDto;
import de.ids_mannheim.korap.dto.converter.AnnotationConverter;
import de.ids_mannheim.korap.entity.AnnotationPair;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.filter.AuthFilter;
@@ -85,8 +86,8 @@
public Response getFoundryDescriptions (String json) {
JsonNode node = JsonUtils.readTree(json);
if (node == null) {
- throw KustvaktResponseHandler.throwit(StatusCodes.MISSING_ARGUMENT,
- "Missing a json string.");
+ throw KustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.MISSING_ARGUMENT, "Missing a json string.", ""));
}
String language;
@@ -100,8 +101,8 @@
}
else if (!(language.equals("en") || language.equals("de"))) {
throw KustvaktResponseHandler.throwit(
- StatusCodes.UNSUPPORTED_VALUE, "Unsupported value:",
- language);
+ new KustvaktException(StatusCodes.UNSUPPORTED_VALUE,
+ "Unsupported value:", language));
}
}
@@ -110,14 +111,19 @@
codes = JsonUtils.convert(node.get("codes"), List.class);
}
catch (IOException | NullPointerException e) {
- throw KustvaktResponseHandler.throwit(StatusCodes.INVALID_ARGUMENT,
- "Bad argument:", json);
+ throw KustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.INVALID_ARGUMENT, "Bad argument:", json));
}
if (codes == null) {
- throw KustvaktResponseHandler.throwit(StatusCodes.MISSING_ATTRIBUTE,
- "Missing attribute:", "codes");
+ throw KustvaktResponseHandler.throwit(
+ new KustvaktException(StatusCodes.MISSING_ATTRIBUTE,
+ "Missing attribute:", "codes"));
}
-
+ else if (codes.isEmpty()) {
+ throw KustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.NO_VALUE_FOUND, "No result found.","codes:[]"));
+ }
+
List<AnnotationPair> annotationPairs = null;
String foundry = "", layer = "";
if (codes.contains("*")) {
@@ -140,8 +146,8 @@
else {
jlog.error("Annotation code is wrong: " + annotationCode);
throw KustvaktResponseHandler.throwit(
- StatusCodes.INVALID_ATTRIBUTE, "Bad attribute:",
- code);
+ new KustvaktException(StatusCodes.INVALID_ATTRIBUTE,
+ "Bad attribute:", code));
}
annotationPairs.addAll(annotationDao
@@ -152,13 +158,13 @@
if (annotationPairs != null && !annotationPairs.isEmpty()) {
List<FoundryDto> dtos = annotationConverter
.convertToFoundryDto(annotationPairs, language);
- jlog.debug("/layers " + annotationPairs.toString());
+ jlog.debug("/description " + annotationPairs.toString());
String result = JsonUtils.toJSON(dtos);
return Response.ok(result).build();
}
else {
- throw KustvaktResponseHandler.throwit(StatusCodes.NO_VALUE_FOUND,
- "No result found.");
+ throw KustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.NO_VALUE_FOUND, "No result found.",""));
}
}