Search in sources :

Example 26 with Source

use of org.orcid.jaxb.model.common_v2.Source in project ORCID-Source by ORCID.

the class PeerReviewManagerImpl method updatePeerReview.

@Override
public PeerReview updatePeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
    PeerReviewEntity existingEntity = peerReviewDao.getPeerReview(orcid, peerReview.getPutCode());
    Visibility originalVisibility = existingEntity.getVisibility();
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    //Save the original source
    String existingSourceId = existingEntity.getSourceId();
    String existingClientSourceId = existingEntity.getClientSourceId();
    // If request comes from the API perform validations
    if (isApiRequest) {
        activityValidator.validatePeerReview(peerReview, sourceEntity, false, isApiRequest, originalVisibility);
        validateGroupId(peerReview);
        List<PeerReview> existingReviews = this.findPeerReviews(orcid, System.currentTimeMillis());
        for (PeerReview existing : existingReviews) {
            // Dont compare the updated peer review with the DB version
            if (!existing.getPutCode().equals(peerReview.getPutCode())) {
                activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceManager.retrieveSourceEntity());
            }
        }
    } else {
        //check vocab of external identifiers
        externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
        externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
    }
    PeerReviewEntity updatedEntity = new PeerReviewEntity();
    orcidSecurityManager.checkSource(existingEntity);
    jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview, updatedEntity);
    updatedEntity.setProfile(new ProfileEntity(orcid));
    updatedEntity.setVisibility(originalVisibility);
    //Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
    updatedEntity.setOrg(updatedOrganization);
    updatedEntity = peerReviewDao.merge(updatedEntity);
    peerReviewDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItem(updatedEntity));
    return jpaJaxbPeerReviewAdapter.toPeerReview(updatedEntity);
}
Also used : PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 27 with Source

use of org.orcid.jaxb.model.common_v2.Source in project ORCID-Source by ORCID.

the class WorkFormTest method getWork.

