Search in sources :

Example 1 with DistributorVersionCapability

use of org.candlepin.model.DistributorVersionCapability in project candlepin by candlepin.

the class ImporterTest method createTestDistributerVersion.

private DistributorVersion createTestDistributerVersion() {
    DistributorVersion dVersion = new DistributorVersion("test-dist-ver");
    Set<DistributorVersionCapability> capabilities = new HashSet<>();
    capabilities.add(new DistributorVersionCapability(null, "capability-1"));
    capabilities.add(new DistributorVersionCapability(null, "capability-2"));
    capabilities.add(new DistributorVersionCapability(null, "capability-3"));
    dVersion.setCapabilities(capabilities);
    return dVersion;
}
Also used : DistributorVersionCapability(org.candlepin.model.DistributorVersionCapability) DistributorVersion(org.candlepin.model.DistributorVersion) HashSet(java.util.HashSet)

Example 2 with DistributorVersionCapability

use of org.candlepin.model.DistributorVersionCapability in project candlepin by candlepin.

the class ExporterTest method exportDistributorVersions.

@Test
public void exportDistributorVersions() throws ExportCreationException, IOException {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
    config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
    Rules mrules = mock(Rules.class);
    Consumer consumer = mock(Consumer.class);
    Principal principal = mock(Principal.class);
    when(mrules.getRules()).thenReturn("foobar");
    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(rc.getRules()).thenReturn(mrules);
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");
    IdentityCertificate idcert = new IdentityCertificate();
    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
    ctype.setId("test-ctype");
    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
    when(consumer.getUuid()).thenReturn("8auuid");
    when(consumer.getName()).thenReturn("consumer_name");
    when(consumer.getTypeId()).thenReturn(ctype.getId());
    when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
    DistributorVersion dv = new DistributorVersion("test-dist-ver");
    Set<DistributorVersionCapability> dvcSet = new HashSet<>();
    dvcSet.add(new DistributorVersionCapability(dv, "capability-1"));
    dvcSet.add(new DistributorVersionCapability(dv, "capability-2"));
    dvcSet.add(new DistributorVersionCapability(dv, "capability-3"));
    dv.setCapabilities(dvcSet);
    List<DistributorVersion> dvList = new ArrayList<>();
    dvList.add(dv);
    when(dvc.findAll()).thenReturn(dvList);
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
    when(ctc.listAll()).thenReturn(cqmock);
    CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
    when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
    when(emptyIteratorMock.iterator()).thenReturn(Arrays.asList().iterator());
    when(cdnc.listAll()).thenReturn(emptyIteratorMock);
    when(ctc.listAll()).thenReturn(emptyIteratorMock);
    // FINALLY test this badboy
    Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
    File export = e.getFullExport(consumer);
    verifyContent(export, "export/distributor_version/test-dist-ver.json", new VerifyDistributorVersion("test-dist-ver.json"));
}
Also used : KeyPair(org.candlepin.model.KeyPair) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CertificateSerial(org.candlepin.model.CertificateSerial) CandlepinQuery(org.candlepin.model.CandlepinQuery) Rules(org.candlepin.model.Rules) ExportRules(org.candlepin.policy.js.export.ExportRules) Date(java.util.Date) Consumer(org.candlepin.model.Consumer) DistributorVersionCapability(org.candlepin.model.DistributorVersionCapability) ConsumerType(org.candlepin.model.ConsumerType) File(java.io.File) Principal(org.candlepin.auth.Principal) IdentityCertificate(org.candlepin.model.IdentityCertificate) DistributorVersion(org.candlepin.model.DistributorVersion) HashSet(java.util.HashSet) MockResultIterator(org.candlepin.test.MockResultIterator) Test(org.junit.Test)

Example 3 with DistributorVersionCapability

use of org.candlepin.model.DistributorVersionCapability 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 4 with DistributorVersionCapability

use of org.candlepin.model.DistributorVersionCapability 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)

Aggregations

DistributorVersion (org.candlepin.model.DistributorVersion)4 DistributorVersionCapability (org.candlepin.model.DistributorVersionCapability)4 HashSet (java.util.HashSet)3 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)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 Principal (org.candlepin.auth.Principal)1 CandlepinQuery (org.candlepin.model.CandlepinQuery)1 CertificateSerial (org.candlepin.model.CertificateSerial)1 Consumer (org.candlepin.model.Consumer)1 ConsumerCapability (org.candlepin.model.ConsumerCapability)1 ConsumerType (org.candlepin.model.ConsumerType)1 IdentityCertificate (org.candlepin.model.IdentityCertificate)1 KeyPair (org.candlepin.model.KeyPair)1 Rules (org.candlepin.model.Rules)1