Search in sources :

Example 71 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class WorksController method getWorkInfo.

/**
     * Returns a blank work
     */
@RequestMapping(value = "/getWorkInfo.json", method = RequestMethod.GET)
@ResponseBody
public WorkForm getWorkInfo(@RequestParam(value = "workId") Long workId) {
    Map<String, String> countries = retrieveIsoCountries();
    Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
    if (workId == null)
        return null;
    long lastModifiedTime = profileEntityManager.getLastModified(getEffectiveUserOrcid());
    Work work = workManager.getWork(this.getEffectiveUserOrcid(), workId, lastModifiedTime);
    if (work != null) {
        WorkForm workForm = WorkForm.valueOf(work);
        if (workForm.getPublicationDate() == null) {
            initializePublicationDate(workForm);
        } else {
            if (workForm.getPublicationDate().getDay() == null) {
                workForm.getPublicationDate().setDay(new String());
            }
            if (workForm.getPublicationDate().getMonth() == null) {
                workForm.getPublicationDate().setMonth(new String());
            }
            if (workForm.getPublicationDate().getYear() == null) {
                workForm.getPublicationDate().setYear(new String());
            }
        }
        // Set country name
        if (!PojoUtil.isEmpty(workForm.getCountryCode())) {
            Text countryName = Text.valueOf(countries.get(workForm.getCountryCode().getValue()));
            workForm.setCountryName(countryName);
        }
        // Set language name
        if (!PojoUtil.isEmpty(workForm.getLanguageCode())) {
            Text languageName = Text.valueOf(languages.get(workForm.getLanguageCode().getValue()));
            workForm.setLanguageName(languageName);
        }
        // Set translated title language name
        if (!(workForm.getTranslatedTitle() == null) && !StringUtils.isEmpty(workForm.getTranslatedTitle().getLanguageCode())) {
            String languageName = languages.get(workForm.getTranslatedTitle().getLanguageCode());
            workForm.getTranslatedTitle().setLanguageName(languageName);
        }
        if (workForm.getContributors() != null) {
            for (Contributor contributor : workForm.getContributors()) {
                if (!PojoUtil.isEmpty(contributor.getOrcid())) {
                    String contributorOrcid = contributor.getOrcid().getValue();
                    if (profileEntityManager.orcidExists(contributorOrcid)) {
                        // contributor is an ORCID user - visibility of user's name in record must be taken into account 
                        ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
                        String publicContributorCreditName = cacheManager.getPublicCreditName(profileEntity);
                        contributor.setCreditName(Text.valueOf(publicContributorCreditName));
                    }
                }
            }
        }
        return workForm;
    }
    return null;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) Work(org.orcid.jaxb.model.record_v2.Work) Contributor(org.orcid.pojo.ajaxForm.Contributor) Text(org.orcid.pojo.ajaxForm.Text) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 72 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class WorksController method initializeFields.

private void initializeFields(WorkForm w) {
    if (w.getVisibility() == null) {
        ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
        Visibility v = profile.getActivitiesVisibilityDefault() == null ? Visibility.fromValue(OrcidVisibilityDefaults.WORKS_DEFAULT.getVisibility().value()) : profile.getActivitiesVisibilityDefault();
        w.setVisibility(v);
    }
    if (w.getTitle() == null) {
        w.setTitle(new Text());
    }
    if (w.getSubtitle() == null) {
        w.setSubtitle(new Text());
    }
    if (w.getTranslatedTitle() == null) {
        TranslatedTitleForm tt = new TranslatedTitleForm();
        tt.setContent(new String());
        tt.setLanguageCode(new String());
        tt.setLanguageName(new String());
        w.setTranslatedTitle(tt);
    }
    if (PojoUtil.isEmpty(w.getJournalTitle())) {
        Text jt = new Text();
        jt.setRequired(false);
        w.setJournalTitle(jt);
    }
    if (PojoUtil.isEmpty(w.getWorkCategory())) {
        Text wCategoryText = new Text();
        wCategoryText.setValue(new String());
        wCategoryText.setRequired(true);
        w.setWorkCategory(wCategoryText);
    }
    if (PojoUtil.isEmpty(w.getWorkType())) {
        Text wTypeText = new Text();
        wTypeText.setValue(new String());
        wTypeText.setRequired(true);
        w.setWorkType(wTypeText);
    }
    initializePublicationDate(w);
    if (w.getWorkExternalIdentifiers() == null || w.getWorkExternalIdentifiers().isEmpty()) {
        WorkExternalIdentifier wei = new WorkExternalIdentifier();
        Text wdiType = new Text();
        wdiType.setValue(new String());
        wei.setWorkExternalIdentifierId(new Text());
        wei.setWorkExternalIdentifierType(wdiType);
        wei.setRelationship(Text.valueOf(Relationship.SELF.value()));
        List<WorkExternalIdentifier> wdiL = new ArrayList<WorkExternalIdentifier>();
        wdiL.add(wei);
        w.setWorkExternalIdentifiers(wdiL);
    }
    if (PojoUtil.isEmpty(w.getUrl())) {
        w.setUrl(new Text());
    }
    if (w.getContributors() == null || w.getContributors().isEmpty()) {
        List<Contributor> contrList = new ArrayList<Contributor>();
        w.setContributors(contrList);
    }
    if (PojoUtil.isEmpty(w.getShortDescription())) {
        w.setShortDescription(new Text());
    }
    if (PojoUtil.isEmpty(w.getLanguageCode())) {
        Text lc = new Text();
        lc.setRequired(false);
        w.setLanguageCode(lc);
    }
    if (PojoUtil.isEmpty(w.getLanguageName())) {
        Text ln = new Text();
        ln.setRequired(false);
        w.setLanguageName(ln);
    }
    if (PojoUtil.isEmpty(w.getCountryCode())) {
        w.setCountryCode(new Text());
    }
    if (PojoUtil.isEmpty(w.getCountryName())) {
        w.setCountryName(new Text());
    }
}
Also used : ArrayList(java.util.ArrayList) Contributor(org.orcid.pojo.ajaxForm.Contributor) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Text(org.orcid.pojo.ajaxForm.Text) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm)

