Search in sources :

Example 1 with Preferences

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

the class OrcidMessageVersionConverterImplV1_2_rc5ToV1_2_rc6 method downgradeProfile.

private void downgradeProfile(OrcidProfile orcidProfile) {
    if (orcidProfile != null) {
        if (orcidProfile.getOrcidBio() != null)
            if (orcidProfile.getOrcidBio().getExternalIdentifiers() != null)
                for (ExternalIdentifier externalIdentifier : orcidProfile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
                    Source source = externalIdentifier.getSource();
                    if (source != null) {
                        SourceOrcid sourceOrcid = source.getSourceOrcid();
                        if (sourceOrcid != null) {
                            externalIdentifier.setSource(null);
                            externalIdentifier.setExternalIdSource(new ExternalIdSource(sourceOrcid));
                        }
                    }
                }
        if (orcidProfile.getOrcidActivities() != null) {
            if (orcidProfile.getOrcidActivities().getOrcidWorks() != null) {
                for (OrcidWork act : orcidProfile.getOrcidActivities().getOrcidWorks().getOrcidWork()) downGradeActivity(act);
            }
        }
        OrcidInternal orcidInternal = orcidProfile.getOrcidInternal();
        if (orcidInternal != null) {
            Preferences prefs = orcidInternal.getPreferences();
            if (prefs != null) {
                prefs.setSendEmailFrequencyDays(null);
                prefs.setSendMemberUpdateRequests(null);
            }
            ReferredBy referredBy = orcidInternal.getReferredBy();
            if (referredBy != null && !OrcidStringUtils.isValidOrcid(referredBy.getPath())) {
                orcidInternal.setReferredBy(null);
            }
        }
    }
}
Also used : WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ExternalIdSource(org.orcid.jaxb.model.message.ExternalIdSource) ReferredBy(org.orcid.jaxb.model.message.ReferredBy) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Preferences(org.orcid.jaxb.model.message.Preferences) ExternalIdSource(org.orcid.jaxb.model.message.ExternalIdSource) Source(org.orcid.jaxb.model.message.Source) WorkSource(org.orcid.jaxb.model.message.WorkSource)

Example 2 with Preferences

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

the class OrcidMessageVersionConverterImplV1_2_rc3ToV1_2_rc4 method upgradeProfile.

private void upgradeProfile(OrcidProfile orcidProfile) {
    if (orcidProfile != null) {
        if (orcidProfile.getOrcidInternal() != null) {
            if (orcidProfile.getOrcidInternal().getPreferences() != null) {
                Preferences prefs = orcidProfile.getOrcidInternal().getPreferences();
                if (prefs.getWorkVisibilityDefault() != null && prefs.getWorkVisibilityDefault().getValue() != null) {
                    prefs.setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(prefs.getWorkVisibilityDefault().getValue()));
                    prefs.setWorkVisibilityDefault(null);
                }
                if (prefs.getDeveloperToolsEnabled() == null) {
                    DeveloperToolsEnabled dtn = new DeveloperToolsEnabled(false);
                    prefs.setDeveloperToolsEnabled(dtn);
                }
            }
        }
    }
}
Also used : ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) Preferences(org.orcid.jaxb.model.message.Preferences) DeveloperToolsEnabled(org.orcid.jaxb.model.message.DeveloperToolsEnabled)

Example 3 with Preferences

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

the class OrcidProfileManagerImplTest method testUpdatePreferences.