private Work getWork() {
    Work work = new Work();
    work.setCountry(new Country(Iso3166Country.US));
    work.setJournalTitle(new Title("Journal title"));
    work.setLanguageCode("en");
    work.setPutCode(Long.valueOf("1"));
    work.setShortDescription("Short description");
    work.setSource(new org.orcid.jaxb.model.common_v2.Source("0000-0000-0000-0000"));
    work.setUrl(new Url("http://myurl.com"));
    work.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    org.orcid.jaxb.model.record_v2.Citation citation = new org.orcid.jaxb.model.record_v2.Citation();
    citation.setCitation("Citation");
    citation.setWorkCitationType(CitationType.FORMATTED_UNSPECIFIED);
    work.setWorkCitation(citation);
    WorkTitle title = new WorkTitle();
    title.setTitle(new Title("Title"));
    title.setTranslatedTitle(new org.orcid.jaxb.model.common_v2.TranslatedTitle("Translated Title", "es"));
    title.setSubtitle(new Subtitle("Subtitle"));
    work.setWorkTitle(title);
    work.setWorkType(WorkType.ARTISTIC_PERFORMANCE);
    Date date = new Date();
    date.setDay("1");
    date.setMonth("1");
    date.setYear("2015");
    GregorianCalendar calendar = date.toCalendar();
    work.setCreatedDate(new CreatedDate(datatypeFactory.newXMLGregorianCalendar(calendar)));
    date = new Date();
    date.setDay("2");
    date.setMonth("2");
    date.setYear("2015");
    calendar = date.toCalendar();
    work.setLastModifiedDate(new LastModifiedDate(datatypeFactory.newXMLGregorianCalendar(calendar)));
    work.setPublicationDate(new PublicationDate(new Year(2015), new Month(3), new Day(3)));
    org.orcid.jaxb.model.record_v2.WorkContributors contributors = new org.orcid.jaxb.model.record_v2.WorkContributors();
    org.orcid.jaxb.model.common_v2.Contributor contributor = new org.orcid.jaxb.model.common_v2.Contributor();
    org.orcid.jaxb.model.common_v2.ContributorAttributes attributes = new org.orcid.jaxb.model.common_v2.ContributorAttributes();
    attributes.setContributorRole(org.orcid.jaxb.model.common_v2.ContributorRole.CO_INVENTOR);
    attributes.setContributorSequence(org.orcid.jaxb.model.record_v2.SequenceType.FIRST);
    contributor.setContributorAttributes(attributes);
    contributor.setContributorEmail(null);
    ContributorOrcid contributorOrcid = new ContributorOrcid("Contributor orcid");
    contributorOrcid.setUri("Contributor uri");
    contributor.setContributorOrcid(contributorOrcid);
    CreditName creditName = new CreditName("Contributor credit name");
    contributor.setCreditName(creditName);
    contributors.getContributor().add(contributor);
    work.setWorkContributors(contributors);
    ExternalIDs externalIdentifiers = new ExternalIDs();
    ExternalID extId = new ExternalID();
    extId.setValue("External Identifier ID");
    extId.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ASIN.value());
    extId.setRelationship(Relationship.SELF);
    externalIdentifiers.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(externalIdentifiers);
    return work;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Contributor(org.orcid.pojo.ajaxForm.Contributor) Url(org.orcid.jaxb.model.common_v2.Url) Month(org.orcid.jaxb.model.common_v2.Month) Work(org.orcid.jaxb.model.record_v2.Work) Citation(org.orcid.pojo.ajaxForm.Citation) PublicationDate(org.orcid.jaxb.model.common_v2.PublicationDate) GregorianCalendar(java.util.GregorianCalendar) CreditName(org.orcid.jaxb.model.common_v2.CreditName) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) CreatedDate(org.orcid.jaxb.model.common_v2.CreatedDate) PublicationDate(org.orcid.jaxb.model.common_v2.PublicationDate) Date(org.orcid.pojo.ajaxForm.Date) Subtitle(org.orcid.jaxb.model.common_v2.Subtitle) Year(org.orcid.jaxb.model.common_v2.Year) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) CreatedDate(org.orcid.jaxb.model.common_v2.CreatedDate) Country(org.orcid.jaxb.model.common_v2.Country) Iso3166Country(org.orcid.jaxb.model.common_v2.Iso3166Country) ContributorOrcid(org.orcid.jaxb.model.common_v2.ContributorOrcid) Day(org.orcid.jaxb.model.common_v2.Day)

Example 28 with Source

use of org.orcid.jaxb.model.common_v2.Source in project ORCID-Source by ORCID.

the class WorkExternalIdentifiersConversionsTest method testConvertToExternalIDs.

@Test
public void testConvertToExternalIDs() {
    WorkExternalIDsConverter conv = new WorkExternalIDsConverter();
    String externalIdentifiersAsString = expectedIDs;
    ExternalIDs ids = conv.convertFrom(externalIdentifiersAsString, null);
    assertEquals(Relationship.SELF, ids.getExternalIdentifier().get(0).getRelationship());
    assertEquals(new Url("http://what.com"), ids.getExternalIdentifier().get(0).getUrl());
    assertEquals("doi", ids.getExternalIdentifier().get(0).getType());
    assertEquals("value", ids.getExternalIdentifier().get(0).getValue());
    assertEquals(Relationship.PART_OF, ids.getExternalIdentifier().get(1).getRelationship());
    assertEquals(new Url("http://whatnow.com"), ids.getExternalIdentifier().get(1).getUrl());
    assertEquals("source-work-id", ids.getExternalIdentifier().get(1).getType());
    assertEquals("value2", ids.getExternalIdentifier().get(1).getValue());
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkExternalIDsConverter(org.orcid.core.adapter.impl.jsonidentifiers.WorkExternalIDsConverter) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test)

Example 29 with Source

use of org.orcid.jaxb.model.common_v2.Source in project ORCID-Source by ORCID.

the class NotificationManagerTest method filterActionedNotificationAlertsTest.

