Fixing a NPE.

deploy_packages_to_gitea
Jens Pelzetter 2023-01-26 19:33:01 +01:00
parent 677a187618
commit 321d5b0337
1 changed files with 7 additions and 14 deletions

View File

@ -51,7 +51,7 @@ import javax.transaction.Transactional;
public abstract class AbstractEntityImExporter<T extends Exportable> { public abstract class AbstractEntityImExporter<T extends Exportable> {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
@Inject @Inject
private EntityManager entityManager; private EntityManager entityManager;
@ -163,12 +163,12 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
if (existingEntityResult.isPresent()) { if (existingEntityResult.isPresent()) {
final T existingEntity = existingEntityResult.get(); final T existingEntity = existingEntityResult.get();
updateExistingEntity(existingEntity, importedEntity); updateExistingEntity(existingEntity, importedEntity);
entityManager.flush(); entityManager.flush();
return existingEntity; return existingEntity;
} else { } else {
saveImportedEntity(importedEntity); saveImportedEntity(importedEntity);
entityManager.flush(); entityManager.flush();
return importedEntity; return importedEntity;
} }
@ -255,7 +255,7 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
/** /**
* Reloads the entity to export. Entities become detacted for several * Reloads the entity to export. Entities become detacted for several
* reasons before they are passed to the null null null null null null null * reasons before they are passed to the null null null null null null null
* null null null null null null null {@link #exportEntity(org.libreccm.imexport.Exportable) method. The * null null null null null null null null {@link #exportEntity(org.libreccm.imexport.Exportable) method. The
* implementation of this should reload the passed entity. * implementation of this should reload the passed entity.
* *
* @param entity The entity to reload. * @param entity The entity to reload.
@ -278,6 +278,9 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
final LocalizedString source, final LocalizedString source,
final LocalizedString target final LocalizedString target
) { ) {
if (source == null || target == null) {
return;
}
final Set<Locale> localesToAdd = source final Set<Locale> localesToAdd = source
.getAvailableLocales() .getAvailableLocales()
.stream() .stream()
@ -286,16 +289,6 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
) )
.collect(Collectors.toSet()); .collect(Collectors.toSet());
final Set<Locale> localesToRemove = target
.getAvailableLocales()
.stream()
.filter(locale -> !source.getAvailableLocales().contains(locale))
.collect(Collectors.toSet());
for (final Locale toRemove : localesToRemove) {
target.removeValue(toRemove);
}
for (final Locale toAdd : localesToAdd) { for (final Locale toAdd : localesToAdd) {
target.putValue(toAdd, source.getValue(toAdd)); target.putValue(toAdd, source.getValue(toAdd));
} }