Merge branch 'fix/MNT-17745_IndexDatesBefore1848' into develop

This commit is contained in:
Alex Mukha
2017-08-22 00:15:31 +01:00
parent 0f672dfb26
commit b3ee00b84d
2 changed files with 116 additions and 35 deletions

View File

@@ -29,6 +29,7 @@ import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@@ -49,6 +50,7 @@ import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.Path.AttributeElement; import org.alfresco.service.cmr.repository.Path.AttributeElement;
import org.alfresco.service.cmr.repository.Path.ChildAssocElement; import org.alfresco.service.cmr.repository.Path.ChildAssocElement;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
import org.alfresco.service.cmr.repository.datatype.TypeConverter; import org.alfresco.service.cmr.repository.datatype.TypeConverter;
import org.alfresco.service.cmr.repository.datatype.TypeConverter.Converter; import org.alfresco.service.cmr.repository.datatype.TypeConverter.Converter;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
@@ -56,9 +58,12 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.extensions.surf.exception.PlatformRuntimeException;
import org.springframework.extensions.webscripts.json.JSONUtils; import org.springframework.extensions.webscripts.json.JSONUtils;
/** /**
@@ -203,7 +208,7 @@ import org.springframework.extensions.webscripts.json.JSONUtils;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private class SOLRTypeConverter static class SOLRTypeConverter
{ {
private NamespaceService namespaceService; private NamespaceService namespaceService;
TypeConverter INSTANCE = new TypeConverter(); TypeConverter INSTANCE = new TypeConverter();
@@ -476,6 +481,22 @@ import org.springframework.extensions.webscripts.json.JSONUtils;
return source.toString(); return source.toString();
} }
}); });
INSTANCE.addConverter(Date.class, String.class, new TypeConverter.Converter<Date, String>()
{
public String convert(Date source)
{
try
{
DateTime dt = new DateTime(source, DateTimeZone.UTC);
return dt.toString();
}
catch (PlatformRuntimeException e)
{
throw new TypeConversionException("Failed to convert date " + source + " to string", e);
}
}
});
} }
} }
} }

View File

@@ -0,0 +1,60 @@
/*
* #%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.repo.web.scripts.solr;
import static org.junit.Assert.*;
import java.util.Date;
import org.alfresco.repo.web.scripts.solr.SOLRSerializer.SOLRTypeConverter;
import org.alfresco.util.ISO8601DateFormat;
import org.junit.Test;
public class SOLRSerializerTest
{
@Test
public void testDateSerializer()
{
SOLRTypeConverter typeConverter = new SOLRTypeConverter(null);
trip(typeConverter, "1912-01-01T00:40:00-06:00", "1912-01-01T06:40:00.000Z");
trip(typeConverter, "1812-01-01T00:40:00-06:00", "1812-01-01T06:40:00.000Z");
trip(typeConverter, "1845-01-01T00:40:00-06:00", "1845-01-01T06:40:00.000Z");
trip(typeConverter, "1846-01-01T00:40:00-06:00", "1846-01-01T06:40:00.000Z");
trip(typeConverter, "1847-01-01T00:40:00-06:00", "1847-01-01T06:40:00.000Z");
trip(typeConverter, "1848-01-01T00:40:00-06:00", "1848-01-01T06:40:00.000Z");
}
private void trip( SOLRTypeConverter typeConverter, String iso, String zulu)
{
Date testDate = ISO8601DateFormat.parse(iso);
String strDate = typeConverter.INSTANCE.convert(String.class, testDate);
assertEquals(zulu, strDate);
}
}