Skip to content

Commit

Permalink
Fix canViewRecord function so that it returned the workflow record. (#…
Browse files Browse the repository at this point in the history
…8152)

* Fix canViewRecord function so that it returned the workflow record.
Prior to this fix, it would always return working copy record if it exists.
Also updated getInternalId to have better error handling

* Update services/src/main/java/org/fao/geonet/api/ApiUtils.java

Co-authored-by: Jose García <[email protected]>

* Fix number check based on review - was checking wrong value.

---------

Co-authored-by: Jose García <[email protected]>
  • Loading branch information
ianwallen and josegar74 committed Jun 24, 2024
1 parent e3f92aa commit 4728e7d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions services/src/main/java/org/fao/geonet/api/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,19 @@ public static String getInternalId(String uuidOrInternalId, Boolean approved)
id = String.valueOf(metadata.getId());
}

if (StringUtils.isEmpty(id)) {
//It wasn't a UUID
id = String.valueOf(metadataUtils.findOne(uuidOrInternalId).getId());
AbstractMetadata foundMetadata = null;
if (!StringUtils.hasLength(id) && Lib.type.isInteger(uuidOrInternalId)) {
//It wasn't a UUID so assume it is an internalId which should be a number
foundMetadata = metadataUtils.findOne(uuidOrInternalId);
} else if (Boolean.TRUE.equals(approved)) {
//It was a UUID, check if draft or approved version
id = String.valueOf(ApplicationContextHolder.get().getBean(MetadataRepository.class)
.findOneByUuid(uuidOrInternalId).getId());
foundMetadata = ApplicationContextHolder.get().getBean(MetadataRepository.class).findOneByUuid(uuidOrInternalId);
}
if (foundMetadata != null) {
id = String.valueOf(foundMetadata.getId());
}

if (StringUtils.isEmpty(id)) {
if (!StringUtils.hasLength(id)) {
throw new ResourceNotFoundException(String.format(
"Record with UUID '%s' not found in this catalog",
uuidOrInternalId));
Expand Down Expand Up @@ -295,13 +298,7 @@ public static AbstractMetadata canViewRecord(String metadataUuid, HttpServletReq
*/
public static AbstractMetadata canViewRecord(String metadataUuid, boolean approved, HttpServletRequest request) throws Exception {
String metadataId;
if (!approved) {
// If the record is not approved then we need to get the id of the record.
metadataId = getInternalId(metadataUuid, approved);
} else {
// Otherwise use the uuid or id that was supplied.
metadataId = metadataUuid;
}
metadataId = getInternalId(metadataUuid, approved);

AbstractMetadata metadata = getRecord(metadataId);
try {
Expand Down

0 comments on commit 4728e7d

Please sign in to comment.