Skip to content

Commit

Permalink
Merge pull request #378 from NUM-Forschungsdatenplattform/develop
Browse files Browse the repository at this point in the history
Release 1.12.0
  • Loading branch information
richardbartha authored Mar 31, 2023
2 parents cf5d262 + c8cda48 commit 3c1db7f
Show file tree
Hide file tree
Showing 58 changed files with 1,851 additions and 956 deletions.
27 changes: 21 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>de.vitagroup.num-portal</groupId>
<artifactId>num-portal</artifactId>
<version>1.11.1</version>
<version>1.12.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand All @@ -30,15 +30,19 @@
<openfeign.version>3.0.3</openfeign.version>
<commons-csv.version>1.9.0</commons-csv.version>
<jacoco.version>0.8.7</jacoco.version>
<dependency-check.version>6.2.2</dependency-check.version>
<dependency-check.version>8.1.2</dependency-check.version>
<failsafe.version>3.0.0-M5</failsafe.version>
<surefire.version>3.0.0-M5</surefire.version>
<ehcache.version>3.10.8</ehcache.version>
<git-commit-id-plugin.version>4.9.9</git-commit-id-plugin.version>
<git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
<skip.dependency.check>false</skip.dependency.check>
<postgresql.version>42.5.0</postgresql.version>
<postgresql.version>42.5.3</postgresql.version>
<hapi.version>5.5.1</hapi.version>
<wiremock-standalone.version>3.0.0-beta-2</wiremock-standalone.version>
<testcontainers.postgresql.version>1.17.6</testcontainers.postgresql.version>
<ossindexAnalyzerEnabled>false</ossindexAnalyzerEnabled>
</properties>

