Skip to content

Commit

Permalink
Bump spring-boot-starter-parent from 1.4.4 -> 3.2.0 and from Java 8 t…
Browse files Browse the repository at this point in the history
…o Java 11.
  • Loading branch information
Skaar, Bjørn-Andre committed Dec 14, 2023
1 parent d2f8e4d commit 282232b
Show file tree
Hide file tree
Showing 140 changed files with 810 additions and 790 deletions.
11 changes: 8 additions & 3 deletions klass-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>


<!--TOMCAT-->
Expand All @@ -77,10 +83,9 @@

<!-- JSTL og EL for JSP / monitor page -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
</dependency>

<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
Expand Down
8 changes: 3 additions & 5 deletions klass-api/src/main/java/no/ssb/klass/KlassApiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.TomcatServletWebServerFactoryCustomizer;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Import;

// CHECKSTYLE:OFF
@SpringBootApplication
@Import(EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat.class)
@Import(TomcatServletWebServerFactoryCustomizer.class)
public class KlassApiApplication extends SpringBootServletInitializer {
// TODO kmgv if using embedded container (e.g. Tomcat) remove below method and extends SpringBootServletInitializer
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
import no.ssb.klass.api.controllers.MonitorController;
import no.ssb.klass.api.controllers.PingController;
import no.ssb.klass.api.util.RestConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.SecurityFilterChain;

/**
* @author Mads Lundemo, SSB.
*/
@Configuration
@Profile(value = { ConfigurationProfiles.API_ONLY }) // makes config disabled for tests
public class KlassApiConfiguration extends WebSecurityConfigurerAdapter {
public class KlassApiConfiguration {

@Override
protected void configure(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
// block sensitive endpoints (actuator)
.antMatchers("/manage**").denyAll() // alt. hasIpAddress("127.0.0.1")
.antMatchers("/manage/**").denyAll()
.requestMatchers("/manage**").denyAll() // alt. hasIpAddress("127.0.0.1")
.requestMatchers("/manage/**").denyAll()

// MLO: Some endpoints might be useful, consider allowing non sensitive ones.
// .antMatchers("/manage/metrics").permitAll()

// allow rest API and health checks
.antMatchers(RestConstants.API_VERSION_V1 + "/**").permitAll()
.antMatchers(PingController.PATH).permitAll()
.antMatchers(MonitorController.PATH).permitAll()
.requestMatchers(RestConstants.API_VERSION_V1 + "/**").permitAll()
.requestMatchers(PingController.PATH).permitAll()
.requestMatchers(MonitorController.PATH).permitAll()

.and()
.csrf().disable()
Expand All @@ -44,6 +45,6 @@ protected void configure(HttpSecurity http) throws Exception {
}
})
.frameOptions().disable();

return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@
import org.springframework.data.web.PagedResourcesAssembler;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
Expand All @@ -68,7 +69,7 @@
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.servlet.view.RedirectView;

import javax.transaction.Transactional;
import jakarta.transaction.Transactional;
import java.beans.PropertyEditorSupport;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -145,7 +146,7 @@ public RedirectView localRedirect() {
}

@RequestMapping(value = "/classificationfamilies", method = RequestMethod.GET)
public Resources<ClassificationFamilySummaryResource> classificationFamilies(
public CollectionModel<ClassificationFamilySummaryResource> classificationFamilies(
// @formatter:off
@RequestParam(value = "ssbSection", required = false) String ssbSection,
@RequestParam(value = "includeCodelists", defaultValue = "false") boolean includeCodelists,
Expand All @@ -160,7 +161,7 @@ public Resources<ClassificationFamilySummaryResource> classificationFamilies(
.map(summary -> new ClassificationFamilySummaryResource(summary, language))
.collect(toList());

return new KlassResources<>(summaryResources, new Link(getCurrentRequest(), Link.REL_SELF));
return new KlassResources<>(summaryResources, Link.of(getCurrentRequest(), IanaLinkRelations.SELF));
}

@RequestMapping(value = "/classificationfamilies/{id}", method = RequestMethod.GET)
Expand All @@ -178,11 +179,11 @@ public ClassificationFamilyResource classificationFamily(
}

@RequestMapping(value = "/ssbsections", method = RequestMethod.GET)
public Resources<SsbSectionResource> ssbsections() {
public CollectionModel<SsbSectionResource> ssbsections() {
List<SsbSectionResource> ssbSectionResources = classificationService
.findResponsibleSectionsWithPublishedVersions().stream()
.sorted().map(SsbSectionResource::new).collect(toList());
return new KlassResources<>(ssbSectionResources, new Link(getCurrentRequest(), Link.REL_SELF));
return new KlassResources<>(ssbSectionResources, Link.of(getCurrentRequest(), IanaLinkRelations.SELF));
}

@RequestMapping(value = "/classifications", method = RequestMethod.GET)
Expand All @@ -196,8 +197,8 @@ public KlassPagedResources<ClassificationSummaryResource> classifications(
Page<ClassificationSeries> classifications = classificationService.findAllPublic(
includeCodelists, changedSince, pageable);

Link self = new Link(getCurrentRequest(), Link.REL_SELF);
PagedResources<ClassificationSummaryResource> response = assembler.toResource(classifications,
Link self = Link.of(getCurrentRequest(), IanaLinkRelations.SELF);
PagedModel<ClassificationSummaryResource> response = assembler.toModel(classifications,
ClassificationSummaryResource::new, self);
addSearchLink(response);
return new KlassPagedResources<>(response);
Expand All @@ -211,12 +212,12 @@ public KlassPagedResources<SearchResultResource> search(
@RequestParam(value = "includeCodelists", defaultValue = "false") boolean includeCodelists,
Pageable pageable, PagedResourcesAssembler<SolrSearchResult> assembler) {
// @formatter:on
Link self = new Link(getCurrentRequest(), Link.REL_SELF);
Link self = Link.of(getCurrentRequest(), IanaLinkRelations.SELF);
ssbSection = extractSsbSection(ssbSection);

FacetAndHighlightPage<SolrSearchResult> page =
searchService.publicSearch(query, pageable, ssbSection, includeCodelists);
PagedResources<SearchResultResource> response = assembler.toResource(page,
PagedModel<SearchResultResource> response = assembler.toModel(page,
searchResult -> new SearchResultResource(searchResult, page.getHighlights(searchResult)),
self);

Expand Down Expand Up @@ -485,12 +486,12 @@ public ResponseEntity<SubscribeResponse> trackChanges(@PathVariable Long classif
if (subscriberService.containsTracking(email, classification)) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(SubscribeResponse.EXISTS);
} else {
URL endSubscriptionUrl = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(ClassificationController.class)
URL endSubscriptionUrl = WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(ClassificationController.class)
.removeTracking(classificationId, email)).toUri().toURL();

String token = subscriberService.trackChanges(email, classification, endSubscriptionUrl);

URL verifySubscriptionUrl = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(ClassificationController.class)
URL verifySubscriptionUrl = WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(ClassificationController.class)
.verifyTracking(email, token)).toUri().toURL();

subscriberService.sendVerificationMail(email, verifySubscriptionUrl, classification);
Expand Down Expand Up @@ -537,10 +538,10 @@ public ResponseEntity<String> verifyTracking(@PathVariable String email, @PathVa
return ResponseEntity.ok("Subscription is verified.");
}

private void addSearchLink(PagedResources<ClassificationSummaryResource> response) {
ControllerLinkBuilder linkBuilder = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(ClassificationController.class).search("query", null, true,
private void addSearchLink(PagedModel<ClassificationSummaryResource> response) {
WebMvcLinkBuilder linkBuilder = WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(ClassificationController.class).search("query", null, true,
null, null));
response.add(new Link(ResourceUtil.createUriTemplate(linkBuilder, "query", "includeCodelists"), "search"));
response.add(Link.of(ResourceUtil.createUriTemplate(linkBuilder, "query", "includeCodelists"), "search"));
}

private String getCurrentRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private MonitorStatus testRestAPI(HttpServletRequest request) {
private MonitorStatus testSearch() {
try {
FacetAndHighlightPage<SolrSearchResult> solrSearchResults =
searchService.publicSearch("*",new PageRequest(0,10),null,true);
searchService.publicSearch("*",PageRequest.of(0,10),null,true);
int results = solrSearchResults.getSize();
if (results>0) {
return new MonitorStatus(SOLR_SEARCH, true, "Søk fungerer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.Links;
import org.springframework.hateoas.PagedModel;

import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collection;
import java.util.List;

/**
* @author Mads Lundemo, SSB.
Expand All @@ -27,9 +27,9 @@
*/
@JacksonXmlRootElement(localName = "pagedEntities")
@XmlRootElement(name = "pagedEntities")
public class KlassPagedResources<T> extends PagedResources<T> {
public class KlassPagedResources<T> extends PagedModel<T> {

public KlassPagedResources(PagedResources<T> p) {
public KlassPagedResources(PagedModel<T> p) {
super(p.getContent(), p.getMetadata(), p.getLinks());
}

Expand All @@ -45,7 +45,7 @@ public Collection<T> getContent() {
@XmlElement(name = "link", namespace = Link.ATOM_NAMESPACE)
@JacksonXmlElementWrapper(localName = "links")
@JacksonXmlProperty(localName = "link")
public List<Link> getLinks() {
public Links getLinks() {
return super.getLinks();
}
}
11 changes: 7 additions & 4 deletions klass-api/src/main/java/no/ssb/klass/api/dto/KlassResources.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.ssb.klass.api.dto;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

Expand All @@ -8,12 +9,14 @@
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import org.springframework.core.ResolvableType;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.CollectionModel;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.springframework.hateoas.Links;

/**
* This class overrides the XML anotations for content and links, We do this so we can change tag names and distinguish
Expand All @@ -30,10 +33,10 @@
*/
@JacksonXmlRootElement(localName = "entities")
@XmlRootElement(name = "entities")
public class KlassResources<T> extends Resources<T> {
public class KlassResources<T> extends CollectionModel<T> {

public KlassResources(Iterable<T> content, Link... links) {
super(content, links);
super(content, (Iterable) Arrays.asList(links), (ResolvableType) null);
}

@Override
Expand All @@ -48,7 +51,7 @@ public Collection<T> getContent() {
@XmlElement(name = "link", namespace = Link.ATOM_NAMESPACE)
@JacksonXmlElementWrapper(localName = "links")
@JacksonXmlProperty(localName = "link")
public List<Link> getLinks() {
public Links getLinks() {
return super.getLinks();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.ssb.klass.api.dto.hal;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package no.ssb.klass.api.dto.hal;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

import org.springframework.hateoas.Link;
import org.springframework.hateoas.core.Relation;
import org.springframework.hateoas.server.core.Relation;

import no.ssb.klass.core.model.Language;
import no.ssb.klass.core.repository.ClassificationFamilySummary;
Expand Down
Loading

0 comments on commit 282232b

Please sign in to comment.