Skip to content

Commit

Permalink
Add Feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ramueSVA authored Nov 25, 2024
1 parent c194e1f commit 01f2f4d
Show file tree
Hide file tree
Showing 22 changed files with 1,058 additions and 591 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ And for intelliJ we include a [intellij-codestyle.xml](/.config/intellij-codesty
1. Add the file in Settings -> Editor -> Code Style -> Java
2. For the checkstyle-plugin you can add the file [checkstyle](/.config/checkstyle.xml) under Settings -> Tools -> Checkstyle -> Configuration File

### Feature

Within the backend, controllers that are defined as Featurable can be activated and deactivated.

Example:

```
(@ConditionalOnProperty(value = “feature.search-by-manager”, havingValue = “true”)
```
They are defined within the application.yml. This configuration is then picked up in the frontend and deactivated features are not displayed there.

## License

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/highmed/numportal/NumPortalApplication.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.highmed.numportal;


import org.highmed.numportal.properties.FeatureProperties;
import org.highmed.numportal.service.atna.AtnaProperties;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -12,7 +11,7 @@
@EnableScheduling
@EnableAsync
@SpringBootApplication
@EnableConfigurationProperties({AtnaProperties.class})
@EnableConfigurationProperties({AtnaProperties.class, FeatureProperties.class})
public class NumPortalApplication {

public static void main(String[] args) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/highmed/numportal/domain/dto/QueryDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.highmed.numportal.domain.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

@Data
@Schema
public class QueryDto {

@NotNull private String aql;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.highmed.numportal.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;


@Data
@ConfigurationProperties(prefix = "feature")
public class FeatureProperties {

private boolean searchByManager = false;

}
105 changes: 105 additions & 0 deletions src/main/java/org/highmed/numportal/service/ManagerService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.highmed.numportal.service;

import org.highmed.numportal.domain.dto.CohortDto;
import org.highmed.numportal.domain.model.ExportType;
import org.highmed.numportal.domain.model.Organization;
import org.highmed.numportal.domain.model.Project;
import org.highmed.numportal.domain.model.ProjectStatus;
import org.highmed.numportal.domain.model.admin.UserDetails;
import org.highmed.numportal.service.atna.AtnaService;
import org.highmed.numportal.service.exception.SystemException;
import org.highmed.numportal.service.util.ExportUtil;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.ehrbase.openehr.sdk.response.dto.QueryResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.highmed.numportal.domain.templates.ExceptionsTemplate.ERROR_WHILE_RETRIEVING_DATA;


@Service
@Slf4j
@AllArgsConstructor
public class ManagerService {

private final UserDetailsService userDetailsService;

private final AtnaService atnaService;

private final CohortService cohortService;

private final ExportUtil exportUtil;

private final ObjectMapper mapper;


public String executeManagerProject(CohortDto cohortDto, List<String> templates, String userId) {
var queryResponse = StringUtils.EMPTY;
var project = createManagerProject();
try {
userDetailsService.checkIsUserApproved(userId);
var templateMap = CollectionUtils.isNotEmpty(templates) ? templates.stream().collect(Collectors.toMap(k -> k, v -> v)) : Collections.emptyMap();
List<QueryResponseData> responseData =
exportUtil.executeDefaultConfiguration(
project.getId(), cohortService.toCohort(cohortDto), (Map<String, String>) templateMap);
queryResponse = mapper.writeValueAsString(responseData);

} catch (Exception e) {
atnaService.logDataExport(userId, project.getId(), project, false);
throw new SystemException(ProjectService.class, ERROR_WHILE_RETRIEVING_DATA,
String.format(ERROR_WHILE_RETRIEVING_DATA, e.getLocalizedMessage()));
}
atnaService.logDataExport(userId, project.getId(), project, true);
return queryResponse;
}

public StreamingResponseBody getManagerExportResponseBody(CohortDto cohortDto, List<String> templates, String userId, ExportType format) {
userDetailsService.checkIsUserApproved(userId);
var project = createManagerProject();

var templateMap = templates.stream().collect(Collectors.toMap(k -> k, v -> v));

List<QueryResponseData> response =
exportUtil.executeDefaultConfiguration(
project.getId(), cohortService.toCohort(cohortDto), templateMap);

if (format == ExportType.json) {
return exportUtil.exportJson(response);
} else {
return exportUtil.exportCsv(response, project.getId());
}
}

private Project createManagerProject() {
var undef = "undef";
return Project.builder()
.id(0L)
.name("Manager data retrieval project")
.createDate(OffsetDateTime.now())
.startDate(LocalDate.now())
.description("Adhoc temp project for manager data retrieval")
.goal(undef)
.usedOutsideEu(false)
.firstHypotheses(undef)
.secondHypotheses(undef)
.description("Temporary project for manager data retrieval")
.coordinator(UserDetails.builder().userId(undef).organization(Organization.builder().id(0L).build()).build())
.status(ProjectStatus.DENIED)
.build();
}


}
Loading

0 comments on commit 01f2f4d

Please sign in to comment.