Skip to content

Commit

Permalink
SHIBUI-685 Added validation for unique IDs in XML
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jul 26, 2018
1 parent b12d7b7 commit fa8fe0f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions ui/src/app/metadata/domain/model/metadata-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface MetadataProvider extends MetadataBase {
'@type': string;
enabled: boolean;
resourceId: string;
xmlId: string;
sortKey: number;
metadataFilters: MetadataFilter[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ export class ProviderEditStepComponent implements OnDestroy {

this.lock.valueChanges.subscribe(locked => this.store.dispatch(locked ? new LockEditor() : new UnlockEditor()));

this.validators$ = this.store.select(fromProvider.getProviderNames).pipe(
withLatestFrom(this.definition$, this.provider$),
map(([names, def, provider]) => def.getValidators(names.filter(n => n !== provider.name)))
this.validators$ = this.definition$.pipe(
withLatestFrom(
this.store.select(fromProvider.getProviderNames),
this.store.select(fromProvider.getProviderXmlIds),
this.provider$
),
map(([def, names, ids, provider]) => def.getValidators(
names.filter(n => n !== provider.name),
ids.filter(id => id !== provider.xmlId)
))
);

this.model$ = this.schema$.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ export const FileBackedHttpMetadataProviderWizard: Wizard<FileBackedHttpMetadata
...BaseMetadataProviderEditor,
label: 'FileBackedHttpMetadataProvider',
type: 'FileBackedHttpMetadataResolver',
getValidators(namesList: string[] = [], xmlIdList: string[] = []): any {
const validators = BaseMetadataProviderEditor.getValidators(namesList);
validators['/xmlId'] = (value, property, form) => {
const err = xmlIdList.indexOf(value) > -1 ? {
code: 'INVALID_ID',
path: `#${property.path}`,
message: 'ID must be unique.',
params: [value]
} : null;
return err;
};
return validators;
},
steps: [
{
id: 'common',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Provider Collection Reducer', () => {
enabled: true,
createdDate: new Date().toLocaleDateString(),
sortKey: 1,
xmlId: 'foo',
metadataFilters: []
},
{
Expand All @@ -42,6 +43,7 @@ describe('Provider Collection Reducer', () => {
enabled: false,
createdDate: new Date().toLocaleDateString(),
sortKey: 2,
xmlId: 'bar',
metadataFilters: []
}
];
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/metadata/provider/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ export const getProviderIds = createSelector(getCollectionState, fromCollection.
export const getProviderCollectionIsLoaded = createSelector(getCollectionState, fromCollection.getIsLoaded);

export const getProviderNames = createSelector(getAllProviders, (providers: MetadataProvider[]) => providers.map(p => p.name));
export const getProviderXmlIds = createSelector(getAllProviders, (providers: MetadataProvider[]) => providers.map(p => p.xmlId));
2 changes: 1 addition & 1 deletion ui/src/app/wizard/model/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Wizard<T> {
formatter(changes: Partial<T>, schema?: any)
};

getValidators?(params: any): { [key: string]: any };
getValidators?(...args: any[]): { [key: string]: any };
}

export interface WizardStep {
Expand Down

0 comments on commit fa8fe0f

Please sign in to comment.