From bc51fc48e43b1614353a0de15c7abdf41047f236 Mon Sep 17 00:00:00 2001 From: glend17 Date: Wed, 27 Oct 2021 12:17:55 -0700 Subject: [PATCH 001/135] [VSPC-171] Added new SpaceBlock --- .../diging/vspace/core/model/ISpaceBlock.java | 17 ++++++++++ .../vspace/core/model/impl/SpaceBlock.java | 33 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 vspace/src/main/java/edu/asu/diging/vspace/core/model/ISpaceBlock.java create mode 100644 vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/SpaceBlock.java diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISpaceBlock.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISpaceBlock.java new file mode 100644 index 000000000..d497ae463 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISpaceBlock.java @@ -0,0 +1,17 @@ +package edu.asu.diging.vspace.core.model; + +public interface ISpaceBlock { + + void setTitle(String text); + + String getTitle(); + + void setId(String id); + + String getId(); + + ISpace getSpace(); + + void setSpace(ISpace space); + +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/SpaceBlock.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/SpaceBlock.java new file mode 100644 index 000000000..c50066950 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/SpaceBlock.java @@ -0,0 +1,33 @@ +package edu.asu.diging.vspace.core.model.impl; + +import javax.persistence.ManyToOne; + +import edu.asu.diging.vspace.core.model.ISpace; +import edu.asu.diging.vspace.core.model.ISpaceBlock; + +public class SpaceBlock extends ContentBlock implements ISpaceBlock { + private String title; + + @ManyToOne(targetEntity = Space.class) + private ISpace space; + + @Override + public String getTitle() { + return title; + } + + @Override + public void setTitle(String title) { + this.title = title; + } + + @Override + public ISpace getSpace() { + return space; + } + + @Override + public void setSpace(ISpace space) { + this.space = space; + } +} From 7be602f5776667760b1a1d4630482caa664220cf Mon Sep 17 00:00:00 2001 From: glend17 Date: Wed, 27 Oct 2021 13:00:38 -0700 Subject: [PATCH 002/135] [VSPC-171] Added SpaceBlock type functionality --- .../core/data/ModuleLinkRepository.java | 4 +- .../core/services/IContentBlockManager.java | 3 ++ .../core/services/IModuleLinkManager.java | 3 +- .../services/impl/ContentBlockManager.java | 10 +++++ .../core/services/impl/ModuleLinkManager.java | 9 +++++ .../web/staff/AddSpaceBlockController.java | 37 +++++++++++++++++++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/data/ModuleLinkRepository.java b/vspace/src/main/java/edu/asu/diging/vspace/core/data/ModuleLinkRepository.java index 9e8d2f3a3..fb6f4e025 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/data/ModuleLinkRepository.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/data/ModuleLinkRepository.java @@ -1,5 +1,7 @@ package edu.asu.diging.vspace.core.data; +import java.util.Optional; + import org.javers.spring.annotation.JaversSpringDataAuditable; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; @@ -9,5 +11,5 @@ @Repository @JaversSpringDataAuditable public interface ModuleLinkRepository extends PagingAndSortingRepository { - + Optional findByModule_Id(String moduleId); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java index 5326f3c69..f1475d92d 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java @@ -7,6 +7,7 @@ import edu.asu.diging.vspace.core.model.IChoiceBlock; import edu.asu.diging.vspace.core.model.IContentBlock; import edu.asu.diging.vspace.core.model.IImageBlock; +import edu.asu.diging.vspace.core.model.ISpaceBlock; import edu.asu.diging.vspace.core.model.ITextBlock; import edu.asu.diging.vspace.core.model.IVSImage; import edu.asu.diging.vspace.core.model.impl.TextBlock; @@ -46,4 +47,6 @@ IChoiceBlock createChoiceBlock(String slideId, List selectedChoices, Int boolean showsAll); Integer findMaxContentOrder(String slideId); + + ISpaceBlock createSpaceBlock(String slideId, String title, Integer contentOrder); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IModuleLinkManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IModuleLinkManager.java index f83233dea..a33a1da39 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IModuleLinkManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IModuleLinkManager.java @@ -3,7 +3,8 @@ import edu.asu.diging.vspace.core.model.IModule; import edu.asu.diging.vspace.core.model.IModuleLink; import edu.asu.diging.vspace.core.model.display.IModuleLinkDisplay; +import edu.asu.diging.vspace.core.model.impl.ModuleLink; public interface IModuleLinkManager extends ILinkManager{ - + ModuleLink getModuleLinkByModuleId(String moduleId); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java index 4bddb855a..7c7456f36 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java @@ -30,6 +30,7 @@ import edu.asu.diging.vspace.core.model.IContentBlock; import edu.asu.diging.vspace.core.model.IImageBlock; import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ISpaceBlock; import edu.asu.diging.vspace.core.model.ITextBlock; import edu.asu.diging.vspace.core.model.IVSImage; import edu.asu.diging.vspace.core.model.impl.ChoiceBlock; @@ -104,6 +105,15 @@ public ITextBlock createTextBlock(String slideId, String text, Integer contentOr textBlock = textBlockRepo.save((TextBlock) textBlock); return textBlock; } + + @Override + public ISpaceBlock createSpaceBlock(String slideId, String title, Integer contentOrder) { + ISlide slide = slideManager.getSlide(slideId); + ISpaceBlock spaceBlock = spaceBlockFactory.createSpaceBlock(slide, title); + spaceBlock.setContentOrder(contentOrder); + spaceBlock = spaceBlockRepo.save((SpaceBlock) spaceBlock); + return spaceBlock; + } private IVSImage saveImage(byte[] image, String filename) { if (image != null && image.length > 0) { diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ModuleLinkManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ModuleLinkManager.java index bcecff46d..6c8e717ef 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ModuleLinkManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ModuleLinkManager.java @@ -103,5 +103,14 @@ protected void removeFromLinkList(ISpace space, IModuleLink link) { protected void deleteLinkRepo(IModuleLink link) { moduleLinkRepo.delete((ModuleLink) link); } + + @Override + public ModuleLink getModuleLinkByModuleId(String moduleId) { + Optional moduleLinkOptional = moduleLinkRepo.findByModule_Id(moduleId); + if(moduleLinkOptional.isPresent()) { + return moduleLinkOptional.get(); + } + return null; + } } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java new file mode 100644 index 000000000..4902e98f6 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java @@ -0,0 +1,37 @@ +package edu.asu.diging.vspace.web.staff; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import edu.asu.diging.vspace.core.model.IModuleLink; +import edu.asu.diging.vspace.core.services.IContentBlockManager; +import edu.asu.diging.vspace.core.services.IModuleLinkManager; + +@Controller +public class AddSpaceBlockController { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private IContentBlockManager contentBlockManager; + + @Autowired + private IModuleLinkManager moduleLinkManager; + + @RequestMapping(value = "/staff/module/{moduleId}/slide/{id}/image", method = RequestMethod.POST) + ResponseEntity addSpaceBlock(@PathVariable("id") String slideId, + @PathVariable("moduleId") String moduleId){ + + IModuleLink moduleLink = moduleLinkManager.getModuleLinkByModuleId(moduleId); + moduleLink.getSpace(); + return new ResponseEntity<>(HttpStatus.OK); + } + +} From 5efc1a9f7e1ca338684a9620eae8008b573f5ea5 Mon Sep 17 00:00:00 2001 From: glend17 Date: Thu, 28 Oct 2021 16:06:46 -0700 Subject: [PATCH 003/135] [VSPC-171] Adding SpaceBlock functionality --- .../data/SpaceContentBlockRepository.java | 13 +++++++++++ .../core/factory/ISpaceBlockFactory.java | 10 +++++++++ .../core/factory/impl/SpaceBlockFactory.java | 22 +++++++++++++++++++ .../diging/vspace/core/model/ISpaceBlock.java | 2 +- .../vspace/core/model/impl/SpaceBlock.java | 4 ++++ .../core/services/IContentBlockManager.java | 3 ++- .../services/impl/ContentBlockManager.java | 15 +++++++++++-- .../web/staff/AddSpaceBlockController.java | 6 ++++- 8 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 vspace/src/main/java/edu/asu/diging/vspace/core/data/SpaceContentBlockRepository.java create mode 100644 vspace/src/main/java/edu/asu/diging/vspace/core/factory/ISpaceBlockFactory.java create mode 100644 vspace/src/main/java/edu/asu/diging/vspace/core/factory/impl/SpaceBlockFactory.java diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/data/SpaceContentBlockRepository.java b/vspace/src/main/java/edu/asu/diging/vspace/core/data/SpaceContentBlockRepository.java new file mode 100644 index 000000000..6cc5a82bc --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/data/SpaceContentBlockRepository.java @@ -0,0 +1,13 @@ +package edu.asu.diging.vspace.core.data; + +import org.javers.spring.annotation.JaversSpringDataAuditable; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.stereotype.Repository; + +import edu.asu.diging.vspace.core.model.impl.SpaceBlock; + +@Repository +@JaversSpringDataAuditable +public interface SpaceContentBlockRepository extends PagingAndSortingRepository { + +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/factory/ISpaceBlockFactory.java b/vspace/src/main/java/edu/asu/diging/vspace/core/factory/ISpaceBlockFactory.java new file mode 100644 index 000000000..877bb0b5c --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/factory/ISpaceBlockFactory.java @@ -0,0 +1,10 @@ +package edu.asu.diging.vspace.core.factory; + +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ISpace; +import edu.asu.diging.vspace.core.model.ISpaceBlock; + +public interface ISpaceBlockFactory { + + ISpaceBlock createSpaceBlock(ISlide slide, String text, ISpace space); +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/factory/impl/SpaceBlockFactory.java b/vspace/src/main/java/edu/asu/diging/vspace/core/factory/impl/SpaceBlockFactory.java new file mode 100644 index 000000000..bf3d8a330 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/factory/impl/SpaceBlockFactory.java @@ -0,0 +1,22 @@ +package edu.asu.diging.vspace.core.factory.impl; + +import org.springframework.stereotype.Service; + +import edu.asu.diging.vspace.core.factory.ISpaceBlockFactory; +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ISpace; +import edu.asu.diging.vspace.core.model.ISpaceBlock; +import edu.asu.diging.vspace.core.model.impl.SpaceBlock; + +@Service +public class SpaceBlockFactory implements ISpaceBlockFactory { + + @Override + public ISpaceBlock createSpaceBlock(ISlide slide, String title, ISpace space) { + ISpaceBlock spaceBlock = new SpaceBlock(); + spaceBlock.setTitle(title); + spaceBlock.setSlide(slide); + spaceBlock.setSpace(space); + return spaceBlock; + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISpaceBlock.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISpaceBlock.java index d497ae463..d12849123 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISpaceBlock.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISpaceBlock.java @@ -1,6 +1,6 @@ package edu.asu.diging.vspace.core.model; -public interface ISpaceBlock { +public interface ISpaceBlock extends IContentBlock { void setTitle(String text); diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/SpaceBlock.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/SpaceBlock.java index c50066950..6dc764119 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/SpaceBlock.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/SpaceBlock.java @@ -1,11 +1,15 @@ package edu.asu.diging.vspace.core.model.impl; +import javax.persistence.Entity; +import javax.persistence.Lob; import javax.persistence.ManyToOne; import edu.asu.diging.vspace.core.model.ISpace; import edu.asu.diging.vspace.core.model.ISpaceBlock; +@Entity public class SpaceBlock extends ContentBlock implements ISpaceBlock { + @Lob private String title; @ManyToOne(targetEntity = Space.class) diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java index f1475d92d..0e59821f2 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java @@ -7,6 +7,7 @@ import edu.asu.diging.vspace.core.model.IChoiceBlock; import edu.asu.diging.vspace.core.model.IContentBlock; import edu.asu.diging.vspace.core.model.IImageBlock; +import edu.asu.diging.vspace.core.model.ISpace; import edu.asu.diging.vspace.core.model.ISpaceBlock; import edu.asu.diging.vspace.core.model.ITextBlock; import edu.asu.diging.vspace.core.model.IVSImage; @@ -48,5 +49,5 @@ IChoiceBlock createChoiceBlock(String slideId, List selectedChoices, Int Integer findMaxContentOrder(String slideId); - ISpaceBlock createSpaceBlock(String slideId, String title, Integer contentOrder); + ISpaceBlock createSpaceBlock(String slideId, String title, Integer contentOrder, ISpace space); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java index 7c7456f36..d7ec72bb9 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java @@ -16,6 +16,7 @@ import edu.asu.diging.vspace.core.data.ContentBlockRepository; import edu.asu.diging.vspace.core.data.ImageContentBlockRepository; import edu.asu.diging.vspace.core.data.ImageRepository; +import edu.asu.diging.vspace.core.data.SpaceContentBlockRepository; import edu.asu.diging.vspace.core.data.TextContentBlockRepository; import edu.asu.diging.vspace.core.exception.BlockDoesNotExistException; import edu.asu.diging.vspace.core.exception.FileStorageException; @@ -23,6 +24,7 @@ import edu.asu.diging.vspace.core.factory.IChoiceBlockFactory; import edu.asu.diging.vspace.core.factory.IImageBlockFactory; import edu.asu.diging.vspace.core.factory.IImageFactory; +import edu.asu.diging.vspace.core.factory.ISpaceBlockFactory; import edu.asu.diging.vspace.core.factory.ITextBlockFactory; import edu.asu.diging.vspace.core.file.IStorageEngine; import edu.asu.diging.vspace.core.model.IChoice; @@ -30,12 +32,14 @@ import edu.asu.diging.vspace.core.model.IContentBlock; import edu.asu.diging.vspace.core.model.IImageBlock; import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ISpace; import edu.asu.diging.vspace.core.model.ISpaceBlock; import edu.asu.diging.vspace.core.model.ITextBlock; import edu.asu.diging.vspace.core.model.IVSImage; import edu.asu.diging.vspace.core.model.impl.ChoiceBlock; import edu.asu.diging.vspace.core.model.impl.ContentBlock; import edu.asu.diging.vspace.core.model.impl.ImageBlock; +import edu.asu.diging.vspace.core.model.impl.SpaceBlock; import edu.asu.diging.vspace.core.model.impl.TextBlock; import edu.asu.diging.vspace.core.model.impl.VSImage; import edu.asu.diging.vspace.core.services.IContentBlockManager; @@ -53,6 +57,9 @@ public class ContentBlockManager implements IContentBlockManager { @Autowired private ITextBlockFactory textBlockFactory; + + @Autowired + private ISpaceBlockFactory spaceBlockFactory; @Autowired private IImageBlockFactory imageBlockFactory; @@ -65,6 +72,9 @@ public class ContentBlockManager implements IContentBlockManager { @Autowired private TextContentBlockRepository textBlockRepo; + + @Autowired + private SpaceContentBlockRepository spaceBlockRepo; @Autowired private ImageContentBlockRepository imageBlockRepo; @@ -107,9 +117,10 @@ public ITextBlock createTextBlock(String slideId, String text, Integer contentOr } @Override - public ISpaceBlock createSpaceBlock(String slideId, String title, Integer contentOrder) { + public ISpaceBlock createSpaceBlock(String slideId, String title, Integer contentOrder, + ISpace space) { ISlide slide = slideManager.getSlide(slideId); - ISpaceBlock spaceBlock = spaceBlockFactory.createSpaceBlock(slide, title); + ISpaceBlock spaceBlock = spaceBlockFactory.createSpaceBlock(slide, title, space); spaceBlock.setContentOrder(contentOrder); spaceBlock = spaceBlockRepo.save((SpaceBlock) spaceBlock); return spaceBlock; diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java index 4902e98f6..f3fa388b2 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import edu.asu.diging.vspace.core.model.IModuleLink; +import edu.asu.diging.vspace.core.model.ISpace; import edu.asu.diging.vspace.core.services.IContentBlockManager; import edu.asu.diging.vspace.core.services.IModuleLinkManager; @@ -30,7 +31,10 @@ ResponseEntity addSpaceBlock(@PathVariable("id") String slideId, @PathVariable("moduleId") String moduleId){ IModuleLink moduleLink = moduleLinkManager.getModuleLinkByModuleId(moduleId); - moduleLink.getSpace(); + ISpace space = moduleLink.getSpace(); + Integer contentOrder = contentBlockManager.findMaxContentOrder(slideId); + contentOrder = contentOrder == null ? 0 : contentOrder + 1; + contentBlockManager.createSpaceBlock(slideId, moduleId, contentOrder, space); return new ResponseEntity<>(HttpStatus.OK); } From 11aa526a48288236fe267d6c31761da93940322c Mon Sep 17 00:00:00 2001 From: glend17 Date: Fri, 29 Oct 2021 16:33:36 -0700 Subject: [PATCH 004/135] [VSPC-171] Front-end changes --- .../web/staff/AddSpaceBlockController.java | 7 +- .../views/staff/modules/slides/slide.html | 78 ++++++++++++++++++- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java index f3fa388b2..34bcc5a99 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddSpaceBlockController.java @@ -12,6 +12,7 @@ import edu.asu.diging.vspace.core.model.IModuleLink; import edu.asu.diging.vspace.core.model.ISpace; +import edu.asu.diging.vspace.core.model.ISpaceBlock; import edu.asu.diging.vspace.core.services.IContentBlockManager; import edu.asu.diging.vspace.core.services.IModuleLinkManager; @@ -26,7 +27,7 @@ public class AddSpaceBlockController { @Autowired private IModuleLinkManager moduleLinkManager; - @RequestMapping(value = "/staff/module/{moduleId}/slide/{id}/image", method = RequestMethod.POST) + @RequestMapping(value = "/staff/module/{moduleId}/slide/{id}/images", method = RequestMethod.POST) ResponseEntity addSpaceBlock(@PathVariable("id") String slideId, @PathVariable("moduleId") String moduleId){ @@ -34,8 +35,8 @@ ResponseEntity addSpaceBlock(@PathVariable("id") String slideId, ISpace space = moduleLink.getSpace(); Integer contentOrder = contentBlockManager.findMaxContentOrder(slideId); contentOrder = contentOrder == null ? 0 : contentOrder + 1; - contentBlockManager.createSpaceBlock(slideId, moduleId, contentOrder, space); - return new ResponseEntity<>(HttpStatus.OK); + ISpaceBlock spaceBlock = contentBlockManager.createSpaceBlock(slideId, moduleId, contentOrder, space); + return new ResponseEntity<>(spaceBlock.getTitle(), HttpStatus.OK); } } diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html index 865ec0c1b..25a873900 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html @@ -417,6 +417,12 @@ $("#addTextAlert").show(); }); + $("#addSpace").click(function() { + $(".EasyMDEContainer").remove(); + markDown = new EasyMDE({element: $('#textBlockText')[0]}); + $("#addSpaceAlert").show(); + }); + $("#addImage").click(function() { $("#addImgAlert").show(); }); @@ -456,6 +462,10 @@ $("#cancelSubmitText").click(function() { $("#addTextAlert").hide(); }); + + $("#cancelSpaceText").click(function() { + $("#addSpaceAlert").hide(); + }); $("#cancelDeleteText").click(function() { $("#confirmDeleteTextAlert").find('input').remove(); @@ -627,6 +637,41 @@ }); }); + $("#submitSpace").on("click", function(e) { + $("#addSpaceAlert").hide(); + e.preventDefault(); + // ------------- creating text content blocks ------------ + + var formData = new FormData(); + var text = markDown.value(); + formData.append('content', text); + markDown.value(''); + $.ajax({ + url: "[(@{'/staff/module/'+${module.id}+'/slide/'+${slide.id}+'/textcontent?'+${_csrf.parameterName}+'='+${_csrf.token}})]", + type: 'POST', + cache : false, + contentType : false, + processData : false, + data: formData, + enctype: 'multipart/form-data', + success: function(data) { + + var textblock = $('

'+text+'

'+'
'); + $(textblock[0]).mouseenter(onMouseEnter).mouseleave(onMouseLeave).dblclick(onDoubleClick); + $('#slideSpace').append(textblock); + }, + error: function(data) { + if (data.status == 403){ + $("#loginAlert").show(); + } + else { + var alert = $(''); + $('.error').append(alert); + } + } + }); + }); + $('input:checkbox').click(function() { if ($(this).is(':checked')) { $('#submitChoices').prop("disabled", false); @@ -864,10 +909,12 @@

Slide: [[${sli
  +     + + 

Double Click on a Block to Edit it

@@ -977,6 +1024,35 @@

+ + diff --git a/vspace/src/main/webapp/resources/extra/Home.css b/vspace/src/main/webapp/resources/extra/Home.css index c5eaf1bd0..e2e643027 100644 --- a/vspace/src/main/webapp/resources/extra/Home.css +++ b/vspace/src/main/webapp/resources/extra/Home.css @@ -719,6 +719,13 @@ text-align: justify; } +.SpaceDivStaff { + position: relative; + top: 0px; + overflow: visible; + text-align: justify; +} + .choiceDiv { position: relative; top: 0px; From 83b4e4dc8caca574cbbe42f7c698da482db800b0 Mon Sep 17 00:00:00 2001 From: glend17 Date: Mon, 8 Nov 2021 12:37:40 -0700 Subject: [PATCH 009/135] [VSPC-171] Delete and edit related changes for space block --- .../core/services/IContentBlockManager.java | 12 ++ .../services/impl/ContentBlockManager.java | 31 ++++++ .../web/staff/DeleteSpaceBlockController.java | 38 +++++++ .../web/staff/EditSpaceBlockController.java | 16 ++- .../views/staff/modules/slides/slide.html | 104 +++++++++++++++++- 5 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 vspace/src/main/java/edu/asu/diging/vspace/web/staff/DeleteSpaceBlockController.java diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java index a2a325a0a..b6c805f15 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java @@ -55,4 +55,16 @@ IChoiceBlock createChoiceBlock(String slideId, List selectedChoices, Int ISpaceBlock getSpaceBlock(String spaceBlockId); void updateSpaceBlock(SpaceBlock textBlock); + + /** + * Delete a space block using an id and also decrease content order by 1 of all + * the slide's block which are after this block + * + * @param blockId - id of resource to be deleted. If the id is null then the + * functions returns nothing. + * @param slideId - id of the slide in which the text block with blockId is + * present. + * + */ + void deleteSpaceBlockById(String blockId, String slideId) throws BlockDoesNotExistException; } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java index 7f9b4095e..1a6f321cb 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java @@ -225,6 +225,37 @@ public void deleteTextBlockById(String blockId, String slideId) throws BlockDoes } } + + /** + * Delete a space block using an id and also decrease content order by 1 of all + * the slide's block which are after this block + * + * @param blockId - id of resource to be deleted. If the id is null then the + * functions returns nothing. + * @param slideId - id of the slide in which the text block with blockId is + * present. + * + */ + @Override + public void deleteSpaceBlockById(String blockId, String slideId) throws BlockDoesNotExistException { + if (blockId == null) { + return; + } + Integer contentOrder = null; + Optional contentBlock = contentBlockRepository.findById(blockId); + if (contentBlock.isPresent()) { + contentOrder = contentBlock.get().getContentOrder(); + } else { + throw new BlockDoesNotExistException("Block Id not present"); + } + try { + spaceBlockRepo.deleteById(blockId); + updateContentOrder(slideId, contentOrder); + } catch (EmptyResultDataAccessException e) { + throw new BlockDoesNotExistException(e); + } + + } /** * Delete an image block using an id and also decrease content order by 1 of all diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/DeleteSpaceBlockController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/DeleteSpaceBlockController.java new file mode 100644 index 000000000..904d3357e --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/DeleteSpaceBlockController.java @@ -0,0 +1,38 @@ +package edu.asu.diging.vspace.web.staff; + +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import edu.asu.diging.vspace.core.exception.BlockDoesNotExistException; +import edu.asu.diging.vspace.core.services.IContentBlockManager; + +public class DeleteSpaceBlockController { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private IContentBlockManager contentBlockManager; + + @RequestMapping(value = "/staff/module/{moduleId}/slide/{id}/space/{blockId}", method = RequestMethod.DELETE) + public ResponseEntity deleteSpaceBlock(@PathVariable("id") String slideId,@PathVariable("blockId") String blockId) throws IOException { + + try { + contentBlockManager.deleteSpaceBlockById(blockId,slideId); + + } catch (BlockDoesNotExistException e) { + logger.warn("Text Id does not exist, bad request.", e); + return new ResponseEntity(HttpStatus.BAD_REQUEST); + } + + return new ResponseEntity(HttpStatus.OK); + } + +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java index 603b37bde..e5dd7fc1f 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java @@ -2,6 +2,8 @@ import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -11,21 +13,33 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import edu.asu.diging.vspace.core.model.ISpace; import edu.asu.diging.vspace.core.model.ISpaceBlock; import edu.asu.diging.vspace.core.model.impl.SpaceBlock; import edu.asu.diging.vspace.core.services.IContentBlockManager; +import edu.asu.diging.vspace.core.services.ISpaceManager; @Controller public class EditSpaceBlockController { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired private IContentBlockManager contentBlockManager; + + @Autowired + private ISpaceManager spaceManager; @RequestMapping(value = "/staff/module/{moduleId}/slide/{id}/space/edit", method = RequestMethod.POST) public ResponseEntity editTextBlock(@PathVariable("id") String slideId, @RequestParam("spaceBlockId") String blockId, @PathVariable("moduleId") String moduleId, - @RequestParam("spaceBlockTitle") String spaceBlockTitle) throws IOException { + @RequestParam("spaceBlockTitle") String spaceBlockTitle, + @RequestParam("spaceId") String spaceId) throws IOException { + logger.info("Space id selected is {}", spaceId); ISpaceBlock spaceBlock = contentBlockManager.getSpaceBlock(blockId); + ISpace space = spaceManager.getSpace(spaceId); spaceBlock.setTitle(spaceBlockTitle); + spaceBlock.setSpace(space); contentBlockManager.updateSpaceBlock((SpaceBlock) spaceBlock); return new ResponseEntity(HttpStatus.OK); diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html index e950b9d5f..94f371970 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html @@ -458,6 +458,13 @@ $('.modal-footer').append(alert); }); + $(document).on("click", ".deleteSpace", function(e) { + $("#confirmDeleteSpaceAlert").show(); + var alert = $(''); + $(alert).attr( 'value', $(this).siblings('input').val()); + $('.modal-footer').append(alert); + }); + $(document).on("click", ".deleteImage", function(e) { $("#confirmDeleteImageAlert").show(); var alert = $(''); @@ -487,6 +494,14 @@ $("#confirmDeleteTextAlert").hide(); }); + $("#cancelDeleteSpace").click(function() { + $("#confirmDeleteSpaceAlert").find('input').remove(); + $("#confirmDeleteTextAlert").find('input').remove(); + $("#confirmDeleteImageAlert").find('input').remove(); + $("#confirmDeleteChoiceBlockAlert").find('input').remove(); + $("#confirmDeleteSpaceAlert").hide(); + }); + $("#cancelDeleteImage").click(function() { $("#confirmDeleteImageAlert").hide(); }); @@ -511,6 +526,7 @@ e.preventDefault(); $("#confirmDeleteImageAlert").find('input').remove(); $("#confirmDeleteChoiceBlockAlert").find('input').remove(); + $("#confirmDeleteSpaceAlert").find('input').remove(); $("#confirmDeleteTextAlert").hide(); var blockId = $('#deleteTextId').attr('value'); $('#deleteTextId').remove() @@ -532,6 +548,35 @@ } }); }); + + // ---------- Delete Space Block ------------- + + $("#deleteSpace").on("click", function(e) { + e.preventDefault(); + $("#confirmDeleteImageAlert").find('input').remove(); + $("#confirmDeleteChoiceBlockAlert").find('input').remove(); + $("#confirmDeleteTextAlert").find('input').remove(); + $("#confirmDeleteSpaceAlert").hide(); + var blockId = $('#deleteSpaceId').attr('value'); + $('#deleteSpaceId').remove() + + // ------------- delete text content blocks ------------ + $.ajax({ + url: "[(@{'/staff/module/'+${module.id}+'/slide/'+${slide.id}+'/space/'})]"+blockId+'?'+[[${_csrf.parameterName}]]+'='+[[${_csrf.token}]], + type: 'DELETE', + success: function(result) { + $('#' + blockId).remove(); + + }, + error: function(data) { + var alert = $(''); + $('.error').append(alert); + $(".error").delay(4000).slideUp(500, function(){ + $(".error").empty(); + }); + } + }); + }); // ---------- Delete Image Block ----------- @@ -539,6 +584,7 @@ e.preventDefault(); $("#confirmDeleteTextAlert").find('input').remove(); $("#confirmDeleteChoiceBlockAlert").find('input').remove(); + $("#confirmDeleteSpaceAlert").find('input').remove(); $("#confirmDeleteImageAlert").hide(); var blockId = $('#deleteImageId').attr('value'); if(blockId == null || blockId == ''){ @@ -571,6 +617,7 @@ e.preventDefault(); $("#confirmDeleteTextAlert").find('input').remove(); $("#confirmDeleteImageAlert").find('input').remove(); + $("#confirmDeleteSpaceAlert").find('input').remove(); $("#confirmDeleteChoiceBlockAlert").hide(); var blockId = $('#deleteChoiceBlockId').attr('value'); if(blockId == null || blockId == ''){ @@ -774,6 +821,13 @@ var blockId = $(this).closest(".open").attr("id"); updateTextBox(blockId, defaultValue); }); + + // must add the event to the document since the buttons are added dynamically + $('#cancelSpaceBlock').on('click',function(){ + $("#editSpaceAlert").hide(); + var blockId = $(this).closest(".open").attr("id"); + updateTextBox(blockId, defaultValue); + }); $('.valueDiv').mouseenter(onMouseEnter).mouseleave(onMouseLeave).dblclick(onDoubleClick); $('.textDivStaff').mouseenter(onMouseEnter).mouseleave(onMouseLeave).dblclick(onDoubleClick); @@ -818,6 +872,8 @@ $("#submitSpaceBlock").on("click", function(e){ e.preventDefault(); // ------------- editting text content blocks ------------ + var selectedSpace = document.getElementById('editSpaceName'); + var spaceId = selectedSpace.options[selectedSpace.selectedIndex].value; var formData = new FormData(); var text = markDown.value(); markDown.value(''); @@ -825,8 +881,9 @@ var blockId = $(".open").attr("id"); formData.append('spaceBlockTitle', text); formData.append('spaceBlockId', blockId); + formData.append('spaceId', spaceId); console.log(text); - console.log(blockId); + console.log(spaceId); $("#editSpaceAlert").hide(); $.ajax({ url: "[(@{'/staff/module/'+${module.id}+'/slide/'+${slide.id}+'/space/edit?'+${_csrf.parameterName}+'='+${_csrf.token}})]", @@ -913,6 +970,25 @@ } }); + $(window).on('load', function () { + var divWindow = $(".valueDiv"); + $(".deleteSpace").css('position', 'absolute'); + $(".deleteSpace").css('right', '0'); + var images = $(".imgDiv"); + resizeImage(images); + + function resizeImage(images) { + for(var i =0; i < images.length; i++) { + if (images[i].width > divWindow.width() || images[i].width >= 800) { + $(".valueDiv").find("#"+images[i].id).css("width", 800); + images[i].width = 800; + } else { + $(".valueDiv").find("#"+images[i].id).css("width", images[i].width); + } + } + } + }); + @@ -997,6 +1073,32 @@
Are you sure you want to delete this + + + -
+

+ +

+

Current selected space is

-

- -

From fb785dc9bd1fc9956894927ce891a08e1f980e01 Mon Sep 17 00:00:00 2001 From: glend17 Date: Tue, 22 Feb 2022 23:14:40 -0700 Subject: [PATCH 020/135] [VSPC-171] Exhibition side link --- vspace/src/main/webapp/WEB-INF/views/exhibition/module.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vspace/src/main/webapp/WEB-INF/views/exhibition/module.html b/vspace/src/main/webapp/WEB-INF/views/exhibition/module.html index 95afbfa19..2bcdd8fb4 100644 --- a/vspace/src/main/webapp/WEB-INF/views/exhibition/module.html +++ b/vspace/src/main/webapp/WEB-INF/views/exhibition/module.html @@ -73,6 +73,8 @@

[[${currentSlideCon.name}]]

[(${contents.htmlRenderedText()})]
+
Date: Wed, 23 Feb 2022 12:00:19 -0700 Subject: [PATCH 021/135] [VSPC-171] PR Review comments addressed --- .../webapp/WEB-INF/views/staff/modules/slides/slide.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html index 812e8b95b..80a7eb2e1 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html @@ -16,6 +16,7 @@ - - - - - + + + + + - - -
- -
- -
-
-

Slide: [[${slide.name}]]

-

[[${slide.description}]]

-
- -
-
-   -   -   - -
-

Double click on a block to edit it. Drag and drop blocks to change their order.

-
- - - - - - - - - - - - - - - -
-
-
- - - - - -
-
-

[[${contents.text}]]

- - - - -
-
-

[[${contents.title}]]

- - - - - -
- - -
-
-
- + + +
+ +
+ +
+
+

+ Slide: + [[${slide.name}]] +

+

[[${slide.description}]]

+
+ +
+
+ +   + +   + +   + +
+

Double click on a block to edit it. + Drag and drop blocks to change their order.

+
+ + + + + + + + + + + + + + + +
+
+
+ + + +
+
+

[[${contents.text}]]

+ + + +
+
+

[[${contents.title}]]

+ + + + +
+ + +
+
+
+ diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java index f7dc68111..faa0bc19b 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java @@ -11,7 +11,6 @@ import java.util.Optional; import java.util.stream.Collectors; -import org.apache.tika.Tika; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -19,7 +18,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import edu.asu.diging.vspace.core.data.ChoiceContentBlockRepository; @@ -77,9 +75,9 @@ public class ContentBlockManagerTest { @Mock private ISlideManager slideManager; - + @Mock - private IStorageEngine storage; + private IStorageEngine storage; @Mock private IImageBlockFactory imageBlockFactory; @@ -89,7 +87,7 @@ public class ContentBlockManagerTest { @Mock private ITextBlockFactory textBlockFactory; - + @Mock private ChoiceBlockFactory choiceBlockFactory; @@ -395,7 +393,7 @@ public void test_updateImageBlock_success2() throws ImageCouldNotBeStoredExcepti public void test_createImageBlock_success() throws ImageCouldNotBeStoredException, FileStorageException { String slideId = "slide1"; String fileName = "dummyFile"; - String contentType = "application/octet-stream"; + String contentType = "application/octet-stream"; Integer contentOrder = 3; ISlide slide = new Slide(); slide.setId(slideId); @@ -416,12 +414,12 @@ public void test_createImageBlock_success() throws ImageCouldNotBeStoredExceptio managerToTest.createImageBlock(slideId, image, fileName, contentOrder); } - + @Test public void test_createImageBlock2_success() throws ImageCouldNotBeStoredException, FileStorageException { String slideId = "slide1"; String fileName = "dummyFile"; - String contentType = "application/octet-stream"; + String contentType = "application/octet-stream"; Integer contentOrder = 3; ISlide slide = new Slide(); slide.setId(slideId); @@ -430,7 +428,6 @@ public void test_createImageBlock2_success() throws ImageCouldNotBeStoredExcepti slideContentImage.setWidth(1300); IImageBlock imageBlock = new ImageBlock(); imageBlock.setContentOrder(contentOrder); - String relativePathString = ""; when(slideManager.getSlide(slideId)).thenReturn(slide); when(imageFactory.createImage(fileName, contentType)).thenReturn(slideContentImage); @@ -456,9 +453,7 @@ public void test_createTextBlock_success() throws BlockDoesNotExistException { String slideId = "slideId"; ISlide slide = null; - String title = "this is a space block"; Integer contentOrder = 2; - Space space = new Space(); String titleString = "Title1"; String text = "text123"; ITextBlock textBlock = new TextBlock(); @@ -481,7 +476,7 @@ public void test_updateTextBlock_success() throws BlockDoesNotExistException { Mockito.verify(textBlockRepo).save((TextBlock) textBlock); } - + @Test public void test_getTextBlock_success() throws BlockDoesNotExistException { String textblockID = "textBlock1"; @@ -492,7 +487,7 @@ public void test_getTextBlock_success() throws BlockDoesNotExistException { assertEquals(textblockID, retrievedTextBlock.getId()); } - + @Test public void test_getChoiceBlock_success() throws BlockDoesNotExistException { String choiceBlockID = "choiceBlock1"; @@ -503,7 +498,7 @@ public void test_getChoiceBlock_success() throws BlockDoesNotExistException { assertEquals(choiceBlockID, retrievedChoiceBlock.getId()); } - + @Test public void test_getImageBlock_success() throws BlockDoesNotExistException { String imgBlockId = "imgBlockId"; @@ -514,7 +509,7 @@ public void test_getImageBlock_success() throws BlockDoesNotExistException { assertEquals(imgBlockId, retrievedImageBlock.getId()); } - + @Test public void test_createChoiceBlock_success() throws BlockDoesNotExistException { @@ -539,14 +534,5 @@ public void test_createChoiceBlock_success() throws BlockDoesNotExistException { Assert.assertEquals(createdChoiceBlock.getContentOrder(), contentOrder); } - - - - - - - - // findMaxContentOrder - // createImageBlock } From 1cc48726a8e70ddc5ce5cab515c5deac879c23e5 Mon Sep 17 00:00:00 2001 From: Baishali Nayak Date: Wed, 6 Jul 2022 16:17:59 -0700 Subject: [PATCH 053/135] [VSPC-171] added changes to resolve codefactor.io problems --- .../vspace/web/staff/SlideController.java | 58 +- .../impl/ContentBlockManagerTest.java | 952 +++++++++--------- 2 files changed, 505 insertions(+), 505 deletions(-) diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/SlideController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/SlideController.java index 769deb140..d620fa8b7 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/SlideController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/SlideController.java @@ -30,39 +30,39 @@ @Controller public class SlideController { - @Autowired - private ISlideManager slideManager; + @Autowired + private ISlideManager slideManager; - @Autowired - private IModuleManager moduleManager; + @Autowired + private IModuleManager moduleManager; - @Autowired - private IContentBlockManager contentBlockManager; + @Autowired + private IContentBlockManager contentBlockManager; - @RequestMapping("/staff/module/{moduleId}/slide/{id}") - public String listSlides(@PathVariable("id") String id, @PathVariable("moduleId") String moduleId, Model model) - throws JsonProcessingException { + @RequestMapping("/staff/module/{moduleId}/slide/{id}") + public String listSlides(@PathVariable("id") String id, @PathVariable("moduleId") String moduleId, Model model) + throws JsonProcessingException { - ISlide slide = slideManager.getSlide(id); - model.addAttribute("module", moduleManager.getModule(moduleId)); - model.addAttribute("slide", slide); - model.addAttribute("slideSequences", slideManager.getSlideSequences(id, moduleId)); - List slideContents = contentBlockManager.getAllContentBlocks(id); - model.addAttribute("slideContents", slideContents); - model.addAttribute("contentCount", - slideContents.size() > 0 ? slideContents.get(slideContents.size() - 1).getContentOrder() : 0); - if (slideManager.getSlide(id) instanceof BranchingPoint) { - model.addAttribute("choices", ((IBranchingPoint) slide).getChoices()); - } - return "staff/modules/slides/slide"; - } + ISlide slide = slideManager.getSlide(id); + model.addAttribute("module", moduleManager.getModule(moduleId)); + model.addAttribute("slide", slide); + model.addAttribute("slideSequences", slideManager.getSlideSequences(id, moduleId)); + List slideContents = contentBlockManager.getAllContentBlocks(id); + model.addAttribute("slideContents", slideContents); + model.addAttribute("contentCount", + slideContents.size() > 0 ? slideContents.get(slideContents.size() - 1).getContentOrder() : 0); + if (slideManager.getSlide(id) instanceof BranchingPoint) { + model.addAttribute("choices", ((IBranchingPoint) slide).getChoices()); + } + return "staff/modules/slides/slide"; + } - @RequestMapping(value = "/staff/module/{moduleId}/slide/{id}/contents", method = RequestMethod.GET) - public ResponseEntity> getAllContentBlocks(Model model, - @PathVariable("moduleId") String moduleId, @PathVariable("id") String slideId, - @ModelAttribute SequenceForm sequenceForm, Principal principal) { + @RequestMapping(value = "/staff/module/{moduleId}/slide/{id}/contents", method = RequestMethod.GET) + public ResponseEntity> getAllContentBlocks(Model model, + @PathVariable("moduleId") String moduleId, @PathVariable("id") String slideId, + @ModelAttribute SequenceForm sequenceForm, Principal principal) { - List slideContents = contentBlockManager.getAllContentBlocks(slideId); - return new ResponseEntity>(slideContents, HttpStatus.OK); - } + List slideContents = contentBlockManager.getAllContentBlocks(slideId); + return new ResponseEntity>(slideContents, HttpStatus.OK); + } } diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java index faa0bc19b..2cd77618c 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java @@ -58,481 +58,481 @@ public class ContentBlockManagerTest { - @Mock - private ContentBlockRepository contentBlockRepository; - - @Mock - private TextContentBlockRepository textBlockRepo; - - @Mock - private SpaceContentBlockRepository spaceBlockRepo; - - @Mock - private ImageContentBlockRepository imageBlockRepo; - - @Mock - private SlideRepository slideRepo; - - @Mock - private ISlideManager slideManager; - - @Mock - private IStorageEngine storage; - - @Mock - private IImageBlockFactory imageBlockFactory; - - @Mock - private SpaceBlockFactory spaceBlockFactory; - - @Mock - private ITextBlockFactory textBlockFactory; - - @Mock - private ChoiceBlockFactory choiceBlockFactory; - - @Mock - private ChoiceContentBlockRepository choiceBlockRepo; - - @Mock - private IImageFactory imageFactory; - - @Mock - private ImageRepository imageRepo; - - @InjectMocks - private ContentBlockManager managerToTest; - - private ContentBlock contentBlock; - - private ContentBlock contentBlock1; - - private List contentBlockList; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - contentBlock = new ContentBlock(); - contentBlock.setContentOrder(1); - - contentBlock1 = new ContentBlock(); - contentBlock1.setContentOrder(2); - - ContentBlock contentBlock1 = new ContentBlock(); - contentBlock1.setContentOrder(2); - ContentBlock contentBlock2 = new ContentBlock(); - contentBlock2.setContentOrder(3); - contentBlockList = new ArrayList<>(); - contentBlockList.add(contentBlock1); - contentBlockList.add(contentBlock2); - } - - @Test - public void test_deleteTextBlockById_success() throws BlockDoesNotExistException { - String textBlockId = "textBlockId_2"; - Optional contentBlockOptional = Optional.of(contentBlock); - when(contentBlockRepository.findById("textBlockId_2")).thenReturn(contentBlockOptional); - when(contentBlockRepository.findBySlide_IdAndContentOrderGreaterThan("slideId_1", Integer.valueOf(1))) - .thenReturn(contentBlockList); - managerToTest.deleteTextBlockById(textBlockId, "slideId_1"); - Mockito.verify(textBlockRepo).deleteById(textBlockId); - List contentOrderList = contentBlockList.stream().map(contentBlock -> contentBlock.getContentOrder()) - .collect(Collectors.toList()); - assertEquals(Integer.valueOf(1), contentOrderList.get(0)); - assertEquals(Integer.valueOf(2), contentOrderList.get(1)); - Mockito.verify(contentBlockRepository).saveAll(contentBlockList); - } - - @Test(expected = BlockDoesNotExistException.class) - public void test_deleteTextBlockById_forNonExistentId() throws BlockDoesNotExistException { - String textBlockId = "notARealId"; - Optional contentBlockOptional = Optional.of(contentBlock); - when(contentBlockRepository.findById("notARealId")).thenReturn(contentBlockOptional); - Mockito.doThrow(EmptyResultDataAccessException.class).when(textBlockRepo).deleteById(textBlockId); - Mockito.doThrow(EmptyResultDataAccessException.class).when(textBlockRepo).existsById(textBlockId); - managerToTest.deleteTextBlockById(textBlockId, "slideId_1"); - } - - @Test(expected = BlockDoesNotExistException.class) - public void test_deleteSpaceBlockById_forNonExistentId() throws BlockDoesNotExistException { - String spaceBlockId = "notARealId"; - when(contentBlockRepository.findById("notARealId")).thenReturn(Optional.empty()); - Mockito.doThrow(EmptyResultDataAccessException.class).when(spaceBlockRepo).deleteById(spaceBlockId); - Mockito.doThrow(EmptyResultDataAccessException.class).when(textBlockRepo).existsById(spaceBlockId); - managerToTest.deleteSpaceBlockById(spaceBlockId, "slideId_1"); - } - - @Test - public void test_deleteSpaceBlock_success() throws BlockDoesNotExistException { - String spaceBlockId = "realId"; - when(contentBlockRepository.findById(spaceBlockId)).thenReturn(Optional.of(contentBlock)); - managerToTest.deleteSpaceBlockById(spaceBlockId, "slideId_1"); - Mockito.verify(spaceBlockRepo).deleteById(spaceBlockId); - - } - - @Test - public void test_createSpaceBlock_success() { - String slideId = "slideId"; - ISlide slide = null; - String title = "this is a space block"; - Integer contentOrder = 2; - Space space = new Space(); - ISpaceBlock spaceBlock = new SpaceBlock(); - Mockito.when(slideManager.getSlide(slideId)).thenReturn(slide); - Mockito.when(spaceBlockRepo.save((SpaceBlock) spaceBlock)).thenReturn((SpaceBlock) spaceBlock); - Mockito.when(spaceBlockFactory.createSpaceBlock(slide, title, (ISpace) space)).thenReturn(spaceBlock); - ISpaceBlock createdBlock = managerToTest.createSpaceBlock(slideId, title, contentOrder, space); - Assert.assertEquals(createdBlock.getContentOrder(), contentOrder); - } - - @Test - public void test_getSpaceBlock_success() { - String spaceId = "spaceId"; - SpaceBlock spaceBlock = new SpaceBlock(); - spaceBlock.setId(spaceId); - when(spaceBlockRepo.findById(spaceId)).thenReturn(Optional.of(spaceBlock)); - ISpaceBlock retrievedSpaceBlock = managerToTest.getSpaceBlock(spaceId); - assertEquals(spaceId, retrievedSpaceBlock.getId()); - } - - @Test - public void test_getSpaceBlock_NonExistentId() throws BlockDoesNotExistException { - String spaceId = "notRealId"; - when(spaceBlockRepo.findById(spaceId)).thenReturn(Optional.empty()); - ISpaceBlock retrievedSpaceBlock = managerToTest.getSpaceBlock(spaceId); - assertNull(retrievedSpaceBlock); - - } - - @Test - public void test_updateSpaceBlock_success() { - String upadtedSpaceId = "spaceId1"; - SpaceBlock spaceBlock = new SpaceBlock(); - spaceBlock.setId(upadtedSpaceId); - Mockito.when(spaceBlockRepo.save(spaceBlock)).thenReturn(spaceBlock); - managerToTest.updateSpaceBlock(spaceBlock); - Mockito.verify(spaceBlockRepo).save(spaceBlock); - - } - - @Test - public void test_deleteTextBlockById_whenIdIsNull() throws BlockDoesNotExistException { - String textBlockId = null; - managerToTest.deleteTextBlockById(null, "slideId_1"); - Mockito.verify(textBlockRepo, Mockito.never()).deleteById(textBlockId); - } - - @Test - public void test_deleteImageBlockById_success() throws BlockDoesNotExistException { - String imageBlockId = "imageBlockId_2"; - Optional contentBlockOptional = Optional.of(contentBlock); - when(contentBlockRepository.findById("imageBlockId_2")).thenReturn(contentBlockOptional); - when(contentBlockRepository.findBySlide_IdAndContentOrderGreaterThan("slideId_1", Integer.valueOf(1))) - .thenReturn(contentBlockList); - managerToTest.deleteImageBlockById(imageBlockId, "slideId_1"); - Mockito.verify(imageBlockRepo).deleteById(imageBlockId); - List contentOrderList = contentBlockList.stream().map(contentBlock -> contentBlock.getContentOrder()) - .collect(Collectors.toList()); - assertEquals(Integer.valueOf(1), contentOrderList.get(0)); - assertEquals(Integer.valueOf(2), contentOrderList.get(1)); - Mockito.verify(contentBlockRepository).saveAll(contentBlockList); - } - - @Test(expected = BlockDoesNotExistException.class) - public void test_deleteImageBlockById_forNonExistentId() throws BlockDoesNotExistException { - String imageBlockId = "notARealId"; - Optional contentBlockOptional = Optional.of(contentBlock); - when(contentBlockRepository.findById("notARealId")).thenReturn(contentBlockOptional); - Mockito.doThrow(EmptyResultDataAccessException.class).when(imageBlockRepo).deleteById(imageBlockId); - managerToTest.deleteImageBlockById(imageBlockId, "slideId_1"); - } - - @Test - public void test_deleteImagetBlockById_whenIdIsNull() throws BlockDoesNotExistException { - String imageBlockId = null; - managerToTest.deleteImageBlockById(null, "slideId_1"); - Mockito.verify(imageBlockRepo, Mockito.never()).deleteById(imageBlockId); - - } - - @Test - public void test_updateContentOrder_success() throws BlockDoesNotExistException { - ContentBlock firstContentBlock = new ContentBlock(); - firstContentBlock.setId("contentBlockId1"); - firstContentBlock.setContentOrder(Integer.valueOf(3)); - - ContentBlock secondContentBlock = new ContentBlock(); - secondContentBlock.setId("contentBlockId2"); - secondContentBlock.setContentOrder(Integer.valueOf(4)); - - List contentBlocks = new ArrayList<>(); - contentBlocks.add(firstContentBlock); - contentBlocks.add(secondContentBlock); - - when(contentBlockRepository.findById("contentBlockId1")).thenReturn(Optional.of(contentBlock)); - when(contentBlockRepository.findById("contentBlockId2")).thenReturn(Optional.of(contentBlock1)); - - managerToTest.updateContentOrder(contentBlocks); - assertEquals(Integer.valueOf(3), contentBlock.getContentOrder()); - assertEquals(Integer.valueOf(4), contentBlock1.getContentOrder()); - - List contentBlockList = new ArrayList<>(); - contentBlockList.add(contentBlock); - contentBlockList.add(contentBlock1); - - Mockito.verify(contentBlockRepository).saveAll(contentBlockList); - } - - @Test(expected = BlockDoesNotExistException.class) - public void test_updateContentOrder_forNonExistentId() throws BlockDoesNotExistException { - ContentBlock contentBlock1 = new ContentBlock(); - contentBlock1.setId("notARealId"); - contentBlock1.setContentOrder(Integer.valueOf(1)); - - List contentBlocks = new ArrayList<>(); - contentBlocks.add(contentBlock1); - - when(contentBlockRepository.findById("notARealId")).thenReturn(Optional.empty()); - managerToTest.updateContentOrder(contentBlocks); - } - - @Test - public void test_getAllContentBlocks_success() throws BlockDoesNotExistException { - - String slideId = "slide1"; - ISlide slide = new Slide(); - slide.setId(slideId); - ContentBlock firstContentBlock = new ContentBlock(); - firstContentBlock.setId("contentBlockId1"); - firstContentBlock.setContentOrder(Integer.valueOf(3)); - - ContentBlock secondContentBlock = new ContentBlock(); - secondContentBlock.setId("contentBlockId2"); - secondContentBlock.setContentOrder(Integer.valueOf(4)); - - List contentBlocks = new ArrayList<>(); - contentBlocks.add(firstContentBlock); - contentBlocks.add(secondContentBlock); - slide.setContents(contentBlocks); - when(slideManager.getSlide(slideId)).thenReturn(slide); - when(slideRepo.findById("notARealId")).thenReturn(Optional.empty()); - - List contentBlock = managerToTest.getAllContentBlocks(slideId); - assertTrue(!contentBlock.isEmpty()); - - } - - @Test - public void test_deleteChoiceBlockById_success() throws BlockDoesNotExistException { - String blockId = "realBlockId"; - String slideId = "realSlideId"; - when(contentBlockRepository.findById(blockId)).thenReturn(Optional.of(contentBlock)); - managerToTest.deleteChoiceBlockById(blockId, slideId); - - } - - @Test - public void test_deleteChoiceBlockById_nullBlockId() throws BlockDoesNotExistException { - String blockId = null; - String slideId = "realSlideId"; - managerToTest.deleteChoiceBlockById(blockId, slideId); - - } - - @Test(expected = BlockDoesNotExistException.class) - public void test_deleteChoiceBlockById_missingContentBlock() throws BlockDoesNotExistException { - String blockId = "realBlockId"; - String slideId = "realSlideId"; - when(contentBlockRepository.findById(blockId)).thenReturn(Optional.empty()); - managerToTest.deleteChoiceBlockById(blockId, slideId); - - } - - @Test(expected = BlockDoesNotExistException.class) - public void test_deleteChoiceBlockById_nonExistentContentBlock() throws BlockDoesNotExistException { - String blockId = "realBlockId"; - String slideId = "realSlideId"; - when(contentBlockRepository.findById(blockId)).thenReturn(Optional.of(contentBlock)); - Mockito.doThrow(EmptyResultDataAccessException.class).when(choiceBlockRepo).deleteById(blockId); - managerToTest.deleteChoiceBlockById(blockId, slideId); - - } - - @Test - public void test_updateImageBlock_success1() throws ImageCouldNotBeStoredException { - String slideId = "realSlideId"; - String fileName = "dummyFile"; - ISlide slide = new Slide(); - slide.setId(slideId); - IVSImage slideContentImage = new VSImage(); - slideContentImage.setHeight(700); - slideContentImage.setWidth(1300); - slideContentImage.setFilename(fileName); - byte[] image = new byte[1000]; - IImageBlock imageBlock = new ImageBlock(); - when(slideManager.getSlide(slideId)).thenReturn(slide); - when(imageFactory.createImage(fileName, fileName)).thenReturn(slideContentImage); - when(imageRepo.save((VSImage) slideContentImage)).thenReturn((VSImage) slideContentImage); - managerToTest.updateImageBlock(imageBlock, image, fileName); - - } - - @Test - public void test_updateImageBlock_success2() throws ImageCouldNotBeStoredException { - - IVSImage slideContentImage = new VSImage(); - slideContentImage.setHeight(700); - slideContentImage.setWidth(1300); - IImageBlock imageBlock = new ImageBlock(); - managerToTest.updateImageBlock(imageBlock, slideContentImage); - - } - - @Test - public void test_createImageBlock_success() throws ImageCouldNotBeStoredException, FileStorageException { - String slideId = "slide1"; - String fileName = "dummyFile"; - String contentType = "application/octet-stream"; - Integer contentOrder = 3; - ISlide slide = new Slide(); - slide.setId(slideId); - IVSImage slideContentImage = new VSImage(); - slideContentImage.setHeight(700); - slideContentImage.setWidth(1300); - IImageBlock imageBlock = new ImageBlock(); - imageBlock.setContentOrder(contentOrder); - byte[] image = new byte[1000]; - String relativePathString = ""; - - when(slideManager.getSlide(slideId)).thenReturn(slide); - when(imageFactory.createImage(fileName, contentType)).thenReturn(slideContentImage); - when(storage.storeFile(image, fileName, contentType)).thenReturn(relativePathString); - when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); - Mockito.when(imageRepo.save((VSImage) slideContentImage)).thenReturn((VSImage) slideContentImage); - Mockito.when(imageBlockFactory.createImageBlock(slide, slideContentImage)).thenReturn(imageBlock); - managerToTest.createImageBlock(slideId, image, fileName, contentOrder); - - } - - @Test - public void test_createImageBlock2_success() throws ImageCouldNotBeStoredException, FileStorageException { - String slideId = "slide1"; - String fileName = "dummyFile"; - String contentType = "application/octet-stream"; - Integer contentOrder = 3; - ISlide slide = new Slide(); - slide.setId(slideId); - IVSImage slideContentImage = new VSImage(); - slideContentImage.setHeight(700); - slideContentImage.setWidth(1300); - IImageBlock imageBlock = new ImageBlock(); - imageBlock.setContentOrder(contentOrder); - - when(slideManager.getSlide(slideId)).thenReturn(slide); - when(imageFactory.createImage(fileName, contentType)).thenReturn(slideContentImage); - when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); - Mockito.when(imageBlockFactory.createImageBlock(slide, slideContentImage)).thenReturn(imageBlock); - CreationReturnValue returnValue = managerToTest.createImageBlock(slideId, slideContentImage, contentOrder); - assertNotNull(returnValue); - - } - - @Test - public void test_saveSpaceBlock_success() throws BlockDoesNotExistException { - ISpaceBlock spaceBlock = new SpaceBlock(); - spaceBlock.setContentOrder(3); - spaceBlock.setId("spaceBlock1"); - managerToTest.saveSpaceBlock(spaceBlock); - Mockito.verify(spaceBlockRepo).save((SpaceBlock) spaceBlock); - - } - - @Test - public void test_createTextBlock_success() throws BlockDoesNotExistException { - - String slideId = "slideId"; - ISlide slide = null; - Integer contentOrder = 2; - String titleString = "Title1"; - String text = "text123"; - ITextBlock textBlock = new TextBlock(); - - Mockito.when(slideManager.getSlide(slideId)).thenReturn(slide); - Mockito.when(textBlockFactory.createTextBlock(slide, text)).thenReturn(textBlock); - Mockito.when(textBlockRepo.save((TextBlock) textBlock)).thenReturn((TextBlock) textBlock); - ITextBlock createdBlock = managerToTest.createTextBlock(titleString, text, contentOrder); - - Assert.assertEquals(createdBlock.getContentOrder(), contentOrder); - - } - - @Test - public void test_updateTextBlock_success() throws BlockDoesNotExistException { - TextBlock textBlock = new TextBlock(); - textBlock.setContentOrder(3); - textBlock.setId("textBlock1"); - managerToTest.updateTextBlock(textBlock); - Mockito.verify(textBlockRepo).save((TextBlock) textBlock); - - } - - @Test - public void test_getTextBlock_success() throws BlockDoesNotExistException { - String textblockID = "textBlock1"; - TextBlock textBlock = new TextBlock(); - textBlock.setId(textblockID); - when(textBlockRepo.findById(textblockID)).thenReturn(Optional.of(textBlock)); - ITextBlock retrievedTextBlock = managerToTest.getTextBlock(textblockID); - assertEquals(textblockID, retrievedTextBlock.getId()); - - } - - @Test - public void test_getChoiceBlock_success() throws BlockDoesNotExistException { - String choiceBlockID = "choiceBlock1"; - ChoiceBlock choiceBlock = new ChoiceBlock(); - choiceBlock.setId(choiceBlockID); - when(choiceBlockRepo.findById(choiceBlockID)).thenReturn(Optional.of(choiceBlock)); - IChoiceBlock retrievedChoiceBlock = managerToTest.getChoiceBlock(choiceBlockID); - assertEquals(choiceBlockID, retrievedChoiceBlock.getId()); - - } - - @Test - public void test_getImageBlock_success() throws BlockDoesNotExistException { - String imgBlockId = "imgBlockId"; - ImageBlock imageBlock = new ImageBlock(); - imageBlock.setId(imgBlockId); - when(imageBlockRepo.findById(imgBlockId)).thenReturn(Optional.of(imageBlock)); - IImageBlock retrievedImageBlock = managerToTest.getImageBlock(imgBlockId); - assertEquals(imgBlockId, retrievedImageBlock.getId()); - - } - - @Test - public void test_createChoiceBlock_success() throws BlockDoesNotExistException { - - String slideId = "slideId"; - Integer contentOrder = 2; - String choiceString = "abcd"; - List selectedChoices = new ArrayList(); - selectedChoices.add(choiceString); - IChoice choice = new Choice(); - ISlide slide = new Slide(); - slide.setId(slideId); - List choices = new ArrayList(); - IChoiceBlock choiceBlock = new ChoiceBlock(); - choiceBlock.setChoices(choices); - choiceBlock.setContentOrder(contentOrder); - - Mockito.when(slideManager.getChoice(choiceString)).thenReturn(choice); - Mockito.when(slideManager.getSlide(slideId)).thenReturn(slide); - Mockito.when(choiceBlockFactory.createChoiceBlock(slide, contentOrder, choices, true)).thenReturn(choiceBlock); - Mockito.when(choiceBlockRepo.save((ChoiceBlock) choiceBlock)).thenReturn((ChoiceBlock) choiceBlock); - IChoiceBlock createdChoiceBlock = managerToTest.createChoiceBlock(slideId, selectedChoices, contentOrder, true); - Assert.assertEquals(createdChoiceBlock.getContentOrder(), contentOrder); - - } + @Mock + private ContentBlockRepository contentBlockRepository; + + @Mock + private TextContentBlockRepository textBlockRepo; + + @Mock + private SpaceContentBlockRepository spaceBlockRepo; + + @Mock + private ImageContentBlockRepository imageBlockRepo; + + @Mock + private SlideRepository slideRepo; + + @Mock + private ISlideManager slideManager; + + @Mock + private IStorageEngine storage; + + @Mock + private IImageBlockFactory imageBlockFactory; + + @Mock + private SpaceBlockFactory spaceBlockFactory; + + @Mock + private ITextBlockFactory textBlockFactory; + + @Mock + private ChoiceBlockFactory choiceBlockFactory; + + @Mock + private ChoiceContentBlockRepository choiceBlockRepo; + + @Mock + private IImageFactory imageFactory; + + @Mock + private ImageRepository imageRepo; + + @InjectMocks + private ContentBlockManager managerToTest; + + private ContentBlock contentBlock; + + private ContentBlock contentBlock1; + + private List contentBlockList; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + contentBlock = new ContentBlock(); + contentBlock.setContentOrder(1); + + contentBlock1 = new ContentBlock(); + contentBlock1.setContentOrder(2); + + ContentBlock contentBlock1 = new ContentBlock(); + contentBlock1.setContentOrder(2); + ContentBlock contentBlock2 = new ContentBlock(); + contentBlock2.setContentOrder(3); + contentBlockList = new ArrayList<>(); + contentBlockList.add(contentBlock1); + contentBlockList.add(contentBlock2); + } + + @Test + public void test_deleteTextBlockById_success() throws BlockDoesNotExistException { + String textBlockId = "textBlockId_2"; + Optional contentBlockOptional = Optional.of(contentBlock); + when(contentBlockRepository.findById("textBlockId_2")).thenReturn(contentBlockOptional); + when(contentBlockRepository.findBySlide_IdAndContentOrderGreaterThan("slideId_1", Integer.valueOf(1))) + .thenReturn(contentBlockList); + managerToTest.deleteTextBlockById(textBlockId, "slideId_1"); + Mockito.verify(textBlockRepo).deleteById(textBlockId); + List contentOrderList = contentBlockList.stream().map(contentBlock -> contentBlock.getContentOrder()) + .collect(Collectors.toList()); + assertEquals(Integer.valueOf(1), contentOrderList.get(0)); + assertEquals(Integer.valueOf(2), contentOrderList.get(1)); + Mockito.verify(contentBlockRepository).saveAll(contentBlockList); + } + + @Test(expected = BlockDoesNotExistException.class) + public void test_deleteTextBlockById_forNonExistentId() throws BlockDoesNotExistException { + String textBlockId = "notARealId"; + Optional contentBlockOptional = Optional.of(contentBlock); + when(contentBlockRepository.findById("notARealId")).thenReturn(contentBlockOptional); + Mockito.doThrow(EmptyResultDataAccessException.class).when(textBlockRepo).deleteById(textBlockId); + Mockito.doThrow(EmptyResultDataAccessException.class).when(textBlockRepo).existsById(textBlockId); + managerToTest.deleteTextBlockById(textBlockId, "slideId_1"); + } + + @Test(expected = BlockDoesNotExistException.class) + public void test_deleteSpaceBlockById_forNonExistentId() throws BlockDoesNotExistException { + String spaceBlockId = "notARealId"; + when(contentBlockRepository.findById("notARealId")).thenReturn(Optional.empty()); + Mockito.doThrow(EmptyResultDataAccessException.class).when(spaceBlockRepo).deleteById(spaceBlockId); + Mockito.doThrow(EmptyResultDataAccessException.class).when(textBlockRepo).existsById(spaceBlockId); + managerToTest.deleteSpaceBlockById(spaceBlockId, "slideId_1"); + } + + @Test + public void test_deleteSpaceBlock_success() throws BlockDoesNotExistException { + String spaceBlockId = "realId"; + when(contentBlockRepository.findById(spaceBlockId)).thenReturn(Optional.of(contentBlock)); + managerToTest.deleteSpaceBlockById(spaceBlockId, "slideId_1"); + Mockito.verify(spaceBlockRepo).deleteById(spaceBlockId); + + } + + @Test + public void test_createSpaceBlock_success() { + String slideId = "slideId"; + ISlide slide = null; + String title = "this is a space block"; + Integer contentOrder = 2; + Space space = new Space(); + ISpaceBlock spaceBlock = new SpaceBlock(); + Mockito.when(slideManager.getSlide(slideId)).thenReturn(slide); + Mockito.when(spaceBlockRepo.save((SpaceBlock) spaceBlock)).thenReturn((SpaceBlock) spaceBlock); + Mockito.when(spaceBlockFactory.createSpaceBlock(slide, title, (ISpace) space)).thenReturn(spaceBlock); + ISpaceBlock createdBlock = managerToTest.createSpaceBlock(slideId, title, contentOrder, space); + Assert.assertEquals(createdBlock.getContentOrder(), contentOrder); + } + + @Test + public void test_getSpaceBlock_success() { + String spaceId = "spaceId"; + SpaceBlock spaceBlock = new SpaceBlock(); + spaceBlock.setId(spaceId); + when(spaceBlockRepo.findById(spaceId)).thenReturn(Optional.of(spaceBlock)); + ISpaceBlock retrievedSpaceBlock = managerToTest.getSpaceBlock(spaceId); + assertEquals(spaceId, retrievedSpaceBlock.getId()); + } + + @Test + public void test_getSpaceBlock_NonExistentId() throws BlockDoesNotExistException { + String spaceId = "notRealId"; + when(spaceBlockRepo.findById(spaceId)).thenReturn(Optional.empty()); + ISpaceBlock retrievedSpaceBlock = managerToTest.getSpaceBlock(spaceId); + assertNull(retrievedSpaceBlock); + + } + + @Test + public void test_updateSpaceBlock_success() { + String upadtedSpaceId = "spaceId1"; + SpaceBlock spaceBlock = new SpaceBlock(); + spaceBlock.setId(upadtedSpaceId); + Mockito.when(spaceBlockRepo.save(spaceBlock)).thenReturn(spaceBlock); + managerToTest.updateSpaceBlock(spaceBlock); + Mockito.verify(spaceBlockRepo).save(spaceBlock); + + } + + @Test + public void test_deleteTextBlockById_whenIdIsNull() throws BlockDoesNotExistException { + String textBlockId = null; + managerToTest.deleteTextBlockById(null, "slideId_1"); + Mockito.verify(textBlockRepo, Mockito.never()).deleteById(textBlockId); + } + + @Test + public void test_deleteImageBlockById_success() throws BlockDoesNotExistException { + String imageBlockId = "imageBlockId_2"; + Optional contentBlockOptional = Optional.of(contentBlock); + when(contentBlockRepository.findById("imageBlockId_2")).thenReturn(contentBlockOptional); + when(contentBlockRepository.findBySlide_IdAndContentOrderGreaterThan("slideId_1", Integer.valueOf(1))) + .thenReturn(contentBlockList); + managerToTest.deleteImageBlockById(imageBlockId, "slideId_1"); + Mockito.verify(imageBlockRepo).deleteById(imageBlockId); + List contentOrderList = contentBlockList.stream().map(contentBlock -> contentBlock.getContentOrder()) + .collect(Collectors.toList()); + assertEquals(Integer.valueOf(1), contentOrderList.get(0)); + assertEquals(Integer.valueOf(2), contentOrderList.get(1)); + Mockito.verify(contentBlockRepository).saveAll(contentBlockList); + } + + @Test(expected = BlockDoesNotExistException.class) + public void test_deleteImageBlockById_forNonExistentId() throws BlockDoesNotExistException { + String imageBlockId = "notARealId"; + Optional contentBlockOptional = Optional.of(contentBlock); + when(contentBlockRepository.findById("notARealId")).thenReturn(contentBlockOptional); + Mockito.doThrow(EmptyResultDataAccessException.class).when(imageBlockRepo).deleteById(imageBlockId); + managerToTest.deleteImageBlockById(imageBlockId, "slideId_1"); + } + + @Test + public void test_deleteImagetBlockById_whenIdIsNull() throws BlockDoesNotExistException { + String imageBlockId = null; + managerToTest.deleteImageBlockById(null, "slideId_1"); + Mockito.verify(imageBlockRepo, Mockito.never()).deleteById(imageBlockId); + + } + + @Test + public void test_updateContentOrder_success() throws BlockDoesNotExistException { + ContentBlock firstContentBlock = new ContentBlock(); + firstContentBlock.setId("contentBlockId1"); + firstContentBlock.setContentOrder(Integer.valueOf(3)); + + ContentBlock secondContentBlock = new ContentBlock(); + secondContentBlock.setId("contentBlockId2"); + secondContentBlock.setContentOrder(Integer.valueOf(4)); + + List contentBlocks = new ArrayList<>(); + contentBlocks.add(firstContentBlock); + contentBlocks.add(secondContentBlock); + + when(contentBlockRepository.findById("contentBlockId1")).thenReturn(Optional.of(contentBlock)); + when(contentBlockRepository.findById("contentBlockId2")).thenReturn(Optional.of(contentBlock1)); + + managerToTest.updateContentOrder(contentBlocks); + assertEquals(Integer.valueOf(3), contentBlock.getContentOrder()); + assertEquals(Integer.valueOf(4), contentBlock1.getContentOrder()); + + List contentBlockList = new ArrayList<>(); + contentBlockList.add(contentBlock); + contentBlockList.add(contentBlock1); + + Mockito.verify(contentBlockRepository).saveAll(contentBlockList); + } + + @Test(expected = BlockDoesNotExistException.class) + public void test_updateContentOrder_forNonExistentId() throws BlockDoesNotExistException { + ContentBlock contentBlock1 = new ContentBlock(); + contentBlock1.setId("notARealId"); + contentBlock1.setContentOrder(Integer.valueOf(1)); + + List contentBlocks = new ArrayList<>(); + contentBlocks.add(contentBlock1); + + when(contentBlockRepository.findById("notARealId")).thenReturn(Optional.empty()); + managerToTest.updateContentOrder(contentBlocks); + } + + @Test + public void test_getAllContentBlocks_success() throws BlockDoesNotExistException { + + String slideId = "slide1"; + ISlide slide = new Slide(); + slide.setId(slideId); + ContentBlock firstContentBlock = new ContentBlock(); + firstContentBlock.setId("contentBlockId1"); + firstContentBlock.setContentOrder(Integer.valueOf(3)); + + ContentBlock secondContentBlock = new ContentBlock(); + secondContentBlock.setId("contentBlockId2"); + secondContentBlock.setContentOrder(Integer.valueOf(4)); + + List contentBlocks = new ArrayList<>(); + contentBlocks.add(firstContentBlock); + contentBlocks.add(secondContentBlock); + slide.setContents(contentBlocks); + when(slideManager.getSlide(slideId)).thenReturn(slide); + when(slideRepo.findById("notARealId")).thenReturn(Optional.empty()); + + List contentBlock = managerToTest.getAllContentBlocks(slideId); + assertTrue(!contentBlock.isEmpty()); + + } + + @Test + public void test_deleteChoiceBlockById_success() throws BlockDoesNotExistException { + String blockId = "realBlockId"; + String slideId = "realSlideId"; + when(contentBlockRepository.findById(blockId)).thenReturn(Optional.of(contentBlock)); + managerToTest.deleteChoiceBlockById(blockId, slideId); + + } + + @Test + public void test_deleteChoiceBlockById_nullBlockId() throws BlockDoesNotExistException { + String blockId = null; + String slideId = "realSlideId"; + managerToTest.deleteChoiceBlockById(blockId, slideId); + + } + + @Test(expected = BlockDoesNotExistException.class) + public void test_deleteChoiceBlockById_missingContentBlock() throws BlockDoesNotExistException { + String blockId = "realBlockId"; + String slideId = "realSlideId"; + when(contentBlockRepository.findById(blockId)).thenReturn(Optional.empty()); + managerToTest.deleteChoiceBlockById(blockId, slideId); + + } + + @Test(expected = BlockDoesNotExistException.class) + public void test_deleteChoiceBlockById_nonExistentContentBlock() throws BlockDoesNotExistException { + String blockId = "realBlockId"; + String slideId = "realSlideId"; + when(contentBlockRepository.findById(blockId)).thenReturn(Optional.of(contentBlock)); + Mockito.doThrow(EmptyResultDataAccessException.class).when(choiceBlockRepo).deleteById(blockId); + managerToTest.deleteChoiceBlockById(blockId, slideId); + + } + + @Test + public void test_updateImageBlock_success1() throws ImageCouldNotBeStoredException { + String slideId = "realSlideId"; + String fileName = "dummyFile"; + ISlide slide = new Slide(); + slide.setId(slideId); + IVSImage slideContentImage = new VSImage(); + slideContentImage.setHeight(700); + slideContentImage.setWidth(1300); + slideContentImage.setFilename(fileName); + byte[] image = new byte[1000]; + IImageBlock imageBlock = new ImageBlock(); + when(slideManager.getSlide(slideId)).thenReturn(slide); + when(imageFactory.createImage(fileName, fileName)).thenReturn(slideContentImage); + when(imageRepo.save((VSImage) slideContentImage)).thenReturn((VSImage) slideContentImage); + managerToTest.updateImageBlock(imageBlock, image, fileName); + + } + + @Test + public void test_updateImageBlock_success2() throws ImageCouldNotBeStoredException { + + IVSImage slideContentImage = new VSImage(); + slideContentImage.setHeight(700); + slideContentImage.setWidth(1300); + IImageBlock imageBlock = new ImageBlock(); + managerToTest.updateImageBlock(imageBlock, slideContentImage); + + } + + @Test + public void test_createImageBlock_success() throws ImageCouldNotBeStoredException, FileStorageException { + String slideId = "slide1"; + String fileName = "dummyFile"; + String contentType = "application/octet-stream"; + Integer contentOrder = 3; + ISlide slide = new Slide(); + slide.setId(slideId); + IVSImage slideContentImage = new VSImage(); + slideContentImage.setHeight(700); + slideContentImage.setWidth(1300); + IImageBlock imageBlock = new ImageBlock(); + imageBlock.setContentOrder(contentOrder); + byte[] image = new byte[1000]; + String relativePathString = ""; + + when(slideManager.getSlide(slideId)).thenReturn(slide); + when(imageFactory.createImage(fileName, contentType)).thenReturn(slideContentImage); + when(storage.storeFile(image, fileName, contentType)).thenReturn(relativePathString); + when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); + Mockito.when(imageRepo.save((VSImage) slideContentImage)).thenReturn((VSImage) slideContentImage); + Mockito.when(imageBlockFactory.createImageBlock(slide, slideContentImage)).thenReturn(imageBlock); + managerToTest.createImageBlock(slideId, image, fileName, contentOrder); + + } + + @Test + public void test_createImageBlock2_success() throws ImageCouldNotBeStoredException, FileStorageException { + String slideId = "slide1"; + String fileName = "dummyFile"; + String contentType = "application/octet-stream"; + Integer contentOrder = 3; + ISlide slide = new Slide(); + slide.setId(slideId); + IVSImage slideContentImage = new VSImage(); + slideContentImage.setHeight(700); + slideContentImage.setWidth(1300); + IImageBlock imageBlock = new ImageBlock(); + imageBlock.setContentOrder(contentOrder); + + when(slideManager.getSlide(slideId)).thenReturn(slide); + when(imageFactory.createImage(fileName, contentType)).thenReturn(slideContentImage); + when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); + Mockito.when(imageBlockFactory.createImageBlock(slide, slideContentImage)).thenReturn(imageBlock); + CreationReturnValue returnValue = managerToTest.createImageBlock(slideId, slideContentImage, contentOrder); + assertNotNull(returnValue); + + } + + @Test + public void test_saveSpaceBlock_success() throws BlockDoesNotExistException { + ISpaceBlock spaceBlock = new SpaceBlock(); + spaceBlock.setContentOrder(3); + spaceBlock.setId("spaceBlock1"); + managerToTest.saveSpaceBlock(spaceBlock); + Mockito.verify(spaceBlockRepo).save((SpaceBlock) spaceBlock); + + } + + @Test + public void test_createTextBlock_success() throws BlockDoesNotExistException { + + String slideId = "slideId"; + ISlide slide = null; + Integer contentOrder = 2; + String titleString = "Title1"; + String text = "text123"; + ITextBlock textBlock = new TextBlock(); + + Mockito.when(slideManager.getSlide(slideId)).thenReturn(slide); + Mockito.when(textBlockFactory.createTextBlock(slide, text)).thenReturn(textBlock); + Mockito.when(textBlockRepo.save((TextBlock) textBlock)).thenReturn((TextBlock) textBlock); + ITextBlock createdBlock = managerToTest.createTextBlock(titleString, text, contentOrder); + + Assert.assertEquals(createdBlock.getContentOrder(), contentOrder); + + } + + @Test + public void test_updateTextBlock_success() throws BlockDoesNotExistException { + TextBlock textBlock = new TextBlock(); + textBlock.setContentOrder(3); + textBlock.setId("textBlock1"); + managerToTest.updateTextBlock(textBlock); + Mockito.verify(textBlockRepo).save((TextBlock) textBlock); + + } + + @Test + public void test_getTextBlock_success() throws BlockDoesNotExistException { + String textblockID = "textBlock1"; + TextBlock textBlock = new TextBlock(); + textBlock.setId(textblockID); + when(textBlockRepo.findById(textblockID)).thenReturn(Optional.of(textBlock)); + ITextBlock retrievedTextBlock = managerToTest.getTextBlock(textblockID); + assertEquals(textblockID, retrievedTextBlock.getId()); + + } + + @Test + public void test_getChoiceBlock_success() throws BlockDoesNotExistException { + String choiceBlockID = "choiceBlock1"; + ChoiceBlock choiceBlock = new ChoiceBlock(); + choiceBlock.setId(choiceBlockID); + when(choiceBlockRepo.findById(choiceBlockID)).thenReturn(Optional.of(choiceBlock)); + IChoiceBlock retrievedChoiceBlock = managerToTest.getChoiceBlock(choiceBlockID); + assertEquals(choiceBlockID, retrievedChoiceBlock.getId()); + + } + + @Test + public void test_getImageBlock_success() throws BlockDoesNotExistException { + String imgBlockId = "imgBlockId"; + ImageBlock imageBlock = new ImageBlock(); + imageBlock.setId(imgBlockId); + when(imageBlockRepo.findById(imgBlockId)).thenReturn(Optional.of(imageBlock)); + IImageBlock retrievedImageBlock = managerToTest.getImageBlock(imgBlockId); + assertEquals(imgBlockId, retrievedImageBlock.getId()); + + } + + @Test + public void test_createChoiceBlock_success() throws BlockDoesNotExistException { + + String slideId = "slideId"; + Integer contentOrder = 2; + String choiceString = "abcd"; + List selectedChoices = new ArrayList(); + selectedChoices.add(choiceString); + IChoice choice = new Choice(); + ISlide slide = new Slide(); + slide.setId(slideId); + List choices = new ArrayList(); + IChoiceBlock choiceBlock = new ChoiceBlock(); + choiceBlock.setChoices(choices); + choiceBlock.setContentOrder(contentOrder); + + Mockito.when(slideManager.getChoice(choiceString)).thenReturn(choice); + Mockito.when(slideManager.getSlide(slideId)).thenReturn(slide); + Mockito.when(choiceBlockFactory.createChoiceBlock(slide, contentOrder, choices, true)).thenReturn(choiceBlock); + Mockito.when(choiceBlockRepo.save((ChoiceBlock) choiceBlock)).thenReturn((ChoiceBlock) choiceBlock); + IChoiceBlock createdChoiceBlock = managerToTest.createChoiceBlock(slideId, selectedChoices, contentOrder, true); + Assert.assertEquals(createdChoiceBlock.getContentOrder(), contentOrder); + + } } From 509407a6434a4d233a5d63e76ca6c9c1a93ac5b8 Mon Sep 17 00:00:00 2001 From: Baishali Nayak Date: Mon, 11 Jul 2022 15:26:30 -0700 Subject: [PATCH 054/135] [VSPC-171] Addressed review comments --- .../vspace/web/staff/SlideController.java | 5 +- .../impl/ContentBlockManagerTest.java | 59 +++++++++++++------ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/SlideController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/SlideController.java index d620fa8b7..5ed7fbeb9 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/SlideController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/SlideController.java @@ -15,8 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import com.fasterxml.jackson.core.JsonProcessingException; - import edu.asu.diging.vspace.core.model.IBranchingPoint; import edu.asu.diging.vspace.core.model.IContentBlock; import edu.asu.diging.vspace.core.model.ISlide; @@ -40,8 +38,7 @@ public class SlideController { private IContentBlockManager contentBlockManager; @RequestMapping("/staff/module/{moduleId}/slide/{id}") - public String listSlides(@PathVariable("id") String id, @PathVariable("moduleId") String moduleId, Model model) - throws JsonProcessingException { + public String listSlides(@PathVariable("id") String id, @PathVariable("moduleId") String moduleId, Model model) { ISlide slide = slideManager.getSlide(id); model.addAttribute("module", moduleManager.getModule(moduleId)); diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java index 2cd77618c..3c57d91a5 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java @@ -163,7 +163,7 @@ public void test_deleteSpaceBlockById_forNonExistentId() throws BlockDoesNotExis } @Test - public void test_deleteSpaceBlock_success() throws BlockDoesNotExistException { + public void test_deleteSpaceBlockById_success() throws BlockDoesNotExistException { String spaceBlockId = "realId"; when(contentBlockRepository.findById(spaceBlockId)).thenReturn(Optional.of(contentBlock)); managerToTest.deleteSpaceBlockById(spaceBlockId, "slideId_1"); @@ -179,11 +179,17 @@ public void test_createSpaceBlock_success() { Integer contentOrder = 2; Space space = new Space(); ISpaceBlock spaceBlock = new SpaceBlock(); + spaceBlock.setTitle(title); + spaceBlock.setId(slideId); + spaceBlock.setSpace(space); Mockito.when(slideManager.getSlide(slideId)).thenReturn(slide); Mockito.when(spaceBlockRepo.save((SpaceBlock) spaceBlock)).thenReturn((SpaceBlock) spaceBlock); Mockito.when(spaceBlockFactory.createSpaceBlock(slide, title, (ISpace) space)).thenReturn(spaceBlock); ISpaceBlock createdBlock = managerToTest.createSpaceBlock(slideId, title, contentOrder, space); Assert.assertEquals(createdBlock.getContentOrder(), contentOrder); + Assert.assertEquals(createdBlock.getTitle(), title); + Assert.assertEquals(createdBlock.getId(), slideId); + Assert.assertEquals(createdBlock.getSpace(), space); } @Test @@ -303,23 +309,22 @@ public void test_getAllContentBlocks_success() throws BlockDoesNotExistException String slideId = "slide1"; ISlide slide = new Slide(); slide.setId(slideId); + String contentBlockIdString = "contentBlockId1"; ContentBlock firstContentBlock = new ContentBlock(); - firstContentBlock.setId("contentBlockId1"); + firstContentBlock.setId(contentBlockIdString); firstContentBlock.setContentOrder(Integer.valueOf(3)); - ContentBlock secondContentBlock = new ContentBlock(); - secondContentBlock.setId("contentBlockId2"); - secondContentBlock.setContentOrder(Integer.valueOf(4)); - List contentBlocks = new ArrayList<>(); contentBlocks.add(firstContentBlock); - contentBlocks.add(secondContentBlock); slide.setContents(contentBlocks); when(slideManager.getSlide(slideId)).thenReturn(slide); when(slideRepo.findById("notARealId")).thenReturn(Optional.empty()); - List contentBlock = managerToTest.getAllContentBlocks(slideId); - assertTrue(!contentBlock.isEmpty()); + List returnedContentBlock = managerToTest.getAllContentBlocks(slideId); + assertEquals(returnedContentBlock.get(0).getId(),contentBlockIdString); + assertEquals(returnedContentBlock.size(),contentBlocks.size()); + assertEquals(returnedContentBlock.get(0).getContentOrder(), Integer.valueOf(3)); + assertTrue(!returnedContentBlock.isEmpty()); } @@ -329,6 +334,7 @@ public void test_deleteChoiceBlockById_success() throws BlockDoesNotExistExcepti String slideId = "realSlideId"; when(contentBlockRepository.findById(blockId)).thenReturn(Optional.of(contentBlock)); managerToTest.deleteChoiceBlockById(blockId, slideId); + Mockito.verify(choiceBlockRepo).deleteById(blockId); } @@ -337,6 +343,7 @@ public void test_deleteChoiceBlockById_nullBlockId() throws BlockDoesNotExistExc String blockId = null; String slideId = "realSlideId"; managerToTest.deleteChoiceBlockById(blockId, slideId); + Mockito.verify(choiceBlockRepo, Mockito.never()).deleteById(blockId); } @@ -346,6 +353,7 @@ public void test_deleteChoiceBlockById_missingContentBlock() throws BlockDoesNot String slideId = "realSlideId"; when(contentBlockRepository.findById(blockId)).thenReturn(Optional.empty()); managerToTest.deleteChoiceBlockById(blockId, slideId); + Mockito.verify(choiceBlockRepo, Mockito.never()).deleteById(blockId); } @@ -356,6 +364,7 @@ public void test_deleteChoiceBlockById_nonExistentContentBlock() throws BlockDoe when(contentBlockRepository.findById(blockId)).thenReturn(Optional.of(contentBlock)); Mockito.doThrow(EmptyResultDataAccessException.class).when(choiceBlockRepo).deleteById(blockId); managerToTest.deleteChoiceBlockById(blockId, slideId); + Mockito.verify(choiceBlockRepo, Mockito.never()).deleteById(blockId); } @@ -375,6 +384,7 @@ public void test_updateImageBlock_success1() throws ImageCouldNotBeStoredExcepti when(imageFactory.createImage(fileName, fileName)).thenReturn(slideContentImage); when(imageRepo.save((VSImage) slideContentImage)).thenReturn((VSImage) slideContentImage); managerToTest.updateImageBlock(imageBlock, image, fileName); + Mockito.verify(imageBlockRepo).save((ImageBlock)imageBlock); } @@ -386,14 +396,16 @@ public void test_updateImageBlock_success2() throws ImageCouldNotBeStoredExcepti slideContentImage.setWidth(1300); IImageBlock imageBlock = new ImageBlock(); managerToTest.updateImageBlock(imageBlock, slideContentImage); + Mockito.verify(imageBlockRepo).save((ImageBlock)imageBlock); } @Test - public void test_createImageBlock_success() throws ImageCouldNotBeStoredException, FileStorageException { + public void test_createImageBlock_success1() throws ImageCouldNotBeStoredException, FileStorageException { String slideId = "slide1"; String fileName = "dummyFile"; String contentType = "application/octet-stream"; + String createdBy = "Baishali"; Integer contentOrder = 3; ISlide slide = new Slide(); slide.setId(slideId); @@ -401,25 +413,31 @@ public void test_createImageBlock_success() throws ImageCouldNotBeStoredExceptio slideContentImage.setHeight(700); slideContentImage.setWidth(1300); IImageBlock imageBlock = new ImageBlock(); - imageBlock.setContentOrder(contentOrder); + imageBlock.setCreatedBy(createdBy); + imageBlock.setImage(slideContentImage); + imageBlock.setId(slideId); byte[] image = new byte[1000]; String relativePathString = ""; when(slideManager.getSlide(slideId)).thenReturn(slide); when(imageFactory.createImage(fileName, contentType)).thenReturn(slideContentImage); when(storage.storeFile(image, fileName, contentType)).thenReturn(relativePathString); - when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); + Mockito.when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); Mockito.when(imageRepo.save((VSImage) slideContentImage)).thenReturn((VSImage) slideContentImage); Mockito.when(imageBlockFactory.createImageBlock(slide, slideContentImage)).thenReturn(imageBlock); - managerToTest.createImageBlock(slideId, image, fileName, contentOrder); - + CreationReturnValue returnValue = managerToTest.createImageBlock(slideId, image, fileName, contentOrder); + assertEquals(returnValue.getElement().getCreatedBy(), createdBy); + assertEquals(returnValue.getElement().getId(), slideId); + assertNotNull(returnValue); + } @Test - public void test_createImageBlock2_success() throws ImageCouldNotBeStoredException, FileStorageException { + public void test_createImageBlock_success2() throws ImageCouldNotBeStoredException, FileStorageException { String slideId = "slide1"; String fileName = "dummyFile"; String contentType = "application/octet-stream"; + String createdBy = "Baishali"; Integer contentOrder = 3; ISlide slide = new Slide(); slide.setId(slideId); @@ -427,13 +445,17 @@ public void test_createImageBlock2_success() throws ImageCouldNotBeStoredExcepti slideContentImage.setHeight(700); slideContentImage.setWidth(1300); IImageBlock imageBlock = new ImageBlock(); - imageBlock.setContentOrder(contentOrder); + imageBlock.setCreatedBy(createdBy); + imageBlock.setImage(slideContentImage); + imageBlock.setId(slideId); when(slideManager.getSlide(slideId)).thenReturn(slide); when(imageFactory.createImage(fileName, contentType)).thenReturn(slideContentImage); when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); Mockito.when(imageBlockFactory.createImageBlock(slide, slideContentImage)).thenReturn(imageBlock); CreationReturnValue returnValue = managerToTest.createImageBlock(slideId, slideContentImage, contentOrder); + assertEquals(returnValue.getElement().getCreatedBy(), createdBy); + assertEquals(returnValue.getElement().getId(), slideId); assertNotNull(returnValue); } @@ -457,13 +479,16 @@ public void test_createTextBlock_success() throws BlockDoesNotExistException { String titleString = "Title1"; String text = "text123"; ITextBlock textBlock = new TextBlock(); + textBlock.setId(slideId); + textBlock.setText(text); Mockito.when(slideManager.getSlide(slideId)).thenReturn(slide); Mockito.when(textBlockFactory.createTextBlock(slide, text)).thenReturn(textBlock); Mockito.when(textBlockRepo.save((TextBlock) textBlock)).thenReturn((TextBlock) textBlock); ITextBlock createdBlock = managerToTest.createTextBlock(titleString, text, contentOrder); - Assert.assertEquals(createdBlock.getContentOrder(), contentOrder); + Assert.assertEquals(createdBlock.getId(), slideId); + Assert.assertEquals(createdBlock.getText(), text); } From c208d600bc475a478eb19d116843202275d75326 Mon Sep 17 00:00:00 2001 From: Baishali Nayak Date: Tue, 12 Jul 2022 15:37:09 -0700 Subject: [PATCH 055/135] [VSPC-171] changed method name --- .../impl/ContentBlockManagerTest.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java index 3c57d91a5..6b8959969 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java @@ -321,8 +321,8 @@ public void test_getAllContentBlocks_success() throws BlockDoesNotExistException when(slideRepo.findById("notARealId")).thenReturn(Optional.empty()); List returnedContentBlock = managerToTest.getAllContentBlocks(slideId); - assertEquals(returnedContentBlock.get(0).getId(),contentBlockIdString); - assertEquals(returnedContentBlock.size(),contentBlocks.size()); + assertEquals(returnedContentBlock.get(0).getId(), contentBlockIdString); + assertEquals(returnedContentBlock.size(), contentBlocks.size()); assertEquals(returnedContentBlock.get(0).getContentOrder(), Integer.valueOf(3)); assertTrue(!returnedContentBlock.isEmpty()); @@ -369,7 +369,7 @@ public void test_deleteChoiceBlockById_nonExistentContentBlock() throws BlockDoe } @Test - public void test_updateImageBlock_success1() throws ImageCouldNotBeStoredException { + public void test_updateImageBlock_successImageUpdatedWithFilename() throws ImageCouldNotBeStoredException { String slideId = "realSlideId"; String fileName = "dummyFile"; ISlide slide = new Slide(); @@ -384,24 +384,25 @@ public void test_updateImageBlock_success1() throws ImageCouldNotBeStoredExcepti when(imageFactory.createImage(fileName, fileName)).thenReturn(slideContentImage); when(imageRepo.save((VSImage) slideContentImage)).thenReturn((VSImage) slideContentImage); managerToTest.updateImageBlock(imageBlock, image, fileName); - Mockito.verify(imageBlockRepo).save((ImageBlock)imageBlock); + Mockito.verify(imageBlockRepo).save((ImageBlock) imageBlock); } @Test - public void test_updateImageBlock_success2() throws ImageCouldNotBeStoredException { + public void test_updateImageBlock_successImageUpdated() throws ImageCouldNotBeStoredException { IVSImage slideContentImage = new VSImage(); slideContentImage.setHeight(700); slideContentImage.setWidth(1300); IImageBlock imageBlock = new ImageBlock(); managerToTest.updateImageBlock(imageBlock, slideContentImage); - Mockito.verify(imageBlockRepo).save((ImageBlock)imageBlock); + Mockito.verify(imageBlockRepo).save((ImageBlock) imageBlock); } @Test - public void test_createImageBlock_success1() throws ImageCouldNotBeStoredException, FileStorageException { + public void test_createImageBlock_successImageCreatedWithFilename() + throws ImageCouldNotBeStoredException, FileStorageException { String slideId = "slide1"; String fileName = "dummyFile"; String contentType = "application/octet-stream"; @@ -425,18 +426,17 @@ public void test_createImageBlock_success1() throws ImageCouldNotBeStoredExcepti Mockito.when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); Mockito.when(imageRepo.save((VSImage) slideContentImage)).thenReturn((VSImage) slideContentImage); Mockito.when(imageBlockFactory.createImageBlock(slide, slideContentImage)).thenReturn(imageBlock); - CreationReturnValue returnValue = managerToTest.createImageBlock(slideId, image, fileName, contentOrder); + CreationReturnValue returnValue = managerToTest.createImageBlock(slideId, image, fileName, contentOrder); assertEquals(returnValue.getElement().getCreatedBy(), createdBy); assertEquals(returnValue.getElement().getId(), slideId); assertNotNull(returnValue); - + } @Test - public void test_createImageBlock_success2() throws ImageCouldNotBeStoredException, FileStorageException { + public void test_createImageBlock_successImageCreated() + throws ImageCouldNotBeStoredException, FileStorageException { String slideId = "slide1"; - String fileName = "dummyFile"; - String contentType = "application/octet-stream"; String createdBy = "Baishali"; Integer contentOrder = 3; ISlide slide = new Slide(); @@ -450,7 +450,6 @@ public void test_createImageBlock_success2() throws ImageCouldNotBeStoredExcepti imageBlock.setId(slideId); when(slideManager.getSlide(slideId)).thenReturn(slide); - when(imageFactory.createImage(fileName, contentType)).thenReturn(slideContentImage); when(imageBlockRepo.save((ImageBlock) imageBlock)).thenReturn((ImageBlock) imageBlock); Mockito.when(imageBlockFactory.createImageBlock(slide, slideContentImage)).thenReturn(imageBlock); CreationReturnValue returnValue = managerToTest.createImageBlock(slideId, slideContentImage, contentOrder); From ff24e7123cfaffefc6e1983080e2f431cc856fe0 Mon Sep 17 00:00:00 2001 From: Baishali Nayak Date: Fri, 10 Mar 2023 16:21:26 -0700 Subject: [PATCH 056/135] [VSPC-171] testing junits --- .../services/impl/ContentBlockManager.java | 3 ++- .../impl/ContentBlockManagerTest.java | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java index 515de4b4d..1266e854b 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java @@ -162,10 +162,11 @@ private IVSVideo saveVideoWithUrl(String url, String title) { return videoRepo.save((VSVideo) vidContent); } - private IVSVideo saveVideo(byte[] video, Long size, String filename, String title) { + public IVSVideo saveVideo(byte[] video, Long size, String filename, String title) { if (video != null && video.length > 0) { Tika tika = new Tika(); String contentType = tika.detect(video); + System.out.println(contentType); IVSVideo slideContentVideo = videoFactory.createVideo(filename, size, contentType); slideContentVideo.setTitle(title); slideContentVideo = videoRepo.save((VSVideo) slideContentVideo); diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java index 0fdee750c..d4c29c151 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java @@ -96,6 +96,7 @@ public class ContentBlockManagerTest { @Mock private SpaceBlockFactory spaceBlockFactory; + @Mock private ChoiceContentBlockRepository choiceBlockRepo; @Mock @@ -577,7 +578,7 @@ public void test_getChoiceBlock_success() throws BlockDoesNotExistException { String choiceBlockID = "choiceBlock1"; ChoiceBlock choiceBlock = new ChoiceBlock(); choiceBlock.setId(choiceBlockID); - when(choiceBlockRepo.findById(choiceBlockID)).thenReturn(Optional.of(choiceBlock)); + when(choiceBlockRepo.findById(Mockito.anyString())).thenReturn(Optional.of(choiceBlock)); IChoiceBlock retrievedChoiceBlock = managerToTest.getChoiceBlock(choiceBlockID); assertEquals(choiceBlockID, retrievedChoiceBlock.getId()); @@ -781,4 +782,24 @@ public void test_createVideoBlock_withVideoURLnull() assertEquals(vblk.getId(), "videoBlock_1"); } + @Test + public void test_updateVideoBlock_success() + throws BlockDoesNotExistException, FileStorageException, VideoCouldNotBeStoredException, IOException { + ISlide slide = new Slide(); + slide.setId("slideId_1"); + when(slideManager.getSlide("slideId_1")).thenReturn(slide); + IVSVideo slideContentVideo = null; + IVideoBlock vidBlock = new VideoBlock(); + when(videoBlockFactory.createVideoBlock(slide, slideContentVideo)).thenReturn(vidBlock); + when(videoRepo.save((VSVideo) slideContentVideo)).thenReturn((VSVideo) slideContentVideo); + ContentBlockManager contentBlockManager = Mockito.spy(managerToTest); + Mockito.when(contentBlockManager.saveVideo(new byte[20], 200L, "title","Baishali")) + .thenReturn(slideContentVideo); + IVideoBlock videoBlock = new VideoBlock(); + videoBlock.setId("videoBlock_1"); + when(videoBlockRepo.save((VideoBlock) vidBlock)).thenReturn((VideoBlock) videoBlock); + managerToTest.updateVideoBlock(videoBlock, new byte[20], 200L, null, null, "video_title"); + + } + } From 6e25188f720a6117a0ee8e6f3dcaa7bc18a44049 Mon Sep 17 00:00:00 2001 From: Baishali Nayak Date: Tue, 14 Mar 2023 12:51:11 -0700 Subject: [PATCH 057/135] [VSPC-171] JUNITS --- .../impl/ContentBlockManagerTest.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java index d4c29c151..2fd756de9 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java @@ -782,24 +782,6 @@ public void test_createVideoBlock_withVideoURLnull() assertEquals(vblk.getId(), "videoBlock_1"); } - @Test - public void test_updateVideoBlock_success() - throws BlockDoesNotExistException, FileStorageException, VideoCouldNotBeStoredException, IOException { - ISlide slide = new Slide(); - slide.setId("slideId_1"); - when(slideManager.getSlide("slideId_1")).thenReturn(slide); - IVSVideo slideContentVideo = null; - IVideoBlock vidBlock = new VideoBlock(); - when(videoBlockFactory.createVideoBlock(slide, slideContentVideo)).thenReturn(vidBlock); - when(videoRepo.save((VSVideo) slideContentVideo)).thenReturn((VSVideo) slideContentVideo); - ContentBlockManager contentBlockManager = Mockito.spy(managerToTest); - Mockito.when(contentBlockManager.saveVideo(new byte[20], 200L, "title","Baishali")) - .thenReturn(slideContentVideo); - IVideoBlock videoBlock = new VideoBlock(); - videoBlock.setId("videoBlock_1"); - when(videoBlockRepo.save((VideoBlock) vidBlock)).thenReturn((VideoBlock) videoBlock); - managerToTest.updateVideoBlock(videoBlock, new byte[20], 200L, null, null, "video_title"); - - } + } From 93de9069c09336e374bd253d8ff56789e0cfe101 Mon Sep 17 00:00:00 2001 From: Baishali Nayak Date: Tue, 14 Mar 2023 15:51:40 -0700 Subject: [PATCH 058/135] [VSPC-171] addressed review comments --- .../services/impl/ContentBlockManager.java | 6 +++--- .../web/staff/EditSpaceBlockController.java | 2 +- .../web/staff/api/SearchSpacesController.java | 6 +++--- .../impl/ContentBlockManagerTest.java | 21 ++++++++++++++++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java index 1266e854b..47f700f3a 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java @@ -166,7 +166,6 @@ public IVSVideo saveVideo(byte[] video, Long size, String filename, String title if (video != null && video.length > 0) { Tika tika = new Tika(); String contentType = tika.detect(video); - System.out.println(contentType); IVSVideo slideContentVideo = videoFactory.createVideo(filename, size, contentType); slideContentVideo.setTitle(title); slideContentVideo = videoRepo.save((VSVideo) slideContentVideo); @@ -265,10 +264,12 @@ public CreationReturnValue createVideoBlock(String slideId, byte[] video, Long s return returnValue; } - private IVSVideo storeVideo(byte[] video, Long size, String fileName, String url, String title) + public IVSVideo storeVideo(byte[] video, Long size, String fileName, String url, String title) throws VideoCouldNotBeStoredException { IVSVideo slideContentVideo = null; + if (video != null) { + slideContentVideo = saveVideo(video, size, fileName, title); storeVideoFile(video, slideContentVideo, fileName); slideContentVideo.setUrl(null); @@ -461,7 +462,6 @@ public void updateImageBlock(IImageBlock imageBlock, IVSImage image) { public void updateVideoBlock(IVideoBlock videoBlock, byte[] video, Long fileSize, String url, String filename, String title) throws VideoCouldNotBeStoredException { IVSVideo slideContentVideo = storeVideo(video, fileSize, filename, url, title); - videoBlock.setVideo(slideContentVideo); videoBlockRepo.save((VideoBlock) videoBlock); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java index 284b63f44..fe097c3c6 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java @@ -40,7 +40,7 @@ public ResponseEntity editSpaceBlock(@PathVariable("id") String slideId, spaceBlock.setTitle(spaceBlockTitle); spaceBlock.setSpace(space); contentBlockManager.updateSpaceBlock( spaceBlock); - + logger.debug("ContentBlock has been Updated"); return new ResponseEntity(HttpStatus.OK); } } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/api/SearchSpacesController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/api/SearchSpacesController.java index f7430c563..343238157 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/api/SearchSpacesController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/api/SearchSpacesController.java @@ -23,10 +23,10 @@ public class SearchSpacesController { private ISpaceManager spaceManager; @RequestMapping("/staff/spaces/search") - public ResponseEntity search(@RequestParam(value = "term", required = false) String searchTerm){ + public ResponseEntity search(@RequestParam(value = "term", required = false) String search){ List spaces = null; - if (searchTerm != null && !searchTerm.trim().isEmpty()) { - spaces = spaceManager.findByName(searchTerm); + if (search != null && !search.trim().isEmpty()) { + spaces = spaceManager.findByName(search); } else { spaces = spaceManager.getAllSpaces(); } diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java index 2fd756de9..ed1e11dfd 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java @@ -782,6 +782,25 @@ public void test_createVideoBlock_withVideoURLnull() assertEquals(vblk.getId(), "videoBlock_1"); } - + @Test + public void test_updateVideoBlock_success() + throws BlockDoesNotExistException, FileStorageException, VideoCouldNotBeStoredException, IOException { + ISlide slide = new Slide(); + slide.setId("slideId_1"); + when(slideManager.getSlide("slideId_1")).thenReturn(slide); + IVSVideo slideContentVideo = new VSVideo(); + slideContentVideo.setId("videoId_1"); + IVideoBlock vidBlock = new VideoBlock(); + videoBlock.setId("videoBlock_1"); + when(videoBlockFactory.createVideoBlock(slide, slideContentVideo)).thenReturn(vidBlock); + when(videoRepo.save((VSVideo) slideContentVideo)).thenReturn((VSVideo) slideContentVideo); + when(videoFactory.createVideo("newFile.mp4", 200L, "application/octet-stream")).thenReturn(slideContentVideo); + ContentBlockManager contentBlockManager = Mockito.spy(managerToTest); + when(contentBlockManager.storeVideo(new byte[20], 200L,"newFile.mp4", "url", "title")).thenReturn(slideContentVideo); + when(contentBlockManager.saveVideo(new byte[20], 200L,"newFile.mp4", "title")).thenReturn(slideContentVideo); + when(videoBlockRepo.save((VideoBlock) vidBlock)).thenReturn( videoBlock); + managerToTest.updateVideoBlock(videoBlock, new byte[20], 200L, "url", "newFile.mp4", "video_title"); + + } } From 45b7fcfe7033cb1a24fc9f4d4bbe2a5f3be8f87e Mon Sep 17 00:00:00 2001 From: Baishali Nayak Date: Tue, 18 Apr 2023 15:15:11 -0700 Subject: [PATCH 059/135] [VSPC-171] addressed review comments --- .../web/staff/EditSpaceBlockController.java | 13 +- .../views/staff/modules/slides/slide.html | 891 +----------------- 2 files changed, 11 insertions(+), 893 deletions(-) diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java index fe097c3c6..68b41c484 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java @@ -21,26 +21,23 @@ @Controller public class EditSpaceBlockController { - - private final Logger logger = LoggerFactory.getLogger(getClass()); - + @Autowired private IContentBlockManager contentBlockManager; - + @Autowired private ISpaceManager spaceManager; @RequestMapping(value = "/staff/module/{moduleId}/slide/{id}/space/edit", method = RequestMethod.POST) public ResponseEntity editSpaceBlock(@PathVariable("id") String slideId, @RequestParam("spaceBlockId") String blockId, @PathVariable("moduleId") String moduleId, - @RequestParam("spaceBlockTitle") String spaceBlockTitle, - @RequestParam("spaceId") String spaceId) throws IOException { + @RequestParam("spaceBlockTitle") String spaceBlockTitle, @RequestParam("spaceId") String spaceId) + throws IOException { ISpaceBlock spaceBlock = contentBlockManager.getSpaceBlock(blockId); ISpace space = spaceManager.getSpace(spaceId); spaceBlock.setTitle(spaceBlockTitle); spaceBlock.setSpace(space); - contentBlockManager.updateSpaceBlock( spaceBlock); - logger.debug("ContentBlock has been Updated"); + contentBlockManager.updateSpaceBlock(spaceBlock); return new ResponseEntity(HttpStatus.OK); } } diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html index df5fdfb6a..bfbfcd88a 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html @@ -28,60 +28,12 @@ } - - - - - - - - -
- -
- -
-
-

- Slide: - [[${slide.name}]] -

-

[[${slide.description}]]

-
- -
-
- -   - -   - -   - -
-

Double click on a block to edit it. - Drag and drop blocks to change their order.

-
- - - - - - - - - - - - - - -
-
-
- - - -
-
-
-

- [[${contents.video.title}]] -

-
- - -
- - - - -
-
-

[[${contents.text}]]

- - - -
- -
-
-
- - + \ No newline at end of file From 086d46422749068e2774767eca4966d595343e1f Mon Sep 17 00:00:00 2001 From: Baishali Nayak Date: Thu, 20 Apr 2023 11:28:34 -0700 Subject: [PATCH 060/135] [VSPC-171] addressed review comments --- .../impl/ContentBlockManagerTest.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java index ed1e11dfd..577e021b0 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManagerTest.java @@ -325,14 +325,6 @@ public void test_deleteImageBlockById_forNonExistentId() throws BlockDoesNotExis managerToTest.deleteImageBlockById(imageBlockId, "slideId_1"); } - @Test - public void test_deleteImagetBlockById_whenIdIsNull() throws BlockDoesNotExistException { - String imageBlockId = null; - managerToTest.deleteImageBlockById(null, "slideId_1"); - Mockito.verify(imageBlockRepo, Mockito.never()).deleteById(imageBlockId); - - } - @Test public void test_updateContentOrder_success() throws BlockDoesNotExistException { ContentBlock firstContentBlock = new ContentBlock(); @@ -408,6 +400,14 @@ public void test_deleteChoiceBlockById_nullBlockId() throws BlockDoesNotExistExc } + @Test + public void test_deleteImagetBlockById_whenIdIsNull() throws BlockDoesNotExistException { + String imageBlockId = null; + managerToTest.deleteImageBlockById(null, "slideId_1"); + Mockito.verify(imageBlockRepo, Mockito.never()).deleteById(imageBlockId); + + } + @Test(expected = BlockDoesNotExistException.class) public void test_deleteChoiceBlockById_missingContentBlock() throws BlockDoesNotExistException { String blockId = "realBlockId"; @@ -794,11 +794,12 @@ public void test_updateVideoBlock_success() videoBlock.setId("videoBlock_1"); when(videoBlockFactory.createVideoBlock(slide, slideContentVideo)).thenReturn(vidBlock); when(videoRepo.save((VSVideo) slideContentVideo)).thenReturn((VSVideo) slideContentVideo); - when(videoFactory.createVideo("newFile.mp4", 200L, "application/octet-stream")).thenReturn(slideContentVideo); + when(videoFactory.createVideo("newFile.mp4", 200L, "application/octet-stream")).thenReturn(slideContentVideo); ContentBlockManager contentBlockManager = Mockito.spy(managerToTest); - when(contentBlockManager.storeVideo(new byte[20], 200L,"newFile.mp4", "url", "title")).thenReturn(slideContentVideo); - when(contentBlockManager.saveVideo(new byte[20], 200L,"newFile.mp4", "title")).thenReturn(slideContentVideo); - when(videoBlockRepo.save((VideoBlock) vidBlock)).thenReturn( videoBlock); + when(contentBlockManager.storeVideo(new byte[20], 200L, "newFile.mp4", "url", "title")) + .thenReturn(slideContentVideo); + when(contentBlockManager.saveVideo(new byte[20], 200L, "newFile.mp4", "title")).thenReturn(slideContentVideo); + when(videoBlockRepo.save((VideoBlock) vidBlock)).thenReturn(videoBlock); managerToTest.updateVideoBlock(videoBlock, new byte[20], 200L, "url", "newFile.mp4", "video_title"); } From eb4e19081d26970b45f2e66f8847f6ecdb40783c Mon Sep 17 00:00:00 2001 From: pkharge Date: Thu, 28 Sep 2023 16:18:25 -0700 Subject: [PATCH 061/135] [story/VSPC-171] review comments --- .../vspace/core/services/IContentBlockManager.java | 2 +- .../vspace/core/services/impl/ContentBlockManager.java | 5 ----- .../vspace/web/staff/EditSpaceBlockController.java | 2 +- .../webapp/WEB-INF/views/staff/modules/slides/slide.html | 9 ++++++++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java index f70c202df..8f3632f1f 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IContentBlockManager.java @@ -82,7 +82,7 @@ IChoiceBlock createChoiceBlock(String slideId, List selectedChoices, Int void updateContentOrder(List contentBlockList) throws BlockDoesNotExistException; - void updateSpaceBlock(ISpaceBlock spaceBlock); +// void updateSpaceBlock(ISpaceBlock spaceBlock); void saveVideoBlock(IVideoBlock videoBlock); diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java index 47f700f3a..844850d46 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ContentBlockManager.java @@ -589,11 +589,6 @@ private void updateContentOrder(String slideId, Integer contentOrder) { } } - @Override - public void updateSpaceBlock(ISpaceBlock spaceBlock) { - spaceBlockRepo.save((SpaceBlock) spaceBlock); - } - @Override public void saveVideoBlock(IVideoBlock videoBlock) { videoRepo.save((VSVideo) videoBlock.getVideo()); diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java index 68b41c484..5e060a917 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditSpaceBlockController.java @@ -37,7 +37,7 @@ public ResponseEntity editSpaceBlock(@PathVariable("id") String slideId, ISpace space = spaceManager.getSpace(spaceId); spaceBlock.setTitle(spaceBlockTitle); spaceBlock.setSpace(space); - contentBlockManager.updateSpaceBlock(spaceBlock); + contentBlockManager.saveSpaceBlock(spaceBlock); return new ResponseEntity(HttpStatus.OK); } } diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html index bfbfcd88a..831838fe1 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/modules/slides/slide.html @@ -1405,14 +1405,21 @@ +