Skip to content

Commit

Permalink
Merged in bugfix/SHIBUI-925 (pull request #254)
Browse files Browse the repository at this point in the history
Bugfix/SHIBUI-925
  • Loading branch information
rmathis authored and Jonathan Johnson committed Dec 10, 2018
2 parents 5b9a841 + 3590d8d commit 42687b5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.jsonschema

import edu.internet2.tier.shibboleth.admin.ui.controller.ErrorResponse
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRepresentation
import mjson.Json
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -10,7 +11,6 @@ import org.springframework.http.ResponseEntity
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.context.request.WebRequest
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter

import javax.annotation.PostConstruct
Expand Down Expand Up @@ -56,8 +56,8 @@ class RelyingPartyOverridesJsonSchemaValidatingControllerAdvice extends RequestB
}

@ExceptionHandler(JsonSchemaValidationFailedException)
final ResponseEntity<?> handleUserNotFoundException(JsonSchemaValidationFailedException ex, WebRequest request) {
new ResponseEntity<>([errors: ex.errors], HttpStatus.BAD_REQUEST)
final ResponseEntity<?> handleJsonSchemaValidationFailedException(JsonSchemaValidationFailedException ex) {
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorResponse("400", String.join('\n', ex.errors)))
}

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private ResponseEntity<?> existingEntityDescriptorCheck(String entityId) {
return ResponseEntity
.status(HttpStatus.CONFLICT)
.headers(headers)
.body(String.format("The entity descriptor with entity id [%s] already exists.", entityId));
.body(new ErrorResponse(String.valueOf(HttpStatus.CONFLICT.value()), String.format("The entity descriptor with entity id [%s] already exists.", entityId)));
}
//No existing entity descriptor, which is an OK condition indicated by returning a null conflict response
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class EntityDescriptorControllerTests extends Specification {
then:
result.andExpect(status().isConflict())
.andExpect(content().string("The entity descriptor with entity id [http://test.scaldingspoon.org/test1] already exists."))
.andExpect(content().string("{\"errorCode\":\"409\",\"errorMessage\":\"The entity descriptor with entity id [http://test.scaldingspoon.org/test1] already exists.\"}"))
}
def "POST /EntityDescriptor handles x-www-form-urlencoded happily"() {
Expand Down
8 changes: 6 additions & 2 deletions ui/src/app/metadata/domain/service/resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ export class ResolverService {
return this.http.post<MetadataResolver>(`${this.base}${this.endpoint}`, xml, {
headers: new HttpHeaders().set('Content-Type', 'application/xml'),
params: new HttpParams().set('spName', name)
});
}).pipe(catchError(error => {
return throwError({ errorCode: error.status, errorMessage: `Unable to upload file ... ${error.error}` });
}));
}

createFromUrl(name: string, url: string): Observable<MetadataResolver> {
let body = `metadataUrl=${url}`;
return this.http.post<MetadataResolver>(`${this.base}${this.endpoint}`, body, {
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'),
params: new HttpParams().set('spName', name)
});
}).pipe(catchError(error => {
return throwError({ errorCode: error.status, errorMessage: `Unable to upload file ... ${error.error}` });
}));
}

preview(id: string): Observable<string> {
Expand Down
33 changes: 27 additions & 6 deletions ui/src/app/metadata/resolver/effect/collection.effects.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Injectable } from '@angular/core';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Router } from '@angular/router';

import { Store } from '@ngrx/store';
import { of } from 'rxjs';
import { map, catchError, switchMap, tap } from 'rxjs/operators';
import { map, catchError, switchMap, tap, withLatestFrom } from 'rxjs/operators';

import * as providerActions from '../action/collection.action';
import * as draftActions from '../action/draft.action';
import { ResolverCollectionActionTypes } from '../action/collection.action';
import { ResolverService } from '../../domain/service/resolver.service';
import { removeNulls } from '../../../shared/util';
import { AddNotification } from '../../../notification/action/notification.action';
import { Notification, NotificationType } from '../../../notification/model/notification';
import { I18nService } from '../../../i18n/service/i18n.service';
import * as fromRoot from '../../../app.reducer';
import * as fromI18n from '../../../i18n/reducer';


/* istanbul ignore next */
@Injectable()
Expand Down Expand Up @@ -112,11 +118,24 @@ export class ResolverCollectionEffects {
ofType<providerActions.AddResolverSuccess>(ResolverCollectionActionTypes.ADD_RESOLVER_SUCCESS),
map(action => action.payload),
map(provider => {
console.log(provider);
return new draftActions.RemoveDraftRequest(provider);
})
);

@Effect()
addResolverFailNotification$ = this.actions$.pipe(
ofType<providerActions.AddResolverFail>(ResolverCollectionActionTypes.ADD_RESOLVER_FAIL),
map(action => action.payload),
withLatestFrom(this.store.select(fromI18n.getMessages)),
map(([error, messages]) => new AddNotification(
new Notification(
NotificationType.Danger,
`${error.errorCode}: ${this.i18nService.translate(error.errorMessage, null, messages)}`,
8000
)
))
);

@Effect()
uploadResolverRequest$ = this.actions$.pipe(
ofType<providerActions.UploadResolverRequest>(ResolverCollectionActionTypes.UPLOAD_RESOLVER_REQUEST),
Expand All @@ -126,7 +145,7 @@ export class ResolverCollectionEffects {
.upload(file.name, file.body)
.pipe(
map(p => new providerActions.AddResolverSuccess(p)),
catchError(() => of(new providerActions.AddResolverFail(file)))
catchError((error) => of(new providerActions.AddResolverFail(error)))
)
)
);
Expand All @@ -140,14 +159,16 @@ export class ResolverCollectionEffects {
.createFromUrl(file.name, file.url)
.pipe(
map(p => new providerActions.AddResolverSuccess(p)),
catchError(() => of(new providerActions.AddResolverFail(file)))
catchError((error) => of(new providerActions.AddResolverFail(error)))
)
)
);

constructor(
private descriptorService: ResolverService,
private actions$: Actions,
private router: Router
private router: Router,
private store: Store<fromRoot.State>,
private i18nService: I18nService
) { }
} /* istanbul ignore next */

0 comments on commit 42687b5

Please sign in to comment.