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-94f89814c4dfpull/2/head
parent
81a7484596
commit
e12c9ee66e
|
|
@ -863,7 +863,6 @@ public class ContentItemManager {
|
|||
|
||||
if (isLive(item)) {
|
||||
liveItem = getLiveVersion(item, ContentItem.class).get();
|
||||
// unpublish(oldLiveItem);
|
||||
} else {
|
||||
try {
|
||||
liveItem = draftItem.getClass().newInstance();
|
||||
|
|
@ -872,7 +871,6 @@ public class ContentItemManager {
|
|||
}
|
||||
}
|
||||
|
||||
liveItem.setVersion(ContentItemVersion.PUBLISHING);
|
||||
liveItem.setItemUuid(draftItem.getItemUuid());
|
||||
liveItem.setContentType(draftItem.getContentType());
|
||||
|
||||
|
|
@ -882,101 +880,6 @@ public class ContentItemManager {
|
|||
liveItem.setLifecycle(lifecycle);
|
||||
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;
|
||||
try {
|
||||
beanInfo = Introspector.getBeanInfo(item.getClass());
|
||||
|
|
@ -1098,6 +1001,93 @@ public class ContentItemManager {
|
|||
liveItem.setVersion(ContentItemVersion.LIVE);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -629,7 +629,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30200"
|
||||
category_id="-2100"
|
||||
object_id="-10200"
|
||||
category_order="2"
|
||||
category_order="1"
|
||||
object_order="2"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue