Skip to content

Commit

Permalink
Added: Action explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Nov 15, 2024
1 parent b8fc26b commit 660e4f9
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.0.1 - 2024-11-14]
## [0.0.1 - 2024-11-15]
### Added
- First version of the project
- Spring Application
Expand Down Expand Up @@ -155,3 +155,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Send emails in async execution pool
- Notification async execution pool
- Exporter async execution pool
- Action explanations
2 changes: 2 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public class ProjectManagerConst {
public final static String PROJECT_DEFAULT_EXPIRATION_TIME_IN_DAYS = "PROJECT_DEFAULT_EXPIRATION_TIME_IN_DAYS";
public final static String PROJECT_MANAGER_EMAIL_FROM = "PROJECT_MANAGER_EMAIL_FROM";
public final static String EMAIL_TEMPLATES_CONFIG = "EMAIL_TEMPLATES_CONFIG";
public final static String ACTION_EXPLANATION_CONFIG = "ACTION_EXPLANATION_CONFIG";
public final static String EMAIL_TEMPLATES_DIRECTORY = "EMAIL_TEMPLATES_DIRECTORY";
public final static String EXPORT_TEMPLATES = "EXPORT_TEMPLATES";
public final static String DATASHIELD_TEMPLATES = "DATASHIELD_TEMPLATES";
Expand Down Expand Up @@ -414,6 +415,7 @@ public class ProjectManagerConst {
public final static String PROJECT_MANAGER_EMAIL_FROM_SV =
HEAD_SV + PROJECT_MANAGER_EMAIL_FROM + ":[email protected]" + BOTTOM_SV;
public final static String EMAIL_TEMPLATES_CONFIG_SV = HEAD_SV + EMAIL_TEMPLATES_CONFIG + BOTTOM_SV;
public final static String ACTION_EXPLANATION_CONFIG_SV = HEAD_SV + ACTION_EXPLANATION_CONFIG + BOTTOM_SV;
public final static String EMAIL_TEMPLATES_DIRECTORY_SV = HEAD_SV + EMAIL_TEMPLATES_DIRECTORY + BOTTOM_SV;
public final static String EXPORT_TEMPLATES_SV = HEAD_SV + EXPORT_TEMPLATES + BOTTOM_SV;
public final static String DATASHIELD_TEMPLATES_SV = HEAD_SV + DATASHIELD_TEMPLATES + BOTTOM_SV;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/de/samply/email/EmailTemplatesFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
@Component
public class EmailTemplatesFactory {

private final ObjectMapper objectMapper = new ObjectMapper();

@Bean
public EmailTemplates createEmailTemplates(@Value(ProjectManagerConst.EMAIL_TEMPLATES_CONFIG_SV) String templates) throws JsonProcessingException {
Optional<String> decodedTemplates = Base64Utils.decodeIfNecessary(templates);
if (decodedTemplates.isEmpty()) {
throw new RuntimeException("No template found");
throw new RuntimeException("No email templates configuration found");
}
return objectMapper.readValue(decodedTemplates.get(), EmailTemplates.class);
return new ObjectMapper().readValue(decodedTemplates.get(), EmailTemplates.class);
}

}
43 changes: 43 additions & 0 deletions src/main/java/de/samply/frontend/ActionExplanation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.samply.frontend;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.samply.project.ProjectType;
import de.samply.project.state.ProjectBridgeheadState;
import de.samply.project.state.ProjectState;
import de.samply.query.QueryState;
import de.samply.user.roles.OrganisationRole;
import de.samply.user.roles.ProjectRole;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ActionExplanation {

private String module;
private String site;

@JsonProperty(value = "project-role")
private ProjectRole projectRole;
@JsonProperty(value = "organisation-role")
private OrganisationRole organisationRole;
@JsonProperty(value = "project-type")
private ProjectType projectType;
@JsonProperty(value = "project-state")
private ProjectState projectState;
@JsonProperty(value = "project-bridgehead-state")
private ProjectBridgeheadState projectBridgeheadState;
@JsonProperty(value = "query-state")
private QueryState queryState;

@JsonProperty(value = "messages", required = true)
private Map<String, String> languageMessageMap;

}
21 changes: 21 additions & 0 deletions src/main/java/de/samply/frontend/ActionExplanations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.samply.frontend;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.Map;
import java.util.Optional;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ActionExplanations {

@JsonProperty("explanations")
private Map<String, ActionExplanation> actionExplanationMap;

public Optional<ActionExplanation> getActionExplanation(String action) {
return Optional.ofNullable(actionExplanationMap.get(action));
}

}
25 changes: 25 additions & 0 deletions src/main/java/de/samply/frontend/ActionExplanationsFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.samply.frontend;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.samply.app.ProjectManagerConst;
import de.samply.utils.Base64Utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class ActionExplanationsFactory {

@Bean
public ActionExplanations actionExplanations(@Value(ProjectManagerConst.ACTION_EXPLANATION_CONFIG_SV) String template) throws JsonProcessingException {
Optional<String> decodedTemplates = Base64Utils.decodeIfNecessary(template);
if (decodedTemplates.isEmpty()) {
throw new RuntimeException("No action explanation config found");
}
return new ObjectMapper().readValue(decodedTemplates.get(), ActionExplanations.class);
}

}
9 changes: 9 additions & 0 deletions src/main/resources/action-explanations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"explanations": {
"CREATE_QUERY": {
"messages": {
"EN": "Please create the project"
}
}
}
}

0 comments on commit 660e4f9

Please sign in to comment.