Skip to content

Commit

Permalink
NIFI-8957 NiFi Registry - Possibility to set a description when creat…
Browse files Browse the repository at this point in the history
…ing a bucket

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes apache#5271.
  • Loading branch information
adenes authored and emiliosetiadarma committed Aug 10, 2021
1 parent 64cf540 commit 54f83ae
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 35 deletions.
Expand Up @@ -27,7 +27,12 @@
<div fxLayout="column" fxLayoutAlign="space-between start" class="pad-bottom-md">
<div class="fill-available-width">
<mat-form-field floatLabel="always" fxFlex>
<input #newBucketInput matInput floatPlaceholder="always" placeholder="Bucket Name">
<input #newBucketName matInput floatPlaceholder="always" placeholder="Bucket Name">
</mat-form-field>
</div>
<div class="fill-available-width">
<mat-form-field floatLabel="always" fxFlex>
<input #newBucketDescription matInput floatPlaceholder="always" placeholder="Description">
</mat-form-field>
</div>
<mat-checkbox #newBucketPublicReadCheckbox [disabled]="protocol === 'http:'" >
Expand All @@ -44,7 +49,8 @@
i18n="Cancel creation of new bucket|A button for cancelling the creation of a new bucket in the registry.@@nf-admin-workflow-cancel-create-bucket-button">
Cancel
</button>
<button [disabled]="newBucketInput.value.length === 0" class="push-left-sm" data-automation-id="create-new-bucket-button" (click)="createBucket(newBucketInput,newBucketPublicReadCheckbox)"
<button [disabled]="newBucketName.value.length === 0" class="push-left-sm" data-automation-id="create-new-bucket-button"
(click)="createBucket(newBucketName, newBucketDescription, newBucketPublicReadCheckbox)"
color="fds-primary" mat-raised-button i18n="Create new bucket button|A button for creating a new bucket in the registry.@@nf-admin-workflow-create-bucket-button">
Create
</button>
Expand Down
Expand Up @@ -47,12 +47,13 @@ NfRegistryCreateBucket.prototype = {
/**
* Create a new bucket.
*
* @param newBucketInput The newBucketInput element.
* @param newBucketName The newBucketName element.
* @param newBucketDescription The newBucketDescription element.
* @param newBucketPublicReadCheckbox The newBucketPublicReadCheckbox element.
*/
createBucket: function (newBucketInput, newBucketPublicReadCheckbox) {
createBucket: function (newBucketName, newBucketDescription, newBucketPublicReadCheckbox) {
var self = this;
this.nfRegistryApi.createBucket(newBucketInput.value, newBucketPublicReadCheckbox.checked).subscribe(function (bucket) {
this.nfRegistryApi.createBucket(newBucketName.value, newBucketDescription.value, newBucketPublicReadCheckbox.checked).subscribe(function (bucket) {
if (!bucket.error) {
self.nfRegistryService.buckets.push(bucket);
self.nfRegistryService.filterBuckets();
Expand Down Expand Up @@ -80,21 +81,15 @@ NfRegistryCreateBucket.prototype = {
*/
cancel: function () {
this.dialogRef.close();
},

/**
* Focus the new bucket input.
*/
ngAfterViewChecked: function () {
this.newBucketInput.nativeElement.focus();
}
};

NfRegistryCreateBucket.annotations = [
new Component({
templateUrl: './nf-registry-create-bucket.html',
queries: {
newBucketInput: new ViewChild('newBucketInput')
newBucketName: new ViewChild('newBucketName'),
newBucketDescription: new ViewChild('newBucketDescription')
}
})
];
Expand Down
Expand Up @@ -39,19 +39,20 @@ describe('NfRegistryCreateBucket Component isolated unit tests', function () {

// Spy
spyOn(nfRegistryApi, 'createBucket').and.callFake(function () {
}).and.returnValue(of({name: 'NewBucket'}));
}).and.returnValue(of({name: 'NewBucket', description: 'NewBucket Description'}));
spyOn(nfRegistryService, 'filterBuckets');
spyOn(comp.dialogRef, 'close');
});

it('should create a new bucket and close the dialog', function () {
// The function to test
comp.createBucket({value: 'NewBucket'}, {checked: false});
comp.createBucket({value: 'NewBucket'}, {value: 'NewBucket Description'}, {checked: false});

//assertions
expect(comp).toBeDefined();
expect(nfRegistryService.buckets.length).toBe(1);
expect(nfRegistryService.buckets[0].name).toBe('NewBucket');
expect(nfRegistryService.buckets[0].description).toBe('NewBucket Description');
expect(nfRegistryService.filterBuckets).toHaveBeenCalled();
expect(comp.dialogRef.close).toHaveBeenCalled();
});
Expand All @@ -61,12 +62,13 @@ describe('NfRegistryCreateBucket Component isolated unit tests', function () {
comp.keepDialogOpen = true;

// The function to test
comp.createBucket({value: 'NewBucket'}, {checked: false});
comp.createBucket({value: 'NewBucket'}, {value: 'NewBucket Description'}, {checked: false});

//assertions
expect(comp).toBeDefined();
expect(nfRegistryService.buckets.length).toBe(1);
expect(nfRegistryService.buckets[0].name).toBe('NewBucket');
expect(nfRegistryService.buckets[0].description).toBe('NewBucket Description');
expect(nfRegistryService.filterBuckets).toHaveBeenCalled();
expect(comp.dialogRef.close.calls.count()).toEqual(0);
});
Expand Down
Expand Up @@ -49,14 +49,14 @@
fxLayoutAlign="space-between center" class="td-data-table">
<div class="td-data-table-column" (click)="nfRegistryService.sortBuckets(column)"
*ngFor="let column of nfRegistryService.bucketColumns"
fxFlex="{{column.width}}">
fxFlex="1 1 {{column.width}}">
{{column.label}}
<i *ngIf="column.active && column.sortable && column.sortOrder === 'ASC'" class="fa fa-caret-up"
aria-hidden="true"></i>
<i *ngIf="column.active && column.sortable && column.sortOrder === 'DESC'" class="fa fa-caret-down"
aria-hidden="true"></i>
</div>
<div class="td-data-table-column">
<div class="td-data-table-column" fxFlex="1 1 10%">
<div fxLayout="row" fxLayoutAlign="end center">
<mat-checkbox class="pad-left-sm" [(ngModel)]="nfRegistryService.allBucketsSelected"
(checked)="nfRegistryService.allBucketsSelected"
Expand All @@ -70,12 +70,12 @@
*ngFor="let row of nfRegistryService.filteredBuckets"
(click)="row.checked = !row.checked;nfRegistryService.determineAllBucketsSelectedState()">
<div class="td-data-table-cell" *ngFor="let column of nfRegistryService.bucketColumns"
fxFlex="{{column.width}}">
fxFlex="1 1 {{column.width}}">
<div class="ellipsis" matTooltip="{{column.format ? column.format(row[column.name]) : row[column.name]}}">
{{column.format ? column.format(row[column.name]) : row[column.name]}}
</div>
</div>
<div class="td-data-table-cell">
<div class="td-data-table-cell" fxFlex="1 1 10%">
<div>
<div *ngIf="nfRegistryService.bucketActions.length <= 4" fxLayout="row" fxLayoutAlign="end center">
<button (click)="nfRegistryService.executeBucketAction(action, row);row.checked = !row.checked;"
Expand Down
Expand Up @@ -35,16 +35,36 @@
value="{{nfRegistryService.bucket.name}}"
[(ngModel)]="bucketname">
</mat-form-field>
<button [disabled]="nfRegistryService.bucket.name === bucketname"
(click)="updateBucketName(bucketnameInput.value)"
</div>
<div class="pad-left-md pad-right-md" flex fxLayoutAlign="start center">
<mat-form-field floatLabel="always" flex>
<input #descriptionInput
data-automation-id="nf-registry-manage-bucket-input-description"
matInput
[disabled]="!nfRegistryService.currentUser.resourcePermissions.buckets.canWrite"
placeholder="Description"
value="{{nfRegistryService.bucket.description}}"
[(ngModel)]="description">
</mat-form-field>
</div>

<div class="pad-left-md pad-right-md" flex fxLayoutAlign="start center">
<button [disabled]="nfRegistryService.bucket.name === bucketname && nfRegistryService.bucket.description === description"
(click)="updateBucketNameAndDescription(bucketnameInput.value, descriptionInput.value)"
data-automation-id="nf-registry-manage-bucket-save-side-nav"
class="input-button"
color="fds-regular"
mat-raised-button>
Save
</button>
</div>
<div class="pad-left-md pad-right-md pad-bottom-sm">

<div class="pad-left-md pad-right-md pad-top-md">
<div class="pad-bottom-sm">
<mat-card-title class="ellipsis">
Permission Settings
</mat-card-title>
</div>
<mat-checkbox #bundlePublicReadCheckbox
[disabled]="!nfRegistryService.currentUser.resourcePermissions.buckets.canWrite || protocol === 'http:'"
[(ngModel)]="allowPublicRead"
Expand Down
Expand Up @@ -63,6 +63,7 @@ function NfRegistryManageBucket(nfRegistryApi, nfRegistryService, tdDataTableSer
];
this.userPermsSearchTerms = [];
this.bucketname = '';
this.description = '';
this.allowBundleRedeploy = false;
this.allowPublicRead = false;
this.bucketPolicies = [];
Expand Down Expand Up @@ -108,6 +109,7 @@ NfRegistryManageBucket.prototype = {
var bucket = response[0];
self.nfRegistryService.bucket = bucket;
self.bucketname = bucket.name;
self.description = bucket.description;
self.allowBundleRedeploy = bucket.allowBundleRedeploy;
self.allowPublicRead = bucket.allowPublicRead;
if (!self.nfRegistryService.currentUser.anonymous) {
Expand Down Expand Up @@ -168,6 +170,7 @@ NfRegistryManageBucket.prototype = {
.subscribe(function (response) {
self.nfRegistryService.bucket = response;
self.bucketname = response.name;
self.description = response.description;
self.allowBundleRedeploy = response.allowBundleRedeploy;
self.allowPublicRead = response.allowPublicRead;

Expand Down Expand Up @@ -208,6 +211,7 @@ NfRegistryManageBucket.prototype = {
.subscribe(function (response) {
self.nfRegistryService.bucket = response;
self.bucketname = response.name;
self.description = response.description;
self.allowBundleRedeploy = response.allowBundleRedeploy;
self.allowPublicRead = response.allowPublicRead;

Expand Down Expand Up @@ -405,13 +409,15 @@ NfRegistryManageBucket.prototype = {
/**
* Update bucket name.
*
* @param username
* @param bucketname The new bucket name. Must be unique otherwise an error will be shown.
* @param description The new bucket description
*/
updateBucketName: function (bucketname) {
updateBucketNameAndDescription: function (bucketname, description) {
var self = this;
this.nfRegistryApi.updateBucket({
'identifier': this.nfRegistryService.bucket.identifier,
'name': bucketname,
'description': description,
'revision': this.nfRegistryService.bucket.revision
}).subscribe(function (response) {
if (!response.status || response.status === 200) {
Expand All @@ -421,11 +427,12 @@ NfRegistryManageBucket.prototype = {
return self.nfRegistryService.bucket.identifier === bucket.identifier;
}).forEach(function (bucket) {
bucket.name = response.name;
bucket.description = response.description;
bucket.revision = response.revision;
});
self.snackBarService.openCoaster({
title: 'Success',
message: 'This bucket name has been updated.',
message: 'This bucket name and description have been updated.',
verticalPosition: 'bottom',
horizontalPosition: 'right',
icon: 'fa fa-check-circle-o',
Expand All @@ -434,6 +441,7 @@ NfRegistryManageBucket.prototype = {
});
} else if (response.status === 409) {
self.bucketname = self.nfRegistryService.bucket.name;
self.description = self.nfRegistryService.bucket.description;
self.allowBundleRedeploy = self.nfRegistryService.bucket.allowBundleRedeploy;
self.allowPublicRead = self.nfRegistryService.bucket.allowPublicRead;

Expand Down Expand Up @@ -462,6 +470,7 @@ NfRegistryManageBucket.prototype = {
if (!response.status || response.status === 200) {
self.nfRegistryService.bucket = response;
self.bucketname = self.nfRegistryService.bucket.name;
self.description = self.nfRegistryService.bucket.description;
self.allowBundleRedeploy = self.nfRegistryService.bucket.allowBundleRedeploy;
self.allowPublicRead = self.nfRegistryService.bucket.allowPublicRead;
} else if (response.status === 404) {
Expand Down Expand Up @@ -521,6 +530,7 @@ NfRegistryManageBucket.prototype = {
if (!response.status || response.status === 200) {
self.nfRegistryService.bucket = response;
self.bucketname = self.nfRegistryService.bucket.name;
self.description = self.nfRegistryService.bucket.description;
self.allowBundleRedeploy = self.nfRegistryService.bucket.allowBundleRedeploy;
self.allowPublicRead = self.nfRegistryService.bucket.allowPublicRead;
} else if (response.status === 404) {
Expand Down Expand Up @@ -580,6 +590,7 @@ NfRegistryManageBucket.prototype = {
if (!response.status || response.status === 200) {
self.nfRegistryService.bucket = response;
self.bucketname = self.nfRegistryService.bucket.name;
self.description = self.nfRegistryService.bucket.description;
self.allowBundleRedeploy = self.nfRegistryService.bucket.allowBundleRedeploy;
self.allowPublicRead = self.nfRegistryService.bucket.allowPublicRead;
} else if (response.status === 404) {
Expand Down
Expand Up @@ -564,6 +564,7 @@ describe('NfRegistryManageBucket Component', function () {
}).and.returnValue(of({
identifier: '123',
name: 'test',
description: 'testDesc',
status: 200
}));

Expand All @@ -580,11 +581,12 @@ describe('NfRegistryManageBucket Component', function () {
expect(nfRegistryApi.getBucket.calls.count()).toBe(1);

// the function to test
comp.updateBucketName('test');
comp.updateBucketNameAndDescription('test', 'testDesc');

//assertions
expect(comp.snackBarService.openCoaster.calls.count()).toBe(1);
expect(comp.nfRegistryService.bucket.name).toBe('test');
expect(comp.nfRegistryService.bucket.description).toBe('testDesc');
}));

it('should fail to update bucket name (409)', fakeAsync(function () {
Expand All @@ -600,7 +602,8 @@ describe('NfRegistryManageBucket Component', function () {
spyOn(nfRegistryApi, 'getBucket').and.callFake(function () {
}).and.returnValue(of({
identifier: '123',
name: 'Bucket #1'
name: 'Bucket #1',
description: 'Bucket description'
}));
spyOn(nfRegistryApi, 'getPolicies').and.callFake(function () {
}).and.returnValue(of([
Expand All @@ -621,6 +624,7 @@ describe('NfRegistryManageBucket Component', function () {
}).and.returnValue(of({
identifier: '123',
name: 'test',
description: 'testDesc',
status: 409
}));

Expand All @@ -637,11 +641,12 @@ describe('NfRegistryManageBucket Component', function () {
expect(nfRegistryApi.getBucket.calls.count()).toBe(1);

// the function to test
comp.updateBucketName('test');
comp.updateBucketNameAndDescription('test', 'testDesc');

//assertions
expect(comp.dialogService.openConfirm.calls.count()).toBe(1);
expect(comp.nfRegistryService.bucket.name).toBe('Bucket #1');
expect(comp.nfRegistryService.bucket.description).toBe('Bucket description');
}));

it('should fail to update bucket name (400)', fakeAsync(function () {
Expand All @@ -657,7 +662,8 @@ describe('NfRegistryManageBucket Component', function () {
spyOn(nfRegistryApi, 'getBucket').and.callFake(function () {
}).and.returnValue(of({
identifier: '123',
name: 'Bucket #1'
name: 'Bucket #1',
description: 'Bucket description'
}));
spyOn(nfRegistryApi, 'getPolicies').and.callFake(function () {
}).and.returnValue(of([
Expand All @@ -678,6 +684,7 @@ describe('NfRegistryManageBucket Component', function () {
}).and.returnValue(of({
identifier: '123',
name: 'test',
description: 'testDesc',
status: 400
}));

Expand All @@ -694,11 +701,12 @@ describe('NfRegistryManageBucket Component', function () {
expect(nfRegistryApi.getBucket.calls.count()).toBe(1);

// the function to test
comp.updateBucketName('test');
comp.updateBucketNameAndDescription('test', 'testDesc');

//assertions
expect(comp.dialogService.openConfirm.calls.count()).toBe(1);
expect(comp.nfRegistryService.bucket.name).toBe('Bucket #1');
expect(comp.nfRegistryService.bucket.description).toBe('Bucket description');
}));

it('should destroy the component', fakeAsync(function () {
Expand Down
Expand Up @@ -293,10 +293,11 @@ NfRegistryApi.prototype = {
* @param {string} name The name of the bucket.
* @returns {*}
*/
createBucket: function (name, allowPublicRead) {
createBucket: function (name, description, allowPublicRead) {
var self = this;
return this.http.post('../nifi-registry-api/buckets', {
'name': name,
'description': description,
'allowPublicRead': allowPublicRead,
'revision': {
'version': 0
Expand Down
Expand Up @@ -462,7 +462,7 @@ describe('NfRegistry API w/ Angular testing utils', function () {

it('should POST to create a new bucket.', inject([HttpTestingController], function (httpMock) {
// api call
nfRegistryApi.createBucket('test').subscribe(function (response) {
nfRegistryApi.createBucket('test', 'testDesc').subscribe(function (response) {
expect(response.identifier).toBe('1234');
});
// the request it made
Expand All @@ -484,7 +484,7 @@ describe('NfRegistry API w/ Angular testing utils', function () {
});

// api call
nfRegistryApi.createBucket('test').subscribe(function (response) {
nfRegistryApi.createBucket('test', 'testDesc').subscribe(function (response) {
expect(response.message).toEqual('Http failure response for ../nifi-registry-api/buckets: 401 POST bucket mock error');
var dialogServiceCall = nfRegistryApi.dialogService.openConfirm.calls.first();
expect(dialogServiceCall.args[0].title).toBe('Error');
Expand Down

0 comments on commit 54f83ae

Please sign in to comment.