Example 73 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class AdminControllerTest method testReviewAccounts.

@Test
public void testReviewAccounts() {
    ProfileEntityCacheManager profileEntityCacheManager = Mockito.mock(ProfileEntityCacheManager.class);
    ProfileEntityManager profileEntityManager = Mockito.mock(ProfileEntityManager.class);
    EmailManager emailManager = Mockito.mock(EmailManager.class);
    AdminController adminController = new AdminController();
    ReflectionTestUtils.setField(adminController, "profileEntityManager", profileEntityManager);
    ReflectionTestUtils.setField(adminController, "emailManager", emailManager);
    ReflectionTestUtils.setField(adminController, "profileEntityCacheManager", profileEntityCacheManager);
    String commaSeparatedValues = "some,orcid,ids,or,emails,to,test,with";
    Mockito.when(emailManager.emailExists(Mockito.anyString())).thenReturn(true);
    Mockito.when(emailManager.emailExists(Mockito.eq("some"))).thenReturn(false);
    Mockito.when(emailManager.emailExists(Mockito.eq("orcid"))).thenReturn(false);
    Map<String, String> map = new HashMap<String, String>();
    map.put("ids", "ids");
    map.put("or", "or");
    map.put("emails", "emails");
    map.put("to", "to");
    map.put("test", "test");
    map.put("with", "with");
    Mockito.when(emailManager.findOricdIdsByCommaSeparatedEmails(Mockito.anyString())).thenReturn(map);
    Mockito.when(profileEntityManager.orcidExists(Mockito.anyString())).thenReturn(true);
    Mockito.when(profileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            String ar1 = invocation.getArgument(0);
            ProfileEntity p = new ProfileEntity();
            p.setId(ar1);
            if (ar1.equals("ids") || ar1.equals("or")) {
                p.setReviewed(true);
            } else {
                p.setReviewed(false);
            }
            return p;
        }
    });
    Mockito.when(profileEntityManager.reviewProfile("some")).thenThrow(new RuntimeException("Controller shouldn't try to review null profile"));
    Mockito.when(profileEntityManager.reviewProfile("orcid")).thenThrow(new RuntimeException("Controller shouldn't try to review null profile"));
    Mockito.when(profileEntityManager.reviewProfile("ids")).thenThrow(new RuntimeException("Controller shouldn't try to review reviewed profile"));
    Mockito.when(profileEntityManager.reviewProfile("or")).thenThrow(new RuntimeException("Controller shouldn't try to review reviewed profile"));
    Mockito.when(profileEntityManager.reviewProfile("emails")).thenReturn(true);
    Mockito.when(profileEntityManager.reviewProfile("to")).thenReturn(true);
    Mockito.when(profileEntityManager.reviewProfile("test")).thenReturn(true);
    Mockito.when(profileEntityManager.reviewProfile("with")).thenReturn(true);
    Map<String, Set<String>> results = adminController.reviewAccounts(commaSeparatedValues);
    assertEquals(2, results.get("notFoundList").size());
    assertTrue(results.get("notFoundList").contains("some"));
    assertTrue(results.get("notFoundList").contains("orcid"));
    assertEquals(2, results.get("alreadyReviewedList").size());
    assertTrue(results.get("alreadyReviewedList").contains("ids"));
    assertTrue(results.get("alreadyReviewedList").contains("or"));
    assertEquals(4, results.get("reviewSuccessfulList").size());
    assertTrue(results.get("reviewSuccessfulList").contains("emails"));
    assertTrue(results.get("reviewSuccessfulList").contains("to"));
    assertTrue(results.get("reviewSuccessfulList").contains("test"));
    assertTrue(results.get("reviewSuccessfulList").contains("with"));
    Mockito.verify(emailManager, Mockito.times(8)).emailExists(Mockito.anyString());
    Mockito.verify(profileEntityManager, Mockito.times(4)).reviewProfile(Mockito.anyString());
}
Also used : ProfileEntityCacheManager(org.orcid.core.manager.ProfileEntityCacheManager) Set(java.util.Set) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) EmailManager(org.orcid.core.manager.EmailManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProfileEntityManager(org.orcid.core.manager.ProfileEntityManager) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 74 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class OrcidSwitchUserFilter method attemptSwitchUser.

@Override
protected Authentication attemptSwitchUser(HttpServletRequest request) throws AuthenticationException {
    String targetUserOrcid = request.getParameter(SPRING_SECURITY_SWITCH_USERNAME_KEY);
    ProfileEntity profileEntity = sourceManager.retrieveSourceProfileEntity();
    if (OrcidType.ADMIN.equals(profileEntity.getOrcidType())) {
        return super.attemptSwitchUser(request);
    }
    // If we are switching back to me it is OK
    if (isSwitchingBack(request)) {
        return super.attemptSwitchUser(request);
    }
    for (GivenPermissionByEntity gpbe : profileEntity.getGivenPermissionBy()) {
        if (gpbe.getGiver().getId().equals(targetUserOrcid)) {
            return super.attemptSwitchUser(request);
        }
    }
    Object[] params = {};
    throw new SwitchUserAuthenticationException(localeManager.resolveMessage("web.orcid.switchuser.exception", params));
}
Also used : SwitchUserAuthenticationException(org.orcid.frontend.web.exception.SwitchUserAuthenticationException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) GivenPermissionByEntity(org.orcid.persistence.jpa.entities.GivenPermissionByEntity)

Example 75 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class WorkspaceController method setOtherNamesFormJson.

@RequestMapping(value = "/my-orcid/otherNamesForms.json", method = RequestMethod.POST)
@ResponseBody
public OtherNamesForm setOtherNamesFormJson(@RequestBody OtherNamesForm onf) throws NoSuchRequestHandlingMethodException {
    onf.setErrors(new ArrayList<String>());
    ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
    Visibility defaultVisibility = Visibility.valueOf(profile.getActivitiesVisibilityDefault());
    if (onf != null) {
        Iterator<OtherNameForm> it = onf.getOtherNames().iterator();
        while (it.hasNext()) {
            OtherNameForm form = it.next();
            if (PojoUtil.isEmpty(form.getContent())) {
                it.remove();
                continue;
            }
            if (form.getContent().length() > SiteConstants.MAX_LENGTH_255) {
                form.setContent(form.getContent().substring(0, SiteConstants.MAX_LENGTH_255));
            }
            //Set default visibility in case it is null
            if (form.getVisibility() == null || form.getVisibility().getVisibility() == null) {
                form.setVisibility(defaultVisibility);
            }
            copyErrors(form, onf);
        }
        if (onf.getErrors().size() > 0) {
            return onf;
        }
        OtherNames otherNames = onf.toOtherNames();
        otherNameManager.updateOtherNames(getEffectiveUserOrcid(), otherNames);
    }
    return onf;
}
Also used : OtherNames(org.orcid.jaxb.model.record_v2.OtherNames) Visibility(org.orcid.pojo.ajaxForm.Visibility) OtherNameForm(org.orcid.pojo.ajaxForm.OtherNameForm) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)231 Test (org.junit.Test)65 Date (java.util.Date)64 Transactional (org.springframework.transaction.annotation.Transactional)58 DBUnitTest (org.orcid.test.DBUnitTest)44 HashMap (java.util.HashMap)41 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)37 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)36 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)33 HashSet (java.util.HashSet)30 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)28 Rollback (org.springframework.test.annotation.Rollback)25 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)20 Set (java.util.Set)16 ArrayList (java.util.ArrayList)15 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)14 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)14 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)13 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)13 Authentication (org.springframework.security.core.Authentication)12