Skip to content

Commit

Permalink
Merge branch 'dev' into #343_suggest_change_and_log
Browse files Browse the repository at this point in the history
# Conflicts:
#	registry-service/src/main/java/org/gbif/registry/service/collections/PrimaryCollectionEntityService.java
#	registry-ws-client/src/main/java/org/gbif/registry/ws/client/collections/CrudClient.java
#	registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/PersonResource.java
  • Loading branch information
marcos-lg committed Apr 29, 2021
2 parents 4e10530 + 6717f1f commit 49cb02c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.gbif.registry.search.dataset.indexing.DatasetRealtimeIndexer;
import org.gbif.ws.NotFoundException;

import java.util.Objects;
import java.util.UUID;

import org.slf4j.Logger;
Expand Down Expand Up @@ -72,22 +73,24 @@ public final <T> void updated(UpdateEvent<T> event) {
// we only care about title & country changes
Organization org1 = (Organization) event.getOldObject();
Organization org2 = (Organization) event.getNewObject();
if (!org1.getTitle().equals(org2.getTitle()) || org1.getCountry() != org2.getCountry()) {
if (!Objects.equals(org1.getTitle(), org2.getTitle()) ||
!Objects.equals(org1.getCountry(), org2.getCountry())) {
indexService.index(org2);
}

} else if (event.getObjectClass().equals(Installation.class)) {
// we only care about the hosting organization
Installation i1 = (Installation) event.getOldObject();
Installation i2 = (Installation) event.getNewObject();
if (!i1.getOrganizationKey().equals(i2.getOrganizationKey())) {
if (!Objects.equals(i1.getOrganizationKey(), (i2.getOrganizationKey())) ||
!Objects.equals(i1.getTitle(), i2.getTitle())) {
indexService.index(i2);
}
} else if (event.getObjectClass().equals(Network.class)) {
// we only care about title changes
Network network1 = (Network)event.getOldObject();
Network network2 = (Network)event.getNewObject();
if (!network1.getTitle().equals(network2.getTitle())) {
if (!Objects.equals(network1.getTitle(), network2.getTitle())) {
indexService.index(network2);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void updateInvalidEntityTest(ServiceType serviceType) {

T newEntity = newInvalidEntity();
newEntity.setKey(key);
assertThrows(Exception.class, () -> service.update(newEntity));
assertThrows(ValidationException.class, () -> service.update(newEntity));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ public interface NetworkEntityClient<T extends NetworkEntity> extends NetworkEnt
@Override
PagingResponse<T> list(@SpringQueryMap Pageable page);

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

@RequestMapping(
method = RequestMethod.PUT,
value = "{key}",
consumes = MediaType.APPLICATION_JSON_VALUE)
void updateResource(@PathVariable("key") UUID key, @RequestBody T entity);

@RequestMapping(
method = RequestMethod.GET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public interface CrudClient<T extends CollectionEntity> extends CrudService<T> {

@Override
default void update(@RequestBody T entity) {
updateEntity(entity.getKey(), entity);
updateResource(entity.getKey(), entity);
}

@RequestMapping(
method = RequestMethod.PUT,
value = "{key}",
consumes = MediaType.APPLICATION_JSON_VALUE)
void updateEntity(@PathVariable("key") UUID key, @RequestBody T entity);
method = RequestMethod.PUT,
value = "{key}",
consumes = MediaType.APPLICATION_JSON_VALUE)
void updateResource(@PathVariable("key") UUID key, @RequestBody T entity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.UUID;

import javax.annotation.Nullable;
import javax.validation.Valid;
import javax.validation.groups.Default;

import org.slf4j.Logger;
Expand All @@ -76,6 +77,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.Maps;

import static com.google.common.base.Preconditions.checkArgument;
import static org.gbif.registry.security.UserRoles.ADMIN_ROLE;
import static org.gbif.registry.security.UserRoles.APP_ROLE;
import static org.gbif.registry.security.UserRoles.EDITOR_ROLE;
Expand Down Expand Up @@ -229,15 +231,18 @@ public PagingResponse<T> listByIdentifier(String identifier, Pageable page) {
*
* @param entity entity that extends NetworkEntity
*/
@PutMapping(
value = {"", "{key}"},
consumes = MediaType.APPLICATION_JSON_VALUE)
@PutMapping(value = "{key}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Validated({PostPersist.class, Default.class})
@Trim
@Transactional
@Secured({ADMIN_ROLE, EDITOR_ROLE, IPT_ROLE})
public void update(@PathVariable("key") UUID key, @Valid @RequestBody @Trim T entity) {
checkArgument(key.equals(entity.getKey()));
update(entity);
}

@Override
public void update(@RequestBody @Trim T entity) {
public void update(T entity) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
entity.setModifiedBy(authentication.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.gbif.api.model.registry.LenientEquals;
import org.gbif.api.model.registry.Metadata;
import org.gbif.api.model.registry.Network;
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.search.DatasetSearchParameter;
Expand Down Expand Up @@ -551,14 +550,8 @@ public UUID create(@RequestBody @Trim Dataset dataset) {
return key;
}

@PutMapping(
value = {"", "{key}"},
consumes = MediaType.APPLICATION_JSON_VALUE)
@Validated({PostPersist.class, Default.class})
@Trim
@Secured({ADMIN_ROLE, EDITOR_ROLE, IPT_ROLE})
@Override
public void update(@RequestBody @Trim Dataset dataset) {
public void update(Dataset dataset) {
Dataset old = super.get(dataset.getKey());
if (old == null) {
throw new IllegalArgumentException("Dataset " + dataset.getKey() + " not existing");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
import org.gbif.api.model.collections.Person;
import org.gbif.api.model.common.paging.Pageable;
import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.registry.PostPersist;
import org.gbif.api.model.registry.search.collections.PersonSuggestResult;
import org.gbif.registry.service.collections.DefaultPersonService;

import java.util.List;
import java.util.UUID;

import javax.validation.Valid;
import javax.validation.groups.Default;

import org.springframework.http.MediaType;
import org.springframework.security.access.annotation.Secured;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -68,9 +72,10 @@ public UUID create(@RequestBody @Trim Person person) {
}

@PutMapping(value = "{key}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Validated({PostPersist.class, Default.class})
@Trim
@Secured({GRSCICOLL_ADMIN_ROLE, GRSCICOLL_EDITOR_ROLE})
public void update(@PathVariable("key") UUID key, @RequestBody @Trim Person person) {
public void update(@PathVariable("key") UUID key, @Valid @RequestBody @Trim Person person) {
checkArgument(key.equals(person.getKey()));
personService.update(person);
}
Expand Down
2 changes: 1 addition & 1 deletion roadmap-grscicoll.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The connection with Index Herbariorum and import of iDigBio enriched the catalog

The current processes are weak, and don’t capture the proposed change in a structured manner.

* Develop an interface allowing anyone to propose a change to any/all fields and state whether they have authority to approve it. Changes are then to be reviewed and applied by the editorial team [[REG-299](https://github.com/gbif/registry/issues/299)].
* Develop an interface allowing anyone to propose a change to any/all fields and state whether they have authority to approve it. Changes are then to be reviewed and applied by the editorial team [[REG-CONSOLE-376](https://github.com/gbif/registry-console/issues/376)].

## Improve documentation

Expand Down

0 comments on commit 49cb02c

Please sign in to comment.