mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
REPO-5631 Investigate different types of results for optional patches difference detection (#472)
* Now supporting other Result implementations when detecting optional patches problems
This commit is contained in:
@@ -85,7 +85,6 @@ import org.alfresco.util.DialectUtil;
|
|||||||
import org.alfresco.util.LogUtil;
|
import org.alfresco.util.LogUtil;
|
||||||
import org.alfresco.util.PropertyCheck;
|
import org.alfresco.util.PropertyCheck;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.alfresco.util.schemacomp.Difference;
|
|
||||||
import org.alfresco.util.schemacomp.ExportDb;
|
import org.alfresco.util.schemacomp.ExportDb;
|
||||||
import org.alfresco.util.schemacomp.MultiFileDumper;
|
import org.alfresco.util.schemacomp.MultiFileDumper;
|
||||||
import org.alfresco.util.schemacomp.MultiFileDumper.DbToXMLFactory;
|
import org.alfresco.util.schemacomp.MultiFileDumper.DbToXMLFactory;
|
||||||
@@ -2004,12 +2003,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(result instanceof Difference))
|
return differenceHelper.findPatchCausingDifference(result);
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return differenceHelper.findPatchCausingDifference((Difference)result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.util.schemacomp;
|
package org.alfresco.util.schemacomp;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
|
|
||||||
@@ -83,36 +85,51 @@ public final class Difference extends Result
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describe()
|
public String describe()
|
||||||
|
{
|
||||||
|
return doDescribe(I18NUtil.getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe(Locale locale)
|
||||||
|
{
|
||||||
|
return doDescribe(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String doDescribe(Locale locale)
|
||||||
{
|
{
|
||||||
if (getLeft() == null)
|
if (getLeft() == null)
|
||||||
{
|
{
|
||||||
return I18NUtil.getMessage(
|
return I18NUtil.getMessage(
|
||||||
"system.schema_comp.diff.target_only",
|
"system.schema_comp.diff.target_only",
|
||||||
|
locale,
|
||||||
getRight().getDbObject().getTypeName(),
|
getRight().getDbObject().getTypeName(),
|
||||||
getRight().getPath(),
|
getRight().getPath(),
|
||||||
getRight().getPropertyValue());
|
getRight().getPropertyValue());
|
||||||
}
|
}
|
||||||
if (getRight() == null)
|
if (getRight() == null)
|
||||||
{
|
{
|
||||||
return I18NUtil.getMessage(
|
return I18NUtil.getMessage(
|
||||||
"system.schema_comp.diff.ref_only",
|
"system.schema_comp.diff.ref_only",
|
||||||
|
locale,
|
||||||
getLeft().getDbObject().getTypeName(),
|
getLeft().getDbObject().getTypeName(),
|
||||||
getLeft().getPath(),
|
getLeft().getPath(),
|
||||||
getLeft().getPropertyValue());
|
getLeft().getPropertyValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return I18NUtil.getMessage(
|
return I18NUtil.getMessage(
|
||||||
"system.schema_comp.diff",
|
"system.schema_comp.diff",
|
||||||
|
locale,
|
||||||
getLeft().getDbObject().getTypeName(),
|
getLeft().getDbObject().getTypeName(),
|
||||||
getLeft().getPath(),
|
getLeft().getPath(),
|
||||||
getLeft().getPropertyValue(),
|
getLeft().getPropertyValue(),
|
||||||
getRight().getPath(),
|
getRight().getPath(),
|
||||||
getRight().getPropertyValue());
|
getRight().getPropertyValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "Difference [where=" + this.where + ", left=" + this.left + ", right=" + this.right + "]";
|
return "Difference [where=" + this.where + ", left=" + this.left + ", right=" + this.right + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -25,8 +25,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.util.schemacomp;
|
package org.alfresco.util.schemacomp;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.alfresco.util.schemacomp.model.DbObject;
|
import org.alfresco.util.schemacomp.model.DbObject;
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
@@ -50,6 +51,17 @@ public class RedundantDbObject extends Result
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describe()
|
public String describe()
|
||||||
|
{
|
||||||
|
return doDescribe(I18NUtil.getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe(Locale locale)
|
||||||
|
{
|
||||||
|
return doDescribe(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String doDescribe(Locale locale)
|
||||||
{
|
{
|
||||||
if (matches.size() > SHOW_MAX_MATCHES)
|
if (matches.size() > SHOW_MAX_MATCHES)
|
||||||
{
|
{
|
||||||
@@ -66,7 +78,7 @@ public class RedundantDbObject extends Result
|
|||||||
"system.schema_comp.redundant_obj",
|
"system.schema_comp.redundant_obj",
|
||||||
matches.size(),
|
matches.size(),
|
||||||
dbObject,
|
dbObject,
|
||||||
describeMatches());
|
describeMatches());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +108,6 @@ public class RedundantDbObject extends Result
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "RedundantDbObject [dbObject=" + this.dbObject + ", matches=" + this.matches + "]";
|
return "RedundantDbObject [dbObject=" + this.dbObject + ", matches=" + this.matches + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -23,8 +23,10 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.util.schemacomp;
|
package org.alfresco.util.schemacomp;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for the result of a differencing or validation operation.
|
* Base class for the result of a differencing or validation operation.
|
||||||
*
|
*
|
||||||
@@ -42,5 +44,14 @@ public abstract class Result
|
|||||||
public String describe()
|
public String describe()
|
||||||
{
|
{
|
||||||
return toString();
|
return toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An overload of the {@link #describe()} that allows you to specify what locale
|
||||||
|
* to use for the loggable message that describes the comparison result.
|
||||||
|
*
|
||||||
|
* @param locale The locale to use for comparison description.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public abstract String describe(Locale locale);
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,6 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
|
||||||
|
|
||||||
public class SchemaDifferenceHelper
|
public class SchemaDifferenceHelper
|
||||||
{
|
{
|
||||||
@@ -76,9 +75,9 @@ public class SchemaDifferenceHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String findPatchCausingDifference(Difference difference)
|
public String findPatchCausingDifference(Result result)
|
||||||
{
|
{
|
||||||
String differenceText = describe(difference);
|
String problemText = describe(result);
|
||||||
for (SchemaUpgradeScriptPatch patch : optionalUpgradePatches)
|
for (SchemaUpgradeScriptPatch patch : optionalUpgradePatches)
|
||||||
{
|
{
|
||||||
if (!isPatchApplied(patch))
|
if (!isPatchApplied(patch))
|
||||||
@@ -86,7 +85,7 @@ public class SchemaDifferenceHelper
|
|||||||
List<String> problemPatterns = getProblemsPatterns(patch);
|
List<String> problemPatterns = getProblemsPatterns(patch);
|
||||||
for (String problemPattern : problemPatterns)
|
for (String problemPattern : problemPatterns)
|
||||||
{
|
{
|
||||||
if (differenceText.matches(problemPattern))
|
if (problemText.matches(problemPattern))
|
||||||
{
|
{
|
||||||
return patch.getId();
|
return patch.getId();
|
||||||
}
|
}
|
||||||
@@ -138,34 +137,14 @@ public class SchemaDifferenceHelper
|
|||||||
return optionalProblems;
|
return optionalProblems;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String describe(Difference difference)
|
/**
|
||||||
|
* Retrieves the comparison result description message in the default system language.
|
||||||
|
*
|
||||||
|
* @param result The result of a differencing or validation operation.
|
||||||
|
* @return Comparison result description message in the default system language.
|
||||||
|
*/
|
||||||
|
protected String describe(Result result)
|
||||||
{
|
{
|
||||||
if (difference.getLeft() == null)
|
return result.describe(ENGLISH);
|
||||||
{
|
|
||||||
return I18NUtil.getMessage(
|
|
||||||
"system.schema_comp.diff.target_only",
|
|
||||||
ENGLISH,
|
|
||||||
difference.getRight().getDbObject().getTypeName(),
|
|
||||||
difference.getRight().getPath(),
|
|
||||||
difference.getRight().getPropertyValue());
|
|
||||||
}
|
|
||||||
if (difference.getRight() == null)
|
|
||||||
{
|
|
||||||
return I18NUtil.getMessage(
|
|
||||||
"system.schema_comp.diff.ref_only",
|
|
||||||
ENGLISH,
|
|
||||||
difference.getLeft().getDbObject().getTypeName(),
|
|
||||||
difference.getLeft().getPath(),
|
|
||||||
difference.getLeft().getPropertyValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return I18NUtil.getMessage(
|
|
||||||
"system.schema_comp.diff",
|
|
||||||
ENGLISH,
|
|
||||||
difference.getLeft().getDbObject().getTypeName(),
|
|
||||||
difference.getLeft().getPath(),
|
|
||||||
difference.getLeft().getPropertyValue(),
|
|
||||||
difference.getRight().getPath(),
|
|
||||||
difference.getRight().getPropertyValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.util.schemacomp;
|
package org.alfresco.util.schemacomp;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,11 +67,23 @@ public class ValidationResult extends Result
|
|||||||
@Override
|
@Override
|
||||||
public String describe()
|
public String describe()
|
||||||
{
|
{
|
||||||
return I18NUtil.getMessage(
|
return doDescribe(I18NUtil.getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe(Locale locale)
|
||||||
|
{
|
||||||
|
return doDescribe(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String doDescribe(Locale locale)
|
||||||
|
{
|
||||||
|
return I18NUtil.getMessage(
|
||||||
"system.schema_comp.validation",
|
"system.schema_comp.validation",
|
||||||
|
locale,
|
||||||
getDbProperty().getDbObject().getTypeName(),
|
getDbProperty().getDbObject().getTypeName(),
|
||||||
getDbProperty().getPath(),
|
getDbProperty().getPath(),
|
||||||
getValue(),
|
getValue(),
|
||||||
message);
|
message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +92,6 @@ public class ValidationResult extends Result
|
|||||||
*/
|
*/
|
||||||
public Object getValue()
|
public Object getValue()
|
||||||
{
|
{
|
||||||
return this.dbProperty.getPropertyValue();
|
return this.dbProperty.getPropertyValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -108,8 +108,8 @@ public class SchemaBootstrapTest
|
|||||||
int numProblems = schemaBootstrap.validateSchema(null, out);
|
int numProblems = schemaBootstrap.validateSchema(null, out);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
assertEquals(1, numProblems);
|
|
||||||
String problems = buff.toString();
|
String problems = buff.toString();
|
||||||
|
assertEquals("Expected 1 problem; but these problems were found instead: \n" + problems + "\n", 1, numProblems);
|
||||||
assertTrue("Missing optional patch-specific problems report: \n" + problems,
|
assertTrue("Missing optional patch-specific problems report: \n" + problems,
|
||||||
problems.contains("The following problems will be resolved once the long running patch "
|
problems.contains("The following problems will be resolved once the long running patch "
|
||||||
+ optionalPatch.getId() + " has been run"));
|
+ optionalPatch.getId() + " has been run"));
|
||||||
|
@@ -53,6 +53,7 @@ import org.junit.Test;
|
|||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
public class SchemaDifferenceHelperUnitTest
|
public class SchemaDifferenceHelperUnitTest
|
||||||
{
|
{
|
||||||
@@ -71,6 +72,7 @@ public class SchemaDifferenceHelperUnitTest
|
|||||||
{
|
{
|
||||||
dialect = mock(Dialect.class);
|
dialect = mock(Dialect.class);
|
||||||
patchService = mock(PatchService.class);
|
patchService = mock(PatchService.class);
|
||||||
|
I18NUtil.registerResourceBundle("alfresco.messages.system-messages");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -164,32 +166,8 @@ public class SchemaDifferenceHelperUnitTest
|
|||||||
|
|
||||||
private SchemaDifferenceHelper createHelper(List<SchemaUpgradeScriptPatch> upgradePatches)
|
private SchemaDifferenceHelper createHelper(List<SchemaUpgradeScriptPatch> upgradePatches)
|
||||||
{
|
{
|
||||||
return new SchemaDifferenceHelper(dialect, patchService, upgradePatches) {
|
return new SchemaDifferenceHelper(dialect, patchService, upgradePatches)
|
||||||
@Override
|
{
|
||||||
protected String describe(Difference difference)
|
|
||||||
{
|
|
||||||
if (difference.getLeft() == null)
|
|
||||||
{
|
|
||||||
return String.format("Difference: unexpected %s found in database with path: %s",
|
|
||||||
|
|
||||||
difference.getRight().getDbObject().getTypeName(),
|
|
||||||
difference.getRight().getPath());
|
|
||||||
}
|
|
||||||
if(difference.getRight() == null)
|
|
||||||
{
|
|
||||||
return String.format("Difference: missing %s from database, expected at path: %s",
|
|
||||||
difference.getLeft().getDbObject().getTypeName(),
|
|
||||||
difference.getLeft().getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.format("Difference: expected %s %s=\"%s\", but was %s=\"%s\"",
|
|
||||||
difference.getLeft().getDbObject().getTypeName(),
|
|
||||||
difference.getLeft().getPath(),
|
|
||||||
difference.getLeft().getPropertyValue(),
|
|
||||||
difference.getRight().getPath(),
|
|
||||||
difference.getRight().getPropertyValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Resource getDialectResource(String resourceUrl)
|
protected Resource getDialectResource(String resourceUrl)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user