Skip to content

Commit

Permalink
Merge pull request #237 from diging/develop
Browse files Browse the repository at this point in the history
Bug/vspc 177 (#236)
  • Loading branch information
jdamerow authored Aug 10, 2021
2 parents e97405b + 8abdf63 commit 9a2e418
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Optional;

import javax.persistence.EntityNotFoundException;
import javax.transaction.Transactional;

import org.apache.tika.Tika;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class SpaceManager implements ISpaceManager {
private SpaceLinkDisplayRepository spaceLinkDisplayRepo;

private final Logger logger = LoggerFactory.getLogger(getClass());

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -141,7 +143,8 @@ public CreationReturnValue storeSpace(ISpace space, byte[] image, String filenam
*
* @see
* edu.asu.diging.vspace.core.services.impl.ISpaceManager#storeSpace(edu.asu.
* diging.vspace.core.model.ISpace,edu.asu.diging.vspace.core.model.impl.VSImage)
* diging.vspace.core.model.ISpace,edu.asu.diging.vspace.core.model.impl.
* VSImage)
*/
@Override
public CreationReturnValue storeSpace(ISpace space, IVSImage image) {
Expand Down Expand Up @@ -201,7 +204,6 @@ public List<ISpace> getAllSpaces() {
return spaces;
}


@Override
public List<ISpace> getSpacesWithStatus(SpaceStatus status) {
List<ISpace> spaces = new ArrayList<>();
Expand All @@ -212,34 +214,34 @@ public List<ISpace> getSpacesWithStatus(SpaceStatus status) {
/**
* Method to delete space based on id
*
* @param id if id is null throws exception, else delete corresponding space
* @param id
* if id is null throws exception, else delete corresponding space
* @throws SpaceDoesNotExistException
*/
@Override
public void deleteSpaceById(String id) {
if(id != null) {
if (id != null) {
List<SpaceLink> spaceLinks = spaceLinkRepo.getLinkedSpaces(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
for(SpaceLink spaceLink : fromSpaceLinks) {
// To delete links that access to the space getting deleted and replacing it as
// null
for (SpaceLink spaceLink : fromSpaceLinks) {
spaceLink.setTargetSpace(null);
spaceLinkRepo.save(spaceLink);
}
// To delete the links on the space getting deleted
for(SpaceLink spaceLink : spaceLinks) {
for (SpaceLink spaceLink : spaceLinks) {
spaceLinkDisplayRepo.deleteBySpaceLinkId(spaceLink.getId());
}
spaceLinkRepo.deleteBySourceSpaceId(id);
// If the space is startSpace, we delete the space from the exhibition first.
if(exhibition != null && exhibition.getStartSpace() != null
if (exhibition != null && exhibition.getStartSpace() != null
&& exhibition.getStartSpace().getId().equalsIgnoreCase(id)) {
exhibition.setStartSpace(null);
exhibitRepo.save(exhibition);
Expand Down Expand Up @@ -268,25 +270,31 @@ public List<SpaceLink> getIncomingLinks(String id) {

@Override
public List<ISpace> getSpacesWithImageId(String imageId) {
if(imageId == null) {
if (imageId == null) {
return null;
}
Optional<VSImage> vsImage = imageRepo.findById(imageId);
if(!vsImage.isPresent()) {
if (!vsImage.isPresent()) {
return null;
}
List<ISpace> spaces = new ArrayList<>();
spaceRepo.findAllByImageId(imageId).forEach(space -> spaces.add(space));
return spaces;
}


@Override
public Iterable<Space> addIncomingLinkInfoToSpaces(Iterable<Space> spaces) {
Iterator<Space> iterator = spaces.iterator();
while(iterator.hasNext()) {
while (iterator.hasNext()) {
Space space = iterator.next();
space.setIncomingLinks( (spaceLinkRepo.findByTargetSpace(space)).size() > 0 ? true : false );
try {
space.setIncomingLinks((spaceLinkRepo.findByTargetSpace(space)).size() > 0 ? true : false);
} catch (EntityNotFoundException ex) {
// if the data is incomplete this might happen (e.g. spaces used in links
// don't exist anymore.
space.setIncomingLinks(false);
logger.error("Could not load space links.", ex);
}
}
return spaces;
}
Expand Down

0 comments on commit 9a2e418

Please sign in to comment.