Skip to content

Commit

Permalink
Merge branch 'master' into SHIBUI-799
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Dec 4, 2018
2 parents 0aa8777 + 50b5b29 commit 59b88c0
Show file tree
Hide file tree
Showing 29 changed files with 353 additions and 238 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package edu.internet2.tier.shibboleth.admin.ui.controller.support;

import com.google.common.collect.ImmutableMap;
import edu.internet2.tier.shibboleth.admin.ui.controller.ErrorResponse;
import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolver;
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
Expand All @@ -30,12 +32,18 @@ public MetadataResolver findResolverOrThrowHttp404(String resolverResourceId) {
return resolver;
}


@ExceptionHandler
//TODO: Review this handler and update accordingly. Do we still need it?
@ExceptionHandler(HttpClientErrorException.class)
public ResponseEntity<?> notFoundHandler(HttpClientErrorException ex) {
if(ex.getStatusCode() == NOT_FOUND) {
return ResponseEntity.status(NOT_FOUND).body(ex.getStatusText());
}
throw ex;
}

@ExceptionHandler(Exception.class)
public final ResponseEntity<ErrorResponse> handleAllOtherExceptions(Exception ex) {
ErrorResponse errorResponse = new ErrorResponse("400", ex.getLocalizedMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
}
104 changes: 35 additions & 69 deletions backend/src/main/resources/dynamic-http-metadata-provider.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"type": "object",
"required": [
"xmlId",
"metadataURL"
"metadataURL",
"metadataRequestURLConstructionScheme"
],
"properties": {
"enabled": {
Expand All @@ -20,6 +21,39 @@
},
"metadataRequestURLConstructionScheme": {
"type": "object",
"required": [
"@type",
"content"
],
"anyOf": [
{
"properties": {
"@type": {
"enum": [
"Regex"
]
}
},
"required": [
"@type",
"content",
"match"
]
},
{
"properties": {
"@type": {
"enum": [
"MetadataQueryProtocol"
]
}
},
"required": [
"@type",
"content"
]
}
],
"properties": {
"@type": {
"title": "label.md-request-type",
Expand All @@ -35,12 +69,6 @@
],
"description": "value.md-query-protocol"
},
{
"enum": [
"Template"
],
"description": "value.template"
},
{
"enum": [
"Regex"
Expand All @@ -54,67 +82,6 @@
"description": "tooltip.md-request-value",
"type": "string"
},
"transformRef": {
"title": "label.transform-ref",
"description": "tooltip.transform-ref",
"type": "string",
"visibleIf": {
"content": [
""
]
}
},
"encodingStyle": {
"title": "label.encoding-style",
"description": "tooltip.encoding-style",
"type": "string",
"widget": {
"id": "select"
},
"default": "FORM",
"oneOf": [
{
"enum": [
"NONE"
],
"description": "None"
},
{
"enum": [
"FORM"
],
"description": "Form"
},
{
"enum": [
"PATH"
],
"description": "Path"
},
{
"enum": [
"FRAGMENT"
],
"description": "Fragment"
}
],
"visibleIf": {
"@type": [
"Template"
]
}
},
"velocityEngine": {
"title": "label.velocity-engine",
"description": "tooltip.velocity-engine",
"type": "string",
"default": "shibboleth.VelocityEngine",
"visibleIf": {
"@type": [
"Template"
]
}
},
"match": {
"title": "label.match",
"description": "tooltip.match",
Expand Down Expand Up @@ -638,7 +605,6 @@
"title": "label.certificate-file",
"description": "tooltip.certificate-file",
"type": "string",
"widget": "textarea",
"default": ""
}
},
Expand Down
5 changes: 5 additions & 0 deletions backend/src/main/resources/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ message.uri-valid-format=URI must be valid format.
message.id-unique=ID must be unique.
message.array-items-must-be-unique=Items in list must be unique.

message.org-name-required=Organization Name is required.
message.org-displayName-required=Organization Name is required.
message.org-url-required=Organization Name is required.
message.org-incomplete=These three fields must all be entered if any single field has a value.

message.conflict=Conflict
message.data-version-contention=Data Version Contention
message.contention-new-version=A newer version of this metadata source has been saved. Below are a list of changes. You can use your changes or their changes.
Expand Down
30 changes: 18 additions & 12 deletions backend/src/main/resources/metadata-sources-ui-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,24 @@
}
},
"dependencies": {
"name": [
"displayName",
"url"
],
"displayName": [
"name",
"url"
],
"url": [
"name",
"displayName"
]
"name": {
"required": [
"displayName",
"url"
]
},
"displayName": {
"required": [
"name",
"url"
]
},
"url": {
"required": [
"name",
"displayName"
]
}
}
},
"contacts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ describe('Metadata Source Base class', () => {
it('should return a list of validators for the ngx-schema-form', () => {
expect(Object.keys(getValidators([]))).toEqual([
'/',
'/entityId'
'/entityId',
'/organization/name',
'/organization/displayName',
'/organization/url'
]);
});
});
Expand Down
18 changes: 16 additions & 2 deletions ui/src/app/metadata/domain/model/wizards/metadata-source-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
}

