Skip to content

Commit

Permalink
Merge pull request #364 from GBishop-PHSA/feature/gh-363
Browse files Browse the repository at this point in the history
gh-363 request param to select finalized models by label
  • Loading branch information
joe-crawford authored Oct 18, 2022
2 parents d2ec1b2 + 74131e7 commit 60a52a4
Show file tree
Hide file tree
Showing 29 changed files with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class PathController extends RestfulController<CatalogueItem> implements MdmCont
}

// Permissions have been checked as part of the interceptor
pathedResource = pathService.findResourceByPathFromRootResource(resource as MdmDomain, params.path)
pathedResource = pathService.findResourceByPathFromRootResource(resource as MdmDomain, params.path, null, [finalised: params.finalised])
} else {
pathedResource = pathService.findResourceByPathFromRootClass(params.securableResourceClass, params.path, currentUserSecurityPolicyManager)
pathedResource =
pathService.findResourceByPathFromRootClass(params.securableResourceClass, params.path, currentUserSecurityPolicyManager, [finalised: params.finalised])
}

if (!pathedResource) return notFound(DomainClass, params.path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class AsyncJobService implements MdmDomainService<AsyncJob> {
}

@Override
AsyncJob findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
AsyncJob findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DomainExportService implements MdmDomainService<DomainExport> {
}

@Override
DomainExport findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
DomainExport findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
throw new ApiNotYetImplementedException('DES', 'findByParentIdAndPathIdentifier')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AuthorityService implements SecurableResourceService<Authority>, MdmDomain
}

@Override
Authority findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
Authority findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
String[] pids = pathIdentifier.split('@')
Authority.findByLabelAndUrl(pids[0], pids[1])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ class VersionedFolderService extends ContainerService<VersionedFolder> implement
}

@Override
VersionedFolder findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
VersionedFolder findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
String[] split = pathIdentifier.split(PathNode.ESCAPED_MODEL_PATH_IDENTIFIER_SEPARATOR)
String label = split[0]
boolean finalisedOnly = pathParams.finalised ? pathParams.finalised.toBoolean() : false

// A specific identity of the model has been requested so make sure we limit to that
if (split.size() == 2) {
Expand All @@ -197,7 +198,7 @@ class VersionedFolderService extends ContainerService<VersionedFolder> implement
}

// If no identity part then we can just get the latest model by the label
findLatestModelByLabel(label)
finalisedOnly ? findLatestFinalisedModelByLabel(label) : findLatestModelByLabel(label)
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class AnnotationService implements MultiFacetItemAwareService<Annotation> {
}

@Override
Annotation findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
Annotation findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
Annotation.byMultiFacetAwareItemId(parentId).eq('label', pathIdentifier).get()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class MetadataService implements MultiFacetItemAwareService<Metadata> {
}

@Override
Metadata findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
Metadata findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
String ns
String key
pathIdentifier.find(/^(.+)\.(.+)$/) {all, foundNs, foundKey ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ReferenceFileService implements CatalogueFileService<ReferenceFile>, Multi
}

@Override
ReferenceFile findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
ReferenceFile findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
ReferenceFile.byMultiFacetAwareItemId(parentId).eq('fileName', pathIdentifier).get()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class RuleService implements MultiFacetItemAwareService<Rule> {
}

@Override
Rule findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
Rule findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
Rule.byMultiFacetAwareItemId(parentId).eq('name', pathIdentifier).get()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SemanticLinkService implements MultiFacetItemAwareService<SemanticLink> {
}

