Search in sources :

Example 1 with SourceClientId

use of org.orcid.jaxb.model.message.SourceClientId in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorImpl method setSponsorFromAuthentication.

public void setSponsorFromAuthentication(OrcidProfile profile) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (profile.getOrcidHistory() == null) {
        OrcidHistory orcidHistory = new OrcidHistory();
        orcidHistory.setCreationMethod(CreationMethod.API);
        profile.setOrcidHistory(orcidHistory);
    }
    profile.getOrcidHistory().setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
        OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
        Source sponsor = new Source();
        String sponsorId = authorizationRequest.getClientId();
        ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(sponsorId);
        if (clientDetails != null) {
            sponsor.setSourceName(new SourceName(clientDetails.getClientName()));
            if (OrcidStringUtils.isClientId(sponsorId)) {
                sponsor.setSourceClientId(new SourceClientId(sponsorId));
            } else {
                sponsor.setSourceOrcid(new SourceOrcid(sponsorId));
            }
        }
        profile.getOrcidHistory().setSource(sponsor);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceName(org.orcid.jaxb.model.message.SourceName) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Source(org.orcid.jaxb.model.message.Source)

Example 2 with SourceClientId

use of org.orcid.jaxb.model.message.SourceClientId in project ORCID-Source by ORCID.

the class OrcidJaxbCopyManagerImpl method createSource.

private Source createSource(String amenderOrcid) {
    Source source = new Source();
    if (OrcidStringUtils.isValidOrcid(amenderOrcid)) {
        source.setSourceOrcid(new SourceOrcid(amenderOrcid));
        source.setSourceClientId(null);
    } else {
        source.setSourceClientId(new SourceClientId(amenderOrcid));
        source.setSourceOrcid(null);
    }
    return source;
}
Also used : SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source)

Example 3 with SourceClientId

use of org.orcid.jaxb.model.message.SourceClientId in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method createSource.

private Source createSource(String amenderOrcid) {
    Source source = new Source();
    if (OrcidStringUtils.isValidOrcid(amenderOrcid)) {
        source.setSourceOrcid(new SourceOrcid(amenderOrcid));
        source.setSourceClientId(null);
    } else {
        source.setSourceClientId(new SourceClientId(amenderOrcid));
        source.setSourceOrcid(null);
    }
    return source;
}
Also used : SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source)

Example 4 with SourceClientId

use of org.orcid.jaxb.model.message.SourceClientId in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorImpl method addExternalIdentifiers.

/**
 * Add new external identifiers to the profile. As with all calls, if the
 * message contains any other elements, a 400 Bad Request will be returned.
 *
 * @param orcidMessage
 *            the message congtaining the external ids
 * @return If successful, returns a 200 OK with the updated content.
 */
@Override
@AccessControl(requiredScope = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE)
public Response addExternalIdentifiers(UriInfo uriInfo, String orcid, OrcidMessage orcidMessage) {
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    try {
        ExternalIdentifiers updatedExternalIdentifiers = orcidProfile.getOrcidBio().getExternalIdentifiers();
        // Get the client profile information
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String clientId = null;
        if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
            OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
            clientId = authorizationRequest.getClientId();
        }
        for (ExternalIdentifier ei : updatedExternalIdentifiers.getExternalIdentifier()) {
            // Set the client profile to each external identifier
            if (ei.getSource() == null) {
                Source source = new Source();
                source.setSourceClientId(new SourceClientId(clientId));
                ei.setSource(source);
            } else {
                // Check if the provided external orcid exists
                Source source = ei.getSource();
                String sourceOrcid = source.retrieveSourcePath();
                if (sourceOrcid != null) {
                    if (StringUtils.isBlank(sourceOrcid) || (!profileEntityManager.orcidExists(sourceOrcid) && !clientDetailsManager.exists(sourceOrcid))) {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put("orcid", sourceOrcid);
                        throw new OrcidNotFoundException(params);
                    }
                }
            }
        }
        orcidProfile = orcidProfileManager.addExternalIdentifiers(orcidProfile);
        return getOrcidMessageResponse(orcidProfile, orcid);
    } catch (DataAccessException e) {
        throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_createorcid.exception"));
    }
}
Also used : ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) HashMap(java.util.HashMap) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) Source(org.orcid.jaxb.model.message.Source) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidNotFoundException(org.orcid.core.exception.OrcidNotFoundException) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) DataAccessException(org.springframework.dao.DataAccessException) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Example 5 with SourceClientId

use of org.orcid.jaxb.model.message.SourceClientId in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method getSource.

private Source getSource() {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    Source source = new Source();
    if (sourceEntity.getSourceProfile() != null && !PojoUtil.isEmpty(sourceEntity.getSourceProfile().getId())) {
        source.setSourceOrcid(new SourceOrcid(getOrcidIdBase(sourceEntity.getSourceProfile().getId())));
    }
    if (sourceEntity.getSourceClient() != null && !PojoUtil.isEmpty(sourceEntity.getSourceClient().getId())) {
        if (OrcidStringUtils.isValidOrcid(sourceEntity.getSourceClient().getId())) {
            source.setSourceOrcid(new SourceOrcid(getOrcidIdBase(sourceEntity.getSourceClient().getId())));
        } else {
            source.setSourceClientId(new SourceClientId(getOrcidIdBase(sourceEntity.getSourceClient().getId())));
        }
    }
    return source;
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source)

Aggregations

Source (org.orcid.jaxb.model.message.Source)6 SourceClientId (org.orcid.jaxb.model.message.SourceClientId)6 SourceOrcid (org.orcid.jaxb.model.message.SourceOrcid)5 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)2 Authentication (org.springframework.security.core.Authentication)2 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)2 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 OrcidBadRequestException (org.orcid.core.exception.OrcidBadRequestException)1 OrcidNotFoundException (org.orcid.core.exception.OrcidNotFoundException)1 AccessControl (org.orcid.core.security.visibility.aop.AccessControl)1 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)1 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)1 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 SourceName (org.orcid.jaxb.model.message.SourceName)1 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)1 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)1 DataAccessException (org.springframework.dao.DataAccessException)1