Search in sources :

Example 1 with HypervisorIdDTO

use of org.candlepin.dto.api.v1.HypervisorIdDTO in project candlepin by candlepin.

the class ConsumerResource method checkForHypervisorIdUpdate.

private boolean checkForHypervisorIdUpdate(Consumer existing, ConsumerDTO incoming) {
    HypervisorIdDTO incomingId = incoming.getHypervisorId();
    if (incomingId != null) {
        HypervisorId existingId = existing.getHypervisorId();
        if (incomingId.getHypervisorId() == null || incomingId.getHypervisorId().isEmpty()) {
            // Allow hypervisorId to be removed
            existing.setHypervisorId(null);
        } else {
            if (existingId != null) {
                if (existingId.getHypervisorId() != null && !existingId.getHypervisorId().equals(incomingId.getHypervisorId())) {
                    existingId.setHypervisorId(incomingId.getHypervisorId());
                    Owner owner = ownerCurator.findOwnerById(existing.getOwnerId());
                    existingId.setOwner(owner);
                } else {
                    return false;
                }
            } else {
                // Safer to build a new clean HypervisorId object
                Owner owner = ownerCurator.findOwnerById(existing.getOwnerId());
                HypervisorId hypervisorId = new HypervisorId(incomingId.getHypervisorId());
                hypervisorId.setOwner(owner);
                existing.setHypervisorId(hypervisorId);
            }
        }
        return true;
    }
    return false;
}
Also used : HypervisorIdDTO(org.candlepin.dto.api.v1.HypervisorIdDTO) Owner(org.candlepin.model.Owner) HypervisorId(org.candlepin.model.HypervisorId)

Aggregations

HypervisorIdDTO (org.candlepin.dto.api.v1.HypervisorIdDTO)1 HypervisorId (org.candlepin.model.HypervisorId)1 Owner (org.candlepin.model.Owner)1