@Override
SemanticLink findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
SemanticLink findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
String[] split = pathIdentifier
SemanticLink.byMultiFacetAwareItemId(parentId)
.eq('linkType', SemanticLinkType.findForLabel(split[0]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class VersionLinkService implements MultiFacetItemAwareService<VersionLink> {
}

@Override
VersionLink findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
VersionLink findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
String[] split = pathIdentifier
VersionLink.byModelId(parentId)
.eq('linkType', SemanticLinkType.findForLabel(split[0]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RuleRepresentationService implements MdmDomainService<RuleRepresentation>
}

@Override
RuleRepresentation findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
RuleRepresentation findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
RuleRepresentation.byRuleId(parentId).eq('language', pathIdentifier).get()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PathService {
}.sort() as Map<String, String>
}

MdmDomain findResourceByPathFromRootResource(MdmDomain rootResourceOfPath, Path path, String modelIdentifierOverride = null) {
MdmDomain findResourceByPathFromRootResource(MdmDomain rootResourceOfPath, Path path, String modelIdentifierOverride = null, Map pathParams = [:]) {
log.trace('Searching for path {} inside {}:{}', path.toString(modelIdentifierOverride), rootResourceOfPath.pathPrefix,
rootResourceOfPath.pathIdentifier)
if (path.isEmpty()) {
Expand All @@ -97,22 +97,22 @@ class PathService {
}

log.trace('Found service [{}] to handle prefix [{}]', domainService.class.simpleName, childNode.prefix)
def child = domainService.findByParentIdAndPathIdentifier(rootResourceOfPath.id, childNode.getFullIdentifier(modelIdentifierOverride))
def child = domainService.findByParentIdAndPathIdentifier(rootResourceOfPath.id, childNode.getFullIdentifier(modelIdentifierOverride), pathParams)

if (!child) {
log.warn('Child [{}] does not exist in root resource [{}]', childNode, Path.from(rootResourceOfPath))
return null
}

// Recurse down the path for that child
findResourceByPathFromRootResource(child, pathToFind, modelIdentifierOverride)
findResourceByPathFromRootResource(child, pathToFind, modelIdentifierOverride, pathParams)
}

MdmDomain findResourceByPathFromRootClass(Class<? extends SecurableResource> rootClass, Path path) {
findResourceByPathFromRootClass(rootClass, path, null)
}

MdmDomain findResourceByPathFromRootClass(Class<? extends SecurableResource> rootClass, Path path, UserSecurityPolicyManager userSecurityPolicyManager) {
MdmDomain findResourceByPathFromRootClass(Class<? extends SecurableResource> rootClass, Path path, UserSecurityPolicyManager userSecurityPolicyManager, Map pathParams = [:]) {
if (path.isEmpty()) {
throw new ApiBadRequestException('PS05', 'Must have a path to search')
}
Expand All @@ -127,7 +127,7 @@ class PathService {
throw new ApiBadRequestException('PS04', "[${rootClass.simpleName}] is not a pathable resource")
}

MdmDomain rootResource = securableResourceService.findByParentIdAndPathIdentifier(null, rootNode.getFullIdentifier())
MdmDomain rootResource = securableResourceService.findByParentIdAndPathIdentifier(null, rootNode.getFullIdentifier(), pathParams)
if (!rootResource) return null

// Confirm root resource exists and its prefix matches the pathed prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ abstract class CatalogueItemService<K extends CatalogueItem> implements MdmDomai
}

@Override
K findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
K findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
findByParentIdAndLabel(parentId, pathIdentifier)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class ContainerService<K extends Container> implements SecurableResourc
}

@Override
K findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
K findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
findByParentIdAndLabel(parentId, pathIdentifier)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ abstract class ModelService<K extends Model>
}

@Override
K findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
K findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
String[] split = pathIdentifier.split(PathNode.ESCAPED_MODEL_PATH_IDENTIFIER_SEPARATOR)
String label = split[0]
boolean finalisedOnly = pathParams.finalised ? pathParams.finalised.toBoolean() : false

// A specific identity of the model has been requested so make sure we limit to that
if (split.size() == 2) {
Expand All @@ -328,7 +329,7 @@ abstract class ModelService<K extends Model>
}

// If no identity part then we can just get the latest model by the label
findLatestModelByLabel(label)
finalisedOnly ? findLatestFinalisedModelByLabel(label) : findLatestModelByLabel(label)
}

boolean useParentIdForSearching(UUID parentId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ trait MdmDomainService<K extends MdmDomain> implements AnonymisableService{

abstract K findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier)

abstract K findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams)

K save(K domain) {
// Default behaviours for save in GormEntity
save(flush: false, validate: true, domain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class SummaryMetadataService implements MultiFacetItemAwareService<SummaryMetada
}

@Override
SummaryMetadata findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
SummaryMetadata findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
SummaryMetadata.byMultiFacetAwareItemId(parentId).eq('label', pathIdentifier).get()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SummaryMetadataReportService implements MdmDomainService<SummaryMetadataRe
}

@Override
SummaryMetadataReport findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
SummaryMetadataReport findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
OffsetDateTime reportDate = OffsetDateTime.parse(pathIdentifier, SummaryMetadataReport.PATH_FORMATTER)
SummaryMetadataReport.bySummaryMetadataId(parentId).eq('reportDate', reportDate).get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ReferenceSummaryMetadataService implements MultiFacetItemAwareService<Refe
}

@Override
ReferenceSummaryMetadata findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
ReferenceSummaryMetadata findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
ReferenceSummaryMetadata.byMultiFacetAwareItemId(parentId).eq('label', pathIdentifier).get()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ReferenceSummaryMetadataReportService implements MdmDomainService<Referenc
}

@Override
ReferenceSummaryMetadataReport findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
ReferenceSummaryMetadataReport findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
OffsetDateTime reportDate = OffsetDateTime.parse(pathIdentifier, ReferenceSummaryMetadataReport.PATH_FORMATTER)
ReferenceSummaryMetadataReport.byReferenceSummaryMetadataId(parentId).eq('reportDate', reportDate).get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ReferenceDataValueService implements MdmDomainService<ReferenceDataValue>
}

@Override
ReferenceDataValue findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
ReferenceDataValue findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
ReferenceDataValue.byReferenceDataModelId(parentId).eq('rowNumber', pathIdentifier.toInteger()).get()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class TermService extends ModelItemService<Term> {
}

@Override
Term findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
Term findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
// Older code used the full term label which is not great but we should be able to handle this here
String legacyHandlingPathIdentifier = pathIdentifier.split(':')[0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class TermRelationshipService extends ModelItemService<TermRelationship> {
}

@Override
TermRelationship findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
TermRelationship findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
String[] split = pathIdentifier.split(/\./)
if (split.size() != 3) throw new ApiBadRequestException('TRS01', "TermRelationship Path identifier is invalid [${pathIdentifier}]")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CatalogueUserService implements UserService, MdmDomainService<CatalogueUse
}

@Override
CatalogueUser findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
CatalogueUser findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UserGroupService implements MdmDomainService<UserGroup> {
}

@Override
UserGroup findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
UserGroup findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
findByName(pathIdentifier)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ApiKeyService implements MdmDomainService<ApiKey> {
}

@Override
ApiKey findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
ApiKey findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class GroupRoleService implements MdmDomainService<GroupRole> {
}

@Override
GroupRole findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
GroupRole findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
getFromCache(pathIdentifier).groupRole
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SecurableResourceGroupRoleService implements MdmDomainService<SecurableRes
}

@Override
SecurableResourceGroupRole findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier) {
SecurableResourceGroupRole findByParentIdAndPathIdentifier(UUID parentId, String pathIdentifier, Map pathParams = [:]) {
return null
}

Expand Down

0 comments on commit 60a52a4

Please sign in to comment.