Search in sources :

Example 11 with DelegateForm

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

the class GivenPermissionToManagerReadOnlyImpl method findByGiver.

@Override
@Cacheable(value = "delegates-by-giver", key = "#giverOrcid.concat('-').concat(#lastModified)")
public List<DelegateForm> findByGiver(String giverOrcid, long lastModified) {
    List<DelegateForm> delegates = new ArrayList<DelegateForm>();
    List<GivenPermissionToEntity> list = givenPermissionToDaoReadOnly.findByGiver(giverOrcid);
    for (GivenPermissionToEntity element : list) {
        DelegateForm form = new DelegateForm();
        form.setApprovalDate(DateUtils.convertToXMLGregorianCalendar(element.getApprovalDate()));
        form.setGiverOrcid(orcidIdentifierUtils.buildOrcidIdentifier(element.getGiver()));
        form.setReceiverOrcid(orcidIdentifierUtils.buildOrcidIdentifier(element.getReceiver().getId()));
        form.setReceiverName(Text.valueOf(element.getReceiver().getDisplayName()));
        delegates.add(form);
    }
    return delegates;
}
Also used : GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) DelegateForm(org.orcid.pojo.DelegateForm) ArrayList(java.util.ArrayList) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 12 with DelegateForm

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

the class ManageDelegatorsController method searchDelegators.

/**
 * Search DB for disambiguated affiliations to suggest to user
 */
@RequestMapping(value = "/search/{query}", method = RequestMethod.GET)
@ResponseBody
public List<DelegateForm> searchDelegators(@PathVariable("query") String query, @RequestParam(value = "limit") int limit) {
    Locale locale = getLocale();
    query = query.toLowerCase(locale);
    String realUserOrcid = getRealUserOrcid();
    String currentOrcid = getEffectiveUserOrcid();
    List<DelegateForm> delegates = givenPermissionToManagerReadOnly.findByReceiver(realUserOrcid, getLastModified(realUserOrcid));
    List<DelegateForm> filtered = new ArrayList<DelegateForm>();
    for (DelegateForm delegate : delegates) {
        String name = delegate.getGiverName().getValue().toLowerCase(locale);
        String orcidUri = delegate.getGiverOrcid().getUri();
        String orcidPath = delegate.getGiverOrcid().getPath();
        if ((name.contains(query) || orcidUri.contains(query)) && !(currentOrcid.equals(orcidPath))) {
            filtered.add(delegate);
        }
    }
    return filtered;
}
Also used : Locale(java.util.Locale) DelegateForm(org.orcid.pojo.DelegateForm) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with DelegateForm

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

the class GivenPermissionToManagerTest method testFindByGiverAndReceiverOrcid.

@Test
public void testFindByGiverAndReceiverOrcid() {
    DelegateForm form = givenPermissionToManagerReadOnly.findByGiverAndReceiverOrcid(GIVER, RECEIVER);
    assertNotNull(form);
    assertEquals(GIVER, form.getGiverOrcid().getPath());
    assertEquals(RECEIVER, form.getReceiverOrcid().getPath());
}
Also used : DelegateForm(org.orcid.pojo.DelegateForm) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 14 with DelegateForm

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

the class GivenPermissionToManagerTest method testRemove.

@Test
public void testRemove() {
    // Create one
    givenPermissionToManager.create(RECEIVER, GIVER);
    // Find it
    DelegateForm form = givenPermissionToManagerReadOnly.findByGiverAndReceiverOrcid(RECEIVER, GIVER);
    assertNotNull(form);
    assertEquals(RECEIVER, form.getGiverOrcid().getPath());
    assertEquals(GIVER, form.getReceiverOrcid().getPath());
    Date rLastModifiedBefore = profileEntityManager.getLastModifiedDate(RECEIVER);
    Date gLastModifiedBefore = profileEntityManager.getLastModifiedDate(GIVER);
    // Delete it
    givenPermissionToManager.remove(RECEIVER, GIVER);
    // Verify it was deleted
    form = givenPermissionToManagerReadOnly.findByGiverAndReceiverOrcid(RECEIVER, GIVER);
    assertNull(form);
    Date rLastModifiedAfter = profileEntityManager.getLastModifiedDate(RECEIVER);
    Date gLastModifiedAfter = profileEntityManager.getLastModifiedDate(GIVER);
    assertTrue(rLastModifiedAfter.after(rLastModifiedBefore));
    assertTrue(gLastModifiedAfter.after(gLastModifiedBefore));
}
Also used : DelegateForm(org.orcid.pojo.DelegateForm) Date(java.util.Date) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

DelegateForm (org.orcid.pojo.DelegateForm)14 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 GivenPermissionToEntity (org.orcid.persistence.jpa.entities.GivenPermissionToEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 Date (java.util.Date)3 BaseTest (org.orcid.core.BaseTest)3 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 IntStream (java.util.stream.IntStream)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Assert.assertEquals (org.junit.Assert.assertEquals)1