Skip to content

Commit

Permalink
Fixed draft saving and creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Oct 12, 2018
1 parent b0b9787 commit 262276d
Show file tree
Hide file tree
Showing 15 changed files with 335 additions and 128 deletions.
294 changes: 235 additions & 59 deletions backend/src/main/resources/metadata-sources-ui-schema.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MetadataTypes } from '../../domain.type';
import { MetadataEntity } from '../../model/metadata-entity';

export class FileBackedHttpMetadataResolver implements MetadataResolver, MetadataEntity {
id = '';
resourceId = '';
createdDate?: string;
modifiedDate?: string;
version: string;
Expand Down Expand Up @@ -53,15 +53,15 @@ export class FileBackedHttpMetadataResolver implements MetadataResolver, Metadat
}

getId(): string {
return this.id ? this.id : this.entityId;
return this.resourceId;
}

getDisplayId(): string {
return this.entityId;
}

isDraft(): boolean {
return this.id ? false : true;
return this.createdDate ? false : true;
}

getCreationDate(): Date {
Expand Down
8 changes: 4 additions & 4 deletions ui/src/app/metadata/domain/model/metadata-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
} from '../model';

export interface MetadataResolver extends MetadataBase {
resourceId?: string;
entityId: string;
resourceId: string;
entityId?: string;
serviceProviderName: string;
organization?: Organization;
contacts?: Contact[];
Expand All @@ -22,6 +22,6 @@ export interface MetadataResolver extends MetadataBase {
serviceProviderSsoDescriptor?: IdpSsoDescriptor;
logoutEndpoints?: LogoutEndpoint[];
serviceEnabled?: boolean;
relyingPartyOverrides: RelyingPartyOverrides;
attributeRelease: string[];
relyingPartyOverrides?: RelyingPartyOverrides;
attributeRelease?: string[];
}
20 changes: 10 additions & 10 deletions ui/src/app/metadata/domain/model/wizards/metadata-source-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 1,
id: 'common',
label: 'label.resolver-common-attributes',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'serviceProviderName',
'entityId'
Expand All @@ -28,7 +28,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 2,
id: 'org-info',
label: 'label.org-info',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'organization',
'contacts'
Expand All @@ -52,7 +52,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 3,
id: 'metadata-ui',
label: 'label.metadata-ui',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'mdui'
]
Expand All @@ -61,7 +61,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 4,
id: 'descriptor-info',
label: 'label.descriptor-info',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'serviceProviderSsoDescriptor'
]
Expand All @@ -70,7 +70,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 5,
id: 'logout-endpoints',
label: 'label.logout-endpoints',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'logoutEndpoints'
],
Expand All @@ -87,7 +87,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 6,
id: 'key-info',
label: 'label.key-info',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'securityInfo'
]
Expand All @@ -96,7 +96,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 7,
id: 'assertion',
label: 'label.assertion',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'assertionConsumerServices'
]
Expand All @@ -105,7 +105,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 8,
id: 'relying-party',
label: 'label.relying-party',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'relyingPartyOverrides'
]
Expand All @@ -114,7 +114,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 9,
id: 'attribute',
label: 'label.attribute-release',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'attributeRelease'
]
Expand All @@ -123,7 +123,7 @@ export class MetadataSourceWizard implements Wizard<MetadataResolver> {
index: 10,
id: 'finish',
label: 'label.finished',
schema: 'assets/schema/source/metadata-source.json',
schema: '/api/ui/MetadataSources',
fields: [
'serviceEnabled'
],
Expand Down
27 changes: 16 additions & 11 deletions ui/src/app/metadata/domain/service/draft.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';

import { Observable, of } from 'rxjs';
import { Observable, of, throwError } from 'rxjs';
import { switchMap } from 'rxjs/operators';

import { MetadataResolver } from '../../domain/model';
Expand All @@ -18,12 +18,13 @@ export class EntityDraftService {
return of(this.storage.query());
}

find(entityId: string): Observable<MetadataResolver> {
find(id: string, attr: string = 'resourceId'): Observable<MetadataResolver> {
if (!id) {
return throwError(404);
}
return this.query().pipe(
switchMap(
list => of(
list.find(entity => entity.entityId === entityId)
)
list => of(list.find(entity => entity[attr] === id))
)
);
}
Expand All @@ -34,15 +35,19 @@ export class EntityDraftService {
}

remove(provider: MetadataResolver): Observable<MetadataResolver> {
this.storage.removeByAttr(provider.entityId, 'entityId');
this.storage.removeByAttr(provider.resourceId, 'resourceId');
return of(provider);
}

update(provider: MetadataResolver): Observable<MetadataResolver> {
let stored = this.storage.findByAttr(provider.id, 'entityId');
stored = Object.assign({}, stored, provider);
this.storage.removeByAttr(provider.entityId, 'entityId');
this.storage.add(stored);
return of(stored);
let stored = this.storage.findByAttr(provider.resourceId, 'resourceId');
if (stored) {
stored = { ...stored, ...provider };
this.storage.removeByAttr(provider.resourceId, 'resourceId');
this.storage.add(stored);
return of(stored);
} else {
return throwError(404);
}
}
} /* istanbul ignore next */
3 changes: 2 additions & 1 deletion ui/src/app/metadata/domain/service/resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export class ResolverService {
}

save(provider: MetadataResolver): Observable<MetadataResolver> {
return this.http.post<MetadataResolver>(`${this.base}${this.endpoint}`, provider);
const { id, ...p } = provider;
return this.http.post<MetadataResolver>(`${this.base}${this.endpoint}`, p);
}

remove(provider: MetadataResolver): Observable<MetadataResolver> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class DashboardResolversListComponent implements OnInit {
if (entity.isDraft()) {
this.router.navigate(['metadata', 'resolver', 'new'], {
queryParams: {
entityId: entity.getId()
id: entity.getId()
}
});
} else {
Expand Down
24 changes: 16 additions & 8 deletions ui/src/app/metadata/resolver/action/draft.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { MetadataResolver } from '../../domain/model';

export enum DraftActionTypes {
FIND = '[Metadata Draft] Find',
SELECT = '[Metadata Draft] Select',
SELECT_REQUEST = '[Metadata Draft] Select Request',
SELECT_SUCCESS = '[Metadata Draft] Select Success',
SELECT_ERROR = '[Metadata Draft] Select Error',
UPDATE_DRAFT_REQUEST = '[Metadata Draft] Update Request',
UPDATE_DRAFT_SUCCESS = '[Metadata Draft] Update Success',
UPDATE_DRAFT_FAIL = '[Metadata Draft] Update Fail',
Expand All @@ -19,19 +21,24 @@ export enum DraftActionTypes {
REMOVE_DRAFT_FAIL = '[Metadata Draft Collection] Remove Draft Fail'
}


export class FindDraft implements Action {
readonly type = DraftActionTypes.FIND;
export class SelectDraftRequest implements Action {
readonly type = DraftActionTypes.SELECT_REQUEST;

constructor(public payload: string) { }
}

export class SelectDraft implements Action {
readonly type = DraftActionTypes.SELECT;
export class SelectDraftSuccess implements Action {
readonly type = DraftActionTypes.SELECT_SUCCESS;

constructor(public payload: string) { }
}

export class SelectDraftError implements Action {
readonly type = DraftActionTypes.SELECT_ERROR;

constructor() { }
}

export class UpdateDraftRequest implements Action {
readonly type = DraftActionTypes.UPDATE_DRAFT_REQUEST;

Expand Down Expand Up @@ -114,8 +121,9 @@ export type DraftActionsUnion =
| RemoveDraftRequest
| RemoveDraftSuccess
| RemoveDraftFail
| FindDraft
| SelectDraft
| SelectDraftRequest
| SelectDraftSuccess
| SelectDraftError
| UpdateDraftRequest
| UpdateDraftSuccess
| UpdateDraftFail;
4 changes: 2 additions & 2 deletions ui/src/app/metadata/resolver/container/draft.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { distinctUntilChanged, map } from 'rxjs/operators';

import { Store } from '@ngrx/store';
import { NgbPopoverConfig } from '@ng-bootstrap/ng-bootstrap';
import { SelectDraft } from '../action/draft.action';
import { SelectDraftRequest } from '../action/draft.action';
import * as fromCollection from '../reducer';

@Component({
Expand All @@ -23,7 +23,7 @@ export class DraftComponent implements OnDestroy {
) {
this.actionsSubscription = route.params.pipe(
distinctUntilChanged(),
map(params => new SelectDraft(params.entityId))
map(params => new SelectDraftRequest(params.entityId))
).subscribe(store);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
import { map, withLatestFrom, distinctUntilChanged } from 'rxjs/operators';
import { SelectDraft } from '../action/draft.action';
import { SelectDraftRequest } from '../action/draft.action';
import { Store } from '@ngrx/store';
import * as fromCollection from '../reducer';

Expand All @@ -28,7 +28,7 @@ export class NewResolverComponent {

this.actionsSubscription = this.route.queryParams.pipe(
distinctUntilChanged(),
map(params => new SelectDraft(params.entityId))
).subscribe(store);
map(params => new SelectDraftRequest(params.id))
).subscribe(this.store);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class ResolverWizardStepComponent implements OnDestroy {
map(([changes, original]) => ({ ...original, ...changes }))
)
.subscribe(changes => {
this.store.dispatch(new UpdateChanges(changes));
if (changes.resourceId) {
this.store.dispatch(new UpdateChanges(changes));
}
});

this.statusChangeEmitted$.pipe(distinctUntilChanged()).subscribe(errors => this.updateStatus(errors));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class ResolverWizardComponent implements OnDestroy, CanComponentDeactivat
private store: Store<fromCollections.State>,
private route: ActivatedRoute,
private router: Router,
private modalService: NgbModal,
@Inject(METADATA_SOURCE_WIZARD) private sourceWizard: Wizard<MetadataResolver>
) {
this.store
Expand Down
42 changes: 33 additions & 9 deletions ui/src/app/metadata/resolver/effect/draft-collection.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { Router } from '@angular/router';
import { of } from 'rxjs';
import { switchMap, map, catchError, tap } from 'rxjs/operators';

import { DraftActionTypes } from '../action/draft.action';
import {
DraftActionTypes,
SelectDraftRequest,
SelectDraftError,
SelectDraftSuccess
} from '../action/draft.action';
import * as actions from '../action/draft.action';
import { EntityDraftService } from '../../domain/service/draft.service';

Expand Down Expand Up @@ -66,7 +71,6 @@ export class DraftCollectionEffects {
ofType<actions.UpdateDraftRequest>(DraftActionTypes.UPDATE_DRAFT_REQUEST),
map(getPayload),
switchMap(provider => {
console.log(provider);
return this.draftService
.update(provider)
.pipe(
Expand All @@ -80,29 +84,49 @@ export class DraftCollectionEffects {

@Effect()
selectDraft$ = this.actions$.pipe(
ofType<actions.SelectDraft>(DraftActionTypes.SELECT),
ofType<SelectDraftRequest>(DraftActionTypes.SELECT_REQUEST),
map(getPayload),
switchMap(id =>
this.draftService
.find(id)
.pipe(
map(p => new actions.FindDraft(p.entityId))
map(p => new SelectDraftSuccess(p.resourceId)),
catchError(e => of(new SelectDraftError()))
)
)
);

@Effect()
removeDraft$ = this.actions$.pipe(
ofType<actions.RemoveDraftRequest>(DraftActionTypes.REMOVE_DRAFT),
selectDraftReload$ = this.actions$.pipe(
ofType<SelectDraftRequest>(DraftActionTypes.SELECT_REQUEST),
map(getPayload),
switchMap(provider =>
map(id => new actions.LoadDraftRequest())
);

@Effect()
selectDraftError$ = this.actions$.pipe(
ofType<SelectDraftError>(DraftActionTypes.SELECT_ERROR),
map(getPayload),
switchMap(id =>
this.draftService
.remove(provider)
.save({ resourceId: `r-${ Date.now() }`, serviceProviderName: '' })
.pipe(
map(p => new actions.RemoveDraftSuccess(p))
map(p => new SelectDraftRequest(p.resourceId)),
catchError(e => of(new SelectDraftError()))
)
)
);

@Effect()
removeDraft$ = this.actions$.pipe(
ofType<actions.RemoveDraftRequest>(DraftActionTypes.REMOVE_DRAFT),
map(getPayload),
switchMap(provider => this.draftService.find(provider.entityId, 'entityId').pipe(
switchMap(selected => this.draftService.remove(selected)),
map(p => new actions.RemoveDraftSuccess(p))
)
)
);
@Effect()
removeDraftSuccessReload$ = this.actions$.pipe(
ofType<actions.RemoveDraftRequest>(DraftActionTypes.REMOVE_DRAFT),
Expand Down
Loading

0 comments on commit 262276d

Please sign in to comment.