Fixed problem with PersonNames when importing Persons
parent
67078ab385
commit
8f77d0726e
|
|
@ -20,6 +20,8 @@ package org.librecms.assets;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
|
@ -27,6 +29,9 @@ import java.util.Objects;
|
||||||
public class PersonImExporter
|
public class PersonImExporter
|
||||||
extends AbstractContactableEntityImExporter<Person> {
|
extends AbstractContactableEntityImExporter<Person> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PersonNameRepository personNameRepo;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<Person> getEntityClass() {
|
public Class<Person> getEntityClass() {
|
||||||
return Person.class;
|
return Person.class;
|
||||||
|
|
@ -46,9 +51,47 @@ public class PersonImExporter
|
||||||
existingContactable.getPersonNames(),
|
existingContactable.getPersonNames(),
|
||||||
importedContactable.getPersonNames()
|
importedContactable.getPersonNames()
|
||||||
)) {
|
)) {
|
||||||
existingContactable.setPersonNames(
|
// existingContactable.setPersonNames(
|
||||||
importedContactable.getPersonNames()
|
// importedContactable.getPersonNames()
|
||||||
);
|
// );
|
||||||
|
for (int i = 0;
|
||||||
|
i < existingContactable.getPersonNames().size()
|
||||||
|
&& i < importedContactable.getPersonNames().size();
|
||||||
|
i++) {
|
||||||
|
final PersonName existing = existingContactable
|
||||||
|
.getPersonNames()
|
||||||
|
.get(i);
|
||||||
|
final PersonName imported = importedContactable
|
||||||
|
.getPersonNames()
|
||||||
|
.get(i);
|
||||||
|
if (!Objects.equals(existing, imported)) {
|
||||||
|
existing.setGivenName(imported.getGivenName());
|
||||||
|
existing.setPrefix(imported.getPrefix());
|
||||||
|
existing.setSuffix(imported.getSuffix());
|
||||||
|
existing.setSurname(imported.getSurname());
|
||||||
|
|
||||||
|
personNameRepo.save(existing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (importedContactable.getPersonNames().size()
|
||||||
|
> existingContactable.getPersonNames().size()) {
|
||||||
|
for (int i = existingContactable.getPersonNames().size();
|
||||||
|
i < importedContactable.getPersonNames().size();
|
||||||
|
i++) {
|
||||||
|
final PersonName imported = importedContactable
|
||||||
|
.getPersonNames()
|
||||||
|
.get(i);
|
||||||
|
final PersonName newPersonName = new PersonName();
|
||||||
|
newPersonName.setGivenName(imported.getGivenName());
|
||||||
|
newPersonName.setPrefix(imported.getPrefix());
|
||||||
|
newPersonName.setSuffix(imported.getSuffix());
|
||||||
|
newPersonName.setSurname(imported.getSurname());
|
||||||
|
|
||||||
|
existingContactable.addPersonName(newPersonName);
|
||||||
|
personNameRepo.save(imported);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.equals(
|
if (!Objects.equals(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue