Skip to content

Commit

Permalink
#25478 Filtering by DEFAULT Variant (#26653)
Browse files Browse the repository at this point in the history
* #25478 Filtering by DEFAULT Variant

* #25478 Including Test
  • Loading branch information
freddyDOTCMS authored Nov 13, 2023
1 parent 8a0c462 commit 2c13f3c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.dotcms.browser;

import com.dotcms.IntegrationTestBase;
import com.dotcms.datagen.FileAssetDataGen;
import com.dotcms.datagen.FolderDataGen;
import com.dotcms.datagen.HTMLPageDataGen;
import com.dotcms.datagen.LanguageDataGen;
import com.dotcms.datagen.LinkDataGen;
import com.dotcms.datagen.SiteDataGen;
import com.dotcms.datagen.TestDataUtils;
import com.dotcms.datagen.*;
import com.dotcms.util.IntegrationTestInitService;
import com.dotcms.variant.model.Variant;
import com.dotmarketing.beans.Host;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.Treeable;
Expand Down Expand Up @@ -43,11 +38,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -609,6 +600,75 @@ public void test_getFolderContent_folderOrderedByName() throws Exception{

}

/**
* Method to test: {@link BrowserAPIImpl#getFolderContent(BrowserQuery)}
* When: A Contentlet has Version in DEFAULT Variant and also in a specific Variant
* Should: Return just the DEFAULT Version
*
* @throws DotDataException
* @throws DotSecurityException
* @throws IOException
*/
@Test
public void getJustDEFAULTVariantVersion() throws DotDataException, DotSecurityException, IOException {
final Host host = new SiteDataGen().nextPersisted();
final Folder folder = new FolderDataGen().site(host).nextPersisted();

final Contentlet file = new FileAssetDataGen(folder, "This is a File")
.folder(folder)
.host(host)
.nextPersisted();

final Variant variant = new VariantDataGen().nextPersisted();
ContentletDataGen.createNewVersion(file, variant, Collections.EMPTY_MAP);

final Map<String, Object> files = browserAPI.getFolderContent(BrowserQuery.builder()
.withHostOrFolderId(folder.getIdentifier())
.build());

assertEquals(1, Integer.parseInt(files.get("total").toString()));

final List list = (List) files.get("list");
assertEquals(1, list.size());
assertEquals(file.getIdentifier(), ((Contentlet.ContentletHashMap) list.get(0)).get("identifier"));
assertEquals(file.getInode(), ((Contentlet.ContentletHashMap) list.get(0)).get("inode"));

}

/**
* Method to test: {@link BrowserAPIImpl#getFolderContent(BrowserQuery)}
* When: A Contentlet has Version in a specific Variant
* Should: Not return this Contentlet
*
* @throws DotDataException
* @throws DotSecurityException
* @throws IOException
*/
@Test
public void notGetSpecificVariantVersion() throws DotDataException, DotSecurityException, IOException {
final Host host = new SiteDataGen().nextPersisted();
final Folder folder = new FolderDataGen().site(host).nextPersisted();

final Variant variant = new VariantDataGen().nextPersisted();

final Contentlet file = new FileAssetDataGen(folder, "This is a File")
.folder(folder)
.host(host)
.variant(variant)
.nextPersisted();


final Map<String, Object> files = browserAPI.getFolderContent(BrowserQuery.builder()
.withHostOrFolderId(folder.getIdentifier())
.build());

assertEquals(0, Integer.parseInt(files.get("total").toString()));

final List list = (List) files.get("list");
assertTrue(list.isEmpty());

}

/**
* <ul>
* <li><b>Method to Test:</b> {@link BrowserAPIImpl#getAssetNameColumn(String)}</li>
Expand Down
4 changes: 4 additions & 0 deletions dotCMS/src/main/java/com/dotcms/browser/BrowserAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.dotcms.business.CloseDBIfOpened;
import com.dotcms.content.business.json.ContentletJsonAPI;
import com.dotcms.content.elasticsearch.business.ESMappingAPIImpl;
import com.dotcms.content.elasticsearch.constants.ESMappingConstants;
import com.dotcms.contenttype.model.type.BaseContentType;
import com.dotcms.uuid.shorty.ShortyIdAPI;
import com.dotmarketing.beans.Host;
Expand Down Expand Up @@ -283,6 +285,8 @@ private Tuple3<String,String, List<Object>> selectQuery(final BrowserQuery brows
final StringBuilder luceneQuery = UtilMethods.isSet(browserQuery.luceneQuery)
? new StringBuilder("+title:*" + browserQuery.luceneQuery.trim() + "* ")
: new StringBuilder();

luceneQuery.append("+" + ESMappingConstants.VARIANT + ":DEFAULT ");
luceneQuery.append(browserQuery.showWorking ? "+working:true " : "+live:true ");
luceneQuery.append(browserQuery.showArchived ? "+deleted:true " : "+deleted:false ");
if (!showAllBaseTypes) {
Expand Down

0 comments on commit 2c13f3c

Please sign in to comment.