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