getValidators(entityIdList: string[]): { [key: string]: any } {
const checkOrg = (value, property, form) => {
const org = property.parent;
const orgValue = org.value || {};
const err = Object.keys(orgValue) && !value ? {
code: 'ORG_INCOMPLETE',
path: `#${property.path}`,
message: `message.org-incomplete`,
params: [value]
} : null;
return err;
};
const validators = {
'/': (value, property, form_current) => {
let errors;
Expand All @@ -68,7 +79,7 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
const item = value[key];
const validatorKey = `/${key}`;
const validator = validators.hasOwnProperty(validatorKey) ? validators[validatorKey] : null;
const error = validator ? validator(item, { path: `/${key}` }, form_current) : null;
const error = validator ? validator(item, form_current.getProperty(key), form_current) : null;
if (error) {
errors = errors || [];
errors.push(error);
Expand All @@ -84,7 +95,10 @@ export class MetadataSourceBase implements Wizard<MetadataResolver> {
params: [value]
} : null;
return err;
}
},
'/organization/name': checkOrg,
'/organization/displayName': checkOrg,
'/organization/url': checkOrg
};
return validators;
}
Expand Down
4 changes: 4 additions & 0 deletions ui/src/app/metadata/domain/service/draft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export class EntityDraftService {
);
}

exists(id: string, attr: string = 'id'): boolean {
return this.storage.query().some(entity => entity[attr] === id);
}

save(provider: MetadataResolver): Observable<MetadataResolver> {
this.storage.add(provider);
return of(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Dashboard Resolvers List Page', () => {
it('should route to the wizard page', () => {
spyOn(router, 'navigate');
instance.edit(draft);
expect(router.navigate).toHaveBeenCalledWith(['metadata', 'resolver', 'new', 'blank', 'org-info'], {
expect(router.navigate).toHaveBeenCalledWith(['metadata', 'resolver', 'new', 'blank', 'common'], {
queryParams: { id: '1' }
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DashboardResolversListComponent implements OnInit {

edit(entity: MetadataEntity): void {
if (entity.isDraft()) {
this.router.navigate(['metadata', 'resolver', 'new', 'blank', 'org-info'], {
this.router.navigate(['metadata', 'resolver', 'new', 'blank', 'common'], {
queryParams: {
id: entity.getId()
}
Expand Down
16 changes: 1 addition & 15 deletions ui/src/app/metadata/provider/model/dynamic-http.provider.form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,7 @@ export const DynamicHttpMetadataProviderWizard: Wizard<DynamicHttpMetadataProvid
...BaseMetadataProviderEditor,
label: 'DynamicHttpMetadataProvider',
type: 'DynamicHttpMetadataResolver',
bindings: {
'/metadataRequestURLConstructionScheme/@type': [
{
'input': (event, property: FormProperty) => {
let transform = property.parent.getProperty('transformRef');
let content = property.parent.getProperty('content');
if (!content.value && property.value !== 'Regex') {
transform.setVisible(true);
} else {
transform.setVisible(false);
}
}
}
]
},
bindings: {},
getValidators(namesList: string[] = [], xmlIdList: string[] = []): any {
const validators = BaseMetadataProviderEditor.getValidators(namesList);
validators['/xmlId'] = (value, property, form) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ <h3 translate="label.how-are-you-adding-the-metadata-information">How are you ad
class="btn btn-lg btn-block btn-secondary"
aria-label="Upload local metadata file or use a metadata URL"
role="button"
routerLink="upload"
[routerLink]="['./', 'upload']"
queryParamsHandling="merge"
routerLinkActive="btn-success">
<translate-i18n key="label.upload-url">Upload/URL</translate-i18n>
<i class="fa fa-link fa-2x d-block"></i>
Expand All @@ -33,7 +34,8 @@ <h3 translate="label.how-are-you-adding-the-metadata-information">How are you ad
class="btn btn-lg btn-block btn-secondary"
aria-label="Create metadata source using the wizard"
role="button"
[routerLink]="['./']"
[routerLink]="['./', 'blank', 'common']"
queryParamsHandling="merge"
routerLinkActive="btn-info">
<translate-i18n key="action.create">Create</translate-i18n>
<i class="fa fa-plus-square fa-2x d-block"></i>
Expand All @@ -47,7 +49,8 @@ <h3 translate="label.how-are-you-adding-the-metadata-information">How are you ad
class="btn btn-lg btn-block btn-secondary"
aria-label="Copy a metadata source"
role="button"
routerLink="copy"
[routerLink]="['./', 'copy']"
queryParamsHandling="merge"
routerLinkActive="btn-warning">
<translate-i18n key="action.copy">Copy</translate-i18n>
<i class="fa fa-copy fa-2x d-block"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('New Resolver Page', () => {
let instance: NewResolverComponent;
let activatedRoute: ActivatedRouteStub = new ActivatedRouteStub();
activatedRoute.testParamMap = { id: 'foo', events: of({}) };
activatedRoute.data = of('foo');

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export class NewResolverComponent {
debounceTime(10),
map(url => {
let child = this.route.snapshot.firstChild;
return child.routeConfig.path.match('blank').length === 0 || child.params.index === 'common';
return !child.routeConfig.path.match('blank') || child.params.index === 'common';
})
);

this.actionsSubscription = this.route.queryParams.pipe(
this.actionsSubscription = this.route.data.pipe(
distinctUntilChanged(),
map(params => new SelectDraftRequest(params.id))
map(data => new SelectDraftRequest(data.draft))
).subscribe(this.store);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,10 @@ export class ResolverWizardStepComponent implements OnDestroy {
this.valueChangeEmitted$.pipe(
withLatestFrom(this.definition$),
filter(([ changes, definition ]) => (!!definition && !!changes)),
map(([ changes, definition ]) => definition.parser(changes.value)),
withLatestFrom(this.store.select(fromResolver.getSelectedDraft)),
map(([changes, original]) => ({ ...original, ...changes }))
map(([ changes, definition ]) => definition.parser(changes.value))
)
.subscribe(changes => {
if (changes.id) {
this.store.dispatch(new UpdateChanges(changes));
}
this.store.dispatch(new UpdateChanges(changes));
});

this.statusChangeEmitted$.pipe(distinctUntilChanged()).subscribe(errors => this.updateStatus(errors));
Expand Down
Loading

0 comments on commit 59b88c0

Please sign in to comment.