mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
83910: Reverse Merge HEAD-BUG-FIX (5.0/Cloud) <<Does not include 83538, 83539 as intended>> 83891: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 81657: Merged DEV to V4.2-BUG-FIX (4.2.4) 78463 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n chars should not be created 80398 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n and | chars should not be created 80403 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Replace bad \n and | characters to _ char patch 83538: MNT-12288 : Reverse Merge V4.2-BUG-FIX (4.2.4) << Caused upgrade failure as the patch relies on search >> 81657 : Merged DEV to V4.2-BUG-FIX (4.2.4) 78463 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n chars should not be created 80398 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n and | chars should not be created 80403 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Replace bad \n and | characters to _ char patch 83539: Merged DEV to V4.2-BUG-FIX (4.2.4) 78463 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n chars should not be created 80398 : MNT-11871 : Adding tag with name containing new lines (\n) breaks the tagging service. - Tags containing \n and | chars should not be created git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@84596 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.tagging.TagScope;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* This patches Alfresco tags to remove broken char sequences from tag names
|
||||
*
|
||||
* @see <a href="https://issues.alfresco.com/jira/browse/MNT-11871">MNT-11871</a>
|
||||
* @author sergey.shcherbovich
|
||||
*/
|
||||
public class ReplaceForbiddenTagCharSequencesPatch extends AbstractPatch
|
||||
{
|
||||
private String REPLACER = "_";
|
||||
private String[] BAD_TAG_SEQUENCES = new String[] {"\n", "|"};
|
||||
|
||||
private static Log logger = LogFactory.getLog(ReplaceForbiddenTagCharSequencesPatch.class);
|
||||
|
||||
private static String SUCCESS_MESSAGE = "patch.replaceForbiddenTagCharSequencesPatch.result";
|
||||
|
||||
private TaggingService taggingService;
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
Set<TagScope> tagScopesToRefresh = new HashSet<>();
|
||||
|
||||
for (StoreRef storeRef : nodeService.getStores())
|
||||
{
|
||||
for (String bad : BAD_TAG_SEQUENCES)
|
||||
{
|
||||
List<String> brokenTags = taggingService.getTags(storeRef, bad);
|
||||
|
||||
for (String tag : brokenTags)
|
||||
{
|
||||
List<NodeRef> taggetNodes = taggingService.findTaggedNodes(storeRef, tag);
|
||||
|
||||
String newTag = findName(storeRef, bad, tag);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Broken tag in " + storeRef + " is " + tag + ", rename to " + newTag);
|
||||
}
|
||||
|
||||
taggingService.changeTag(storeRef, tag, newTag);
|
||||
|
||||
for (NodeRef nodeRef : taggetNodes)
|
||||
{
|
||||
tagScopesToRefresh.addAll(taggingService.findAllTagScopes(nodeRef));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Scopes to refresh : " + tagScopesToRefresh.size());
|
||||
}
|
||||
|
||||
for (TagScope tagScope : tagScopesToRefresh)
|
||||
{
|
||||
taggingService.refreshTagScope(tagScope.getNodeRef(), false);
|
||||
}
|
||||
|
||||
return I18NUtil.getMessage(SUCCESS_MESSAGE);
|
||||
}
|
||||
|
||||
private String findName(StoreRef storeRef, String badSequence, String tag)
|
||||
{
|
||||
String newTag = tag.replace(badSequence, REPLACER);
|
||||
|
||||
if (taggingService.getTagNodeRef(storeRef, newTag) != null)
|
||||
{
|
||||
return findName(storeRef, badSequence, tag.replace(badSequence, badSequence + REPLACER));
|
||||
}
|
||||
|
||||
return newTag;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
}
|
||||
}
|
@@ -25,16 +25,13 @@ import java.io.InputStreamReader;
|
||||
import java.io.Serializable;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -76,7 +73,6 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ISO9075;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -113,10 +109,6 @@ public class TaggingServiceImpl implements TaggingService,
|
||||
|
||||
/** Tag Details Delimiter */
|
||||
private static final String TAG_DETAILS_DELIMITER = "|";
|
||||
/** Next tag delimiter */
|
||||
private static final String NEXT_TAG_DELIMITER = "\n";
|
||||
|
||||
private static Set<String> FORBIDDEN_TAGS_SEQUENCES = new HashSet<String>(Arrays.asList(new String[] {NEXT_TAG_DELIMITER, TAG_DETAILS_DELIMITER}));
|
||||
|
||||
/** Policy behaviour */
|
||||
private JavaBehaviour updateTagBehaviour;
|
||||
@@ -728,14 +720,6 @@ public class TaggingServiceImpl implements TaggingService,
|
||||
*/
|
||||
private NodeRef getTagNodeRef(StoreRef storeRef, String tag, boolean create)
|
||||
{
|
||||
for (String forbiddenSequence : FORBIDDEN_TAGS_SEQUENCES)
|
||||
{
|
||||
if (create && tag.contains(forbiddenSequence))
|
||||
{
|
||||
throw new IllegalArgumentException("Tag name must not contain " + StringEscapeUtils.escapeJava(forbiddenSequence) + " char sequence");
|
||||
}
|
||||
}
|
||||
|
||||
NodeRef tagNodeRef = null;
|
||||
Collection<ChildAssociationRef> results = this.categoryService.getRootCategories(storeRef, ContentModel.ASPECT_TAGGABLE, tag, create);
|
||||
if (!results.isEmpty())
|
||||
@@ -1330,7 +1314,7 @@ public class TaggingServiceImpl implements TaggingService,
|
||||
{
|
||||
if (bFirst == false)
|
||||
{
|
||||
result.append(NEXT_TAG_DELIMITER);
|
||||
result.append("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user