Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/main/java/de/codefor/opacapi/RestAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.security.Security;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

@RestController
public class RestAPI {
Expand Down Expand Up @@ -133,6 +131,29 @@ public List<MySearchField> searchFields(@PathVariable String libraryName) throws
return searchFields;
}

@RequestMapping(value = "/libraries/{libraryName}/catalog/structured-search",
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},
consumes = MediaType.ALL_VALUE)
public CatalogSearchResults structuredSearch(@PathVariable String libraryName,
HttpServletRequest request)
throws IOException, JSONException, OpacApi.OpacErrorException {

Map<String, String[]> map = request.getParameterMap();
List<SearchQuery> searchQueries = new ArrayList<>();

for (Map.Entry<String, String[]> entry : map.entrySet()) {
SearchField searchField = new SearchField() {};
searchField.setId(entry.getKey());
searchQueries.add(new SearchQuery(searchField, entry.getValue()[0]));
}

OpacApi api = getOpacApi(libraryName);
Map<String, SearchRequestResult> results = new HashMap<>();
results.put(libraryName, api.search(searchQueries));

return new CatalogSearchResults(results);
}

@RequestMapping(value = "/libraries/{libraryName}/catalog/search",
method = RequestMethod.GET,
Expand Down