Search in sources :

Example 6 with GivenPermissionToEntity

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

the class GivenPermissionToManagerTest method testFindByGiverAndReceiverOrcid.

@Test
public void testFindByGiverAndReceiverOrcid() {
    GivenPermissionToEntity entity = givenPermissionToManager.findByGiverAndReceiverOrcid(GIVER, RECEIVER);
    assertNotNull(entity);
    assertEquals(GIVER, entity.getGiver());
    assertEquals(RECEIVER, entity.getReceiver().getId());
}
Also used : GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 7 with GivenPermissionToEntity

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

the class GivenPermissionToManagerTest method testRemove.

@Test
public void testRemove() {
    // Create one
    givenPermissionToManager.create(RECEIVER, GIVER);
    // Find it
    GivenPermissionToEntity entity = givenPermissionToManager.findByGiverAndReceiverOrcid(RECEIVER, GIVER);
    assertNotNull(entity);
    assertEquals(RECEIVER, entity.getGiver());
    assertEquals(GIVER, entity.getReceiver().getId());
    Date rLastModifiedBefore = profileEntityManager.getLastModifiedDate(RECEIVER);
    Date gLastModifiedBefore = profileEntityManager.getLastModifiedDate(GIVER);
    // Delete it
    givenPermissionToManager.remove(RECEIVER, GIVER);
    // Verify it was deleted
    entity = givenPermissionToManager.findByGiverAndReceiverOrcid(RECEIVER, GIVER);
    assertNull(entity);
    Date rLastModifiedAfter = profileEntityManager.getLastModifiedDate(RECEIVER);
    Date gLastModifiedAfter = profileEntityManager.getLastModifiedDate(GIVER);
    assertTrue(rLastModifiedAfter.after(rLastModifiedBefore));
    assertTrue(gLastModifiedAfter.after(gLastModifiedBefore));
}
Also used : GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) Date(java.util.Date) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 8 with GivenPermissionToEntity

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

the class Jpa2JaxbAdapterImpl method getDelegation.

private Delegation getDelegation(ProfileEntity profileEntity) {
    Set<GivenPermissionToEntity> givenPermissionToEntities = profileEntity.getGivenPermissionTo();
    Set<GivenPermissionByEntity> givenPermissionByEntities = profileEntity.getGivenPermissionBy();
    Delegation delegation = null;
    if (givenPermissionToEntities != null && !givenPermissionToEntities.isEmpty()) {
        delegation = new Delegation();
        GivenPermissionTo givenPermissionTo = new GivenPermissionTo();
        delegation.setGivenPermissionTo(givenPermissionTo);
        for (GivenPermissionToEntity givenPermissionToEntity : givenPermissionToEntities) {
            DelegationDetails delegationDetails = new DelegationDetails();
            DelegateSummary delegateSummary = new DelegateSummary(new OrcidIdentifier(getOrcidIdBase(givenPermissionToEntity.getReceiver().getId())));
            delegateSummary.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(givenPermissionToEntity.getReceiver().getLastModified())));
            String receiverCreditName = givenPermissionToEntity.getReceiver().getDisplayName();
            delegateSummary.setCreditName(StringUtils.isNotBlank(receiverCreditName) ? new CreditName(receiverCreditName) : null);
            delegationDetails.setDelegateSummary(delegateSummary);
            delegationDetails.setApprovalDate(new ApprovalDate(DateUtils.convertToXMLGregorianCalendar(givenPermissionToEntity.getApprovalDate())));
            givenPermissionTo.getDelegationDetails().add(delegationDetails);
        }
    }
    if (givenPermissionByEntities != null && !givenPermissionByEntities.isEmpty()) {
        if (delegation == null) {
            delegation = new Delegation();
        }
        GivenPermissionBy givenPermissionBy = new GivenPermissionBy();
        delegation.setGivenPermissionBy(givenPermissionBy);
        for (GivenPermissionByEntity givenPermissionByEntity : givenPermissionByEntities) {
            DelegationDetails delegationDetails = new DelegationDetails();
            DelegateSummary delegateSummary = new DelegateSummary(new OrcidIdentifier(getOrcidIdBase((givenPermissionByEntity.getGiver().getId()))));
            delegateSummary.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(givenPermissionByEntity.getGiver().getLastModified())));
            String creditName = givenPermissionByEntity.getGiver().getDisplayName();
            delegateSummary.setCreditName(StringUtils.isNotBlank(creditName) ? new CreditName(creditName) : null);
            delegationDetails.setDelegateSummary(delegateSummary);
            delegationDetails.setApprovalDate(new ApprovalDate(DateUtils.convertToXMLGregorianCalendar(givenPermissionByEntity.getApprovalDate())));
            givenPermissionBy.getDelegationDetails().add(delegationDetails);
        }
    }
    return delegation;
}
Also used : GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) GivenPermissionByEntity(org.orcid.persistence.jpa.entities.GivenPermissionByEntity)

Example 9 with GivenPermissionToEntity

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

the class SetUpClientsAndUsers method setUpDelegates.

// ------------------------------------------------------------------------------
/**
 * Set up delegates
 * Please see tests:
 */
public void setUpDelegates(String giver, String receiver) {
    GivenPermissionToEntity permission = new GivenPermissionToEntity();
    permission.setGiver(giver);
    ProfileSummaryEntity r = new ProfileSummaryEntity(receiver);
    r.setLastModified(new Date());
    permission.setReceiver(r);
    permission.setApprovalDate(new Date());
    givenPermissionToDao.merge(permission);
    givenPermissionToDao.flush();
}
Also used : ProfileSummaryEntity(org.orcid.persistence.jpa.entities.ProfileSummaryEntity) GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) Date(java.util.Date) LocalDate(java.time.LocalDate) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate)

Example 10 with GivenPermissionToEntity

use of org.orcid.persistence.jpa.entities.GivenPermissionToEntity 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)

Aggregations

GivenPermissionToEntity (org.orcid.persistence.jpa.entities.GivenPermissionToEntity)10 Date (java.util.Date)4 Test (org.junit.Test)4 DelegateForm (org.orcid.pojo.DelegateForm)4 ArrayList (java.util.ArrayList)3 BaseTest (org.orcid.core.BaseTest)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 HashSet (java.util.HashSet)2 LocalDate (java.time.LocalDate)1 Arrays (java.util.Arrays)1 List (java.util.List)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 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertTrue (org.junit.Assert.assertTrue)1