mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-16274: Enable quick share for custom sub types of cm:content
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@47380 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -54,6 +54,7 @@
|
|||||||
<!-- Calendar Service base bean -->
|
<!-- Calendar Service base bean -->
|
||||||
<bean id="quickShareService" class="org.alfresco.repo.quickshare.QuickShareServiceImpl" init-method="init">
|
<bean id="quickShareService" class="org.alfresco.repo.quickshare.QuickShareServiceImpl" init-method="init">
|
||||||
<property name="attributeService" ref="AttributeService"/>
|
<property name="attributeService" ref="AttributeService"/>
|
||||||
|
<property name="dictionaryService" ref="dictionaryService"/>
|
||||||
<property name="enabled" value="${system.quickshare.enabled}" />
|
<property name="enabled" value="${system.quickshare.enabled}" />
|
||||||
<property name="nodeService" ref="NodeService"/>
|
<property name="nodeService" ref="NodeService"/>
|
||||||
<property name="personService" ref="PersonService"/>
|
<property name="personService" ref="PersonService"/>
|
||||||
|
@@ -40,6 +40,7 @@ import org.alfresco.repo.tenant.TenantUtil;
|
|||||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||||
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
||||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||||
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareDisabledException;
|
import org.alfresco.service.cmr.quickshare.QuickShareDisabledException;
|
||||||
@@ -79,6 +80,7 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
|||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
private AttributeService attributeService;
|
private AttributeService attributeService;
|
||||||
|
private DictionaryService dictionaryService;
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
private PersonService personService;
|
private PersonService personService;
|
||||||
private PolicyComponent policyComponent;
|
private PolicyComponent policyComponent;
|
||||||
@@ -101,6 +103,14 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
|||||||
this.attributeService = attributeService;
|
this.attributeService = attributeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dictionary service
|
||||||
|
*/
|
||||||
|
public void setDictionaryService(DictionaryService dictionaryService)
|
||||||
|
{
|
||||||
|
this.dictionaryService = dictionaryService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the node service
|
* Set the node service
|
||||||
*/
|
*/
|
||||||
@@ -167,7 +177,7 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
|||||||
|
|
||||||
//Check the node is the correct type
|
//Check the node is the correct type
|
||||||
QName typeQName = nodeService.getType(nodeRef);
|
QName typeQName = nodeService.getType(nodeRef);
|
||||||
if (! typeQName.equals(ContentModel.TYPE_CONTENT))
|
if (isSharable(typeQName) == false)
|
||||||
{
|
{
|
||||||
throw new InvalidNodeRefException(nodeRef);
|
throw new InvalidNodeRefException(nodeRef);
|
||||||
}
|
}
|
||||||
@@ -312,6 +322,12 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
|||||||
{
|
{
|
||||||
metadata.put("sharedId", nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDID));
|
metadata.put("sharedId", nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDID));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QName type = nodeService.getType(nodeRef);
|
||||||
|
boolean sharable = isSharable(type);
|
||||||
|
metadata.put("sharable", sharable);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||||
model.put("item", metadata);
|
model.put("item", metadata);
|
||||||
@@ -425,7 +441,7 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
|||||||
public Void doWork() throws Exception
|
public Void doWork() throws Exception
|
||||||
{
|
{
|
||||||
QName typeQName = nodeService.getType(nodeRef);
|
QName typeQName = nodeService.getType(nodeRef);
|
||||||
if (! typeQName.equals(ContentModel.TYPE_CONTENT))
|
if (! isSharable(typeQName))
|
||||||
{
|
{
|
||||||
throw new InvalidNodeRefException(nodeRef);
|
throw new InvalidNodeRefException(nodeRef);
|
||||||
}
|
}
|
||||||
@@ -451,6 +467,10 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSharable(QName type)
|
||||||
|
{
|
||||||
|
return type.equals(ContentModel.TYPE_CONTENT) || dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT);
|
||||||
|
}
|
||||||
// Prevent copying of Quick share properties on node copy.
|
// Prevent copying of Quick share properties on node copy.
|
||||||
@Override
|
@Override
|
||||||
public CopyBehaviourCallback getCopyCallback(QName classRef, CopyDetails copyDetails)
|
public CopyBehaviourCallback getCopyCallback(QName classRef, CopyDetails copyDetails)
|
||||||
|
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -33,16 +34,19 @@ import org.alfresco.repo.model.Repository;
|
|||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||||
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
||||||
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
||||||
import org.alfresco.service.cmr.repository.CopyService;
|
import org.alfresco.service.cmr.repository.CopyService;
|
||||||
|
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.test.junitrules.AlfrescoPerson;
|
import org.alfresco.util.test.junitrules.AlfrescoPerson;
|
||||||
import org.alfresco.util.test.junitrules.ApplicationContextInit;
|
import org.alfresco.util.test.junitrules.ApplicationContextInit;
|
||||||
|
import org.alfresco.util.test.junitrules.TemporaryModels;
|
||||||
import org.alfresco.util.test.junitrules.TemporaryNodes;
|
import org.alfresco.util.test.junitrules.TemporaryNodes;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@@ -66,9 +70,40 @@ public class QuickShareServiceIntegrationTest
|
|||||||
{
|
{
|
||||||
private static final ApplicationContextInit testContext = new ApplicationContextInit();
|
private static final ApplicationContextInit testContext = new ApplicationContextInit();
|
||||||
|
|
||||||
|
private static final String MODEL =
|
||||||
|
"<?xml version='1.0' encoding='UTF-8'?>" +
|
||||||
|
"<model name='lx:lxmodel' xmlns='http://www.alfresco.org/model/dictionary/1.0'>" +
|
||||||
|
"<description>LX model</description>" +
|
||||||
|
"<author>Peter Löfgren</author>" +
|
||||||
|
"<version>1.0</version>" +
|
||||||
|
"<imports>" +
|
||||||
|
"<import uri='http://www.alfresco.org/model/dictionary/1.0' prefix='d' />" +
|
||||||
|
"<import uri='http://www.alfresco.org/model/content/1.0' prefix='cm' />" +
|
||||||
|
"</imports>" +
|
||||||
|
"<namespaces>" +
|
||||||
|
"<namespace uri='http://bugtestmodel' prefix='lx' />" +
|
||||||
|
"</namespaces>" +
|
||||||
|
"<constraints>" +
|
||||||
|
"</constraints>" +
|
||||||
|
"<types>" +
|
||||||
|
"<type name='lx:doc'>" +
|
||||||
|
"<title>LX dokument</title>" +
|
||||||
|
"<parent>cm:content</parent>" +
|
||||||
|
"<mandatory-aspects>" +
|
||||||
|
"<aspect>cm:generalclassifiable</aspect>" +
|
||||||
|
"</mandatory-aspects>" +
|
||||||
|
"</type>" +
|
||||||
|
"<type name='lx:doc2'>" +
|
||||||
|
"<title>LX dokument 2</title>" +
|
||||||
|
"<parent>cm:cmobject</parent>" +
|
||||||
|
"</type>" +
|
||||||
|
"</types>" +
|
||||||
|
"</model>";
|
||||||
|
|
||||||
private static CopyService copyService;
|
private static CopyService copyService;
|
||||||
private static NodeService nodeService;
|
private static NodeService nodeService;
|
||||||
private static QuickShareService quickShareService;
|
private static QuickShareService quickShareService;
|
||||||
|
private static DictionaryService dictionaryService;
|
||||||
private static Repository repository;
|
private static Repository repository;
|
||||||
|
|
||||||
private static AlfrescoPerson user1 = new AlfrescoPerson(testContext, "UserOne");
|
private static AlfrescoPerson user1 = new AlfrescoPerson(testContext, "UserOne");
|
||||||
@@ -77,6 +112,8 @@ public class QuickShareServiceIntegrationTest
|
|||||||
// A rule to manage test nodes reused across all the test methods
|
// A rule to manage test nodes reused across all the test methods
|
||||||
@Rule public TemporaryNodes testNodes = new TemporaryNodes(testContext);
|
@Rule public TemporaryNodes testNodes = new TemporaryNodes(testContext);
|
||||||
|
|
||||||
|
@Rule public TemporaryModels temporaryModels = new TemporaryModels(testContext);
|
||||||
|
|
||||||
@ClassRule public static RuleChain classChain = RuleChain.outerRule(testContext)
|
@ClassRule public static RuleChain classChain = RuleChain.outerRule(testContext)
|
||||||
.around(user1)
|
.around(user1)
|
||||||
.around(user2);
|
.around(user2);
|
||||||
@@ -96,6 +133,7 @@ public class QuickShareServiceIntegrationTest
|
|||||||
ApplicationContext ctx = testContext.getApplicationContext();
|
ApplicationContext ctx = testContext.getApplicationContext();
|
||||||
|
|
||||||
copyService = ctx.getBean("CopyService", CopyService.class);
|
copyService = ctx.getBean("CopyService", CopyService.class);
|
||||||
|
dictionaryService = ctx.getBean("dictionaryService", DictionaryService.class);
|
||||||
nodeService = ctx.getBean("NodeService", NodeService.class);
|
nodeService = ctx.getBean("NodeService", NodeService.class);
|
||||||
quickShareService = ctx.getBean("QuickShareService", QuickShareService.class);
|
quickShareService = ctx.getBean("QuickShareService", QuickShareService.class);
|
||||||
repository = ctx.getBean("repositoryHelper", Repository.class);
|
repository = ctx.getBean("repositoryHelper", Repository.class);
|
||||||
@@ -160,18 +198,8 @@ public class QuickShareServiceIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test public void unshare() {
|
@Test public void unshare() {
|
||||||
final QuickShareDTO dto = share(testNode, user1.getUsername());
|
final QuickShareDTO dto = share(testNode, user1.getUsername());
|
||||||
|
unshare(dto.getId(), user1.getUsername());
|
||||||
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doWork() throws Exception
|
|
||||||
{
|
|
||||||
quickShareService.unshareContent(dto.getId());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, user1.getUsername());
|
|
||||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>(){
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -186,6 +214,21 @@ public class QuickShareServiceIntegrationTest
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void unshare(final String sharedId, final String userName) {
|
||||||
|
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doWork() throws Exception
|
||||||
|
{
|
||||||
|
quickShareService.unshareContent(sharedId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, userName);
|
||||||
|
}
|
||||||
|
|
||||||
private QuickShareDTO share(final NodeRef nodeRef, String username)
|
private QuickShareDTO share(final NodeRef nodeRef, String username)
|
||||||
{
|
{
|
||||||
return AuthenticationUtil.runAs(new RunAsWork<QuickShareDTO>()
|
return AuthenticationUtil.runAs(new RunAsWork<QuickShareDTO>()
|
||||||
@@ -255,4 +298,66 @@ public class QuickShareServiceIntegrationTest
|
|||||||
}
|
}
|
||||||
}, user1.getUsername());
|
}, user1.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content types that extend cm:content should be shareable.
|
||||||
|
*
|
||||||
|
* See https://issues.alfresco.com/jira/browse/ALF-16274.
|
||||||
|
*/
|
||||||
|
@Test public void testWithCustomContentType()
|
||||||
|
{
|
||||||
|
ByteArrayInputStream modelStream = new ByteArrayInputStream(MODEL.getBytes());
|
||||||
|
temporaryModels.loadModel(modelStream);
|
||||||
|
|
||||||
|
QName sharableType = QName.createQName("{http://bugtestmodel}doc");
|
||||||
|
QName unsharableType = QName.createQName("{http://bugtestmodel}doc2");
|
||||||
|
|
||||||
|
final NodeRef sharableNode = testNodes.createNodeWithTextContent(userHome,
|
||||||
|
"Quick Share Custom Type Sharable Test Node",
|
||||||
|
sharableType,
|
||||||
|
user1.getUsername(),
|
||||||
|
"Quick Share Test Node Content");
|
||||||
|
|
||||||
|
Map<String, Object> metadata = getMetadata(sharableNode, user1);
|
||||||
|
|
||||||
|
assertTrue((Boolean)metadata.get("sharable"));
|
||||||
|
|
||||||
|
QuickShareDTO dto = share(sharableNode, user1.getUsername());
|
||||||
|
unshare(dto.getId(), user1.getUsername());
|
||||||
|
|
||||||
|
final NodeRef unsharableNode = testNodes.createNodeWithTextContent(userHome,
|
||||||
|
"Quick Share Custom Type Unsharable Test Node",
|
||||||
|
unsharableType,
|
||||||
|
user1.getUsername(),
|
||||||
|
"Quick Share Test Node Content");
|
||||||
|
|
||||||
|
metadata = getMetadata(unsharableNode, user1);
|
||||||
|
assertFalse((Boolean)metadata.get("sharable"));
|
||||||
|
|
||||||
|
boolean exceptionThrown = false;
|
||||||
|
try {
|
||||||
|
// Prior to fixing ALF-16274, this would throw an InvalidNodeRefException.
|
||||||
|
share(unsharableNode, user1.getUsername());
|
||||||
|
}
|
||||||
|
catch(InvalidNodeRefException ex)
|
||||||
|
{
|
||||||
|
exceptionThrown = true;
|
||||||
|
}
|
||||||
|
assertTrue("InvalidNodeRefException not thrown on trying to share an unsharable content type", exceptionThrown);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Map<String, Object> getMetadata(final NodeRef nodeRef, AlfrescoPerson user) {
|
||||||
|
Map<String, Object> container = AuthenticationUtil.runAs(new RunAsWork<Map<String, Object>>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> doWork() throws Exception
|
||||||
|
{
|
||||||
|
return quickShareService.getMetaData(nodeRef);
|
||||||
|
}
|
||||||
|
}, user.getUsername());
|
||||||
|
return (Map<String, Object>)container.get("item");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,164 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2012
|
||||||
|
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.util.test.junitrules;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.repo.dictionary.DictionaryDAO;
|
||||||
|
import org.alfresco.repo.dictionary.M2Model;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
|
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.junit.rules.ExternalResource;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A JUnit rule designed to help with the automatic cleanup of temporary models and to make it easier to
|
||||||
|
* create common test models with JUnit code.
|
||||||
|
*
|
||||||
|
* @author Alex Miller
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public class TemporaryModels extends ExternalResource
|
||||||
|
{
|
||||||
|
private static final Log logger = LogFactory.getLog(TemporaryModels.class);
|
||||||
|
|
||||||
|
private final ApplicationContextInit appContextRule;
|
||||||
|
|
||||||
|
private final Set<QName> loadedModels = new HashSet<QName>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs the rule with a reference to a {@link ApplicationContextInit rule} which can be used to retrieve the ApplicationContext.
|
||||||
|
*
|
||||||
|
* @param appContextRule a rule which can be used to retrieve the spring app context.
|
||||||
|
*/
|
||||||
|
public TemporaryModels(ApplicationContextInit appContextRule)
|
||||||
|
{
|
||||||
|
this.appContextRule = appContextRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override protected void before() throws Throwable
|
||||||
|
{
|
||||||
|
// Intentionally empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void after()
|
||||||
|
{
|
||||||
|
final RetryingTransactionHelper transactionHelper = getTransactionHelper();
|
||||||
|
final DictionaryDAO dictionaryDAO = getDictionaryDAO();
|
||||||
|
|
||||||
|
// Run as system to ensure all non-system nodes can be deleted irrespective of which user created them.
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||||
|
{
|
||||||
|
@Override public Void doWork() throws Exception
|
||||||
|
{
|
||||||
|
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
@Override public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
for (QName model : loadedModels)
|
||||||
|
{
|
||||||
|
dictionaryDAO.removeModel(model);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, AuthenticationUtil.getSystemUserName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private RetryingTransactionHelper getTransactionHelper() {
|
||||||
|
final ApplicationContext springContext = appContextRule.getApplicationContext();
|
||||||
|
|
||||||
|
final RetryingTransactionHelper transactionHelper = springContext.getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
|
||||||
|
return transactionHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QName loadModel(String modelPath, ClassLoader classLoader)
|
||||||
|
{
|
||||||
|
InputStream modelStream = classLoader.getResourceAsStream(modelPath);
|
||||||
|
if (modelStream == null)
|
||||||
|
{
|
||||||
|
throw new DictionaryException("Could not find bootstrap model " + modelPath);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return loadModel(modelStream);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
modelStream.close();
|
||||||
|
}
|
||||||
|
catch (IOException ioe)
|
||||||
|
{
|
||||||
|
logger.warn("Failed to close model input stream for '"+modelPath+"': "+ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public QName loadModel(InputStream modelStream)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final M2Model model = M2Model.createModel(modelStream);
|
||||||
|
|
||||||
|
return loadModel(model);
|
||||||
|
}
|
||||||
|
catch(DictionaryException e)
|
||||||
|
{
|
||||||
|
throw new DictionaryException("Could not import model", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private QName loadModel(final M2Model model) {
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Loading model: "+model.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
final DictionaryDAO dictionaryDAO = getDictionaryDAO();
|
||||||
|
QName modelQName = dictionaryDAO.putModel(model);
|
||||||
|
loadedModels.add(modelQName);
|
||||||
|
return modelQName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private DictionaryDAO getDictionaryDAO() {
|
||||||
|
final ApplicationContext springContext = appContextRule.getApplicationContext();
|
||||||
|
|
||||||
|
DictionaryDAO dictionaryDAO = springContext.getBean("dictionaryDAO", DictionaryDAO.class);
|
||||||
|
return dictionaryDAO;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user