Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

Reproduction and partial fix for indexing documents with CR in name #673

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 81 additions & 81 deletions src/main/java/org/alfresco/repo/web/scripts/solr/SOLRSerializer.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
/*
* #%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%
*/
/*
* #%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 java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.domain.node.ContentDataWithId;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.MLText;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.Path.AttributeElement;
import org.alfresco.service.cmr.repository.Path.ChildAssocElement;
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.Converter;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.surf.exception.PlatformRuntimeException;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.domain.node.ContentDataWithId;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.MLText;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.Path.AttributeElement;
import org.alfresco.service.cmr.repository.Path.ChildAssocElement;
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.Converter;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.surf.exception.PlatformRuntimeException;
import org.springframework.extensions.webscripts.json.JSONUtils;

/**
Expand Down Expand Up @@ -438,7 +438,7 @@ public String convert(Path source)
{
public String convert(ChildAssociationRef source)
{
return source.toString();
return org.json.simple.JSONObject.escape(source.toString());
}
});

Expand Down Expand Up @@ -480,22 +480,22 @@ public String convert(Boolean source)
{
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);
}
}
});
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);
}
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@

import java.util.Date;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.web.scripts.solr.SOLRSerializer.SOLRTypeConverter;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ISO8601DateFormat;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.mockito.Mockito;

public class SOLRSerializerTest
{
Expand All @@ -57,4 +66,24 @@ private void trip( SOLRTypeConverter typeConverter, String iso, String zulu)
String strDate = typeConverter.INSTANCE.convert(String.class, testDate);
assertEquals(zulu, strDate);
}

@Test
public void testChildAssociationRefToJSONString() {
SOLRSerializer solrSerializer = new SOLRSerializer();
solrSerializer.setDictionaryService(Mockito.mock(DictionaryService.class));
solrSerializer.setNamespaceService(Mockito.mock(NamespaceService.class));
solrSerializer.init();
QName childQName = QName.createQName("hello", "wo\rld");
ChildAssociationRef childAssociationRef = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS,
new NodeRef("workspace://SpacesStore/parent"), childQName, new NodeRef("workspace://SpacesStore/child"));
String validJsonString = solrSerializer.serializeToJSONString(childAssociationRef);
// Constructing a json object using the value
String jsonObjectString = String.format("{ \"key\": \"%s\" }", validJsonString);
try {
JSONObject jsonObject = new JSONObject(jsonObjectString);
} catch (JSONException e) {
// This only happens when there is a problem parsing the string
assert false;
}
}
}