Search in sources :

Example 1 with WrongSourceException

use of org.orcid.core.exception.WrongSourceException in project ORCID-Source by ORCID.

the class NotificationManagerImpl method flagAsArchived.

@Override
@Transactional
public Notification flagAsArchived(String orcid, Long id, boolean validateForApi) throws OrcidNotificationAlreadyReadException {
    NotificationEntity notificationEntity = notificationDao.findByOricdAndId(orcid, id);
    if (notificationEntity == null) {
        return null;
    }
    String sourceId = sourceManager.retrieveSourceOrcid();
    if (validateForApi) {
        if (sourceId != null && !sourceId.equals(notificationEntity.getElementSourceId())) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("activity", "notification");
            throw new WrongSourceException(params);
        }
        if (notificationEntity.getReadDate() != null) {
            throw new OrcidNotificationAlreadyReadException();
        }
    }
    if (notificationEntity.getArchivedDate() == null) {
        notificationEntity.setArchivedDate(new Date());
        notificationDao.merge(notificationEntity);
    }
    return notificationAdapter.toNotification(notificationEntity);
}
Also used : WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidNotificationAlreadyReadException(org.orcid.core.exception.OrcidNotificationAlreadyReadException) HashMap(java.util.HashMap) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with WrongSourceException

use of org.orcid.core.exception.WrongSourceException in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_PeerReviewsTest method testUpdatePeerReviewWhenYouAreNotTheSourceOf.

@Test
public void testUpdatePeerReviewWhenYouAreNotTheSourceOf() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewPeerReview("4444-4444-4444-4447", 2L);
    assertNotNull(response);
    PeerReview peerReview = (PeerReview) response.getEntity();
    assertNotNull(peerReview);
    assertEquals("http://peer_review.com/2", peerReview.getUrl().getValue());
    assertEquals("APP-6666666666666666", peerReview.getSource().retrieveSourcePath());
    // Update the info
    peerReview.setUrl(new Url("http://updated.com/url"));
    peerReview.getSubjectName().getTitle().setContent("Updated Title");
    peerReview.getExternalIdentifiers().getExternalIdentifier().iterator().next().setValue("different");
    try {
        response = serviceDelegator.updatePeerReview("4444-4444-4444-4447", 2L, peerReview);
        fail();
    } catch (WrongSourceException wse) {
    }
    response = serviceDelegator.viewPeerReview("4444-4444-4444-4447", Long.valueOf(2));
    peerReview = (PeerReview) response.getEntity();
    assertNotNull(peerReview);
    assertEquals("http://peer_review.com/2", peerReview.getUrl().getValue());
    assertEquals("APP-6666666666666666", peerReview.getSource().retrieveSourcePath());
}
Also used : Response(javax.ws.rs.core.Response) WrongSourceException(org.orcid.core.exception.WrongSourceException) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Url(org.orcid.jaxb.model.common_v2.Url) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

WrongSourceException (org.orcid.core.exception.WrongSourceException)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 OrcidNotificationAlreadyReadException (org.orcid.core.exception.OrcidNotificationAlreadyReadException)1 Url (org.orcid.jaxb.model.common_v2.Url)1 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)1 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)1 ActionableNotificationEntity (org.orcid.persistence.jpa.entities.ActionableNotificationEntity)1 NotificationEntity (org.orcid.persistence.jpa.entities.NotificationEntity)1 DBUnitTest (org.orcid.test.DBUnitTest)1 Transactional (org.springframework.transaction.annotation.Transactional)1