use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method updateClient.
/**
* Updates a client profile, updates can be adding or removing redirect uris
* or updating the client fields
*
* @param client
* The updated client
* @return the updated OrcidClient
*/
public OrcidClient updateClient(OrcidClient client) {
ClientDetailsEntity clientDetailsEntity = null;
if (client.getClientId() != null) {
// Look up the existing client.
String clientId = client.getClientId();
clientDetailsEntity = clientDetailsDao.find(clientId);
if (clientDetailsEntity == null) {
// error.
throw new OrcidClientGroupManagementException("Unable to find client: " + clientId);
} else {
// If the existing client is found, then update the client
// details from the incoming client, and save using the
// client details manager.
updateClientDetailsEntityFromClient(client, clientDetailsEntity, true);
clientDetailsManager.merge(clientDetailsEntity);
}
}
return adapter.toOrcidClient(clientDetailsEntity);
}
use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method processClient.
/**
* Get a client and evaluates if it is new or it is an update and act
* accordingly.
*
* @param groupOrcid
* The client owner
* @param clientDetailsEntities
* The cached list of clients
* @param client
* The client that is being evaluated
* @param clientType
* The type of client
*/
private void processClient(String groupOrcid, SortedSet<ClientDetailsEntity> clientDetailsEntities, OrcidClient client, ClientType clientType) {
if (client.getClientId() == null) {
// If the client ID in the incoming client is null, then create
// a new client.
// Use the client details service to create the client details
ClientDetailsEntity clientDetailsEntity = createClientDetails(groupOrcid, client, clientType);
// And link the client to the copy of the profile cached in
// memory by Hibernate
clientDetailsEntities.add(clientDetailsEntity);
} else {
// If the client ID in the incoming client is not null, then
// look up the existing client.
String clientId = client.getClientId();
ClientDetailsEntity clientDetailsEntity = clientDetailsManager.findByClientId(clientId);
if (clientDetailsEntity == null) {
// error.
throw new OrcidClientGroupManagementException("Unable to find client: " + clientId);
} else {
if (!PojoUtil.isEmpty(clientDetailsEntity.getGroupProfileId()) && !clientDetailsEntity.getGroupProfileId().equals(groupOrcid)) {
// error.
throw new OrcidClientGroupManagementException(String.format("Client %s does not belong to group %s (actually belongs to group %s)", clientId, groupOrcid, clientDetailsEntity.getGroupProfileId()));
}
// If the existing client is found, then update the client
// details from the incoming client
updateClientDetailsEntityFromClient(client, clientDetailsEntity, true);
clientDetailsManager.merge(clientDetailsEntity);
}
}
}
use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method updateGroup.
/**
* Updates an existing group profile. If the group doesnt exists it will
* throw a OrcidClientGroupManagementException
*
* @param orcidClientGroup
* The group to be updated
*/
@Transactional
public void updateGroup(OrcidClientGroup orcidClientGroup) {
String groupOrcid = orcidClientGroup.getGroupOrcid();
// If the incoming client group ORCID is not null, then lookup the
// existing client group.
ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
if (groupProfileEntity == null) {
// then raise an error.
throw new OrcidClientGroupManagementException("Group ORCID was specified but does not yet exist: " + groupOrcid);
} else {
boolean updateClientScopes = false;
// profile DAO
if (!orcidClientGroup.getEmail().equals(groupProfileEntity.getPrimaryEmail().getId())) {
EmailEntity primaryEmailEntity = new EmailEntity();
primaryEmailEntity.setId(orcidClientGroup.getEmail().toLowerCase().trim());
primaryEmailEntity.setCurrent(true);
primaryEmailEntity.setVerified(true);
primaryEmailEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
groupProfileEntity.setPrimaryEmail(primaryEmailEntity);
}
if (groupProfileEntity.getRecordNameEntity() == null) {
groupProfileEntity.setRecordNameEntity(new RecordNameEntity());
groupProfileEntity.getRecordNameEntity().setProfile(groupProfileEntity);
}
// Set the record name entity table
groupProfileEntity.getRecordNameEntity().setCreditName(orcidClientGroup.getGroupName());
groupProfileEntity.getRecordNameEntity().setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
groupProfileEntity.setSalesforeId(orcidClientGroup.getSalesforceId());
// If group type changed
if (!groupProfileEntity.getGroupType().equals(orcidClientGroup.getType())) {
// Update the group type
groupProfileEntity.setGroupType(orcidClientGroup.getType());
// Set the flag to update the client scopes
updateClientScopes = true;
}
// Merge changes
profileDao.merge(groupProfileEntity);
profileEntityManager.updateLastModifed(groupOrcid);
// Update client types and scopes
if (updateClientScopes)
updateClientTypeDueGroupTypeUpdate(groupProfileEntity);
}
}
use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method updateClient.
/**
* Updates a client profile, updates can be adding or removing redirect uris
* or updating the client fields
*
* @param groupOrcid
* The group owner for this client
* @param client
* The updated client
* @return the updated OrcidClient
*/
public OrcidClient updateClient(String groupOrcid, OrcidClient client) {
ClientDetailsEntity clientDetailsEntity = null;
if (client.getClientId() != null) {
// Look up the existing client.
String clientId = client.getClientId();
clientDetailsEntity = clientDetailsDao.find(clientId);
if (clientDetailsEntity == null) {
// error.
throw new OrcidClientGroupManagementException("Unable to find client: " + clientId);
} else {
if (!PojoUtil.isEmpty(clientDetailsEntity.getGroupProfileId()) && !clientDetailsEntity.getGroupProfileId().equals(groupOrcid)) {
// error.
throw new OrcidClientGroupManagementException(String.format("Client %s does not belong to group %s (actually belongs to group %s)", clientId, groupOrcid, clientDetailsEntity.getGroupProfileId()));
}
// If the existing client is found, then update the client
// details from the incoming client, and save using the client
// details manager
updateClientDetailsEntityFromClient(client, clientDetailsEntity, true);
clientDetailsManager.merge(clientDetailsEntity);
}
}
return adapter.toOrcidClient(clientDetailsEntity);
}
use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method createAndPersistClientProfile.
/**
* Creates a new client and set the group orcid as the owner of that client
*
* @param groupOrcid
* The group owner for this client
* @param client
* The new client
* @return the new OrcidClient
*/
public OrcidClient createAndPersistClientProfile(String groupOrcid, OrcidClient client) throws OrcidClientGroupManagementException {
if (!isAllowedToAddNewClient(groupOrcid))
throw new OrcidClientGroupManagementException("Your contract allows you to have only 1 client.");
ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
checkAndSetClientType(client, groupProfileEntity.getGroupType());
// Use the client details service to create the client details
ClientDetailsEntity clientDetailsEntity = createClientDetails(groupOrcid, client, client.getType());
// Link the client to the copy of the profile cached in
// memory by Hibernate
SortedSet<ClientDetailsEntity> clientProfileEntities = groupProfileEntity.getClients();
if (clientProfileEntities == null) {
clientProfileEntities = new TreeSet<>(new OrcidEntityIdComparator<String>());
groupProfileEntity.setClients(clientProfileEntities);
}
clientProfileEntities.add(clientDetailsEntity);
return adapter.toOrcidClient(clientDetailsEntity);
}
Aggregations