Changed handling of PersonName entity
parent
38851e6783
commit
67078ab385
|
|
@ -44,13 +44,11 @@ public class ContactEntryRepository
|
|||
|
||||
@Override
|
||||
public Long getIdOfEntity(final ContactEntry entity) {
|
||||
|
||||
return entity.getContactEntryId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew(final ContactEntry entity) {
|
||||
|
||||
return entity.getContactEntryId() == 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,11 +40,10 @@ public class ContactableEntityManager {
|
|||
|
||||
public void addContactEntryToContactableEntity(
|
||||
final ContactEntry contactEntry,
|
||||
final ContactableEntity contactableEntity) {
|
||||
|
||||
final ContactableEntity contactableEntity
|
||||
) {
|
||||
if (contactEntry.getOrder() == 0) {
|
||||
contactEntry
|
||||
.setOrder(contactableEntity.getContactEntries().size());
|
||||
contactEntry.setOrder(contactableEntity.getContactEntries().size());
|
||||
}
|
||||
contactableEntity.addContactEntry(contactEntry);
|
||||
entryRepository.save(contactEntry);
|
||||
|
|
@ -53,7 +52,8 @@ public class ContactableEntityManager {
|
|||
|
||||
public void removeContactEntryFromContactableEntity(
|
||||
final ContactEntry contactEntry,
|
||||
final ContactableEntity contactableEntity) {
|
||||
final ContactableEntity contactableEntity
|
||||
) {
|
||||
|
||||
contactableEntity.removeContactEntry(contactEntry);
|
||||
assetRepository.save(contactableEntity);
|
||||
|
|
@ -61,7 +61,8 @@ public class ContactableEntityManager {
|
|||
|
||||
public void addPostalAddressToContactableEntity(
|
||||
final PostalAddress postalAddress,
|
||||
final ContactableEntity contactableEntity) {
|
||||
final ContactableEntity contactableEntity
|
||||
) {
|
||||
|
||||
contactableEntity.setPostalAddress(postalAddress);
|
||||
assetRepository.save(postalAddress);
|
||||
|
|
@ -70,7 +71,8 @@ public class ContactableEntityManager {
|
|||
|
||||
public void removePostalAddressFromContactableEntity(
|
||||
final PostalAddress postalAddress,
|
||||
final ContactableEntity contactableEntity) {
|
||||
final ContactableEntity contactableEntity
|
||||
) {
|
||||
|
||||
contactableEntity.setPostalAddress(null);
|
||||
assetRepository.save(postalAddress);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
|
@ -31,33 +30,29 @@ import javax.transaction.Transactional;
|
|||
public class PersonManager {
|
||||
|
||||
@Inject
|
||||
private PersonRepository personRepository;
|
||||
private PersonRepository personRepo;
|
||||
|
||||
@Inject
|
||||
private PersonNameRepository personNameRepo;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
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);
|
||||
|
||||
personRepository.save(toPerson);
|
||||
personNameRepo.save(personName);
|
||||
personRepo.save(toPerson);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void removePersonName(final Person person,
|
||||
final PersonName personName) {
|
||||
|
||||
public void removePersonName(
|
||||
final Person person,
|
||||
final PersonName personName
|
||||
) {
|
||||
person.removePersonName(personName);
|
||||
|
||||
personRepository.save(person);
|
||||
personNameRepo.delete(personName);
|
||||
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