Skip to content

Commit

Permalink
NIFI-13536 Added branch parameter to REST methods for listing buckets…
Browse files Browse the repository at this point in the history
… and flows

This closes #9071

Signed-off-by: David Handermann <exceptionfactory@apache.org>
  • Loading branch information
bbende authored and exceptionfactory committed Jul 18, 2024
1 parent e205f27 commit 16c9ea4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2438,31 +2438,34 @@ ControllerServiceReferencingComponentsEntity updateControllerServiceReferencingC
* Gets the flows for the current user for the specified registry and bucket.
*
* @param registryClientId registry client id
* @param branch the branch
* @param bucketId bucket id
* @return the flows
*/
Set<VersionedFlowEntity> getFlowsForUser(String registryClientId, String bucketId);
Set<VersionedFlowEntity> getFlowsForUser(String registryClientId, String branch, String bucketId);


/**
* Returns the details of a versioned flow from a given bucket of a given registry.
*
* @param registryClientId registry client id
* @param branch the branch
* @param bucketId bucket id
* @param flowId flow id
* @return the flow details
*/
VersionedFlowEntity getFlowForUser(String registryClientId, String bucketId, String flowId);
VersionedFlowEntity getFlowForUser(String registryClientId, String branch, String bucketId, String flowId);

/**
* Gets the versions of the specified registry, bucket, and flow for the current user.
*
* @param registryClientId registry client id
* @param branch the branch
* @param bucketId bucket id
* @param flowId flow id
* @return the versions of the flow
*/
Set<VersionedFlowSnapshotMetadataEntity> getFlowVersionsForUser(String registryClientId, String bucketId, String flowId);
Set<VersionedFlowSnapshotMetadataEntity> getFlowVersionsForUser(String registryClientId, String branch, String bucketId, String flowId);

