mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Moved instanceOf method from ServiceBaseImpl class to a utility class
This commit is contained in:
@@ -37,7 +37,7 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.hold.HoldService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.json.JSONArray;
|
||||
@@ -70,8 +70,8 @@ public abstract class BaseHold extends DeclarativeWebScript
|
||||
/** node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Dictionary service */
|
||||
private DictionaryService dictionaryService;
|
||||
/** Node type utility */
|
||||
private NodeTypeUtility nodeTypeUtility;
|
||||
|
||||
/**
|
||||
* Set the hold service
|
||||
@@ -108,11 +108,11 @@ public abstract class BaseHold extends DeclarativeWebScript
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService dictionary service
|
||||
* @param nodeTypeUtility node type utility
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
public void setNodeTypeUtility(NodeTypeUtility nodeTypeUtility)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
this.nodeTypeUtility = nodeTypeUtility;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +220,7 @@ public abstract class BaseHold extends DeclarativeWebScript
|
||||
|
||||
// ensure that the node we are adding to the hold is a record or record folder or active content
|
||||
if (!recordService.isRecord(nodeRef) && !recordFolderService.isRecordFolder(nodeRef) &&
|
||||
!dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_CONTENT))
|
||||
!nodeTypeUtility.instanceOf(nodeService.getType(nodeRef), ContentModel.TYPE_CONTENT))
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Items added to a hold must be either a record, a record folder or active content.");
|
||||
}
|
||||
|
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2019 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.module.org_alfresco_module_rm.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* Utility class to check if a node type is instance of another type
|
||||
*
|
||||
* @author Claudia Agache
|
||||
* @since 3.2
|
||||
*/
|
||||
public class NodeTypeUtility
|
||||
{
|
||||
/** Dictionary service */
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
private static Map<String, Boolean> instanceOfCache = new WeakHashMap<>();
|
||||
|
||||
/**
|
||||
* @param dictionaryService dictionary service
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to quickly determine whether one class is equal to or sub of another.
|
||||
*
|
||||
* @param className class name
|
||||
* @param ofClassName class name to check against
|
||||
* @return boolean true if equal to or sub, false otherwise
|
||||
*/
|
||||
public boolean instanceOf(QName className, QName ofClassName)
|
||||
{
|
||||
ParameterCheck.mandatory("className", className);
|
||||
ParameterCheck.mandatory("ofClassName", ofClassName);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
String key = className.toString() + "|" + ofClassName.toString();
|
||||
if (instanceOfCache.containsKey(key))
|
||||
{
|
||||
result = instanceOfCache.get(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ofClassName.equals(className) ||
|
||||
dictionaryService.isSubClass(className, ofClassName))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
instanceOfCache.put(key, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -29,7 +29,6 @@ package org.alfresco.module.org_alfresco_module_rm.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
|
||||
@@ -80,6 +79,9 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
|
||||
/** Content service */
|
||||
protected ContentService contentService;
|
||||
|
||||
/** Node type utility */
|
||||
protected NodeTypeUtility nodeTypeUtility;
|
||||
|
||||
/**
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
@@ -120,7 +122,15 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
|
||||
{
|
||||
this.authenticationUtil = authenticationUtil;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param nodeTypeUtility node type utility
|
||||
*/
|
||||
public void setNodeTypeUtility(NodeTypeUtility nodeTypeUtility)
|
||||
{
|
||||
this.nodeTypeUtility = nodeTypeUtility;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param transactionalResourceHelper transactional resource helper
|
||||
*/
|
||||
@@ -470,8 +480,6 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
|
||||
return instanceOf(className, ofClassName);
|
||||
}
|
||||
|
||||
private static Map<String, Boolean> instanceOfCache = new WeakHashMap<>();
|
||||
|
||||
/**
|
||||
* Utility method to quickly determine whether one class is equal to or sub of another.
|
||||
*
|
||||
@@ -481,28 +489,7 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
|
||||
*/
|
||||
protected boolean instanceOf(QName className, QName ofClassName)
|
||||
{
|
||||
ParameterCheck.mandatory("className", className);
|
||||
ParameterCheck.mandatory("ofClassName", ofClassName);
|
||||
|
||||
boolean result = false;
|
||||
|
||||
String key = className.toString() + "|" + ofClassName.toString();
|
||||
if (instanceOfCache.containsKey(key))
|
||||
{
|
||||
result = instanceOfCache.get(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ofClassName.equals(className) ||
|
||||
dictionaryService.isSubClass(className, ofClassName))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
instanceOfCache.put(key, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
return nodeTypeUtility.instanceOf(className, ofClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user