Search in sources :

Example 6 with DistributorVersion

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;
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) DistributorVersionCapability(org.candlepin.model.DistributorVersionCapability) ConsumerCapability(org.candlepin.model.ConsumerCapability) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) DistributorVersion(org.candlepin.model.DistributorVersion)

Example 7 with DistributorVersion

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;
}
Also used : DistributorVersion(org.candlepin.model.DistributorVersion) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 8 with DistributorVersion

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;
}
Also used : DistributorVersionCapability(org.candlepin.model.DistributorVersionCapability) DistributorVersion(org.candlepin.model.DistributorVersion)

Example 9 with 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());
        }
    }
}
Also used : DistributorVersion(org.candlepin.model.DistributorVersion)

Aggregations

DistributorVersion (org.candlepin.model.DistributorVersion)9 File (java.io.File)4 HashSet (java.util.HashSet)4 DistributorVersionCapability (org.candlepin.model.DistributorVersionCapability)4 Test (org.junit.Test)2 ApiOperation (io.swagger.annotations.ApiOperation)1 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 ZipInputStream (java.util.zip.ZipInputStream)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1