fixed bugs

This commit is contained in:
anhefti 2018-12-04 13:34:23 +01:00
parent bae30aeb87
commit d829233662
4 changed files with 34 additions and 12 deletions

View file

@ -12,6 +12,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
public final class Utils {
@ -57,4 +58,10 @@ public final class Utils {
return Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(items)));
}
public static <T> List<T> asImmutableList(final T[] array) {
return (array != null)
? Collections.unmodifiableList(Arrays.asList(array))
: Collections.emptyList();
}
}

View file

@ -8,10 +8,18 @@
package ch.ethz.seb.sebserver.webservice.datalayer;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.FieldError;
public class APIMessage {
import ch.ethz.seb.sebserver.gbl.util.Utils;
public class APIMessage implements Serializable {
private static final long serialVersionUID = -6858683658311637361L;
public enum ErrorMessage {
UNEXPECTED("1000", "Unexpected intenral server-side error"),
@ -37,7 +45,11 @@ public class APIMessage {
}
public APIMessage of(final String detail, final String... attributes) {
return new APIMessage(this.messageCode, this.systemMessage, detail, attributes);
return new APIMessage(
this.messageCode,
this.systemMessage,
detail,
Utils.asImmutableList(attributes));
}
public APIMessage of(final Throwable error) {
@ -48,18 +60,20 @@ public class APIMessage {
public final String messageCode;
public final String systemMessage;
public final String details;
public final String[] attributes;
public final List<String> attributes;
public APIMessage(
final String messageCode,
final String systemMessage,
final String details,
final String[] attributes) {
final List<String> attributes) {
this.messageCode = messageCode;
this.systemMessage = systemMessage;
this.details = details;
this.attributes = attributes;
this.attributes = (attributes != null)
? Collections.unmodifiableList(attributes)
: Collections.emptyList();
}
public APIMessage(final String messageCode, final String systemMessage, final String details) {
@ -82,7 +96,7 @@ public class APIMessage {
return this.details;
}
public String[] getAttributes() {
public List<String> getAttributes() {
return this.attributes;
}
@ -110,7 +124,6 @@ public class APIMessage {
public APIMessage getAPIMessage() {
return this.apiMessage;
}
}
}

View file

@ -188,7 +188,9 @@ public class AuthorizationGrantService {
}
private AuthorizationGrantRule getGrantRule(final EntityType type) {
return this.exceptionalRules.computeIfAbsent(type, entityType -> new BaseTypeGrantRule(entityType));
return this.exceptionalRules.computeIfAbsent(
type,
entityType -> new BaseTypeGrantRule(entityType, this));
}
private GrantRuleBuilder addGrant(final EntityType entityType) {
@ -207,17 +209,17 @@ public class AuthorizationGrantService {
* entity-instance for the given grant type.
* if true return true
* if false return false */
private final class BaseTypeGrantRule implements AuthorizationGrantRule {
private static class BaseTypeGrantRule implements AuthorizationGrantRule {
private final EntityType type;
private final Map<UserRole, RoleTypeGrant> grants;
public BaseTypeGrantRule(final EntityType type) {
public BaseTypeGrantRule(final EntityType type, final AuthorizationGrantService service) {
this.type = type;
this.grants = new EnumMap<>(UserRole.class);
for (final UserRole role : UserRole.values()) {
this.grants.put(role,
AuthorizationGrantService.this.grants.get(new RoleTypeKey(type, role)));
service.grants.get(new RoleTypeKey(type, role)));
}
}

View file

@ -300,7 +300,7 @@ public class UserDaoImpl implements UserDAO {
private Result<UserInfo> toDomainModel(final String nameId, final UserRecord record) {
if (record == null) {
Result.ofError(new ResourceNotFoundException(
return Result.ofError(new ResourceNotFoundException(
Domain.USER.TYPE_NAME,
String.valueOf(nameId)));
}