Several bugfixes

pull/1/head
Jens Pelzetter 2020-02-16 19:59:29 +01:00
parent 4819e25c67
commit aefaea77b8
4 changed files with 71 additions and 49 deletions

View File

@ -11,6 +11,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import javax.enterprise.context.RequestScoped;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import javax.transaction.Transactional; import javax.transaction.Transactional;
@ -18,6 +19,7 @@ import javax.transaction.Transactional;
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped
public class JournalRepository extends AbstractEntityRepository<Long, Journal> { public class JournalRepository extends AbstractEntityRepository<Long, Journal> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -13,6 +13,7 @@ import org.librecms.assets.Organization;
import org.librecms.assets.Person; import org.librecms.assets.Person;
import org.librecms.assets.PersonRepository; import org.librecms.assets.PersonRepository;
import org.librecms.contentsection.AssetRepository; import org.librecms.contentsection.AssetRepository;
import org.librecms.contentsection.ContentItemRepository;
import org.scientificcms.contenttypes.sciproject.Contact; import org.scientificcms.contenttypes.sciproject.Contact;
import org.scientificcms.contenttypes.sciproject.Membership; import org.scientificcms.contenttypes.sciproject.Membership;
import org.scientificcms.contenttypes.sciproject.MembershipStatus; import org.scientificcms.contenttypes.sciproject.MembershipStatus;
@ -69,6 +70,9 @@ class SciProjectController {
@Inject @Inject
private ConfigurationManager confManager; private ConfigurationManager confManager;
@Inject
private ContentItemRepository contentItemRepository;
@Inject @Inject
private ContactableEntityRepository contactableRepository; private ContactableEntityRepository contactableRepository;
@ -100,7 +104,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getContacts(final long forProjectId) { public List<Map<String, Object>> getContacts(final long forProjectId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(forProjectId, SciProject.class) .findById(forProjectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -131,7 +135,7 @@ class SciProjectController {
public Optional<Contact> findContact(final long projectId, public Optional<Contact> findContact(final long projectId,
final Object key) { final Object key) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -153,7 +157,7 @@ class SciProjectController {
final long contactableId, final long contactableId,
final String contactType) { final String contactType) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -175,7 +179,7 @@ class SciProjectController {
final long contactableId, final long contactableId,
final String contactType) { final String contactType) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -199,14 +203,14 @@ class SciProjectController {
contact.get().setContactType(contactType); contact.get().setContactType(contactType);
projectRepository.save(project); contentItemRepository.save(project);
} }
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public void removeContact(final long projectId, final long contactId) { public void removeContact(final long projectId, final long contactId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -230,7 +234,7 @@ class SciProjectController {
public void swapWithPreviousContact(final long projectId, public void swapWithPreviousContact(final long projectId,
final long contactId) { final long contactId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -258,7 +262,7 @@ class SciProjectController {
contact.setOrder(prevOrder); contact.setOrder(prevOrder);
prevContact.setOrder(order); prevContact.setOrder(order);
projectRepository.save(project); contentItemRepository.save(project);
} }
} }
@ -266,7 +270,7 @@ class SciProjectController {
public void swapWithNextContact(final long projectId, public void swapWithNextContact(final long projectId,
final long contactId) { final long contactId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -294,7 +298,7 @@ class SciProjectController {
contact.setOrder(nextOrder); contact.setOrder(nextOrder);
nextContact.setOrder(order); nextContact.setOrder(order);
projectRepository.save(project); contentItemRepository.save(project);
} }
} }
@ -302,7 +306,7 @@ class SciProjectController {
public boolean hasContact(final long projectId, public boolean hasContact(final long projectId,
final long contactableId) { final long contactableId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -325,7 +329,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getMembers(final long projectId) { public List<Map<String, Object>> getMembers(final long projectId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -366,7 +370,7 @@ class SciProjectController {
public Optional<Membership> findMembership(final long projectId, public Optional<Membership> findMembership(final long projectId,
final Object key) { final Object key) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -389,7 +393,7 @@ class SciProjectController {
final String role, final String role,
final String status) { final String status) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -419,7 +423,7 @@ class SciProjectController {
final String role, final String role,
final String status) { final String status) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -451,14 +455,14 @@ class SciProjectController {
membership.get().setRole(role); membership.get().setRole(role);
membership.get().setStatus(membershipStatus); membership.get().setStatus(membershipStatus);
projectRepository.save(project); contentItemRepository.save(project);
} }
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public void removeMember(final long projectId, final long membershipId) { public void removeMember(final long projectId, final long membershipId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -480,7 +484,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public boolean hasMember(final long projectId, final long memberId) { public boolean hasMember(final long projectId, final long memberId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -508,7 +512,7 @@ class SciProjectController {
final String descriptionText, final String descriptionText,
final Locale language) { final Locale language) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -520,14 +524,14 @@ class SciProjectController {
desc.addValue(Objects.requireNonNull(language), desc.addValue(Objects.requireNonNull(language),
descriptionText); descriptionText);
projectRepository.save(project); contentItemRepository.save(project);
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public Optional<Sponsoring> findSponsoring(final long projectId, public Optional<Sponsoring> findSponsoring(final long projectId,
final Object key) { final Object key) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -547,7 +551,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getSponsors(final long forProjectId) { public List<Map<String, Object>> getSponsors(final long forProjectId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(forProjectId, SciProject.class) .findById(forProjectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -579,7 +583,7 @@ class SciProjectController {
final long sponsorId, final long sponsorId,
final String withFundingCode) { final String withFundingCode) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -597,7 +601,7 @@ class SciProjectController {
public void removeSponsor(final long projectId, final long sponsoringId) { public void removeSponsor(final long projectId, final long sponsoringId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -619,7 +623,7 @@ class SciProjectController {
public boolean hasSponsor(final long projectId, final long sponsorId) { public boolean hasSponsor(final long projectId, final long sponsorId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -643,7 +647,7 @@ class SciProjectController {
final long sponsorId, final long sponsorId,
final String fundingCode) { final String fundingCode) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -663,14 +667,14 @@ class SciProjectController {
final Sponsoring sponsoring = result.get(); final Sponsoring sponsoring = result.get();
sponsoring.setFundingCode(fundingCode); sponsoring.setFundingCode(fundingCode);
projectRepository.save(project); contentItemRepository.save(project);
} }
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public void swapWithPrevSponsoring(final long projectId, public void swapWithPrevSponsoring(final long projectId,
final long sponsoringId) { final long sponsoringId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -698,14 +702,14 @@ class SciProjectController {
sponsoring.setOrder(prevOrder); sponsoring.setOrder(prevOrder);
prevSponsoring.setOrder(order); prevSponsoring.setOrder(order);
projectRepository.save(project); contentItemRepository.save(project);
} }
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public void swapWithNextSponsoring(final long projectId, public void swapWithNextSponsoring(final long projectId,
final long sponsoringId) { final long sponsoringId) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -733,7 +737,7 @@ class SciProjectController {
sponsoring.setOrder(nextOrder); sponsoring.setOrder(nextOrder);
nextSponsoring.setOrder(order); nextSponsoring.setOrder(order);
projectRepository.save(project); contentItemRepository.save(project);
} }
} }
@ -742,7 +746,7 @@ class SciProjectController {
final Locale locale, final Locale locale,
final Map<String, Object> data) { final Map<String, Object> data) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -765,7 +769,7 @@ class SciProjectController {
project.getFundingVolume().addValue(locale, volume); project.getFundingVolume().addValue(locale, volume);
} }
projectRepository.save(project); contentItemRepository.save(project);
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -773,7 +777,7 @@ class SciProjectController {
final Locale selectedLocale, final Locale selectedLocale,
final Map<String, Object> data) { final Map<String, Object> data) {
final SciProject project = projectRepository final SciProject project = contentItemRepository
.findById(projectId, SciProject.class) .findById(projectId, SciProject.class)
.orElseThrow( .orElseThrow(
() -> new IllegalArgumentException( () -> new IllegalArgumentException(
@ -795,7 +799,7 @@ class SciProjectController {
project.setEnd(endDate); project.setEnd(endDate);
project.getShortDescription().addValue(selectedLocale, shortDesc); project.getShortDescription().addValue(selectedLocale, shortDesc);
projectRepository.save(project); contentItemRepository.save(project);
} }
private boolean filterContact(final Contact contact, private boolean filterContact(final Contact contact,

View File

@ -8,6 +8,7 @@ package org.scientificcms.contenttypes.sciproject;
import org.librecms.assets.ContactableEntity; import org.librecms.assets.ContactableEntity;
import org.librecms.assets.Organization; import org.librecms.assets.Organization;
import org.librecms.assets.Person; import org.librecms.assets.Person;
import org.librecms.contentsection.ContentItemRepository;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
@ -26,6 +27,9 @@ public class SciProjectMananger implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Inject
private ContentItemRepository contentItemRepository;
@Inject @Inject
private SciProjectRepository sciProjectRepository; private SciProjectRepository sciProjectRepository;
@ -47,7 +51,7 @@ public class SciProjectMananger implements Serializable {
toProject.addContact(contact); toProject.addContact(contact);
sciProjectRepository.save(toProject); contentItemRepository.save(toProject);
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -70,7 +74,7 @@ public class SciProjectMananger implements Serializable {
if (result.isPresent()) { if (result.isPresent()) {
final Contact remove = result.get(); final Contact remove = result.get();
fromProject.removeContact(remove); fromProject.removeContact(remove);
sciProjectRepository.save(fromProject); contentItemRepository.save(fromProject);
} }
} }
@ -97,7 +101,7 @@ public class SciProjectMananger implements Serializable {
toProject.addMember(membership); toProject.addMember(membership);
sciProjectRepository.save(toProject); contentItemRepository.save(toProject);
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -124,7 +128,7 @@ public class SciProjectMananger implements Serializable {
if (result.isPresent()) { if (result.isPresent()) {
final Membership remove = result.get(); final Membership remove = result.get();
fromProject.removeMembership(remove); fromProject.removeMembership(remove);
sciProjectRepository.save(fromProject); contentItemRepository.save(fromProject);
} }
} }
@ -145,7 +149,7 @@ public class SciProjectMananger implements Serializable {
toProject.addSponsor(sponsoring); toProject.addSponsor(sponsoring);
sciProjectRepository.save(toProject); contentItemRepository.save(toProject);
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
@ -165,7 +169,7 @@ public class SciProjectMananger implements Serializable {
if (result.isPresent()) { if (result.isPresent()) {
final Sponsoring sponsoring = result.get(); final Sponsoring sponsoring = result.get();
fromProject.removeSponsor(sponsoring); fromProject.removeSponsor(sponsoring);
sciProjectRepository.save(fromProject); contentItemRepository.save(fromProject);
} }
} }

View File

@ -8,25 +8,37 @@ package org.scientificcms.contenttypes.sciproject;
import org.librecms.assets.Person; import org.librecms.assets.Person;
import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentItemRepository;
import java.io.Serializable;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional; import javax.transaction.Transactional;
/** /**
* Repository providing queries for retrieving {@link SciProject} items.
*
* This repository does not provide method for saving or deleting
* {@link SciProject} items. Please use the {@link ContentItemRepository} to
* save or delete {@link SciProject} items.
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
@RequestScoped @RequestScoped
public class SciProjectRepository extends ContentItemRepository { public class SciProjectRepository implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Inject
private EntityManager entityManager;
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereBeginIsBefore(final LocalDate date) { public List<SciProject> findWhereBeginIsBefore(final LocalDate date) {
return getEntityManager() return entityManager
.createNamedQuery("SciProject.findWhereBeginIsBefore", .createNamedQuery("SciProject.findWhereBeginIsBefore",
SciProject.class) SciProject.class)
.setParameter("date", date) .setParameter("date", date)
@ -37,7 +49,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereBeginIs(final LocalDate date) { public List<SciProject> findWhereBeginIs(final LocalDate date) {
return getEntityManager() return entityManager
.createNamedQuery("SciProject.findWhereBeginIs", SciProject.class) .createNamedQuery("SciProject.findWhereBeginIs", SciProject.class)
.setParameter("date", date) .setParameter("date", date)
.getResultList(); .getResultList();
@ -46,7 +58,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereBeginIsAfter(final LocalDate date) { public List<SciProject> findWhereBeginIsAfter(final LocalDate date) {
return getEntityManager() return entityManager
.createNamedQuery("SciProject.findWhereBeginIsAfter", .createNamedQuery("SciProject.findWhereBeginIsAfter",
SciProject.class) SciProject.class)
.setParameter("date", date) .setParameter("date", date)
@ -56,7 +68,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereEndIsBefore(final LocalDate date) { public List<SciProject> findWhereEndIsBefore(final LocalDate date) {
return getEntityManager() return entityManager
.createNamedQuery("SciProject.findWhereEndIsBefore", .createNamedQuery("SciProject.findWhereEndIsBefore",
SciProject.class) SciProject.class)
.setParameter("date", date) .setParameter("date", date)
@ -65,7 +77,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereEndIs(final LocalDate date) { public List<SciProject> findWhereEndIs(final LocalDate date) {
return getEntityManager() return entityManager
.createNamedQuery("SciProject.findWhereEndIs", .createNamedQuery("SciProject.findWhereEndIs",
SciProject.class) SciProject.class)
.setParameter("date", date) .setParameter("date", date)
@ -75,7 +87,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereEndIsAfter(final LocalDate date) { public List<SciProject> findWhereEndIsAfter(final LocalDate date) {
return getEntityManager() return entityManager
.createNamedQuery("SciProject.findWhereEndIsAfter", .createNamedQuery("SciProject.findWhereEndIsAfter",
SciProject.class) SciProject.class)
.setParameter("date", date) .setParameter("date", date)
@ -85,7 +97,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findByMember(final Person member) { public List<SciProject> findByMember(final Person member) {
return getEntityManager() return entityManager
.createNamedQuery("SciProject.findByMember", SciProject.class) .createNamedQuery("SciProject.findByMember", SciProject.class)
.setParameter("member", member) .setParameter("member", member)
.getResultList(); .getResultList();