<repositories>
Expand Down Expand Up @@ -115,7 +119,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.16.0</version>
<version>${testcontainers.postgresql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -130,6 +134,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>com.github.ehrbase.openEHR_SDK</groupId>
<artifactId>client</artifactId>
Expand All @@ -150,6 +158,11 @@
<artifactId>modelmapper</artifactId>
<version>${modelmapper.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jaxrsserver-base</artifactId>
<version>${hapi.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down Expand Up @@ -215,9 +228,10 @@
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>2.27.2</version>
<version>${wiremock-standalone.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -365,6 +379,7 @@
<configuration>
<formats>HTML,XML</formats>
<skip>${skip.dependency.check}</skip>
<ossindexAnalyzerEnabled>${ossindexAnalyzerEnabled}</ossindexAnalyzerEnabled>
</configuration>
<executions>
<execution>
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/de/vitagroup/num/config/FttpClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package de.vitagroup.num.config;

import ca.uhn.fhir.context.FhirContext;
import de.vitagroup.num.properties.FttpProperties;
import java.security.KeyStore;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@RequiredArgsConstructor
public class FttpClientConfig {

private static final String CERTIFICATE_TYPE = "PKCS12";

private final FttpProperties fttpProperties;

@Bean
public FhirContext fhirContext() {
return FhirContext.forR4();
}

@Bean
public CloseableHttpClient httpClient() {
try {
var keyStore = KeyStore.getInstance(CERTIFICATE_TYPE);

keyStore.load(getClass().getResourceAsStream(fttpProperties.getCertificatePath()),
fttpProperties.getCertificateKey().toCharArray());

SSLContext sslContext =
SSLContextBuilder.create().loadKeyMaterial(keyStore, fttpProperties.getCertificateKey().toCharArray()).build();

HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslFactory =
new SSLConnectionSocketFactory(sslContext, hostnameVerifier);

CloseableHttpClient client;

if (fttpProperties.isUseBasicAuth()) {
var provider = new BasicCredentialsProvider();
provider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(fttpProperties.getUsername(), fttpProperties.getPassword())
);

client = HttpClients.custom().setSSLSocketFactory(sslFactory).setDefaultCredentialsProvider(provider).build();
} else {
client = HttpClients.custom().setSSLSocketFactory(sslFactory).build();
}

return client;
} catch (Exception e) {
log.error("Failed to create http client for fttp communication with cause [{}]", e.getLocalizedMessage());
}
return null;
}
}
6 changes: 6 additions & 0 deletions src/main/java/de/vitagroup/num/domain/EntityGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.vitagroup.num.domain;

public enum EntityGroup {

PROJECT_STATUS;
}
56 changes: 26 additions & 30 deletions src/main/java/de/vitagroup/num/domain/Project.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,34 @@
package de.vitagroup.num.domain;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import de.vitagroup.num.domain.admin.UserDetails;
import de.vitagroup.num.domain.repository.CategorySetConverter;
import de.vitagroup.num.domain.repository.MapConverter;
import de.vitagroup.num.domain.admin.UserDetails;
import de.vitagroup.num.domain.repository.StringSetConverter;
import lombok.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.CascadeType;
import javax.persistence.Convert;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import java.time.OffsetDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import lombok.ToString;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import java.util.Set;

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(exclude = {"cohort", "transitions"})
@EqualsAndHashCode(exclude = {"cohort", "transitions","translations"})
public class Project implements Serializable {

@Id
Expand Down Expand Up @@ -105,11 +87,25 @@ public class Project implements Serializable {
inverseJoinColumns = @JoinColumn(name = "user_details_id"))
private List<UserDetails> researchers;

@JsonIgnore
@ToString.Exclude
@OneToMany(fetch = FetchType.LAZY)
@JoinColumnOrFormula(column = @JoinColumn(name = "property", referencedColumnName = "status", insertable = false, updatable = false))
@NotFound(action = NotFoundAction.IGNORE)
private Set<Translation> translations = new HashSet<>();

@ToString.Exclude
@JsonManagedReference
@OneToMany(mappedBy = "project", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<ProjectTransition> transitions = new HashSet<>();

public Project(Long id, String name, OffsetDateTime createDate, UserDetails coordinator) {
this.id = id;
this.name = name;
this.createDate = createDate;
this.coordinator = coordinator;
}

public boolean hasEmptyOrDifferentOwner(String userId) {
return ObjectUtils.isEmpty(coordinator) || !coordinator.getUserId().equals(userId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/vitagroup/num/domain/ProjectStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static List<ProjectStatus> getAllProjectStatusToViewAsCoordinator() {
}

public static List<ProjectStatus> getAllProjectStatusToViewAsResearcher() {
return Arrays.asList(ProjectStatus.PUBLISHED, ProjectStatus.CLOSED);
return Arrays.asList(ProjectStatus.PUBLISHED);
}

public static List<ProjectStatus> getAllProjectStatusToViewAsApprover() {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/de/vitagroup/num/domain/Translation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.vitagroup.num.domain;

import de.vitagroup.num.domain.dto.Language;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Translation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "entity_group", nullable = false)
@Enumerated(EnumType.STRING)
private EntityGroup entityGroup;

@Column(name = "entity_id")
private Long entityId;

@Column(nullable = false)
private String property;

@Column(nullable = false)
private String value;

@Column(name = "language_code", nullable = false)
@Enumerated(EnumType.STRING)
private Language language;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@NoArgsConstructor
public class CohortGroupDto {

@ApiModelProperty(value = "The unique identifier", example = "1")
@ApiModelProperty(value = "The unique identifier", example = "1", hidden = true)
private Long id;

@ApiModelProperty(value = "Cohort group operation to be applied to the children", example = "AND")
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/vitagroup/num/domain/dto/ProjectViewTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.OffsetDateTime;

@Data
@Builder
Expand All @@ -29,4 +30,6 @@ public class ProjectViewTO {

private LocalDate endDate;

private OffsetDateTime createDate;

}
7 changes: 7 additions & 0 deletions src/main/java/de/vitagroup/num/domain/dto/SearchCriteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class SearchCriteria {
// boolean flag used for users search/filter (optional)
public static final String FILTER_USER_WITH_ROLES_KEY = "withRoles";

private static final String AUTHOR_NAME = "author";

public static final String FILTER_BY_STATUS = "status";

private Map<String, ?> filter;

private String sort;
Expand All @@ -44,4 +48,7 @@ public boolean isValid() {
}
return true;
}
public boolean isSortByAuthor() {
return AUTHOR_NAME.equals(this.getSortBy());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.vitagroup.num.domain.Project;
import de.vitagroup.num.domain.ProjectStatus;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
Expand All @@ -23,4 +24,9 @@ public interface ProjectRepository extends JpaRepository<Project, Long>, CustomP
nativeQuery = true)
List<Project> findLatestProjects(
int count, String status1, String status2, String status3);


@Query(value = "SELECT new Project(pr.id, pr.name, pr.createDate, pr.coordinator) FROM Project pr " +
"WHERE pr.status IN (:statuses) ORDER BY pr.createDate DESC ")
List<Project> findByStatusInOrderByCreateDateDesc(List<ProjectStatus> statuses, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.vitagroup.num.domain.repository;

import de.vitagroup.num.domain.EntityGroup;
import de.vitagroup.num.domain.Organization;
import de.vitagroup.num.domain.Project;
import de.vitagroup.num.domain.admin.UserDetails;
Expand Down Expand Up @@ -44,7 +45,7 @@ public Page<Project> findProjects(ProjectSpecification projectSpecification, Pag
if (projectSpecification.getSortOrder() != null) {
Sort.Order sortOrder = projectSpecification.getSortOrder();
Expression<?> orderByExpression = null;
if (projectSpecification.getSortOrder().getProperty().equals("organization")) {
if (ProjectSpecification.COORDINATOR_ORGANIZATION.equals(projectSpecification.getSortOrder().getProperty())) {
Fetch<Project, UserDetails> coordinator = root.fetch("coordinator");
Fetch<UserDetails, Organization> organization = coordinator.fetch("organization", JoinType.LEFT);
Join<Project, UserDetails> coordinatorJoin = (Join<Project, UserDetails>) coordinator;
Expand All @@ -53,7 +54,16 @@ public Page<Project> findProjects(ProjectSpecification projectSpecification, Pag
groupByExpressions.add(organizationJoin.get("id"));
orderByExpression = organizationJoin.get("name");
} else {
if (!"author".equals(sortOrder.getProperty())) {
if (ProjectSpecification.COLUMN_PROJECT_STATUS.equals(projectSpecification.getSortOrder().getProperty())) {
Join<Object, Object> translationJoin = root.join("translations", JoinType.LEFT);
translationJoin.on(cb.and(
cb.equal(translationJoin.get("entityGroup"), EntityGroup.PROJECT_STATUS),
cb.equal(translationJoin.get("language"), projectSpecification.getLanguage()),
cb.equal(translationJoin.get("property"), root.get("status"))
));
groupByExpressions.add(translationJoin.get("value"));
orderByExpression = translationJoin.get("value");
} else if (!"author".equals(sortOrder.getProperty())) {
orderByExpression = root.get(sortOrder.getProperty());
}
}
Expand Down
Loading

0 comments on commit 3c1db7f

Please sign in to comment.