Search in sources :

Example 16 with Record

use of org.orcid.jaxb.model.v3.dev1.record.Record in project ORCID-Source by ORCID.

the class RecordManagerTest method testGetRecord.

@Test
public void testGetRecord() {
    Record record = recordManager.getRecord(ORCID);
    assertNotNull(record);
    assertNotNull(record.getActivitiesSummary());
    assertNotNull(record.getPerson());
    Person person = record.getPerson();
    assertNotNull(person.getExternalIdentifiers());
    assertNotNull(person.getExternalIdentifiers().getExternalIdentifiers());
    assertEquals(5, person.getExternalIdentifiers().getExternalIdentifiers().size());
    assertNotNull(person.getResearcherUrls());
    assertNotNull(person.getResearcherUrls().getResearcherUrls());
    assertEquals(5, person.getResearcherUrls().getResearcherUrls().size());
    assertNotNull(person.getOtherNames());
    assertNotNull(person.getOtherNames().getOtherNames());
    assertEquals(5, person.getOtherNames().getOtherNames().size());
    assertNotNull(person.getAddresses());
    assertNotNull(person.getAddresses().getAddress());
    assertEquals(5, person.getAddresses().getAddress().size());
    assertNotNull(person.getKeywords());
    assertNotNull(person.getKeywords().getKeywords());
    assertEquals(5, person.getKeywords().getKeywords().size());
    assertNotNull(person.getEmails());
    assertNotNull(person.getEmails().getEmails());
    assertEquals(5, person.getEmails().getEmails().size());
    assertNotNull(person.getBiography());
    assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility());
    assertEquals("Biography for 0000-0000-0000-0003", person.getBiography().getContent());
    assertNotNull(person.getName());
    assertNotNull(person.getName().getCreditName());
    assertEquals("Credit Name", person.getName().getCreditName().getContent());
    assertNotNull(person.getName().getFamilyName());
    assertEquals("Family Name", person.getName().getFamilyName().getContent());
    assertNotNull(person.getName().getGivenNames());
    assertEquals("Given Names", person.getName().getGivenNames().getContent());
    assertEquals(Visibility.PUBLIC, person.getName().getVisibility());
    ActivitiesSummary activities = record.getActivitiesSummary();
    assertNotNull(activities);
    assertNotNull(activities.getEducations());
    assertNotNull(activities.getEducations().getSummaries());
    assertEquals(5, activities.getEducations().getSummaries().size());
    assertNotNull(activities.getEmployments());
    assertNotNull(activities.getEmployments().getSummaries());
    assertEquals(5, activities.getEmployments().getSummaries().size());
    assertNotNull(activities.getFundings());
    assertNotNull(activities.getFundings().getFundingGroup());
    assertEquals(5, activities.getFundings().getFundingGroup().size());
    assertNotNull(activities.getPeerReviews());
    assertNotNull(activities.getPeerReviews().getPeerReviewGroup());
    assertEquals(5, activities.getPeerReviews().getPeerReviewGroup().size());
    assertNotNull(activities.getWorks());
    assertNotNull(activities.getWorks().getWorkGroup());
    assertEquals(5, activities.getWorks().getWorkGroup().size());
}
Also used : Record(org.orcid.jaxb.model.v3.dev1.record.Record) Person(org.orcid.jaxb.model.v3.dev1.record.Person) ActivitiesSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 17 with Record

use of org.orcid.jaxb.model.v3.dev1.record.Record in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendAmendEmail.

@Override
public void sendAmendEmail(String userOrcid, AmendedSection amendedSection, Collection<Item> items) {
    String amenderOrcid = sourceManager.retrieveSourceOrcid();
    ProfileEntity record = profileEntityCacheManager.retrieve(userOrcid);
    Locale locale = getUserLocaleFromProfileEntity(record);
    if (amenderOrcid == null) {
        LOGGER.info("Not sending amend email to {} because amender is null", userOrcid);
        return;
    }
    if (amenderOrcid.equals(userOrcid)) {
        LOGGER.debug("Not sending amend email, because self edited: {}", userOrcid);
        return;
    }
    Boolean sendChangeNotifications = record.getSendChangeNotifications();
    if (sendChangeNotifications == null || !sendChangeNotifications) {
        LOGGER.debug("Not sending amend email, because option to send change notifications is disabled: {}", userOrcid);
        return;
    }
    org.orcid.jaxb.model.common_v2.OrcidType amenderType = profileDao.retrieveOrcidType(amenderOrcid);
    if (amenderType != null && OrcidType.ADMIN.equals(OrcidType.fromValue(amenderType.value()))) {
        LOGGER.debug("Not sending amend email, because modified by admin ({}): {}", amenderOrcid, userOrcid);
        return;
    }
    String subject = getSubject("email.subject.amend", locale);
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", deriveEmailFriendlyName(record));
    templateParams.put("orcid", userOrcid);
    templateParams.put("amenderName", extractAmenderName(userOrcid, amenderOrcid));
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("subject", subject);
    addMessageParams(templateParams, locale);
    // Generate body from template
    String body = templateManager.processTemplate("amend_email.ftl", templateParams);
    // Generate html from template
    String html = templateManager.processTemplate("amend_email_html.ftl", templateParams);
    boolean notificationsEnabled = record.getEnableNotifications();
    if (notificationsEnabled) {
        NotificationAmended notification = new NotificationAmended();
        notification.setNotificationType(NotificationType.AMENDED);
        notification.setAmendedSection(amendedSection);
        if (items != null) {
            notification.setItems(new Items(new ArrayList<>(items)));
        }
        createNotification(userOrcid, notification);
    } else {
        String primaryEmail = emailManager.findPrimaryEmail(userOrcid).getEmail();
        mailGunManager.sendEmail(AMEND_NOTIFY_ORCID_ORG, primaryEmail, subject, body, html);
    }
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)

