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());
}
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));
}
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;
}
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();
}
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;
}
Aggregations