diff --git a/README.md b/README.md index c9193b92e..627fa9789 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,6 @@ ![Docker Image Version (latest by date)](https://img.shields.io/docker/v/digingasu/virtual-spaces?color=yellow&label=Docker%20Hub&sort=date) -Virtual Spaces 2.0 let's you build virtual exhibitions through a web application. Upload images of your (virtual or real) spaces and link them by placing links on them. Create modules that provide more details about the topics you present. +Virtual Spaces 2.0 lets you build virtual exhibitions through a web application. Upload images of your (virtual or real) spaces and link them by placing links on them. Create modules that provide more details about the topics you present. You can find Virtual Spaces documentation [here](https://diging.atlassian.net/wiki/spaces/VS2D). diff --git a/vspace/.classpath b/vspace/.classpath index 9d58bf752..3aa72561a 100644 --- a/vspace/.classpath +++ b/vspace/.classpath @@ -49,4 +49,4 @@ - + \ No newline at end of file diff --git a/vspace/pom.xml b/vspace/pom.xml index 53d5b0be7..d5fcef347 100644 --- a/vspace/pom.xml +++ b/vspace/pom.xml @@ -40,6 +40,7 @@ TomcatServer + v0.16.1 diff --git a/vspace/src/main/java/edu/asu/diging/simpleusers/web/admin/UsersUtility.java b/vspace/src/main/java/edu/asu/diging/simpleusers/web/admin/UsersUtility.java new file mode 100644 index 000000000..40b272e85 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/simpleusers/web/admin/UsersUtility.java @@ -0,0 +1,27 @@ +package edu.asu.diging.simpleusers.web.admin; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.springframework.security.core.authority.SimpleGrantedAuthority; + +/** + * Utility class that contains methods for ListUsersController + * @author Glen Dsouza + */ +public class UsersUtility { + + /** + * This method checks if the User has a specific Role assigned to them. + * It takes as parameter a set of User Roles of the type SimpleGrantedAuthority + * and it validates if the User Role exists with the second parameter which is + * a String of the type of Role we need to validate. + * @param userRoles a set of SimpleGrantedAuthority containing details of the roles assigned to a User + * @param role the role that needs to be checked against userRoles + * @return Boolean: True if User is assigned the role, else False. + */ + public static Boolean checkUserRoleExists(Set userRoles, String role) { + return userRoles.stream().anyMatch(roleKey -> (roleKey.toString().equals(role))); + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/data/ModuleRepository.java b/vspace/src/main/java/edu/asu/diging/vspace/core/data/ModuleRepository.java index 36913f981..34292dfb2 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/data/ModuleRepository.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/data/ModuleRepository.java @@ -3,9 +3,12 @@ import java.util.List; import org.javers.spring.annotation.JaversSpringDataAuditable; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; +import edu.asu.diging.vspace.core.model.IModule; import edu.asu.diging.vspace.core.model.impl.Module; @Repository @@ -13,7 +16,9 @@ public interface ModuleRepository extends PagingAndSortingRepository { List findTop5ByOrderByCreationDateDesc(); - - List findAllByOrderByCreationDateDesc(); + Page findDistinctByNameContainingOrDescriptionContaining(Pageable requestedPage, String name, + String description); + + List findAllByOrderByCreationDateDesc(); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/data/SlideRepository.java b/vspace/src/main/java/edu/asu/diging/vspace/core/data/SlideRepository.java index 11d27b9a5..5ce307643 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/data/SlideRepository.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/data/SlideRepository.java @@ -3,10 +3,13 @@ import java.util.List; import org.javers.spring.annotation.JaversSpringDataAuditable; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; +import edu.asu.diging.vspace.core.model.ISlide; import edu.asu.diging.vspace.core.model.impl.Sequence; import edu.asu.diging.vspace.core.model.impl.Slide; @@ -16,8 +19,11 @@ public interface SlideRepository extends PagingAndSortingRepository findSlidesForModule(String moduleId); - + @Query("SELECT d.sequence FROM Slide d WHERE d.id = ?1") public List getSequencesForSlide(String slideId); + Page findDistinctByNameContainingOrDescriptionContaining(Pageable requestedPage, String name, + String description); + } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/data/SpaceRepository.java b/vspace/src/main/java/edu/asu/diging/vspace/core/data/SpaceRepository.java index 6b1a1d334..7107d36e2 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/data/SpaceRepository.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/data/SpaceRepository.java @@ -3,9 +3,12 @@ import java.util.List; import org.javers.spring.annotation.JaversSpringDataAuditable; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; +import edu.asu.diging.vspace.core.model.ISpace; import edu.asu.diging.vspace.core.model.impl.Space; import edu.asu.diging.vspace.core.model.impl.SpaceStatus; @@ -19,4 +22,6 @@ public interface SpaceRepository extends PagingAndSortingRepository findAllByImageId(String imageId); + Page findDistinctByNameContainingOrDescriptionContaining(Pageable requestedPage, String name, + String description); } \ No newline at end of file diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/data/TextContentBlockRepository.java b/vspace/src/main/java/edu/asu/diging/vspace/core/data/TextContentBlockRepository.java index be7604f95..24c64d7dc 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/data/TextContentBlockRepository.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/data/TextContentBlockRepository.java @@ -1,13 +1,20 @@ package edu.asu.diging.vspace.core.data; import org.javers.spring.annotation.JaversSpringDataAuditable; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; +import edu.asu.diging.vspace.core.model.ISlide; import edu.asu.diging.vspace.core.model.impl.TextBlock; @Repository @JaversSpringDataAuditable public interface TextContentBlockRepository extends PagingAndSortingRepository { + @Query("SELECT DISTINCT c.slide FROM ContentBlock c, TextBlock t WHERE c.id = t.id AND t.text LIKE %?1%") + public Page findWithNameOrDescription(Pageable requestedPage, String searchText); + } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISlide.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISlide.java index 3c0774842..59985eee6 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISlide.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/ISlide.java @@ -11,5 +11,8 @@ public interface ISlide extends IVSpaceElement { void setContents(List contents); List getContents(); - + + IImageBlock getFirstImageBlock(); + + ITextBlock getFirstMatchedTextBlock(String searchTerm); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/ITextBlock.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/ITextBlock.java index f5e7fd69a..b86e08556 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/model/ITextBlock.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/ITextBlock.java @@ -9,5 +9,7 @@ public interface ITextBlock extends IContentBlock { void setId(String id); String getId(); + + String htmlRenderedText(); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/Slide.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/Slide.java index a073f7e07..350de758e 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/Slide.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/Slide.java @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Optional; import javax.persistence.CascadeType; import javax.persistence.Entity; @@ -18,28 +19,28 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import edu.asu.diging.vspace.core.model.IContentBlock; +import edu.asu.diging.vspace.core.model.IImageBlock; import edu.asu.diging.vspace.core.model.IModule; import edu.asu.diging.vspace.core.model.ISequence; import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ITextBlock; @Entity public class Slide extends VSpaceElement implements ISlide { @Id @GeneratedValue(generator = "slide_id_generator") - @GenericGenerator(name = "slide_id_generator", - parameters = @Parameter(name = "prefix", value = "SLI"), - strategy = "edu.asu.diging.vspace.core.data.IdGenerator") + @GenericGenerator(name = "slide_id_generator", parameters = @Parameter(name = "prefix", value = "SLI"), strategy = "edu.asu.diging.vspace.core.data.IdGenerator") private String id; @ManyToOne(targetEntity = Module.class) private IModule module; - //-------- @JsonIgnore used as this entity will be returned in a controller - @JsonIgnore + // -------- @JsonIgnore used as this entity will be returned in a controller + @JsonIgnore @OneToMany(targetEntity = ContentBlock.class, mappedBy = "slide", cascade = CascadeType.ALL) private List contents; - + @JsonIgnore @ManyToMany(mappedBy = "slides", targetEntity = Sequence.class) private List sequence; @@ -77,8 +78,7 @@ public IModule getModule() { /* * (non-Javadoc) * - * @see - * edu.asu.diging.vspace.core.model.impl.ISlide#setImage(edu.asu.diging. + * @see edu.asu.diging.vspace.core.model.impl.ISlide#setImage(edu.asu.diging. * vspace. core.model.IModule) */ @Override @@ -106,15 +106,14 @@ public int compare(IContentBlock o1, IContentBlock o2) { /* * (non-Javadoc) * - * @see - * edu.asu.diging.vspace.core.model.impl.ISlide#setContents(edu.asu.diging. + * @see edu.asu.diging.vspace.core.model.impl.ISlide#setContents(edu.asu.diging. * vspace. core.model.IContentBlock) */ @Override public void setContents(List contents) { this.contents = contents; } - + /* * (non-Javadoc) * @@ -127,12 +126,51 @@ public List getSequence() { /* * (non-Javadoc) * - * @see - * edu.asu.diging.vspace.core.model.impl.ISlide#setSequence(java.util.List) + * @see edu.asu.diging.vspace.core.model.impl.ISlide#setSequence(java.util.List) */ public void setSequence(List sequence) { this.sequence = sequence; } + /** + * This Method will retrieve the first ImageBlock of a slide if the ImageBlock + * is present + * + * @return IImageBlock + */ + @Override + @JsonIgnore + public IImageBlock getFirstImageBlock() { + List allBlocks = getContents(); + if (allBlocks != null) { + Optional firstImageBlock = allBlocks.stream() + .filter(contentBlock -> contentBlock instanceof ImageBlock).findFirst(); + if (firstImageBlock.isPresent()) { + return (ImageBlock) firstImageBlock.get(); + } + } + return null; + } + /** + * This Method will return the first Text block whose content has searchTerm in + * it. + * + * @param searchTerm the search string which is being searched. + * @return TextBlock + */ + @Override + @JsonIgnore + public ITextBlock getFirstMatchedTextBlock(String searchTerm) { + List allBlocks = getContents(); + if (allBlocks != null) { + Optional firstMatchedTextBlock = allBlocks.stream() + .filter(contentBlock -> contentBlock instanceof TextBlock) + .filter(contentBlock -> ((TextBlock) contentBlock).getText().contains(searchTerm)).findFirst(); + if (firstMatchedTextBlock.isPresent()) { + return (TextBlock) firstMatchedTextBlock.get(); + } + } + return null; + } } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/TextBlock.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/TextBlock.java index 3e6db108f..2ffb5a31b 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/TextBlock.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/TextBlock.java @@ -37,6 +37,13 @@ public void setText(String text) { this.text = text; } + /* + * (non-Javadoc) + * + * @see + * edu.asu.diging.vspace.core.model.impl.ITextBlock#htmlRenderedText() + */ + @Override @Transient public String htmlRenderedText() { Parser parser = Parser.builder().build(); @@ -44,5 +51,4 @@ public String htmlRenderedText() { HtmlRenderer renderer = HtmlRenderer.builder().build(); return renderer.render(document); } - } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IModuleManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IModuleManager.java index 5f5e74b23..d8956f85e 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IModuleManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IModuleManager.java @@ -2,6 +2,9 @@ import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + import edu.asu.diging.vspace.core.model.IModule; import edu.asu.diging.vspace.core.model.ISequence; import edu.asu.diging.vspace.core.model.ISlide; @@ -19,5 +22,6 @@ public interface IModuleManager { List getModuleSequences(String moduleId); ISequence checkIfSequenceExists(String moduleId, String sequenceId); - + + Page findByNameOrDescription(Pageable requestedPage,String searchText); } \ No newline at end of file diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/ISlideManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/ISlideManager.java index b08b27249..947f4c9ce 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/ISlideManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/ISlideManager.java @@ -1,14 +1,17 @@ package edu.asu.diging.vspace.core.services; +import java.util.List; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + import edu.asu.diging.vspace.core.model.IBranchingPoint; +import edu.asu.diging.vspace.core.model.IChoice; import edu.asu.diging.vspace.core.model.IModule; import edu.asu.diging.vspace.core.model.ISlide; import edu.asu.diging.vspace.core.model.display.SlideType; -import java.util.List; - import edu.asu.diging.vspace.core.model.impl.Sequence; import edu.asu.diging.vspace.core.model.impl.Slide; -import edu.asu.diging.vspace.core.model.IChoice; import edu.asu.diging.vspace.web.staff.forms.SlideForm; public interface ISlideManager { @@ -28,5 +31,6 @@ public interface ISlideManager { void deleteSlideById(String slideId, String moduleId); List getSlideSequences(String slideId, String moduleId); - + + Page findByNameOrDescription(Pageable requestedPage,String searchText); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/ISpaceManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/ISpaceManager.java index e1e046e6a..ec812cdfd 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/ISpaceManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/ISpaceManager.java @@ -2,6 +2,9 @@ import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + import edu.asu.diging.vspace.core.exception.SpaceDoesNotExistException; import edu.asu.diging.vspace.core.model.ISpace; import edu.asu.diging.vspace.core.model.IVSImage; @@ -33,5 +36,6 @@ public interface ISpaceManager { List getIncomingLinks(String id); Iterable addIncomingLinkInfoToSpaces(Iterable spaces); - + + Page findByNameOrDescription(Pageable requestedPage,String searchText); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/IStaffSearchManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IStaffSearchManager.java new file mode 100644 index 000000000..a358b2e68 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/IStaffSearchManager.java @@ -0,0 +1,18 @@ +package edu.asu.diging.vspace.core.services; + +import org.springframework.data.domain.Page; + +import edu.asu.diging.vspace.core.model.IModule; +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ISpace; + +public interface IStaffSearchManager { + + Page searchInSpaces(String searchTerm, int page); + + Page searchInModules(String searchTerm, int page); + + Page searchInSlides(String searchTerm, int page); + + Page searchInSlideTexts(String searchTerm, int page); +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ModuleManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ModuleManager.java index 5d8b6e06d..29e30db40 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ModuleManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ModuleManager.java @@ -8,6 +8,8 @@ import javax.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import edu.asu.diging.vspace.core.data.ModuleRepository; @@ -82,4 +84,9 @@ public List getModuleSequences(String moduleId) { public ISequence checkIfSequenceExists(String moduleId, String sequenceId) { return sequenceRepo.findSequenceForModuleAndSequence(moduleId,sequenceId); } + + @Override + public Page findByNameOrDescription(Pageable requestedPage,String searchText) { + return moduleRepo.findDistinctByNameContainingOrDescriptionContaining(requestedPage,searchText,searchText); + } } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SlideManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SlideManager.java index bb92a52c3..fefd99c1e 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SlideManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SlideManager.java @@ -10,6 +10,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import edu.asu.diging.vspace.core.data.BranchingPointRepository; @@ -30,7 +32,6 @@ import edu.asu.diging.vspace.core.services.ISlideManager; import edu.asu.diging.vspace.web.staff.forms.SlideForm; - @Service public class SlideManager implements ISlideManager { @@ -56,33 +57,39 @@ public class SlideManager implements ISlideManager { @Override public ISlide createSlide(IModule module, SlideForm slideForm, SlideType type) { - ISlide slide = slideFactory.createSlide(module, slideForm, type); + ISlide slide = slideFactory.createSlide(module, slideForm, type); return slideRepo.save((Slide) slide); } @Override public IBranchingPoint createBranchingPoint(IModule module, SlideForm slideForm, SlideType type) { - ISlide branchingPoint = slideFactory.createSlide(module, slideForm, type); + ISlide branchingPoint = slideFactory.createSlide(module, slideForm, type); return bpointRepo.save((BranchingPoint) branchingPoint); } @Override public void updateBranchingPoint(IBranchingPoint branchingPoint, List editedChoiceSequenceIds) { - List existingChoices=branchingPoint.getChoices(); - List existingChoiceSequenceIds=existingChoices.stream().map(choiceSequence -> choiceSequence.getSequence().getId()).collect(Collectors.toList()); - List deletedChoiceSequenceIds = (List) CollectionUtils.subtract(existingChoiceSequenceIds, editedChoiceSequenceIds); - List addedChoiceSequenceIds = (List) CollectionUtils.subtract(editedChoiceSequenceIds,existingChoiceSequenceIds); + List existingChoices = branchingPoint.getChoices(); + List existingChoiceSequenceIds = existingChoices.stream() + .map(choiceSequence -> choiceSequence.getSequence().getId()).collect(Collectors.toList()); + List deletedChoiceSequenceIds = (List) CollectionUtils.subtract(existingChoiceSequenceIds, + editedChoiceSequenceIds); + List addedChoiceSequenceIds = (List) CollectionUtils.subtract(editedChoiceSequenceIds, + existingChoiceSequenceIds); List newlyAddedChoices = choiceFactory.createChoices(addedChoiceSequenceIds); existingChoices.addAll(newlyAddedChoices); - List choicesToDelete = existingChoices.stream().filter(choice -> deletedChoiceSequenceIds.contains(choice.getSequence().getId())).collect(Collectors.toList()); + List choicesToDelete = existingChoices.stream() + .filter(choice -> deletedChoiceSequenceIds.contains(choice.getSequence().getId())) + .collect(Collectors.toList()); existingChoices.removeIf(choice -> deletedChoiceSequenceIds.contains(choice.getSequence().getId())); branchingPoint.setChoices(existingChoices); bpointRepo.save((BranchingPoint) branchingPoint); /* - * We did not use deleteAll on choiceRepo as choicesToDelete is a list of IChoice - * and cannot be casted into Choice and objects of other type can also implement IChoice + * We did not use deleteAll on choiceRepo as choicesToDelete is a list of + * IChoice and cannot be casted into Choice and objects of other type can also + * implement IChoice */ - for(IChoice deletedChoice : choicesToDelete) { + for (IChoice deletedChoice : choicesToDelete) { choiceRepo.deleteById(deletedChoice.getId()); } } @@ -112,7 +119,7 @@ public void updateSlide(Slide slide) { @Override public void deleteSlideById(String slideId, String moduleId) { - if(slideId == null) { + if (slideId == null) { logger.error("Slide Id cannot be null."); return; } @@ -121,11 +128,11 @@ public void deleteSlideById(String slideId, String moduleId) { Slide slideObj = (Slide) getSlide(slideId); List slideObjToRemove = new ArrayList<>(); slideObjToRemove.add(slideObj); - if(slideObj == null) { + if (slideObj == null) { return; } for (Sequence sequence : sequences) { - if(sequence.getSlides().contains(slideObj)) { + if (sequence.getSlides().contains(slideObj)) { sequence.getSlides().removeAll(slideObjToRemove); sequenceRepo.save(sequence); } @@ -154,4 +161,10 @@ public List getSlideSequences(String slideId, String moduleId) { } return sequenceSlides; } + + @Override + public Page findByNameOrDescription(Pageable requestedPage, String searchText) { + + return slideRepo.findDistinctByNameContainingOrDescriptionContaining(requestedPage, searchText,searchText); + } } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SpaceManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SpaceManager.java index 12ad85664..63884749c 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SpaceManager.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/SpaceManager.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Optional; -import javax.persistence.EntityNotFoundException; import javax.transaction.Transactional; import org.apache.tika.Tika; @@ -13,6 +12,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.PropertySource; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import edu.asu.diging.vspace.core.data.ExhibitionRepository; @@ -291,4 +292,9 @@ public Iterable addIncomingLinkInfoToSpaces(Iterable spaces) { } return spaces; } + + @Override + public Page findByNameOrDescription(Pageable requestedPage, String searchText) { + return spaceRepo.findDistinctByNameContainingOrDescriptionContaining(requestedPage, searchText,searchText); + } } \ No newline at end of file diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/StaffSearchManager.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/StaffSearchManager.java new file mode 100644 index 000000000..34ca9c3eb --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/StaffSearchManager.java @@ -0,0 +1,184 @@ +package edu.asu.diging.vspace.core.services.impl; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import edu.asu.diging.vspace.core.data.TextContentBlockRepository; +import edu.asu.diging.vspace.core.model.IModule; +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ISpace; +import edu.asu.diging.vspace.core.services.IModuleManager; +import edu.asu.diging.vspace.core.services.ISlideManager; +import edu.asu.diging.vspace.core.services.ISpaceManager; +import edu.asu.diging.vspace.core.services.IStaffSearchManager; + +/** + * This class has all the methods with the business logics for searching a word + * in staff page. + * + * @author Avirup Biswas + * + */ +@Service +public class StaffSearchManager implements IStaffSearchManager { + + @Value("${page_size}") + private int pageSize; + + @Autowired + private ISpaceManager spaceManager; + + @Autowired + private IModuleManager moduleManager; + + @Autowired + private ISlideManager slideManager; + + @Autowired + private TextContentBlockRepository textContentBlockRepo; + + /** + * Method to return the requested spaces whose name or description contains the + * search string + * + * @param searchTerm string which has been searched + * @param page. The page number starts from 1. + * @return set of spaces whose name or description contains the search string in + * the requested page. + */ + @Override + public Page searchInSpaces(String searchTerm, int page) { + /* if page<1, 1st page is returned */ + if (page < 1) { + page = 1; + } + Pageable requestedPageForSpace = PageRequest.of(page - 1, pageSize); + Page spacePage = spaceManager.findByNameOrDescription(requestedPageForSpace, searchTerm); + int totalSpacePage = spacePage.getTotalPages(); + /* + * spring will just return an empty dataset if a page that is greater than the + * total number of pages is returned. So, the page given (except when it's < 1, + * then set it to 1) and then checking if the total page count is smaller than + * the given one (if so, make another request). In most cases the page number + * will be within the range of pages, so we would need only one db call. Only in + * cases where the page number is wrong, would a second one be needed.if + * page>total pages,last page is returned. + */ + if (page > totalSpacePage) { + totalSpacePage = totalSpacePage == 0 ? 1 : totalSpacePage; + requestedPageForSpace = PageRequest.of(totalSpacePage - 1, pageSize); + spacePage = spaceManager.findByNameOrDescription(requestedPageForSpace, searchTerm); + } + return spacePage; + } + + /** + * Method to return the requested modules whose name or description contains the + * search string + * + * @param searchTerm string which has been searched + * @param page. The page number starts from 1. + * @return set of modules whose name or description contains the search string + * in the requested page. + */ + @Override + public Page searchInModules(String searchTerm, int page) { + /* if page<1, 1st page is returned */ + if (page < 1) { + page = 1; + } + Pageable requestedPageForModule = PageRequest.of(page - 1, pageSize); + Page modulePage = moduleManager.findByNameOrDescription(requestedPageForModule, searchTerm); + int totalModulePage = modulePage.getTotalPages(); + /* + * spring will just return an empty dataset if a page that is greater than the + * total number of pages is returned. So, the page given (except when it's < 1, + * then set it to 1) and then checking if the total page count is smaller than + * the given one (if so, make another request). In most cases the page number + * will be within the range of pages, so we would need only one db call. Only in + * cases where the page number is wrong, would a second one be needed.if + * page>total pages,last page is returned. + */ + if (page > totalModulePage) { + totalModulePage = totalModulePage == 0 ? 1 : totalModulePage; + requestedPageForModule = PageRequest.of(totalModulePage - 1, pageSize); + modulePage = moduleManager.findByNameOrDescription(requestedPageForModule, searchTerm); + } + return modulePage; + } + + /** + * Method to return the requested slides whose name or description contains the + * search string + * + * @param searchTerm string which has been searched + * @param page. The page number starts from 1. + * @return set of slides whose name or description contains the search string in + * the requested page. + */ + @Override + public Page searchInSlides(String searchTerm, int page) { + /* if page<1, 1st page is returned */ + if (page < 1) { + page = 1; + } + Pageable requestedPageForSlide = PageRequest.of(page - 1, pageSize); + Page slidePage = slideManager.findByNameOrDescription(requestedPageForSlide, searchTerm); + int totalSlidePage = slidePage.getTotalPages(); + /* + * spring will just return an empty dataset if a page that is greater than the + * total number of pages is returned. So, the page given (except when it's < 1, + * then set it to 1) and then checking if the total page count is smaller than + * the given one (if so, make another request). In most cases the page number + * will be within the range of pages, so we would need only one db call. Only in + * cases where the page number is wrong, would a second one be needed.if + * page>total pages,last page is returned. + */ + if (page > totalSlidePage) { + totalSlidePage = totalSlidePage == 0 ? 1 : totalSlidePage; + requestedPageForSlide = PageRequest.of(totalSlidePage - 1, pageSize); + slidePage = slideManager.findByNameOrDescription(requestedPageForSlide, searchTerm); + } + return slidePage; + } + + /** + * Method to return the requested slides whose text blocks contains the search + * string + * + * @param searchTerm string which has been searched + * @param page. The page number starts from 1. + * @return list of slides whose text blocks contains the search string in the + * requested page. + */ + @Override + public Page searchInSlideTexts(String searchTerm, int page) { + /* if page<1, 1st page is returned */ + if (page < 1) { + page = 1; + } + Pageable requestedPageForSlideText = PageRequest.of(page - 1, pageSize); + Page slidetextPage = textContentBlockRepo.findWithNameOrDescription(requestedPageForSlideText, + searchTerm); + int totalSlideTextPage = slidetextPage.getTotalPages(); + /* + * spring will just return an empty dataset if a page that is greater than the + * total number of pages is returned. So, the page given (except when it's < 1, + * then set it to 1) and then checking if the total page count is smaller than + * the given one (if so, make another request). In most cases the page number + * will be within the range of pages, so we would need only one db call. Only in + * cases where the page number is wrong, would a second one be needed.if + * page>total pages,last page is returned. + */ + if (page > totalSlideTextPage) { + totalSlideTextPage = totalSlideTextPage == 0 ? 1 : totalSlideTextPage; + requestedPageForSlideText = PageRequest.of(totalSlideTextPage - 1, pageSize); + slidetextPage = textContentBlockRepo.findWithNameOrDescription(requestedPageForSlideText, searchTerm); + } + return slidetextPage; + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchModuleResults.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchModuleResults.java new file mode 100644 index 000000000..7020f2318 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchModuleResults.java @@ -0,0 +1,39 @@ +package edu.asu.diging.vspace.core.services.impl.model; + +import java.util.List; +import java.util.Map; + +import edu.asu.diging.vspace.core.model.IModule; + +public class StaffSearchModuleResults { + + private List modules; + + private Map moduleImageIdMap; + + private Map moduleAlertMessages; + + public List getModules() { + return modules; + } + + public void setModules(List modules) { + this.modules = modules; + } + + public Map getModuleImageIdMap() { + return moduleImageIdMap; + } + + public void setModuleImageIdMap(Map moduleImageIdMap) { + this.moduleImageIdMap = moduleImageIdMap; + } + + public Map getModuleAlertMessages() { + return moduleAlertMessages; + } + + public void setModuleAlertMessages(Map moduleAlertMessages) { + this.moduleAlertMessages = moduleAlertMessages; + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSlideResults.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSlideResults.java new file mode 100644 index 000000000..a4da9dd45 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSlideResults.java @@ -0,0 +1,29 @@ +package edu.asu.diging.vspace.core.services.impl.model; + +import java.util.List; +import java.util.Map; + +import edu.asu.diging.vspace.core.model.ISlide; + +public class StaffSearchSlideResults { + + private List slides; + + private Map firstImageOfSlide; + + public List getSlides() { + return slides; + } + + public void setSlides(List slides) { + this.slides = slides; + } + + public Map getFirstImageOfSlide() { + return firstImageOfSlide; + } + + public void setFirstImageOfSlide(Map firstImageOfSlide) { + this.firstImageOfSlide = firstImageOfSlide; + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSlideTextBlockResults.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSlideTextBlockResults.java new file mode 100644 index 000000000..b1dbb2390 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSlideTextBlockResults.java @@ -0,0 +1,40 @@ +package edu.asu.diging.vspace.core.services.impl.model; + +import java.util.List; +import java.util.Map; + +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.impl.Slide; + +public class StaffSearchSlideTextBlockResults { + + private List slidesWithMatchedTextBlock; + + private Map slideToFirstImageMap; + + private Map slideToFirstTextBlockMap; + + public List getSlidesWithMatchedTextBlock() { + return slidesWithMatchedTextBlock; + } + + public void setSlidesWithMatchedTextBlock(List slidesWithMatchedTextBlock) { + this.slidesWithMatchedTextBlock = slidesWithMatchedTextBlock; + } + + public Map getSlideToFirstImageMap() { + return slideToFirstImageMap; + } + + public void setSlideToFirstImageMap(Map slideToFirstImageMap) { + this.slideToFirstImageMap = slideToFirstImageMap; + } + + public Map getSlideToFirstTextBlockMap() { + return slideToFirstTextBlockMap; + } + + public void setSlideToFirstTextBlockMap(Map slideToFirstTextBlockMap) { + this.slideToFirstTextBlockMap = slideToFirstTextBlockMap; + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSpaceResults.java b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSpaceResults.java new file mode 100644 index 000000000..0b31dabf5 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/model/StaffSearchSpaceResults.java @@ -0,0 +1,19 @@ +package edu.asu.diging.vspace.core.services.impl.model; + +import java.util.List; + +import edu.asu.diging.vspace.core.model.ISpace; + +public class StaffSearchSpaceResults { + + private List spaces; + + public List getSpaces() { + return spaces; + } + + public void setSpaces(List spaces) { + this.spaces = spaces; + } + +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddModuleLinkController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddModuleLinkController.java index 5fcf88ac8..eb0b30338 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddModuleLinkController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/AddModuleLinkController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -36,7 +37,7 @@ public class AddModuleLinkController { public ResponseEntity createModuleLink(@PathVariable("id") String id, @RequestParam("x") String x, @RequestParam("y") String y, @RequestParam("rotation") String rotation, @RequestParam("moduleLinkLabel") String title, @RequestParam("linkedModule") String linkedModuleId, @RequestParam("moduleLinkLabel") String moduleLinkLabel, - @RequestParam("type") String displayType) + @RequestParam("moduleType") String displayType, @RequestParam("moduleLinkImage") MultipartFile file) throws NumberFormatException, SpaceDoesNotExistException, IOException, ImageCouldNotBeStoredException { ISpace source = spaceManager.getSpace(id); @@ -50,12 +51,19 @@ public ResponseEntity createModuleLink(@PathVariable("id") String id, @R node.put("errorMessage", "No link coordinates specified."); return new ResponseEntity(mapper.writeValueAsString(node), HttpStatus.BAD_REQUEST); } - + + byte[] linkImage = null; + String filename = null; + if (file != null) { + linkImage = file.getBytes(); + filename = file.getOriginalFilename(); + } + DisplayType type = displayType.isEmpty() ? null : DisplayType.valueOf(displayType); IModuleLinkDisplay display; try { display = moduleLinkManager.createLink(title, id, new Float(x), new Float(y), - new Integer(rotation), linkedModuleId, moduleLinkLabel, type, null, null); + new Integer(rotation), linkedModuleId, moduleLinkLabel, type, linkImage, filename); } catch (SpaceDoesNotExistException e) { ObjectMapper mapper = new ObjectMapper(); ObjectNode node = mapper.createObjectNode(); diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/DashboardController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/DashboardController.java index 27d6ef5d8..1ec954eef 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/DashboardController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/DashboardController.java @@ -30,4 +30,4 @@ public String displayDashboard(Model model) { return "staff/dashboard/dashboard"; } -} +} \ No newline at end of file diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditModuleLinkController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditModuleLinkController.java index cf9b31a27..8d64eb2ae 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditModuleLinkController.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/EditModuleLinkController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; import edu.asu.diging.vspace.core.exception.ImageCouldNotBeStoredException; import edu.asu.diging.vspace.core.exception.LinkDoesNotExistsException; @@ -32,16 +33,22 @@ public ResponseEntity editModuleLink(@PathVariable("id") String id, @Req @RequestParam("y") String y, @RequestParam("rotation") String rotation, @RequestParam("moduleLinkLabel") String title, @RequestParam("linkedModule") String linkedModuleId, @RequestParam("moduleLinkLabel") String moduleLinkLabel, @RequestParam("moduleLinkIdValueEdit") String moduleLinkIdValueEdit, @RequestParam("moduleLinkDisplayId") String moduleLinkDisplayId, - @RequestParam("type") String displayType) + @RequestParam("type") String displayType, @RequestParam("moduleLinkImage") MultipartFile file) throws NumberFormatException, SpaceDoesNotExistException, LinkDoesNotExistsException, IOException, ImageCouldNotBeStoredException { ResponseEntity validation = checkIfSpaceExists(spaceManager, id, x, y); if(validation!=null) { return validation; } + byte[] linkImage = null; + String filename = null; + if (file != null) { + linkImage = file.getBytes(); + filename = file.getOriginalFilename(); + } DisplayType type = displayType.isEmpty() ? null : DisplayType.valueOf(displayType); IModuleLinkDisplay display = (IModuleLinkDisplay) moduleLinkManager.updateLink(title, id, new Float(x), new Float(y), - new Integer(rotation), linkedModuleId, moduleLinkLabel, moduleLinkIdValueEdit, moduleLinkDisplayId, type, null, null); + new Integer(rotation), linkedModuleId, moduleLinkLabel, moduleLinkIdValueEdit, moduleLinkDisplayId, type, linkImage, filename); return success(display.getLink().getId(), display.getId(), display.getPositionX(), display.getPositionY(), display.getRotation(),null,title,displayType,linkedModuleId,null); } diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchController.java new file mode 100644 index 000000000..6ee62cbdc --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchController.java @@ -0,0 +1,120 @@ +package edu.asu.diging.vspace.web.staff; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import edu.asu.diging.vspace.core.model.IModule; +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ISpace; +import edu.asu.diging.vspace.core.model.impl.Module; +import edu.asu.diging.vspace.core.model.impl.Slide; +import edu.asu.diging.vspace.core.model.impl.Space; +import edu.asu.diging.vspace.core.services.IStaffSearchManager; + +@Controller +public class StaffSearchController { + + @Autowired + private IStaffSearchManager staffSearchManager; + + @RequestMapping(value = "/staff/search") + public String searchInVspace( + @RequestParam(value = "spacePagenum", required = false, defaultValue = "1") String spacePagenum, + @RequestParam(value = "modulePagenum", required = false, defaultValue = "1") String modulePagenum, + @RequestParam(value = "slidePagenum", required = false, defaultValue = "1") String slidePagenum, + @RequestParam(value = "slideTextPagenum", required = false, defaultValue = "1") String slideTextPagenum, + Model model, @RequestParam(name = "searchText") String searchTerm) { + + paginationForSpace(spacePagenum, model, searchTerm); + + paginationForModule(modulePagenum, model, searchTerm); + + paginationForSlide(slidePagenum, model, searchTerm); + + paginationForSlideText(slideTextPagenum, model, searchTerm); + + model.addAttribute("searchWord", searchTerm); + + return "/staff/search/staffSearch"; + } + + /** + * This method is used to search the search string specified in the input + * parameter(searchTerm) and return the spaces corresponding to the page number + * specified in the input parameter(spacePagenum) whose name or description + * contains the search string. The spacePagenum is starting from 1. + * + * @param spacePagenum current page number sent as request parameter in the URL. + * @param model This the object of Model attribute in spring MVC. + * @param searchTerm This is the search string which is being searched. + */ + private void paginationForSpace(String spacePagenum, Model model, String searchTerm) { + Page spacePage = staffSearchManager.searchInSpaces(searchTerm, Integer.parseInt(spacePagenum)); + model.addAttribute("spaceCurrentPageNumber", Integer.parseInt(spacePagenum)); + model.addAttribute("spaceTotalPages", spacePage.getTotalPages()); + model.addAttribute("spaceSearchResults", spacePage.getContent()); + model.addAttribute("spaceCount", spacePage.getTotalElements()); + } + + /** + * This method is used to search the search string specified in the input + * parameter(searchTerm) and return the module corresponding to the page number + * specified in the input parameter(spacePagenum) whose name or description + * contains the search string. The modulePagenum is starting from 1. + * + * @param modulePagenum current page number sent as request parameter in the + * URL. + * @param model This the object of Model attribute in spring MVC. + * @param searchTerm This is the search string which is being searched. + */ + private void paginationForModule(String modulePagenum, Model model, String searchTerm) { + Page modulePage = staffSearchManager.searchInModules(searchTerm, Integer.parseInt(modulePagenum)); + model.addAttribute("moduleCurrentPageNumber", Integer.parseInt(modulePagenum)); + model.addAttribute("moduleTotalPages", modulePage.getTotalPages()); + model.addAttribute("moduleSearchResults", modulePage.getContent()); + model.addAttribute("moduleCount", modulePage.getTotalElements()); + } + + /** + * This method is used to search the search string specified in the input + * parameter(searchTerm) and return the slides corresponding to the page number + * specified in the input parameter(spacePagenum) whose name or description + * contains the search string. The slidePagenum is starting from 1. + * + * @param slidePagenum current page number sent as request parameter in the URL. + * @param model This the object of Model attribute in spring MVC. + * @param searchTerm This is the search string which is being searched. + */ + private void paginationForSlide(String slidePagenum, Model model, String searchTerm) { + Page slidePage = staffSearchManager.searchInSlides(searchTerm, Integer.parseInt(slidePagenum)); + model.addAttribute("slideCurrentPageNumber", Integer.parseInt(slidePagenum)); + model.addAttribute("slideTotalPages", slidePage.getTotalPages()); + model.addAttribute("slideSearchResults", slidePage.getContent()); + model.addAttribute("slideCount", slidePage.getTotalElements()); + } + + /** + * This method is used to search the search string specified in the input + * parameter(searchTerm) and return the slides corresponding to the page number + * specified in the input parameter(spacePagenum) whose text block contains the + * search string. The slideTextPagenum is starting from 1. + * + * @param slideTextPagenum current page number sent as request parameter in the + * URL. + * @param model This the object of Model attribute in spring MVC. + * + * @param searchTerm This is the search string which is being searched. + */ + private void paginationForSlideText(String slideTextPagenum, Model model, String searchTerm) { + Page slideTextPage = staffSearchManager.searchInSlideTexts(searchTerm, + Integer.parseInt(slideTextPagenum)); + model.addAttribute("slideTextCurrentPageNumber", Integer.parseInt(slideTextPagenum)); + model.addAttribute("slideTextTotalPages", slideTextPage.getTotalPages()); + model.addAttribute("slideTextSearchResults", slideTextPage.getContent()); + model.addAttribute("slideTextCount", slideTextPage.getTotalElements()); + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchModuleController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchModuleController.java new file mode 100644 index 000000000..972d730fc --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchModuleController.java @@ -0,0 +1,82 @@ +package edu.asu.diging.vspace.web.staff; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import edu.asu.diging.vspace.core.model.IModule; +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.impl.Slide; +import edu.asu.diging.vspace.core.services.ISequenceManager; +import edu.asu.diging.vspace.core.services.IStaffSearchManager; +import edu.asu.diging.vspace.core.services.impl.model.StaffSearchModuleResults; + +@Controller +public class StaffSearchModuleController { + + @Autowired + private IStaffSearchManager staffSearchManager; + + @Autowired + private ISequenceManager sequenceManager; + + @RequestMapping(value = "/staff/search/module") + public ResponseEntity searchInVspace( + @RequestParam(value = "modulePagenum", required = false, defaultValue = "1") String modulePagenum, + Model model, @RequestParam(name = "searchText") String searchTerm) { + + List moduleList = paginationForModule(modulePagenum, searchTerm); + StaffSearchModuleResults staffSearch = new StaffSearchModuleResults(); + staffSearch.setModules(moduleList); + + Map moduleFirstSlideImage = new HashMap<>(); + Map isModuleConfiguredMap = new HashMap<>(); + + for (IModule module : moduleList) { + if (module.getStartSequence() == null) { + isModuleConfiguredMap.put(module.getId(), false); + moduleFirstSlideImage.put(module.getId(), null); + } else { + isModuleConfiguredMap.put(module.getId(), true); + String startSequenceID = module.getStartSequence().getId(); + List slides = sequenceManager.getSequence(startSequenceID) != null + ? sequenceManager.getSequence(startSequenceID).getSlides() + : null; + + Slide slide = slides != null && !slides.isEmpty() ? (Slide) slides.get(0) : null; + + if (slide != null && slide.getFirstImageBlock() != null) { + moduleFirstSlideImage.put(module.getId(), slide.getFirstImageBlock().getImage().getId()); + } + } + } + staffSearch.setModuleImageIdMap(moduleFirstSlideImage); + staffSearch.setModuleAlertMessages(isModuleConfiguredMap); + return new ResponseEntity(staffSearch, HttpStatus.OK); + } + + /** + * This method is used to search the search string specified in the input + * parameter(searchTerm) and return the module corresponding to the page number + * specified in the input parameter(spacePagenum) whose name or description + * contains the search string. + * + * @param modulePagenum current page number sent as request parameter in the + * URL. + * @param searchTerm This is the search string which is being searched. + */ + private List paginationForModule(String modulePagenum, String searchTerm) { + Page modulePage = staffSearchManager.searchInModules(searchTerm, Integer.parseInt(modulePagenum)); + return modulePage.getContent(); + } + +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSlideController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSlideController.java new file mode 100644 index 000000000..cf7581cc9 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSlideController.java @@ -0,0 +1,59 @@ +package edu.asu.diging.vspace.web.staff; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.services.IStaffSearchManager; +import edu.asu.diging.vspace.core.services.impl.model.StaffSearchSlideResults; + +@Controller +public class StaffSearchSlideController { + + @Autowired + private IStaffSearchManager staffSearchManager; + + @RequestMapping(value = "/staff/search/slide") + public ResponseEntity searchInVspace( + @RequestParam(value = "slidePagenum", required = false, defaultValue = "1") String slidePagenum, + Model model, @RequestParam(name = "searchText") String searchTerm) { + + List slideList = paginationForSlide(slidePagenum, searchTerm); + StaffSearchSlideResults staffSearch = new StaffSearchSlideResults(); + staffSearch.setSlides(slideList); + + Map slideFirstImage = new HashMap<>(); + + for (ISlide slide : slideList) { + if (slide != null && slide.getFirstImageBlock() != null) { + slideFirstImage.put(slide.getId(), slide.getFirstImageBlock().getImage().getId()); + } + } + staffSearch.setFirstImageOfSlide(slideFirstImage); + return new ResponseEntity(staffSearch, HttpStatus.OK); + } + + /** + * This method is used to search the search string specified in the input + * parameter(searchTerm) and return the slides corresponding to + * the page number specified in the input parameter(spacePagenum) whose name or + * description contains the search string. + * + * @param slidePagenum current page number sent as request parameter in the URL. + * @param searchTerm This is the search string which is being searched. + */ + private List paginationForSlide(String slidePagenum, String searchTerm) { + Page slidePage = staffSearchManager.searchInSlides(searchTerm, Integer.parseInt(slidePagenum)); + return slidePage.getContent(); + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSlideTextController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSlideTextController.java new file mode 100644 index 000000000..d0c9f1d54 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSlideTextController.java @@ -0,0 +1,71 @@ +package edu.asu.diging.vspace.web.staff; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.services.IStaffSearchManager; +import edu.asu.diging.vspace.core.services.impl.model.StaffSearchSlideTextBlockResults; + +@Controller +public class StaffSearchSlideTextController { + + @Autowired + private IStaffSearchManager staffSearchManager; + + @RequestMapping(value = "/staff/search/slideText") + public ResponseEntity searchInVspace(HttpServletRequest request, + @RequestParam(value = "slideTextPagenum", required = false, defaultValue = "1") String slideTextPagenum, + Model model, @RequestParam(name = "searchText") String searchTerm) { + + List slideTextList = paginationForSlideText(slideTextPagenum, searchTerm); + StaffSearchSlideTextBlockResults staffSearch = new StaffSearchSlideTextBlockResults(); + staffSearch.setSlidesWithMatchedTextBlock(slideTextList); + + Map slideTextFirstImageMap = new HashMap<>(); + + Map slideTextFirstTextBlockMap = new HashMap<>(); + + for (ISlide slide : slideTextList) { + if (slide != null) { + if (slide.getFirstImageBlock() != null) { + slideTextFirstImageMap.put(slide.getId(), slide.getFirstImageBlock().getImage().getId()); + } + if (slide.getFirstMatchedTextBlock(searchTerm) != null) { + slideTextFirstTextBlockMap.put(slide.getId(), slide.getFirstMatchedTextBlock(searchTerm).htmlRenderedText()); + } + } + } + staffSearch.setSlideToFirstImageMap(slideTextFirstImageMap); + staffSearch.setSlideToFirstTextBlockMap(slideTextFirstTextBlockMap); + return new ResponseEntity(staffSearch, HttpStatus.OK); + } + + /** + * This method is used to search the search string specified in the input + * parameter(searchTerm) and return the slides corresponding to the page number + * specified in the input parameter(spacePagenum) whose text block contains the + * search string + * + * @param slideTextPagenum current page number sent as request parameter in the + * URL. + * @param searchTerm This is the search string which is being searched. + */ + private List paginationForSlideText(String slideTextPagenum, String searchTerm) { + Page slideTextPage = staffSearchManager.searchInSlideTexts(searchTerm, + Integer.parseInt(slideTextPagenum)); + return slideTextPage.getContent(); + } +} diff --git a/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSpaceController.java b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSpaceController.java new file mode 100644 index 000000000..b6ab7ed46 --- /dev/null +++ b/vspace/src/main/java/edu/asu/diging/vspace/web/staff/StaffSearchSpaceController.java @@ -0,0 +1,50 @@ +package edu.asu.diging.vspace.web.staff; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import edu.asu.diging.vspace.core.model.ISpace; +import edu.asu.diging.vspace.core.services.IStaffSearchManager; +import edu.asu.diging.vspace.core.services.impl.model.StaffSearchSpaceResults; + +@Controller +public class StaffSearchSpaceController { + + @Autowired + private IStaffSearchManager staffSearchManager; + + @RequestMapping(value = "/staff/search/space") + public ResponseEntity searchInVspace( + @RequestParam(value = "spacePagenum", required = false, defaultValue = "1") String spacePagenum, + Model model, @RequestParam(name = "searchText") String searchTerm) throws JsonProcessingException { + + List spaceList = paginationForSpace(spacePagenum, searchTerm); + StaffSearchSpaceResults staffSearch = new StaffSearchSpaceResults(); + staffSearch.setSpaces(spaceList); + return new ResponseEntity(staffSearch, HttpStatus.OK); + } + + /** + * This method is used to search the search string specified in the input + * parameter(searchTerm) and return the spaces corresponding to + * the page number specified in the input parameter(spacePagenum) whose name or + * description contains the search string. + * + * @param spacePagenum current page number sent as request parameter in the URL. + * @param searchTerm This is the search string which is being searched. + */ + private List paginationForSpace(String spacePagenum, String searchTerm) { + Page spacePage = staffSearchManager.searchInSpaces(searchTerm, Integer.parseInt(spacePagenum)); + return spacePage.getContent(); + } +} diff --git a/vspace/src/main/resources/config.properties b/vspace/src/main/resources/config.properties index 723d1415a..5aacd55f2 100644 --- a/vspace/src/main/resources/config.properties +++ b/vspace/src/main/resources/config.properties @@ -9,3 +9,4 @@ page_size=10 image_category_SPACE_BACKGROUND_IMAGE=Space Background Image image_category_SLIDE_IMAGE=Slide Image image_category_LINK_IMAGE=Link Image +buildNum=${buildNumber} \ No newline at end of file diff --git a/vspace/src/main/webapp/WEB-INF/views/exhibition/space.html b/vspace/src/main/webapp/WEB-INF/views/exhibition/space.html index 7a4755b12..d65b92ac1 100644 --- a/vspace/src/main/webapp/WEB-INF/views/exhibition/space.html +++ b/vspace/src/main/webapp/WEB-INF/views/exhibition/space.html @@ -209,8 +209,8 @@ let maxWidth='(max-width: 1200px)'; function openNav(){ - $("#mySidenav").css("width", "250px"); - } + $("#mySidenav").css("width", "250px"); + } function closeNav(){ $("#mySidenav").css("width", "0"); } @@ -324,7 +324,7 @@ 'overflow': 'visible' }); } - }) + }); moduleLinks.forEach(function(link,index){ if(link!=null){ var posX = parseInt($("#space").css('margin-left')) + $("#space").position().left; @@ -332,7 +332,13 @@ var moduleLink = $(''); var moduleLinkURL = [[@{|/exhibit/${space?.id}/module/|}]]+link.link.module.id; moduleLink.attr("href", moduleLinkURL); - var linkDisplay = $('
'+link.link.name+'
'); + var linkDisplay; + if(link.type=="IMAGE" && link.image != null){ + var moduleImageURL = [[@{/api/image/}]]+link.image.id; + linkDisplay = $(''); + } else { + linkDisplay = $('
'+link.link.name+'
'); + } linkDisplay.css('position', 'absolute'); linkDisplay.css('transform', 'rotate('+link.rotation+'deg)'); linkDisplay.css('fill', 'grey'); diff --git a/vspace/src/main/webapp/WEB-INF/views/layouts/main.html b/vspace/src/main/webapp/WEB-INF/views/layouts/main.html index 2a4b3e0ae..d3ecbaa47 100644 --- a/vspace/src/main/webapp/WEB-INF/views/layouts/main.html +++ b/vspace/src/main/webapp/WEB-INF/views/layouts/main.html @@ -46,7 +46,9 @@
- This web application was built with Virtual Spaces 2.0 + This web application was built with Virtual Spaces 2.0. + Version +
diff --git a/vspace/src/main/webapp/WEB-INF/views/layouts/navbar_staff.html b/vspace/src/main/webapp/WEB-INF/views/layouts/navbar_staff.html index 2b9b36407..978e3ef7a 100644 --- a/vspace/src/main/webapp/WEB-INF/views/layouts/navbar_staff.html +++ b/vspace/src/main/webapp/WEB-INF/views/layouts/navbar_staff.html @@ -1,8 +1,5 @@ - - -
@@ -60,14 +57,20 @@ -
- + +
\ No newline at end of file diff --git a/vspace/src/main/webapp/WEB-INF/views/register.html b/vspace/src/main/webapp/WEB-INF/views/register.html index f5e8875d9..0eb206d65 100644 --- a/vspace/src/main/webapp/WEB-INF/views/register.html +++ b/vspace/src/main/webapp/WEB-INF/views/register.html @@ -1,11 +1,14 @@ +
-

Create new Account

Create new Account
- +
+
+
+
- +
+
diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/modules/module.html b/vspace/src/main/webapp/WEB-INF/views/staff/modules/module.html index eb544cf97..64433f0bd 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/modules/module.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/modules/module.html @@ -230,7 +230,8 @@

diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/modules/modulelist.html b/vspace/src/main/webapp/WEB-INF/views/staff/modules/modulelist.html index 970e2f76a..dd85c868c 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/modules/modulelist.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/modules/modulelist.html @@ -2,6 +2,7 @@ + + + + +
+ +
+ +
+
+
+ +
+

Found [[${spaceCount}]] result

+

Found [[${spaceCount}]] results

+
+ Keyword: + + [[${searchWord}]] +
+
+
+
+
No result to display.
+
+
+ +
+
+
+ +
+
+
+ +
+

Found [[${moduleCount}]] result

+

Found [[${moduleCount}]] results

+
+ Keyword: + + [[${searchWord}]] +
+
+
+
+
No result to display.
+
+
+ +
+
+
+ +
+
+
+ +
+

Found [[${slideCount}]] result

+

Found [[${slideCount}]] results

+
+ Keyword: + + [[${searchWord}]] +
+
+
+
+
No result to display.
+
+
+ +
+
+
+ +
+
+
+ +
+

Found [[${slideTextCount}]] result

+

Found [[${slideTextCount}]] results

+
+ Keyword: + + [[${searchWord}]] +
+
+
+
+
No result to display.
+
+
+ +
+
+
+
+
+ + diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/spaces/space.html b/vspace/src/main/webapp/WEB-INF/views/staff/spaces/space.html index acf6fd02c..9ab2912b3 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/spaces/space.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/spaces/space.html @@ -40,6 +40,13 @@ showSpaceLink(createSpaceLinkInfo()); } +var moduleLinkIconReader = new FileReader(); +var moduleLinkIcon; +moduleLinkIconReader.onload = function(e) { + moduleLinkIcon = e.target.result; + showModuleLink(createModuleLinkInfo()); +} + var externalLinkIconReader = new FileReader(); var externalLinkIcon; externalLinkIconReader.onload = function(e) { @@ -133,7 +140,7 @@ } else if(link.type=="IMAGE" && link.image != null){ var moduleImageURL = [[@{/api/image/}]]+link.image.id; - moduleLink = $(''); + moduleLink = $(''); } else{ moduleLink = $('

'+link.link.name+'

'); @@ -311,7 +318,9 @@ var link; if (moduleLink["type"] == "ALERT") { link = $(''); - }else{ + } else if(moduleLink["type"] == "IMAGE" && moduleLinkIcon) { + link = $(''); + } else{ $(module_label).css({ 'position': 'absolute', 'font-size': "10px", @@ -503,7 +512,7 @@ info["rotation"] = $("#moduleLinkRotation").val(); info["linkedModule"] = $("#linkedModule").val(); info["moduleLinkLabel"] = $("#moduleLinkLabel").val(); - info["type"] = $("#type").val(); + info["type"] = $("#moduleType").val(); return info; } @@ -514,7 +523,7 @@ info["rotation"] = $("#moduleLinkRotationEdit").val(); info["linkedModule"] = $("#moduleLinkIdEdit").val(); info["moduleLinkLabel"] = $("#moduleLinkLabelEdit").val(); - info["type"] = $("#typeEdit").val(); + info["type"] = $("#moduleTypeEdit").val(); return info; } @@ -552,8 +561,10 @@ $("#spaceLinkId").val(spaceLinkId); $("#spaceLinkIdValueEdit").val(spaceLinkId); $("#spaceLinkRotationEdit").val(rotation); - $('#typeSpaceEdit option[value="'+linkType+'"]').attr("selected", "selected"); - $('#spaceLinkIdEdit option[value="'+selectedSpaceId+'"]').attr("selected", "selected"); + $("#typeSpaceEdit option:selected").prop('selected', false); + $('#typeSpaceEdit option[value="'+linkType+'"]').prop("selected", true); + $("#spaceLinkIdEdit option:selected").prop('selected', false); + $('#spaceLinkIdEdit option[value="'+selectedSpaceId+'"]').prop("selected", true); if(linkType != "IMAGE"){ resetHighlighting(); } @@ -579,7 +590,6 @@ } function makeModuleLinksEditable(moduleLinkName, moduleLinkId, rotation, selectedModuleId, posXEdit, posYEdit, displayLinkId, linkType) { - selectedModuleLinkId=moduleLinkId; storeX=posXEdit; storeY=posYEdit; @@ -590,8 +600,10 @@ $("#moduleLinkId").val(moduleLinkId); $("#moduleLinkIdValueEdit").val(moduleLinkId); $("#moduleLinkRotationEdit").val(rotation); - $('#typeEdit option[value="'+linkType+'"]').attr("selected", "selected"); - $('#moduleLinkIdEdit option[value="'+selectedModuleId+'"]').attr("selected", "selected"); + $("#moduleTypeEdit option:selected").prop('selected', false); + $('#moduleTypeEdit option[value="'+linkType+'"]').prop("selected", true); + $("#moduleLinkIdEdit option:selected").prop('selected', false); + $('#moduleLinkIdEdit option[value="'+selectedModuleId+'"]').prop("selected", true); resetHighlighting(); $('[data-link-id="' + moduleLinkId + '"]').css("color", "#c1bb88"); $('div[data-link-id="' + moduleLinkId + '"]').removeClass("alert-primary"); @@ -621,7 +633,8 @@ $("#externalLinkLabelEdit").val(linkName); $("#externalLinkIdValueEdit").val(linkId); $("#externalLinkURLEdit").val(externalLinkURL); - $('#extTypeEdit option[value="'+linkType+'"]').attr("selected", "selected"); + $("#extTypeEdit option:selected").prop('selected', false); + $('#extTypeEdit option[value="'+linkType+'"]').prop("selected",true); resetHighlighting(); $('[data-link-id="' + linkId + '"]').css("color", "#c1bb88"); @@ -818,6 +831,7 @@ $("div#incomingLinks").append(""+spaceName+""); } $("#space").css("display", "none"); + linkIcon=null; drawLinks(); } }); @@ -825,7 +839,8 @@ $("#createModuleLinkBtn").click(function(e) { e.preventDefault(); - + $('#errorAlert').hide(); + if (storeX == undefined || storeY == undefined) { $("#errorMsg").text("Please click on the image to specify where the new link should be located.") $('#errorAlert').show(); @@ -834,7 +849,8 @@ var linkedModules = $("#linkedModule").val(); var moduleLabel = $("#moduleLinkLabel").val(); - + var type = $("#moduleType option:selected").text(); + if (moduleLabel == undefined || moduleLabel == "") { $("#errorMsg").text("Please enter the label for module.") $('#errorAlert').show(); @@ -846,6 +862,12 @@ $('#errorAlert').show(); return; } + + if (type == undefined || type == "Choose...") { + $("#errorMsg").text("Please select a link type in Type dropdown.") + $('#errorAlert').show(); + return; + } $("#moduleLinkX").val(storeX); $("#moduleLinkY").val(storeY); @@ -886,6 +908,7 @@ $("."+linkData["id"]).remove(); form[0].reset(); $("#space").css("display", "none"); + moduleLinkIcon=null; drawLinks(); } }); @@ -1105,6 +1128,7 @@ form[0].reset(); $("#external-arrow").attr("id",""); $("#space").css("display", "none"); + externalLinkIcon=null; drawLinks(); } }); @@ -1238,6 +1262,12 @@ linkIconReader.readAsDataURL(this.files[0]); } }); + + $("#moduleLinkImage").change(function() { + if (this.files && this.files[0]) { + moduleLinkIconReader.readAsDataURL(this.files[0]); + } + }); $("#externalLinkImage").change(function() { if (this.files && this.files[0]) { @@ -1249,6 +1279,7 @@ $(".cancelSpaceLinkBtn").click(function() { storeX = null; storeY = null; + linkIcon = null; $("#link").remove(); $("#space_label").remove(); @@ -1261,6 +1292,7 @@ $(".cancelModuleLinkBtn").click(function() { storeX = null; storeY = null; + moduleLinkIcon=null; $("#link").remove(); $("#module_label").remove(); $("#space").hide(); @@ -1272,6 +1304,7 @@ $(".cancelExternalLinkBtn").click(function() { storeX = null; storeY = null; + externalLinkIcon=null; $("#external-link").remove(); $("div#link").remove(); $("#external-arrow").remove(); @@ -1542,7 +1575,6 @@
Create new Module Link
-
@@ -1564,7 +1596,20 @@
Create new Module Link
name="moduleLinkLabel" id="moduleLinkLabel">
- + +
+
+ +
+
+ +
+
+
@@ -1577,6 +1622,16 @@
Create new Module Link
+ + +
+
+ +
+
+ +
+

@@ -1771,7 +1826,6 @@

- @@ -1800,6 +1854,18 @@
style="width: inherit; background: var(--base-grey)">
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+

diff --git a/vspace/src/main/webapp/WEB-INF/views/staff/user/list.html b/vspace/src/main/webapp/WEB-INF/views/staff/user/list.html index eb5b2c2b8..abf169574 100644 --- a/vspace/src/main/webapp/WEB-INF/views/staff/user/list.html +++ b/vspace/src/main/webapp/WEB-INF/views/staff/user/list.html @@ -27,13 +27,13 @@

-
- + +
-
- -
+
+ +
diff --git a/vspace/src/main/webapp/resources/extra/Home.css b/vspace/src/main/webapp/resources/extra/Home.css index 6e5c2aa02..c5eaf1bd0 100644 --- a/vspace/src/main/webapp/resources/extra/Home.css +++ b/vspace/src/main/webapp/resources/extra/Home.css @@ -757,6 +757,20 @@ background: #f2f2f2; } +.searchInput { + display: flex !important; + background: var(--base-grey) !important; + border-radius: 5px !important; +} + +.searchImg { + border-radius: 25px; + float: left; + width: 150px; + height: 150px; + margin-right: 15px !important; +} + .shepherd-button { background-color: var(--primary) !important; color: white !important; diff --git a/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.eot b/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.eot deleted file mode 100644 index 0d2b0c161..000000000 Binary files a/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.eot and /dev/null differ diff --git a/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.svg b/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.svg deleted file mode 100644 index a152e1c1a..000000000 --- a/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.svg +++ /dev/null @@ -1,173 +0,0 @@ - - - -Generated by IcoMoon - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.ttf b/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.ttf deleted file mode 100644 index bd11279d6..000000000 Binary files a/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.ttf and /dev/null differ diff --git a/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.woff b/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.woff deleted file mode 100644 index d8ac629ff..000000000 Binary files a/vspace/src/main/webapp/resources/extra/diging-icon-fonts/diging-icon-pack.woff and /dev/null differ diff --git a/vspace/src/main/webapp/resources/extra/diging-icon-pack.css b/vspace/src/main/webapp/resources/extra/diging-icon-pack.css index de29080fc..c606ae8a7 100644 --- a/vspace/src/main/webapp/resources/extra/diging-icon-pack.css +++ b/vspace/src/main/webapp/resources/extra/diging-icon-pack.css @@ -1,10 +1,10 @@ @font-face { font-family: 'icomoon'; - src: url('fonts/diging-icon-pack.eot?3whofe'); - src: url('fonts/diging-icon-pack.eot?3whofe#iefix') format('embedded-opentype'), - url('fonts/diging-icon-pack.ttf?3whofe') format('truetype'), - url('fonts/diging-icon-pack.woff?3whofe') format('woff'), - url('fonts/diging-icon-pack.svg?3whofe#icomoon') format('svg'); + src: url('fonts/diging-icon-pack.eot?fszp5s'); + src: url('fonts/diging-icon-pack.eot?fszp5s#iefix') format('embedded-opentype'), + url('fonts/diging-icon-pack.ttf?fszp5s') format('truetype'), + url('fonts/diging-icon-pack.woff?fszp5s') format('woff'), + url('fonts/diging-icon-pack.svg?fszp5s#icomoon') format('svg'); font-weight: normal; font-style: normal; font-display: block; @@ -25,6 +25,61 @@ -moz-osx-font-smoothing: grayscale; } +@keyframes rotation { + from { + transform: rotate(0deg); + } + to { + transform: rotate(359deg); + } +} +.icon-newspaper:before { + content: "\e9bb"; +} +.icon-firefox:before { + content: "\e9bc"; +} +.icon-brush:before { + content: "\e9bd"; +} +.icon-film-reel:before { + content: "\e9be"; +} +.icon-gavel:before { + content: "\e9bf"; +} +.icon-grad-cap:before { + content: "\e9c0"; +} +.icon-up-down-arrow:before { + content: "\e9c4"; +} +.icon-pen:before { + content: "\e9b9"; +} +.icon-sticky-note:before { + content: "\e9ba"; +} +.icon-spinner:before { + content: "\e9b8"; + animation: rotation 2s ease-out infinite; + display: inline-block; +} +.icon-invoice:before { + content: "\e9c1"; +} +.icon-user-check:before { + content: "\e9c2"; +} +.icon-stop-circle:before { + content: "\e9c3"; +} +.icon-anchor:before { + content: "\e9b6"; +} +.icon-sync:before { + content: "\e9b7"; +} .icon-admin-slash:before { content: "\e93c"; } @@ -310,6 +365,9 @@ .icon-image-delete:before { content: "\e951"; } +.icon-img:before { + content: "\e9b5"; +} .icon-info:before { content: "\e953"; } diff --git a/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.eot b/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.eot index 3fd868ddb..35b9b6ab5 100644 Binary files a/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.eot and b/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.eot differ diff --git a/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.svg b/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.svg index 1d162be4b..41c313be2 100644 --- a/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.svg +++ b/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.svg @@ -188,4 +188,20 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.ttf b/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.ttf index 4e8b4c550..b594bd66b 100644 Binary files a/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.ttf and b/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.ttf differ diff --git a/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.woff b/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.woff index 511588413..1d3ec7f78 100644 Binary files a/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.woff and b/vspace/src/main/webapp/resources/extra/fonts/diging-icon-pack.woff differ diff --git a/vspace/src/main/webapp/resources/images/placeholder.png b/vspace/src/main/webapp/resources/images/placeholder.png new file mode 100644 index 000000000..226d50772 Binary files /dev/null and b/vspace/src/main/webapp/resources/images/placeholder.png differ diff --git a/vspace/src/test/java/edu/asu/diging/simpleusers/web/admin/UsersUtilityTest.java b/vspace/src/test/java/edu/asu/diging/simpleusers/web/admin/UsersUtilityTest.java new file mode 100644 index 000000000..086495b86 --- /dev/null +++ b/vspace/src/test/java/edu/asu/diging/simpleusers/web/admin/UsersUtilityTest.java @@ -0,0 +1,35 @@ +package edu.asu.diging.simpleusers.web.admin; + +import java.util.HashSet; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.springframework.security.core.authority.SimpleGrantedAuthority; + +import org.junit.Assert; + +public class UsersUtilityTest { + + @Mock + private UsersUtility usersUtility; + + HashSet roles; + + @Before + public void setUp() { + roles = new HashSet(); + roles.add(new SimpleGrantedAuthority("ROLE_STAFF")); + } + + @Test + public void test_checkUserRoleExists_roleExists() { + Assert.assertEquals(usersUtility.checkUserRoleExists(roles, "ROLE_STAFF"), true); + } + + @Test + public void test_checkUserRoleExists_roleNotExists() { + Assert.assertEquals(usersUtility.checkUserRoleExists(roles, "ROLE_USER"), false); + } + +} diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ModuleLinkManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ModuleLinkManagerTest.java index f11409ebc..6b5090701 100644 --- a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ModuleLinkManagerTest.java +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/ModuleLinkManagerTest.java @@ -12,13 +12,17 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import edu.asu.diging.vspace.core.data.ImageRepository; import edu.asu.diging.vspace.core.data.ModuleLinkRepository; import edu.asu.diging.vspace.core.data.display.ModuleLinkDisplayRepository; +import edu.asu.diging.vspace.core.exception.FileStorageException; import edu.asu.diging.vspace.core.exception.ImageCouldNotBeStoredException; import edu.asu.diging.vspace.core.exception.LinkDoesNotExistsException; import edu.asu.diging.vspace.core.exception.SpaceDoesNotExistException; +import edu.asu.diging.vspace.core.factory.IImageFactory; import edu.asu.diging.vspace.core.factory.IModuleLinkDisplayFactory; import edu.asu.diging.vspace.core.factory.IModuleLinkFactory; +import edu.asu.diging.vspace.core.file.IStorageEngine; import edu.asu.diging.vspace.core.model.IModule; import edu.asu.diging.vspace.core.model.IModuleLink; import edu.asu.diging.vspace.core.model.ISpace; @@ -51,6 +55,15 @@ public class ModuleLinkManagerTest { @Mock private IModuleLinkFactory moduleLinkFactory; + + @Mock + private IImageFactory imageFactory; + + @Mock + private ImageRepository imageRepo; + + @Mock + private IStorageEngine storage; @Mock private IModuleLinkDisplayFactory moduleLinkDisplayFactory; @@ -58,16 +71,19 @@ public class ModuleLinkManagerTest { @InjectMocks private ModuleLinkManager managerToTest = new ModuleLinkManager(); - private String spaceId1; + private String spaceId1, imageId, imageFileName, modDisplayLinkId; @Before public void init() { MockitoAnnotations.initMocks(this); spaceId1 = "SPA000000014"; + imageId = "IMG00000001"; + imageFileName = "Module Image 1"; + modDisplayLinkId = "MDLD001"; } @Test - public void test_createLink_success() throws SpaceDoesNotExistException, ImageCouldNotBeStoredException { + public void test_createLink_success() throws SpaceDoesNotExistException, ImageCouldNotBeStoredException, FileStorageException { Space space = new Space(); space.setId(spaceId1); @@ -94,7 +110,7 @@ public void test_createLink_success() throws SpaceDoesNotExistException, ImageCo moduleLink.setTarget(target); IModuleLinkDisplay moduleDisplayLink = new ModuleLinkDisplay(); - moduleDisplayLink.setId("MDLD001"); + moduleDisplayLink.setId(modDisplayLinkId); moduleDisplayLink.setPositionX(10); moduleDisplayLink.setPositionY(30); moduleDisplayLink.setRotation(40); @@ -117,6 +133,48 @@ public void test_createLink_success() throws SpaceDoesNotExistException, ImageCo Assert.assertEquals(moduleDisplayLink.getType(), savedModuleLinkDisplay1.getType()); Assert.assertEquals(moduleDisplayLink.getLink().getTarget().getId(), savedModuleLinkDisplay1.getLink().getTarget().getId()); Mockito.verify(moduleLinkDisplayRepo).save((ModuleLinkDisplay)moduleDisplayLink); + + + //For moduleLink as Image + IVSImage modImage = new VSImage(); + modImage.setId(imageId); + modImage.setFilename(imageFileName); + modImage.setHeight(200); + modImage.setWidth(400); + + IModuleLinkDisplay moduleDisplayLinkImage = new ModuleLinkDisplay(); + moduleDisplayLinkImage.setId(modDisplayLinkId); + moduleDisplayLinkImage.setPositionX(10); + moduleDisplayLinkImage.setPositionY(30); + moduleDisplayLinkImage.setRotation(40); + moduleDisplayLinkImage.setType(DisplayType.IMAGE); + moduleDisplayLinkImage.setImage(modImage); + Mockito.when(moduleLinkFactory.createModuleLink("New Module Link", space)).thenReturn(moduleLink); + moduleDisplayLinkImage.setLink(moduleLink); + + Mockito.when(moduleLinkDisplayFactory.createModuleLinkDisplay(moduleLink)).thenReturn(moduleDisplayLinkImage); + + Mockito.when(imageFactory.createImage(Mockito.anyString(), Mockito.anyString())).thenReturn(modImage); + Mockito.when(imageRepo.save((VSImage) modImage)).thenReturn((VSImage) modImage); + Mockito.when(storage.storeFile(new byte[20], imageFileName, modImage.getId())).thenReturn("Dummy File Path"); + + Mockito.when(moduleLinkRepo.save((ModuleLink) moduleLink)).thenReturn((ModuleLink)moduleLink); + Mockito.when(moduleLinkDisplayRepo.save((ModuleLinkDisplay)moduleDisplayLinkImage)).thenReturn((ModuleLinkDisplay)moduleDisplayLinkImage); + + IModuleLinkDisplay savedModuleLinkDisplay2 = managerToTest.createLink("New Module Link", spaceId1, 10, 30, 40, "MOD001", "New Module Link", DisplayType.IMAGE, new byte[20], imageFileName); + Assert.assertEquals(moduleDisplayLinkImage.getId(), savedModuleLinkDisplay2.getId()); + Assert.assertEquals(moduleDisplayLinkImage.getName(), savedModuleLinkDisplay2.getName()); + Assert.assertEquals(new Double(moduleDisplayLinkImage.getPositionX()), new Double(savedModuleLinkDisplay2.getPositionX())); + Assert.assertEquals(new Double(moduleDisplayLinkImage.getPositionY()), new Double(savedModuleLinkDisplay2.getPositionY())); + Assert.assertEquals(moduleDisplayLinkImage.getRotation(), savedModuleLinkDisplay2.getRotation()); + Assert.assertEquals(moduleDisplayLinkImage.getLink().getId(), savedModuleLinkDisplay2.getLink().getId()); + Assert.assertEquals(moduleDisplayLinkImage.getType(), savedModuleLinkDisplay2.getType()); + Assert.assertEquals(moduleDisplayLinkImage.getLink().getTarget().getId(), savedModuleLinkDisplay2.getLink().getTarget().getId()); + Assert.assertEquals(moduleDisplayLinkImage.getImage().getHeight(), savedModuleLinkDisplay2.getImage().getHeight()); + Assert.assertEquals(moduleDisplayLinkImage.getImage().getWidth(), savedModuleLinkDisplay2.getImage().getWidth()); + Assert.assertEquals(moduleDisplayLinkImage.getImage().getId(), savedModuleLinkDisplay2.getImage().getId()); + Mockito.verify(moduleLinkDisplayRepo).save((ModuleLinkDisplay)moduleDisplayLinkImage); + } @Test @@ -143,7 +201,7 @@ public void test_updateLink_success() throws SpaceDoesNotExistException, LinkDoe Mockito.when(moduleManager.getModule("MOD001")).thenReturn(target); moduleLink.setTarget(target); - moduleLinkDisplay.setId("MDLD001"); + moduleLinkDisplay.setId(modDisplayLinkId); moduleLinkDisplay.setLink(moduleLink); moduleLinkDisplay.setName("TestModule"); @@ -177,13 +235,32 @@ public void test_updateLink_success() throws SpaceDoesNotExistException, LinkDoe Mockito.when(moduleLinkRepo.save((ModuleLink) moduleLink)).thenReturn((ModuleLink)moduleLink); Mockito.when(moduleLinkDisplayRepo.save((ModuleLinkDisplay)moduleLinkDisplay)).thenReturn((ModuleLinkDisplay)moduleLinkDisplayUpdated); - IModuleLinkDisplay actualUpdatedLink = managerToTest.updateLink("TestModuleEdited", spaceId1, 100, 300, 180, "MOD002", "TestModuleEdited", "MOL001", "MDLD001", DisplayType.ALERT, null, null); + IModuleLinkDisplay actualUpdatedLink = managerToTest.updateLink("TestModuleEdited", spaceId1, 100, 300, 180, "MOD002", "TestModuleEdited", "MOL001", modDisplayLinkId, DisplayType.ALERT, null, null); Assert.assertEquals(moduleLinkDisplayUpdated.getId(), actualUpdatedLink.getId()); Assert.assertEquals(moduleLinkDisplayUpdated.getName(), actualUpdatedLink.getName()); Assert.assertEquals(new Double(moduleLinkDisplayUpdated.getPositionX()), new Double(actualUpdatedLink.getPositionX())); Assert.assertEquals(new Double(moduleLinkDisplayUpdated.getPositionY()), new Double(actualUpdatedLink.getPositionY())); Assert.assertEquals(moduleLinkDisplayUpdated.getLink().getTarget(), actualUpdatedLink.getLink().getTarget()); Assert.assertEquals(moduleLinkDisplayUpdated.getType(), actualUpdatedLink.getType()); + + //For moduleLink as Image + IVSImage modImage = new VSImage(); + modImage.setId(imageId); + modImage.setFilename(imageFileName); + modImage.setHeight(200); + modImage.setWidth(400); + + moduleLinkDisplay.setType(DisplayType.IMAGE); + moduleLinkDisplay.setImage(modImage); + moduleLinkDisplayUpdated.setType(DisplayType.ARROW); + + IModuleLinkDisplay actualUpdatedLink2 = managerToTest.updateLink("TestModuleEdited", spaceId1, 100, 300, 180, "MOD002", "TestModuleEdited", "MOL001", modDisplayLinkId, DisplayType.ALERT, null, null); + Assert.assertEquals(moduleLinkDisplayUpdated.getId(), actualUpdatedLink2.getId()); + Assert.assertEquals(moduleLinkDisplayUpdated.getName(), actualUpdatedLink2.getName()); + Assert.assertEquals(new Double(moduleLinkDisplayUpdated.getPositionX()), new Double(actualUpdatedLink2.getPositionX())); + Assert.assertEquals(new Double(moduleLinkDisplayUpdated.getPositionY()), new Double(actualUpdatedLink2.getPositionY())); + Assert.assertEquals(moduleLinkDisplayUpdated.getLink().getTarget(), actualUpdatedLink2.getLink().getTarget()); + Assert.assertEquals(moduleLinkDisplayUpdated.getType(), actualUpdatedLink2.getType()); } @Test @@ -203,7 +280,7 @@ public void test_deleteLink_linkPresent() { target.setId("MOD005"); moduleLink.setTarget(target); - moduleLinkDisplay.setId("MDLD001"); + moduleLinkDisplay.setId(modDisplayLinkId); moduleLinkDisplay.setLink(moduleLink); moduleLinkDisplay.setName("TestModule"); diff --git a/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/StaffSearchManagerTest.java b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/StaffSearchManagerTest.java new file mode 100644 index 000000000..332db5167 --- /dev/null +++ b/vspace/src/test/java/edu/asu/diging/vspace/core/services/impl/StaffSearchManagerTest.java @@ -0,0 +1,375 @@ +package edu.asu.diging.vspace.core.services.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.test.util.ReflectionTestUtils; + +import edu.asu.diging.vspace.core.data.TextContentBlockRepository; +import edu.asu.diging.vspace.core.model.IModule; +import edu.asu.diging.vspace.core.model.ISlide; +import edu.asu.diging.vspace.core.model.ISpace; +import edu.asu.diging.vspace.core.model.impl.Module; +import edu.asu.diging.vspace.core.model.impl.Slide; +import edu.asu.diging.vspace.core.model.impl.Space; +import edu.asu.diging.vspace.core.services.IModuleManager; +import edu.asu.diging.vspace.core.services.ISlideManager; +import edu.asu.diging.vspace.core.services.ISpaceManager; + +public class StaffSearchManagerTest { + + @Mock + private ISpaceManager spaceManager; + + @Mock + private IModuleManager moduleManager; + + @Mock + private ISlideManager slideManager; + + @Mock + private TextContentBlockRepository textContentBlockRepo; + + @InjectMocks + private StaffSearchManager serviceToTest; + + private List spaces; + + private List lastPageSpaces; + + private List modules; + + private List lastPageModules; + + private List slides; + + private List lastPageSlides; + + private List slideTexts; + + private List lastPageSlideTexts; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + + spaces = new ArrayList<>(); + StringBuilder spaceIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + Space space = new Space(); + spaceIdBuilder.setLength(0); + spaceIdBuilder.append("SPACE_ID_"); + spaceIdBuilder.append(String.valueOf(i)); + space.setId(spaceIdBuilder.toString()); + spaces.add(space); + } + + lastPageSpaces = new ArrayList<>(); + for (int i = 11; i <= 12; i++) { + Space space = new Space(); + spaceIdBuilder.setLength(0); + spaceIdBuilder.append("SPACE_ID_"); + spaceIdBuilder.append(String.valueOf(i)); + space.setId(spaceIdBuilder.toString()); + lastPageSpaces.add(space); + } + + modules = new ArrayList<>(); + StringBuilder moduleIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + Module module = new Module(); + moduleIdBuilder.setLength(0); + moduleIdBuilder.append("MODULE_ID_"); + moduleIdBuilder.append(String.valueOf(i)); + module.setId(moduleIdBuilder.toString()); + modules.add(module); + } + + lastPageModules = new ArrayList<>(); + for (int i = 11; i <= 12; i++) { + Module module = new Module(); + moduleIdBuilder.setLength(0); + moduleIdBuilder.append("MODULE_ID_"); + moduleIdBuilder.append(String.valueOf(i)); + module.setId(moduleIdBuilder.toString()); + lastPageModules.add(module); + } + + slides = new ArrayList<>(); + StringBuilder slideIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + Slide slide = new Slide(); + slideIdBuilder.setLength(0); + slideIdBuilder.append("SLIDE_ID_"); + slideIdBuilder.append(String.valueOf(i)); + slide.setId(slideIdBuilder.toString()); + slides.add(slide); + } + + lastPageSlides = new ArrayList<>(); + for (int i = 11; i <= 12; i++) { + Slide slide = new Slide(); + slideIdBuilder.setLength(0); + slideIdBuilder.append("SLIDE_ID_"); + slideIdBuilder.append(String.valueOf(i)); + slide.setId(slideIdBuilder.toString()); + lastPageSlides.add(slide); + } + + slideTexts = new ArrayList<>(); + StringBuilder slideTextIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + Slide slideText = new Slide(); + slideTextIdBuilder.setLength(0); + slideTextIdBuilder.append("SLIDETEXT_ID_"); + slideTextIdBuilder.append(String.valueOf(i)); + slideText.setId(slideTextIdBuilder.toString()); + slideTexts.add(slideText); + } + + lastPageSlideTexts = new ArrayList<>(); + for (int i = 11; i <= 12; i++) { + Slide slideText = new Slide(); + slideTextIdBuilder.setLength(0); + slideTextIdBuilder.append("SLIDETEXT_ID_"); + slideTextIdBuilder.append(String.valueOf(i)); + slideText.setId(slideTextIdBuilder.toString()); + lastPageSlideTexts.add(slideText); + } + + ReflectionTestUtils.setField(serviceToTest, "pageSize", 10); + } + + @Test + public void test_searchInSpaces_success() { + + Pageable requestedPage = PageRequest.of(0, 10); + String search = "space"; + when(spaceManager.findByNameOrDescription(requestedPage, search)) + .thenReturn(new PageImpl(spaces,requestedPage, 12)); + Page tempResult = serviceToTest.searchInSpaces(search, 1); + assertEquals(10, tempResult.getContent().size()); + List idList = tempResult.stream().map(space -> space.getId()).collect(Collectors.toList()); + StringBuilder dummySpaceIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + dummySpaceIdBuilder.setLength(0); + dummySpaceIdBuilder.append("SPACE_ID_"); + dummySpaceIdBuilder.append(String.valueOf(i)); + assertEquals(dummySpaceIdBuilder.toString(),idList.get(i-1)); + } + verify(spaceManager).findByNameOrDescription(requestedPage, search); + } + + @Test + public void test_searchInSpaces_pageGreaterThanTotalPages() { + + Pageable requestedPage = PageRequest.of(6, 10); + String search = "space"; + when(spaceManager.findByNameOrDescription(requestedPage, search)).thenReturn(new PageImpl(new ArrayList(),requestedPage, 12)); + Pageable requestedPage1 = PageRequest.of(1, 10); + when(spaceManager.findByNameOrDescription(requestedPage1, search)).thenReturn(new PageImpl(lastPageSpaces,requestedPage1, 12)); + Page tempResult = serviceToTest.searchInSpaces(search, 7); + assertEquals(2, tempResult.getContent().size()); + List idList = tempResult.stream().map(space -> space.getId()).collect(Collectors.toList()); + assertEquals("SPACE_ID_11",idList.get(0)); + assertEquals("SPACE_ID_12",idList.get(1)); + verify(spaceManager).findByNameOrDescription(requestedPage, search); + verify(spaceManager).findByNameOrDescription(requestedPage1, search); + } + + @Test + public void test_searchInSpaces_negativePage() { + + Pageable requestedPage = PageRequest.of(0, 10); + String search = "space"; + when(spaceManager.findByNameOrDescription(requestedPage, search)).thenReturn(new PageImpl(spaces, requestedPage, 12)); + Page tempResult = serviceToTest.searchInSpaces(search, -1); + assertEquals(10, tempResult.getContent().size()); + List idList = tempResult.stream().map(space -> space.getId()).collect(Collectors.toList()); + StringBuilder dummySpaceIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + dummySpaceIdBuilder.setLength(0); + dummySpaceIdBuilder.append("SPACE_ID_"); + dummySpaceIdBuilder.append(String.valueOf(i)); + assertEquals(dummySpaceIdBuilder.toString(),idList.get(i-1)); + } + verify(spaceManager).findByNameOrDescription(requestedPage, search); + } + + @Test + public void test_searchInModules_success() { + + Pageable requestedPage = PageRequest.of(0, 10); + String search = "module"; + when(moduleManager.findByNameOrDescription(requestedPage, search)).thenReturn(new PageImpl(modules, requestedPage, 12)); + Page tempResult = serviceToTest.searchInModules(search, 1); + assertEquals(10, tempResult.getContent().size()); + List idList = tempResult.stream().map(module -> module.getId()).collect(Collectors.toList()); + StringBuilder dummyModuleIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + dummyModuleIdBuilder.setLength(0); + dummyModuleIdBuilder.append("MODULE_ID_"); + dummyModuleIdBuilder.append(String.valueOf(i)); + assertEquals(dummyModuleIdBuilder.toString(),idList.get(i-1)); + } + verify(moduleManager).findByNameOrDescription(requestedPage, search); + } + + @Test + public void test_searchInModules_pageGreaterThanTotalPages() { + + Pageable requestedPage = PageRequest.of(6, 10); + String search = "module"; + when(moduleManager.findByNameOrDescription(requestedPage, search)).thenReturn(new PageImpl(new ArrayList(), requestedPage, 12)); + Pageable requestedPage1 = PageRequest.of(1, 10); + when(moduleManager.findByNameOrDescription(requestedPage1, search)).thenReturn(new PageImpl(lastPageModules, requestedPage1, 12)); + Page tempResult = serviceToTest.searchInModules(search, 7); + assertEquals(2, tempResult.getContent().size()); + List idList = tempResult.stream().map(module -> module.getId()).collect(Collectors.toList()); + assertEquals("MODULE_ID_11",idList.get(0)); + assertEquals("MODULE_ID_12",idList.get(1)); + verify(moduleManager).findByNameOrDescription(requestedPage, search); + verify(moduleManager).findByNameOrDescription(requestedPage1, search); + } + + @Test + public void test_searchInModules_negativePage() { + Pageable requestedPage = PageRequest.of(0, 10); + String search = "module"; + when(moduleManager.findByNameOrDescription(requestedPage, search)).thenReturn(new PageImpl(modules, requestedPage, 12)); + Page tempResult = serviceToTest.searchInModules(search, -2); + assertEquals(10, tempResult.getContent().size()); + List idList = tempResult.stream().map(module -> module.getId()).collect(Collectors.toList()); + StringBuilder dummyModuleIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + dummyModuleIdBuilder.setLength(0); + dummyModuleIdBuilder.append("MODULE_ID_"); + dummyModuleIdBuilder.append(String.valueOf(i)); + assertEquals(dummyModuleIdBuilder.toString(),idList.get(i-1)); + } + verify(moduleManager).findByNameOrDescription(requestedPage, search); + } + + @Test + public void test_searchInSlides_success() { + Pageable requestedPage = PageRequest.of(0, 10); + String search = "slide"; + when(slideManager.findByNameOrDescription(requestedPage, search)).thenReturn(new PageImpl(slides, requestedPage, 12)); + Page tempResult = serviceToTest.searchInSlides(search, 1); + assertEquals(10, tempResult.getContent().size()); + List idList = tempResult.stream().map(slide -> slide.getId()).collect(Collectors.toList()); + StringBuilder dummySlideIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + dummySlideIdBuilder.setLength(0); + dummySlideIdBuilder.append("SLIDE_ID_"); + dummySlideIdBuilder.append(String.valueOf(i)); + assertEquals(dummySlideIdBuilder.toString(),idList.get(i-1)); + } + verify(slideManager).findByNameOrDescription(requestedPage, search); + } + + @Test + public void test_searchInSlides_pageGreaterThanTotalPages() { + Pageable requestedPage = PageRequest.of(6, 10); + String search = "slide"; + when(slideManager.findByNameOrDescription(requestedPage, search)).thenReturn(new PageImpl(new ArrayList(), requestedPage, 12)); + Pageable requestedPage1 = PageRequest.of(1, 10); + when(slideManager.findByNameOrDescription(requestedPage1, search)).thenReturn(new PageImpl(lastPageSlides, requestedPage1, 12)); + Page tempResult = serviceToTest.searchInSlides(search, 7); + assertEquals(2, tempResult.getContent().size()); + List idList = tempResult.stream().map(slide -> slide.getId()).collect(Collectors.toList()); + assertEquals("SLIDE_ID_11",idList.get(0)); + assertEquals("SLIDE_ID_12",idList.get(1)); + verify(slideManager).findByNameOrDescription(requestedPage, search); + verify(slideManager).findByNameOrDescription(requestedPage1, search); + } + + @Test + public void test_searchInSlides_negativePage() { + Pageable requestedPage = PageRequest.of(0, 10); + String search = "slide"; + when(slideManager.findByNameOrDescription(requestedPage, search)).thenReturn(new PageImpl(slides, requestedPage, 12)); + Page tempResult = serviceToTest.searchInSlides(search, -2); + assertEquals(10, tempResult.getContent().size()); + List idList = tempResult.stream().map(slide -> slide.getId()).collect(Collectors.toList()); + StringBuilder dummySlideIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + dummySlideIdBuilder.setLength(0); + dummySlideIdBuilder.append("SLIDE_ID_"); + dummySlideIdBuilder.append(String.valueOf(i)); + assertEquals(dummySlideIdBuilder.toString(),idList.get(i-1)); + } + verify(slideManager).findByNameOrDescription(requestedPage, search); + } + + @Test + public void test_searchInSlideTexts_success() { + Pageable requestedPage = PageRequest.of(0, 10); + String search = "test"; + when(textContentBlockRepo.findWithNameOrDescription(requestedPage, search)) + .thenReturn(new PageImpl(slideTexts, requestedPage, 12)); + Page tempResult = serviceToTest.searchInSlideTexts(search, 1); + assertEquals(10, tempResult.getContent().size()); + List idList = tempResult.stream().map(slide -> slide.getId()).collect(Collectors.toList()); + StringBuilder dummySlideTextIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + dummySlideTextIdBuilder.setLength(0); + dummySlideTextIdBuilder.append("SLIDETEXT_ID_"); + dummySlideTextIdBuilder.append(String.valueOf(i)); + assertEquals(dummySlideTextIdBuilder.toString(),idList.get(i-1)); + } + verify(textContentBlockRepo).findWithNameOrDescription(requestedPage, search); + } + + @Test + public void test_searchInSlideTexts_pageGreaterThanTotalPages() { + Pageable requestedPage = PageRequest.of(6, 10); + String search = "test"; + when(textContentBlockRepo.findWithNameOrDescription(requestedPage, search)) + .thenReturn(new PageImpl(new ArrayList(), requestedPage, 12)); + Pageable requestedPage1 = PageRequest.of(1, 10); + when(textContentBlockRepo.findWithNameOrDescription(requestedPage1, search)) + .thenReturn(new PageImpl(lastPageSlideTexts, requestedPage1, 12)); + Page tempResult = serviceToTest.searchInSlideTexts(search, 7); + assertEquals(2, tempResult.getContent().size()); + List idList = tempResult.stream().map(slide -> slide.getId()).collect(Collectors.toList()); + assertEquals("SLIDETEXT_ID_11",idList.get(0)); + assertEquals("SLIDETEXT_ID_12",idList.get(1)); + verify(textContentBlockRepo).findWithNameOrDescription(requestedPage, search); + verify(textContentBlockRepo).findWithNameOrDescription(requestedPage1, search); + } + + @Test + public void test_searchInSlideTexts_negativePage() { + Pageable requestedPage = PageRequest.of(0, 10); + String search = "test"; + when(textContentBlockRepo.findWithNameOrDescription(requestedPage, search)) + .thenReturn(new PageImpl(slideTexts, requestedPage, 12)); + Page tempResult = serviceToTest.searchInSlideTexts(search, -2); + assertEquals(10, tempResult.getContent().size()); + List idList = tempResult.stream().map(slide -> slide.getId()).collect(Collectors.toList()); + StringBuilder dummySlideTextIdBuilder = new StringBuilder(); + for (int i = 1; i <= 10; i++) { + dummySlideTextIdBuilder.setLength(0); + dummySlideTextIdBuilder.append("SLIDETEXT_ID_"); + dummySlideTextIdBuilder.append(String.valueOf(i)); + assertEquals(dummySlideTextIdBuilder.toString(),idList.get(i-1)); + } + verify(textContentBlockRepo).findWithNameOrDescription(requestedPage, search); + } + +}