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.UUID;
import javax.enterprise.context.RequestScoped;
import javax.persistence.NoResultException;
import javax.transaction.Transactional;
@ -18,6 +19,7 @@ import javax.transaction.Transactional;
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class JournalRepository extends AbstractEntityRepository<Long, Journal> {
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.PersonRepository;
import org.librecms.contentsection.AssetRepository;
import org.librecms.contentsection.ContentItemRepository;
import org.scientificcms.contenttypes.sciproject.Contact;
import org.scientificcms.contenttypes.sciproject.Membership;
import org.scientificcms.contenttypes.sciproject.MembershipStatus;
@ -69,6 +70,9 @@ class SciProjectController {
@Inject
private ConfigurationManager confManager;
@Inject
private ContentItemRepository contentItemRepository;
@Inject
private ContactableEntityRepository contactableRepository;
@ -100,7 +104,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getContacts(final long forProjectId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(forProjectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -131,7 +135,7 @@ class SciProjectController {
public Optional<Contact> findContact(final long projectId,
final Object key) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -153,7 +157,7 @@ class SciProjectController {
final long contactableId,
final String contactType) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -175,7 +179,7 @@ class SciProjectController {
final long contactableId,
final String contactType) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -199,14 +203,14 @@ class SciProjectController {
contact.get().setContactType(contactType);
projectRepository.save(project);
contentItemRepository.save(project);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void removeContact(final long projectId, final long contactId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -230,7 +234,7 @@ class SciProjectController {
public void swapWithPreviousContact(final long projectId,
final long contactId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -258,7 +262,7 @@ class SciProjectController {
contact.setOrder(prevOrder);
prevContact.setOrder(order);
projectRepository.save(project);
contentItemRepository.save(project);
}
}
@ -266,7 +270,7 @@ class SciProjectController {
public void swapWithNextContact(final long projectId,
final long contactId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -294,7 +298,7 @@ class SciProjectController {
contact.setOrder(nextOrder);
nextContact.setOrder(order);
projectRepository.save(project);
contentItemRepository.save(project);
}
}
@ -302,7 +306,7 @@ class SciProjectController {
public boolean hasContact(final long projectId,
final long contactableId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -325,7 +329,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getMembers(final long projectId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -366,7 +370,7 @@ class SciProjectController {
public Optional<Membership> findMembership(final long projectId,
final Object key) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -389,7 +393,7 @@ class SciProjectController {
final String role,
final String status) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -419,7 +423,7 @@ class SciProjectController {
final String role,
final String status) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -451,14 +455,14 @@ class SciProjectController {
membership.get().setRole(role);
membership.get().setStatus(membershipStatus);
projectRepository.save(project);
contentItemRepository.save(project);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void removeMember(final long projectId, final long membershipId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -480,7 +484,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED)
public boolean hasMember(final long projectId, final long memberId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -508,7 +512,7 @@ class SciProjectController {
final String descriptionText,
final Locale language) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -520,14 +524,14 @@ class SciProjectController {
desc.addValue(Objects.requireNonNull(language),
descriptionText);
projectRepository.save(project);
contentItemRepository.save(project);
}
@Transactional(Transactional.TxType.REQUIRED)
public Optional<Sponsoring> findSponsoring(final long projectId,
final Object key) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -547,7 +551,7 @@ class SciProjectController {
@Transactional(Transactional.TxType.REQUIRED)
public List<Map<String, Object>> getSponsors(final long forProjectId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(forProjectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -579,7 +583,7 @@ class SciProjectController {
final long sponsorId,
final String withFundingCode) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -597,7 +601,7 @@ class SciProjectController {
public void removeSponsor(final long projectId, final long sponsoringId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -619,7 +623,7 @@ class SciProjectController {
public boolean hasSponsor(final long projectId, final long sponsorId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -643,7 +647,7 @@ class SciProjectController {
final long sponsorId,
final String fundingCode) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -663,14 +667,14 @@ class SciProjectController {
final Sponsoring sponsoring = result.get();
sponsoring.setFundingCode(fundingCode);
projectRepository.save(project);
contentItemRepository.save(project);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void swapWithPrevSponsoring(final long projectId,
final long sponsoringId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -698,14 +702,14 @@ class SciProjectController {
sponsoring.setOrder(prevOrder);
prevSponsoring.setOrder(order);
projectRepository.save(project);
contentItemRepository.save(project);
}
}
@Transactional(Transactional.TxType.REQUIRED)
public void swapWithNextSponsoring(final long projectId,
final long sponsoringId) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -733,7 +737,7 @@ class SciProjectController {
sponsoring.setOrder(nextOrder);
nextSponsoring.setOrder(order);
projectRepository.save(project);
contentItemRepository.save(project);
}
}
@ -742,7 +746,7 @@ class SciProjectController {
final Locale locale,
final Map<String, Object> data) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -765,7 +769,7 @@ class SciProjectController {
project.getFundingVolume().addValue(locale, volume);
}
projectRepository.save(project);
contentItemRepository.save(project);
}
@Transactional(Transactional.TxType.REQUIRED)
@ -773,7 +777,7 @@ class SciProjectController {
final Locale selectedLocale,
final Map<String, Object> data) {
final SciProject project = projectRepository
final SciProject project = contentItemRepository
.findById(projectId, SciProject.class)
.orElseThrow(
() -> new IllegalArgumentException(
@ -795,7 +799,7 @@ class SciProjectController {
project.setEnd(endDate);
project.getShortDescription().addValue(selectedLocale, shortDesc);
projectRepository.save(project);
contentItemRepository.save(project);
}
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.Organization;
import org.librecms.assets.Person;
import org.librecms.contentsection.ContentItemRepository;
import java.io.Serializable;
import java.util.Objects;
@ -26,6 +27,9 @@ public class SciProjectMananger implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private ContentItemRepository contentItemRepository;
@Inject
private SciProjectRepository sciProjectRepository;
@ -47,7 +51,7 @@ public class SciProjectMananger implements Serializable {
toProject.addContact(contact);
sciProjectRepository.save(toProject);
contentItemRepository.save(toProject);
}
@Transactional(Transactional.TxType.REQUIRED)
@ -70,7 +74,7 @@ public class SciProjectMananger implements Serializable {
if (result.isPresent()) {
final Contact remove = result.get();
fromProject.removeContact(remove);
sciProjectRepository.save(fromProject);
contentItemRepository.save(fromProject);
}
}
@ -97,7 +101,7 @@ public class SciProjectMananger implements Serializable {
toProject.addMember(membership);
sciProjectRepository.save(toProject);
contentItemRepository.save(toProject);
}
@Transactional(Transactional.TxType.REQUIRED)
@ -124,7 +128,7 @@ public class SciProjectMananger implements Serializable {
if (result.isPresent()) {
final Membership remove = result.get();
fromProject.removeMembership(remove);
sciProjectRepository.save(fromProject);
contentItemRepository.save(fromProject);
}
}
@ -145,7 +149,7 @@ public class SciProjectMananger implements Serializable {
toProject.addSponsor(sponsoring);
sciProjectRepository.save(toProject);
contentItemRepository.save(toProject);
}
@Transactional(Transactional.TxType.REQUIRED)
@ -165,7 +169,7 @@ public class SciProjectMananger implements Serializable {
if (result.isPresent()) {
final Sponsoring sponsoring = result.get();
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.contentsection.ContentItemRepository;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
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>
*/
@RequestScoped
public class SciProjectRepository extends ContentItemRepository {
public class SciProjectRepository implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private EntityManager entityManager;
@Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereBeginIsBefore(final LocalDate date) {
return getEntityManager()
return entityManager
.createNamedQuery("SciProject.findWhereBeginIsBefore",
SciProject.class)
.setParameter("date", date)
@ -37,7 +49,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereBeginIs(final LocalDate date) {
return getEntityManager()
return entityManager
.createNamedQuery("SciProject.findWhereBeginIs", SciProject.class)
.setParameter("date", date)
.getResultList();
@ -46,7 +58,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereBeginIsAfter(final LocalDate date) {
return getEntityManager()
return entityManager
.createNamedQuery("SciProject.findWhereBeginIsAfter",
SciProject.class)
.setParameter("date", date)
@ -56,7 +68,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereEndIsBefore(final LocalDate date) {
return getEntityManager()
return entityManager
.createNamedQuery("SciProject.findWhereEndIsBefore",
SciProject.class)
.setParameter("date", date)
@ -65,7 +77,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereEndIs(final LocalDate date) {
return getEntityManager()
return entityManager
.createNamedQuery("SciProject.findWhereEndIs",
SciProject.class)
.setParameter("date", date)
@ -75,7 +87,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findWhereEndIsAfter(final LocalDate date) {
return getEntityManager()
return entityManager
.createNamedQuery("SciProject.findWhereEndIsAfter",
SciProject.class)
.setParameter("date", date)
@ -85,7 +97,7 @@ public class SciProjectRepository extends ContentItemRepository {
@Transactional(Transactional.TxType.REQUIRED)
public List<SciProject> findByMember(final Person member) {
return getEntityManager()
return entityManager
.createNamedQuery("SciProject.findByMember", SciProject.class)
.setParameter("member", member)
.getResultList();