Skip to content

Commit

Permalink
checks before deleting subentities
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed May 26, 2021
1 parent ff97cf0 commit 850a030
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public int addIdentifier(UUID entityKey, Identifier identifier) {
@Override
public void deleteIdentifier(UUID entityKey, int identifierKey) {
Identifier identifierToDelete = identifierMapper.get(identifierKey);
checkArgument(identifierToDelete != null, "Identifier to delete doesn't exist");

baseMapper.deleteIdentifier(entityKey, identifierKey);

eventManager.post(
Expand Down Expand Up @@ -156,6 +158,8 @@ public int addTag(UUID key, String value) {
@Override
public void deleteTag(UUID entityKey, int tagKey) {
Tag tagToDelete = tagMapper.get(tagKey);
checkArgument(tagToDelete != null, "Tag to delete doesn't exist");

baseMapper.deleteTag(entityKey, tagKey);
eventManager.post(
SubEntityCollectionEvent.newInstance(
Expand Down Expand Up @@ -222,6 +226,8 @@ public int addMachineTag(UUID targetEntityKey, TagName tagName, String value) {
@Override
public void deleteMachineTag(UUID targetEntityKey, int machineTagKey) {
MachineTag machineTagToDelete = machineTagMapper.get(machineTagKey);
checkArgument(machineTagToDelete != null, "Machine Tag to delete doesn't exist");

baseMapper.deleteMachineTag(targetEntityKey, machineTagKey);
eventManager.post(
SubEntityCollectionEvent.newInstance(
Expand Down Expand Up @@ -270,6 +276,7 @@ public void deleteMachineTags(UUID targetEntityKey, String namespace, String nam
.collect(Collectors.toList());

baseMapper.deleteMachineTags(targetEntityKey, namespace, name);

machineTagsToDelete.forEach(
mt ->
eventManager.post(
Expand Down Expand Up @@ -316,6 +323,8 @@ public int addComment(UUID targetEntityKey, Comment comment) {
@Override
public void deleteComment(UUID targetEntityKey, int commentKey) {
Comment commentToDelete = commentMapper.get(commentKey);
checkArgument(commentToDelete != null, "Comment to delete doesn't exist");

baseMapper.deleteComment(targetEntityKey, commentKey);
eventManager.post(
SubEntityCollectionEvent.newInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import org.gbif.api.model.collections.PrimaryCollectionEntity;
import org.gbif.api.model.registry.Commentable;
import org.gbif.api.model.registry.Identifiable;
import org.gbif.api.model.registry.Identifier;
import org.gbif.api.model.registry.MachineTag;
import org.gbif.api.model.registry.MachineTaggable;
import org.gbif.api.model.registry.PostPersist;
import org.gbif.api.model.registry.PrePersist;
import org.gbif.api.model.registry.Tag;
import org.gbif.api.model.registry.Taggable;
import org.gbif.api.service.collections.PrimaryCollectionEntityService;
import org.gbif.registry.events.EventManager;
Expand Down Expand Up @@ -234,6 +231,8 @@ public List<OccurrenceMapping> listOccurrenceMappings(@NotNull UUID uuid) {
@Override
public void deleteOccurrenceMapping(UUID entityKey, int occurrenceMappingKey) {
OccurrenceMapping occurrenceMappingToDelete = occurrenceMappingMapper.get(occurrenceMappingKey);
checkArgument(occurrenceMappingToDelete != null, "Occurrence Mapping to delete doesn't exist");

primaryEntityMapper.deleteOccurrenceMapping(entityKey, occurrenceMappingKey);
eventManager.post(
SubEntityCollectionEvent.newInstance(
Expand Down

0 comments on commit 850a030

Please sign in to comment.