Merged 5.2.N (5.2.2) to HEAD (5.2)

137066 gjames: Merged searchrep (5.2.1) to 5.2.N (5.2.1)
      136887 gjames: SEARCH-449: Added localisation element


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@137581 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrei Rebegea
2017-06-15 11:16:53 +00:00
parent d776dffab9
commit ecf8dae504
4 changed files with 200 additions and 59 deletions

View File

@@ -46,6 +46,7 @@ import org.alfresco.rest.api.search.model.FacetFields;
import org.alfresco.rest.api.search.model.FacetQuery;
import org.alfresco.rest.api.search.model.FilterQuery;
import org.alfresco.rest.api.search.model.Limits;
import org.alfresco.rest.api.search.model.Localization;
import org.alfresco.rest.api.search.model.Pivot;
import org.alfresco.rest.api.search.model.Query;
import org.alfresco.rest.api.search.model.Scope;
@@ -78,6 +79,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Locale.Builder;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -115,11 +118,11 @@ public class SearchMapper
SearchParameters sp = new SearchParameters();
setDefaults(sp);
fromLocalization(sp, searchQuery.getLocalization());
fromQuery(sp, searchQuery.getQuery());
fromPaging(sp, params.getPaging());
fromSort(sp, searchQuery.getSort());
fromTemplate(sp, searchQuery.getTemplates());
fromTimezone(sp, searchQuery.getTimezone());
validateInclude(searchQuery.getInclude());
fromDefault(sp, searchQuery.getDefaults());
fromFilterQuery(sp, searchQuery.getFilterQueries());
@@ -691,44 +694,65 @@ public class SearchMapper
* @param sp SearchParameters
* @param timezoneId a valid java.time.ZoneId
*/
public void fromTimezone(SearchParameters sp, String timezoneId)
public void fromLocalization(SearchParameters sp, Localization localization)
{
/*
* java.util.TimeZone will not error if you set an invalid timezone
* it just falls back to GMT without telling you.
*
* So I am using java.time.ZoneId because that throws an error,
* if I then convert a ZoneId to Timezone I have the same problem (silently uses GMT)
* so
* I am converting using both methods:
* If a timezoneId is invalid then an Invalid error is thrown
* If its not possible to take a java.time.ZoneId and convert it to a java.util.TimeZone then an Incompatible error is thrown
*
*/
if (timezoneId!= null && !timezoneId.isEmpty())
if (localization != null)
{
ZoneId validZoneId = null;
TimeZone timeZone = null;
try
if (!localization.getLocales().isEmpty())
{
validZoneId = ZoneId.of(timezoneId);
timeZone = TimeZone.getTimeZone(timezoneId);
}
catch (Exception e)
{
throw new IllegalArgumentException("Invalid timezoneId "+timezoneId);
try
{
localization.getLocales().forEach(localeStr -> {
if (localeStr != null) localeStr = localeStr.replace('_','-');
sp.addLocale(Locale.forLanguageTag(localeStr));
});
}
catch (Exception e)
{
throw new IllegalArgumentException("Invalid locale " + localization.getLocales());
}
}
if (validZoneId.getId().equals(timeZone.getID()))
/*
* java.util.TimeZone will not error if you set an invalid timezone
* it just falls back to GMT without telling you.
*
* So I am using java.time.ZoneId because that throws an error,
* if I then convert a ZoneId to Timezone I have the same problem (silently uses GMT)
* so
* I am converting using both methods:
* If a timezoneId is invalid then an Invalid error is thrown
* If its not possible to take a java.time.ZoneId and convert it to a java.util.TimeZone then an Incompatible error is thrown
*
*/
String timezoneId = localization.getTimezone();
if (timezoneId != null && !timezoneId.isEmpty())
{
sp.setTimezone(validZoneId.getId());
}
else
{
throw new IllegalArgumentException("Incompatible timezoneId "+timezoneId);
}
ZoneId validZoneId = null;
TimeZone timeZone = null;
try
{
validZoneId = ZoneId.of(timezoneId);
timeZone = TimeZone.getTimeZone(timezoneId);
}
catch (Exception e)
{
throw new IllegalArgumentException("Invalid timezoneId " + timezoneId);
}
if (validZoneId.getId().equals(timeZone.getID()))
{
sp.setTimezone(validZoneId.getId());
}
else
{
throw new IllegalArgumentException("Incompatible timezoneId " + timezoneId);
}
}
}
}

View File

@@ -0,0 +1,59 @@
/*-
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.api.search.model;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Collections;
import java.util.List;
/**
* POJO class representing Localization parameters
*/
public class Localization
{
private final String timezone;
private final List<String> locales;
@JsonCreator
public Localization(@JsonProperty("timezone") String timezone,
@JsonProperty("locales") List<String> locales)
{
this.timezone = timezone;
this.locales = locales == null? Collections.emptyList():locales;
}
public String getTimezone()
{
return timezone;
}
public List<String> getLocales()
{
return locales;
}
}

View File

@@ -62,7 +62,7 @@ public class SearchQuery
private final List<Pivot> pivots;
private final List<StatsRequestParameters> stats;
private final List<RangeParameters> ranges;
private final String timezone;
private final Localization localization;
public static final SearchQuery EMPTY = new SearchQuery(null, null, null, null, null, null,
null,null, null, null, null,null, null, null, null,
@@ -88,7 +88,7 @@ public class SearchQuery
@JsonProperty("pivots") List<Pivot> pivots,
@JsonProperty("stats") List<StatsRequestParameters> stats,
@JsonProperty("ranges") List<RangeParameters> ranges,
@JsonProperty("timezone") String timezone)
@JsonProperty("localization") Localization localization)
{
this.query = query;
this.includeRequest = includeRequest==null?false:includeRequest;
@@ -109,7 +109,7 @@ public class SearchQuery
this.pivots = pivots;
this.stats = stats;
this.ranges = ranges;
this.timezone = timezone;
this.localization = localization;
}
public Query getQuery()
@@ -206,8 +206,9 @@ public class SearchQuery
return ranges;
}
public String getTimezone()
public Localization getLocalization()
{
return timezone;
return localization;
}
}