use of org.orcid.persistence.jpa.entities.OrcidEntityIdComparator 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.persistence.jpa.entities.OrcidEntityIdComparator 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);
}
use of org.orcid.persistence.jpa.entities.OrcidEntityIdComparator in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method createOrUpdateOrcidClientGroup.
@Override
@Transactional
public OrcidClient createOrUpdateOrcidClientGroup(String groupOrcid, OrcidClient orcidClient) {
OrcidClient result = null;
// Use the profile DAO to link the clients to the group, so get the
// group profile entity.
ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
SortedSet<ClientDetailsEntity> clientDetailsEntities = groupProfileEntity.getClients();
if (clientDetailsEntities == null) {
clientDetailsEntities = new TreeSet<>(new OrcidEntityIdComparator<String>());
groupProfileEntity.setClients(clientDetailsEntities);
}
processClient(groupOrcid, clientDetailsEntities, orcidClient, getClientType(groupProfileEntity.getGroupType()));
OrcidClientGroup group = retrieveOrcidClientGroup(groupOrcid);
for (OrcidClient populatedClient : group.getOrcidClient()) {
if (compareClients(orcidClient, populatedClient))
result = populatedClient;
}
// Regenerate client group and return.
return result;
}
Aggregations