Search in sources :

Example 1 with Content

use of org.candlepin.model.dto.Content in project candlepin by candlepin.

the class X509V3ExtensionUtil method makePathTree.

public PathNode makePathTree(List<Content> contents, PathNode parent) {
    PathNode endMarker = new PathNode();
    for (Content c : contents) {
        String path = c.getPath();
        if (treeDebug) {
            log.debug(path);
        }
        StringTokenizer st = new StringTokenizer(path, "/");
        makePathForURL(st, parent, endMarker);
    }
    if (treeDebug) {
        printTree(parent, 0);
    }
    condenseSubTreeNodes(endMarker);
    if (treeDebug) {
        printTree(parent, 0);
    }
    return parent;
}
Also used : StringTokenizer(java.util.StringTokenizer) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.dto.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent)

Example 2 with Content

use of org.candlepin.model.dto.Content in project candlepin by candlepin.

the class X509V3ExtensionUtil method retrieveContentValue.

private byte[] retrieveContentValue(EntitlementBody eb) throws IOException {
    List<Content> contentList = getContentList(eb);
    PathNode treeRoot = makePathTree(contentList, new PathNode());
    List<String> nodeStrings = orderStrings(treeRoot);
    if (nodeStrings.size() == 0) {
        return new byte[0];
    }
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    List<HuffNode> stringHuffNodes = getStringNodeList(nodeStrings);
    HuffNode stringTrieParent = makeTrie(stringHuffNodes);
    data.write(byteProcess(nodeStrings));
    List<PathNode> orderedNodes = orderNodes(treeRoot);
    List<HuffNode> pathNodeHuffNodes = getPathNodeNodeList(orderedNodes);
    HuffNode pathNodeTrieParent = makeTrie(pathNodeHuffNodes);
    data.write(makeNodeDictionary(stringTrieParent, pathNodeTrieParent, orderedNodes));
    return data.toByteArray();
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.dto.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with Content

use of org.candlepin.model.dto.Content in project candlepin by candlepin.

the class X509V3ExtensionUtil method createContent.

/*
     * createContent
     *
     * productArchList is a list of arch strings parse from
     *   product attributes.
     */
public List<Content> createContent(Set<ProductContent> productContent, Product sku, String contentPrefix, Map<String, EnvironmentContent> promotedContent, Consumer consumer, Product product) {
    List<Content> toReturn = new ArrayList<>();
    boolean enableEnvironmentFiltering = config.getBoolean(ConfigProperties.ENV_CONTENT_FILTERING);
    // Return only the contents that are arch appropriate
    Set<ProductContent> archApproriateProductContent = filterContentByContentArch(productContent, consumer, product);
    List<String> skuDisabled = sku.getSkuDisabledContentIds();
    List<String> skuEnabled = sku.getSkuEnabledContentIds();
    for (ProductContent pc : archApproriateProductContent) {
        Content content = new Content();
        if (enableEnvironmentFiltering && consumer.getEnvironmentId() != null && !promotedContent.containsKey(pc.getContent().getId())) {
            log.debug("Skipping content not promoted to environment: {}", pc.getContent());
            continue;
        }
        // Augment the content path with the prefix if it is passed in
        String contentPath = this.createFullContentPath(contentPrefix, pc);
        content.setId(pc.getContent().getId());
        content.setType(pc.getContent().getType());
        content.setName(pc.getContent().getName());
        content.setLabel(pc.getContent().getLabel());
        content.setVendor(pc.getContent().getVendor());
        content.setPath(contentPath);
        content.setGpgUrl(pc.getContent().getGpgUrl());
        // Set content model's arches here, inheriting from the product if
        // they are not set on the content.
        List<String> archesList = new ArrayList<>();
        Set<String> contentArches = Arch.parseArches(pc.getContent().getArches());
        if (contentArches.isEmpty()) {
            archesList.addAll(Arch.parseArches(product.getAttributeValue(Product.Attributes.ARCHITECTURE)));
        } else {
            archesList.addAll(Arch.parseArches(pc.getContent().getArches()));
        }
        content.setArches(archesList);
        Boolean enabled = pc.isEnabled();
        // sku level content enable override. if on both lists, active wins.
        if (skuDisabled.contains(pc.getContent().getId())) {
            enabled = false;
        }
        if (skuEnabled.contains(pc.getContent().getId())) {
            enabled = true;
        }
        // Check if we should override the enabled flag due to setting on promoted content
        if (enableEnvironmentFiltering && consumer.getEnvironmentId() != null) {
            // we know content has been promoted at this point
            Boolean enabledOverride = promotedContent.get(pc.getContent().getId()).getEnabled();
            if (enabledOverride != null) {
                log.debug("overriding enabled flag: {}", enabledOverride);
                enabled = enabledOverride;
            }
        }
        // only included if not the default value of true
        if (!enabled) {
            content.setEnabled(enabled);
        }
        // Include metadata expiry if specified on the content
        if (pc.getContent().getMetadataExpire() != null) {
            content.setMetadataExpire(pc.getContent().getMetadataExpire());
        }
        // Include required tags if specified on the content set
        String requiredTags = pc.getContent().getRequiredTags();
        if ((requiredTags != null) && !requiredTags.equals("")) {
            StringTokenizer st = new StringTokenizer(requiredTags, ",");
            List<String> tagList = new ArrayList<>();
            while (st.hasMoreElements()) {
                tagList.add((String) st.nextElement());
            }
            content.setRequiredTags(tagList);
        }
        toReturn.add(content);
    }
    return toReturn;
}
Also used : StringTokenizer(java.util.StringTokenizer) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.dto.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) ArrayList(java.util.ArrayList) ProductContent(org.candlepin.model.ProductContent)

Aggregations

EnvironmentContent (org.candlepin.model.EnvironmentContent)3 ProductContent (org.candlepin.model.ProductContent)3 Content (org.candlepin.model.dto.Content)3 StringTokenizer (java.util.StringTokenizer)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1