use of org.apache.commons.lang3.StringUtils.isNotEmpty in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ExperienceFragmentDataImpl method getLocalizedFragmentVariationPath.
/**
* Returns the localized path of the experience fragment variation if the experience fragment resource is defined
* in a template.
*
* @return Localized experience fragment variation path
* @see ExperienceFragment#getLocalizedFragmentVariationPath()
*/
@Nullable
public String getLocalizedFragmentVariationPath() {
if (localizedFragmentVariationPath != null) {
return localizedFragmentVariationPath;
}
// get the configured fragment variation path
String fragmentVariationPath = resource.getValueMap().get(ExperienceFragment.PN_FRAGMENT_VARIATION_PATH, String.class);
if (currentPage != null && inTemplate()) {
final Resource pageResource = Optional.ofNullable(currentPage).map(p -> p.adaptTo(Resource.class)).orElse(null);
final String currentPageRootPath = pageResource != null ? LocalizationUtils.getLocalizationRoot(pageResource, resourceResolver, languageManager, relationshipManager) : null;
// we should use getLocalizationRoot instead of getXfLocalizationRoot once the XF UI supports creating Live and Language Copies
String xfRootPath = getXfLocalizationRoot(fragmentVariationPath, currentPageRootPath);
if (StringUtils.isNotEmpty(currentPageRootPath) && StringUtils.isNotEmpty(xfRootPath)) {
String xfRelativePath = StringUtils.substring(fragmentVariationPath, xfRootPath.length());
String localizedXfRootPath = StringUtils.replace(currentPageRootPath, CONTENT_ROOT, ExperienceFragmentsConstants.CONTENT_PATH, 1);
localizedFragmentVariationPath = StringUtils.join(localizedXfRootPath, xfRelativePath, PATH_DELIMITER_CHAR, NN_CONTENT);
}
}
String xfContentPath = String.join(Character.toString(PATH_DELIMITER_CHAR), fragmentVariationPath, NN_CONTENT);
if (!resourceExists(localizedFragmentVariationPath) && resourceExists(xfContentPath)) {
localizedFragmentVariationPath = xfContentPath;
}
if (!isExperienceFragmentVariation(localizedFragmentVariationPath)) {
localizedFragmentVariationPath = null;
}
return localizedFragmentVariationPath;
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LinkHandler method resolveRedirects.
/**
* Attempts to resolve the redirect chain starting from the given page, avoiding loops.
*
* @param page The starting {@link Page}
* @return A pair of {@link Page} and {@link String} the redirect chain resolves to. The page can be the original page, if no redirect
* target is defined or even {@code null} if the redirect chain does not resolve to a valid page, in this case one should use the right
* part of the pair (the {@link String} redirect target).
*/
@NotNull
public Pair<Page, String> resolveRedirects(@Nullable final Page page) {
Page result = page;
String redirectTarget = null;
if (page != null && page.getPageManager() != null) {
Set<String> redirectCandidates = new LinkedHashSet<>();
redirectCandidates.add(page.getPath());
while (result != null && StringUtils.isNotEmpty((redirectTarget = result.getProperties().get(PageImpl.PN_REDIRECT_TARGET, String.class)))) {
result = page.getPageManager().getPage(redirectTarget);
if (result != null) {
if (!redirectCandidates.add(result.getPath())) {
LOGGER.warn("Detected redirect loop for the following pages: {}.", redirectCandidates);
break;
}
}
}
}
return new ImmutablePair<>(result, redirectTarget);
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project cloudstack by apache.
the class QueryManagerImpl method listDetailOptions.
@Override
public DetailOptionsResponse listDetailOptions(final ListDetailOptionsCmd cmd) {
final ResourceObjectType type = cmd.getResourceType();
final String resourceUuid = cmd.getResourceId();
final Map<String, List<String>> options = new HashMap<>();
switch(type) {
case Template:
case UserVm:
HypervisorType hypervisorType = HypervisorType.None;
if (StringUtils.isNotEmpty(resourceUuid) && ResourceObjectType.Template.equals(type)) {
hypervisorType = _templateDao.findByUuid(resourceUuid).getHypervisorType();
}
if (StringUtils.isNotEmpty(resourceUuid) && ResourceObjectType.UserVm.equals(type)) {
hypervisorType = _vmInstanceDao.findByUuid(resourceUuid).getHypervisorType();
}
fillVMOrTemplateDetailOptions(options, hypervisorType);
break;
default:
throw new CloudRuntimeException("Resource type not supported.");
}
if (CallContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN) {
final List<String> userDenyListedSettings = Stream.of(QueryService.UserVMDeniedDetails.value().split(",")).map(item -> (item).trim()).collect(Collectors.toList());
for (final String detail : userDenyListedSettings) {
if (options.containsKey(detail)) {
options.remove(detail);
}
}
}
return new DetailOptionsResponse(options);
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method checkAttributes.
private void checkAttributes(TrackedEntityInstance dtoEntityInstance, ImportOptions importOptions, ImportConflicts importConflicts, boolean teiExistsInDatabase) {
if (dtoEntityInstance.getAttributes().isEmpty()) {
return;
}
List<String> fileValues = new ArrayList<>();
org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance = null;
if (teiExistsInDatabase) {
daoEntityInstance = teiService.getTrackedEntityInstance(dtoEntityInstance.getTrackedEntityInstance(), importOptions.getUser());
if (daoEntityInstance == null) {
return;
}
daoEntityInstance.getTrackedEntityAttributeValues().stream().filter(attrVal -> attrVal.getAttribute().getValueType().isFile()).forEach(attrVal -> fileValues.add(attrVal.getValue()));
}
for (Attribute attribute : dtoEntityInstance.getAttributes()) {
if (StringUtils.isNotEmpty(attribute.getValue())) {
// Cache was populated in prepareCaches, so I should hit the
// cache
TrackedEntityAttribute daoEntityAttribute = getTrackedEntityAttribute(importOptions.getIdSchemes(), attribute.getAttribute());
if (daoEntityAttribute == null) {
importConflicts.addConflict("Attribute.attribute", "Invalid attribute " + attribute.getAttribute());
continue;
}
if (attribute.getValue() != null && attribute.getValue().length() > TEA_VALUE_MAX_LENGTH) {
// We shorten the value to first 25 characters, since we
// dont want to post a 1200+ string back.
importConflicts.addConflict("Attribute.value", String.format("Value exceeds the character limit of %s characters: '%s...'", TEA_VALUE_MAX_LENGTH, attribute.getValue().substring(0, 25)));
}
if (daoEntityAttribute.isUnique()) {
// Cache was populated in prepareCaches, so I should hit the
// cache
OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), dtoEntityInstance.getOrgUnit());
checkAttributeUniquenessWithinScope(daoEntityInstance, daoEntityAttribute, attribute.getValue(), organisationUnit, importConflicts);
}
validateAttributeType(attribute, importOptions, importConflicts);
if (daoEntityAttribute.getValueType().isFile() && checkAssigned(attribute, fileValues)) {
importConflicts.addConflict("Attribute.value", String.format("File resource with uid '%s' has already been assigned to a different object", attribute.getValue()));
}
}
}
}
use of org.apache.commons.lang3.StringUtils.isNotEmpty in project dhis2-core by dhis2.
the class FilteringHelper method setFilteringParams.
/**
* Sets the filtering defined by filters list into the paramsMap.
*
* @param filters the source of filtering params
* @param paramsMap the map that will receive the filtering params
* @param currentUser the current user logged
*/
public static void setFilteringParams(final Set<String> filters, final WebOptions options, final MapSqlParameterSource paramsMap, final User currentUser) {
final Locale currentLocale = defaultIfNull(getUserSetting(DB_LOCALE), getUserSetting(UI_LOCALE));
if (currentLocale != null && isNotBlank(currentLocale.getLanguage())) {
paramsMap.addValue(LOCALE, trimToEmpty(currentLocale.getLanguage()));
}
final String ilikeName = extractValueFromFilter(filters, NAME_ILIKE);
if (StringUtils.isNotEmpty(ilikeName)) {
paramsMap.addValue(NAME, wrap(addIlikeReplacingCharacters(ilikeName), "%"));
}
final String ilikeDisplayName = extractValueFromFilter(filters, DISPLAY_NAME_ILIKE);
if (StringUtils.isNotEmpty(ilikeDisplayName)) {
paramsMap.addValue(DISPLAY_NAME, wrap(addIlikeReplacingCharacters(ilikeDisplayName), "%"));
}
final String ilikeShortName = extractValueFromFilter(filters, SHORT_NAME_ILIKE);
if (StringUtils.isNotEmpty(ilikeShortName)) {
paramsMap.addValue(SHORT_NAME, wrap(addIlikeReplacingCharacters(ilikeShortName), "%"));
}
final String ilikeDisplayShortName = extractValueFromFilter(filters, DISPLAY_SHORT_NAME_ILIKE);
if (StringUtils.isNotEmpty(ilikeDisplayShortName)) {
paramsMap.addValue(DISPLAY_SHORT_NAME, wrap(addIlikeReplacingCharacters(ilikeDisplayShortName), "%"));
}
final String equalId = extractValueFromFilter(filters, ID_EQUAL, true);
if (isNotBlank(equalId)) {
paramsMap.addValue(UID, equalId);
}
final String rootJunction = options.getRootJunction().name();
if (isNotBlank(rootJunction)) {
paramsMap.addValue(ROOT_JUNCTION, rootJunction);
}
final String identifiableToken = extractValueFromFilter(filters, IDENTIFIABLE_TOKEN);
if (identifiableToken != null) {
final List<String> wordsAsTokens = getTokens(identifiableToken);
if (CollectionUtils.isNotEmpty(wordsAsTokens)) {
paramsMap.addValue(IDENTIFIABLE_TOKEN_COMPARISON, StringUtils.join(wordsAsTokens, ","));
}
}
if (containsFilterWithAnyOfPrefixes(filters, VALUE_TYPE_EQUAL.getCombination(), VALUE_TYPE_IN.getCombination())) {
final Set<String> valueTypesFilter = extractAllValueTypesFromFilters(filters);
assertThatValueTypeFilterHasOnlyAggregatableTypes(valueTypesFilter, filters);
paramsMap.addValue(VALUE_TYPES, extractAllValueTypesFromFilters(filters));
} else {
// Includes all value types.
paramsMap.addValue(VALUE_TYPES, getAggregatables().stream().map(type -> type.name()).collect(toSet()));
}
final String programId = extractValueFromFilter(filters, PROGRAM_ID_EQUAL, true);
// Add program id filtering id, if present.
if (isNotBlank(programId)) {
paramsMap.addValue(PROGRAM_ID, programId);
}
// Add user group filtering, when present.
if (currentUser != null && CollectionUtils.isNotEmpty(currentUser.getGroups())) {
final Set<String> userGroupUids = currentUser.getGroups().stream().filter(group -> group != null).map(group -> trimToEmpty(group.getUid())).collect(toSet());
paramsMap.addValue(USER_GROUP_UIDS, "{" + join(",", userGroupUids) + "}");
}
}
Aggregations