Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit fc94460

Browse files
committed
use DataHelper.getShortUuid for filename prefix (SORMAS-Foundation#4057)
1 parent 758d7c8 commit fc94460

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/utils/DataHelper.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
/*******************************************************************************
1+
/*
22
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
3-
* Copyright © 2016-2018 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
4-
*
3+
* Copyright © 2016-2021 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
54
* This program is free software: you can redistribute it and/or modify
65
* it under the terms of the GNU General Public License as published by
76
* the Free Software Foundation, either version 3 of the License, or
87
* (at your option) any later version.
9-
*
108
* This program is distributed in the hope that it will be useful,
119
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1210
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1311
* GNU General Public License for more details.
14-
*
1512
* You should have received a copy of the GNU General Public License
1613
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17-
*******************************************************************************/
14+
*/
15+
1816
package de.symeda.sormas.api.utils;
1917

2018
import java.io.BufferedReader;
@@ -35,7 +33,6 @@
3533
import java.util.TreeSet;
3634

3735
import de.symeda.sormas.api.AgeGroup;
38-
import de.symeda.sormas.api.EntityDto;
3936
import de.symeda.sormas.api.HasUuid;
4037
import de.symeda.sormas.api.Language;
4138
import de.symeda.sormas.api.caze.AgeAndBirthDateDto;
@@ -156,15 +153,15 @@ public static byte[] longToBytes(long x, long y) {
156153
return buffer.array();
157154
}
158155

159-
public static String getShortUuid(EntityDto domainObject) {
156+
public static String getShortUuid(HasUuid domainObject) {
160157
return getShortUuid(domainObject.getUuid());
161158
}
162159

163160
public static String getShortUuid(String uuid) {
164161

165162
if (uuid == null)
166163
return null;
167-
return uuid.substring(0, 6).toUpperCase();
164+
return uuid.substring(0, Math.min(uuid.length(), 6)).toUpperCase();
168165
}
169166

170167
public static class Pair<K, V> implements Serializable {

sormas-api/src/test/java/de/symeda/sormas/api/utils/DataHelperTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ public void testTryParseLong() {
4242
assertEquals((Long) Long.MAX_VALUE, DataHelper.tryParseLong(String.valueOf(Long.MAX_VALUE)));
4343
assertNull(DataHelper.tryParseLong(String.valueOf(Long.MAX_VALUE) + "0"));
4444
}
45+
46+
@Test
47+
public void testShortUuid() {
48+
assertEquals("A", DataHelper.getShortUuid("A"));
49+
assertEquals("UZOUEH", DataHelper.getShortUuid("UZOUEH-HP7DRG-YOJ74F-PXWL2JZ4"));
50+
assertNull(DataHelper.getShortUuid((String) null));
51+
}
4552
}

sormas-ui/src/main/java/de/symeda/sormas/ui/docgeneration/EventDocumentLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import de.symeda.sormas.api.i18n.Captions;
3131
import de.symeda.sormas.api.i18n.I18nProperties;
3232
import de.symeda.sormas.api.i18n.Strings;
33+
import de.symeda.sormas.api.utils.DataHelper;
3334

3435
public class EventDocumentLayout extends AbstractDocgenerationLayout {
3536

@@ -48,8 +49,7 @@ protected List<String> getAvailableTemplates() {
4849

4950
@Override
5051
protected String generateFilename(String templateFile) {
51-
String uuid = eventReferenceDto.getUuid();
52-
return uuid.substring(0, Math.min(5, uuid.length())) + "_" + templateFile;
52+
return DataHelper.getShortUuid(eventReferenceDto) + "_" + templateFile;
5353
}
5454

5555
@Override

sormas-ui/src/main/java/de/symeda/sormas/ui/docgeneration/QuarantineOrderLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import de.symeda.sormas.api.sample.SampleIndexDto;
4444
import de.symeda.sormas.api.sample.SampleReferenceDto;
4545
import de.symeda.sormas.api.user.UserReferenceDto;
46+
import de.symeda.sormas.api.utils.DataHelper;
4647
import de.symeda.sormas.api.utils.SortProperty;
4748
import de.symeda.sormas.ui.UserProvider;
4849

@@ -108,8 +109,7 @@ protected List<String> getAvailableTemplates() {
108109

109110
@Override
110111
protected String generateFilename(String templateFile) {
111-
String uuid = referenceDto.getUuid();
112-
return uuid.substring(0, Math.min(5, uuid.length())) + "_" + templateFile;
112+
return DataHelper.getShortUuid(referenceDto) + "_" + templateFile;
113113
}
114114

115115
@Override

0 commit comments

Comments
 (0)