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;
}
Aggregations