Skip to content

Commit

Permalink
Bug/vspc 177 (#234)
Browse files Browse the repository at this point in the history
* [VSPC-177] fixed registration issue; attempt to fix space not found

fixed issue when no exhibition mode has been set yet

* [VSPC-177] removed commented out code

* [VSPC-177] fixed test cases
  • Loading branch information
jdamerow authored Aug 10, 2021
1 parent 873c29e commit e07588c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public interface SpaceLinkRepository extends PagingAndSortingRepository<SpaceLin

@Query("select d from SpaceLink d where d.sourceSpace.id = ?1")
List<SpaceLink> getLinkedSpaces(String id);

@Query("select d from SpaceLink d where d.targetSpace.id = ?1")
List<SpaceLink> getLinkedFromSpaces(String id);

List<SpaceLink> findByTargetSpace(ISpace space);
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ public List<ISpace> getSpacesWithStatus(SpaceStatus status) {
public void deleteSpaceById(String id) {
if(id != null) {
List<SpaceLink> spaceLinks = spaceLinkRepo.getLinkedSpaces(id);
List<SpaceLink> fromSpaceLinks = spaceLinkRepo.getLinkedFromSpaces(id);

List<SpaceLink> fromSpaceLinks = new ArrayList<>();
Optional<Space> space = spaceRepo.findById(id);
if (space.isPresent()) {
fromSpaceLinks = spaceLinkRepo.findByTargetSpace(space.get());
}

Exhibition exhibition = (Exhibition) exhibitionManager.getStartExhibition();
// When space has other links attached to it
// To delete links that access to the space getting deleted and replacing it as null
Expand Down Expand Up @@ -252,8 +258,12 @@ public List<SpaceLink> getOutgoingLinks(String id) {

@Override
public List<SpaceLink> getIncomingLinks(String id) {

return spaceLinkRepo.getLinkedFromSpaces(id);
Optional<Space> space = spaceRepo.findById(id);
if (space.isPresent()) {
return spaceLinkRepo.findByTargetSpace(space.get());
} else {
return new ArrayList<>();
}
}

@Override
Expand All @@ -276,7 +286,7 @@ public Iterable<Space> addIncomingLinkInfoToSpaces(Iterable<Space> spaces) {
Iterator<Space> iterator = spaces.iterator();
while(iterator.hasNext()) {
Space space = iterator.next();
space.setIncomingLinks( (spaceLinkRepo.getLinkedFromSpaces(space.getId())).size() > 0 ? true : false );
space.setIncomingLinks( (spaceLinkRepo.findByTargetSpace(space)).size() > 0 ? true : false );
}
return spaces;
}
Expand Down
2 changes: 1 addition & 1 deletion vspace/src/main/webapp/WEB-INF/views/exhibition/space.html
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
<h6
th:if="${exhibitionConfig.customMessage != '' && exhibitionConfig.mode == 'OFFLINE'}">[[${exhibitionConfig.customMessage}]]</h6>
<h6
th:unless="${exhibitionConfig.customMessage != '' && exhibitionConfig.mode == 'OFFLINE'}">[[${exhibitionConfig.mode.value}]]</h6>
th:unless="${exhibitionConfig.customMessage != '' && exhibitionConfig.mode == 'OFFLINE'}">[[${exhibitionConfig.mode?.value}]]</h6>
</div>
<div id="Module_1" class="Home_Class" style="margin: -45px 0 60px auto;">
<div id="mySidenav" class="sidenav">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
</head>

<body>
<div th:fragment="navbar">
<div th:fragment="navbar">
<div id="mySidenav" class="sidenav">
<ul class="side-list" style="padding:1px;display: table;margin: 0 auto;padding-top:35px">
<li class="nav-link alert alert-warning"
sec:authorize="hasAnyRole('ADMIN', 'STAFF')"
th:if="${exhibition}"
style="text-align: center;"
th:style="${#strings.equals(exhibition.mode,'ACTIVE') ? 'display: none' : 'display: block'}">
th:style="${#strings.equals(exhibition.mode,'ACTIVE') or #strings.equals(exhibition.mode,null) ? 'display: none' : 'display: block'}">
<span><span class="icon-warning secondary"></span></span>
<span th:if="${exhibition.mode == 'MAINTENANCE'}">Exhibition under maintenance</span>
<span th:if="${exhibition.mode == 'OFFLINE'}">Exhibition is offline</span>
Expand Down
2 changes: 1 addition & 1 deletion vspace/src/main/webapp/WEB-INF/views/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h2 class="">Login</h2>
</form>
<div class="float-right">
<small> Don't have an account yet? <a
th:href="@{/registeruser}" style="color:blue;">Sign up!</a><br>
th:href="@{/register}" style="color:blue;">Sign up!</a><br>
Forgot your password? <a
th:href="@{/reset/password/request}" style="color:blue;">Reset
it!</a>
Expand Down
2 changes: 1 addition & 1 deletion vspace/src/main/webapp/WEB-INF/views/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</head>
<body>
<div class="row justify-content-center" layout:fragment="content">
<div class="col-4">
<div class="col-12">
<div class="register-form">
<form th:action="@{|/register?${_csrf.parameterName}=${_csrf.token}|}" method="POST" name="f"
class="form-horizontal">
Expand Down
2 changes: 1 addition & 1 deletion vspace/src/main/webapp/resources/extra/Home.css
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@

.register-form {
padding: 48px;
width: 30%;
width: 50%;
margin: auto;
border-radius: 10px;
background: #f2f2f2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ public void test_deleteSpaceById_whenIdIsNull() throws SpaceDoesNotExistExceptio
}

@Test
public void test_deleteSpaceById_forNonExistentId() {
public void test_deleteSpaceById_forNonExistentId() {
Mockito.when(spaceRepo.findById(spaceId)).thenReturn(Optional.empty());
managerToTest.deleteSpaceById(spaceId);
Mockito.verify(spaceDisplayRepo).deleteBySpaceId(spaceId);
Mockito.verify(spaceRepo).deleteById(spaceId);
}

@Test
public void test_deleteSpaceById_forSuccess() {
public void test_deleteSpaceById_forSuccess() {
Mockito.when(spaceRepo.findById(spaceId1)).thenReturn(Optional.empty());
managerToTest.deleteSpaceById(spaceId1);
Mockito.verify(spaceDisplayRepo).deleteBySpaceId(spaceId1);
Mockito.verify(spaceRepo).deleteById(spaceId1);
Expand All @@ -152,6 +154,7 @@ public void test_deleteSpaceById_whenSpaceHasLinks() {
space.setId(spaceId2);
spaceLink.setId(spaceLinkId1);
spaceLink.setTargetSpace(space);
Mockito.when(spaceRepo.findById(spaceId1)).thenReturn(Optional.empty());
Mockito.when(spaceLinkRepo.getLinkedSpaces(spaceId1)).thenReturn(Arrays.asList(spaceLink));
managerToTest.deleteSpaceById(spaceId1);
Mockito.verify(spaceLinkRepo).deleteBySourceSpaceId(spaceId1);
Expand All @@ -167,7 +170,8 @@ public void test_deleteSpaceById_whenLinksToSpace() {
space.setId(spaceId1);
spaceLink.setId(spaceLinkId1);
spaceLink.setTargetSpace(space);
Mockito.when(spaceLinkRepo.getLinkedFromSpaces(spaceId1)).thenReturn(Arrays.asList(spaceLink));
Mockito.when(spaceRepo.findById(spaceId1)).thenReturn(Optional.of(space));
Mockito.when(spaceLinkRepo.findByTargetSpace(space)).thenReturn(Arrays.asList(spaceLink));
managerToTest.deleteSpaceById(spaceId1);
Assert.assertEquals(spaceLink.getTargetSpace(), null);
Mockito.verify(spaceLinkRepo).deleteBySourceSpaceId(spaceId1);
Expand Down

0 comments on commit e07588c

Please sign in to comment.