Skip to content

Commit

Permalink
removed the PUT without key for collections
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed Apr 28, 2021
1 parent 6c4501c commit 0419758
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,21 +561,23 @@ public void createCollectionWithoutCodeTest(ServiceType serviceType) {
public void updateCollectionWithoutCodeTest(ServiceType serviceType) {
CollectionService service = (CollectionService) getService(serviceType);
Collection c = newEntity();
service.create(c);
UUID key = service.create(c);

c.setCode(null);
assertThrows(IllegalArgumentException.class, () -> service.update(c));
Collection created = service.get(key);
created.setCode(null);
assertThrows(IllegalArgumentException.class, () -> service.update(created));
}

@ParameterizedTest
@EnumSource(ServiceType.class)
public void updateAndReplaceTest(ServiceType serviceType) {
CollectionService service = (CollectionService) getService(serviceType);
Collection c = newEntity();
service.create(c);
UUID key = service.create(c);

c.setReplacedBy(UUID.randomUUID());
assertThrows(IllegalArgumentException.class, () -> service.update(c));
Collection created = service.get(key);
created.setReplacedBy(UUID.randomUUID());
assertThrows(IllegalArgumentException.class, () -> service.update(created));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,25 +407,27 @@ public void createInstitutionWithoutCodeTest(ServiceType serviceType) {
public void updateInstitutionWithoutCodeTest(ServiceType serviceType) {
InstitutionService service = (InstitutionService) getService(serviceType);
Institution i = newEntity();
service.create(i);
UUID key = service.create(i);

i.setCode(null);
assertThrows(IllegalArgumentException.class, () -> service.update(i));
Institution created = service.get(key);
created.setCode(null);
assertThrows(IllegalArgumentException.class, () -> service.update(created));
}

@ParameterizedTest
@EnumSource(ServiceType.class)
public void updateAndReplaceTest(ServiceType serviceType) {
InstitutionService service = (InstitutionService) getService(serviceType);
Institution i = newEntity();
service.create(i);
UUID key = service.create(i);

i.setReplacedBy(UUID.randomUUID());
assertThrows(IllegalArgumentException.class, () -> service.update(i));
Institution created = service.get(key);
created.setReplacedBy(UUID.randomUUID());
assertThrows(IllegalArgumentException.class, () -> service.update(created));

i.setReplacedBy(null);
i.setConvertedToCollection(UUID.randomUUID());
assertThrows(IllegalArgumentException.class, () -> service.update(i));
created.setReplacedBy(null);
created.setConvertedToCollection(UUID.randomUUID());
assertThrows(IllegalArgumentException.class, () -> service.update(created));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ public interface CrudClient<T extends CollectionEntity> extends CrudService<T> {
@Override
T get(@PathVariable("key") UUID key);

@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
@Override
void update(@RequestBody T entity);
default void update(@RequestBody T entity) {
updateEntity(entity.getKey(), entity);
}

@RequestMapping(
method = RequestMethod.PUT,
value = "{key}",
consumes = MediaType.APPLICATION_JSON_VALUE)
void updateEntity(@PathVariable("key") UUID key, @RequestBody T entity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,9 @@

import org.gbif.api.annotation.Trim;
import org.gbif.api.model.collections.Address;
import org.gbif.api.model.collections.Collection;
import org.gbif.api.model.collections.CollectionEntity;
import org.gbif.api.model.collections.Contactable;
import org.gbif.api.model.collections.Institution;
import org.gbif.api.model.collections.OccurrenceMappeable;
import org.gbif.api.model.collections.OccurrenceMapping;
import org.gbif.api.model.collections.Person;
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.PrePersist;
import org.gbif.api.model.registry.Tag;
import org.gbif.api.model.registry.Taggable;
import org.gbif.api.model.collections.*;
import org.gbif.api.model.registry.*;
import org.gbif.api.service.collections.ContactService;
import org.gbif.api.service.collections.OccurrenceMappingService;
import org.gbif.registry.events.EventManager;
Expand Down Expand Up @@ -67,10 +55,10 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.google.common.base.Preconditions.checkArgument;
import static org.gbif.registry.security.UserRoles.GRSCICOLL_ADMIN_ROLE;
import static org.gbif.registry.security.UserRoles.GRSCICOLL_EDITOR_ROLE;
import static org.gbif.registry.security.UserRoles.IDIGBIO_GRSCICOLL_EDITOR_ROLE;
import static com.google.common.base.Preconditions.checkArgument;

/**
* Base class to implement the main methods of {@link CollectionEntity} that are also @link
Expand Down Expand Up @@ -183,9 +171,7 @@ public UUID create(@RequestBody @Trim T entity) {
return entity.getKey();
}

@PutMapping(
value = {"", "{key}"},
consumes = MediaType.APPLICATION_JSON_VALUE)
@PutMapping(value = "{key}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Trim
@Transactional
@Secured({GRSCICOLL_ADMIN_ROLE, GRSCICOLL_EDITOR_ROLE})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ public UUID create(@RequestBody @Trim Person person) {
return person.getKey();
}

@PutMapping(
value = {"", "{key}"},
consumes = MediaType.APPLICATION_JSON_VALUE)
@PutMapping(value = "{key}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Trim
@Transactional
@Secured({GRSCICOLL_ADMIN_ROLE, GRSCICOLL_EDITOR_ROLE})
Expand Down

0 comments on commit 0419758

Please sign in to comment.