-
Notifications
You must be signed in to change notification settings - Fork 3
Story/vspc 196 #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Story/vspc 196 #344
Changes from all commits
bc5fd0b
53ed254
0466d24
abb5e86
8570989
e88f51c
b4f181d
83af595
eead7d2
f0fb64f
4eb3421
8d554ba
16e70d5
782bc9d
ac9881b
6181c3c
f438063
a3550c7
931c1c7
56ec6cc
bb8bab3
757fd0b
75e74b3
cd55e23
fda3666
1103247
8f67f83
574a8fe
3664213
b961df0
d43c21c
62d4b17
5e06a9c
d836461
0b28067
3d1e014
628a36d
6b5abca
c881484
0ee7527
9a8996e
9a875e6
939ee9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,13 @@ | |
| import edu.asu.diging.vspace.core.model.IVSImage; | ||
| import edu.asu.diging.vspace.core.model.IVSpaceElement; | ||
| import edu.asu.diging.vspace.core.model.display.DisplayType; | ||
| import edu.asu.diging.vspace.core.model.display.ExternalLinkDisplayMode; | ||
| import edu.asu.diging.vspace.core.model.display.ILinkDisplay; | ||
| import edu.asu.diging.vspace.core.model.impl.VSImage; | ||
| import edu.asu.diging.vspace.core.services.IImageService; | ||
| import edu.asu.diging.vspace.core.services.ILinkManager; | ||
| import edu.asu.diging.vspace.core.services.ISpaceManager; | ||
|
|
||
| import edu.asu.diging.vspace.core.exception.ImageDoesNotExistException; | ||
| @Transactional | ||
| public abstract class LinkManager<L extends ILink<T>, T extends IVSpaceElement, U extends ILinkDisplay> | ||
| implements ILinkManager<L, T, U> { | ||
|
|
@@ -36,37 +38,82 @@ public abstract class LinkManager<L extends ILink<T>, T extends IVSpaceElement, | |
|
|
||
| @Autowired | ||
| private IStorageEngine storage; | ||
|
|
||
| @Autowired | ||
| private IImageService imageService; | ||
|
|
||
| protected abstract void deleteLinkRepo(L link); | ||
|
|
||
| protected abstract void deleteLinkDisplayRepo(L link); | ||
|
|
||
| protected abstract void removeFromLinkList(ISpace space, L link); | ||
|
|
||
| protected abstract U updateLinkAndDisplay(L link, U displayLink); | ||
|
|
||
| protected abstract U getDisplayLink(String linkDisplayId) throws LinkDoesNotExistsException; | ||
|
|
||
| protected abstract L getLink(String linkId); | ||
|
|
||
| protected abstract L createLinkObject(String title, String id) throws SpaceDoesNotExistException; | ||
|
|
||
| protected abstract T getTarget(String linkedId); | ||
|
|
||
| protected abstract U createDisplayLink(L link); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm so confused, why is this here? I this needed for this ticket?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah I see, this should not be moved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This came from merging changes from the main branch |
||
| @Override | ||
| public U createLink(String title, String id, float positionX, float positionY, int rotation, String linkedId, | ||
| String linkLabel, DisplayType displayType, byte[] linkImage, String imageFilename) | ||
| throws SpaceDoesNotExistException, ImageCouldNotBeStoredException, SpaceDoesNotExistException { | ||
| String linkLabel, String linkDesc, DisplayType displayType, byte[] linkImage, String imageFilename, String existingImageId) | ||
| throws SpaceDoesNotExistException, ImageCouldNotBeStoredException, ImageDoesNotExistException { | ||
|
|
||
| if (title == null || title.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("Title cannot be null or empty."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not the right exception to throw; it's a runtime exception so it does not need to be caught and handled, because it would be thrown if it's an argument that simply can't be dealt with. Here, it can definitely be dealt with if the title is null (simply ask the user to enter a title). Also, I don't see why the title couldn't be empty. If the user, for instance, adds an image, there does not need to be title to make this work. |
||
| } | ||
| if (id == null || id.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("ID cannot be null or empty."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above, wrong exception to be thrown. |
||
| } | ||
| if (linkedId == null || linkedId.trim().isEmpty()) { | ||
| throw new SpaceDoesNotExistException("Linked ID cannot be null or empty."); | ||
| } | ||
| if (displayType == null) { | ||
| throw new IllegalArgumentException("DisplayType cannot be null."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
| } | ||
| if ((linkImage == null || linkImage.length == 0) && (existingImageId == null || existingImageId.trim().isEmpty())) { | ||
| throw new ImageDoesNotExistException("Either linkImage or existingImageId must be provided."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong exception to throw. Image does not exist is different than no image provided. |
||
| } | ||
|
|
||
| L link = createLinkObject(title, id); | ||
| T target = getTarget(linkedId); | ||
| link.setName(linkLabel); | ||
| link.setDescription(linkDesc); | ||
| link.setTarget(target); | ||
| U displayLink = createDisplayLink(link); | ||
| setDisplayProperties(displayLink, id, positionX, positionY, rotation, displayType, linkImage, imageFilename); | ||
| if(existingImageId!=null && !existingImageId.trim().isEmpty()) { | ||
| setDisplayProperties(displayLink, positionX, positionY, rotation, displayType, existingImageId); | ||
| } else { | ||
| setDisplayProperties(displayLink, id, positionX, positionY, rotation, displayType, linkImage, imageFilename); | ||
| } | ||
| return updateLinkAndDisplay(link, displayLink); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public U updateLink(String title, String id, float positionX, float positionY, int rotation, String linkedId, | ||
| String linkLabel, String linkId, String linkDisplayId, DisplayType displayType, byte[] linkImage, | ||
| String imageFilename) | ||
| throws SpaceDoesNotExistException, LinkDoesNotExistsException, ImageCouldNotBeStoredException { | ||
|
|
||
| String linkLabel, String linkDesc, String linkId, String linkDisplayId, DisplayType displayType, byte[] linkImage, | ||
| String imageFilename, String existingImageId) | ||
| throws SpaceDoesNotExistException, LinkDoesNotExistsException, ImageCouldNotBeStoredException, ImageDoesNotExistException { | ||
| validateSpace(id); | ||
|
|
||
| L link = getLink(linkId); | ||
| T target = getTarget(linkedId); | ||
| link.setName(title); | ||
| link.setDescription(linkDesc); | ||
| link.setTarget(target); | ||
| U displayLink = getDisplayLink(linkDisplayId); | ||
| setDisplayProperties(displayLink, id, positionX, positionY, rotation, displayType, linkImage, imageFilename); | ||
| return updateLinkAndDisplay(link, displayLink); | ||
| if(existingImageId!=null && !existingImageId.trim().isEmpty()) { | ||
| setDisplayProperties(displayLink, positionX, positionY, rotation, displayType, existingImageId); | ||
| } else { | ||
| setDisplayProperties(displayLink, id, positionX, positionY, rotation, displayType, linkImage, imageFilename); | ||
| } | ||
| return updateLinkAndDisplay(link,displayLink); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -77,38 +124,26 @@ public void deleteLink(String linkId) { | |
| deleteLinkRepo(link); | ||
| } | ||
|
|
||
| protected abstract void deleteLinkRepo(L link); | ||
|
|
||
| protected abstract void deleteLinkDisplayRepo(L link); | ||
|
|
||
| protected abstract void removeFromLinkList(ISpace space, L link); | ||
|
|
||
| protected abstract U updateLinkAndDisplay(L link, U displayLink); | ||
|
|
||
| protected abstract U getDisplayLink(String linkDisplayId) throws LinkDoesNotExistsException; | ||
|
|
||
| protected abstract L getLink(String linkId); | ||
|
|
||
| protected abstract L createLinkObject(String title, String id); | ||
|
|
||
| protected abstract T getTarget(String linkedId); | ||
|
|
||
| protected abstract U createDisplayLink(L link); | ||
|
|
||
| protected void validateSpace(String id) throws SpaceDoesNotExistException { | ||
| ISpace source = spaceManager.getSpace(id); | ||
| if (source == null) { | ||
| throw new SpaceDoesNotExistException(); | ||
| } | ||
| } | ||
|
|
||
| protected void setLinkDisplay(ILinkDisplay linkDisplay, float positionX, float positionY, int rotation, DisplayType displayType) { | ||
| linkDisplay.setPositionX(positionX); | ||
| linkDisplay.setPositionY(positionY); | ||
| linkDisplay.setRotation(rotation); | ||
| linkDisplay.setType(displayType != null ? displayType : DisplayType.ARROW); | ||
| } | ||
|
|
||
| protected void setDisplayProperties(ILinkDisplay linkDisplay, String id, float positionX, float positionY, | ||
| int rotation, DisplayType displayType, byte[] linkImage, String imageFilename) | ||
| throws ImageCouldNotBeStoredException { | ||
| linkDisplay.setPositionX(positionX); | ||
| linkDisplay.setPositionY(positionY); | ||
| linkDisplay.setRotation(rotation); | ||
| linkDisplay.setType(displayType != null ? displayType : DisplayType.ARROW); | ||
|
|
||
| setLinkDisplay(linkDisplay, positionX, positionY, rotation, displayType); | ||
|
|
||
| if (linkImage != null && linkImage.length > 0) { | ||
| Tika tika = new Tika(); | ||
| String contentType = tika.detect(linkImage); | ||
|
|
@@ -125,4 +160,15 @@ protected void setDisplayProperties(ILinkDisplay linkDisplay, String id, float p | |
| linkDisplay.setImage(image); | ||
| } | ||
| } | ||
|
|
||
| protected void setDisplayProperties(ILinkDisplay linkDisplay, float positionX, float positionY, int rotation, | ||
| DisplayType displayType, String existingImageId) throws ImageCouldNotBeStoredException, ImageDoesNotExistException { | ||
| setLinkDisplay(linkDisplay, positionX, positionY, rotation, displayType); | ||
| if(existingImageId!=null && !existingImageId.trim().isEmpty()) { | ||
| IVSImage image = imageService.getImageById(existingImageId); | ||
| linkDisplay.setImage(image); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.