Skip to content

Commit

Permalink
Added: Last document variables in email context
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Dec 2, 2024
1 parent 8170f6a commit 44d722e
Show file tree
Hide file tree
Showing 5 changed files with 36 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-29]
## [0.0.1 - 2024-12-02]
### Added
- First version of the project
- Spring Application
Expand Down Expand Up @@ -168,3 +168,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Email context project bridgeheads variable
- Decode Base64 values of email context
- Enable minus in variables of email context
- Last document variables in email context
7 changes: 7 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ public class ProjectManagerConst {
public final static String EMAIL_CONTEXT_EMAIL_TO_FIRST_NAME = "email-to-first-name";
public final static String EMAIL_CONTEXT_EMAIL_TO_LAST_NAME = "email-to-last-name";
public final static String EMAIL_CONTEXT_EMAIL_TO_NAME = "email-to-name";
public final static String EMAIL_CONTEXT_LAST_DOCUMENT_LABEL = "last-document-label";
public final static String EMAIL_CONTEXT_LAST_DOCUMENT_FILENAME = "last-document-filename";
public final static String EMAIL_CONTEXT_LAST_DOCUMENT_URL = "last-document-url";
public final static String EMAIL_CONTEXT_LAST_DOCUMENT_SENDER_NAME = "last-document-url-sender-name";
public final static String EMAIL_CONTEXT_LAST_DOCUMENT_SENDER_FIRST_NAME = "last-document-url-sender-first-name";
public final static String EMAIL_CONTEXT_LAST_DOCUMENT_SENDER_LAST_NAME = "last-document-url-sender-last-name";
public final static String EMAIL_CONTEXT_LAST_DOCUMENT_SENDER_EMAIL = "last-document-url-sender-email";


public final static String[] EMAIL_CONTEXT_VARIABLES = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface ProjectDocumentRepository extends JpaRepository<ProjectDocument

Optional<ProjectDocument> findFirstByProjectAndDocumentTypeAndBridgeheadOrderByCreatedAtDesc(Project project, DocumentType documentType, String bridgehead);

Optional<ProjectDocument> findTopByProjectOrderByCreatedAtDesc(Project project);

List<ProjectDocument> findAllByProjectAndDocumentTypeOrderByLabelAsc(Project project, DocumentType documentType);

@Query("SELECT pd FROM ProjectDocument pd WHERE (pd.bridgehead = :bridgehead OR pd.bridgehead = 'NONE') " +
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/de/samply/email/EmailKeyValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.samply.db.model.ProjectBridgeheadUser;
import de.samply.db.model.Query;
import de.samply.db.repository.ProjectBridgeheadRepository;
import de.samply.db.repository.ProjectDocumentRepository;
import de.samply.db.repository.ProjectRepository;
import de.samply.db.repository.UserRepository;
import de.samply.frontend.FrontendService;
Expand All @@ -29,19 +30,22 @@ public class EmailKeyValues {
private final ProjectRepository projectRepository;
private final UserRepository userRepository;
private final BridgeheadConfiguration bridgeheadConfiguration;
private final ProjectDocumentRepository projectDocumentRepository;


public EmailKeyValues(FrontendService frontendService,
EmailContext emailContext,
ProjectBridgeheadRepository projectBridgeheadRepository,
ProjectRepository projectRepository,
UserRepository userRepository,
BridgeheadConfiguration bridgeheadConfiguration) {
BridgeheadConfiguration bridgeheadConfiguration,
ProjectDocumentRepository projectDocumentRepository) {
this.frontendService = frontendService;
this.projectBridgeheadRepository = projectBridgeheadRepository;
this.projectRepository = projectRepository;
this.userRepository = userRepository;
this.bridgeheadConfiguration = bridgeheadConfiguration;
this.projectDocumentRepository = projectDocumentRepository;
keyValues.putAll(emailContext.getContext());
}

Expand Down Expand Up @@ -141,6 +145,7 @@ public EmailKeyValues add(Project project) {
addKeyValue(ProjectManagerConst.EMAIL_CONTEXT_PROJECT_TYPE, () -> project.getType().toString());
add(project.getQuery());
addBridgeheads(project);
addLastDocument(project);
}
return this;
}
Expand All @@ -152,6 +157,19 @@ private void addBridgeheads(Project project) {
.collect(Collectors.joining(",")));
}

private void addLastDocument(Project project) {
projectDocumentRepository.findTopByProjectOrderByCreatedAtDesc(project).ifPresent(projectDocument -> {
addKeyValue(ProjectManagerConst.EMAIL_CONTEXT_LAST_DOCUMENT_LABEL, projectDocument::getLabel);
addKeyValue(ProjectManagerConst.EMAIL_CONTEXT_LAST_DOCUMENT_FILENAME, projectDocument::getOriginalFilename);
addKeyValue(ProjectManagerConst.EMAIL_CONTEXT_LAST_DOCUMENT_URL, projectDocument::getUrl);
addEmailData(projectDocument.getCreatorEmail(),
ProjectManagerConst.EMAIL_CONTEXT_LAST_DOCUMENT_SENDER_EMAIL,
ProjectManagerConst.EMAIL_CONTEXT_LAST_DOCUMENT_SENDER_FIRST_NAME,
ProjectManagerConst.EMAIL_CONTEXT_LAST_DOCUMENT_SENDER_LAST_NAME,
ProjectManagerConst.EMAIL_CONTEXT_LAST_DOCUMENT_SENDER_NAME);
});
}

public EmailKeyValues add(Query query) {
if (query != null) {
addKeyValue(ProjectManagerConst.EMAIL_CONTEXT_QUERY,
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/de/samply/email/EmailKeyValuesFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.samply.bridgehead.BridgeheadConfiguration;
import de.samply.db.repository.ProjectBridgeheadRepository;
import de.samply.db.repository.ProjectDocumentRepository;
import de.samply.db.repository.ProjectRepository;
import de.samply.db.repository.UserRepository;
import de.samply.frontend.FrontendService;
Expand All @@ -16,24 +17,27 @@ public class EmailKeyValuesFactory {
private final ProjectRepository projectRepository;
private final UserRepository userRepository;
private final BridgeheadConfiguration bridgeheadConfiguration;
private final ProjectDocumentRepository projectDocumentRepository;

public EmailKeyValuesFactory(FrontendService frontendService,
EmailContext emailContext,
ProjectBridgeheadRepository projectBridgeheadRepository,
ProjectRepository projectRepository,
UserRepository userRepository,
BridgeheadConfiguration bridgeheadConfiguration) {
BridgeheadConfiguration bridgeheadConfiguration,
ProjectDocumentRepository projectDocumentRepository) {
this.frontendService = frontendService;
this.emailContext = emailContext;
this.projectBridgeheadRepository = projectBridgeheadRepository;
this.projectRepository = projectRepository;
this.userRepository = userRepository;
this.bridgeheadConfiguration = bridgeheadConfiguration;
this.projectDocumentRepository = projectDocumentRepository;
}

public EmailKeyValues newInstance() {
return new EmailKeyValues(frontendService, emailContext, projectBridgeheadRepository, projectRepository,
userRepository, bridgeheadConfiguration);
userRepository, bridgeheadConfiguration, projectDocumentRepository);
}

}

0 comments on commit 44d722e

Please sign in to comment.