use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class GroupAdministratorController method createClient.
@RequestMapping(value = "/add-client.json", method = RequestMethod.POST)
@Produces(value = { MediaType.APPLICATION_JSON })
@ResponseBody
public Client createClient(@RequestBody Client client) {
// Clean the error list
client.setErrors(new ArrayList<String>());
// Validate fields
validateDisplayName(client);
validateWebsite(client);
validateShortDescription(client);
validateRedirectUris(client);
copyErrors(client.getDisplayName(), client);
copyErrors(client.getWebsite(), client);
copyErrors(client.getShortDescription(), client);
for (RedirectUri redirectUri : client.getRedirectUris()) {
copyErrors(redirectUri, client);
}
if (client.getErrors().size() == 0) {
OrcidProfile profile = getEffectiveProfile();
String groupOrcid = profile.getOrcidIdentifier().getPath();
if (profile.getType() == null || !profile.getType().equals(OrcidType.GROUP)) {
LOGGER.warn("Trying to create client with non group user {}", profile.getOrcidIdentifier().getPath());
throw new OrcidClientGroupManagementException(getMessage("web.orcid.privilege.exception"));
}
OrcidClient result = null;
try {
result = orcidClientGroupManager.createAndPersistClientProfile(groupOrcid, client.toOrcidClient());
} catch (OrcidClientGroupManagementException e) {
LOGGER.error(e.getMessage());
result = new OrcidClient();
result.setErrors(new ErrorDesc(getMessage("manage.developer_tools.group.cannot_create_client")));
}
client = Client.valueOf(result);
}
return client;
}
use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerTest method testAddUpdaterToBasicInstitutionGroup.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddUpdaterToBasicInstitutionGroup() {
final OrcidClientGroup group = new OrcidClientGroup();
group.setGroupName("Elsevier");
group.setEmail("basic-institution-member@elsevier.com" + System.currentTimeMillis());
group.setType(MemberType.BASIC_INSTITUTION);
OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {
public OrcidClientGroup doInTransaction(TransactionStatus status) {
return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
}
});
RedirectUris redirectUris = new RedirectUris();
RedirectUri redirectUri = new RedirectUri("http://uri.com");
redirectUris.getRedirectUri().add(redirectUri);
OrcidClient client1 = new OrcidClient();
client1.setDisplayName("Name");
client1.setRedirectUris(redirectUris);
client1.setShortDescription("Description");
client1.setType(ClientType.UPDATER);
client1.setWebsite("http://site.com");
// Add one creator client to a basic group should fail
try {
OrcidClient orcidClient = orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
assertEquals(orcidClient.getType(), ClientType.CREATOR);
} catch (OrcidClientGroupManagementException e) {
}
}
use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerTest method testAddMoreThanOneClientToBasicGroup.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddMoreThanOneClientToBasicGroup() {
final OrcidClientGroup group = new OrcidClientGroup();
group.setGroupName("Elsevier");
group.setEmail("basic-member@elsevier.com" + System.currentTimeMillis());
group.setType(MemberType.BASIC);
OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {
public OrcidClientGroup doInTransaction(TransactionStatus status) {
return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
}
});
RedirectUris redirectUris = new RedirectUris();
RedirectUri redirectUri = new RedirectUri("http://uri.com");
redirectUris.getRedirectUri().add(redirectUri);
OrcidClient client1 = new OrcidClient();
client1.setDisplayName("Name");
client1.setRedirectUris(redirectUris);
client1.setShortDescription("Description");
client1.setType(ClientType.UPDATER);
client1.setWebsite("http://site.com");
// Add one client
try {
orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
} catch (OrcidClientGroupManagementException e) {
fail();
}
OrcidClient client2 = new OrcidClient();
client2.setDisplayName("Name");
client2.setRedirectUris(redirectUris);
client2.setShortDescription("Description");
client2.setType(ClientType.UPDATER);
client2.setWebsite("http://site.com");
// Add other client should fail
try {
orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client2);
fail();
} catch (OrcidClientGroupManagementException e) {
}
}
use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerTest method testAddCreatorToBasicGroup.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddCreatorToBasicGroup() {
final OrcidClientGroup group = new OrcidClientGroup();
group.setGroupName("Elsevier");
group.setEmail("basic-member@elsevier.com" + System.currentTimeMillis());
group.setType(MemberType.PREMIUM);
OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {
public OrcidClientGroup doInTransaction(TransactionStatus status) {
return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
}
});
RedirectUris redirectUris = new RedirectUris();
RedirectUri redirectUri = new RedirectUri("http://uri.com");
redirectUris.getRedirectUri().add(redirectUri);
OrcidClient client1 = new OrcidClient();
client1.setDisplayName("Name");
client1.setRedirectUris(redirectUris);
client1.setShortDescription("Description");
client1.setType(ClientType.CREATOR);
client1.setWebsite("http://site.com");
// Add one creator client to a basic group should fail
try {
OrcidClient orcidClient = orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
assertEquals(ClientType.UPDATER, orcidClient.getType());
} catch (OrcidClientGroupManagementException e) {
}
}
use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerTest method testAddUpdaterToPremiumInstitutionGroup.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddUpdaterToPremiumInstitutionGroup() {
final OrcidClientGroup group = new OrcidClientGroup();
group.setGroupName("Elsevier");
group.setEmail("premium-institution-member@elsevier.com" + System.currentTimeMillis());
group.setType(MemberType.PREMIUM_INSTITUTION);
OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {
public OrcidClientGroup doInTransaction(TransactionStatus status) {
return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
}
});
RedirectUris redirectUris = new RedirectUris();
RedirectUri redirectUri = new RedirectUri("http://uri.com");
redirectUris.getRedirectUri().add(redirectUri);
OrcidClient client1 = new OrcidClient();
client1.setDisplayName("Name");
client1.setRedirectUris(redirectUris);
client1.setShortDescription("Description");
client1.setType(ClientType.UPDATER);
client1.setWebsite("http://site.com");
// Add one creator client to a premium group should fail
try {
OrcidClient orcidClient = orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
assertEquals(orcidClient.getType(), ClientType.PREMIUM_CREATOR);
} catch (OrcidClientGroupManagementException e) {
}
}
Aggregations