diff --git a/etc/service_custom_message.properties b/etc/service_custom_message.properties index b09945ce..e6d8dd5c 100644 --- a/etc/service_custom_message.properties +++ b/etc/service_custom_message.properties @@ -60,4 +60,16 @@ SERVICE_CUSTOM_MESSAGE_53 = Get user SERVICE_CUSTOM_MESSAGE_54 = Get active user SERVICE_CUSTOM_MESSAGE_55 = Create user SERVICE_CUSTOM_MESSAGE_56 = Update user -SERVICE_CUSTOM_MESSAGE_57 = Delete user \ No newline at end of file +SERVICE_CUSTOM_MESSAGE_57 = Delete user + +SERVICE_CUSTOM_MESSAGE_58 = Set PersonalisationData +SERVICE_CUSTOM_MESSAGE_59 = Get PersonalisationData + +SERVICE_CUSTOM_MESSAGE_60 = Get Comments +SERVICE_CUSTOM_MESSAGE_61 = Get Requirements + +SERVICE_CUSTOM_MESSAGE_62 = Get EntityOverview + + + + diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/BazaarService.java b/src/main/de/rwth/dbis/acis/bazaar/service/BazaarService.java index 278d7019..22c0616a 100755 --- a/src/main/de/rwth/dbis/acis/bazaar/service/BazaarService.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/BazaarService.java @@ -352,7 +352,7 @@ private void registerUserAtFirstLogin() throws Exception { // create user User.Builder userBuilder = User.geBuilder(email); User user = userBuilder.admin(false).las2peerId(agent.getIdentifier()).userName(loginName).profileImage(profileImage) - .emailLeadSubscription(true).emailFollowSubscription(true).build(); + .emailLeadSubscription(true).emailFollowSubscription(true).personalizationEnabled(true).build(); user = dalFacade.createUser(user); int userId = user.getId(); this.getNotificationDispatcher().dispatchNotification(user.getCreationDate(), Activity.ActivityAction.CREATE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_55, diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/CategoryResource.java b/src/main/de/rwth/dbis/acis/bazaar/service/CategoryResource.java index bcefdfc2..a02ed932 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/CategoryResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/CategoryResource.java @@ -224,7 +224,6 @@ public Response getCategory(@PathParam("categoryId") int categoryId) { * @return Response with the created project as a JSON object. */ @POST - @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "This method allows to create a new category under a given a project.") diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/CommentsResource.java b/src/main/de/rwth/dbis/acis/bazaar/service/CommentsResource.java index 721f1223..36f7e2ae 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/CommentsResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/CommentsResource.java @@ -65,9 +65,10 @@ public CommentsResource() throws Exception { * * @param page page number * @param perPage number of comments by page - * @param embedParents embed context/parents of comment (project, requirement) * @param search search string * @param sort sort order + * @param filters set of comments to return + * @param embedParents embed context/parents of comment (project, requirement) * @return Response with list of all requirements */ @GET @@ -83,7 +84,7 @@ public Response getAllComments( @ApiParam(value = "Elements of comments by page", required = false) @DefaultValue("10") @QueryParam("per_page") int perPage, @ApiParam(value = "Search filter", required = false) @QueryParam("search") String search, @ApiParam(value = "Sort", required = false, allowMultiple = true, allowableValues = "name,date") @DefaultValue("name") @QueryParam("sort") List sort, - @ApiParam(value = "Filter", required = true, allowMultiple = false, allowableValues = "created, following, replies") @QueryParam("filters") List filters, + @ApiParam(value = "Filter", required = true, allowMultiple = false, allowableValues = "created, following, replies, developing") @QueryParam("filters") List filters, @ApiParam(value = "Embed parents", required = true, allowMultiple = true, allowableValues = "project, requirement") @QueryParam("embedParents") List embedParents) { @@ -135,9 +136,8 @@ public Response getAllComments( commentResult = dalFacade.listAllComments(pageInfo); } - //TODO Results in "No CommentRecord found with id: 0" - //bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_3, - // 0, Activity.DataType.COMMENT, internalUserId); + bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE_LIST, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_60, + 0, Activity.DataType.COMMENT, internalUserId); Map> parameter = new HashMap<>(); parameter.put("page", new ArrayList() {{ diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/PersonalisationDataResource.java b/src/main/de/rwth/dbis/acis/bazaar/service/PersonalisationDataResource.java index 65b97e6c..5b4dee72 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/PersonalisationDataResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/PersonalisationDataResource.java @@ -1,6 +1,7 @@ package de.rwth.dbis.acis.bazaar.service; import de.rwth.dbis.acis.bazaar.service.dal.DALFacade; +import de.rwth.dbis.acis.bazaar.service.dal.entities.Activity; import de.rwth.dbis.acis.bazaar.service.dal.entities.PersonalisationData; import de.rwth.dbis.acis.bazaar.service.dal.entities.PrivilegeEnum; import de.rwth.dbis.acis.bazaar.service.exception.BazaarException; @@ -88,6 +89,9 @@ public Response getPersonalisationData(@PathParam("key") String key, @PathParam( ExceptionHandler.getInstance().throwException(ExceptionLocation.BAZAARSERVICE, ErrorCode.AUTHORIZATION, Localization.getInstance().getResourceBundle().getString("error.authorization.personalisationData.read")); } PersonalisationData data = dalFacade.getPersonalisationData(internalUserId, key, version); + bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_59, + 0, Activity.DataType.PERSONALISATION, internalUserId, new Activity.AdditionalObject(data)); + return Response.ok(data.toJSON()).build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { @@ -111,8 +115,10 @@ public Response getPersonalisationData(@PathParam("key") String key, @PathParam( /** * This method allows to save a personalisationData - * + * @param key The plugins identifier + * @param version The plugins identifier * @param data as JSON object + * * @return Response with the created attachment as JSON object. */ @PUT @@ -157,6 +163,9 @@ public Response setPersonalisationData(@PathParam("key") String key, @PathParam( } dalFacade.setPersonalisationData(fullData); + bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.UPDATE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_58, + 0, Activity.DataType.PERSONALISATION, internalUserId, new Activity.AdditionalObject(fullData)); + return Response.ok(fullData.toJSON()).build(); } catch (BazaarException bex) { diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/ProjectsResource.java b/src/main/de/rwth/dbis/acis/bazaar/service/ProjectsResource.java index a34adb78..dc5e05f2 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/ProjectsResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/ProjectsResource.java @@ -19,12 +19,15 @@ import io.swagger.annotations.*; import jodd.vtor.Vtor; + + import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.xml.bind.DatatypeConverter; import java.net.HttpURLConnection; import java.util.*; +import java.util.stream.Collectors; @Api(value = "projects", description = "Projects resource") @SwaggerDefinition( @@ -63,10 +66,13 @@ public ProjectsResource() throws Exception { * @param perPage number of projects by page * @param search search string * @param sort sort order + * @param filters set of projects to return + * @param ids list of ids for projects that should be returned + * @param context java rs context used for logging + * * @return Response with list of all projects */ @GET - @Path("/") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "This method returns the list of projects on the server.") @ApiResponses(value = { @@ -79,8 +85,9 @@ public Response getProjects( @ApiParam(value = "Elements of project by page", required = false) @DefaultValue("10") @QueryParam("per_page") int perPage, @ApiParam(value = "Search filter", required = false) @QueryParam("search") String search, @ApiParam(value = "Sort", required = false, allowMultiple = true, allowableValues = "name,date,last_activity,requirement,follower") @DefaultValue("name") @QueryParam("sort") List sort, - @ApiParam(value = "Filter", required = false, allowMultiple = true, allowableValues = "all, created, following") @QueryParam("filters") List filters, - @ApiParam(value = "Ids", required = false, allowMultiple = true) @QueryParam("ids") List ids) { + @ApiParam(value = "Filter", required = false, allowMultiple = true, allowableValues = "all, created, following, contributed") @QueryParam("filters") List filters, + @ApiParam(value = "Ids", required = false, allowMultiple = true) @QueryParam("ids") List ids, + @javax.ws.rs.core.Context javax.ws.rs.container.ContainerRequestContext context) { DALFacade dalFacade = null; try { @@ -105,6 +112,8 @@ public Response getProjects( sortList.add(sortField); } + + dalFacade = bazaarService.getDBConnection(); Integer internalUserId = dalFacade.getUserIdByLAS2PeerId(userId); @@ -129,8 +138,8 @@ public Response getProjects( // return public projects and the ones the user belongs to projectsResult = dalFacade.listPublicAndAuthorizedProjects(pageInfo, internalUserId); } - bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_3, - 0, Activity.DataType.PROJECT, internalUserId); + bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE_LIST, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_3, + 0, Activity.DataType.PROJECT, internalUserId, new Activity.AdditionalObject(new Activity.RequestInformation(context))); Map> parameter = new HashMap<>(); parameter.put("page", new ArrayList() {{ @@ -145,6 +154,8 @@ public Response getProjects( }}); } parameter.put("sort", sort); + parameter.put("filters", filters); + parameter.put("ids", ids.stream().map(Object::toString).collect(Collectors.toList())); //List from List, thanks to https://stackoverflow.com/a/23024375/3567992 Response.ResponseBuilder responseBuilder = Response.ok(); responseBuilder = responseBuilder.entity(projectsResult.toJSON()); @@ -182,7 +193,7 @@ public Response getProjects( @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems") }) - public Response getProject(@PathParam("projectId") int projectId) { + public Response getProject(@PathParam("projectId") int projectId, @javax.ws.rs.core.Context javax.ws.rs.container.ContainerRequestContext context) { DALFacade dalFacade = null; try { String registrarErrors = bazaarService.notifyRegistrars(EnumSet.of(BazaarFunction.VALIDATION, BazaarFunction.USER_FIRST_LOGIN_HANDLING)); @@ -206,7 +217,7 @@ public Response getProject(@PathParam("projectId") int projectId) { } Project projectToReturn = dalFacade.getProjectById(projectId, internalUserId); bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_4, - projectId, Activity.DataType.PROJECT, internalUserId); + projectId, Activity.DataType.PROJECT, internalUserId, new Activity.AdditionalObject(new Activity.RequestInformation(context))); return Response.ok(projectToReturn.toJSON()).build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { @@ -235,7 +246,6 @@ public Response getProject(@PathParam("projectId") int projectId) { * @return Response with the created project as a JSON object. */ @POST - @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "This method allows to create a new project.") diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/RequirementsResource.java b/src/main/de/rwth/dbis/acis/bazaar/service/RequirementsResource.java index b86fe884..ec8f057b 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/RequirementsResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/RequirementsResource.java @@ -65,6 +65,8 @@ public RequirementsResource() throws Exception { * @param perPage number of requirements by page * @param search search string * @param sort sort order + * @param filters set of element returned + * @param embedParents list of parents to embed with the response * @return Response with list of all requirements */ @GET @@ -80,7 +82,7 @@ public Response getRequirements( @ApiParam(value = "Elements of requirements by page", required = false) @DefaultValue("10") @QueryParam("per_page") int perPage, @ApiParam(value = "Search filter", required = false) @QueryParam("search") String search, @ApiParam(value = "Sort", required = false, allowMultiple = true, allowableValues = "name,date,last_activity,requirement,follower") @DefaultValue("name") @QueryParam("sort") List sort, - @ApiParam(value = "Filter", required = true, allowMultiple = true, allowableValues = "created, following") @QueryParam("filters") List filters, + @ApiParam(value = "Filter", required = true, allowMultiple = false, allowableValues = "created, following, contributed") @DefaultValue("created") @QueryParam("filters") List filters, @ApiParam(value = "Embed parents", required = true, allowMultiple = true, allowableValues = "project") @QueryParam("embedParents") List embedParents) { DALFacade dalFacade = null; @@ -130,9 +132,10 @@ public Response getRequirements( } else { requirementsResult = dalFacade.listAllRequirements(pageInfo, internalUserId); } - //TODO NotificationDispatcher tries to find Requirement with id 0 as additional Object, need to implement logic for multiple - //bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_3, - // 0, Activity.DataType.REQUIREMENT, internalUserId); + + bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE_LIST, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_61, + 0, Activity.DataType.REQUIREMENT, internalUserId); + Map> parameter = new HashMap<>(); parameter.put("page", new ArrayList() {{ @@ -146,6 +149,8 @@ public Response getRequirements( add(String.valueOf(search)); }}); } + parameter.put("filters", filters); + parameter.put("embedParents", embedParents); parameter.put("sort", sort); Response.ResponseBuilder responseBuilder = Response.ok(); @@ -415,7 +420,7 @@ public Response getRequirementsForCategory(int categoryId, int page, int perPage @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems") }) - public Response getRequirement(@PathParam("requirementId") int requirementId) { + public Response getRequirement(@PathParam("requirementId") int requirementId, @javax.ws.rs.core.Context javax.ws.rs.container.ContainerRequestContext context) { DALFacade dalFacade = null; try { Agent agent = Context.getCurrent().getMainAgent(); @@ -428,7 +433,7 @@ public Response getRequirement(@PathParam("requirementId") int requirementId) { Integer internalUserId = dalFacade.getUserIdByLAS2PeerId(userId); Requirement requirement = dalFacade.getRequirementById(requirementId, internalUserId); bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_25, - requirementId, Activity.DataType.REQUIREMENT, internalUserId); + requirementId, Activity.DataType.REQUIREMENT, internalUserId, new Activity.AdditionalObject(new Activity.RequestInformation(context))); if (dalFacade.isRequirementPublic(requirementId)) { boolean authorized = new AuthorizationManager().isAuthorized(internalUserId, PrivilegeEnum.Read_PUBLIC_REQUIREMENT, String.valueOf(requirement.getProjectId()), dalFacade); if (!authorized) { diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/UsersResource.java b/src/main/de/rwth/dbis/acis/bazaar/service/UsersResource.java index da4143a1..1fc119a2 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/UsersResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/UsersResource.java @@ -241,8 +241,8 @@ public Response getEntityOverview( @ApiParam(value = "Search filter", required = false) @QueryParam("search") String search, @ApiParam(value = "Types of entities to include", required = true, allowMultiple = true, allowableValues = "projects,categories,requirements") @QueryParam("include") List include, @ApiParam(value = "Sort", required = false, allowMultiple = true, allowableValues = "name,date,last_activity,requirement,follower") @DefaultValue("date") @QueryParam("sort") List sort, - @ApiParam(value = "Filter", required = false, allowMultiple = true, allowableValues = "created, following, developing") @DefaultValue("created") @QueryParam("filters") List filters){ - //Possibly allow filtertype "all"? + @ApiParam(value = "Filter", required = false, allowMultiple = true, allowableValues = "created, following, developing") @DefaultValue("created") @QueryParam("filters") List filters, + @javax.ws.rs.core.Context javax.ws.rs.container.ContainerRequestContext context){ DALFacade dalFacade = null; try { String registrarErrors = bazaarService.notifyRegistrars(EnumSet.of(BazaarFunction.VALIDATION, BazaarFunction.USER_FIRST_LOGIN_HANDLING)); @@ -273,13 +273,13 @@ public Response getEntityOverview( for(String filterOption : filters) { filterMap.put(filterOption,internalUserId.toString()); } + //Only used as wrapper for filter, sort & search PageInfo pageInfo = new PageInfo(0, 0, filterMap, sortList, search); EntityOverview result = dalFacade.getEntitiesForUser(include, pageInfo, internalUserId); - // Wrong SERVICE_CUSTOM_MESSAGE_3 ? - bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_3, - 0, Activity.DataType.USER, internalUserId); + bazaarService.getNotificationDispatcher().dispatchNotification(new Date(), Activity.ActivityAction.RETRIEVE, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_62, + 0, Activity.DataType.USER, internalUserId, new Activity.AdditionalObject(new Activity.RequestInformation(context))); Response.ResponseBuilder responseBuilder = Response.ok(); diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/DALFacade.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/DALFacade.java index ddf4c952..fd5911bc 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/DALFacade.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/DALFacade.java @@ -135,6 +135,15 @@ public interface DALFacade { * @return list of users to receive email notification */ List getRecipientListForRequirement(int requirementId) throws BazaarException; + + /** + * Creates an Entity-Overview for a given user + * @param includes List of entities to include values: [projects, categories, requirements] + * @param pageable Used for search-term, filters and sorting + * @param userId userId for privilege-check + */ + EntityOverview getEntitiesForUser(List includes, Pageable pageable, int userId) throws BazaarException; + //endregion //region Project @@ -452,19 +461,12 @@ public interface DALFacade { PaginationResult listCommentsByRequirementId(int requirementId, Pageable pageable) throws BazaarException; /** + * Lists all Comments, filtered according to pagination information * @param pageable pagination information - * @param includeContext include context of comment * @return the set of comments */ PaginationResult listAllComments(Pageable pageable) throws BazaarException; - /** - * @param userId the identifier of user we are looking at - * @param pageable pagination information - * @return the answers for a given user - */ - PaginationResult listAllAnswers(Pageable pageable, int userId) throws BazaarException; - /** * @param commentId * @return the comment for a given id @@ -586,26 +588,27 @@ public interface DALFacade { void addUserToRole(int userId, String roleName, String context) throws BazaarException; //endregion + //region Personalisation - + /** + * Receives the PersonalisationData with a given id + * @param id which identifies the personalisationData. + */ + PersonalisationData getPersonalisationData(int id) throws Exception; /** * Receives the PersonalisationData for a given userid, key and version * @param userId which owns the personalisationData. * @param key which identifies the personalisationData. - * @param version of the key's plugin + * @param version which identifies the personalisationData */ PersonalisationData getPersonalisationData(int userId, String key, int version) throws BazaarException; /** * Creates a new record or alters the existing record to save a given personalisationData - * @param personalisationData which holds the data to be saved + * @param personalisationData changed personalisationData record */ void setPersonalisationData(PersonalisationData personalisationData) throws BazaarException; - /** - * Creates an Entity-Overview for a given user - * @param includes List of entities to include values: [projects, categories, requirements] - * @param pageable Used for search-term, filters and sorting - * @param userId userId for privilege-check - */ - EntityOverview getEntitiesForUser(List includes, Pageable pageable, int userId) throws BazaarException; + //endregion + + } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/DALFacadeImpl.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/DALFacadeImpl.java index ef462206..b2558593 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/DALFacadeImpl.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/DALFacadeImpl.java @@ -481,11 +481,6 @@ public PaginationResult listAllComments(Pageable pageable) throws Bazaa commentRepository = (commentRepository != null) ? commentRepository : new CommentRepositoryImpl(dslContext); return commentRepository.findAllComments(pageable); } - @Override - public PaginationResult listAllAnswers(Pageable pageable, int userId) throws BazaarException { - commentRepository = (commentRepository != null) ? commentRepository : new CommentRepositoryImpl(dslContext); - return commentRepository.findAllAnswers(pageable, userId); - } @Override public Comment getCommentById(int commentId) throws Exception { @@ -645,15 +640,21 @@ public PersonalisationData getPersonalisationData(int userId, String key, int ve return personalisationDataRepository.findByKey(userId,version,key); } @Override + public PersonalisationData getPersonalisationData(int id) throws Exception { + personalisationDataRepository = (personalisationDataRepository != null) ? personalisationDataRepository : new PersonalisationDataRepositoryImpl(dslContext); + return personalisationDataRepository.findById(id); + } + @Override public void setPersonalisationData(PersonalisationData personalisationData) throws BazaarException { personalisationDataRepository = (personalisationDataRepository != null) ? personalisationDataRepository : new PersonalisationDataRepositoryImpl(dslContext); personalisationDataRepository.insertOrUpdate(personalisationData); } + @Override public EntityOverview getEntitiesForUser(List includes, Pageable pageable, int userId) throws BazaarException { - //categoryRepository = (categoryRepository != null) ? categoryRepository : new CategoryRepositoryImpl(dslContext); + /* Combines required Entities from the different Repositories */ EntityOverview.Builder result = EntityOverview.getBuilder(); for(String include : includes) { if(include.equals("projects")){ diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Activity.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Activity.java index a678e2b8..4839a623 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Activity.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Activity.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; +import javax.ws.rs.container.ContainerRequestContext; + import java.util.Date; public class Activity extends EntityBase { @@ -89,16 +91,18 @@ public AdditionalObject getAdditionalObject() { public enum DataType { STATISTIC, + PERSONALISATION, PROJECT, CATEGORY, REQUIREMENT, COMMENT, ATTACHMENT, - USER + USER; } public enum ActivityAction { RETRIEVE, + RETRIEVE_LIST, RETRIEVE_CHILD, CREATE, UPDATE, @@ -184,6 +188,7 @@ public Activity build() { } } + @JsonFilter("AdditionalObjectFilter") public static class AdditionalObject { @JsonFilter("ActivityFilter") private Project project; @@ -197,6 +202,16 @@ public static class AdditionalObject { @JsonFilter("ActivityFilter") private User user; + private PersonalisationData personalisationData; + + private RequestInformation request; + + + + + + + public Project getProject() { return project; } @@ -213,11 +228,82 @@ public User getUser() { return user; } - public AdditionalObject(Project project, Category category, Requirement requirement, User user) { + public PersonalisationData getPersonalisationData(){ return personalisationData;} + + public RequestInformation getRequest(){ return request; } + + public void setProject(Project project) { + this.project = project; + } + + public void setCategory(Category category) { + this.category = category; + } + + public void setRequirement(Requirement requirement) { + this.requirement = requirement; + } + + public void setUser(User user) { + this.user = user; + } + + public void setPersonalisationData(PersonalisationData personalisationData) { + this.personalisationData = personalisationData; + } + public void setRequest(RequestInformation request){ + this.request = request; + } + + + + + + public AdditionalObject(Project project, Category category, Requirement requirement, User user, PersonalisationData personalisationData, RequestInformation request) { this.project = project; this.category = category; this.requirement = requirement; this.user = user; + this.personalisationData = personalisationData; + this.request = request; + } + public AdditionalObject(Project project, Category category, Requirement requirement, User user, PersonalisationData personalisationData) { + this(project, category, requirement, user, personalisationData, null); + } + public AdditionalObject(Project project, Category category, Requirement requirement, User user) { + this(project, category, requirement, user, null, null); + } + public AdditionalObject(RequestInformation request) { + this(null, null, null, null, null, request); + } + public AdditionalObject(PersonalisationData data) { + this(null, null, null, null, data, null); } + + + } + public static class RequestInformation { + private String requestUri; + private String referer; + private String userAgent; + + public String getRequestUri() { return requestUri; } + public String getReferer() { return referer; } + public String getUserAgent() { return userAgent; } + + public RequestInformation(String requestUri, String referer, String userAgent){ + this.referer = referer; + this.requestUri = requestUri; + this.userAgent = userAgent; + } + public RequestInformation(ContainerRequestContext context){ + this(null,null,null); + this.referer = context.getHeaderString("referer"); + //this.userAgent = context.getHeaderString("user-agent"); //Commented out for now since not used + this.requestUri = context.getUriInfo().getRequestUri().toString(); + + + + } } } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CommentRepository.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CommentRepository.java index 5a7e740c..36741182 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CommentRepository.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CommentRepository.java @@ -34,7 +34,6 @@ public interface CommentRepository extends Repository { PaginationResult findAllByRequirementId(int requirementId, Pageable pageable) throws BazaarException; PaginationResult findAllComments(Pageable pageable) throws BazaarException; - PaginationResult findAllAnswers(Pageable pageable, int userId) throws BazaarException; boolean belongsToPublicProject(int id) throws BazaarException; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CommentRepositoryImpl.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CommentRepositoryImpl.java index 57b18ea2..449850cb 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CommentRepositoryImpl.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CommentRepositoryImpl.java @@ -52,63 +52,6 @@ public CommentRepositoryImpl(DSLContext jooq) { } - - @Override - public PaginationResult findAllAnswers(Pageable pageable, int userId) throws BazaarException { - PaginationResult result = null; - List comments; - try { - comments = new ArrayList<>(); - de.rwth.dbis.acis.bazaar.service.dal.jooq.tables.User creatorUser = USER.as("creatorUser"); - de.rwth.dbis.acis.bazaar.service.dal.jooq.tables.Comment SUB_COMMENTS = COMMENT.as("sub_comments"); - - Field idCount = jooq.selectCount() - .from(COMMENT) - .where( - // transformer.getFilterConditions(pageable.getFilters())) - // .and( - transformer.getSearchCondition(pageable.getSearch()) - ) - .asField("idCount"); - - - List queryResults = jooq.select(COMMENT.fields()) - .select(creatorUser.fields()).select(idCount) - .from(COMMENT) - .leftSemiJoin(SUB_COMMENTS).on(( - COMMENT.REPLY_TO_COMMENT_ID.eq(SUB_COMMENTS.REPLY_TO_COMMENT_ID) //Refering same thread/base-comment - .and( - COMMENT.CREATION_DATE.greaterThan(SUB_COMMENTS.CREATION_DATE) //replies have greater timestamp than the users comment - ).and( - SUB_COMMENTS.USER_ID.eq(userId) //Comments the user wrote - )).or( - COMMENT.REPLY_TO_COMMENT_ID.eq(SUB_COMMENTS.ID).and(SUB_COMMENTS.USER_ID.eq(userId)) - ) - ) - .join(creatorUser).on(creatorUser.ID.equal(COMMENT.USER_ID)) - .where(COMMENT.USER_ID.notEqual(userId)) //Hide "own" answers - .orderBy(transformer.getSortFields(pageable.getSorts())) - .limit(pageable.getPageSize()) - .offset(pageable.getOffset()) - .fetch(); - - Comment entry = null; - for (Record record : queryResults) { - if (entry == null || transformer.getEntityFromTableRecord(record.into(CommentRecord.class)).getId() != entry.getId()) { - entry = convertToCommentWithUser(record, creatorUser); - comments.add(entry); - } - } - int total = (queryResults.isEmpty() ? 0 : ((Integer) queryResults.get(0).get("idCount"))); - result = new PaginationResult<>(total, pageable, comments); - } catch (Exception e) { - ExceptionHandler.getInstance().convertAndThrowException(e, ExceptionLocation.REPOSITORY, ErrorCode.UNKNOWN); - } - - return result; - } - - @Override public PaginationResult findAllComments(Pageable pageable) throws BazaarException { PaginationResult result = null; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/PersonalisationDataRepositoryImpl.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/PersonalisationDataRepositoryImpl.java index 07ca709d..29f0d8ea 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/PersonalisationDataRepositoryImpl.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/PersonalisationDataRepositoryImpl.java @@ -23,7 +23,13 @@ public PersonalisationDataRepositoryImpl(DSLContext jooq) { super(jooq, new PersonalisationDataTransformer()); } - + /** + * Finds the Entry for a given userId, Key and Version (all part of composite key) + * @param userId userId for the PersonalisationData Entry + * @param version userId for the PersonalisationData Entry + * @param key key for the PersonalisationData Entry + * @return Entry if found, Throws bazaarException otherwise. + * **/ @Override public PersonalisationData findByKey(int userId, int version, String key) throws BazaarException{ PersonalisationData data = null; @@ -44,6 +50,11 @@ public PersonalisationData findByKey(int userId, int version, String key) throws } return data; } + + /** + * CREATES if does not exist or UPDATES if exists + * @param data PersonalisationData to insert/Update + * **/ @Override public void insertOrUpdate(PersonalisationData data) throws BazaarException{ jooq.insertInto(PERSONALISATION_DATA, PERSONALISATION_DATA.IDENTIFIER, PERSONALISATION_DATA.USER_ID, PERSONALISATION_DATA.VERSION, PERSONALISATION_DATA.SETTING) diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/ProjectRepositoryImpl.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/ProjectRepositoryImpl.java index 850b5ab0..fc3fade5 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/ProjectRepositoryImpl.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/ProjectRepositoryImpl.java @@ -279,6 +279,9 @@ public PaginationResult findAllPublicAndAuthorized(Pageable pageable, i .offset(pageable.getOffset()) .fetch(); + + + for (Record queryResult : queryResults) { ProjectRecord projectRecord = queryResult.into(PROJECT); Project project = transformer.getEntityFromTableRecord(projectRecord); @@ -301,6 +304,9 @@ public PaginationResult findAllPublicAndAuthorized(Pageable pageable, i return result; } + /** + * @return List of Integers (Project-Ids) matching the filters & sorts from pageable. Page-Size/Offset is ignored + * **/ @Override public List listAllProjectIds(Pageable pageable, int userId) throws BazaarException { List projectIds = new ArrayList<>(); diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CommentTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CommentTransformer.java index a1f29597..00d70772 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CommentTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CommentTransformer.java @@ -95,7 +95,6 @@ public Collection> getSortFields(List return Collections.singletonList(COMMENT.CREATION_DATE.asc()); } - List> sortFields = new ArrayList<>(); for (Pageable.SortField sort : sorts) { switch (sort.getField()) { @@ -148,20 +147,22 @@ public Collection getFilterConditions(Map f COMMENT.USER_ID.eq(Integer.parseInt(filterEntry.getValue())) ); }else - if(filterEntry.getKey().equals("following")){ conditions.add( COMMENT.REQUIREMENT_ID.in( + //Requirement Follows DSL.select(REQUIREMENT_FOLLOWER_MAP.REQUIREMENT_ID) .from(REQUIREMENT_FOLLOWER_MAP) .where(REQUIREMENT_FOLLOWER_MAP.USER_ID.eq(Integer.parseInt(filterEntry.getValue()))) .union( + //Category Follows DSL.select(REQUIREMENT_CATEGORY_MAP.REQUIREMENT_ID) .from(REQUIREMENT_CATEGORY_MAP) .join(CATEGORY_FOLLOWER_MAP) .on(REQUIREMENT_CATEGORY_MAP.CATEGORY_ID.eq(CATEGORY_FOLLOWER_MAP.CATEGORY_ID) .and(CATEGORY_FOLLOWER_MAP.USER_ID.eq(Integer.parseInt(filterEntry.getValue())))) ).union( + //Project Follows DSL.select(REQUIREMENT.ID) .from(REQUIREMENT) .join(PROJECT_FOLLOWER_MAP) @@ -193,9 +194,9 @@ public Collection getFilterConditions(Map f ).where(IN_COMMENTS.USER_ID.notEqual(Integer.parseInt(filterEntry.getValue()))) // Remove Users "Own" Comments ) ); - } + }else + -/* if(filterEntry.getKey().equals("developing")){ conditions.add( COMMENT.REQUIREMENT_ID.in( @@ -207,8 +208,8 @@ public Collection getFilterConditions(Map f ); - }else - */ + } + else{ conditions.add( diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/ProjectTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/ProjectTransformer.java index 61ed0b6a..6e52d868 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/ProjectTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/ProjectTransformer.java @@ -221,6 +221,29 @@ public Collection getFilterConditions(Map f .where(PROJECT_FOLLOWER_MAP.USER_ID.eq(Integer.parseInt(filterEntry.getValue()))) ) ); + }else if(filterEntry.getKey().equals("contributed")){ + Integer userId = Integer.parseInt(filterEntry.getValue()); + conditions.add( + PROJECT.ID.in( + DSL.select(PROJECT.ID).from(PROJECT).where(PROJECT.LEADER_ID.eq(userId)).union( + DSL.select(CATEGORY.PROJECT_ID).from(CATEGORY).where(CATEGORY.LEADER_ID.eq(userId))).union( + DSL.select(REQUIREMENT.PROJECT_ID).from(REQUIREMENT) + .leftOuterJoin(ATTACHMENT).on(REQUIREMENT.ID.equal(ATTACHMENT.REQUIREMENT_ID)) + .leftOuterJoin(COMMENT).on(REQUIREMENT.ID.equal(COMMENT.REQUIREMENT_ID)) + .leftOuterJoin(REQUIREMENT_DEVELOPER_MAP).on(REQUIREMENT.ID.equal(REQUIREMENT_DEVELOPER_MAP.REQUIREMENT_ID)) + .leftOuterJoin(VOTE).on(VOTE.REQUIREMENT_ID.equal(REQUIREMENT.ID)) + .where( + REQUIREMENT.CREATOR_ID.eq(userId) + .or(REQUIREMENT.LEAD_DEVELOPER_ID.eq(userId)) + .or(COMMENT.USER_ID.eq(userId)) + .or(REQUIREMENT_DEVELOPER_MAP.USER_ID.eq(userId)) + .or(REQUIREMENT.ID.equal(VOTE.REQUIREMENT_ID).and(VOTE.USER_ID.eq(userId))) + .or(VOTE.USER_ID.eq(userId)) + .or(ATTACHMENT.USER_ID.eq(userId)) + ) + ) + ) + ); } else{ conditions.add(DSL.falseCondition()); diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementTransformer.java index 43b27727..17c6f92e 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementTransformer.java @@ -242,7 +242,31 @@ public Collection getFilterConditions(Map f REQUIREMENT.LEAD_DEVELOPER_ID.eq(Integer.parseInt(filterEntry.getValue())) ) ); - }else{ + + }else if(filterEntry.getKey().equals("contributed")){ + Integer userId = Integer.parseInt(filterEntry.getValue()); + conditions.add( + REQUIREMENT.ID.in( + DSL.select(REQUIREMENT.ID).from(REQUIREMENT) + .leftOuterJoin(ATTACHMENT).on(REQUIREMENT.ID.equal(ATTACHMENT.REQUIREMENT_ID)) + .leftOuterJoin(COMMENT).on(REQUIREMENT.ID.equal(COMMENT.REQUIREMENT_ID)) + .leftOuterJoin(REQUIREMENT_DEVELOPER_MAP).on(REQUIREMENT.ID.equal(REQUIREMENT_DEVELOPER_MAP.REQUIREMENT_ID)) + .leftOuterJoin(VOTE).on(VOTE.REQUIREMENT_ID.equal(REQUIREMENT.ID)) + .where( + REQUIREMENT.CREATOR_ID.eq(userId) + .or(REQUIREMENT.LEAD_DEVELOPER_ID.eq(userId)) + .or(COMMENT.USER_ID.eq(userId)) + .or(REQUIREMENT_DEVELOPER_MAP.USER_ID.eq(userId)) + .or(REQUIREMENT.ID.equal(VOTE.REQUIREMENT_ID).and(VOTE.USER_ID.eq(userId))) + .or(VOTE.USER_ID.eq(userId)) + .or(ATTACHMENT.USER_ID.eq(userId)) + ) + + ) + ); + } + + else{ conditions.add( DSL.falseCondition() ); diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/notification/ActivityDispatcher.java b/src/main/de/rwth/dbis/acis/bazaar/service/notification/ActivityDispatcher.java index 30f0ef18..59dea571 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/notification/ActivityDispatcher.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/notification/ActivityDispatcher.java @@ -114,9 +114,9 @@ public void sendActivityOverRMI(Date creationDate, Activity.ActivityAction activ Activity activity = activityBuilder.build(); FilterProvider filters = - new SimpleFilterProvider().addFilter( - "ActivityFilter", - SimpleBeanPropertyFilter.filterOutAllExcept("id", "name")); + new SimpleFilterProvider() + .addFilter("ActivityFilter", SimpleBeanPropertyFilter.filterOutAllExcept("id", "name")) + .addFilter("AdditionalObjectFilter", SimpleBeanPropertyFilter.serializeAllExcept("request", "personalisationData")); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/notification/NotificationDispatcher.java b/src/main/de/rwth/dbis/acis/bazaar/service/notification/NotificationDispatcher.java index bfa3e1d4..db29507d 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/notification/NotificationDispatcher.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/notification/NotificationDispatcher.java @@ -12,6 +12,8 @@ public interface NotificationDispatcher extends Runnable { void dispatchNotification(Date creationDate, Activity.ActivityAction activityAction, final MonitoringEvent mobSOSEvent, int dataId, Activity.DataType dataType, int userId); + void dispatchNotification(Date creationDate, Activity.ActivityAction activityAction, final MonitoringEvent mobSOSEvent, + int dataId, Activity.DataType dataType, int userId, Activity.AdditionalObject additionalObject); void setBazaarService(BazaarService service); diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/notification/NotificationDispatcherImp.java b/src/main/de/rwth/dbis/acis/bazaar/service/notification/NotificationDispatcherImp.java index 9863dc61..155645bb 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/notification/NotificationDispatcherImp.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/notification/NotificationDispatcherImp.java @@ -42,25 +42,43 @@ public void setEmailDispatcher(EmailDispatcher emailDispatcher) { @Override public void dispatchNotification(final Date creationDate, final Activity.ActivityAction activityAction, final MonitoringEvent mobSOSEvent, final int dataId, final Activity.DataType dataType, final int userId) { + dispatchNotification(creationDate, activityAction,mobSOSEvent, dataId, dataType, userId, null); + } + + @Override + public void dispatchNotification(final Date creationDate, final Activity.ActivityAction activityAction, final MonitoringEvent mobSOSEvent, + final int dataId, final Activity.DataType dataType, final int userId,Activity.AdditionalObject additionalObject) { // Filters to generate JSON elements FilterProvider filters = - new SimpleFilterProvider().addFilter( - "ActivityFilter", - SimpleBeanPropertyFilter.filterOutAllExcept("id", "name")); + new SimpleFilterProvider() + .addFilter("ActivityFilter", SimpleBeanPropertyFilter.filterOutAllExcept("id", "name")) + .addFilter("AdditionalObjectFilter", SimpleBeanPropertyFilter.serializeAllExcept()); mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setFilters(filters); - Activity.AdditionalObject additionalObject = generateAdditionalObject(dataType, dataId, userId); + if(additionalObject == null) { + additionalObject = generateAdditionalObject(dataType, dataId, userId); + }else{ + //If we parse an external additional Object, merge the generated one with the external. + Activity.AdditionalObject defaultAdditional = generateAdditionalObject(dataType, dataId, userId); + if(additionalObject.getCategory() != null) defaultAdditional.setCategory(additionalObject.getCategory()); + if(additionalObject.getPersonalisationData() != null) defaultAdditional.setPersonalisationData(additionalObject.getPersonalisationData()); + if(additionalObject.getProject() != null) defaultAdditional.setProject(additionalObject.getProject()); + if(additionalObject.getRequirement() != null) defaultAdditional.setRequirement(additionalObject.getRequirement()); + if(additionalObject.getUser() != null) defaultAdditional.setUser(additionalObject.getUser()); + if(additionalObject.getRequest() != null) defaultAdditional.setRequest(additionalObject.getRequest()); + additionalObject = defaultAdditional; + } try { - if (emailDispatcher != null && (activityAction == Activity.ActivityAction.CREATE || activityAction == Activity.ActivityAction.UPDATE || + if (emailDispatcher != null && (dataType != Activity.DataType.PERSONALISATION) && (activityAction == Activity.ActivityAction.CREATE || activityAction == Activity.ActivityAction.UPDATE || activityAction == Activity.ActivityAction.REALIZE)) { // add email emailDispatcher.addEmailNotification(creationDate, activityAction, dataId, dataType, userId, additionalObject); } - if (activityDispatcher != null && (activityAction == Activity.ActivityAction.CREATE || activityAction == Activity.ActivityAction.UPDATE || + if (activityDispatcher != null && (dataType != Activity.DataType.PERSONALISATION) && (activityAction == Activity.ActivityAction.CREATE || activityAction == Activity.ActivityAction.UPDATE || activityAction == Activity.ActivityAction.REALIZE || activityAction == Activity.ActivityAction.DEVELOP || activityAction == Activity.ActivityAction.LEADDEVELOP || activityAction == Activity.ActivityAction.FOLLOW || activityAction == Activity.ActivityAction.VOTE)) { @@ -83,25 +101,28 @@ private Activity.AdditionalObject generateAdditionalObject(Activity.DataType dat dalFacade = bazaarService.getDBConnection(); User user = dalFacade.getUserById(userId); - if (dataType.equals(Activity.DataType.PROJECT) && dataId != 0) { + if (dataType.equals(Activity.DataType.PERSONALISATION) && dataId != 0) { + PersonalisationData personalisationData = dalFacade.getPersonalisationData(dataId); + additionalObject = new Activity.AdditionalObject(null, null, null, user, personalisationData); + } else if (dataType.equals(Activity.DataType.PROJECT) && dataId != 0) { Project project = dalFacade.getProjectById(dataId, userId); additionalObject = new Activity.AdditionalObject(project, null, null, user); - } else if (dataType.equals(Activity.DataType.CATEGORY)) { + } else if (dataType.equals(Activity.DataType.CATEGORY) && dataId != 0) { Category category = dalFacade.getCategoryById(dataId, userId); Project project = dalFacade.getProjectById(category.getProjectId(), userId); additionalObject = new Activity.AdditionalObject(project, category, null, user); - } else if (dataType.equals(Activity.DataType.REQUIREMENT)) { + } else if (dataType.equals(Activity.DataType.REQUIREMENT) && dataId != 0) { Requirement requirement = dalFacade.getRequirementById(dataId, userId); Category category = dalFacade.getCategoryById(requirement.getCategories().get(0).getId(), userId); Project project = dalFacade.getProjectById(requirement.getProjectId(), userId); additionalObject = new Activity.AdditionalObject(project, category, requirement, user); - } else if (dataType.equals(Activity.DataType.COMMENT)) { + } else if (dataType.equals(Activity.DataType.COMMENT) && dataId != 0) { Comment comment = dalFacade.getCommentById(dataId); Requirement requirement = dalFacade.getRequirementById(comment.getRequirementId(), userId); Category category = dalFacade.getCategoryById(requirement.getCategories().get(0).getId(), userId); Project project = dalFacade.getProjectById(requirement.getProjectId(), userId); additionalObject = new Activity.AdditionalObject(project, category, requirement, user); - } else if (dataType.equals(Activity.DataType.ATTACHMENT)) { + } else if (dataType.equals(Activity.DataType.ATTACHMENT) && dataId != 0) { Attachment attachment = dalFacade.getAttachmentById(dataId); Requirement requirement = dalFacade.getRequirementById(attachment.getRequirementId(), userId); Category category = dalFacade.getCategoryById(requirement.getCategories().get(0).getId(), userId);