/**
* Updates the specified registry using the specified revision.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3272,27 +3272,24 @@ public Set<FlowRegistryBucketEntity> getBucketsForUser(final String registryClie
}

@Override
public Set<VersionedFlowEntity> getFlowsForUser(final String registryClientId, final String bucketId) {
public Set<VersionedFlowEntity> getFlowsForUser(final String registryClientId, final String branch, final String bucketId) {
final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
final FlowRegistryBranch defaultBranch = flowRegistryDAO.getDefaultBranchForUser(clientUserContext, registryClientId);
return flowRegistryDAO.getFlowsForUser(clientUserContext, registryClientId, defaultBranch.getName(), bucketId).stream()
return flowRegistryDAO.getFlowsForUser(clientUserContext, registryClientId, branch, bucketId).stream()
.map(rf -> createVersionedFlowEntity(registryClientId, rf))
.collect(Collectors.toSet());
}

@Override
public VersionedFlowEntity getFlowForUser(final String registryClientId, final String bucketId, final String flowId) {
public VersionedFlowEntity getFlowForUser(final String registryClientId, final String branch, final String bucketId, final String flowId) {
final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
final FlowRegistryBranch defaultBranch = flowRegistryDAO.getDefaultBranchForUser(clientUserContext, registryClientId);
final RegisteredFlow flow = flowRegistryDAO.getFlowForUser(clientUserContext, registryClientId, defaultBranch.getName(), bucketId, flowId);
final RegisteredFlow flow = flowRegistryDAO.getFlowForUser(clientUserContext, registryClientId, branch, bucketId, flowId);
return createVersionedFlowEntity(registryClientId, flow);
}

@Override
public Set<VersionedFlowSnapshotMetadataEntity> getFlowVersionsForUser(final String registryClientId, final String bucketId, final String flowId) {
public Set<VersionedFlowSnapshotMetadataEntity> getFlowVersionsForUser(final String registryClientId, final String branch, final String bucketId, final String flowId) {
final FlowRegistryClientUserContext clientUserContext = FlowRegistryClientContextFactory.getContextForUser(NiFiUserUtils.getNiFiUser());
final FlowRegistryBranch defaultBranch = flowRegistryDAO.getDefaultBranchForUser(clientUserContext, registryClientId);
return flowRegistryDAO.getFlowVersionsForUser(clientUserContext, registryClientId, defaultBranch.getName(), bucketId, flowId).stream()
return flowRegistryDAO.getFlowVersionsForUser(clientUserContext, registryClientId, branch, bucketId, flowId).stream()
.map(md -> createVersionedFlowSnapshotMetadataEntity(registryClientId, md))
.collect(Collectors.toCollection(LinkedHashSet::new));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ public Response getBuckets(
@Parameter(
description = "The name of a branch to get the buckets from. If not specified the default branch of the registry client will be used."
)
@QueryParam("branch") String branch) throws NiFiRegistryException {
@QueryParam("branch") String branch) {

authorizeFlow();

Expand Down Expand Up @@ -1995,11 +1995,16 @@ public Response getFlows(
description = "The bucket id.",
required = true
)
@PathParam("bucket-id") String bucketId) {
@PathParam("bucket-id") String bucketId,
@Parameter(
description = "The name of a branch to get the flows from. If not specified the default branch of the registry client will be used."
)
@QueryParam("branch") String branch) {

authorizeFlow();

final Set<VersionedFlowEntity> registeredFlows = serviceFacade.getFlowsForUser(registryId, bucketId);
final String selectedBranch = branch == null ? serviceFacade.getDefaultBranch(registryId).getBranch().getName() : branch;
final Set<VersionedFlowEntity> registeredFlows = serviceFacade.getFlowsForUser(registryId, selectedBranch, bucketId);
final SortedSet<VersionedFlowEntity> sortedFlows = sortFlows(registeredFlows);

final VersionedFlowsEntity versionedFlowsEntity = new VersionedFlowsEntity();
Expand Down Expand Up @@ -2054,11 +2059,16 @@ public Response getDetails(
description = "The flow id.",
required = true
)
@PathParam("flow-id") String flowId) {
@PathParam("flow-id") String flowId,
@Parameter(
description = "The name of a branch to get the flow from. If not specified the default branch of the registry client will be used."
)
@QueryParam("branch") String branch) {

authorizeFlow();

final VersionedFlowEntity flowDetails = serviceFacade.getFlowForUser(registryId, bucketId, flowId);
final String selectedBranch = branch == null ? serviceFacade.getDefaultBranch(registryId).getBranch().getName() : branch;
final VersionedFlowEntity flowDetails = serviceFacade.getFlowForUser(registryId, selectedBranch, bucketId, flowId);
return generateOkResponse(flowDetails).build();
}

Expand Down Expand Up @@ -2191,11 +2201,16 @@ public Response getVersions(
description = "The flow id.",
required = true
)
@PathParam("flow-id") String flowId) {
@PathParam("flow-id") String flowId,
@Parameter(
description = "The name of a branch to get the flow versions from. If not specified the default branch of the registry client will be used."
)
@QueryParam("branch") String branch) {

authorizeFlow();

final Set<VersionedFlowSnapshotMetadataEntity> registeredFlowSnapshotMetadataSet = serviceFacade.getFlowVersionsForUser(registryId, bucketId, flowId);
final String selectedBranch = branch == null ? serviceFacade.getDefaultBranch(registryId).getBranch().getName() : branch;
final Set<VersionedFlowSnapshotMetadataEntity> registeredFlowSnapshotMetadataSet = serviceFacade.getFlowVersionsForUser(registryId, selectedBranch, bucketId, flowId);

final VersionedFlowSnapshotMetadataSetEntity versionedFlowSnapshotMetadataSetEntity = new VersionedFlowSnapshotMetadataSetEntity();
versionedFlowSnapshotMetadataSetEntity.setVersionedFlowSnapshotMetadataSet(registeredFlowSnapshotMetadataSet);
Expand Down

0 comments on commit 16c9ea4

Please sign in to comment.