@Test
@Transactional
@Rollback(true)
public void testUpdatePreferences() {
    OrcidProfile profile1 = createBasicProfile();
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    assertEquals(Visibility.PRIVATE, profile1.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue());
    OrcidProfile profile2 = new OrcidProfile();
    profile2.setOrcidIdentifier(TEST_ORCID);
    OrcidInternal internal = new OrcidInternal();
    profile2.setOrcidInternal(internal);
    Preferences preferences = new Preferences();
    internal.setPreferences(preferences);
    preferences.setSendChangeNotifications(new SendChangeNotifications(false));
    preferences.setSendOrcidNews(new SendOrcidNews(true));
    preferences.setDeveloperToolsEnabled(new DeveloperToolsEnabled(true));
    preferences.setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.PUBLIC));
    orcidProfileManager.updatePreferences(profile2.getOrcidIdentifier().getPath(), profile2.getOrcidInternal().getPreferences());
    OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(false, retrievedProfile.getOrcidInternal().getPreferences().getSendChangeNotifications().isValue());
    assertEquals(true, retrievedProfile.getOrcidInternal().getPreferences().getSendOrcidNews().isValue());
    assertEquals(true, retrievedProfile.getOrcidInternal().getPreferences().getDeveloperToolsEnabled().isValue());
    assertEquals(Visibility.PUBLIC, retrievedProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) SendOrcidNews(org.orcid.jaxb.model.message.SendOrcidNews) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) Preferences(org.orcid.jaxb.model.message.Preferences) DefaultPreferences(org.orcid.core.constants.DefaultPreferences) SendChangeNotifications(org.orcid.jaxb.model.message.SendChangeNotifications) DeveloperToolsEnabled(org.orcid.jaxb.model.message.DeveloperToolsEnabled) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Preferences

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

the class EmailMessageSenderTest method testCreateDigest.

@Test
public void testCreateDigest() throws IOException {
    OrcidProfile orcidProfile = new OrcidProfile();
    OrcidBio orcidBio = new OrcidBio();
    orcidProfile.setOrcidBio(orcidBio);
    PersonalDetails personalDetails = new PersonalDetails();
    orcidBio.setPersonalDetails(personalDetails);
    personalDetails.setGivenNames(new GivenNames("John"));
    personalDetails.setFamilyName(new FamilyName("Watson"));
    OrcidInternal orcidInternal = new OrcidInternal();
    Preferences preferences = new Preferences();
    orcidProfile.setOrcidInternal(orcidInternal);
    orcidInternal.setPreferences(preferences);
    preferences.setSendEmailFrequencyDays("7.0");
    List<Notification> notifications = new ArrayList<>();
    NotificationPermission notification1 = new NotificationPermission();
    notification1.setPutCode(1L);
    Items activities1 = new Items();
    notification1.setItems(activities1);
    activities1.getItems().add(createActivity(ItemType.WORK, "Work 1", "123446/67654"));
    activities1.getItems().add(createActivity(ItemType.WORK, "Work 2", "http://dx.doi.org/123446/67655"));
    notification1.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T13:39:31"));
    notification1.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/12345"));
    Source source1 = new Source();
    source1.setSourceName(new SourceName("Super Institution 1"));
    source1.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
    notification1.setSource(source1);
    notifications.add(notification1);
    NotificationPermission notification2 = new NotificationPermission();
    notification2.setPutCode(2L);
    Items activities2 = new Items();
    notification2.setItems(activities2);
    activities2.getItems().add(createActivity(ItemType.EMPLOYMENT, "Employment 1 ", "12345/abc"));
    notification2.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-08-17T10:22:15"));
    notification2.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/abc"));
    Source source2 = new Source();
    source2.setSourceName(new SourceName("Super Institution 1"));
    source2.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
    notification2.setSource(source2);
    notifications.add(notification2);
    NotificationPermission notification3 = new NotificationPermission();
    notification3.setPutCode(3L);
    Items activities3 = new Items();
    notification3.setItems(activities3);
    activities3.getItems().add(createActivity(ItemType.WORK, "Work 3", "12345/def"));
    activities3.getItems().add(createActivity(ItemType.WORK, "Work 4", "12345/ghi"));
    notification3.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
    notification3.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/def"));
    Source source3 = new Source();
    source3.setSourceName(new SourceName("Lovely Publisher 1"));
    notification3.setSource(source3);
    source3.setSourceClientId(new SourceClientId("APP-ABCD-ABCD-ABCD-ABCD"));
    notifications.add(notification3);
    NotificationCustom notification4 = new NotificationCustom();
    notification4.setPutCode(4L);
    notification4.setSubject("We have release a new messaging feature");
    notification4.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
    notifications.add(notification4);
    NotificationCustom notification5 = new NotificationCustom();
    notification5.setPutCode(5L);
    notification5.setSubject("The ORCID registry is now available in Orc");
    notification5.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-11T06:42:18"));
    notifications.add(notification5);
    NotificationAmended notification6 = new NotificationAmended();
    notification6.setPutCode(6L);
    notification6.setSubject("Amended by member");
    notification6.setAmendedSection(AmendedSection.FUNDING);
    notification6.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-12T18:44:36"));
    notification6.setSource(source3);
    notifications.add(notification6);
    EmailMessage emailMessage = emailMessageSender.createDigest(orcidProfile, notifications, Locale.ENGLISH);
    assertNotNull(emailMessage);
    String expectedBodyText = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.txt"));
    String expectedBodyHtml = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.html"));
    assertTrue(expectedBodyText.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
    assertTrue(expectedBodyHtml.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
    assertTrue(expectedBodyText.contains("Super Institution 1: Request to add items"));
    assertTrue(expectedBodyHtml.contains("Super Institution 1: Request to add items"));
    assertTrue(expectedBodyText.contains("/action"));
    assertTrue(expectedBodyHtml.contains("/action"));
    assertEquals("[ORCID] John Watson you have 6 new notifications", emailMessage.getSubject());
}
Also used : OrcidBio(org.orcid.jaxb.model.message.OrcidBio) FamilyName(org.orcid.jaxb.model.message.FamilyName) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ArrayList(java.util.ArrayList) SourceName(org.orcid.jaxb.model.common_v2.SourceName) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) Notification(org.orcid.jaxb.model.notification_v2.Notification) Source(org.orcid.jaxb.model.common_v2.Source) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) GivenNames(org.orcid.jaxb.model.message.GivenNames) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Items(org.orcid.jaxb.model.notification.permission_v2.Items) Preferences(org.orcid.jaxb.model.message.Preferences) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 5 with Preferences

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

