Changed handling of PersonName entity
parent
38851e6783
commit
67078ab385
|
|
@ -44,13 +44,11 @@ public class ContactEntryRepository
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getIdOfEntity(final ContactEntry entity) {
|
public Long getIdOfEntity(final ContactEntry entity) {
|
||||||
|
|
||||||
return entity.getContactEntryId();
|
return entity.getContactEntryId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNew(final ContactEntry entity) {
|
public boolean isNew(final ContactEntry entity) {
|
||||||
|
|
||||||
return entity.getContactEntryId() == 0;
|
return entity.getContactEntryId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,10 @@ public class ContactableEntityManager {
|
||||||
|
|
||||||
public void addContactEntryToContactableEntity(
|
public void addContactEntryToContactableEntity(
|
||||||
final ContactEntry contactEntry,
|
final ContactEntry contactEntry,
|
||||||
final ContactableEntity contactableEntity) {
|
final ContactableEntity contactableEntity
|
||||||
|
) {
|
||||||
if (contactEntry.getOrder() == 0) {
|
if (contactEntry.getOrder() == 0) {
|
||||||
contactEntry
|
contactEntry.setOrder(contactableEntity.getContactEntries().size());
|
||||||
.setOrder(contactableEntity.getContactEntries().size());
|
|
||||||
}
|
}
|
||||||
contactableEntity.addContactEntry(contactEntry);
|
contactableEntity.addContactEntry(contactEntry);
|
||||||
entryRepository.save(contactEntry);
|
entryRepository.save(contactEntry);
|
||||||
|
|
@ -53,7 +52,8 @@ public class ContactableEntityManager {
|
||||||
|
|
||||||
public void removeContactEntryFromContactableEntity(
|
public void removeContactEntryFromContactableEntity(
|
||||||
final ContactEntry contactEntry,
|
final ContactEntry contactEntry,
|
||||||
final ContactableEntity contactableEntity) {
|
final ContactableEntity contactableEntity
|
||||||
|
) {
|
||||||
|
|
||||||
contactableEntity.removeContactEntry(contactEntry);
|
contactableEntity.removeContactEntry(contactEntry);
|
||||||
assetRepository.save(contactableEntity);
|
assetRepository.save(contactableEntity);
|
||||||
|
|
@ -61,7 +61,8 @@ public class ContactableEntityManager {
|
||||||
|
|
||||||
public void addPostalAddressToContactableEntity(
|
public void addPostalAddressToContactableEntity(
|
||||||
final PostalAddress postalAddress,
|
final PostalAddress postalAddress,
|
||||||
final ContactableEntity contactableEntity) {
|
final ContactableEntity contactableEntity
|
||||||
|
) {
|
||||||
|
|
||||||
contactableEntity.setPostalAddress(postalAddress);
|
contactableEntity.setPostalAddress(postalAddress);
|
||||||
assetRepository.save(postalAddress);
|
assetRepository.save(postalAddress);
|
||||||
|
|
@ -70,7 +71,8 @@ public class ContactableEntityManager {
|
||||||
|
|
||||||
public void removePostalAddressFromContactableEntity(
|
public void removePostalAddressFromContactableEntity(
|
||||||
final PostalAddress postalAddress,
|
final PostalAddress postalAddress,
|
||||||
final ContactableEntity contactableEntity) {
|
final ContactableEntity contactableEntity
|
||||||
|
) {
|
||||||
|
|
||||||
contactableEntity.setPostalAddress(null);
|
contactableEntity.setPostalAddress(null);
|
||||||
assetRepository.save(postalAddress);
|
assetRepository.save(postalAddress);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.assets;
|
package org.librecms.assets;
|
||||||
|
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
@ -31,33 +30,29 @@ import javax.transaction.Transactional;
|
||||||
public class PersonManager {
|
public class PersonManager {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PersonRepository personRepository;
|
private PersonRepository personRepo;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PersonNameRepository personNameRepo;
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void addPersonName(
|
public void addPersonName(
|
||||||
final Person toPerson, final PersonName personName
|
final Person toPerson,
|
||||||
|
final PersonName personName
|
||||||
) {
|
) {
|
||||||
// final PersonName current = Objects
|
|
||||||
// .requireNonNull(toPerson, "Can't add a name to Person null.")
|
|
||||||
// .getPersonName();
|
|
||||||
//
|
|
||||||
// if (current == null) {
|
|
||||||
// toPerson.addPersonName(new PersonName());
|
|
||||||
// } else {
|
|
||||||
// toPerson.addPersonName(current);
|
|
||||||
// }
|
|
||||||
toPerson.addPersonName(personName);
|
toPerson.addPersonName(personName);
|
||||||
|
personNameRepo.save(personName);
|
||||||
personRepository.save(toPerson);
|
personRepo.save(toPerson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void removePersonName(final Person person,
|
public void removePersonName(
|
||||||
final PersonName personName) {
|
final Person person,
|
||||||
|
final PersonName personName
|
||||||
|
) {
|
||||||
person.removePersonName(personName);
|
person.removePersonName(personName);
|
||||||
|
personNameRepo.delete(personName);
|
||||||
personRepository.save(person);
|
personRepo.save(person);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.assets;
|
||||||
|
|
||||||
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class PersonNameRepository
|
||||||
|
extends AbstractEntityRepository<Long, PersonName> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<PersonName> getEntityClass() {
|
||||||
|
return PersonName.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdAttributeName() {
|
||||||
|
return "personNameId";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getIdOfEntity(final PersonName entity) {
|
||||||
|
return entity.getPersonNameId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNew(final PersonName entity) {
|
||||||
|
return entity.getPersonNameId() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue