Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subcodes #218

Merged
merged 15 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>care.smith.top</groupId>
<artifactId>top-backend</artifactId>
<version>0.7.7</version>
<version>0.8.0</version>
<packaging>jar</packaging>

<name>TOP Backend</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import care.smith.top.model.CodeScope;
import care.smith.top.model.CodeSystemPage;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand All @@ -21,7 +23,11 @@ public class CodeApiDelegateImpl implements CodeApiDelegate {

@Override
public ResponseEntity<Code> getCode(URI uri, String codeSystemId, CodeScope scope) {
return ResponseEntity.ok(codeService.getCode(uri, codeSystemId, null));
return ResponseEntity.ok(
codeService.getCode(
URI.create(URLDecoder.decode(uri.toString(), Charset.defaultCharset())),
codeSystemId,
scope));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.firewall.HttpFirewall;
import org.springframework.security.web.firewall.StrictHttpFirewall;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
Expand All @@ -22,6 +24,15 @@ public class SecurityConfiguration {

@Autowired private JwtAuthenticationProvider customAuthenticationProvider;

@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
StrictHttpFirewall firewall = new StrictHttpFirewall();
firewall.setAllowUrlEncodedSlash(true);
firewall.setAllowUrlEncodedDoubleSlash(true);
firewall.setAllowUrlEncodedPercent(true);
return firewall;
}

@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.sessionManagement()
Expand Down
94 changes: 76 additions & 18 deletions src/main/java/care/smith/top/backend/model/jpa/CodeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@
import care.smith.top.model.Code;
import care.smith.top.model.CodeSystem;
import java.net.URI;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.persistence.*;
import javax.validation.constraints.NotNull;

@Embeddable
@Entity(name = "code")
RalphBln marked this conversation as resolved.
Show resolved Hide resolved
public class CodeDao {

@Id @GeneratedValue private Long id;

@ManyToOne(optional = true)
@JoinColumn(name = "parent_id", referencedColumnName = "id")
private CodeDao parent;

@OrderColumn
@OneToMany(
cascade = {CascadeType.ALL},
orphanRemoval = true)
@JoinColumn(name = "parent_id")
private List<CodeDao> children;

@Column(nullable = false)
private String code;

Expand Down Expand Up @@ -39,47 +56,52 @@ public CodeDao(@NotNull Code code) {
name = code.getName();
if (code.getUri() != null) uri = code.getUri().toString();
if (code.getCodeSystem() != null) codeSystemUri = code.getCodeSystem().getUri().toString();
this.children =
Optional.ofNullable(code.getChildren()).orElse(Collections.emptyList()).stream()
.map(this::deepTranslate)
.collect(Collectors.toList());
}

public Code toApiModel() {
return new Code()
.code(code)
.uri(uri != null ? URI.create(uri) : null)
.name(name)
.codeSystem(new CodeSystem().uri(URI.create(codeSystemUri)));
.codeSystem(new CodeSystem().uri(URI.create(codeSystemUri)))
.children(getChildren().stream().map(CodeDao::toApiModel).collect(Collectors.toList()))
.synonyms(Collections.emptyList());
}

public String getCode() {
return code;
public CodeDao id(@NotNull Long id) {
this.id = id;
return this;
}

public CodeDao code(@NotNull String code) {
this.code = code;
public CodeDao parent(@NotNull CodeDao parent) {
this.parent = parent;
return this;
}

public String getName() {
return name;
public CodeDao children(List<CodeDao> children) {
this.children = children;
return this;
}

public CodeDao name(String name) {
this.name = name;
public CodeDao code(@NotNull String code) {
this.code = code;
return this;
}

public String getUri() {
return uri;
public CodeDao name(String name) {
this.name = name;
return this;
}

public CodeDao uri(String uri) {
this.uri = uri;
return this;
}

public String getCodeSystemUri() {
return codeSystemUri;
}

public CodeDao codeSystemUri(@NotNull String codeSystemUri) {
this.codeSystemUri = codeSystemUri;
return this;
Expand Down Expand Up @@ -108,4 +130,40 @@ public int hashCode() {
result = 31 * result + getCodeSystemUri().hashCode();
return result;
}

public Long getId() {
return id;
}

public CodeDao getParent() {
return parent;
}

public List<CodeDao> getChildren() {
return children;
}

public String getCode() {
return code;
}

public String getName() {
return name;
}

public String getUri() {
return uri;
}

public String getCodeSystemUri() {
return codeSystemUri;
}

private CodeDao deepTranslate(Code code) {
final CodeDao codeDao = new CodeDao(code);
return codeDao.children(
Optional.ofNullable(code.getChildren()).orElse(Collections.emptyList()).stream()
.map(childCode -> deepTranslate(childCode).parent(codeDao))
.collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public class EntityVersionDao {

@ElementCollection @OrderColumn private List<LocalisableTextDao> descriptions = null;

@ElementCollection @OrderColumn private List<CodeDao> codes = null;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@OrderColumn
private List<CodeDao> codes = null;

@OneToOne private EntityVersionDao previousVersion;

Expand Down
Loading
Loading