the class OrcidProfileManagerImplTest method testDefaultVisibilityForItemsAppliedOnUpdate.

@Test
@Transactional
@Rollback(true)
public void testDefaultVisibilityForItemsAppliedOnUpdate() {
    OrcidProfile profile = createBasicProfile();
    OrcidHistory orcidHistory = new OrcidHistory();
    orcidHistory.setClaimed(new Claimed(true));
    orcidHistory.setCreationMethod(CreationMethod.DIRECT);
    orcidHistory.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    profile.setOrcidHistory(orcidHistory);
    Keyword k = new Keyword("word", null);
    Keywords kk = new Keywords();
    kk.getKeyword().add(k);
    kk.setVisibility(Visibility.LIMITED);
    ResearcherUrl r = new ResearcherUrl(new Url("http://whatever.com"), null);
    ResearcherUrls rr = new ResearcherUrls();
    rr.getResearcherUrl().add(r);
    rr.setVisibility(Visibility.LIMITED);
    ExternalIdentifier i = new ExternalIdentifier(null);
    i.setExternalIdReference(new ExternalIdReference("ref"));
    i.setExternalIdCommonName(new ExternalIdCommonName("cn"));
    ExternalIdentifiers ii = new ExternalIdentifiers();
    ii.getExternalIdentifier().add(i);
    ii.setVisibility(Visibility.LIMITED);
    OtherNames oo = new OtherNames();
    oo.addOtherName("other", null);
    oo.setVisibility(Visibility.LIMITED);
    profile.getOrcidBio().setKeywords(kk);
    profile.getOrcidBio().setResearcherUrls(rr);
    profile.getOrcidBio().setExternalIdentifiers(ii);
    profile.getOrcidBio().getPersonalDetails().setOtherNames(oo);
    //Create the profile
    profile = orcidProfileManager.createOrcidProfile(profile, true, false);
    Preferences preferences = new Preferences();
    preferences.setSendChangeNotifications(new SendChangeNotifications(true));
    preferences.setSendOrcidNews(new SendOrcidNews(true));
    //Default visibility for user will be LIMITED
    preferences.setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
    preferences.setNotificationsEnabled(DefaultPreferences.NOTIFICATIONS_ENABLED);
    preferences.setSendEmailFrequencyDays(DefaultPreferences.SEND_EMAIL_FREQUENCY_DAYS);
    preferences.setSendMemberUpdateRequests(DefaultPreferences.SEND_MEMBER_UPDATE_REQUESTS);
    OrcidInternal internal = new OrcidInternal();
    internal.setPreferences(preferences);
    profile.setOrcidInternal(internal);
    profile.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
    //Claim the profile
    profile = orcidProfileManager.updateOrcidProfile(profile);
    //now attempt to alter privacy.  It should fail as record has been claimed.
    profile.getOrcidBio().getKeywords().setVisibility(Visibility.PUBLIC);
    profile.getOrcidBio().getResearcherUrls().setVisibility(Visibility.PUBLIC);
    profile.getOrcidBio().getExternalIdentifiers().setVisibility(Visibility.PUBLIC);
    profile.getOrcidBio().getPersonalDetails().getOtherNames().setVisibility(Visibility.PUBLIC);
    profile = orcidProfileManager.updateOrcidProfile(profile);
    assertEquals("word", profile.getOrcidBio().getKeywords().getKeyword().iterator().next().getContent());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getKeywords().getKeyword().iterator().next().getVisibility());
    assertEquals(new Url("http://whatever.com"), profile.getOrcidBio().getResearcherUrls().getResearcherUrl().iterator().next().getUrl());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().iterator().next().getVisibility());
    assertEquals("cn", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator().next().getExternalIdCommonName().getContent());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator().next().getVisibility());
    assertEquals("other", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().iterator().next().getContent());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().iterator().next().getVisibility());
}
Also used : SendOrcidNews(org.orcid.jaxb.model.message.SendOrcidNews) Keywords(org.orcid.jaxb.model.message.Keywords) Keyword(org.orcid.jaxb.model.message.Keyword) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) OtherNames(org.orcid.jaxb.model.message.OtherNames) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Claimed(org.orcid.jaxb.model.message.Claimed) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) Url(org.orcid.jaxb.model.message.Url) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) Preferences(org.orcid.jaxb.model.message.Preferences) DefaultPreferences(org.orcid.core.constants.DefaultPreferences) SendChangeNotifications(org.orcid.jaxb.model.message.SendChangeNotifications) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Preferences (org.orcid.jaxb.model.message.Preferences)15 OrcidInternal (org.orcid.jaxb.model.message.OrcidInternal)10 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)10 ActivitiesVisibilityDefault (org.orcid.jaxb.model.message.ActivitiesVisibilityDefault)7 SendChangeNotifications (org.orcid.jaxb.model.message.SendChangeNotifications)6 SendOrcidNews (org.orcid.jaxb.model.message.SendOrcidNews)6 Date (java.util.Date)5 Test (org.junit.Test)5 DefaultPreferences (org.orcid.core.constants.DefaultPreferences)5 Claimed (org.orcid.jaxb.model.message.Claimed)5 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)5 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)5 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)5 ResearcherUrl (org.orcid.jaxb.model.message.ResearcherUrl)4 Url (org.orcid.jaxb.model.message.Url)4 ApprovalDate (org.orcid.jaxb.model.message.ApprovalDate)3 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)3 ExternalIdCommonName (org.orcid.jaxb.model.message.ExternalIdCommonName)3 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)3 ExternalIdUrl (org.orcid.jaxb.model.message.ExternalIdUrl)3