fix cache bug within ClientConnection request / more tests

This commit is contained in:
anhefti 2019-09-11 08:19:10 +02:00
parent eb71c4bcc4
commit bffdcc07e3
10 changed files with 141 additions and 29 deletions

View file

@ -69,7 +69,7 @@ public class ClientConnectionData {
while (i1.hasNext()) {
final IndicatorValue iv1 = i1.next();
final IndicatorValue iv2 = i2.next();
if (iv1.getType() != iv2.getType() || Math.round(iv1.getValue() - iv2.getValue()) < .0001) {
if (iv1.getType() != iv2.getType() || iv1.getValue() != iv2.getValue()) {
return false;
}
}

View file

@ -165,6 +165,27 @@ public class AttributeMapping {
.collect(Collectors.toList()));
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("AttributeMapping [templateId=");
builder.append(this.templateId);
builder.append(", attributeIdMapping=");
builder.append(this.attributeIdMapping);
builder.append(", attributeNameIdMapping=");
builder.append(this.attributeNameIdMapping);
builder.append(", orientationAttributeMapping=");
builder.append(this.orientationAttributeMapping);
builder.append(", orientationAttributeNameMapping=");
builder.append(this.orientationAttributeNameMapping);
builder.append(", childAttributeMapping=");
builder.append(this.childAttributeMapping);
builder.append(", attributeGroupMapping=");
builder.append(this.attributeGroupMapping);
builder.append("]");
return builder.toString();
}
private List<ConfigurationAttribute> getChildAttributes(final ConfigurationAttribute attribute) {
return this.attributeIdMapping
.values()

View file

@ -68,7 +68,7 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService {
private final InputFieldBuilderSupplier inputFieldBuilderSupplier;
private final Collection<ValueChangeRule> valueChangeRules;
protected ExamConfigurationServiceImpl(
public ExamConfigurationServiceImpl(
final RestService restService,
final JSONMapper jsonMapper,
final WidgetFactory widgetFactory,
@ -109,7 +109,7 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService {
.getBuilder(GetOrientations.class)
.withQueryParam(Orientation.FILTER_ATTR_TEMPLATE_ID, String.valueOf(templateId))
.call()
.onError(t -> log.error("Failed to get all Orientation of template {}", templateId))
.onError(t -> log.error("Failed to get all Orientation of template {}", templateId, t))
.getOrThrow());
});
}

View file

@ -49,6 +49,10 @@ public interface ClientConnectionDAO extends EntityDAO<ClientConnection, ClientC
@CacheEvict(cacheNames = CONNECTION_TOKENS_CACHE, allEntries = true)
Result<ClientConnection> createNew(ClientConnection data);
@Override
@CacheEvict(cacheNames = CONNECTION_TOKENS_CACHE, allEntries = true)
Result<ClientConnection> save(ClientConnection data);
/** Deletes the given ClientConnection data.
*
* This evicts all entries from the CONNECTION_TOKENS_CACHE.

View file

@ -134,15 +134,12 @@ final class MockupLmsAPITemplate implements LmsAPITemplate {
if (StringUtils.isNoneBlank(externalAddressAlias)) {
try {
if (log.isDebugEnabled()) {
log.debug("Found external address alias: {}", externalAddressAlias);
}
final String _externalStartURI =
this.webserviceInfo.getHttpScheme() +
"://" + externalAddressAlias + "/api/";
log.info("Use external address for course access: {}", _externalStartURI);
if (log.isDebugEnabled()) {
log.debug("Use external address for course access: {}", _externalStartURI);
}
return new QuizData(
quizData.id, quizData.institutionId, quizData.lmsSetupId, quizData.lmsType,

View file

@ -259,11 +259,6 @@ final class OpenEdxLmsAPITemplate implements LmsAPITemplate {
String _externalStartURI = lmsSetup.lmsApiUrl + OPEN_EDX_DEFAULT_COURSE_START_URL_PREFIX;
if (StringUtils.isNoneBlank(externalAddressAlias)) {
try {
if (log.isDebugEnabled()) {
log.debug("Found external address alias: {}", externalAddressAlias);
}
final URL url = new URL(lmsSetup.lmsApiUrl);
final int port = url.getPort();
_externalStartURI = this.webserviceInfo.getHttpScheme() +
@ -273,7 +268,9 @@ final class OpenEdxLmsAPITemplate implements LmsAPITemplate {
: StringUtils.EMPTY)
+ Constants.URL_PATH_SEPARATOR;
log.info("Use external address for course access: {}", _externalStartURI);
if (log.isDebugEnabled()) {
log.debug("Use external address for course access: {}", _externalStartURI);
}
} catch (final Exception e) {
log.error("Failed to create external address from alias: ", e);
}

View file

@ -20,6 +20,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.web.bind.MethodArgumentNotValidException;
@ -50,7 +51,12 @@ public class APIExceptionHandler extends ResponseEntityExceptionHandler {
final HttpStatus status,
final WebRequest request) {
log.error("Unexpected generic error catched at the API endpoint: ", ex);
if (ex instanceof AccessDeniedException) {
log.warn("Access denied: ", ex);
} else {
log.error("Unexpected generic error catched at the API endpoint: ", ex);
}
final List<APIMessage> errors = Arrays.asList(APIMessage.ErrorMessage.GENERIC.of(ex.getMessage()));
return new ResponseEntity<>(
errors,
@ -145,6 +151,16 @@ public class APIExceptionHandler extends ResponseEntityExceptionHandler {
.createErrorResponse(ex.getMessage());
}
@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<Object> handleUnexpected(
final AccessDeniedException ex,
final WebRequest request) {
log.warn("Access denied: ", ex);
return APIMessage.ErrorMessage.FORBIDDEN
.createErrorResponse(ex.getMessage());
}
@ExceptionHandler(Exception.class)
public ResponseEntity<Object> handleUnexpected(
final Exception ex,

View file

@ -251,7 +251,6 @@ public class ExamAPI_V1_Controller {
if (log.isDebugEnabled()) {
log.debug("Updated connection: {}", connection);
}
//handshakeUpdate(connectionToken, Long.valueOf(examId), null, principal, request);
}
final ServletOutputStream outputStream = response.getOutputStream();

View file

@ -78,8 +78,8 @@ public class HTTPClientBot {
public HTTPClientBot(final Map<String, String> args) {
this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://ralph.ethz.ch:8080");
//this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://localhost:8080");
//this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://ralph.ethz.ch:8080");
this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://localhost:8080");
this.accessTokenEndpoint = args.getOrDefault("accessTokenEndpoint", "/oauth/token");
this.clientId = args.getOrDefault("clientId", "TO_SET");
@ -147,11 +147,12 @@ public class HTTPClientBot {
headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
this.connectBody = new HttpEntity<>(API.PARAM_INSTITUTION_ID +
Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR +
HTTPClientBot.this.institutionId +
Constants.FORM_URL_ENCODED_SEPARATOR +
API.EXAM_API_PARAM_EXAM_ID +
Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR +
HTTPClientBot.this.examId,
HTTPClientBot.this.institutionId
// + Constants.FORM_URL_ENCODED_SEPARATOR
// + API.EXAM_API_PARAM_EXAM_ID
// + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR
// + HTTPClientBot.this.examId
,
headers);
}

File diff suppressed because one or more lines are too long