Search in sources :

Example 1 with GivenPermissionByEntity

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"));
}
Also used : SwitchUserAuthenticationException(org.orcid.frontend.web.exception.SwitchUserAuthenticationException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) GivenPermissionByEntity(org.orcid.persistence.jpa.entities.GivenPermissionByEntity)

Example 2 with GivenPermissionByEntity

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;
}
Also used : GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) GivenPermissionByEntity(org.orcid.persistence.jpa.entities.GivenPermissionByEntity)

Example 3 with GivenPermissionByEntity

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;
}
Also used : DelegateForm(org.orcid.pojo.DelegateForm) ArrayList(java.util.ArrayList) GivenPermissionByEntity(org.orcid.persistence.jpa.entities.GivenPermissionByEntity) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

GivenPermissionByEntity (org.orcid.persistence.jpa.entities.GivenPermissionByEntity)3 ArrayList (java.util.ArrayList)1 SwitchUserAuthenticationException (org.orcid.frontend.web.exception.SwitchUserAuthenticationException)1 GivenPermissionToEntity (org.orcid.persistence.jpa.entities.GivenPermissionToEntity)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 DelegateForm (org.orcid.pojo.DelegateForm)1 Cacheable (org.springframework.cache.annotation.Cacheable)1