CCM NG: Fixed several test failures due to recent changes.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4594 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
2b414205ae
commit
e525d974bb
|
|
@ -71,95 +71,95 @@ import static org.librecms.CmsConstants.*;
|
||||||
//@Indexed
|
//@Indexed
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.findById",
|
name = "ContentItem.findById",
|
||||||
query = "SELECT i FROM ContentItem i "
|
query = "SELECT i FROM ContentItem i "
|
||||||
+ "WHERE i.objectId = :objectId "
|
+ "WHERE i.objectId = :objectId "
|
||||||
+ "AND (EXISTS(SELECT p FROM Permission p "
|
+ "AND (EXISTS(SELECT p FROM Permission p "
|
||||||
+ "WHERE p.grantedPrivilege = 'read' "
|
+ "WHERE p.grantedPrivilege = 'read' "
|
||||||
+ "AND p.grantee IN :roles "
|
+ "AND p.grantee IN :roles "
|
||||||
+ "AND p.object = i)"
|
+ "AND p.object = i)"
|
||||||
+ "OR true = :admin)")
|
+ "OR true = :admin)")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.findByType",
|
name = "ContentItem.findByType",
|
||||||
query = "SELECT i FROM ContentItem i WHERE TYPE(i) = :type")
|
query = "SELECT i FROM ContentItem i WHERE TYPE(i) = :type")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.findByFolder",
|
name = "ContentItem.findByFolder",
|
||||||
query = "SELECT i FROM ContentItem i "
|
query = "SELECT i FROM ContentItem i "
|
||||||
+ "JOIN i.categories c "
|
+ "JOIN i.categories c "
|
||||||
+ "WHERE c.category = :folder "
|
+ "WHERE c.category = :folder "
|
||||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
||||||
+ "'")
|
+ "'")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.countItemsInFolder",
|
name = "ContentItem.countItemsInFolder",
|
||||||
query = "SELECT count(i) FROM ContentItem i "
|
query = "SELECT count(i) FROM ContentItem i "
|
||||||
+ "JOIN i.categories c "
|
+ "JOIN i.categories c "
|
||||||
+ "WHERE c.category = :folder "
|
+ "WHERE c.category = :folder "
|
||||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
||||||
+ "'")
|
+ "'")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.findByNameInFolder",
|
name = "ContentItem.findByNameInFolder",
|
||||||
query = "SELECT i FROM ContentItem i "
|
query = "SELECT i FROM ContentItem i "
|
||||||
+ "JOIN i.categories c "
|
+ "JOIN i.categories c "
|
||||||
+ "WHERE c.category = :folder "
|
+ "WHERE c.category = :folder "
|
||||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
||||||
+ "' "
|
+ "' "
|
||||||
+ "AND i.displayName = :name")
|
+ "AND i.displayName = :name")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.countByNameInFolder",
|
name = "ContentItem.countByNameInFolder",
|
||||||
query = "SELECT COUNT(i) FROM ContentItem i "
|
query = "SELECT COUNT(i) FROM ContentItem i "
|
||||||
+ "JOIN i.categories c "
|
+ "JOIN i.categories c "
|
||||||
+ "WHERE c.category = :folder "
|
+ "WHERE c.category = :folder "
|
||||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
||||||
+ "' "
|
+ "' "
|
||||||
+ "AND i.displayName = :name")
|
+ "AND i.displayName = :name")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.filterByFolderAndName",
|
name = "ContentItem.filterByFolderAndName",
|
||||||
query = "SELECT i FROM ContentItem i "
|
query = "SELECT i FROM ContentItem i "
|
||||||
+ "JOIN i.categories c "
|
+ "JOIN i.categories c "
|
||||||
+ "WHERE c.category = :folder "
|
+ "WHERE c.category = :folder "
|
||||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
||||||
+ "' "
|
+ "' "
|
||||||
+ "AND LOWER(i.displayName) LIKE CONCAT(LOWER(:name), '%')")
|
+ "AND LOWER(i.displayName) LIKE CONCAT(LOWER(:name), '%')")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.countFilterByFolderAndName",
|
name = "ContentItem.countFilterByFolderAndName",
|
||||||
query = "SELECT COUNT(i) FROM ContentItem i "
|
query = "SELECT COUNT(i) FROM ContentItem i "
|
||||||
+ "JOIN i.categories c "
|
+ "JOIN i.categories c "
|
||||||
+ "WHERE c.category = :folder "
|
+ "WHERE c.category = :folder "
|
||||||
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
|
||||||
+ "' "
|
+ "' "
|
||||||
+ "AND LOWER(i.displayName) LIKE CONCAT(LOWER(:name), '%')"
|
+ "AND LOWER(i.displayName) LIKE CONCAT(LOWER(:name), '%')"
|
||||||
)
|
)
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.hasLiveVersion",
|
name = "ContentItem.hasLiveVersion",
|
||||||
query = "SELECT (CASE WHEN COUNT(i) > 0 THEN true ELSE false END) "
|
query = "SELECT (CASE WHEN COUNT(i) > 0 THEN true ELSE false END) "
|
||||||
+ "FROM ContentItem i "
|
+ "FROM ContentItem i "
|
||||||
+ "WHERE i.itemUuid = :uuid "
|
+ "WHERE i.itemUuid = :uuid "
|
||||||
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE")
|
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.findDraftVersion",
|
name = "ContentItem.findDraftVersion",
|
||||||
query = "SELECT i FROM ContentItem i "
|
query = "SELECT i FROM ContentItem i "
|
||||||
+ "WHERE i.itemUuid = :uuid "
|
+ "WHERE i.itemUuid = :uuid "
|
||||||
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.DRAFT")
|
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.DRAFT")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.findLiveVersion",
|
name = "ContentItem.findLiveVersion",
|
||||||
query = "SELECT i FROM ContentItem i "
|
query = "SELECT i FROM ContentItem i "
|
||||||
+ "WHERE i.itemUuid = :uuid "
|
+ "WHERE i.itemUuid = :uuid "
|
||||||
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE")
|
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE")
|
||||||
,
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ContentItem.findItemWithWorkflow",
|
name = "ContentItem.findItemWithWorkflow",
|
||||||
query = "SELECT i FROM ContentItem i "
|
query = "SELECT i FROM ContentItem i "
|
||||||
+ "WHERE i.workflow = :workflow"
|
+ "WHERE i.workflow = :workflow"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
public class ContentItem extends CcmObject implements Serializable {
|
public class ContentItem extends CcmObject implements Serializable {
|
||||||
|
|
@ -178,13 +178,13 @@ public class ContentItem extends CcmObject implements Serializable {
|
||||||
*/
|
*/
|
||||||
@Embedded
|
@Embedded
|
||||||
@AssociationOverride(
|
@AssociationOverride(
|
||||||
name = "values",
|
name = "values",
|
||||||
joinTable = @JoinTable(name = "CONTENT_ITEM_NAMES",
|
joinTable = @JoinTable(name = "CONTENT_ITEM_NAMES",
|
||||||
schema = DB_SCHEMA,
|
schema = DB_SCHEMA,
|
||||||
joinColumns = {
|
joinColumns = {
|
||||||
@JoinColumn(name = "OBJECT_ID")
|
@JoinColumn(name = "OBJECT_ID")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
// @Field
|
// @Field
|
||||||
private LocalizedString name;
|
private LocalizedString name;
|
||||||
|
|
@ -203,13 +203,13 @@ public class ContentItem extends CcmObject implements Serializable {
|
||||||
*/
|
*/
|
||||||
@Embedded
|
@Embedded
|
||||||
@AssociationOverride(
|
@AssociationOverride(
|
||||||
name = "values",
|
name = "values",
|
||||||
joinTable = @JoinTable(name = "CONTENT_ITEM_TITLES",
|
joinTable = @JoinTable(name = "CONTENT_ITEM_TITLES",
|
||||||
schema = DB_SCHEMA,
|
schema = DB_SCHEMA,
|
||||||
joinColumns = {
|
joinColumns = {
|
||||||
@JoinColumn(name = "OBJECT_ID")
|
@JoinColumn(name = "OBJECT_ID")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@IndexedEmbedded
|
@IndexedEmbedded
|
||||||
private LocalizedString title;
|
private LocalizedString title;
|
||||||
|
|
@ -219,12 +219,12 @@ public class ContentItem extends CcmObject implements Serializable {
|
||||||
*/
|
*/
|
||||||
@Embedded
|
@Embedded
|
||||||
@AssociationOverride(
|
@AssociationOverride(
|
||||||
name = "values",
|
name = "values",
|
||||||
joinTable = @JoinTable(name = "CONTENT_ITEM_DESCRIPTIONS",
|
joinTable = @JoinTable(name = "CONTENT_ITEM_DESCRIPTIONS",
|
||||||
schema = DB_SCHEMA,
|
schema = DB_SCHEMA,
|
||||||
joinColumns = {
|
joinColumns = {
|
||||||
@JoinColumn(name = "OBJECT_ID")}
|
@JoinColumn(name = "OBJECT_ID")}
|
||||||
))
|
))
|
||||||
@IndexedEmbedded
|
@IndexedEmbedded
|
||||||
private LocalizedString description;
|
private LocalizedString description;
|
||||||
|
|
||||||
|
|
@ -432,19 +432,35 @@ public class ContentItem extends CcmObject implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreationDate() {
|
public Date getCreationDate() {
|
||||||
return new Date(creationDate.getTime());
|
if (creationDate == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return new Date(creationDate.getTime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreationDate(final Date creationDate) {
|
public void setCreationDate(final Date creationDate) {
|
||||||
this.creationDate = new Date(creationDate.getTime());
|
if (creationDate == null) {
|
||||||
|
this.creationDate = null;
|
||||||
|
} else {
|
||||||
|
this.creationDate = new Date(creationDate.getTime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastModified() {
|
public Date getLastModified() {
|
||||||
return new Date(lastModified.getTime());
|
if (lastModified == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return new Date(lastModified.getTime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastModified(final Date lastModified) {
|
public void setLastModified(final Date lastModified) {
|
||||||
this.lastModified = new Date(lastModified.getTime());
|
if (lastModified == null) {
|
||||||
|
this.lastModified = null;
|
||||||
|
} else {
|
||||||
|
this.lastModified = new Date(lastModified.getTime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreationUserName() {
|
public String getCreationUserName() {
|
||||||
|
|
@ -533,15 +549,15 @@ public class ContentItem extends CcmObject implements Serializable {
|
||||||
@Override
|
@Override
|
||||||
public String toString(final String data) {
|
public String toString(final String data) {
|
||||||
return super.toString(String.format(", itemUuid = %s, "
|
return super.toString(String.format(", itemUuid = %s, "
|
||||||
+ "name = %s, "
|
+ "name = %s, "
|
||||||
// + "contentType = { %s }, "
|
// + "contentType = { %s }, "
|
||||||
+ "title = %s, "
|
+ "title = %s, "
|
||||||
+ "description = %s, "
|
+ "description = %s, "
|
||||||
+ "version = %s, "
|
+ "version = %s, "
|
||||||
+ "launchDate = %s, "
|
+ "launchDate = %s, "
|
||||||
+ "lifecycle = { %s }, "
|
+ "lifecycle = { %s }, "
|
||||||
+ "workflow = { %s }"
|
+ "workflow = { %s }"
|
||||||
+ "%s",
|
+ "%s",
|
||||||
itemUuid,
|
itemUuid,
|
||||||
Objects.toString(name),
|
Objects.toString(name),
|
||||||
// Objects.toString(contentType),
|
// Objects.toString(contentType),
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,8 @@ import javax.transaction.Transactional;
|
||||||
import org.libreccm.security.PermissionChecker;
|
import org.libreccm.security.PermissionChecker;
|
||||||
import org.librecms.contentsection.privileges.TypePrivileges;
|
import org.librecms.contentsection.privileges.TypePrivileges;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager class providing several methods to manipulate {@link ContentItem}s.
|
* Manager class providing several methods to manipulate {@link ContentItem}s.
|
||||||
*
|
*
|
||||||
|
|
@ -389,6 +391,9 @@ public class ContentItemManager {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// final String uuid = UUID.randomUUID().toString();
|
||||||
|
// copy.setUuid(uuid);
|
||||||
|
// copy.setItemUuid(uuid);
|
||||||
copy.setContentType(contentType.get());
|
copy.setContentType(contentType.get());
|
||||||
|
|
||||||
if (draftItem.getWorkflow() != null) {
|
if (draftItem.getWorkflow() != null) {
|
||||||
|
|
@ -399,26 +404,6 @@ public class ContentItemManager {
|
||||||
copy.setWorkflow(copyWorkflow);
|
copy.setWorkflow(copyWorkflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
contentItemRepo.save(copy);
|
|
||||||
|
|
||||||
draftItem.getCategories().forEach(categorization -> categoryManager
|
|
||||||
.addObjectToCategory(copy, categorization.getCategory()));
|
|
||||||
|
|
||||||
final Optional<Folder> itemFolder = getItemFolder(draftItem);
|
|
||||||
if (itemFolder.isPresent()) {
|
|
||||||
try {
|
|
||||||
categoryManager.removeObjectFromCategory(
|
|
||||||
copy, getItemFolder(draftItem).get());
|
|
||||||
} catch (ObjectNotAssignedToCategoryException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
categoryManager.addObjectToCategory(
|
|
||||||
copy,
|
|
||||||
targetFolder,
|
|
||||||
CATEGORIZATION_TYPE_FOLDER);
|
|
||||||
|
|
||||||
for (AttachmentList attachmentList : item.getAttachments()) {
|
for (AttachmentList attachmentList : item.getAttachments()) {
|
||||||
copyAttachmentList(attachmentList, copy);
|
copyAttachmentList(attachmentList, copy);
|
||||||
}
|
}
|
||||||
|
|
@ -536,6 +521,24 @@ public class ContentItemManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentItemRepo.save(copy);
|
||||||
|
|
||||||
|
draftItem.getCategories().forEach(categorization -> categoryManager
|
||||||
|
.addObjectToCategory(copy, categorization.getCategory()));
|
||||||
|
final Optional<Folder> itemFolder = getItemFolder(draftItem);
|
||||||
|
if (itemFolder.isPresent()) {
|
||||||
|
try {
|
||||||
|
categoryManager.removeObjectFromCategory(
|
||||||
|
copy, getItemFolder(draftItem).get());
|
||||||
|
} catch (ObjectNotAssignedToCategoryException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
categoryManager.addObjectToCategory(
|
||||||
|
copy,
|
||||||
|
targetFolder,
|
||||||
|
CATEGORIZATION_TYPE_FOLDER);
|
||||||
|
|
||||||
if (targetFolder.equals(getItemFolder(item).orElse(null))) {
|
if (targetFolder.equals(getItemFolder(item).orElse(null))) {
|
||||||
final long number = contentItemRepo.countFilterByFolderAndName(
|
final long number = contentItemRepo.countFilterByFolderAndName(
|
||||||
targetFolder, String.format("%s_copy",
|
targetFolder, String.format("%s_copy",
|
||||||
|
|
@ -546,8 +549,6 @@ public class ContentItemManager {
|
||||||
index));
|
index));
|
||||||
}
|
}
|
||||||
|
|
||||||
contentItemRepo.save(copy);
|
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,10 @@ public class ContentItemRepository
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private FolderRepository folderRepo;
|
private FolderRepository folderRepo;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ContentItemManager itemManager;
|
private ContentItemManager itemManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private CategoryManager categoryManager;
|
private CategoryManager categoryManager;
|
||||||
|
|
||||||
|
|
@ -372,7 +372,12 @@ public class ContentItemRepository
|
||||||
public void save(final ContentItem item) {
|
public void save(final ContentItem item) {
|
||||||
final Date now = new Date();
|
final Date now = new Date();
|
||||||
final Subject subject = shiro.getSubject();
|
final Subject subject = shiro.getSubject();
|
||||||
final String userName = subject.getPrincipal().toString();
|
final String userName;
|
||||||
|
if (subject == null || subject.getPrincipal() == null) {
|
||||||
|
userName = "";
|
||||||
|
} else {
|
||||||
|
userName = subject.getPrincipal().toString();
|
||||||
|
}
|
||||||
|
|
||||||
if (isNew(item)) {
|
if (isNew(item)) {
|
||||||
item.setCreationDate(now);
|
item.setCreationDate(now);
|
||||||
|
|
@ -383,7 +388,7 @@ public class ContentItemRepository
|
||||||
|
|
||||||
super.save(item);
|
super.save(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
@Override
|
@Override
|
||||||
public void delete(final ContentItem item) {
|
public void delete(final ContentItem item) {
|
||||||
|
|
@ -393,27 +398,26 @@ public class ContentItemRepository
|
||||||
+ "is live.",
|
+ "is live.",
|
||||||
item.getItemUuid()));
|
item.getItemUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
final ContentItem draft = itemManager.getDraftVersion(item,
|
final ContentItem draft = itemManager.getDraftVersion(item,
|
||||||
ContentItem.class);
|
ContentItem.class);
|
||||||
// draft.getCategories().stream()
|
// draft.getCategories().stream()
|
||||||
// .map(categorization -> categorization.getCategory())
|
// .map(categorization -> categorization.getCategory())
|
||||||
// .forEach(category -> removeCategoryFromItem(item, category));
|
// .forEach(category -> removeCategoryFromItem(item, category));
|
||||||
for(final Categorization categorization : draft.getCategories()) {
|
for (final Categorization categorization : draft.getCategories()) {
|
||||||
final Category category = categorization.getCategory();
|
final Category category = categorization.getCategory();
|
||||||
|
|
||||||
removeCategoryFromItem(item, category);
|
removeCategoryFromItem(item, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
super.delete(draft);
|
super.delete(draft);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeCategoryFromItem(final ContentItem item,
|
private void removeCategoryFromItem(final ContentItem item,
|
||||||
final Category category) {
|
final Category category) {
|
||||||
try {
|
try {
|
||||||
categoryManager.removeObjectFromCategory(item, category);
|
categoryManager.removeObjectFromCategory(item, category);
|
||||||
} catch(ObjectNotAssignedToCategoryException ex) {
|
} catch (ObjectNotAssignedToCategoryException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,8 @@ public class ContentItemRepositoryTest {
|
||||||
.addAsLibraries(getCcmCoreDependencies())
|
.addAsLibraries(getCcmCoreDependencies())
|
||||||
.addAsResource("test-persistence.xml",
|
.addAsResource("test-persistence.xml",
|
||||||
"META-INF/persistence.xml")
|
"META-INF/persistence.xml")
|
||||||
.addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
|
.addAsResource("configs/shiro.ini", "shiro.ini")
|
||||||
|
.addAsWebInfResource("test-web.xml", "web.xml")
|
||||||
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
|
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -514,7 +514,7 @@
|
||||||
<ccm_core.categorizations categorization_id="-30400"
|
<ccm_core.categorizations categorization_id="-30400"
|
||||||
category_id="-1600"
|
category_id="-1600"
|
||||||
object_id="-900"
|
object_id="-900"
|
||||||
category_order="1"
|
category_order="2"
|
||||||
object_order="4"
|
object_order="4"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
|
|
@ -514,7 +514,7 @@
|
||||||
<ccm_core.categorizations categorization_id="-30400"
|
<ccm_core.categorizations categorization_id="-30400"
|
||||||
category_id="-410"
|
category_id="-410"
|
||||||
object_id="-900"
|
object_id="-900"
|
||||||
category_order="1"
|
category_order="2"
|
||||||
object_order="4"
|
object_order="4"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
|
|
@ -682,7 +682,7 @@
|
||||||
<ccm_core.categorizations categorization_id="-30110"
|
<ccm_core.categorizations categorization_id="-30110"
|
||||||
category_id="-2300"
|
category_id="-2300"
|
||||||
object_id="-10110"
|
object_id="-10110"
|
||||||
category_order="1"
|
category_order="2"
|
||||||
object_order="1"
|
object_order="1"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
|
|
@ -676,7 +676,7 @@
|
||||||
<ccm_core.categorizations categorization_id="-30500"
|
<ccm_core.categorizations categorization_id="-30500"
|
||||||
category_id="-2120"
|
category_id="-2120"
|
||||||
object_id="-10500"
|
object_id="-10500"
|
||||||
category_order="1"
|
category_order="2"
|
||||||
object_order="1"
|
object_order="1"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
|
|
@ -647,7 +647,7 @@
|
||||||
<ccm_core.categorizations categorization_id="-30100"
|
<ccm_core.categorizations categorization_id="-30100"
|
||||||
category_id="-2110"
|
category_id="-2110"
|
||||||
object_id="-10100"
|
object_id="-10100"
|
||||||
category_order="1"
|
category_order="2"
|
||||||
object_order="1"
|
object_order="1"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
|
|
@ -566,7 +566,7 @@
|
||||||
<ccm_core.categorizations categorization_id="-30100"
|
<ccm_core.categorizations categorization_id="-30100"
|
||||||
category_id="-2300"
|
category_id="-2300"
|
||||||
object_id="-10100"
|
object_id="-10100"
|
||||||
category_order="1"
|
category_order="2"
|
||||||
object_order="1"
|
object_order="1"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
|
|
@ -567,7 +567,7 @@
|
||||||
<ccm_core.categorizations categorization_id="-30100"
|
<ccm_core.categorizations categorization_id="-30100"
|
||||||
category_id="-2120"
|
category_id="-2120"
|
||||||
object_id="-10100"
|
object_id="-10100"
|
||||||
category_order="1"
|
category_order="2"
|
||||||
object_order="1"
|
object_order="1"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
|
|
@ -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="1"
|
category_order="2"
|
||||||
object_order="2"
|
object_order="2"
|
||||||
category_index="false"
|
category_index="false"
|
||||||
type="folder" />
|
type="folder" />
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ package org.libreccm.auditing;
|
||||||
|
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.subject.Subject;
|
||||||
|
|
||||||
|
|
||||||
import org.hibernate.envers.RevisionListener;
|
import org.hibernate.envers.RevisionListener;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.security.Shiro;
|
import org.libreccm.security.Shiro;
|
||||||
|
|
@ -46,7 +45,11 @@ public class CcmRevisionListener implements RevisionListener {
|
||||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
||||||
|
|
||||||
final Subject subject = shiro.getSubject();
|
final Subject subject = shiro.getSubject();
|
||||||
revision.setUserName(subject.getPrincipal().toString());
|
if (subject == null || subject.getPrincipal() == null) {
|
||||||
|
revision.setUserName("");
|
||||||
|
} else {
|
||||||
|
revision.setUserName(subject.getPrincipal().toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ public class CategoryManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSubCategories(final Category category) {
|
public boolean hasSubCategories(final Category category) {
|
||||||
|
|
||||||
Objects.requireNonNull(
|
Objects.requireNonNull(
|
||||||
category,
|
category,
|
||||||
"Can't determine if Category null has sub categories.");
|
"Can't determine if Category null has sub categories.");
|
||||||
|
|
@ -167,22 +167,22 @@ public class CategoryManager {
|
||||||
final TypedQuery<Boolean> query = entityManager.createNamedQuery(
|
final TypedQuery<Boolean> query = entityManager.createNamedQuery(
|
||||||
"Category.hasSubCategories", Boolean.class);
|
"Category.hasSubCategories", Boolean.class);
|
||||||
query.setParameter("category", category);
|
query.setParameter("category", category);
|
||||||
|
|
||||||
return query.getSingleResult();
|
return query.getSingleResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasObjects(final Category category) {
|
public boolean hasObjects(final Category category) {
|
||||||
|
|
||||||
Objects.requireNonNull(category,
|
Objects.requireNonNull(category,
|
||||||
"Can't determine if category null has objects.");
|
"Can't determine if category null has objects.");
|
||||||
|
|
||||||
final TypedQuery<Boolean> query = entityManager.createNamedQuery(
|
final TypedQuery<Boolean> query = entityManager.createNamedQuery(
|
||||||
"Category.hasObjects", Boolean.class);
|
"Category.hasObjects", Boolean.class);
|
||||||
query.setParameter("category", category);
|
query.setParameter("category", category);
|
||||||
|
|
||||||
return query.getSingleResult();
|
return query.getSingleResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an object is assigned to a category.
|
* Check if an object is assigned to a category.
|
||||||
*
|
*
|
||||||
|
|
@ -277,9 +277,9 @@ public class CategoryManager {
|
||||||
query.setParameter("category", category);
|
query.setParameter("category", category);
|
||||||
query.setParameter("object", object);
|
query.setParameter("object", object);
|
||||||
|
|
||||||
final Categorization categorization;
|
final List<Categorization> categorizations;
|
||||||
try {
|
try {
|
||||||
categorization = query.getSingleResult();
|
categorizations = query.getResultList();
|
||||||
} catch (NoResultException ex) {
|
} catch (NoResultException ex) {
|
||||||
LOGGER.warn(String.format(
|
LOGGER.warn(String.format(
|
||||||
"No categorization for category %s and object %s found."
|
"No categorization for category %s and object %s found."
|
||||||
|
|
@ -289,8 +289,8 @@ public class CategoryManager {
|
||||||
ex);
|
ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
entityManager.remove(categorization);
|
categorizations.forEach(entityManager::remove);
|
||||||
|
|
||||||
// shiro.getSystemUser().execute(() -> {
|
// shiro.getSystemUser().execute(() -> {
|
||||||
// object.removeCategory(categorization);
|
// object.removeCategory(categorization);
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ import org.jboss.arquillian.persistence.TestExecutionPhase;
|
||||||
@PersistenceTest
|
@PersistenceTest
|
||||||
@Transactional(TransactionMode.COMMIT)
|
@Transactional(TransactionMode.COMMIT)
|
||||||
@CreateSchema({"create_ccm_core_schema.sql"})
|
@CreateSchema({"create_ccm_core_schema.sql"})
|
||||||
@CleanupUsingScript(value = {"cleanup.sql"},
|
@CleanupUsingScript(value = {"cleanup.sql"},
|
||||||
phase = TestExecutionPhase.BEFORE)
|
phase = TestExecutionPhase.BEFORE)
|
||||||
public class CcmObjectRepositoryTest {
|
public class CcmObjectRepositoryTest {
|
||||||
|
|
||||||
|
|
@ -100,33 +100,43 @@ public class CcmObjectRepositoryTest {
|
||||||
@Deployment
|
@Deployment
|
||||||
public static WebArchive createDeployment() {
|
public static WebArchive createDeployment() {
|
||||||
return ShrinkWrap
|
return ShrinkWrap
|
||||||
.create(WebArchive.class,
|
.create(WebArchive.class,
|
||||||
"LibreCCM-org.libreccm.core.CcmObjectRepositoryTest.war").
|
"LibreCCM-org.libreccm.core.CcmObjectRepositoryTest.war")
|
||||||
addPackage(org.libreccm.auditing.CcmRevision.class.getPackage())
|
.addPackage(org.libreccm.auditing.CcmRevision.class.getPackage())
|
||||||
.addPackage(org.libreccm.categorization.Categorization.class
|
.addPackage(org.libreccm.categorization.Categorization.class
|
||||||
.getPackage())
|
.getPackage())
|
||||||
.addPackage(org.libreccm.configuration.Configuration.class.
|
.addPackage(org.libreccm.configuration.Configuration.class.
|
||||||
getPackage())
|
getPackage())
|
||||||
.addPackage(org.libreccm.core.CcmObject.class.getPackage())
|
.addPackage(org.libreccm.core.CcmObject.class.getPackage())
|
||||||
.addPackage(org.libreccm.jpa.EntityManagerProducer.class
|
.addPackage(org.libreccm.jpa.EntityManagerProducer.class
|
||||||
.getPackage())
|
.getPackage())
|
||||||
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
|
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
|
||||||
.getPackage())
|
.getPackage())
|
||||||
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
|
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
|
||||||
addPackage(org.libreccm.security.PermissionChecker.class
|
.addClass(org.libreccm.modules.CcmModule.class)
|
||||||
.getPackage())
|
.addClass(org.libreccm.modules.ModuleEvent.class)
|
||||||
.addPackage(org.libreccm.testutils.EqualsVerifier.class.
|
.addClass(org.libreccm.modules.InitEvent.class)
|
||||||
getPackage())
|
.addClass(org.libreccm.modules.InstallEvent.class)
|
||||||
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
|
.addClass(org.libreccm.modules.UnInstallEvent.class)
|
||||||
.getPackage())
|
.addClass(org.libreccm.modules.ShutdownEvent.class)
|
||||||
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
|
.addPackage(org.libreccm.security.PermissionChecker.class
|
||||||
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
|
.getPackage())
|
||||||
.addClass(org.libreccm.portation.Portable.class)
|
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
|
||||||
.addAsLibraries(getModuleDependencies())
|
.addPackage(org.libreccm.testutils.EqualsVerifier.class.
|
||||||
.addAsResource("test-persistence.xml",
|
getPackage())
|
||||||
"META-INF/persistence.xml")
|
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
|
||||||
.addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
|
.getPackage())
|
||||||
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
|
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
|
||||||
|
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
|
||||||
|
.addClass(org.libreccm.portation.Portable.class)
|
||||||
|
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
|
||||||
|
.getPackage())
|
||||||
|
.addAsLibraries(getModuleDependencies())
|
||||||
|
.addAsResource("test-persistence.xml",
|
||||||
|
"META-INF/persistence.xml")
|
||||||
|
.addAsResource("configs/shiro.ini", "shiro.ini")
|
||||||
|
.addAsWebInfResource("test-web.xml", "web.xml")
|
||||||
|
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -163,7 +173,7 @@ public class CcmObjectRepositoryTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/"
|
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/"
|
||||||
+ "after-save-changed.yml")
|
+ "after-save-changed.yml")
|
||||||
@InSequence(4)
|
@InSequence(4)
|
||||||
public void datasetOnly2() {
|
public void datasetOnly2() {
|
||||||
System.out.println("Dataset loaded successfully.");
|
System.out.println("Dataset loaded successfully.");
|
||||||
|
|
@ -277,9 +287,9 @@ public class CcmObjectRepositoryTest {
|
||||||
@Test
|
@Test
|
||||||
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
||||||
@ShouldMatchDataSet(
|
@ShouldMatchDataSet(
|
||||||
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
|
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
|
||||||
+ "after-save-new.yml",
|
+ "after-save-new.yml",
|
||||||
excludeColumns = {"object_id", "uuid"})
|
excludeColumns = {"object_id", "uuid"})
|
||||||
@InSequence(300)
|
@InSequence(300)
|
||||||
public void saveNewCcmObject() {
|
public void saveNewCcmObject() {
|
||||||
final CcmObject obj = new CcmObject();
|
final CcmObject obj = new CcmObject();
|
||||||
|
|
@ -297,9 +307,9 @@ public class CcmObjectRepositoryTest {
|
||||||
@Test
|
@Test
|
||||||
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
||||||
@ShouldMatchDataSet(
|
@ShouldMatchDataSet(
|
||||||
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
|
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
|
||||||
+ "after-save-changed.yml",
|
+ "after-save-changed.yml",
|
||||||
excludeColumns = {"object_id"})
|
excludeColumns = {"object_id"})
|
||||||
@InSequence(400)
|
@InSequence(400)
|
||||||
public void saveChangedCcmObject() {
|
public void saveChangedCcmObject() {
|
||||||
final CcmObject obj = ccmObjectRepository.findById(-20L).get();
|
final CcmObject obj = ccmObjectRepository.findById(-20L).get();
|
||||||
|
|
@ -328,9 +338,9 @@ public class CcmObjectRepositoryTest {
|
||||||
@Test
|
@Test
|
||||||
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
||||||
@ShouldMatchDataSet(
|
@ShouldMatchDataSet(
|
||||||
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
|
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
|
||||||
+ "after-delete.yml",
|
+ "after-delete.yml",
|
||||||
excludeColumns = {"object_id"})
|
excludeColumns = {"object_id"})
|
||||||
@InSequence(600)
|
@InSequence(600)
|
||||||
public void deleteCcmObject() {
|
public void deleteCcmObject() {
|
||||||
final CcmObject obj = ccmObjectRepository.findById(-20L).get();
|
final CcmObject obj = ccmObjectRepository.findById(-20L).get();
|
||||||
|
|
@ -343,8 +353,10 @@ public class CcmObjectRepositoryTest {
|
||||||
* a {@link IllegalArgumentException} if called with {@link null} for the
|
* a {@link IllegalArgumentException} if called with {@link null} for the
|
||||||
* object to delete.
|
* object to delete.
|
||||||
*/
|
*/
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ShouldThrowException(IllegalArgumentException.class)
|
@ShouldThrowException(NullPointerException.class)
|
||||||
|
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
||||||
|
@ShouldMatchDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
||||||
@InSequence(700)
|
@InSequence(700)
|
||||||
public void deleteNullValue() {
|
public void deleteNullValue() {
|
||||||
ccmObjectRepository.delete(null);
|
ccmObjectRepository.delete(null);
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ public class PartyRepositoryTest {
|
||||||
.getPackage())
|
.getPackage())
|
||||||
.addPackage(
|
.addPackage(
|
||||||
org.libreccm.configuration.ConfigurationManager.class
|
org.libreccm.configuration.ConfigurationManager.class
|
||||||
.getPackage())
|
.getPackage())
|
||||||
.addPackage(org.libreccm.l10n.LocalizedString.class
|
.addPackage(org.libreccm.l10n.LocalizedString.class
|
||||||
.getPackage())
|
.getPackage())
|
||||||
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
|
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
|
||||||
|
|
@ -269,8 +269,11 @@ public class PartyRepositoryTest {
|
||||||
shiro.getSystemUser().execute(() -> partyRepository.delete(user));
|
shiro.getSystemUser().execute(() -> partyRepository.delete(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ShouldThrowException(IllegalArgumentException.class)
|
@ShouldThrowException(NullPointerException.class)
|
||||||
|
@UsingDataSet("datasets/org/libreccm/security/PartyRepositoryTest/data.yml")
|
||||||
|
@ShouldMatchDataSet(
|
||||||
|
"datasets/org/libreccm/security/PartyRepositoryTest/data.yml")
|
||||||
@InSequence(700)
|
@InSequence(700)
|
||||||
public void deleteNullValue() {
|
public void deleteNullValue() {
|
||||||
shiro.getSystemUser().execute(() -> partyRepository.delete(null));
|
shiro.getSystemUser().execute(() -> partyRepository.delete(null));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue