mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged WEBAPP-API (5.2.1) to 5.2.N (5.2.1)
132578 jkaabimofrad: APPSREPO-59: Modified the model validator to ignore the TYPE_NAMESPACE when there is a DIFF_DELETED type. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@132589 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,31 +1,30 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* 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 Repository
|
||||
* %%
|
||||
* 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.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -46,7 +45,7 @@ import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.ModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.NamespaceDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
@@ -73,7 +72,7 @@ public class ModelValidatorImpl implements ModelValidator
|
||||
private static final Log logger = LogFactory.getLog(ModelValidatorImpl.class);
|
||||
|
||||
private DictionaryDAO dictionaryDAO;
|
||||
private DictionaryService dictionaryService;
|
||||
private DictionaryService dictionaryService;
|
||||
private QNameDAO qnameDAO;
|
||||
private NamespaceService namespaceService;
|
||||
private TransactionService transactionService;
|
||||
@@ -122,11 +121,11 @@ public class ModelValidatorImpl implements ModelValidator
|
||||
this.tenantAdminService = tenantAdminService;
|
||||
}
|
||||
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
private void checkCustomModelNamespace(M2Model model, String tenantDomain)
|
||||
{
|
||||
if(tenantDomain != null && !tenantDomain.equals("") && enforceTenantInNamespace)
|
||||
@@ -477,7 +476,16 @@ public class ModelValidatorImpl implements ModelValidator
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to validate model update - found deleted " + modelDiff.getElementType() + " '" + modelDiff.getElementName() + "'");
|
||||
/*
|
||||
* As the M2Model#compile method will detect and throw exception for any missing namespace which
|
||||
* is required to define any Type, Aspect or Property, we can safely add this extra check.
|
||||
* See APPSREPO-59 comment for details.
|
||||
*/
|
||||
if (!modelDiff.getElementType().equals(M2ModelDiff.TYPE_NAMESPACE))
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to validate model update - found deleted " + modelDiff.getElementType() + " '" + modelDiff
|
||||
.getElementName() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,37 +493,37 @@ public class ModelValidatorImpl implements ModelValidator
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to validate model update - found non-incrementally updated " + modelDiff.getElementType() + " '" + modelDiff.getElementName() + "'");
|
||||
}
|
||||
|
||||
if(modelDiff.getDiffType().equals(M2ModelDiff.DIFF_CREATED))
|
||||
{
|
||||
if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_NAMESPACE))
|
||||
{
|
||||
ModelDefinition importedModel = dictionaryService.getModelByNamespaceUri(modelDiff.getNamespaceDefinition().getUri());
|
||||
if(importedModel != null && !model.getNamespaces().isEmpty())
|
||||
{
|
||||
checkCircularDependency(importedModel, model, importedModel.getName().getLocalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(modelDiff.getDiffType().equals(M2ModelDiff.DIFF_CREATED))
|
||||
{
|
||||
if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_NAMESPACE))
|
||||
{
|
||||
ModelDefinition importedModel = dictionaryService.getModelByNamespaceUri(modelDiff.getNamespaceDefinition().getUri());
|
||||
if(importedModel != null && !model.getNamespaces().isEmpty())
|
||||
{
|
||||
checkCircularDependency(importedModel, model, importedModel.getName().getLocalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO validate that any deleted constraints are not being referenced - else currently will become anon - or push down into model compilation (check backwards compatibility ...)
|
||||
}
|
||||
|
||||
private void checkCircularDependency(ModelDefinition model, M2Model existingModel, String parentPrefixedName) throws AlfrescoRuntimeException
|
||||
{
|
||||
for (NamespaceDefinition importedNamespace : model.getImportedNamespaces())
|
||||
{
|
||||
ModelDefinition md = null;
|
||||
if ((md = dictionaryService.getModelByNamespaceUri(importedNamespace.getUri())) != null)
|
||||
{
|
||||
if (existingModel.getNamespace(importedNamespace.getUri()) != null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to validate model update - found circular dependency. You can't set parent " + parentPrefixedName + " as it's model already depends on " + existingModel.getName());
|
||||
}
|
||||
checkCircularDependency(md, existingModel, parentPrefixedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void checkCircularDependency(ModelDefinition model, M2Model existingModel, String parentPrefixedName) throws AlfrescoRuntimeException
|
||||
{
|
||||
for (NamespaceDefinition importedNamespace : model.getImportedNamespaces())
|
||||
{
|
||||
ModelDefinition md = null;
|
||||
if ((md = dictionaryService.getModelByNamespaceUri(importedNamespace.getUri())) != null)
|
||||
{
|
||||
if (existingModel.getNamespace(importedNamespace.getUri()) != null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to validate model update - found circular dependency. You can't set parent " + parentPrefixedName + " as it's model already depends on " + existingModel.getName());
|
||||
}
|
||||
checkCircularDependency(md, existingModel, parentPrefixedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* 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 Repository
|
||||
* %%
|
||||
* 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.dictionary;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -37,6 +37,7 @@ import org.alfresco.repo.domain.qname.QNameDAO;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
@@ -50,6 +51,7 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -102,6 +104,12 @@ public class ModelValidatorTest
|
||||
addModel();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp()
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
private QName addModel()
|
||||
{
|
||||
this.testNamespace = "http://www.alfresco.org/test/" + modelName;
|
||||
@@ -449,4 +457,54 @@ public class ModelValidatorTest
|
||||
};
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(deleteModelAgainCallback, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an unused imported namespace can be deleted.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteNamespace() throws Exception
|
||||
{
|
||||
// authenticate
|
||||
AuthenticationUtil.pushAuthentication();
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
// Remove the only property (created in setup method)
|
||||
this.type.removeProperty(this.property.getName());
|
||||
// We don't have any property that references the imported dictionary namespace, so remove it.
|
||||
this.model.removeImport(NamespaceService.DICTIONARY_MODEL_1_0_URI);
|
||||
|
||||
// Check that it compiles
|
||||
CompiledModel compiledModel = model.compile(dictionaryDAO, namespaceDAO, true);
|
||||
modelValidator.validateModel(compiledModel);
|
||||
|
||||
// Remove the imported content model namespace
|
||||
this.model.removeImport(NamespaceService.CONTENT_MODEL_1_0_URI);
|
||||
try
|
||||
{
|
||||
model.compile(dictionaryDAO, namespaceDAO, true);
|
||||
fail("Should have failed as the model's type references the content model (cm:folder).");
|
||||
}
|
||||
catch (DictionaryException dx)
|
||||
{
|
||||
//expected
|
||||
}
|
||||
|
||||
// Add the content model namespace back
|
||||
model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX);
|
||||
model.compile(dictionaryDAO, namespaceDAO, true);
|
||||
|
||||
// Remove the defined namespace
|
||||
this.model.removeNamespace(testNamespace);
|
||||
try
|
||||
{
|
||||
model.compile(dictionaryDAO, namespaceDAO, true);
|
||||
fail("Should have failed as the type's name references the namespace.");
|
||||
}
|
||||
catch (DictionaryException dx)
|
||||
{
|
||||
//expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user