use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method createOrUpdateOrcidClientGroup.
@Override
@Transactional
public OrcidClientGroup createOrUpdateOrcidClientGroup(OrcidClientGroup orcidClientGroup) {
// For each client in the client group, validate the client type
for (OrcidClient client : orcidClientGroup.getOrcidClient()) {
checkAndSetClientType(client, orcidClientGroup.getType());
}
String groupOrcid = orcidClientGroup.getGroupOrcid();
if (groupOrcid == null) {
orcidClientGroup = createGroup(orcidClientGroup);
groupOrcid = orcidClientGroup.getGroupOrcid();
} else {
updateGroup(orcidClientGroup);
}
// Use the profile DAO to link the clients to the group, so get the
// group profile entity.
ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
SortedSet<ClientDetailsEntity> clientProfileEntities = groupProfileEntity.getClients();
if (clientProfileEntities == null) {
clientProfileEntities = new TreeSet<>(new OrcidEntityIdComparator<String>());
groupProfileEntity.setClients(clientProfileEntities);
}
// For each client in the client group
for (OrcidClient client : orcidClientGroup.getOrcidClient()) {
processClient(groupOrcid, clientProfileEntities, client, getClientType(groupProfileEntity.getGroupType()));
}
// Regenerate client group and return.
return retrieveOrcidClientGroup(groupOrcid);
}
use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method retrieveOrcidClientGroup.
@Override
@Transactional
public OrcidClientGroup retrieveOrcidClientGroup(String groupOrcid) {
ProfileEntity profileEntity = profileDao.find(groupOrcid);
if (profileEntity == null) {
return null;
}
OrcidClientGroup group = adapter.toOrcidClientGroup(profileEntity);
for (OrcidClient client : group.getOrcidClient()) {
client.setClientSecret(encryptionManager.decryptForInternalUse(client.getClientSecret()));
}
return group;
}
use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.
the class MembersManagerImpl method updateClient.
@Override
public Client updateClient(Client client) {
OrcidClient result = null;
try {
result = orcidClientGroupManager.updateClient(client.toOrcidClient());
clearCache();
} catch (OrcidClientGroupManagementException e) {
LOGGER.error(e.getMessage());
result = new OrcidClient();
result.setErrors(new ErrorDesc(getMessage("manage.developer_tools.group.unable_to_update")));
}
return Client.valueOf(result);
}
use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.
the class Client method valueOf.
public static Client valueOf(OrcidClient orcidClient) {
Client client = new Client();
client.setClientId(Text.valueOf(orcidClient.getClientId()));
client.setClientSecret(Text.valueOf(orcidClient.getClientSecret()));
client.setDisplayName(Text.valueOf(orcidClient.getDisplayName()));
client.setShortDescription(Text.valueOf(orcidClient.getShortDescription()));
if (orcidClient.getType() != null)
client.setType(Text.valueOf(orcidClient.getType().value()));
client.setWebsite(Text.valueOf(orcidClient.getWebsite()));
Checkbox persistentTokenEnabled = new Checkbox();
persistentTokenEnabled.setValue(orcidClient.isPersistentTokenEnabled());
client.setPersistentTokenEnabled(persistentTokenEnabled);
List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
RedirectUris orcidRedirectUris = orcidClient.getRedirectUris();
if (orcidRedirectUris != null && orcidRedirectUris.getRedirectUri() != null) {
for (org.orcid.jaxb.model.clientgroup.RedirectUri orcidRedirectUri : orcidRedirectUris.getRedirectUri()) {
redirectUris.add(RedirectUri.toRedirectUri(orcidRedirectUri));
}
}
if (orcidClient.getIdp() != null) {
client.setAuthenticationProviderId(Text.valueOf(orcidClient.getIdp()));
}
client.setRedirectUris(redirectUris);
client.setAllowAutoDeprecate(Checkbox.valueOf(orcidClient.getAllowAutoDeprecate()));
return client;
}
use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerTest method testCreateOrcidCreatorClientGroup.
@Test
public void testCreateOrcidCreatorClientGroup() {
OrcidClientGroup createdGroup = orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
assertNotNull(createdGroup);
assertEquals(group.getGroupName(), createdGroup.getGroupName());
assertEquals(group.getEmail(), createdGroup.getEmail());
assertNotNull(createdGroup.getGroupOrcid());
List<OrcidClient> createdClients = createdGroup.getOrcidClient();
assertNotNull(createdClients);
assertEquals(2, createdClients.size());
Map<String, OrcidClient> createdClientsMappedByName = new HashMap<String, OrcidClient>();
for (OrcidClient createdClient : createdClients) {
assertNotNull(createdClient.getClientId());
assertNotNull(createdClient.getClientSecret());
assertNotNull(createdClient.getIdp());
createdClientsMappedByName.put(createdClient.getDisplayName(), createdClient);
}
OrcidClient complexityClient = createdClientsMappedByName.get("Ecological Complexity");
assertNotNull(complexityClient);
assertEquals("http://www.journals.elsevier.com/ecological-complexity", complexityClient.getWebsite());
assertEquals("An International Journal on Biocomplexity in the Environment and Theoretical Ecology", complexityClient.getShortDescription());
List<RedirectUri> createdRedirectUris = complexityClient.getRedirectUris().getRedirectUri();
assertNotNull(createdRedirectUris);
assertEquals(1, createdRedirectUris.size());
assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", createdRedirectUris.get(0).getValue());
// Look up client details directly to check scopes
ClientDetailsEntity complexityEntity = clientDetailsManager.findByClientId(complexityClient.getClientId());
Set<String> clientScopeTypes = complexityEntity.getScope();
assertNotNull(clientScopeTypes);
assertTrue(clientScopeTypes.contains("/orcid-profile/read-limited"));
assertTrue(clientScopeTypes.contains("/orcid-bio/read-limited"));
assertTrue(clientScopeTypes.contains("/orcid-works/read-limited"));
}
Aggregations