use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class ConsumerResource method updateCapabilities.
/**
* @param existing
* @param update
* @return a String object
*/
private boolean updateCapabilities(Consumer existing, ConsumerDTO update) {
boolean change = false;
if (update == null) {
// create
if ((existing.getCapabilities() == null || existing.getCapabilities().isEmpty()) && existing.getFact("distributor_version") != null) {
Set<DistributorVersionCapability> capabilities = distributorVersionCurator.findCapabilitiesByDistVersion(existing.getFact("distributor_version"));
if (capabilities != null) {
Set<ConsumerCapability> ccaps = new HashSet<>();
for (DistributorVersionCapability dvc : capabilities) {
ConsumerCapability cc = new ConsumerCapability(existing, dvc.getName());
ccaps.add(cc);
}
existing.setCapabilities(ccaps);
}
change = true;
}
} else {
// update
if (update.getCapabilities() != null) {
Set<ConsumerCapability> entityCapabilities = populateCapabilities(existing, update);
if (!entityCapabilities.equals(existing.getCapabilities())) {
existing.setCapabilities(entityCapabilities);
change = true;
}
} else if (update.getFact("distributor_version") != null) {
DistributorVersion dv = distributorVersionCurator.findByName(update.getFact("distributor_version"));
if (dv != null) {
Set<ConsumerCapability> ccaps = new HashSet<>();
for (DistributorVersionCapability dvc : dv.getCapabilities()) {
ConsumerCapability cc = new ConsumerCapability(existing, dvc.getName());
ccaps.add(cc);
}
existing.setCapabilities(ccaps);
}
change = true;
}
}
if (change) {
log.debug("Capabilities changed.");
} else {
log.debug("Capability list either null or does not contain changes.");
}
return change;
}
use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class DistributorVersionResource method update.
@ApiOperation(notes = "Updates a Distributor Version", value = "update")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}")
public DistributorVersion update(@PathParam("id") String id, @ApiParam(name = "distributorVersion", required = true) DistributorVersion dv, @Context Principal principal) {
DistributorVersion existing = verifyAndLookupDistributorVersion(id);
existing.setDisplayName(dv.getDisplayName());
existing.setCapabilities(dv.getCapabilities());
curator.merge(existing);
return existing;
}
use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class DistributorVersionImporter method createObject.
public DistributorVersion createObject(ObjectMapper mapper, Reader reader) throws IOException {
DistributorVersion distributorVersion = mapper.readValue(reader, DistributorVersion.class);
distributorVersion.setId(null);
for (DistributorVersionCapability dvc : distributorVersion.getCapabilities()) {
dvc.setId(null);
}
return distributorVersion;
}
use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class DistributorVersionImporter method store.
/**
* @param distVers Set of Distributor Versions.
*/
public void store(Set<DistributorVersion> distVers) {
log.debug("Creating/updating distributor versions");
for (DistributorVersion distVer : distVers) {
DistributorVersion existing = curator.findByName(distVer.getName());
if (existing == null) {
curator.create(distVer);
log.debug("Created distributor version: " + distVer.getName());
} else {
existing.setCapabilities(distVer.getCapabilities());
existing.setDisplayName(distVer.getDisplayName());
curator.merge(existing);
log.debug("Updating distributor version: " + distVer.getName());
}
}
}
Aggregations