diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/Entity.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/Entity.java index 07e438e3..be3f84cd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/Entity.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/Entity.java @@ -13,18 +13,29 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.EntityType; +/** Defines generic interface for all types of Entity. */ public interface Entity extends ModelIdAware { public static final String FILTER_ATTR_INSTITUTION = API.PARAM_INSTITUTION_ID; public static final String FILTER_ATTR_ACTIVE = "active"; public static final String FILTER_ATTR_NAME = "name"; + /** Get the type of the entity. + * + * @return the type of the entity */ @JsonIgnore EntityType entityType(); + /** Get the name of the entity + * + * @return the name of the entity */ @JsonIgnore String getName(); + /** Get an unique EntityKey for the entity consisting of the model identifier of the entity + * and the type of the entity. + * + * @return unique EntityKey for the entity */ @JsonIgnore default EntityKey getEntityKey() { final String modelId = getModelId(); @@ -34,6 +45,10 @@ public interface Entity extends ModelIdAware { return new EntityKey(modelId, entityType()); } + /** Creates an EntityName instance from a given Entity. + * + * @param entity The Entity instance + * @return EntityName instance created form given Entity */ public static EntityName toName(final Entity entity) { return new EntityName( entity.entityType(), diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityKey.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityKey.java index 9f6aca6b..636eeb40 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityKey.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityKey.java @@ -17,17 +17,25 @@ import com.fasterxml.jackson.annotation.JsonProperty; import ch.ethz.seb.sebserver.gbl.api.EntityType; +/** A EntityKey uniquely identifies a domain entity within the SEB Server's domain model. + * A EntityKey consists of the model identifier of a domain entity and the type of the entity. */ public class EntityKey implements Serializable { private static final long serialVersionUID = -2368065921846821061L; + /** The model identifier of the entity */ @JsonProperty(value = "modelId", required = true) @NotNull public final String modelId; + + /** The type of the entity */ @JsonProperty(value = "entityType", required = true) @NotNull public final EntityType entityType; + /** pre-calculated hash value. Since EntityKey is fully immutable this is a valid optimization */ + private final int hash; + @JsonCreator public EntityKey( @JsonProperty(value = "modelId", required = true) final String modelId, @@ -42,31 +50,41 @@ public class EntityKey implements Serializable { this.modelId = modelId; this.entityType = entityType; + + final int prime = 31; + int result = 1; + result = prime * result + ((this.entityType == null) ? 0 : this.entityType.hashCode()); + result = prime * result + ((this.modelId == null) ? 0 : this.modelId.hashCode()); + this.hash = result; } public EntityKey( final Long pk, final EntityType entityType) { - this.modelId = String.valueOf(pk); - this.entityType = entityType; + this(String.valueOf(pk), entityType); + if (pk == null) { + throw new IllegalArgumentException("modelId has null reference"); + } } + /** Get the model identifier of this EntityKey + * + * @return the model identifier of this EntityKey */ public String getModelId() { return this.modelId; } + /** Get the entity type EntityKey + * + * @return the model identifier of this EntityKey */ public EntityType getEntityType() { return this.entityType; } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.entityType == null) ? 0 : this.entityType.hashCode()); - result = prime * result + ((this.modelId == null) ? 0 : this.modelId.hashCode()); - return result; + return this.hash; } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/ModelIdAware.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/ModelIdAware.java index 59d9a61e..9dcafbd1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/ModelIdAware.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/ModelIdAware.java @@ -10,8 +10,12 @@ package ch.ethz.seb.sebserver.gbl.model; import com.fasterxml.jackson.annotation.JsonIgnore; +/** Interface for all domain model objects that has a model identifier */ public interface ModelIdAware { + /** Get the model identifier of the domain model object + * + * @return the model identifier of the domain model object */ @JsonIgnore String getModelId(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java index fb9cf2d5..ebdc3b5b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java @@ -84,6 +84,12 @@ public final class Result { return this.error != null ? errorHandler.apply(this.error) : this.value; } + /** Use this to get the referenced result element or on error case, use the given error handler + * to handle the error and use a given supplier to get an alternative element for further processing + * + * @param errorHandler the error handler to handle an error if happened + * @param supplier supplies an alternative result element on error case + * @return returns the referenced result element or the alternative element given by the supplier on error */ public T get(final Consumer errorHandler, final Supplier supplier) { if (this.error != null) { errorHandler.accept(this.error); @@ -93,6 +99,9 @@ public final class Result { } } + /** Apply a given error handler that consumes the error if there is one. + * + * @param errorHandler the error handler */ public void handleError(final Consumer errorHandler) { if (this.error != null) { errorHandler.accept(this.error); @@ -120,6 +129,9 @@ public final class Result { return this.value; } + /** Get the referenced result element or in error case, throws the referenced error + * + * @return the referenced result element */ public T getOrThrow() { if (this.error != null) { if (this.error instanceof RuntimeException) { @@ -145,6 +157,9 @@ public final class Result { return this.error; } + /** Indicates whether this Result refers to an error or not. + * + * @return true if this Result refers to an error */ public boolean hasError() { return this.error != null; } @@ -210,9 +225,14 @@ public final class Result { } } - public Result onErrorDo(final Consumer block) { + /** Uses a given error handler to apply an error if there is one and returning itself again + * for further processing. + * + * @param errorHandler the error handler + * @return self reference */ + public Result onErrorDo(final Consumer errorHandler) { if (this.error != null) { - block.accept(this.error); + errorHandler.accept(this.error); } return this; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Tuple.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Tuple.java index 269f004f..ed8b4fa9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Tuple.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Tuple.java @@ -8,9 +8,12 @@ package ch.ethz.seb.sebserver.gbl.util; +/** A tuple of two elements of the same type */ public class Tuple { + /** The first element of the tuple */ public final T _1; + /** The second element of the tuple */ public final T _2; public Tuple(final T _1, final T _2) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java index 26170478..13fa7245 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java @@ -29,12 +29,20 @@ import ch.ethz.seb.sebserver.gbl.Constants; public final class Utils { + /** Get an immutable List from a Collection of elements + * + * @param collection Collection of elements + * @return immutable List */ public static List immutableListOf(final Collection collection) { return (collection != null) ? Collections.unmodifiableList(new ArrayList<>(collection)) : Collections.emptyList(); } + /** Get a immutable Collection from a Collection of elements + * + * @param collection Collection of elements + * @return immutable Collection */ public static Collection immutableCollectionOf(final Collection collection) { return (collection != null) ? Collections.unmodifiableCollection(collection) @@ -53,10 +61,18 @@ public final class Utils { return Collections.unmodifiableCollection(Arrays.asList(values)); } + /** Get a immutable Set from a Collection of elements + * + * @param collection Collection of elements + * @return immutable Set */ public static Set immutableSetOf(final Collection collection) { return immutableSetOf(new HashSet<>(collection)); } + /** Get a immutable Set from a Set of elements + * + * @param set Set of elements + * @return immutable Set */ public static Set immutableSetOf(final Set set) { return (set != null) ? Collections.unmodifiableSet(set) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/PermissionDeniedException.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/PermissionDeniedException.java index 48a1b721..c27e2d2b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/PermissionDeniedException.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/PermissionDeniedException.java @@ -15,8 +15,11 @@ public class PermissionDeniedException extends RuntimeException { private static final long serialVersionUID = 5333137812363042580L; + /** The EntityType of the denied permission check */ public final EntityType entityType; + /** The PrivilegeType of the denied permission check */ public final PrivilegeType privilegeType; + /** The user identifier of the denied permission check */ public final String userId; public PermissionDeniedException( diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/client/ClientCredentials.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/client/ClientCredentials.java index 652c9a91..dede5a95 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/client/ClientCredentials.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/client/ClientCredentials.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -8,16 +8,20 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.client; +/** Defines a simple data bean holding (encrypted) client credentials */ public final class ClientCredentials { + /** The client id or client name parameter */ public final String clientId; + /** The client secret parameter */ public final String secret; + /** An client access token if supported */ public final String accessToken; public ClientCredentials( - final String clientId, - final String secret, + final String clientId, + final String secret, final String accessToken) { - + this.clientId = clientId; this.secret = secret; this.accessToken = accessToken; diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ActivatableEntityDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ActivatableEntityDAO.java index cd47fcff..2b6263db 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ActivatableEntityDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ActivatableEntityDAO.java @@ -16,7 +16,7 @@ import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.model.ModelIdAware; import ch.ethz.seb.sebserver.gbl.util.Result; -/** Interface of a DAO for an Entity that has activation feature. +/** Interface of a Data Access Object for an Entity that has activation feature. * * @param the type of Entity */ public interface ActivatableEntityDAO extends EntityDAO { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/EntityDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/EntityDAO.java index 1b34902a..50c885de 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/EntityDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/EntityDAO.java @@ -24,6 +24,10 @@ import ch.ethz.seb.sebserver.gbl.model.EntityName; import ch.ethz.seb.sebserver.gbl.model.ModelIdAware; import ch.ethz.seb.sebserver.gbl.util.Result; +/** Defines generic interface for all Entity based Data Access Objects + * + * @param The specific type of the Entity domain model + * @param The specific type of the Entity domain model to create a new Entity */ public interface EntityDAO { /** Get the entity type for a concrete EntityDAO implementation. @@ -34,7 +38,7 @@ public interface EntityDAO { /** Use this to get an Entity instance of concrete type by database identifier/primary-key (PK) * * @param id the data base identifier of the entity - * @return Result refer the Entity instance with the specified database identifier or refer to an error if + * @return Result referring the Entity instance with the specified database identifier or refer to an error if * happened */ Result byPK(Long id); @@ -44,7 +48,7 @@ public interface EntityDAO { * but usually they are the same. * * @param id the model identifier - * @return Result refer the Entity instance with the specified model identifier or refer to an error if + * @return Result referring the Entity instance with the specified model identifier or refer to an error if * happened */ @Transactional(readOnly = true) default Result byModelId(final String id) { @@ -53,12 +57,20 @@ public interface EntityDAO { }).flatMap(this::byPK); } - Result> loadEntities(Collection keys); + /** Get a collection of all entities for the given Set of entity keys. + * + * @param keys the Set of EntityKey to get the Entity's for + * @return Result referring the collection or an error if happened */ + Result> byEntityKeys(Set keys); + /** Get a collection of all EntityName for the given Set of EntityKey. + * + * @param keys the Set of EntityKey to get the EntityName's for + * @return Result referring the collection or an error if happened */ @Transactional(readOnly = true) - default Result> loadEntityNames(final Collection keys) { + default Result> getEntityNames(final Set keys) { return Result.tryCatch(() -> { - return loadEntities(keys) + return byEntityKeys(keys) .getOrThrow() .stream() .map(entity -> new EntityName( @@ -69,27 +81,56 @@ public interface EntityDAO { }); } + /** Create a new Entity from the given entity domain model data. + * + * @param data The entity domain model data + * @return Result referring to the newly created Entity or an error if happened */ Result createNew(M data); /** Use this to save/modify an entity. * * @param data entity instance containing all data that should be saved - * @return A Result of the entity instance where the successfully saved/modified entity data is available or a + * @return A Result referring the entity instance where the successfully saved/modified entity data is available or + * a * reported exception on error case */ Result save(T data); /** Use this to delete a set Entity by a Collection of EntityKey * * @param all The Collection of EntityKey to delete - * @return Result of a collection of all entities that has been deleted or refer to an error if + * @return Result referring a collection of all entities that has been deleted or refer to an error if * happened */ Result> delete(Set all); + /** Get a (unordered) collection of all Entities that matches the given filter criteria. + * The possible filter criteria for a specific Entity type is defined by the entity type. + * + * This adds filtering in SQL level by creating the select where clause from related + * filter criteria of the specific Entity type. If the filterMap contains a value for + * a particular filter criteria the value is extracted from the map and added to the where + * clause of the SQL select statement. + * + * @param filterMap FilterMap instance containing all the relevant filter criteria + * @return Result referring to collection of all matching entities or an error if happened */ @Transactional(readOnly = true) default Result> allMatching(final FilterMap filterMap) { return allMatching(filterMap, e -> true); } + /** Get a (unordered) collection of all Entities that matches a given filter criteria + * and a given predicate. + * + * The possible filter criteria for a specific Entity type is defined by the entity type. + * This adds filtering in SQL level by creating the select where clause from related + * filter criteria of the specific Entity type. If the filterMap contains a value for + * a particular filter criteria the value is extracted from the map and added to the where + * clause of the SQL select statement. + * + * The predicate is applied after the SQL query by filtering the resulting list with the + * predicate after on the SQL query result, before returning. + * + * @param filterMap FilterMap instance containing all the relevant filter criteria + * @return Result referring to collection of all matching entities or an error if happened */ Result> allMatching(FilterMap filterMap, Predicate predicate); /** Context based utility method to extract an expected single resource entry form a Collection of specified type. diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java index dcec75f7..c2e5cd7d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java @@ -11,10 +11,6 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.dao; import ch.ethz.seb.sebserver.gbl.model.exam.Exam; import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionSupportDAO; +/** Concrete EntityDAO interface of Exam entities */ public interface ExamDAO extends ActivatableEntityDAO, BulkActionSupportDAO { - -// Result importFromQuizData(Long institutionId, Long lmsSetupId, QuizData quizData); -// -// Result byQuizId(String quizId); - } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/FilterMap.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/FilterMap.java index 035eb1ab..43c6ca9c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/FilterMap.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/FilterMap.java @@ -22,6 +22,12 @@ import ch.ethz.seb.sebserver.gbl.model.institution.SebClientConfig; import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; import ch.ethz.seb.sebserver.webservice.datalayer.batis.JodaTimeTypeResolver; +/** A Map containing various filter criteria from a certain API request. + * This is used as a data object that can be used to collect API request parameter + * data on one side and supply filter criteria based access to concrete Entity filtering + * on the other side. + * + * All text based filter criteria are used as SQL wildcard's */ public class FilterMap extends POSTMapper { public FilterMap() { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/IndicatorDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/IndicatorDAO.java index caec6323..86da7e9f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/IndicatorDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/IndicatorDAO.java @@ -14,8 +14,13 @@ import ch.ethz.seb.sebserver.gbl.model.exam.Indicator; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionSupportDAO; +/** Concrete EntityDAO interface of Indicator entities */ public interface IndicatorDAO extends EntityDAO, BulkActionSupportDAO { + /** Get a collection of all Indicator entities for a specified exam. + * + * @param examId the Exam identifier to get the Indicators for + * @return Result referring to the collection of Indicators of an Exam or to an error if happened */ Result> allForExam(Long examId); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/InstitutionDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/InstitutionDAO.java index ccc4a75b..2388ef8f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/InstitutionDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/InstitutionDAO.java @@ -11,9 +11,8 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.dao; import ch.ethz.seb.sebserver.gbl.model.institution.Institution; import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionSupportDAO; -public interface InstitutionDAO - extends ActivatableEntityDAO, BulkActionSupportDAO { - - boolean exists(String name); - +/** Concrete EntityDAO interface of Institution entities */ +public interface InstitutionDAO extends + ActivatableEntityDAO, + BulkActionSupportDAO { } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/LmsSetupDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/LmsSetupDAO.java index 39c40170..cfdea8ab 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/LmsSetupDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/LmsSetupDAO.java @@ -13,7 +13,13 @@ import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionSupportDAO; import ch.ethz.seb.sebserver.webservice.servicelayer.client.ClientCredentials; +/** Concrete EntityDAO interface of LmsSetup entities */ public interface LmsSetupDAO extends ActivatableEntityDAO, BulkActionSupportDAO { + /** Get the configured ClientCredentials for a given LmsSetup. + * The ClientCredentials are still encoded as they are on DB storage + * + * @param lmsSetupId the identifier of the LmsSetup to get the ClientCredentials for + * @return the configured ClientCredentials for a given LmsSetup */ Result getLmsAPIAccessCredentials(String lmsSetupId); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ResourceNotFoundException.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ResourceNotFoundException.java index af2103b1..89069b03 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ResourceNotFoundException.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ResourceNotFoundException.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.model.EntityKey; +/** Thrown by Data Access Object if an requested Entity or other requested resource wasn't found */ @ResponseStatus(HttpStatus.NOT_FOUND) public final class ResourceNotFoundException extends RuntimeException { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/SebClientConfigDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/SebClientConfigDAO.java index e23be8c3..fe516e50 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/SebClientConfigDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/SebClientConfigDAO.java @@ -13,10 +13,16 @@ import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionSupportDAO; import ch.ethz.seb.sebserver.webservice.servicelayer.client.ClientCredentials; +/** Concrete EntityDAO interface of SebClientConfig entities */ public interface SebClientConfigDAO extends ActivatableEntityDAO, BulkActionSupportDAO { + /** Get the configured ClientCredentials for a given SebClientConfig. + * The ClientCredentials are still encoded as they are on DB storage + * + * @param modelId the model identifier of the SebClientConfig to get the ClientCredentials for + * @return the configured ClientCredentials for a given SebClientConfig */ Result getSebClientCredentials(String modelId); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/TransactionHandler.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/TransactionHandler.java index e3533537..37812a36 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/TransactionHandler.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/TransactionHandler.java @@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.dao; import org.springframework.transaction.interceptor.TransactionInterceptor; +/** Defines some static Spring based transaction handling functionality for rollback handling */ public interface TransactionHandler { /** Use this to mark the current transaction within the calling thread as "to rollback". diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/UserActivityLogDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/UserActivityLogDAO.java index 05c574ef..a1e4d21c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/UserActivityLogDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/UserActivityLogDAO.java @@ -17,6 +17,7 @@ import ch.ethz.seb.sebserver.gbl.model.user.UserActivityLog; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.SEBServerUser; +/** Concrete EntityDAO interface of UserActivityLog entities */ public interface UserActivityLogDAO extends EntityDAO, UserRelatedEntityDAO { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/UserRelatedEntityDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/UserRelatedEntityDAO.java index 01c101cc..5f0a708e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/UserRelatedEntityDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/UserRelatedEntityDAO.java @@ -13,8 +13,7 @@ import java.util.Collection; import ch.ethz.seb.sebserver.gbl.model.Entity; import ch.ethz.seb.sebserver.gbl.util.Result; -/** Interface for a DAo handling an Entity with relations to an user (account) - * +/** Interface for all Data Access Objects handling an Entity with relations to an user (account) * * @param the concrete type of the Entity */ public interface UserRelatedEntityDAO { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java index 759914d4..e36b000c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java @@ -285,7 +285,7 @@ public class ExamDAOImpl implements ExamDAO { @Override @Transactional(readOnly = true) - public Result> loadEntities(final Collection keys) { + public Result> byEntityKeys(final Set keys) { return Result.tryCatch(() -> { final List ids = extractPKsFromKeys(keys); return this.examRecordMapper.selectByExample() diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/IndicatorDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/IndicatorDAOImpl.java index e84a0711..0ba770bb 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/IndicatorDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/IndicatorDAOImpl.java @@ -105,7 +105,7 @@ public class IndicatorDAOImpl implements IndicatorDAO { @Override @Transactional(readOnly = true) - public Result> loadEntities(final Collection keys) { + public Result> byEntityKeys(final Set keys) { return Result.tryCatch(() -> { final List ids = extractPKsFromKeys(keys); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/InstitutionDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/InstitutionDAOImpl.java index 90fd402d..3c68e42d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/InstitutionDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/InstitutionDAOImpl.java @@ -56,21 +56,6 @@ public class InstitutionDAOImpl implements InstitutionDAO { return EntityType.INSTITUTION; } - @Override - @Transactional(readOnly = true) - public boolean exists(final String name) { - if (StringUtils.isBlank(name)) { - return false; - } - - final Long count = this.institutionRecordMapper.countByExample() - .where(InstitutionRecordDynamicSqlSupport.name, isEqualTo(name)) - .build() - .execute(); - - return count != null && count.longValue() > 0; - } - @Override @Transactional(readOnly = true) public Result byPK(final Long id) { @@ -248,7 +233,7 @@ public class InstitutionDAOImpl implements InstitutionDAO { @Override @Transactional(readOnly = true) - public Result> loadEntities(final Collection keys) { + public Result> byEntityKeys(final Set keys) { return Result.tryCatch(() -> { final List ids = extractPKsFromKeys(keys); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/LmsSetupDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/LmsSetupDAOImpl.java index 78fdbdd6..88f3344e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/LmsSetupDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/LmsSetupDAOImpl.java @@ -252,7 +252,7 @@ public class LmsSetupDAOImpl implements LmsSetupDAO { @Override @Transactional(readOnly = true) - public Result> loadEntities(final Collection keys) { + public Result> byEntityKeys(final Set keys) { return Result.tryCatch(() -> { final List ids = extractPKsFromKeys(keys); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/SebClientConfigDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/SebClientConfigDAOImpl.java index 5ca2aad1..84bc4511 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/SebClientConfigDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/SebClientConfigDAOImpl.java @@ -223,7 +223,7 @@ public class SebClientConfigDAOImpl implements SebClientConfigDAO { @Override @Transactional(readOnly = true) - public Result> loadEntities(final Collection keys) { + public Result> byEntityKeys(final Set keys) { return Result.tryCatch(() -> { final List ids = extractPKsFromKeys(keys); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserActivityLogDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserActivityLogDAOImpl.java index 56188ea5..48aff299 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserActivityLogDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserActivityLogDAOImpl.java @@ -317,7 +317,7 @@ public class UserActivityLogDAOImpl implements UserActivityLogDAO { @Override @Transactional(readOnly = true) - public Result> loadEntities(final Collection keys) { + public Result> byEntityKeys(final Set keys) { // TODO Auto-generated method stub return Result.ofTODO(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java index cba6c377..908c1535 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/UserDAOImpl.java @@ -343,7 +343,7 @@ public class UserDAOImpl implements UserDAO { @Override @Transactional(readOnly = true) - public Result> loadEntities(final Collection keys) { + public Result> byEntityKeys(final Set keys) { return Result.tryCatch(() -> { final List ids = extractPKsFromKeys(keys); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/validation/BeanValidationService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/validation/BeanValidationService.java index 34b371ab..12d05388 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/validation/BeanValidationService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/validation/BeanValidationService.java @@ -22,6 +22,11 @@ import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ActivatableEntityDAO; +/** This service can be used to 'manually' validate a Bean that is annotated within bean + * validation annotations. + * + * On validation error BeanValidationException is used to collect all validation issues + * and report them within the Result. */ @Service @WebServiceProfile public class BeanValidationService { @@ -41,6 +46,14 @@ public class BeanValidationService { dao -> dao)); } + /** Validates a given bean that is annotated with Java bean validation annotations + * + * On validation error BeanValidationException is used to collect all validation issues + * and report them within the Result. + * + * @param bean the Bean to validate + * @return Result referring the Bean if there are no validation issues or to a BeanValidationException + * containing the collected validation issues */ public Result validateBean(final T bean) { final DirectFieldBindingResult errors = new DirectFieldBindingResult(bean, ""); this.validator.validate(bean, errors); @@ -51,6 +64,10 @@ public class BeanValidationService { return Result.of(bean); } + /** Indicates whether the Entity of a given EntityKey is currently active or not. + * + * @param entityKey the EntityKey of the Entity to check + * @return true if the Entity of a given EntityKey is currently active */ public boolean isActive(final EntityKey entityKey) { final ActivatableEntityDAO activatableEntityDAO = this.activatableDAOs.get(entityKey.entityType); if (activatableEntityDAO == null) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/EntityController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/EntityController.java index eebff1d2..7021c915 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/EntityController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/EntityController.java @@ -240,10 +240,10 @@ public abstract class EntityController new EntityKey(modelId, this.entityDAO.entityType())) - .collect(Collectors.toList()); + .collect(Collectors.toSet()); }) - .flatMap(this.entityDAO::loadEntities) + .flatMap(this.entityDAO::byEntityKeys) .getOrThrow() .stream() .filter(this.authorization::hasReadonlyGrant) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/RevokeTokenEndpoint.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/RevokeTokenEndpoint.java index bb855b84..3cd3c96a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/RevokeTokenEndpoint.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/RevokeTokenEndpoint.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; +/** Spring MVC controller that defines a revoke token endpoint */ @Controller @WebServiceProfile public class RevokeTokenEndpoint { diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index e81b6294..92ee888d 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -27,6 +27,7 @@ sebserver.form.validation.fieldError.username.notunique=This Username is already sebserver.form.validation.fieldError.password.wrong=Old password is wrong sebserver.form.validation.fieldError.password.mismatch=Re-typed password don't match new password sebserver.form.validation.fieldError.invalidURL=The input does not match the URL pattern. +sebserver.form.validation.fieldError.exists=This name already exists. Please choose another. sebserver.error.unexpected=Unexpected Error sebserver.page.message=Information sebserver.dialog.confirm.title=Confirmation