Skip to content

Commit

Permalink
SHIBUI-1382 Implemented restore call
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Aug 12, 2019
1 parent 3a2cee5 commit f302e90
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
6 changes: 3 additions & 3 deletions ui/src/app/metadata/configuration/action/restore.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export enum RestoreActionTypes {
SELECT_VERSION_REQUEST = '[Restore Version] Select Version Request',

RESTORE_VERSION_REQUEST = '[Restore Version] Restore Version Request',
RESTORE_VERSION_SUCCESS = '[Restore Version] Restore Version Request',
RESTORE_VERSION_ERROR = '[Restore Version] Restore Version Request',
RESTORE_VERSION_SUCCESS = '[Restore Version] Restore Version Success',
RESTORE_VERSION_ERROR = '[Restore Version] Restore Version Error',

CLEAR_VERSION = '[Restore Version] Clear Versions'
}
Expand All @@ -26,7 +26,7 @@ export class RestoreVersionRequest implements Action {

export class RestoreVersionSuccess implements Action {
readonly type = RestoreActionTypes.RESTORE_VERSION_SUCCESS;
constructor(public payload: Metadata) { }
constructor(public payload: { id: string, type: string, model: Metadata }) { }
}

export class RestoreVersionError implements Action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class RestoreComponent implements OnDestroy {
this.restore$.pipe(
withLatestFrom(
this.store.select(fromConfiguration.getSelectedVersionId),
this.store.select(fromConfiguration.getConfigurationModelType),
this.store.select(fromConfiguration.getConfigurationModelKind),
this.store.select(fromConfiguration.getConfigurationModelId)
),
map(([restore, version, type, id]) => new RestoreVersionRequest({ id, type, version }))
Expand Down
46 changes: 38 additions & 8 deletions ui/src/app/metadata/configuration/effect/restore.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import {
SelectVersionRestoreRequest,
SelectVersionRestoreError,
SelectVersionRestoreSuccess,
RestoreVersionRequest
RestoreVersionRequest,
RestoreVersionSuccess,
RestoreVersionError
} from '../action/restore.action';
import { MetadataHistoryService } from '../service/history.service';
import { of } from 'rxjs';
import { Router, ActivatedRoute } from '@angular/router';

import { AddNotification } from '../../../notification/action/notification.action';
import { Notification, NotificationType } from '../../../notification/model/notification';


@Injectable()
Expand All @@ -32,16 +38,40 @@ export class RestoreVersionEffects {
restoreVersion$ = this.actions$.pipe(
ofType<RestoreVersionRequest>(RestoreActionTypes.RESTORE_VERSION_REQUEST),
map(action => action.payload),
switchMap(({ id, type, version }) => {
return this.historyService.getVersion(id, version, type).pipe(
map(v => new SelectVersionRestoreSuccess(v)),
catchError(err => of(new SelectVersionRestoreError(err)))
);
})
switchMap(({ id, type, version }) =>
this.historyService.restoreVersion(id, type, version).pipe(
map(v => new RestoreVersionSuccess({ id, type, model: v })),
catchError(err => of(new RestoreVersionError(err)))
)
)
);

@Effect()
restoreVersionSuccessNotification$ = this.actions$.pipe(
ofType<RestoreVersionSuccess>(RestoreActionTypes.RESTORE_VERSION_SUCCESS),
map(action => action.payload),
map((data) =>
new AddNotification(new Notification(
NotificationType.Success,
`Version Restored!`,
5000
))
)
);

@Effect({dispatch: false})
restoreVersionSuccessRedirect$ = this.actions$.pipe(
ofType<RestoreVersionSuccess>(RestoreActionTypes.RESTORE_VERSION_SUCCESS),
map(action => action.payload),
switchMap((data) =>
this.router.navigate(['/metadata', data.type, data.id, 'configuration', 'options'])
)
);

constructor(
private historyService: MetadataHistoryService,
private actions$: Actions
private actions$: Actions,
private router: Router,
private route: ActivatedRoute
) { }
}
15 changes: 14 additions & 1 deletion ui/src/app/metadata/configuration/service/history.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { MetadataHistory } from '../model/history';

import { PATHS } from '../../configuration/configuration.values';
import { MetadataVersion } from '../model/version';
import { map } from 'rxjs/operators';
import { map, catchError, switchMap } from 'rxjs/operators';
import { Metadata } from '../../domain/domain.type';
import { withLatestFrom } from 'rxjs-compat/operator/withLatestFrom';

@Injectable()
export class MetadataHistoryService {
Expand Down Expand Up @@ -39,4 +40,16 @@ export class MetadataHistoryService {
`/${this.base}/${PATHS[type]}/${resourceId}`;
return this.http.get<Metadata>(api);
}

updateVersion(resourceId: string, type: string, model: Metadata): Observable<Metadata> {
return this.http.put<Metadata>(`/${this.base}/${PATHS[type]}/${resourceId}`, model);
}

restoreVersion(resourceId: string, type: string, versionId: string): Observable<Metadata> {
return this.getVersions(resourceId, [null, versionId], type).pipe(
switchMap(([current, toRestore]) =>
this.updateVersion(resourceId, type, { ...toRestore, version: current.version })
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
const checkOrg = (value, property, form) => {
const org = property.parent;
const orgValue = org.value || {};
console.log(orgValue);
const err = Object.keys(orgValue) && !value ? {
code: 'ORG_INCOMPLETE',
path: `#${property.path}`,
Expand Down

0 comments on commit f302e90

Please sign in to comment.