use of org.apache.commons.lang3.StringUtils.isNotEmpty in project halyard by spinnaker.
the class KubernetesV2Service method getResourceYaml.
default String getResourceYaml(AccountDeploymentDetails<KubernetesAccount> details, GenerateService.ResolvedConfiguration resolvedConfiguration) {
ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
String namespace = getNamespace(settings);
List<ConfigSource> configSources = stageConfig(details, resolvedConfiguration);
Map<String, String> env = configSources.stream().map(ConfigSource::getEnv).map(Map::entrySet).flatMap(Collection::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
env.putAll(settings.getEnv());
List<String> volumes = configSources.stream().map(c -> {
TemplatedResource volume = new JinjaJarResource("/kubernetes/manifests/volume.yml");
volume.addBinding("name", c.getId());
return volume.toString();
}).collect(Collectors.toList());
List<String> volumeMounts = configSources.stream().map(c -> {
TemplatedResource volume = new JinjaJarResource("/kubernetes/manifests/volumeMount.yml");
volume.addBinding("name", c.getId());
volume.addBinding("mountPath", c.getMountPath());
return volume.toString();
}).collect(Collectors.toList());
TemplatedResource probe;
if (StringUtils.isNotEmpty(settings.getHealthEndpoint())) {
probe = new JinjaJarResource("/kubernetes/manifests/execReadinessProbe.yml");
probe.addBinding("command", getReadinessExecCommand(settings));
} else {
probe = new JinjaJarResource("/kubernetes/manifests/tcpSocketReadinessProbe.yml");
probe.addBinding("port", settings.getPort());
}
TemplatedResource container = new JinjaJarResource("/kubernetes/manifests/container.yml");
container.addBinding("name", getService().getCanonicalName());
container.addBinding("imageId", settings.getArtifactId());
container.addBinding("port", settings.getPort());
container.addBinding("volumeMounts", volumeMounts);
container.addBinding("probe", probe.toString());
container.addBinding("env", env);
List<String> containers = Collections.singletonList(container.toString());
TemplatedResource podSpec = new JinjaJarResource("/kubernetes/manifests/podSpec.yml").addBinding("containers", containers).addBinding("volumes", volumes);
return new JinjaJarResource("/kubernetes/manifests/deployment.yml").addBinding("name", getService().getCanonicalName()).addBinding("namespace", namespace).addBinding("replicas", settings.getTargetSize()).addBinding("podAnnotations", settings.getKubernetes().getPodAnnotations()).addBinding("podSpec", podSpec.toString()).toString();
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project Asqatasun by Asqatasun.
the class Rgaa30Rule110103 method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
/* If the page has no input form element, the test is not applicable */
if (inputFormMap.entrySet().isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) {
/* The attribute Emptiness Checker. Keep default value i.e failed
when attribute is empty
*/
ElementChecker attributeEmptinessChecker = new TextEmptinessChecker(new TextAttributeOfElementBuilder(ARIA_LABELLEDBY_ATTR), ARIA_LABELLEDBY_EMPTY_MSG, null);
attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
ElementHandler<Element> inputWithoutLabel = new ElementHandlerImpl();
ElementHandler<Element> notUniqueLabel = new ElementHandlerImpl();
for (Element el : entry.getValue().get()) {
if (StringUtils.isNotEmpty(el.attr(ARIA_LABELLEDBY_ATTR))) {
ElementHandler<Element> labelHandler = new ElementHandlerImpl();
labelHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromAttributeTypeAndValue(ID_ATTR, el.attr(ARIA_LABELLEDBY_ATTR))));
if (labelHandler.get().isEmpty()) {
inputWithoutLabel.add(el);
} else if (labelHandler.get().size() > 1) {
notUniqueLabel.add(el);
notUniqueLabel.addAll(labelHandler.get());
}
}
}
/* Check if the form element has a label associated */
ElementChecker elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, FORM_ELEMENT_WITHOUT_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, inputWithoutLabel, testSolutionHandler);
/* Check if the id attr of the label associated to the form element is unique */
elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, FORM_ELEMENT_WITH_NOT_UNIQUE_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, notUniqueLabel, testSolutionHandler);
}
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class Utils method getWrappedImageResourceWithInheritance.
/**
* Wraps an image resource with the properties and child resources of the inherited featured image of either
* the linked page or the page containing the resource.
*
* @param resource The image resource
* @param linkHandler The link handler
* @param currentStyle The style of the image resource
* @param currentPage The page containing the image resource
* @return The wrapped image resource augmented with inherited properties and child resource if inheritance is enabled, the plain image resource otherwise.
*/
public static Resource getWrappedImageResourceWithInheritance(Resource resource, LinkHandler linkHandler, Style currentStyle, Page currentPage) {
if (resource == null) {
LOGGER.error("The resource is not defined");
return null;
}
if (linkHandler == null) {
LOGGER.error("The link handler is not defined");
return null;
}
ValueMap properties = resource.getValueMap();
String fileReference = properties.get(DownloadResource.PN_REFERENCE, String.class);
Resource fileResource = resource.getChild(DownloadResource.NN_FILE);
boolean imageFromPageImage = properties.get(PN_IMAGE_FROM_PAGE_IMAGE, StringUtils.isEmpty(fileReference) && fileResource == null);
boolean altValueFromPageImage = properties.get(PN_ALT_VALUE_FROM_PAGE_IMAGE, imageFromPageImage);
if (imageFromPageImage) {
Resource inheritedResource = null;
String linkURL = properties.get(ImageResource.PN_LINK_URL, String.class);
boolean actionsEnabled = (currentStyle != null) ? !currentStyle.get(Teaser.PN_ACTIONS_DISABLED, !properties.get(Teaser.PN_ACTIONS_ENABLED, true)) : properties.get(Teaser.PN_ACTIONS_ENABLED, true);
Resource firstAction = Optional.of(resource).map(res -> res.getChild(Teaser.NN_ACTIONS)).map(actions -> actions.getChildren().iterator().next()).orElse(null);
if (StringUtils.isNotEmpty(linkURL)) {
// the inherited resource is the featured image of the linked page
Optional<Link> link = linkHandler.getLink(resource);
inheritedResource = link.map(link1 -> (Page) link1.getReference()).map(ComponentUtils::getFeaturedImage).orElse(null);
} else if (actionsEnabled && firstAction != null) {
// the inherited resource is the featured image of the first action's page (the resource is assumed to be a teaser)
inheritedResource = Optional.of(linkHandler.getLink(firstAction, Teaser.PN_ACTION_LINK)).map(link1 -> {
if (link1.isPresent()) {
Page linkedPage = (Page) link1.get().getReference();
return Optional.ofNullable(linkedPage).map(ComponentUtils::getFeaturedImage).orElse(null);
}
return null;
}).orElse(null);
} else {
// the inherited resource is the featured image of the current page
inheritedResource = Optional.ofNullable(currentPage).map(page -> {
Template template = page.getTemplate();
// make sure the resource is part of the currentPage or of its template
if (StringUtils.startsWith(resource.getPath(), currentPage.getPath()) || (template != null && StringUtils.startsWith(resource.getPath(), template.getPath()))) {
return ComponentUtils.getFeaturedImage(currentPage);
}
return null;
}).orElse(null);
}
Map<String, String> overriddenProperties = new HashMap<>();
Map<String, Resource> overriddenChildren = new HashMap<>();
String inheritedFileReference = null;
Resource inheritedFileResource = null;
String inheritedAlt = null;
String inheritedAltValueFromDAM = null;
if (inheritedResource != null) {
// Define the inherited properties
ValueMap inheritedProperties = inheritedResource.getValueMap();
inheritedFileReference = inheritedProperties.get(DownloadResource.PN_REFERENCE, String.class);
inheritedFileResource = inheritedResource.getChild(DownloadResource.NN_FILE);
inheritedAlt = inheritedProperties.get(ImageResource.PN_ALT, String.class);
inheritedAltValueFromDAM = inheritedProperties.get(PN_ALT_VALUE_FROM_DAM, String.class);
}
overriddenProperties.put(DownloadResource.PN_REFERENCE, inheritedFileReference);
overriddenChildren.put(DownloadResource.NN_FILE, inheritedFileResource);
// don't inherit the image title from the page image
overriddenProperties.put(PN_TITLE_VALUE_FROM_DAM, "false");
if (altValueFromPageImage) {
overriddenProperties.put(ImageResource.PN_ALT, inheritedAlt);
overriddenProperties.put(PN_ALT_VALUE_FROM_DAM, inheritedAltValueFromDAM);
} else {
overriddenProperties.put(PN_ALT_VALUE_FROM_DAM, "false");
}
return new CoreResourceWrapper(resource, resource.getResourceType(), null, overriddenProperties, overriddenChildren);
}
return resource;
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LinkHandler method resolvePage.
/**
* Attempts to resolve a Link URL and page for the given page. Redirect chains are followed, if
* shadowing is not disabled.
*
* @param page Page
* @return A pair of {@link String} and {@link Page} the page resolves to.
*/
@NotNull
private Pair<Page, String> resolvePage(@Nullable final Page page) {
Page resolved = page;
String redirectTarget = null;
String linkURL = null;
if (!isShadowingDisabled()) {
Pair<Page, String> pair = resolveRedirects(page);
resolved = pair.getLeft();
redirectTarget = pair.getRight();
}
if (resolved == null) {
if (StringUtils.isNotEmpty(redirectTarget)) {
return new ImmutablePair<>(page, redirectTarget);
} else {
resolved = page;
}
}
if (resolved != null) {
linkURL = getPageLinkURL(resolved);
}
return new ImmutablePair<>(resolved, linkURL);
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServlet method doGet.
@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws IOException {
Timer.Context requestDuration = metrics.startDurationRecording();
try {
metrics.markServletInvocation();
RequestPathInfo requestPathInfo = request.getRequestPathInfo();
List<String> selectorList = selectorToList(requestPathInfo.getSelectorString());
String suffix = requestPathInfo.getSuffix();
String imageName = StringUtils.isNotEmpty(suffix) ? FilenameUtils.getName(suffix) : "";
if (StringUtils.isNotEmpty(suffix)) {
String suffixExtension = FilenameUtils.getExtension(suffix);
if (StringUtils.isNotEmpty(suffixExtension)) {
if (!suffixExtension.equals(requestPathInfo.getExtension())) {
LOGGER.error("The suffix part defines a different extension than the request: {}.", suffix);
metrics.markImageErrors();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
} else {
LOGGER.error("Invalid suffix: {}.", suffix);
metrics.markImageErrors();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
Resource component = request.getResource();
ResourceResolver resourceResolver = request.getResourceResolver();
if (!component.isResourceType(IMAGE_RESOURCE_TYPE)) {
// image coming from template; need to switch resource
Resource componentCandidate = null;
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
if (pageManager != null) {
Page page = pageManager.getContainingPage(component);
if (page != null) {
Template template = page.getTemplate();
if (template != null) {
if (StringUtils.isNotEmpty(suffix)) {
long lastModifiedSuffix = getRequestLastModifiedSuffix(suffix);
String relativeTemplatePath = lastModifiedSuffix == 0 ? // no timestamp info, but extension is valid; get resource name
suffix.substring(0, suffix.lastIndexOf('.')) : // timestamp info, get parent path from suffix
suffix.substring(0, suffix.lastIndexOf("/" + String.valueOf(lastModifiedSuffix)));
String imagePath = ResourceUtil.normalize(template.getPath() + relativeTemplatePath);
if (StringUtils.isNotEmpty(imagePath) && !template.getPath().equals(imagePath)) {
componentCandidate = resourceResolver.getResource(imagePath);
}
}
}
}
}
if (componentCandidate == null) {
LOGGER.error("Unable to retrieve an image from this page's template.");
metrics.markImageErrors();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
component = componentCandidate;
}
LinkHandler linkHandler = request.adaptTo(LinkHandler.class);
Style currentStyle = WCMUtils.getStyle(request);
Page currentPage = Optional.ofNullable(resourceResolver.adaptTo(PageManager.class)).map(pageManager -> pageManager.getContainingPage(request.getResource())).orElse(null);
Resource wrappedImageResourceWithInheritance = getWrappedImageResourceWithInheritance(component, linkHandler, currentStyle, currentPage);
ImageComponent imageComponent = new ImageComponent(wrappedImageResourceWithInheritance);
if (imageComponent.source == Source.NOCONTENT || imageComponent.source == Source.NONEXISTING) {
LOGGER.error("Either the image from {} does not have a valid file reference" + " or the containing page does not have a valid featured image", component.getPath());
metrics.markImageErrors();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
ValueMap componentProperties = component.getValueMap();
long lastModifiedEpoch = 0;
Calendar lastModifiedDate = componentProperties.get(JcrConstants.JCR_LASTMODIFIED, Calendar.class);
if (lastModifiedDate == null) {
lastModifiedDate = componentProperties.get(NameConstants.PN_PAGE_LAST_MOD, Calendar.class);
}
if (lastModifiedDate != null) {
lastModifiedEpoch = lastModifiedDate.getTimeInMillis();
}
Asset asset = null;
if (imageComponent.source == Source.ASSET) {
asset = imageComponent.imageResource.adaptTo(Asset.class);
if (asset == null) {
LOGGER.error("Unable to adapt resource {} used by image {} to an asset.", imageComponent.imageResource.getPath(), component.getPath());
metrics.markImageErrors();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
long assetLastModifiedEpoch = asset.getLastModified();
if (assetLastModifiedEpoch > lastModifiedEpoch) {
lastModifiedEpoch = assetLastModifiedEpoch;
}
}
long requestLastModifiedSuffix = getRequestLastModifiedSuffix(suffix);
if (requestLastModifiedSuffix >= 0 && requestLastModifiedSuffix != lastModifiedEpoch) {
String redirectLocation = getRedirectLocation(request, lastModifiedEpoch);
if (StringUtils.isNotEmpty(redirectLocation)) {
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location", redirectLocation);
return;
} else {
LOGGER.error("Unable to determine correct redirect location.");
metrics.markImageErrors();
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
if (!handleIfModifiedSinceHeader(request, response, lastModifiedEpoch)) {
Map<String, Integer> transformationMap = getTransformationMap(selectorList, component);
Integer jpegQualityInPercentage = transformationMap.get(SELECTOR_QUALITY_KEY);
double quality = jpegQualityInPercentage / 100.0d;
int resizeWidth = transformationMap.get(SELECTOR_WIDTH_KEY);
String imageType = getImageType(requestPathInfo.getExtension());
if (imageComponent.source == Source.FILE) {
transformAndStreamFile(response, componentProperties, resizeWidth, quality, imageComponent.imageResource, imageType, imageName);
} else if (imageComponent.source == Source.ASSET) {
transformAndStreamAsset(response, componentProperties, resizeWidth, quality, asset, imageType, imageName);
}
metrics.markImageStreamed();
}
} catch (IllegalArgumentException e) {
LOGGER.error("Invalid image request", e.getMessage());
metrics.markImageErrors();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} finally {
requestDuration.stop();
}
}
Aggregations