use of org.orcid.persistence.jpa.entities.GivenPermissionByEntity 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(OrcidType.valueOf(profileEntity.getOrcidType().name()))) {
return switchUser(request);
}
// If we are switching back to me it is OK
if (isSwitchingBack(request)) {
return switchUser(request);
}
List<GivenPermissionByEntity> givenPermissionBy = givenPermissionToDao.findByReceiver(profileEntity.getId());
for (GivenPermissionByEntity gpbe : givenPermissionBy) {
if (gpbe.getGiver().getId().equals(targetUserOrcid)) {
return switchUser(request);
}
}
throw new SwitchUserAuthenticationException(localeManager.resolveMessage("web.orcid.switchuser.exception"));
}
use of org.orcid.persistence.jpa.entities.GivenPermissionByEntity 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.GivenPermissionByEntity in project ORCID-Source by ORCID.
the class GivenPermissionToManagerReadOnlyImpl method findByReceiver.
@Override
@Cacheable(value = "delegates-by-receiver", key = "#receiverOrcid.concat('-').concat(#lastModified)")
public List<DelegateForm> findByReceiver(String receiverOrcid, long lastModified) {
List<DelegateForm> delegates = new ArrayList<DelegateForm>();
List<GivenPermissionByEntity> list = givenPermissionToDaoReadOnly.findByReceiver(receiverOrcid);
for (GivenPermissionByEntity element : list) {
DelegateForm form = new DelegateForm();
form.setApprovalDate(DateUtils.convertToXMLGregorianCalendar(element.getApprovalDate()));
form.setLastModifiedDate(DateUtils.convertToXMLGregorianCalendar(element.getGiver().getLastModified()));
form.setGiverName(Text.valueOf(element.getGiver().getDisplayName()));
form.setGiverOrcid(orcidIdentifierUtils.buildOrcidIdentifier(element.getGiver().getId()));
form.setReceiverOrcid(orcidIdentifierUtils.buildOrcidIdentifier(element.getReceiver()));
delegates.add(form);
}
return delegates;
}
Aggregations