Example 18 with Record

use of org.orcid.jaxb.model.v3.dev1.record.Record in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendDelegationRequestEmail.

@Override
public void sendDelegationRequestEmail(String managedOrcid, String trustedOrcid, String link) {
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("link", link);
    ProfileEntity managedEntity = profileEntityCacheManager.retrieve(managedOrcid);
    ProfileEntity trustedEntity = profileEntityCacheManager.retrieve(trustedOrcid);
    String emailNameForDelegate = deriveEmailFriendlyName(managedEntity);
    String trustedOrcidName = deriveEmailFriendlyName(trustedEntity);
    templateParams.put("emailNameForDelegate", emailNameForDelegate);
    templateParams.put("trustedOrcidName", trustedOrcidName);
    templateParams.put("trustedOrcidValue", trustedOrcid);
    templateParams.put("managedOrcidValue", managedOrcid);
    String primaryEmail = emailManager.findPrimaryEmail(managedOrcid).getEmail();
    if (primaryEmail == null) {
        LOGGER.info("Cant send admin delegate email if primary email is null: {}", managedOrcid);
        return;
    }
    org.orcid.jaxb.model.common_v2.Locale locale = managedEntity.getLocale();
    Locale userLocale = LocaleUtils.toLocale("en");
    if (locale != null) {
        userLocale = LocaleUtils.toLocale(locale.value());
    }
    addMessageParams(templateParams, userLocale);
    String htmlBody = templateManager.processTemplate("admin_delegate_request_html.ftl", templateParams);
    // Send message
    if (apiRecordCreationEmailEnabled) {
        String subject = messages.getMessage("email.subject.admin_as_delegate", new Object[] { trustedOrcidName }, userLocale);
        boolean notificationsEnabled = trustedEntity != null ? trustedEntity.getEnableNotifications() : false;
        if (notificationsEnabled) {
            NotificationCustom notification = new NotificationCustom();
            notification.setNotificationType(NotificationType.CUSTOM);
            notification.setSubject(subject);
            notification.setBodyHtml(htmlBody);
            createNotification(managedOrcid, notification);
        } else {
            mailGunManager.sendEmail(DELEGATE_NOTIFY_ORCID_ORG, primaryEmail, subject, null, htmlBody);
        }
        profileEventDao.persist(new ProfileEventEntity(managedOrcid, ProfileEventType.ADMIN_PROFILE_DELEGATION_REQUEST));
    } else {
        LOGGER.debug("Not sending admin delegate email, because API record creation email option is disabled. Message would have been: {}", htmlBody);
    }
}
Also used : Locale(java.util.Locale) ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom)

Example 19 with Record

use of org.orcid.jaxb.model.v3.dev1.record.Record in project ORCID-Source by ORCID.

the class ProfileEntityManagerImpl method clearRecord.

/**
 * Clears all record info but the email addresses, that stay unmodified
 */
