use of cz.metacentrum.perun.cabinet.bl.CabinetException in project perun by CESNET.
the class ThanksManagerBlImpl method createThanks.
// methods -------------------------
public Thanks createThanks(PerunSession sess, Thanks t) throws CabinetException, InternalErrorException {
if (t.getCreatedDate() == null) {
t.setCreatedDate(new Date());
}
if (thanksExist(t)) {
throw new CabinetException("Can't create duplicate thanks.", ErrorCodes.THANKS_ALREADY_EXISTS);
}
t = getThanksManagerDao().createThanks(sess, t);
log.debug("{} created.", t);
// recalculate thanks for all publication's authors
List<Author> authors = new ArrayList<Author>();
authors = getAuthorshipManagerBl().getAuthorsByPublicationId(t.getPublicationId());
// sort to prevent locking
synchronized (ThanksManagerBlImpl.class) {
for (Author a : authors) {
getCabinetManagerBl().setThanksAttribute(a.getId());
}
}
return t;
}
use of cz.metacentrum.perun.cabinet.bl.CabinetException in project perun by CESNET.
the class PublicationManagerBlImpl method createPublication.
// business methods --------------------------------
@Override
public Publication createPublication(PerunSession sess, Publication p) throws CabinetException, InternalErrorException {
if (p.getCreatedDate() == null)
p.setCreatedDate(new Date());
p.setCreatedByUid(sess.getPerunPrincipal().getUserId());
// check existence
if (publicationExists(p)) {
throw new CabinetException("Cannot create duplicate publication: " + p, ErrorCodes.PUBLICATION_ALREADY_EXISTS);
}
Publication createdPublication;
if (p.getExternalId() == 0 && p.getPublicationSystemId() == 0) {
// get internal pub. system
PublicationSystem ps = getPublicationSystemManagerBl().getPublicationSystemByName("INTERNAL");
// There is only one internal system so, get(0) is safe
p.setPublicationSystemId(ps.getId());
}
stripLongParams(p);
createdPublication = getPublicationManagerDao().createPublication(sess, p);
log.debug("{} created.", createdPublication);
return createdPublication;
}
use of cz.metacentrum.perun.cabinet.bl.CabinetException in project perun by CESNET.
the class PublicationManagerBlImpl method deletePublication.
@Override
public void deletePublication(PerunSession sess, Publication publication) throws CabinetException, InternalErrorException {
try {
// delete authors
for (Authorship a : getAuthorshipManagerBl().getAuthorshipsByPublicationId(publication.getId())) {
getAuthorshipManagerBl().deleteAuthorship(sess, a);
}
// delete thanks
for (Thanks t : getThanksManagerBl().getThanksByPublicationId(publication.getId())) {
getThanksManagerBl().deleteThanks(sess, t);
}
// delete publication
if (AuthzResolver.isAuthorized(sess, Role.PERUNADMIN)) {
// only perun admin can actually delete publication
getPublicationManagerDao().deletePublication(publication);
log.debug("{} deleted.", publication);
}
// publications without authors are: "to be deleted by perun admin"
} catch (DataIntegrityViolationException ex) {
throw new CabinetException("Can't delete publication with Authors or Thanks. Please remove them first in order to delete publication.", ErrorCodes.PUBLICATION_HAS_AUTHORS_OR_THANKS);
} catch (PerunException ex) {
throw new CabinetException(ErrorCodes.PERUN_EXCEPTION, ex);
}
}
use of cz.metacentrum.perun.cabinet.bl.CabinetException in project perun by CESNET.
the class ThanksManagerIntegrationTest method createThanksWhenExistsByOwnerAndPublicationTest.
@Test
public void createThanksWhenExistsByOwnerAndPublicationTest() throws Exception {
System.out.println("ThanksManagerIntegrationTest.createThanksWhenExistsByOwnerAndPublicationTest");
Thanks t = new Thanks();
t.setCreatedBy(sess.getPerunPrincipal().getActor());
t.setCreatedDate(new Date());
t.setOwnerId(owner.getId());
t.setPublicationId(publicationOne.getId());
getCabinetManager().createThanks(sess, t);
try {
getCabinetManager().createThanks(sess, t);
} catch (CabinetException ex) {
if (!ex.getType().equals(ErrorCodes.THANKS_ALREADY_EXISTS)) {
fail("Different exception was thrown when creating \"same\" Thanks: " + ex + ", but expected: THANKS_ALREADY_EXISTS");
}
}
}
use of cz.metacentrum.perun.cabinet.bl.CabinetException in project perun by CESNET.
the class ThanksManagerIntegrationTest method createThanksWhenExistsByIDTest.
@Test
public void createThanksWhenExistsByIDTest() throws Exception {
System.out.println("ThanksManagerIntegrationTest.createThanksWhenExistsByIDTest");
Thanks t = new Thanks();
t.setCreatedBy(sess.getPerunPrincipal().getActor());
t.setCreatedDate(new Date());
t.setOwnerId(owner.getId());
t.setPublicationId(publicationOne.getId());
getCabinetManager().createThanks(sess, t);
try {
getCabinetManager().createThanks(sess, t);
} catch (CabinetException ex) {
if (!ex.getType().equals(ErrorCodes.THANKS_ALREADY_EXISTS)) {
fail("Different exception was thrown when creating \"same\" Thanks: " + ex + ", but expected: THANKS_ALREADY_EXISTS");
}
}
}
Aggregations