Search in sources :

Example 1 with OrcidEntityIdComparator

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);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidEntityIdComparator(org.orcid.persistence.jpa.entities.OrcidEntityIdComparator) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with OrcidEntityIdComparator

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);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidEntityIdComparator(org.orcid.persistence.jpa.entities.OrcidEntityIdComparator) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 3 with OrcidEntityIdComparator

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;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidEntityIdComparator(org.orcid.persistence.jpa.entities.OrcidEntityIdComparator) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 OrcidEntityIdComparator (org.orcid.persistence.jpa.entities.OrcidEntityIdComparator)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)2 Transactional (org.springframework.transaction.annotation.Transactional)2 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)1 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)1