Search in sources :

Example 1 with BiographyForm

use of org.orcid.pojo.ajaxForm.BiographyForm in project ORCID-Source by ORCID.

the class ManageProfileController method getBiographyForm.

@RequestMapping(value = "/biographyForm.json", method = RequestMethod.GET)
@ResponseBody
public BiographyForm getBiographyForm() {
    Biography bio = biographyManager.getBiography(getCurrentUserOrcid(), profileEntityManager.getLastModified(getCurrentUserOrcid()));
    BiographyForm form = BiographyForm.valueOf(bio);
    if (form.getVisiblity() == null) {
        ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
        form.setVisiblity(Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
    }
    return form;
}
Also used : BiographyForm(org.orcid.pojo.ajaxForm.BiographyForm) Biography(org.orcid.jaxb.model.record_v2.Biography) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with BiographyForm

use of org.orcid.pojo.ajaxForm.BiographyForm in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testValidateBiography.

@Test
public void testValidateBiography() {
    BiographyManager mockBiographyManager = Mockito.mock(BiographyManager.class);
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    TargetProxyHelper.injectIntoProxy(controller, "biographyManager", mockBiographyManager);
    when(mockBiographyManager.exists(Mockito.anyString())).thenReturn(true);
    BiographyForm bf = new BiographyForm();
    // No NPE exception on empty bio
    controller.setBiographyFormJson(bf);
    assertNotNull(bf.getErrors());
    assertTrue(bf.getErrors().isEmpty());
    String bio = StringUtils.repeat('a', 5001);
    bf.setBiography(Text.valueOf(bio));
    controller.setBiographyFormJson(bf);
    assertEquals(1, bf.getErrors().size());
    assertEquals("Length.changePersonalInfoForm.biography", bf.getErrors().get(0));
    bio = StringUtils.repeat('a', 5000);
    bf.setBiography(Text.valueOf(bio));
    controller.setBiographyFormJson(bf);
    assertTrue(bf.getErrors().isEmpty());
    Biography bioElement = new Biography();
    bioElement.setContent(bio);
    verify(mockBiographyManager, times(1)).updateBiography(Mockito.eq(USER_ORCID), Mockito.eq(bioElement));
}
Also used : BiographyForm(org.orcid.pojo.ajaxForm.BiographyForm) BiographyManager(org.orcid.core.manager.BiographyManager) Biography(org.orcid.jaxb.model.record_v2.Biography) Test(org.junit.Test)

Aggregations

Biography (org.orcid.jaxb.model.record_v2.Biography)2 BiographyForm (org.orcid.pojo.ajaxForm.BiographyForm)2 Test (org.junit.Test)1 BiographyManager (org.orcid.core.manager.BiographyManager)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1