RED-3942 - Improve clone performance

This commit is contained in:
Timo Bejan 2022-05-23 20:28:39 +03:00
parent 06c9162b0f
commit e136be5bd4

View File

@ -123,7 +123,6 @@ public class DossierTemplateCloneService {
private void cloneDictionariesWithEntries(String dossierTemplateId, String clonedDossierTemplateId) {
var types = dictionaryPersistenceService.getAllTypesForDossierTemplate(dossierTemplateId, false);
for (TypeEntity t : types) {
var type = dictionaryPersistenceService.addType(t.getType(), clonedDossierTemplateId, t.getHexColor(), t.getRecommendationHexColor(), t.getRank(), t.isHint(), t.isCaseInsensitive(), t.isRecommendation(), t.getDescription(), t.isAddToDictionaryAction(), t.getLabel(), null, t.isHasDictionary(), t.isSystemManaged(), t.isAutoHideSkipped());
@ -190,15 +189,19 @@ public class DossierTemplateCloneService {
var reportTemplates = reportTemplatePersistenceService.findByDossierTemplateId(dossierTemplate.getId());
for (ReportTemplateEntity rte : reportTemplates) {
var storedReportTemplate = storageService.getObject(rte.getStorageId());
String storageId = clonedDossierTemplateId + "/" + rte.getFileName();
String templateId = UUID.randomUUID().toString();
try {
storageService.storeObject(storageId, storedReportTemplate.getInputStream());
} catch (IOException e) {
throw new ConflictException("Could not clone report templates of dossier template.");
if (storageService.objectExists(rte.getStorageId())) {
var storedReportTemplate = storageService.getObject(rte.getStorageId());
String storageId = clonedDossierTemplateId + "/" + rte.getFileName();
String templateId = UUID.randomUUID().toString();
try {
storageService.storeObject(storageId, storedReportTemplate.getInputStream());
} catch (IOException e) {
throw new ConflictException("Could not clone report templates of dossier template.");
}
reportTemplatePersistenceService.insert(clonedDossierTemplateId, templateId, storageId, rte.getFileName(), rte.isActiveByDefault(), rte.isMultiFileReport());
} else {
log.debug("Deleted Report-template {} will not be cloned", rte.getTemplateId());
}
reportTemplatePersistenceService.insert(clonedDossierTemplateId, templateId, storageId, rte.getFileName(), rte.isActiveByDefault(), rte.isMultiFileReport());
}
}