Commit 1adb3aef authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

change from field injection to constructor injection. closes #56

parent 3e82a77b
Pipeline #139171 passed with stages
in 9 minutes and 32 seconds
......@@ -22,14 +22,17 @@ import info.textgrid.rep.shared.ViewMode;
@SessionAttributes("basket")
public class BasketController {
@Autowired
private TgsearchClientService tgsearchClientService;
@Autowired
private I18NProvider i18nProvider;
private static final Log log = LogFactory.getLog(BasketController.class);
@Autowired
public BasketController(TgsearchClientService tgsearchClientService, I18NProvider i18nProvider) {
this.tgsearchClientService = tgsearchClientService;
this.i18nProvider = i18nProvider;
}
@ModelAttribute("basket")
public Basket getBasket() {
return new Basket();
......
......@@ -36,26 +36,33 @@ import info.textgrid.rep.shared.ViewMode;
@Controller
public class BrowseController {
@Autowired
private TgrepConfigurationService tgrepConfig;
@Autowired
private AggregatorClientService aggregatorClient;
@Autowired
private TgcrudClientService tgcrudClientService;
@Autowired
private TgsearchClientService tgsearchClientService;
@Autowired
private TgcrudClientService tgcrudClient;
private TgsearchClientService tgsearchClient;
private MarkdownRenderService markdownRenderService;
@Autowired
private I18NProvider i18nProvider;
private static final Log log = LogFactory.getLog(BrowseController.class);
@Autowired
public BrowseController(
TgrepConfigurationService tgrepConfig,
AggregatorClientService aggregatorClient,
TgcrudClientService tgcrudClient,
TgsearchClientService tgsearchClient,
MarkdownRenderService markdownRenderService,
I18NProvider i18nProvider) {
this.tgrepConfig = tgrepConfig;
this.aggregatorClient = aggregatorClient;
this.tgcrudClient = tgcrudClient;
this.tgsearchClient = tgsearchClient;
this.markdownRenderService = markdownRenderService;
this.i18nProvider = i18nProvider;
}
@GetMapping("/browse/{id}")
public String browse(
Locale locale,
......@@ -78,7 +85,7 @@ public class BrowseController {
mode.equals("gallery")));
model.addAttribute("viewmodes", viewmodes);
List<ResultType> results = this.tgsearchClientService.listRootCollections().getResult();
List<ResultType> results = this.tgsearchClient.listRootCollections().getResult();
model.addAttribute("results", results);
model.addAttribute("browseRootAggregations", true);
return "browse";
......@@ -91,7 +98,7 @@ public class BrowseController {
model.addAttribute("textgridUri", id);
ResultType metadata = this.tgsearchClientService.getMetadata(id);
ResultType metadata = this.tgsearchClient.getMetadata(id);
model.addAttribute("metadata", metadata);
// for path, todo: create a tagfile for path
......@@ -238,7 +245,7 @@ public class BrowseController {
List<ResultType> results;
if (format.contains("text/tg.work+xml")) {
results = this.tgsearchClientService.getSearchClient()
results = this.tgsearchClient.getSearchClient()
.searchQuery()
.setQuery("*")
.addFilter("edition.isEditionOf:"+id)
......@@ -246,7 +253,7 @@ public class BrowseController {
.execute()
.getResult();
} else {
results = this.tgsearchClientService.listAggregation(id).getResult();
results = this.tgsearchClient.listAggregation(id).getResult();
}
model.addAttribute("results", results);
}
......@@ -269,7 +276,7 @@ public class BrowseController {
InputStream contentStream;
String content;
try {
contentStream = this.tgcrudClientService.read(id);
contentStream = this.tgcrudClient.read(id);
content = markdownRenderService.renderHtml(contentStream);
} catch (CrudClientException e) {
//TODO: nicer error strings
......@@ -286,7 +293,7 @@ public class BrowseController {
private void listRevisions(Model model, String id, ResultType metadata) {
String baseUri = id.substring(0, id.indexOf("."));
Revisions revisions = tgsearchClientService.listRevisions(id);
Revisions revisions = tgsearchClient.listRevisions(id);
int displayRev = metadata.getObject().getGeneric().getGenerated().getRevision();
BigInteger latestRev = Collections.max(revisions.getRevision());
if(BigInteger.valueOf(displayRev).compareTo(latestRev) < 0) {
......
......@@ -17,11 +17,15 @@ import info.textgrid.rep.service.TgsearchClientService;
@Controller
public class BrowseFacetController {
@Autowired
private TgsearchClientService tgsearchClientService;
private static final Log log = LogFactory.getLog(BrowseFacetController.class);
@Autowired
public BrowseFacetController(TgsearchClientService tgsearchClientService) {
this.tgsearchClientService = tgsearchClientService;
}
@GetMapping("/facet/{facet}")
public String render(
Locale locale,
......
......@@ -17,17 +17,23 @@ import info.textgrid.rep.i18n.I18NProvider;
@Controller
public class DocController {
@Autowired
private ResourceLoader resourceLoader;
@Autowired
private I18NProvider i18nProvider;
@Autowired
private MarkdownRenderService markdownRenderService;
private static final Log log = LogFactory.getLog(DocController.class);
@Autowired
public DocController(
ResourceLoader resourceLoader,
I18NProvider i18nProvider,
MarkdownRenderService markdownRenderService) {
this.resourceLoader = resourceLoader;
this.i18nProvider = i18nProvider;
this.markdownRenderService = markdownRenderService;
}
@GetMapping("/")
public String renderIndex(
Model model,
......
......@@ -25,14 +25,17 @@ import info.textgrid.rep.shared.ViewMode;
@Controller
public class SearchController {
@Autowired
private TgsearchClientService tgsearchClientService;
@Autowired
private TgsearchClientService tgsearchClient;
private I18NProvider i18nProvider;
private static final Logger logger = LoggerFactory.getLogger(SearchController.class);
@Autowired
public SearchController(TgsearchClientService tgsearchClient, I18NProvider i18nProvider) {
this.tgsearchClient = tgsearchClient;
this.i18nProvider = i18nProvider;
}
/**
* without this method the filter param passed to search could be separated at
* a comma, for example "filter:Tucholsky, Kurt" would become
......@@ -67,7 +70,7 @@ public class SearchController {
// the filter only request, e.g. from facet-browse
realQueryString = "*";
}
Response res = this.tgsearchClientService.search(realQueryString, order, start, limit, filter, sandbox);
Response res = this.tgsearchClient.search(realQueryString, order, start, limit, filter, sandbox);
Pager pager = new Pager()
.setHits(Integer.parseInt(res.getHits()))
......
......@@ -2,7 +2,6 @@ package info.textgrid.rep.service;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
......@@ -20,12 +19,12 @@ public class AggregatorClientService {
private static final Log log = LogFactory.getLog(AggregatorClientService.class);
private TgrepConfigurationService tgrepConfig;
Client restClient = ClientBuilder
.newClient().property("thread.safe.client", "true");
Client restClient;
@Autowired
public AggregatorClientService(TgrepConfigurationService tgrepConfig) {
this.tgrepConfig = tgrepConfig;
restClient = ClientBuilder.newClient().property("thread.safe.client", "true");
}
private static final long serialVersionUID = -2920076918342185011L;
......@@ -69,12 +68,9 @@ public class AggregatorClientService {
try {
linkPattern = URLEncoder.encode("/browse/_/tgrep/@URI@&fragment=@ID@", "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("error encoding link pattern",e);
}
//System.out.println("lp: " + linkPattern);
WebTarget target = restClient.target(this.tgrepConfig.getTextgridHost());
target = target.path("/1.0/aggregator/html/"+id)
.queryParam("embedded", "true")
......@@ -83,9 +79,6 @@ public class AggregatorClientService {
.queryParam("linkPattern", linkPattern);
Invocation.Builder builder = target.request();
//Response response = builder.get();
//System.out.println("response is there: " + response.getStatus());
return builder.get(String.class);
}
......
......@@ -12,16 +12,14 @@ import info.textgrid.clients.tgcrud.CrudClientException;
@Service
public class TgcrudClientService {
@Autowired
private TgrepConfigurationService tgrepConfig;
private CrudClient crudClient;
private static final Log log = LogFactory.getLog(TgsearchClientService.class);
@PostConstruct
public void postConstruct() throws CrudClientException {
@Autowired
public TgcrudClientService(TgrepConfigurationService tgrepConfig) throws CrudClientException {
this.tgrepConfig = tgrepConfig;
this.setupClient();
}
......
......@@ -2,7 +2,6 @@ package info.textgrid.rep.service;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,13 +20,17 @@ public class TgsearchClientService {
@Value("${tgsearch.query.facetlimit}")
private int facetLimit = 10;
@Autowired
private TgrepConfigurationService tgrepConfig;
private SearchClient searchClient;
private static final Log log = LogFactory.getLog(TgsearchClientService.class);
@Autowired
public TgsearchClientService (TgrepConfigurationService tgrepConfig) {
this.tgrepConfig = tgrepConfig;
this.setupClient();
}
private List<String> facets = Arrays.asList(new String[] {
"edition.agent.value",
"work.genre",
......@@ -35,18 +38,11 @@ public class TgsearchClientService {
"project.value"
});
@PostConstruct
public void postConstruct() {
this.setupClient();
}
private void setupClient() {
log.info("setting up tgsearch client for host: " + tgrepConfig.getTextgridHost());
// Create Searchclient with GZIP compression enabled
searchClient = new SearchClient(tgrepConfig.getTextgridHost() + "/1.0/tgsearch-public")
.enableGzipCompression();
}
public Response search(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment