Improvements for ContentItemNameFix tool.
git-svn-id: https://svn.libreccm.org/ccm/trunk@3132 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
f0de90b13c
commit
e534e03cf9
|
|
@ -65,7 +65,9 @@ public class ContentItemNameFix extends Program {
|
||||||
pretend = cmdLine.hasOption("p");
|
pretend = cmdLine.hasOption("p");
|
||||||
|
|
||||||
if (pretend) {
|
if (pretend) {
|
||||||
System.out.printf("Pretend option is on, only showing what would be done...\n");
|
System.out.printf("Pretend option is on, only showing what would be done...\n\n");
|
||||||
|
} else {
|
||||||
|
System.out.print("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
new KernelExcursion() {
|
new KernelExcursion() {
|
||||||
|
|
@ -84,7 +86,7 @@ public class ContentItemNameFix extends Program {
|
||||||
draftBundles.addEqualsFilter(ContentItem.VERSION, "draft");
|
draftBundles.addEqualsFilter(ContentItem.VERSION, "draft");
|
||||||
|
|
||||||
while (draftBundles.next()) {
|
while (draftBundles.next()) {
|
||||||
checkDraftBundle(draftBundles.getDataObject());
|
checkBundle(draftBundles.getDataObject());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,62 +98,88 @@ public class ContentItemNameFix extends Program {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDraftBundle(final DataObject bundleObj) {
|
private void checkBundle(final DataObject bundleObj) {
|
||||||
|
|
||||||
final ContentBundle draftBundle = new ContentBundle(bundleObj);
|
final ContentBundle draftBundle = new ContentBundle(bundleObj);
|
||||||
final ContentItem primaryDraftItem = draftBundle.getPrimaryInstance();
|
final ContentItem primaryDraftItem = draftBundle.getPrimaryInstance();
|
||||||
|
|
||||||
//This is our reference, all bundles, instances etc belonging to the item sould have this
|
final String itemId = primaryDraftItem.getID().toString();
|
||||||
|
final String itemPath = String.format("%s:/%s",
|
||||||
|
primaryDraftItem.getContentSection().getName(),
|
||||||
|
primaryDraftItem.getPath());
|
||||||
|
|
||||||
|
final HeaderStatus headerStatus = new HeaderStatus();
|
||||||
|
|
||||||
|
//This is our reference, all bundles, instances etc belonging to the item sould have this
|
||||||
//name
|
//name
|
||||||
final String itemName = primaryDraftItem.getName();
|
final String itemName = primaryDraftItem.getName();
|
||||||
|
|
||||||
if (!draftBundle.getName().equals(itemName)) {
|
if (!draftBundle.getName().equals(itemName)) {
|
||||||
|
printItemHeaderLine(itemId, itemPath, headerStatus);
|
||||||
|
|
||||||
System.out.printf(
|
System.out.printf(
|
||||||
"ContentBundle %s for item %s has wrong name. Should be '%s' but is '%s'.",
|
"\t Draft ContentBundle has wrong name: Is '%s' but should be '%s'.",
|
||||||
draftBundle.getID().toString(),
|
|
||||||
primaryDraftItem.getID().toString(),
|
|
||||||
itemName,
|
itemName,
|
||||||
draftBundle.getName());
|
draftBundle.getName());
|
||||||
if (!pretend) {
|
if (pretend) {
|
||||||
|
System.out.print("\n");
|
||||||
|
} else {
|
||||||
draftBundle.setName(itemName);
|
draftBundle.setName(itemName);
|
||||||
System.out.printf(" Corrected.\n");
|
System.out.printf(" Corrected.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkInstances(draftBundle, itemName);
|
checkInstances(draftBundle, itemName, itemId, itemPath, headerStatus);
|
||||||
|
|
||||||
final ContentBundle liveBundle = (ContentBundle) draftBundle.getLiveVersion();
|
final ContentBundle liveBundle = (ContentBundle) draftBundle.getLiveVersion();
|
||||||
if (liveBundle != null) {
|
if (liveBundle != null) {
|
||||||
if (!liveBundle.getName().equals(itemName)) {
|
if (!liveBundle.getName().equals(itemName)) {
|
||||||
|
printItemHeaderLine(itemId, itemPath, headerStatus);
|
||||||
|
|
||||||
System.out.printf(
|
System.out.printf(
|
||||||
"Live ContentBundle '%s' has wrong name. Should be '%s' but is '%s'",
|
"\tLive ContentBundle has wrong name. Should be '%s' but is '%s'",
|
||||||
liveBundle.getID().toString(),
|
|
||||||
itemName,
|
itemName,
|
||||||
liveBundle.getName());
|
liveBundle.getName());
|
||||||
|
|
||||||
if (!pretend) {
|
if (pretend) {
|
||||||
|
System.out.print("\n");
|
||||||
|
} else {
|
||||||
liveBundle.setName(itemName);
|
liveBundle.setName(itemName);
|
||||||
System.out.printf(" Corrected.\n");
|
System.out.printf(" Corrected.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkInstances(liveBundle, itemName, itemId, itemPath, headerStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkInstances(liveBundle, itemName);
|
if (headerStatus.isHeaderPrinted()) {
|
||||||
|
System.out.print("\n");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkInstances(final ContentBundle draftBundle, final String itemName) {
|
private void checkInstances(final ContentBundle draftBundle,
|
||||||
|
final String itemName,
|
||||||
|
final String itemId,
|
||||||
|
final String itemPath,
|
||||||
|
final HeaderStatus headerStatus) {
|
||||||
final ItemCollection instances = draftBundle.getInstances();
|
final ItemCollection instances = draftBundle.getInstances();
|
||||||
ContentItem current;
|
ContentItem current;
|
||||||
while (instances.next()) {
|
while (instances.next()) {
|
||||||
current = instances.getContentItem();
|
current = instances.getContentItem();
|
||||||
|
|
||||||
if (!itemName.equals(current.getName())) {
|
if (!itemName.equals(current.getName())) {
|
||||||
System.out.printf("Item %s has wrong name. Should be '%s', but is '%s'.",
|
printItemHeaderLine(itemId, itemPath, headerStatus);
|
||||||
current.getID().toString(),
|
System.out.printf(
|
||||||
itemName,
|
"\t%s instance %s (language: %s has wrong name. Should be '%s', but is '%s'.",
|
||||||
current.getName());
|
current.getVersion(),
|
||||||
if (!pretend) {
|
current.getID().toString(),
|
||||||
|
current.getLanguage(),
|
||||||
|
itemName,
|
||||||
|
current.getName());
|
||||||
|
if (pretend) {
|
||||||
|
System.out.print("\n");
|
||||||
|
} else {
|
||||||
current.setName(itemName);
|
current.setName(itemName);
|
||||||
System.out.printf(" Corrected.\n");
|
System.out.printf(" Corrected.\n");
|
||||||
}
|
}
|
||||||
|
|
@ -160,4 +188,31 @@ public class ContentItemNameFix extends Program {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class HeaderStatus {
|
||||||
|
|
||||||
|
private boolean headerPrinted = false;
|
||||||
|
|
||||||
|
public HeaderStatus() {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHeaderPrinted() {
|
||||||
|
return headerPrinted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeaderPrinted(final boolean headerPrinted) {
|
||||||
|
this.headerPrinted = headerPrinted;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printItemHeaderLine(final String itemId,
|
||||||
|
final String itemPath,
|
||||||
|
final HeaderStatus headerStatus) {
|
||||||
|
if (!headerStatus.isHeaderPrinted()) {
|
||||||
|
System.out.printf("Problems with item %s (id: %s):\n", itemPath, itemId);
|
||||||
|
headerStatus.setHeaderPrinted(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue