Skip to content

Commit

Permalink
#24738 change on the field we use to get to the asset
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrizzio-dotCMS committed Jun 30, 2023
1 parent 1b25978 commit dbd413c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.dotcms.rest.api.v1.asset;

import static com.dotcms.util.CollectionsUtils.map;

import com.amazonaws.services.rekognition.model.Asset;
import com.dotcms.contenttype.exception.NotFoundInDbException;
import com.dotcms.datagen.ContentletDataGen;
import com.dotcms.datagen.FileAssetDataGen;
Expand All @@ -21,7 +18,6 @@
import com.dotcms.util.IntegrationTestInitService;
import com.dotcms.variant.model.Variant;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Identifier;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
Expand All @@ -35,15 +31,12 @@
import com.dotmarketing.util.UUIDGenerator;
import com.liferay.portal.model.User;
import com.liferay.portal.util.WebKeys;
import io.vavr.control.Try;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.RandomStringUtils;
import org.glassfish.jersey.internal.util.Base64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private Tuple3<String,String, List<Object>> selectQuery(final BrowserQuery brows
if(UtilMethods.isSet(browserQuery.fileName)){
final String matchText = browserQuery.fileName.toLowerCase().trim();
sqlQuery.append(" and (");
sqlQuery.append(getAssetNameColumn(ASSET_NAME_EQ.toString()));
sqlQuery.append(" LOWER(id.asset_name) = ?");
sqlQuery.append(" ) ");
parameters.add( matchText );
}
Expand Down
7 changes: 6 additions & 1 deletion dotCMS/src/main/java/com/dotcms/browser/BrowserQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ public Builder withFilter(@Nonnull String filter) {

public Builder withFileName(@Nonnull String fileName) {
if (UtilMethods.isSet(fileName)) {
luceneQuery.append(StringPool.SPACE).append(fileName);
// for exact file-name match we need to relay exclusively on the database
// we can not trust on the use of the title field indexed in lucene
// As different files can share the same title, and we need an exact match on identifier.asset_name
// Therefore we need to make it fail on purpose by adding a non-existing value to the query
// If we include this fileNAme here BrowserAPI will try to match the title in lucene bringing back false positives
luceneQuery.append(StringPool.SPACE).append("___").append(fileName).append("___");
this.fileName = fileName;
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.BooleanUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.jetbrains.annotations.NotNull;

/**
* In typical dotCMS resource fashion this class is responsible for undertaking the heavy lifting
Expand Down Expand Up @@ -379,7 +377,7 @@ public FileAsset getAsset(final AssetsRequestForm form, final User user)
Contentlet.class::cast).collect(Collectors.toList());
if (assets.isEmpty()) {
throw new NotFoundInDbException(
String.format(" Asset [%s] not found for lang [%s] and working/live state [%b] ",
String.format(" Asset [%s] not found for lang [%s] and live status [%b] ",
assetName, form.language(),
BooleanUtils.toString(form.live(), "live", "working", "unspecified"))
);
Expand Down

0 comments on commit dbd413c

Please sign in to comment.