@Test
public void filterActionedNotificationAlertsTest() {
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
    when(mockNotificationDao.findByOricdAndId(Matchers.anyString(), Matchers.anyLong())).thenReturn(null);
    List<Notification> notifications = IntStream.range(0, 10).mapToObj(new IntFunction<Notification>() {

        @Override
        public Notification apply(int value) {
            if (value % 3 == 0) {
                NotificationInstitutionalConnection n = new NotificationInstitutionalConnection();
                n.setSource(new Source("0000-0000-0000-0000"));
                n.setPutCode(Long.valueOf(value));
                return n;
            } else {
                NotificationPermission n = new NotificationPermission();
                n.setPutCode(Long.valueOf(value));
                return n;
            }
        }
    }).collect(Collectors.toList());
    assertEquals(10, notifications.size());
    notifications = notificationManager.filterActionedNotificationAlerts(notifications, "some-orcid");
    assertEquals(6, notifications.size());
    for (Notification n : notifications) {
        assertEquals(NotificationType.PERMISSION, n.getNotificationType());
        assertNotNull(n.getPutCode());
        assertThat(n.getPutCode(), not(anyOf(is(Long.valueOf(0)), is(Long.valueOf(3)), is(Long.valueOf(6)), is(Long.valueOf(9)))));
    }
}
Also used : NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) IntFunction(java.util.function.IntFunction) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Source(org.orcid.jaxb.model.common_v2.Source) Notification(org.orcid.jaxb.model.notification_v2.Notification) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 30 with Source

use of org.orcid.jaxb.model.common_v2.Source in project ORCID-Source by ORCID.

the class ExternalIDValidatorTest method testValidateWorkOrPeerReview.

@Test
public void testValidateWorkOrPeerReview() {
    //call for ExternalID and ExternalIDs
    //ID valid
    ExternalID id1 = new ExternalID();
    id1.setRelationship(Relationship.SELF);
    id1.setType("doi");
    id1.setValue("value1");
    id1.setUrl(new Url("http://value1.com"));
    validator.validateWorkOrPeerReview(id1);
    //ID bad type
    try {
        id1.setType("invalid");
        validator.validateWorkOrPeerReview(id1);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    //id null
    try {
        id1.setType(null);
        validator.validateWorkOrPeerReview(id1);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    ExternalIDs ids = new ExternalIDs();
    ids.getExternalIdentifier().add(id1);
    //IDS one invalid
    id1.setType("invalid");
    try {
        validator.validateWorkOrPeerReview(ids);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    //IDS one valid (lowercase)
    id1.setType("doi");
    validator.validateWorkOrPeerReview(ids);
    //IDS two valid
    ExternalID id2 = new ExternalID();
    id2.setRelationship(Relationship.SELF);
    id2.setType("source-work-id");
    id2.setValue("value2");
    id2.setUrl(new Url("http://value1.com"));
    ids.getExternalIdentifier().add(id2);
    validator.validateWorkOrPeerReview(ids);
    //IDS one invalid, one valid
    id2.setType("not-a-type");
    try {
        validator.validateWorkOrPeerReview(ids);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Url(org.orcid.jaxb.model.common_v2.Url) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 Source (org.orcid.jaxb.model.common_v2.Source)16 Source (hex.glm.GLM2.Source)11 Url (org.orcid.jaxb.model.common_v2.Url)11 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)11 Visibility (org.orcid.jaxb.model.common_v2.Visibility)10 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)7 Items (org.orcid.jaxb.model.notification.permission_v2.Items)6 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 Date (java.util.Date)5 HashMap (java.util.HashMap)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5 Item (org.orcid.jaxb.model.notification.permission_v2.Item)5 CreatedDate (org.orcid.jaxb.model.common_v2.CreatedDate)4 LastModifiedDate (org.orcid.jaxb.model.common_v2.LastModifiedDate)4 SourceName (org.orcid.jaxb.model.common_v2.SourceName)4 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)4 SourceOrcid (org.orcid.jaxb.model.common_v2.SourceOrcid)3 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)3