Managers for complex associations between publication entities
parent
9ed08ad047
commit
6d457cb538
|
|
@ -10,7 +10,6 @@ import org.hibernate.envers.Audited;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.scientificcms.publications;
|
||||||
|
|
||||||
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class CollectedVolumeManager implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublicationRepository publicationRepository;
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void addArticleToCollectedVolume(
|
||||||
|
final ArticleInCollectedVolume article,
|
||||||
|
final CollectedVolume collectedVolume
|
||||||
|
) {
|
||||||
|
Objects.requireNonNull(article);
|
||||||
|
Objects.requireNonNull(collectedVolume);
|
||||||
|
|
||||||
|
article.setCollectedVolume(collectedVolume);
|
||||||
|
collectedVolume.addArticle(article);
|
||||||
|
|
||||||
|
publicationRepository.save(article);
|
||||||
|
publicationRepository.save(collectedVolume);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void removeArticleFromCollectedVolume(
|
||||||
|
final ArticleInCollectedVolume article,
|
||||||
|
final CollectedVolume collectedVolume
|
||||||
|
) {
|
||||||
|
Objects.requireNonNull(article);
|
||||||
|
Objects.requireNonNull(collectedVolume);
|
||||||
|
|
||||||
|
if (!collectedVolume.equals(article.getCollectedVolume())
|
||||||
|
|| !collectedVolume.getArticles().contains(article)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"The provided article %s is not an article of the "
|
||||||
|
+ "provided collected volume %s.",
|
||||||
|
article.getUuid(),
|
||||||
|
collectedVolume.getUuid()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
article.setCollectedVolume(null);
|
||||||
|
collectedVolume.removeArticle(article);
|
||||||
|
|
||||||
|
publicationRepository.save(article);
|
||||||
|
publicationRepository.save(collectedVolume);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.scientificcms.publications;
|
||||||
|
|
||||||
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class JournalManager {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private JournalRepository journalRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublicationRepository publicationRepository;
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void addArticleToJournal(final ArticleInJournal article,
|
||||||
|
final Journal journal) {
|
||||||
|
Objects.requireNonNull(article);
|
||||||
|
Objects.requireNonNull(journal);
|
||||||
|
|
||||||
|
article.setJournal(journal);
|
||||||
|
journal.addArticle(article);
|
||||||
|
|
||||||
|
publicationRepository.save(article);
|
||||||
|
journalRepository.save(journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void removeArticleFromJournal(final ArticleInJournal article,
|
||||||
|
final Journal journal) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(article);
|
||||||
|
Objects.requireNonNull(journal);
|
||||||
|
|
||||||
|
if (!journal.equals(article.getJournal())
|
||||||
|
|| !journal.getArticles().contains(article)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"The provided article %s is not an article of the "
|
||||||
|
+ "provided journal %s.",
|
||||||
|
article.getUuid(),
|
||||||
|
journal.getUuid()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
article.setJournal(null);
|
||||||
|
journal.removeArticle(article);
|
||||||
|
|
||||||
|
publicationRepository.save(article);
|
||||||
|
journalRepository.save(journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,8 @@ package org.scientificcms.publications;
|
||||||
|
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
|
@ -35,4 +37,10 @@ public class JournalRepository extends AbstractEntityRepository<Long, Journal>{
|
||||||
return entity.getJournalId() == 0;
|
return entity.getJournalId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initNewEntity(final Journal entity) {
|
||||||
|
entity.setUuid(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.scientificcms.publications;
|
||||||
|
|
||||||
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class ProceedingsManager {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublicationRepository publicationRepository;
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void addPaperToCollectedVolume(final InProceedings paper,
|
||||||
|
final Proceedings proceedings) {
|
||||||
|
Objects.requireNonNull(paper);
|
||||||
|
Objects.requireNonNull(proceedings);
|
||||||
|
|
||||||
|
paper.setProceedings(proceedings);
|
||||||
|
proceedings.addPaper(paper);
|
||||||
|
|
||||||
|
publicationRepository.save(paper);
|
||||||
|
publicationRepository.save(proceedings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void removeArticleFromCollectedVolume(
|
||||||
|
final InProceedings paper,
|
||||||
|
final Proceedings collectedVolume
|
||||||
|
) {
|
||||||
|
Objects.requireNonNull(paper);
|
||||||
|
Objects.requireNonNull(collectedVolume);
|
||||||
|
|
||||||
|
if (!collectedVolume.equals(paper.getProceedings())
|
||||||
|
|| !collectedVolume.getPapers().contains(paper)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"The provided paper %s is not a paper of the "
|
||||||
|
+ "provided proceedings %s.",
|
||||||
|
paper.getUuid(),
|
||||||
|
collectedVolume.getUuid()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
paper.setProceedings(null);
|
||||||
|
collectedVolume.removePaper(paper);
|
||||||
|
|
||||||
|
publicationRepository.save(paper);
|
||||||
|
publicationRepository.save(collectedVolume);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -31,6 +31,9 @@ public class PublicationManager {
|
||||||
@Inject
|
@Inject
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void addAuthor(final Person person,
|
public void addAuthor(final Person person,
|
||||||
final Publication toPublication) {
|
final Publication toPublication) {
|
||||||
|
|
||||||
|
|
@ -43,6 +46,9 @@ public class PublicationManager {
|
||||||
toPublication.getAuthorships().size());
|
toPublication.getAuthorships().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void addAuthor(final Person person,
|
public void addAuthor(final Person person,
|
||||||
final Publication toPublication,
|
final Publication toPublication,
|
||||||
final boolean asEditor) {
|
final boolean asEditor) {
|
||||||
|
|
@ -69,7 +75,7 @@ public class PublicationManager {
|
||||||
public void addAuthor(final Person person,
|
public void addAuthor(final Person person,
|
||||||
final Publication toPublication,
|
final Publication toPublication,
|
||||||
final boolean asEditor,
|
final boolean asEditor,
|
||||||
final long atPosition) {
|
final int atPosition) {
|
||||||
|
|
||||||
Objects.requireNonNull(person);
|
Objects.requireNonNull(person);
|
||||||
Objects.requireNonNull(toPublication);
|
Objects.requireNonNull(toPublication);
|
||||||
|
|
@ -115,6 +121,9 @@ public class PublicationManager {
|
||||||
publicationRepository.save(toPublication);
|
publicationRepository.save(toPublication);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void removeAuthor(final Person author,
|
public void removeAuthor(final Person author,
|
||||||
final Publication fromPublication) {
|
final Publication fromPublication) {
|
||||||
|
|
||||||
|
|
@ -125,17 +134,179 @@ public class PublicationManager {
|
||||||
.findAny();
|
.findAny();
|
||||||
|
|
||||||
if (!result.isPresent()) {
|
if (!result.isPresent()) {
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Authorship remove = result.get();
|
final Authorship remove = result.get();
|
||||||
fromPublication.removeAuthorship(remove);
|
fromPublication.removeAuthorship(remove);
|
||||||
|
|
||||||
for(int i = 0; i < fromPublication.getAuthorships().size(); i++) {
|
for (int i = 0; i < fromPublication.getAuthorships().size(); i++) {
|
||||||
fromPublication.getAuthorships().get(i).setAuthorOrder(i);
|
fromPublication.getAuthorships().get(i).setAuthorOrder(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
entityManager.remove(remove);
|
entityManager.remove(remove);
|
||||||
publicationRepository.save(fromPublication);
|
publicationRepository.save(fromPublication);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void moveAuthorToPosition(final Publication ofPublication,
|
||||||
|
final Person author,
|
||||||
|
final int toPosition) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(ofPublication);
|
||||||
|
Objects.requireNonNull(author);
|
||||||
|
if (toPosition < 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Can't move author to a negative position."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Optional<Authorship> result = ofPublication
|
||||||
|
.getAuthorships()
|
||||||
|
.stream()
|
||||||
|
.filter(authorship -> authorship.getAuthor().equals(author))
|
||||||
|
.findAny();
|
||||||
|
|
||||||
|
if (result.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"Person %s is not an author of the publication %s.",
|
||||||
|
Objects.toString(author),
|
||||||
|
Objects.toString(ofPublication)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveAuthorshipToPosition(ofPublication, result.get(), toPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void moveAuthorshipToPosition(final Publication ofPublication,
|
||||||
|
final Authorship moving,
|
||||||
|
final int toPosition) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(ofPublication);
|
||||||
|
Objects.requireNonNull(moving);
|
||||||
|
if (toPosition < 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Can't move author to a negative position."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toPosition < moving.getAuthorOrder()) {
|
||||||
|
ofPublication
|
||||||
|
.getAuthorships()
|
||||||
|
.stream()
|
||||||
|
.filter(
|
||||||
|
authorship -> authorship.getAuthorOrder() >= toPosition
|
||||||
|
&& authorship.getAuthorOrder()
|
||||||
|
< moving.getAuthorOrder()
|
||||||
|
)
|
||||||
|
.forEach(
|
||||||
|
authorship -> authorship.setAuthorOrder(
|
||||||
|
authorship.getAuthorOrder() + 1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
moving.setAuthorOrder(toPosition);
|
||||||
|
|
||||||
|
} else if (toPosition > moving.getAuthorOrder()) {
|
||||||
|
ofPublication
|
||||||
|
.getAuthorships()
|
||||||
|
.stream()
|
||||||
|
.filter(
|
||||||
|
authorship -> authorship.getAuthorOrder() > moving
|
||||||
|
.getAuthorOrder()
|
||||||
|
&& authorship.getAuthorOrder()
|
||||||
|
<= toPosition
|
||||||
|
)
|
||||||
|
.forEach(
|
||||||
|
authorship -> authorship.setAuthorOrder(
|
||||||
|
authorship.getAuthorOrder() - 1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
publicationRepository.save(ofPublication);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void swapWithPrevious(final Publication publication,
|
||||||
|
final Authorship authorship) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(publication);
|
||||||
|
Objects.requireNonNull(authorship);
|
||||||
|
|
||||||
|
if (!publication.getAuthorships().contains(authorship)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"Provided Authorship entity %s is not part of "
|
||||||
|
+ "the provided Publication entity %s.",
|
||||||
|
Objects.toString(authorship),
|
||||||
|
Objects.toString(publication)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authorship.getAuthorOrder() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Authorship previous = publication
|
||||||
|
.getAuthorships()
|
||||||
|
.get((int) authorship.getAuthorOrder() - 1);
|
||||||
|
final long previousOrder = previous.getAuthorOrder();
|
||||||
|
final long movingOrder = authorship.getAuthorOrder();
|
||||||
|
|
||||||
|
previous.setAuthorOrder(movingOrder);
|
||||||
|
authorship.setAuthorOrder(previousOrder);
|
||||||
|
|
||||||
|
publicationRepository.save(publication);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void swapWithNext(final Publication publication,
|
||||||
|
final Authorship authorship) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(publication);
|
||||||
|
Objects.requireNonNull(authorship);
|
||||||
|
|
||||||
|
if (!publication.getAuthorships().contains(authorship)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"Provided Authorship entity %s is not part of "
|
||||||
|
+ "the provided Publication entity %s.",
|
||||||
|
Objects.toString(authorship),
|
||||||
|
Objects.toString(publication)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authorship.getAuthorOrder() > publication
|
||||||
|
.getAuthorships().size() - 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Authorship next = publication
|
||||||
|
.getAuthorships()
|
||||||
|
.get((int) authorship.getAuthorOrder() + 1);
|
||||||
|
final long nextOrder = next.getAuthorOrder();
|
||||||
|
final long movingOrder = authorship.getAuthorOrder();
|
||||||
|
|
||||||
|
next.setAuthorOrder(movingOrder);
|
||||||
|
authorship.setAuthorOrder(nextOrder);
|
||||||
|
|
||||||
|
publicationRepository.save(publication);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ package org.scientificcms.publications;
|
||||||
|
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,4 +41,10 @@ public class PublicationRepository
|
||||||
return Publication.class;
|
return Publication.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initNewEntity(final Publication entity) {
|
||||||
|
final String uuid = UUID.randomUUID().toString();
|
||||||
|
entity.setUuid(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.scientificcms.publications;
|
||||||
|
|
||||||
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class PublisherManager {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublicationRepository publicationRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublisherRepository publisherRepository;
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void addPublicationToPublisher(
|
||||||
|
final PublicationWithPublisher publication,
|
||||||
|
final Publisher publisher
|
||||||
|
) {
|
||||||
|
Objects.requireNonNull(publication);
|
||||||
|
Objects.requireNonNull(publisher);
|
||||||
|
|
||||||
|
publication.setPublisher(publisher);
|
||||||
|
publisher.addPublication(publication);
|
||||||
|
|
||||||
|
publicationRepository.save(publication);
|
||||||
|
publisherRepository.save(publisher);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(ItemPrivileges.EDIT)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public void removePublicationFromPublisher(
|
||||||
|
final PublicationWithPublisher publication,
|
||||||
|
final Publisher publisher
|
||||||
|
) {
|
||||||
|
Objects.requireNonNull(publication);
|
||||||
|
Objects.requireNonNull(publisher);
|
||||||
|
|
||||||
|
if (!publisher.equals(publication.getPublisher())
|
||||||
|
|| !publisher.getPublications().contains(publication)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"The provided publication %s is not an publication of the "
|
||||||
|
+ "provided publisher %s.",
|
||||||
|
publication.getUuid(),
|
||||||
|
publisher.getUuid()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
publication.setPublisher(null);
|
||||||
|
publisher.removePublication(publication);
|
||||||
|
|
||||||
|
publicationRepository.save(publication);
|
||||||
|
publisherRepository.save(publisher);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,12 +7,14 @@ package org.scientificcms.publications;
|
||||||
|
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class PublisherRepository
|
public class PublisherRepository
|
||||||
extends AbstractEntityRepository<Long, Publisher>{
|
extends AbstractEntityRepository<Long, Publisher> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
@ -36,4 +38,9 @@ public class PublisherRepository
|
||||||
return entity.getPublisherId() == 0;
|
return entity.getPublisherId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initNewEntity(final Publisher entity) {
|
||||||
|
entity.setUuid(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue