code cleanup

This commit is contained in:
anhefti 2020-01-06 12:14:10 +01:00
parent 663662d50e
commit 771641627b
3 changed files with 20 additions and 7 deletions

View file

@ -8,9 +8,17 @@
package ch.ethz.seb.sebserver.gbl;
import java.util.Collection;
import org.eclipse.swt.graphics.RGB;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.core.ParameterizedTypeReference;
import com.fasterxml.jackson.core.type.TypeReference;
import ch.ethz.seb.sebserver.gbl.api.APIMessage;
import ch.ethz.seb.sebserver.gbl.api.authorization.Privilege;
/** Global Constants used in SEB Server web-service as well as in web-gui component */
public final class Constants {
@ -107,4 +115,11 @@ public final class Constants {
public static final RGB WHITE_RGB = new RGB(255, 255, 255);
public static final RGB BLACK_RGB = new RGB(0, 0, 0);
public static final TypeReference<Collection<APIMessage>> TYPE_REFERENCE_API_MESSAGE = new TypeReference<>() {
};
public static final ParameterizedTypeReference<Collection<Privilege>> TYPE_REFERENCE_PRIVILEGES =
new ParameterizedTypeReference<>() {
};
}

View file

@ -17,7 +17,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@ -25,6 +24,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.api.authorization.Privilege;
@ -183,6 +183,8 @@ public class CurrentUser {
this.attributes.clear();
}
this.privileges = null;
if (isAvailable()) {
if (this.authContext.logout()) {
this.authContext = null;
@ -225,8 +227,7 @@ public class CurrentUser {
.toUriString(),
HttpMethod.GET,
HttpEntity.EMPTY,
new ParameterizedTypeReference<Collection<Privilege>>() {
});
Constants.TYPE_REFERENCE_PRIVILEGES);
if (exchange.getStatusCodeValue() == HttpStatus.OK.value()) {
final Collection<Privilege> privileges = exchange.getBody();

View file

@ -22,8 +22,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.type.TypeReference;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.APIMessage;
@ -149,8 +147,7 @@ public class InstructionProcessor {
try {
final Collection<APIMessage> errorMessage = this.jsonMapper.readValue(
response,
new TypeReference<Collection<APIMessage>>() {
});
Constants.TYPE_REFERENCE_API_MESSAGE);
pageContext.notifyUnexpectedError(new RestCallError(
"Failed to propagate SEB client instruction: ",