use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class Jpa2JaxbAdapterImpl method toOrcidClientGroup.
@Override
public OrcidClientGroup toOrcidClientGroup(ProfileEntity profileEntity) {
OrcidClientGroup group = new OrcidClientGroup();
group.setGroupOrcid(profileEntity.getId());
if (profileEntity.getRecordNameEntity() != null) {
group.setGroupName(profileEntity.getRecordNameEntity().getCreditName());
}
group.setType(profileEntity.getGroupType());
Set<EmailEntity> emailEntities = profileEntity.getEmails();
for (EmailEntity emailEntity : emailEntities) {
group.setEmail(emailEntity.getId());
}
for (ClientDetailsEntity clientDetailsEntity : profileEntity.getClients()) {
OrcidClient client = toOrcidClient(clientDetailsEntity);
group.getOrcidClient().add(client);
}
return group;
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class ThirdPartyLinkManagerImpl method getClients.
private List<OrcidClient> getClients(RedirectUriType rut) {
List<OrcidClient> orcidClients = new ArrayList<OrcidClient>();
List<ClientRedirectUriEntity> entitiesWithPredefinedScopes = clientRedirectDao.findClientDetailsWithRedirectScope();
for (ClientRedirectUriEntity entity : entitiesWithPredefinedScopes) {
if (rut.value().equals(entity.getRedirectUriType())) {
ClientDetailsEntity clientDetails = entity.getClientDetailsEntity();
RedirectUri redirectUri = new RedirectUri(entity.getRedirectUri());
String prefefinedScopes = entity.getPredefinedClientScope();
redirectUri.setScope(new ArrayList<ScopePathType>(ScopePathType.getScopesFromSpaceSeparatedString(prefefinedScopes)));
redirectUri.setType(RedirectUriType.fromValue(entity.getRedirectUriType()));
redirectUri.setActType(entity.getUriActType());
redirectUri.setGeoArea(entity.getUriGeoArea());
RedirectUris redirectUris = new RedirectUris();
redirectUris.getRedirectUri().add(redirectUri);
OrcidClient minimalClientDetails = new OrcidClient();
minimalClientDetails.setDisplayName(clientDetails.getClientName());
minimalClientDetails.setShortDescription(clientDetails.getClientDescription());
minimalClientDetails.setClientId(clientDetails.getClientId());
minimalClientDetails.setRedirectUris(redirectUris);
orcidClients.add(minimalClientDetails);
}
}
return orcidClients;
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class SourceManagerImpl method retrieveSourceEntity.
@Override
public SourceEntity retrieveSourceEntity() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return null;
}
// API
if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
String clientId = authorizationRequest.getClientId();
ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
SourceEntity sourceEntity = new SourceEntity();
sourceEntity.setSourceClient(new ClientDetailsEntity(clientId, clientDetails.getClientName()));
sourceEntity.getSourceName();
return sourceEntity;
}
String userOrcid = retrieveEffectiveOrcid(authentication);
if (userOrcid == null) {
// Must be system role
return null;
}
// Normal web user
SourceEntity sourceEntity = new SourceEntity();
sourceEntity.setSourceProfile(new ProfileEntity(userOrcid));
return sourceEntity;
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class ClientDetailsManagerReadOnlyImpl method findByClientId.
@Override
public ClientDetailsEntity findByClientId(String clientId) {
ClientDetailsEntity result = null;
try {
Date lastModified = clientDetailsDao.getLastModified(clientId);
result = clientDetailsDao.findByClientId(clientId, lastModified.getTime());
if (result != null) {
if (!result.getClientId().equals(clientId))
LOGGER.error("Client getClientId doesn't match. Requested: " + clientId + " Returned: " + result.getClientId());
if (!result.getId().equals(clientId))
LOGGER.error("Client getId() doesn't match. Requested: " + clientId + " Returned: " + result.getId());
}
} catch (NoResultException nre) {
LOGGER.error("Error getting client by id:" + clientId, nre);
}
return result;
}
use of org.orcid.persistence.jpa.entities.ClientDetailsEntity in project ORCID-Source by ORCID.
the class NotificationManagerTest method testAmendEmail.
@Test
public void testAmendEmail() throws JAXBException, IOException, URISyntaxException {
SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
String testOrcid = "0000-0000-0000-0003";
for (Locale locale : Locale.values()) {
NotificationEntity previousNotification = notificationDao.findLatestByOrcid(testOrcid);
long minNotificationId = previousNotification != null ? previousNotification.getId() : -1;
OrcidProfile orcidProfile = getProfile(locale);
notificationManager.sendAmendEmail(orcidProfile, AmendedSection.UNKNOWN);
// New notification entity should have been created
NotificationEntity latestNotification = notificationDao.findLatestByOrcid(testOrcid);
assertNotNull(latestNotification);
assertTrue(latestNotification.getId() > minNotificationId);
assertEquals(NotificationType.AMENDED, latestNotification.getNotificationType());
}
}
Aggregations