private void clearRecord(String orcid, Boolean disableTokens) {
    // Remove works
    workManager.removeAllWorks(orcid);
    // Remove funding
    fundingManager.removeAllFunding(orcid);
    // Remove affiliations
    affiliationsManager.removeAllAffiliations(orcid);
    // Remove peer reviews
    peerReviewManager.removeAllPeerReviews(orcid);
    // Remove addresses
    addressManager.removeAllAddress(orcid);
    // Remove external identifiers
    externalIdentifierManager.removeAllExternalIdentifiers(orcid);
    // Remove researcher urls
    researcherUrlManager.removeAllResearcherUrls(orcid);
    // Remove other names
    otherNameManager.removeAllOtherNames(orcid);
    // Remove keywords
    profileKeywordManager.removeAllKeywords(orcid);
    // Remove biography
    if (biographyManager.exists(orcid)) {
        Biography deprecatedBio = new Biography();
        deprecatedBio.setContent(null);
        deprecatedBio.setVisibility(Visibility.PRIVATE);
        biographyManager.updateBiography(orcid, deprecatedBio);
    }
    // Set the deactivated names
    if (recordNameManager.exists(orcid)) {
        Name name = new Name();
        name.setCreditName(new CreditName());
        name.setGivenNames(new GivenNames("Given Names Deactivated"));
        name.setFamilyName(new FamilyName("Family Name Deactivated"));
        name.setVisibility(Visibility.PUBLIC);
        name.setPath(orcid);
        recordNameManager.updateRecordName(orcid, name);
    }
    // 
    userConnectionDao.deleteByOrcid(orcid);
    if (disableTokens) {
        // Disable any token that belongs to this record
        orcidOauth2TokenDetailService.disableAccessTokenByUserOrcid(orcid, RevokeReason.RECORD_DEACTIVATED);
    }
    // Change default visibility to private
    profileDao.updateDefaultVisibility(orcid, org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
}
Also used : FamilyName(org.orcid.jaxb.model.v3.dev1.record.FamilyName) GivenNames(org.orcid.jaxb.model.v3.dev1.record.GivenNames) Biography(org.orcid.jaxb.model.v3.dev1.record.Biography) CreditName(org.orcid.jaxb.model.v3.dev1.record.CreditName) FamilyName(org.orcid.jaxb.model.v3.dev1.record.FamilyName) CreditName(org.orcid.jaxb.model.v3.dev1.record.CreditName) Name(org.orcid.jaxb.model.v3.dev1.record.Name)

Example 20 with Record

use of org.orcid.jaxb.model.v3.dev1.record.Record in project ORCID-Source by ORCID.

the class TransientNonEmptyStringTest method testMarshal.

/**
 *    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 *    <common:external-ids xmlns:internal="http://www.orcid.org/ns/internal" xmlns:address="http://www.orcid.org/ns/address" xmlns:email="http://www.orcid.org/ns/email" xmlns:history="http://www.orcid.org/ns/history" xmlns:employment="http://www.orcid.org/ns/employment" xmlns:person="http://www.orcid.org/ns/person" xmlns:education="http://www.orcid.org/ns/education" xmlns:other-name="http://www.orcid.org/ns/other-name" xmlns:personal-details="http://www.orcid.org/ns/personal-details" xmlns:bulk="http://www.orcid.org/ns/bulk" xmlns:common="http://www.orcid.org/ns/common" xmlns:record="http://www.orcid.org/ns/record" xmlns:keyword="http://www.orcid.org/ns/keyword" xmlns:activities="http://www.orcid.org/ns/activities" xmlns:deprecated="http://www.orcid.org/ns/deprecated" xmlns:external-identifier="http://www.orcid.org/ns/external-identifier" xmlns:funding="http://www.orcid.org/ns/funding" xmlns:error="http://www.orcid.org/ns/error" xmlns:preferences="http://www.orcid.org/ns/preferences" xmlns:work="http://www.orcid.org/ns/work" xmlns:researcher-url="http://www.orcid.org/ns/researcher-url" xmlns:peer-review="http://www.orcid.org/ns/peer-review">
 *        <common:external-id>
 *            <common:external-id-type>doi</common:external-id-type>
 *            <common:external-id-value>value</common:external-id-value>
 *            <common:external-id-normalized transient="true">normalized-value</common:external-id-normalized>
 *        </common:external-id>
 *    </common:external-ids>
 * @throws JAXBException
 * @throws SAXException
 * @throws IOException
 */
@Test
public void testMarshal() throws JAXBException, SAXException, IOException {
    ExternalIDs ids = new ExternalIDs();
    ExternalID id = new ExternalID();
    id.setType("doi");
    id.setValue("value");
    id.setNormalized(new TransientNonEmptyString("normalized-value"));
    ids.getExternalIdentifier().add(id);
    JAXBContext context = JAXBContext.newInstance(ExternalIDs.class);
    Marshaller marshaller = context.createMarshaller();
    StringWriter sw = new StringWriter();
    marshaller.marshal(ids, sw);
    assertTrue(sw.toString().contains("<common:external-id-normalized transient=\"true\">normalized-value</common:external-id-normalized>"));
    SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = factory.newSchema(getClass().getResource("/common_3.0_dev1/common-3.0_dev1.xsd"));
    Validator validator = schema.newValidator();
    validator.validate(new JAXBSource(context, ids));
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Marshaller(javax.xml.bind.Marshaller) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) StringWriter(java.io.StringWriter) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Schema(javax.xml.validation.Schema) JAXBContext(javax.xml.bind.JAXBContext) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) Validator(javax.xml.validation.Validator) JAXBSource(javax.xml.bind.util.JAXBSource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 Record (org.orcid.jaxb.model.v3.dev1.record.Record)33 Email (org.orcid.jaxb.model.v3.dev1.record.Email)18 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)18 Person (org.orcid.jaxb.model.v3.dev1.record.Person)17 Address (org.orcid.jaxb.model.v3.dev1.record.Address)16 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)16 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)16 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)16 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)15 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)15 Name (org.orcid.jaxb.model.v3.dev1.record.Name)15 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)15 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)15 EmploymentSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary)15 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)15 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)15 OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)14 DistinctionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary)14 InvitedPositionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.InvitedPositionSummary)14