Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALFREDAPI-549 Remove facet if datetime range for 4.x #208

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Alfred API v4 and older are currently in End of Life.
We are moving away from the [Dynamic Extensions](https://github.com/xenit-eu/dynamic-extensions-for-alfresco) platform towards [Alfresco MVC](https://github.com/dgradecak/alfresco-mvc) platform to reduce our maintenance efforts.
Please follow the [installation gude](https://docs.xenit.eu/alfred-api/user/installation/) to upgrade to Alfred API v5+.

## 4.1.2 (2024-05-08)

### Fixed
* [ALFREDAPI-549](https://xenitsupport.jira.com/browse/ALFREDAPI-549): drop pure datetime range from facet results

## 4.1.1 (2024-04-25)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,25 +247,28 @@ private Map<String, List<ScriptFacetResult>> getFacetResults(SearchParameters sp
// qName => {http://www.alfresco.org/model/content/1.0}created
// 7 => {!afts}
key = key.replace("{!afts}","");
String facetTokenName = key.substring(0, key.indexOf(":["));
String qName = facetTokenToQname(facetTokenName);

// Retrieve the previous facet queries
List<ScriptFacetResult> fqs = result.get(qName);
if (fqs == null) {
fqs = new ArrayList<>();
}
int indexOfColonBracket = key.indexOf(":[");
if (indexOfColonBracket == key.lastIndexOf(':')) {
String facetTokenName = key.substring(0, indexOfColonBracket);
String qName = facetTokenToQname(facetTokenName);

// Retrieve the previous facet queries
List<ScriptFacetResult> fqs = result.get(qName);
if (fqs == null) {
fqs = new ArrayList<>();
}

// Get the handler for this qName
FacetLabelDisplayHandler handler = facetLabelDisplayHandlerRegistry.getDisplayHandler(facetTokenName);
String val = key.substring(key.indexOf(":[") + 1);
FacetLabel facetLabel = (handler == null) ? new FacetLabel(val, val, -1) : handler.getDisplayLabel(key);
// Get the handler for this qName
FacetLabelDisplayHandler handler = facetLabelDisplayHandlerRegistry.getDisplayHandler(facetTokenName);
String val = key.substring(indexOfColonBracket + 1);
FacetLabel facetLabel = (handler == null) ? new FacetLabel(val, val, -1) : handler.getDisplayLabel(key);

// See if we have a nice textual version of this label
String label = this.translationService.getMessageTranslation(facetLabel.getLabel());
// See if we have a nice textual version of this label
String label = this.translationService.getMessageTranslation(facetLabel.getLabel());

fqs.add(new ScriptFacetResult(facetLabel.getValue(), label, facetLabel.getLabelIndex(), entry.getValue()));
result.put(qName, fqs);
fqs.add(new ScriptFacetResult(facetLabel.getValue(), label, facetLabel.getLabelIndex(), entry.getValue()));
result.put(qName, fqs);
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import eu.xenit.apix.alfresco.search.SearchFacetsService;
Expand All @@ -12,14 +14,20 @@
import eu.xenit.apix.search.FacetSearchResult.FacetValue;
import eu.xenit.apix.search.SearchQuery.FacetOptions;
import eu.xenit.apix.translation.ITranslationService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.repo.search.impl.solr.facet.SolrFacetHelper;
import org.alfresco.repo.search.impl.solr.facet.SolrFacetService;
import org.alfresco.repo.search.impl.solr.facet.handler.AbstractFacetLabelDisplayHandler;
import org.alfresco.repo.search.impl.solr.facet.handler.ContentSizeBucketsDisplayHandler;
import org.alfresco.repo.search.impl.solr.facet.handler.DateBucketsDisplayHandler;
import org.alfresco.repo.search.impl.solr.facet.handler.FacetLabelDisplayHandlerRegistry;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
Expand All @@ -33,6 +41,7 @@
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;

public class SearchFacetServiceUnitTest {
Expand All @@ -43,14 +52,16 @@ public class SearchFacetServiceUnitTest {
FacetOptions facetOptionsMock;
ResultSet resultSetMock;
SearchParameters searchParametersMock;
ITranslationService translationServiceMock;

public void initMocks() {
ServiceRegistry serviceRegistryMock = mock(ServiceRegistry.class);

SolrFacetHelper solrFacetHelperMock = mock(SolrFacetHelper.class);
translationServiceMock = mock(ITranslationService.class);

FacetLabelDisplayHandlerRegistry facetLabelDisplayHandlerRegistryStub =
new FacetLabelDisplayHandlerRegistry();
initFacetLabelDisplayHandler(serviceRegistryMock);

DataTypeDefinition textDataTypeDef = mock(DataTypeDefinition.class);
when(textDataTypeDef.getName()).thenReturn(DataTypeDefinition.TEXT);
Expand Down Expand Up @@ -94,8 +105,7 @@ public void initMocks() {
when(serviceRegistryMock.getDictionaryService()).thenReturn(dictionaryServiceMock);
when(serviceRegistryMock.getSolrFacetHelper()).thenReturn(solrFacetHelperMock);
when(serviceRegistryMock.getFacetLabelDisplayHandlerRegistry()).thenReturn(facetLabelDisplayHandlerRegistryStub);
searchFacetsService = new SearchFacetsServiceImpl(serviceRegistryMock, mock(SolrFacetService.class), mock(
ITranslationService.class));
searchFacetsService = new SearchFacetsServiceImpl(serviceRegistryMock, mock(SolrFacetService.class), translationServiceMock);

facetOptionsMock = mock(FacetOptions.class);
when(facetOptionsMock.isEnabled()).thenReturn(true);
Expand Down Expand Up @@ -126,6 +136,40 @@ public void initMocks() {
when(fieldFacetMock_B.getField()).thenReturn("@{http://test.apix.xenit.eu/model/content}documentStatus");
fieldFacets.add(fieldFacetMock_B);
when(searchParametersMock.getFieldFacets()).thenReturn(fieldFacets);
when(translationServiceMock.getMessageTranslation("faceted-search.size.0-10KB.label")).thenReturn("0 to 10KB");
when(translationServiceMock.getMessageTranslation("faceted-search.date.one-year.label")).thenReturn("This year");
}

private FacetLabelDisplayHandlerRegistry initFacetLabelDisplayHandler(ServiceRegistry serviceRegistry) {
FacetLabelDisplayHandlerRegistry facetLabelDisplayHandlerRegistry = new FacetLabelDisplayHandlerRegistry();
List<AbstractFacetLabelDisplayHandler> displayHandlers = new ArrayList<>();
displayHandlers.add(new ContentSizeBucketsDisplayHandler(
Set.of("@{http://www.alfresco.org/model/content/1.0}content.size"),
new LinkedHashMap<>(Map.of(
"[0 TO 10240]", "faceted-search.size.0-10KB.label",
"[10240 TO 102400]", "faceted-search.size.10-100KB.label",
"[102400 TO 1048576]", "faceted-search.size.100KB-1MB.label",
"[1048576 TO 16777216]", "faceted-search.size.1-16MB.label",
"[16777216 TO 134217728]", "faceted-search.size.16-128MB.label",
"[134217728 TO MAX]", "faceted-search.size.over128.label"
)))
);
displayHandlers.add(new DateBucketsDisplayHandler(
Set.of("@{http://www.alfresco.org/model/content/1.0}created",
"@{http://www.alfresco.org/model/content/1.0}modified"),
new LinkedHashMap<>(Map.of(
"[NOW/DAY-1DAY TO NOW/DAY+1DAY]", "faceted-search.date.one-day.label",
"[NOW/DAY-7DAYS TO NOW/DAY+1DAY]", "faceted-search.date.one-week.label",
"[NOW/DAY-1MONTH TO NOW/DAY+1DAY]", "faceted-search.date.one-month.label",
"[NOW/DAY-6MONTHS TO NOW/DAY+1DAY]", "faceted-search.date.six-months.label",
"[NOW/DAY-1YEAR TO NOW/DAY+1DAY]", "faceted-search.date.one-year.label"
))));
displayHandlers.forEach(displayHandler -> {
displayHandler.setRegistry(facetLabelDisplayHandlerRegistry);
displayHandler.setServiceRegistry(serviceRegistry);
displayHandler.register();
});
return facetLabelDisplayHandlerRegistry;
}

public List<FacetSearchResult> initExpectedResult_for_assertThat_getFacetResults_returnIncludes_translationsForListOfValueConstraints() {
Expand Down Expand Up @@ -154,7 +198,8 @@ public List<FacetSearchResult> initExpectedResult_for_assertThat_getFacetResults
contentResult.setName("{http://www.alfresco.org/model/content/1.0}content.size");
List<FacetValue> contentValues = new ArrayList<>();
FacetValue contentFacetValue = new FacetValue();
contentFacetValue.setValue("[0 TO 10240]");
contentFacetValue.setValue("0\"..\"10240");
contentFacetValue.setLabel("0 to 10KB");
contentFacetValue.setCount(1);
contentValues.add(contentFacetValue);
contentResult.setValues(contentValues);
Expand All @@ -163,20 +208,12 @@ public List<FacetSearchResult> initExpectedResult_for_assertThat_getFacetResults
modifiedResult.setName("{http://www.alfresco.org/model/content/1.0}modified");
List<FacetValue> modifiedValues = new ArrayList<>();
FacetValue modifiedFacetValue = new FacetValue();
modifiedFacetValue.setValue("[NOW/DAY-1YEAR TO NOW/DAY+1DAY]");
modifiedFacetValue.setValue("NOW/DAY-1YEAR\"..\"NOW/DAY+1DAY");
modifiedFacetValue.setCount(2);
modifiedFacetValue.setLabel("This year");;
modifiedValues.add(modifiedFacetValue);
modifiedResult.setValues(modifiedValues);
expectedResult.add(modifiedResult);
FacetSearchResult createdResult = new FacetSearchResult();
createdResult.setName("{http://www.alfresco.org/model/content/1.0}created");
List<FacetValue> createdValues = new ArrayList<>();
FacetValue createdFacetValue = new FacetValue();
createdFacetValue.setValue("[2020-08-31T07:00:00.000Z TO 2023-09-02T10:01:00.000Z]");
createdFacetValue.setCount(1);
createdValues.add(createdFacetValue);
createdResult.setValues(createdValues);
expectedResult.add(createdResult);
return expectedResult;
}

Expand All @@ -187,6 +224,7 @@ public void assertThat_getFacetResults_returnIncludes_translationsForListOfValue
List<FacetSearchResult> result = searchFacetsService.getFacetResults(facetOptionsMock, resultSetMock,
searchParametersMock);
assertEquals(expectedResult, result);
verify(translationServiceMock, times(2)).getMessageTranslation(Mockito.anyString());
}

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ buildscript {
}

ext {
versionWithoutQualifier = '4.1.1'
versionWithoutQualifier = '4.1.2'

jackson_version = '2.8.3'
swagger_version = "1.5.7"
Expand Down