Skip to content

Commit

Permalink
Merge pull request #13092 from SORMAS-Foundation/feature-13043_bulk_a…
Browse files Browse the repository at this point in the history
…ction_send_emails_with_uploaded_attached_docs

#13043 - Bulk action - send emails with uploaded attached documents
  • Loading branch information
sergiupacurariu authored Apr 30, 2024
2 parents 6f87098 + 60f748d commit 6803853
Show file tree
Hide file tree
Showing 53 changed files with 1,689 additions and 189 deletions.
35 changes: 35 additions & 0 deletions sormas-api/src/main/java/de/symeda/sormas/api/DocumentHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* ******************************************************************************
* * SORMAS® - Surveillance Outbreak Response Management & Analysis System
* * Copyright © 2016-2024 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <https://www.gnu.org/licenses/>.
* ******************************************************************************
*/

package de.symeda.sormas.api;

import de.symeda.sormas.api.utils.FileExtensionNotAllowedException;

public class DocumentHelper {

public static String getFileExtension(String fileName) {
int index = fileName.lastIndexOf('.');
if (index > 0) {
return fileName.substring(index);
} else {
throw new FileExtensionNotAllowedException(String.format("File name (%s) is not properly formatted", fileName));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* ******************************************************************************
* * SORMAS® - Surveillance Outbreak Response Management & Analysis System
* * Copyright © 2016-2024 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <https://www.gnu.org/licenses/>.
* ******************************************************************************
*/

package de.symeda.sormas.api.docgeneneration;

import java.io.Serializable;

import de.symeda.sormas.api.document.DocumentDto;

public class EmailAttachementDto implements Serializable {

private static final long serialVersionUID = -6376903475087381451L;

private final DocumentDto document;

private final byte[] content;

public EmailAttachementDto(DocumentDto document, byte[] content) {
this.document = document;
this.content = content;
}

public DocumentDto getDocument() {
return document;
}

public byte[] getContent() {
return content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import de.symeda.sormas.api.i18n.Validations;
Expand All @@ -33,8 +32,6 @@ public class DocumentDto extends PseudonymizableDto {
public static final String NAME = "name";
public static final String CONTENT_TYPE = "contentType";
public static final String SIZE = "size";
public static final String RELATED_ENTITY_UUID = "relatedEntityUuid";
public static final String RELATED_ENTITY_CLASS = "relatedEntityClass";

@NotNull(message = Validations.requiredField)
private UserReferenceDto uploadingUser;
Expand All @@ -46,12 +43,6 @@ public class DocumentDto extends PseudonymizableDto {
private String mimeType;
@NotNull(message = Validations.requiredField)
private long size;
@NotBlank(message = Validations.requiredField)
@Pattern(regexp = UUID_REGEX, message = Validations.patternNotMatching)
@Size(min = FieldConstraints.CHARACTER_LIMIT_UUID_MIN, max = FieldConstraints.CHARACTER_LIMIT_UUID_MAX, message = Validations.textSizeNotInRange)
private String relatedEntityUuid;
@NotNull(message = Validations.requiredField)
private DocumentRelatedEntityType relatedEntityType;

public static DocumentDto build() {
DocumentDto document = new DocumentDto();
Expand Down Expand Up @@ -92,23 +83,7 @@ public void setSize(long size) {
this.size = size;
}

public String getRelatedEntityUuid() {
return relatedEntityUuid;
public DocumentReferenceDto toReference() {
return new DocumentReferenceDto(getUuid(), name);
}

public void setRelatedEntityUuid(String relatedEntityUuid) {
this.relatedEntityUuid = relatedEntityUuid;
}

public DocumentRelatedEntityType getRelatedEntityType() {
return relatedEntityType;
}

public void setRelatedEntityType(DocumentRelatedEntityType relatedEntityType) {
this.relatedEntityType = relatedEntityType;
}

public DocumentReferenceDto toReference() {
return new DocumentReferenceDto(getUuid(), name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public interface DocumentFacade {

DocumentDto getDocumentByUuid(String uuid);

DocumentDto saveDocument(@Valid DocumentDto dto, byte[] bytes) throws IOException;
DocumentDto saveDocument(@Valid DocumentDto dto, byte[] bytes, List<DocumentRelatedEntityDto> relatedEntities) throws IOException;

void deleteDocument(String uuid);
void deleteDocument(String uuid, String relatedEntityUuids, DocumentRelatedEntityType relatedEntityType);

List<DocumentDto> getDocumentsRelatedToEntity(DocumentRelatedEntityType type, String uuid);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* ******************************************************************************
* * SORMAS® - Surveillance Outbreak Response Management & Analysis System
* * Copyright © 2016-2024 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <https://www.gnu.org/licenses/>.
* ******************************************************************************
*/

package de.symeda.sormas.api.document;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import de.symeda.sormas.api.i18n.Validations;
import de.symeda.sormas.api.utils.DataHelper;
import de.symeda.sormas.api.utils.FieldConstraints;
import de.symeda.sormas.api.utils.pseudonymization.PseudonymizableDto;

public class DocumentRelatedEntityDto extends PseudonymizableDto {

public static final String RELATED_ENTITY_UUID = "relatedEntityUuid";
public static final String RELATED_ENTITY_TYPE = "relatedEntityType";

@NotNull
private DocumentReferenceDto document;
@NotBlank(message = Validations.requiredField)
@Pattern(regexp = UUID_REGEX, message = Validations.patternNotMatching)
@Size(min = FieldConstraints.CHARACTER_LIMIT_UUID_MIN, max = FieldConstraints.CHARACTER_LIMIT_UUID_MAX, message = Validations.textSizeNotInRange)
private String relatedEntityUuid;
@NotNull(message = Validations.requiredField)
private DocumentRelatedEntityType relatedEntityType;

public DocumentRelatedEntityDto() {
}

public static DocumentRelatedEntityDto build(DocumentRelatedEntityType documentRelatedEntityType, String relatedEntityUuid) {
DocumentRelatedEntityDto documentRelatedEntities = new DocumentRelatedEntityDto();
documentRelatedEntities.setUuid(DataHelper.createUuid());
documentRelatedEntities.setRelatedEntityType(documentRelatedEntityType);
documentRelatedEntities.setRelatedEntityUuid(relatedEntityUuid);
return documentRelatedEntities;
}

public DocumentReferenceDto getDocument() {
return document;
}

public void setDocument(DocumentReferenceDto document) {
this.document = document;
}

public String getRelatedEntityUuid() {
return relatedEntityUuid;
}

public void setRelatedEntityUuid(String relatedEntityUuid) {
this.relatedEntityUuid = relatedEntityUuid;
}

public DocumentRelatedEntityType getRelatedEntityType() {
return relatedEntityType;
}

public void setRelatedEntityType(DocumentRelatedEntityType relatedEntityType) {
this.relatedEntityType = relatedEntityType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ******************************************************************************
* * SORMAS® - Surveillance Outbreak Response Management & Analysis System
* * Copyright © 2016-2024 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <https://www.gnu.org/licenses/>.
* ******************************************************************************
*/

package de.symeda.sormas.api.document;

import javax.ejb.Remote;

@Remote
public interface DocumentRelatedEntityFacade {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* ******************************************************************************
* * SORMAS® - Surveillance Outbreak Response Management & Analysis System
* * Copyright © 2016-2024 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <https://www.gnu.org/licenses/>.
* ******************************************************************************
*/

package de.symeda.sormas.api.externalemail;

public class AttachmentException extends Exception {

public AttachmentException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
/*
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
* Copyright © 2016-2023 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package de.symeda.sormas.api.externalemail;

import java.io.IOException;
import java.util.List;
import java.util.Set;

import javax.ejb.Remote;
import javax.validation.Valid;

import de.symeda.sormas.api.ReferenceDto;
import de.symeda.sormas.api.common.progress.ProcessedEntity;
import de.symeda.sormas.api.docgeneneration.DocumentTemplateException;
import de.symeda.sormas.api.docgeneneration.DocumentWorkflow;
import de.symeda.sormas.api.document.DocumentReferenceDto;
import de.symeda.sormas.api.person.PersonReferenceDto;
import de.symeda.sormas.api.utils.ValidationException;

@Remote
public interface ExternalEmailFacade {

List<String> getTemplateNames(DocumentWorkflow documentWorkflow);

List<DocumentReferenceDto> getAttachableDocuments(DocumentWorkflow documentWorkflow, String relatedEntityUuid);
List<DocumentReferenceDto> getAttachableDocuments(DocumentWorkflow documentWorkflow, String relatedEntityUuid);

void sendEmail(@Valid ExternalEmailOptionsDto options) throws DocumentTemplateException, ExternalEmailException;
void sendEmail(@Valid ExternalEmailOptionsDto options)
throws DocumentTemplateException, ExternalEmailException, AttachmentException, ValidationException;

boolean isAttachmentAvailable(PersonReferenceDto personReferenceDto);
List<ProcessedEntity> sendBulkEmail(@Valid ExternalEmailOptionsWithAttachmentsDto options, List<ReferenceDto> rootEntityReferences)
throws IOException;

boolean isAttachmentAvailable(PersonReferenceDto personReferenceDto);

Set<String> getAttachableFileExtensions();
}
Loading

0 comments on commit 6803853

Please sign in to comment.