CCM NG/ccm-cms: Some bugfixes for the ContentItemManager fixing test failures
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4712 8810af33-2d31-482b-a856-94f89814c4df
parent
dc2c2ce2d2
commit
84bb34ff13
|
|
@ -863,7 +863,6 @@ public class ContentItemManager {
|
||||||
|
|
||||||
if (isLive(item)) {
|
if (isLive(item)) {
|
||||||
liveItem = getLiveVersion(item, ContentItem.class).get();
|
liveItem = getLiveVersion(item, ContentItem.class).get();
|
||||||
// unpublish(oldLiveItem);
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
liveItem = draftItem.getClass().newInstance();
|
liveItem = draftItem.getClass().newInstance();
|
||||||
|
|
@ -872,7 +871,6 @@ public class ContentItemManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
liveItem.setVersion(ContentItemVersion.PUBLISHING);
|
|
||||||
liveItem.setItemUuid(draftItem.getItemUuid());
|
liveItem.setItemUuid(draftItem.getItemUuid());
|
||||||
liveItem.setContentType(draftItem.getContentType());
|
liveItem.setContentType(draftItem.getContentType());
|
||||||
|
|
||||||
|
|
@ -882,101 +880,6 @@ public class ContentItemManager {
|
||||||
liveItem.setLifecycle(lifecycle);
|
liveItem.setLifecycle(lifecycle);
|
||||||
liveItem.setWorkflow(draftItem.getWorkflow());
|
liveItem.setWorkflow(draftItem.getWorkflow());
|
||||||
|
|
||||||
contentItemRepo.save(liveItem);
|
|
||||||
|
|
||||||
final List<Category> oldCategories = liveItem
|
|
||||||
.getCategories()
|
|
||||||
.stream()
|
|
||||||
.map(categorization -> categorization.getCategory())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
oldCategories.forEach(category -> {
|
|
||||||
try {
|
|
||||||
categoryManager.removeObjectFromCategory(liveItem, category);
|
|
||||||
} catch (ObjectNotAssignedToCategoryException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
contentItemRepo.save(liveItem);
|
|
||||||
|
|
||||||
draftItem.getCategories().forEach(categorization -> categoryManager
|
|
||||||
.addObjectToCategory(liveItem,
|
|
||||||
categorization.getCategory(),
|
|
||||||
categorization.getType()));
|
|
||||||
|
|
||||||
contentItemRepo.save(liveItem);
|
|
||||||
|
|
||||||
for (int i = 0; i < draftItem.getAttachments().size(); i++) {
|
|
||||||
final AttachmentList sourceList = draftItem.getAttachments().get(i);
|
|
||||||
|
|
||||||
final AttachmentList targetList;
|
|
||||||
if (liveItem.getAttachments().size() < i + 1) {
|
|
||||||
targetList = new AttachmentList();
|
|
||||||
copyLocalizedString(sourceList.getDescription(),
|
|
||||||
targetList.getDescription());
|
|
||||||
|
|
||||||
targetList.setItem(liveItem);
|
|
||||||
liveItem.addAttachmentList(targetList);
|
|
||||||
targetList.setName(sourceList.getName());
|
|
||||||
copyLocalizedString(sourceList.getTitle(),
|
|
||||||
targetList.getTitle());
|
|
||||||
targetList.setOrder(sourceList.getOrder());
|
|
||||||
targetList.setUuid(UUID.randomUUID().toString());
|
|
||||||
} else {
|
|
||||||
targetList = liveItem.getAttachments().get(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 0; j < sourceList.getAttachments().size(); j++) {
|
|
||||||
final ItemAttachment<?> sourceAttachment = sourceList.
|
|
||||||
getAttachments().get(j);
|
|
||||||
final ItemAttachment<Asset> targetAttachment;
|
|
||||||
if (targetList.getAttachments().size() < j + 1) {
|
|
||||||
targetAttachment = new ItemAttachment<>();
|
|
||||||
} else {
|
|
||||||
targetAttachment = (ItemAttachment<Asset>) targetList.
|
|
||||||
getAttachments().get(j);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sourceAttachment.getAsset().equals(targetAttachment)) {
|
|
||||||
final Asset oldTargetAsset = targetAttachment.getAsset();
|
|
||||||
if (oldTargetAsset != null
|
|
||||||
&& !assetManager.isShared(oldTargetAsset)) {
|
|
||||||
targetAttachment.setAsset(null);
|
|
||||||
oldTargetAsset.removeItemAttachment(targetAttachment);
|
|
||||||
entityManager.remove(oldTargetAsset);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Asset sourceAsset = sourceAttachment.getAsset();
|
|
||||||
final Asset targetAsset;
|
|
||||||
if (assetManager.isShared(sourceAttachment.getAsset())) {
|
|
||||||
targetAsset = sourceAttachment.getAsset();
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
targetAsset = sourceAttachment.getAsset().getClass()
|
|
||||||
.newInstance();
|
|
||||||
} catch (InstantiationException | IllegalAccessException ex) {
|
|
||||||
throw new UnexpectedErrorException(ex);
|
|
||||||
}
|
|
||||||
copyAsset(sourceAsset, targetAsset);
|
|
||||||
|
|
||||||
entityManager.persist(targetAsset);
|
|
||||||
}
|
|
||||||
|
|
||||||
targetAttachment.setAsset(targetAsset);
|
|
||||||
targetAttachment.setAttachmentList(targetList);
|
|
||||||
targetAttachment.setSortKey(sourceAttachment.getSortKey());
|
|
||||||
targetAttachment.setUuid(UUID.randomUUID().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
targetList.addAttachment(targetAttachment);
|
|
||||||
|
|
||||||
entityManager.persist(targetAttachment);
|
|
||||||
entityManager.merge(targetList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
contentItemRepo.save(liveItem);
|
|
||||||
|
|
||||||
final BeanInfo beanInfo;
|
final BeanInfo beanInfo;
|
||||||
try {
|
try {
|
||||||
beanInfo = Introspector.getBeanInfo(item.getClass());
|
beanInfo = Introspector.getBeanInfo(item.getClass());
|
||||||
|
|
@ -1098,6 +1001,93 @@ public class ContentItemManager {
|
||||||
liveItem.setVersion(ContentItemVersion.LIVE);
|
liveItem.setVersion(ContentItemVersion.LIVE);
|
||||||
contentItemRepo.save(liveItem);
|
contentItemRepo.save(liveItem);
|
||||||
|
|
||||||
|
final List<Category> oldCategories = liveItem
|
||||||
|
.getCategories()
|
||||||
|
.stream()
|
||||||
|
.map(categorization -> categorization.getCategory())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
oldCategories.forEach(category -> {
|
||||||
|
try {
|
||||||
|
categoryManager.removeObjectFromCategory(liveItem, category);
|
||||||
|
} catch (ObjectNotAssignedToCategoryException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
draftItem.getCategories().forEach(categorization -> categoryManager
|
||||||
|
.addObjectToCategory(liveItem,
|
||||||
|
categorization.getCategory(),
|
||||||
|
categorization.getType()));
|
||||||
|
|
||||||
|
for (int i = 0; i < draftItem.getAttachments().size(); i++) {
|
||||||
|
final AttachmentList sourceList = draftItem.getAttachments().get(i);
|
||||||
|
|
||||||
|
final AttachmentList targetList;
|
||||||
|
if (liveItem.getAttachments().size() < i + 1) {
|
||||||
|
targetList = new AttachmentList();
|
||||||
|
copyLocalizedString(sourceList.getDescription(),
|
||||||
|
targetList.getDescription());
|
||||||
|
|
||||||
|
targetList.setItem(liveItem);
|
||||||
|
liveItem.addAttachmentList(targetList);
|
||||||
|
targetList.setName(sourceList.getName());
|
||||||
|
copyLocalizedString(sourceList.getTitle(),
|
||||||
|
targetList.getTitle());
|
||||||
|
targetList.setOrder(sourceList.getOrder());
|
||||||
|
targetList.setUuid(UUID.randomUUID().toString());
|
||||||
|
} else {
|
||||||
|
targetList = liveItem.getAttachments().get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < sourceList.getAttachments().size(); j++) {
|
||||||
|
final ItemAttachment<?> sourceAttachment = sourceList.
|
||||||
|
getAttachments().get(j);
|
||||||
|
final ItemAttachment<Asset> targetAttachment;
|
||||||
|
if (targetList.getAttachments().size() < j + 1) {
|
||||||
|
targetAttachment = new ItemAttachment<>();
|
||||||
|
} else {
|
||||||
|
targetAttachment = (ItemAttachment<Asset>) targetList.
|
||||||
|
getAttachments().get(j);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sourceAttachment.getAsset().equals(targetAttachment)) {
|
||||||
|
final Asset oldTargetAsset = targetAttachment.getAsset();
|
||||||
|
if (oldTargetAsset != null
|
||||||
|
&& !assetManager.isShared(oldTargetAsset)) {
|
||||||
|
targetAttachment.setAsset(null);
|
||||||
|
oldTargetAsset.removeItemAttachment(targetAttachment);
|
||||||
|
entityManager.remove(oldTargetAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Asset sourceAsset = sourceAttachment.getAsset();
|
||||||
|
final Asset targetAsset;
|
||||||
|
if (assetManager.isShared(sourceAttachment.getAsset())) {
|
||||||
|
targetAsset = sourceAttachment.getAsset();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
targetAsset = sourceAttachment.getAsset().getClass()
|
||||||
|
.newInstance();
|
||||||
|
} catch (InstantiationException | IllegalAccessException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
copyAsset(sourceAsset, targetAsset);
|
||||||
|
|
||||||
|
entityManager.persist(targetAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
targetAttachment.setAsset(targetAsset);
|
||||||
|
targetAttachment.setAttachmentList(targetList);
|
||||||
|
targetAttachment.setSortKey(sourceAttachment.getSortKey());
|
||||||
|
targetAttachment.setUuid(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
targetList.addAttachment(targetAttachment);
|
||||||
|
|
||||||
|
entityManager.persist(targetAttachment);
|
||||||
|
entityManager.merge(targetList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return liveItem;
|
return liveItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -629,7 +629,7 @@
|
||||||
<ccm_core.categorizations categorization_id="-30200"
|
<ccm_core.categorizations categorization_id="-30200"
|
||||||
category_id="-2100"
|
category_id="-2100"
|
||||||
object_id="-10200"
|
object_id="-10200"
|
||||||
category_order="2"
|
category_order="1"
|
||||||
object_order="2"
|
object_order="2"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue