diff --git a/etc/ant_configuration/service.properties b/etc/ant_configuration/service.properties index 1ca94066..29e95767 100755 --- a/etc/ant_configuration/service.properties +++ b/etc/ant_configuration/service.properties @@ -1,4 +1,4 @@ -service.version=0.7 +service.version=0.7.1 service.name=de.rwth.dbis.acis.bazaar.service service.path=de/rwth/dbis/acis/bazaar/service service.class=BazaarService diff --git a/etc/de.rwth.dbis.acis.bazaar.service.BazaarService.properties b/etc/de.rwth.dbis.acis.bazaar.service.BazaarService.properties index 4d623ebf..c9d96687 100644 --- a/etc/de.rwth.dbis.acis.bazaar.service.BazaarService.properties +++ b/etc/de.rwth.dbis.acis.bazaar.service.BazaarService.properties @@ -1,7 +1,7 @@ dbUserName=root dbPassword=reqbaz dbUrl=jdbc:mysql://localhost:3306/reqbaz -lang=eng +lang=en country=us baseURL=http://localhost:8080/bazaar/ frontendBaseURL=http://localhost:5000/ @@ -9,4 +9,5 @@ activityTrackerService=de.rwth.dbis.acis.activitytracker.service.ActivityTracker activityOrigin=https://requirements-bazaar.org smtpServer= emailFromAddress= +emailSummaryTimePeriodInMinutes= monitor= \ No newline at end of file diff --git a/src/i18n/Translation_en.properties b/src/i18n/Translation_en.properties index 4a47d5ef..ffb99a1f 100644 --- a/src/i18n/Translation_en.properties +++ b/src/i18n/Translation_en.properties @@ -49,24 +49,28 @@ error.authorization.requirement.modify=Only the creator can modify requirements. error.resource.notfound=$s not found. # email fields. english only at the moment. -email.subject.requirement.created=New Requirement: -email.subject.requirement.updated=Updated Requirement: -email.subject.requirement.realized=Realized Requirement: -email.subject.comment.created=New Comment to Requirement: -email.subject.comment.updated=Updated Comment to Requirement: -email.subject.category.created=New Component: -email.subject.category.updated=Updated Component: -email.subject.project.created=New Project: -email.subject.project.updated=Updated Project: email.bodyText.greeting=Hello, -email.bodyText.requirement.created=a new requirement that might may be interested in was created: -email.bodyText.requirement.updated=a requirement that you might be interested in was updated: -email.bodyText.requirement.realized=a requirement that you might be interested in was realized: -email.bodyText.comment.created=a new comment that you might be interested in was posted: -email.bodyText.comment.updated=a comment that you might be interested in was updated: -email.bodyText.category.created=a new category that you might be interested in was created: -email.bodyText.category.updated=a category that you might be interested in was updated: -email.bodyText.project.created=a new project that you might be interested in was created: -email.bodyText.project.updated=a project that you might be interested in was updated: -email.bodyText.footer1=This email was automatically sent by Requirements Bazaar. -email.bodyText.footer2=To change your email notification settings, please go to your profile settings on Requirements Bazaar. \ No newline at end of file +email.bodyText.user=User +email.bodyText.created=created +email.bodyText.updated=updated +email.bodyText.realized=realized +email.bodyText.project=project +email.bodyText.category=category +email.bodyText.requirement=requirement +email.bodyText.comment=comment +email.bodyText.attachment=attachment +email.bodyText.forDetails=For more details, check: +email.bodyText.in=in +email.bodyText.for=for +email.bodyText.with=with +email.bodyText.the=the +email.bodyText.description=description +email.subject.New=New +email.subject.singleSummary=update on Requirements Bazaar! +email.subject.multipleSummary=updates on Requirements Bazaar! +email.subject.updated=Updated +email.subject.realized=Realized +email.bodyText.news=Requirements Bazaar has news for an item you are following: +email.bodyText.nextSummary=In case there is more activity on Requirements Bazaar, we will send you another notification in around %s minutes. +email.bodyText.bestWishes=Best,\r\n Requirements Bazaar +email.bodyText.footer=This email was generated automatically by Requirements Bazaar.\r\nTo change your email notification settings, please log in and check your profile settings:\r\nhttps://requirements-bazaar.org \ No newline at end of file diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/AttachmentsResource.java b/src/main/de/rwth/dbis/acis/bazaar/service/AttachmentsResource.java index 89649f9c..ad4eb3e9 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/AttachmentsResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/AttachmentsResource.java @@ -106,9 +106,8 @@ public Response getAttachmentsForRequirement(int requirementId, int page, int pe responseBuilder = responseBuilder.entity(attachmentsResult.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, attachmentsResult, "requirements/" + String.valueOf(requirementId) + "/attachments", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, attachmentsResult); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); 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 5ccad894..bb5e9636 100755 --- a/src/main/de/rwth/dbis/acis/bazaar/service/BazaarService.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/BazaarService.java @@ -52,10 +52,7 @@ import org.jooq.SQLDialect; import javax.sql.DataSource; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.Link; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -87,6 +84,7 @@ public class BazaarService extends RESTService { protected String activityOrigin; protected String smtpServer; protected String emailFromAddress; + protected String emailSummaryTimePeriodInMinutes; private Vtor vtor; private List functionRegistrar; @@ -118,38 +116,29 @@ public BazaarService() throws Exception { dataSource = setupDataSource(dbUrl, dbUserName, dbPassword); functionRegistrar = new ArrayList<>(); - functionRegistrar.add(new BazaarFunctionRegistrar() { - @Override - public void registerFunction(EnumSet functions) throws BazaarException { - DALFacade dalFacade = null; - try { - dalFacade = getDBConnection(); - AuthorizationManager.SyncPrivileges(dalFacade); - } catch (BazaarException ex) { - ExceptionHandler.getInstance().convertAndThrowException(ex, ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, Localization.getInstance().getResourceBundle().getString("error.privilege_sync")); - } catch (Exception e) { - ExceptionHandler.getInstance().convertAndThrowException(e, ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, Localization.getInstance().getResourceBundle().getString("error.privilege_sync")); - } finally { - closeDBConnection(dalFacade); - } + functionRegistrar.add(functions -> { + DALFacade dalFacade = null; + try { + dalFacade = getDBConnection(); + AuthorizationManager.SyncPrivileges(dalFacade); + } catch (BazaarException ex) { + ExceptionHandler.getInstance().convertAndThrowException(ex, ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, Localization.getInstance().getResourceBundle().getString("error.privilege_sync")); + } catch (Exception e) { + ExceptionHandler.getInstance().convertAndThrowException(e, ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, Localization.getInstance().getResourceBundle().getString("error.privilege_sync")); + } finally { + closeDBConnection(dalFacade); } }); - functionRegistrar.add(new BazaarFunctionRegistrar() { - @Override - public void registerFunction(EnumSet functions) { - if (functions.contains(BazaarFunction.VALIDATION)) { - createValidators(); - } + functionRegistrar.add(functions -> { + if (functions.contains(BazaarFunction.VALIDATION)) { + createValidators(); } }); - functionRegistrar.add(new BazaarFunctionRegistrar() { - @Override - public void registerFunction(EnumSet functions) throws Exception { - if (functions.contains(BazaarFunction.USER_FIRST_LOGIN_HANDLING)) { - registerUserAtFirstLogin(); - } + functionRegistrar.add(functions -> { + if (functions.contains(BazaarFunction.USER_FIRST_LOGIN_HANDLING)) { + registerUserAtFirstLogin(); } }); @@ -160,8 +149,20 @@ public void registerFunction(EnumSet functions) throws Exception if (!smtpServer.isEmpty()) { Properties props = System.getProperties(); props.put("mail.smtp.host", smtpServer); - notificationDispatcher.setEmailDispatcher(new EmailDispatcher(this, smtpServer, emailFromAddress, frontendBaseURL)); + notificationDispatcher.setEmailDispatcher(new EmailDispatcher(this, smtpServer, emailFromAddress, frontendBaseURL, emailSummaryTimePeriodInMinutes)); + + if (!emailSummaryTimePeriodInMinutes.isEmpty()) { + try { + // This task is scheduled to run every 60 seconds * emailSummaryTimePeriodInMinutes + Timer timer = new Timer(); + timer.scheduleAtFixedRate((NotificationDispatcherImp) notificationDispatcher, 0, 60000 * Integer.valueOf(emailSummaryTimePeriodInMinutes)); + } catch (Exception ex) { + logger.warning(ex.getMessage()); + } + } + } + notificationDispatcher.setBazaarService(this); } @@ -169,7 +170,7 @@ public void registerFunction(EnumSet functions) throws Exception @SwaggerDefinition( info = @Info( title = "Requirements Bazaar", - version = "0.7", + version = "0.7.1", description = "Requirements Bazaar project", termsOfService = "http://requirements-bazaar.org", contact = @Contact( @@ -202,7 +203,6 @@ public static class Resource { @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns statistics", response = Statistic.class), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"), - @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems") }) public Response getStatistics( @@ -240,6 +240,32 @@ public Response getStatistics( bazaarService.closeDBConnection(dalFacade); } } + + /** + * This method sends all notifications (emails) in the waiting queue. Run this method before shutting down Requirements Bazaar. + * + * @return Response + */ + @POST + @Path("/notifications") + @ApiOperation(value = "This method sends all notifications (emails) in the waiting queue. Run this method before shutting down Requirements Bazaar.") + @ApiResponses(value = { + @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "Notifications send"), + @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"), + @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems") + }) + public Response sendNotifications() { + // TODO: Use authorization scopes to limit users who can run this method to admins + try { + bazaarService.notificationDispatcher.run(); + return Response.status(Response.Status.CREATED).build(); + } catch (Exception ex) { + BazaarException bex = ExceptionHandler.getInstance().convert(ex, ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, ex.getMessage()); + L2pLogger.logEvent(NodeObserver.Event.SERVICE_ERROR, Context.getCurrent().getMainAgent(), "Send Notifications failed"); + bazaarService.logger.warning(bex.getMessage()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); + } + } } public String notifyRegistrars(EnumSet functions) { @@ -342,7 +368,7 @@ public static DataSource setupDataSource(String dbUrl, String dbUserName, String return dataSource; } - public DALFacade getDBConnection() throws Exception { + public DALFacade getDBConnection() throws Exception { // TODO: Specify Exception return new DALFacadeImpl(dataSource, SQLDialect.MYSQL); } 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 4a53fbf3..b21a13e6 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/CategoryResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/CategoryResource.java @@ -133,9 +133,8 @@ public Response getCategoriesForProject(int projectId, int page, int perPage, St responseBuilder = responseBuilder.entity(categoriesResult.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, categoriesResult, "projects/" + String.valueOf(projectId) + "/categories", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, categoriesResult); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); @@ -685,9 +684,8 @@ public Response getFollowersForCategory(@PathParam("categoryId") int categoryId, responseBuilder = responseBuilder.entity(categoryFollowers.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, categoryFollowers, "categories/" + String.valueOf(categoryId) + "/followers", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, categoryFollowers); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); 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 c8626188..433190ae 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/CommentsResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/CommentsResource.java @@ -106,9 +106,8 @@ public Response getCommentsForRequirement(int requirementId, int page, int perPa responseBuilder = responseBuilder.entity(commentsResult.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, commentsResult, "requirements/" + String.valueOf(requirementId) + "/comments", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, commentsResult); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); 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 508a7f63..5fbd6e16 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/ProjectsResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/ProjectsResource.java @@ -138,9 +138,8 @@ public Response getProjects( responseBuilder = responseBuilder.entity(projectsResult.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, projectsResult, "projects", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, projectsResult); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { logger.warning(bex.getMessage()); L2pLogger.logEvent(NodeObserver.Event.SERVICE_ERROR, Context.getCurrent().getMainAgent(), "Get projects failed"); @@ -612,9 +611,8 @@ public Response getFollowersForProject(@PathParam("projectId") int projectId, responseBuilder = responseBuilder.entity(projectFollowers.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, projectFollowers, "projects/" + String.valueOf(projectId) + "/followers", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, projectFollowers); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); 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 804dec33..67884b80 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/RequirementsResource.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/RequirementsResource.java @@ -77,7 +77,7 @@ public Response getRequirementsForProject(int projectId, int page, int perPage, ExceptionHandler.getInstance().throwException(ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, registrarErrors); } HashMap filters = new HashMap<>(); - if (stateFilter != "all") { + if (!Objects.equals(stateFilter, "all")) { filters.put("realized", stateFilter); } List sortList = new ArrayList<>(); @@ -141,9 +141,8 @@ public Response getRequirementsForProject(int projectId, int page, int perPage, responseBuilder = responseBuilder.entity(requirementsResult.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, requirementsResult, "projects/" + String.valueOf(projectId) + "/requirements", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, requirementsResult); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); @@ -185,7 +184,7 @@ public Response getRequirementsForCategory(int categoryId, int page, int perPage ExceptionHandler.getInstance().throwException(ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, registrarErrors); } HashMap filters = new HashMap<>(); - if (stateFilter != "all") { + if (!Objects.equals(stateFilter, "all")) { filters.put("realized", stateFilter); } List sortList = new ArrayList<>(); @@ -251,9 +250,8 @@ public Response getRequirementsForCategory(int categoryId, int page, int perPage responseBuilder = responseBuilder.entity(requirementsResult.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, requirementsResult, "categories/" + String.valueOf(categoryId) + "/requirements", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, requirementsResult); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); @@ -1225,9 +1223,8 @@ public Response getDevelopersForRequirement(@PathParam("requirementId") int requ responseBuilder = responseBuilder.entity(requirementDevelopers.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, requirementDevelopers, "requirements/" + String.valueOf(requirementId) + "/developers", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, requirementDevelopers); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); @@ -1352,9 +1349,8 @@ public Response getFollowersForRequirement(@PathParam("requirementId") int requi responseBuilder = responseBuilder.entity(requirementFollowers.toJSON()); responseBuilder = bazaarService.paginationLinks(responseBuilder, requirementFollowers, "requirements/" + String.valueOf(requirementId) + "/followers", parameter); responseBuilder = bazaarService.xHeaderFields(responseBuilder, requirementFollowers); - Response response = responseBuilder.build(); - return response; + return responseBuilder.build(); } catch (BazaarException bex) { if (bex.getErrorCode() == ErrorCode.AUTHORIZATION) { return Response.status(Response.Status.UNAUTHORIZED).entity(ExceptionHandler.getInstance().toJSON(bex)).build(); 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 70ea9b5c..3328b088 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 @@ -89,8 +89,7 @@ public void close() { @Override public User createUser(User user) throws BazaarException { userRepository = (userRepository != null) ? userRepository : new UserRepositoryImpl(dslContext); - User newUser = userRepository.add(user); - return newUser; + return userRepository.add(user); } @Override @@ -400,8 +399,7 @@ public Category deleteCategoryById(int categoryId, int userId) throws Exception } } - Category deletedCategory = categoryRepository.delete(categoryId); - return deletedCategory; + return categoryRepository.delete(categoryId); } @Override 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 baa24372..a678e2b8 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 @@ -3,8 +3,6 @@ import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.JsonNode; import java.util.Date; @@ -25,7 +23,7 @@ public class Activity extends EntityBase { private AdditionalObject additionalObject; - protected Activity(Builder builder) { + private Activity(Builder builder) { this.id = builder.id; this.creationDate = builder.creationDate; this.activityAction = builder.activityAction; @@ -182,8 +180,7 @@ public Builder addititionalObject(AdditionalObject additionalObject) { } public Activity build() { - Activity created = new Activity(this); - return created; + return new Activity(this); } } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Attachment.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Attachment.java index 0449245f..64aafb5b 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Attachment.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Attachment.java @@ -151,7 +151,7 @@ public static class Builder { private String fileUrl; private Date creationDate; private Date lastUpdatedDate; - public User creator; + User creator; public Builder id(int id) { this.id = id; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Category.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Category.java index be9e44b3..33f55776 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Category.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Category.java @@ -158,7 +158,7 @@ public Boolean isFollower() { public static class Builder { - public User leader; + User leader; private int id; private String description; private String name; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/CategoryContributors.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/CategoryContributors.java index a1295a21..55646449 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/CategoryContributors.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/CategoryContributors.java @@ -103,8 +103,7 @@ public Builder attachmentCreator(List attachmentCreator) { } public CategoryContributors build() { - CategoryContributors created = new CategoryContributors(this); - return created; + return new CategoryContributors(this); } } } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/CategoryFollower.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/CategoryFollower.java index 9e466db9..f388a881 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/CategoryFollower.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/CategoryFollower.java @@ -5,7 +5,7 @@ public class CategoryFollower extends EntityBase { private final int CategoryId; private final int UserId; - public CategoryFollower(Builder builder) { + private CategoryFollower(Builder builder) { Id = builder.id; CategoryId = builder.categoryId; UserId = builder.userId; @@ -28,9 +28,9 @@ public static Builder getBuilder() { } public static class Builder { - public int userId; - public int categoryId; - public int id; + int userId; + int categoryId; + int id; public Builder userId(int userId) { this.userId = userId; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Comment.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Comment.java index 7a6639a1..74813768 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Comment.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Comment.java @@ -111,9 +111,9 @@ public static class Builder { private String message; private int requirementId; private Integer replyToComment; - public Date creationDate; - public Date lastUpdatedDate; - public User creator; + Date creationDate; + Date lastUpdatedDate; + User creator; public Builder(String message) { diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Email.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Email.java new file mode 100644 index 00000000..5731eaba --- /dev/null +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Email.java @@ -0,0 +1,135 @@ +package de.rwth.dbis.acis.bazaar.service.dal.entities; + + +import java.util.Date; +import java.util.Set; + +public class Email extends EntityBase { + + private final transient int id; + + private final Set recipients; + private final String subject; + private final String starting; + private final String message; + private final String closing; + private final String footer; + private final Date creationDate; + + protected Email(Builder builder) { + id = builder.id; + recipients = builder.recipients; + subject = builder.subject; + starting = builder.starting; + message = builder.message; + closing = builder.closing; + footer = builder.footer; + creationDate = builder.creationDate; + } + + public int getId() { + return id; + } + + public Set getRecipients() { + return recipients; + } + + public String getSubject() { + return subject; + } + + public String getStarting() { + return starting; + } + + public String getMessage() { + return message; + } + + public String getClosing() { + return closing; + } + + public String getFooter() { + return footer; + } + + public Date getCreationDate() { + return creationDate; + } + + public void removeRecipient(User user) { + recipients.remove(user); + } + + public static Activity.Builder getBuilder() { + return new Activity.Builder(); + } + + public static class Builder { + + private int id; + private Set recipients; + private String subject; + private String starting; + private String message; + private String closing; + private String footer; + private Date creationDate; + + public Builder() { + + } + + public Builder(Email email) { + this.recipients = email.recipients; + this.subject = email.subject; + this.starting = email.starting; + this.message = email.message; + this.closing = email.closing; + this.footer = email.footer; + this.creationDate = email.creationDate; + } + + public Builder recipients(Set recipients) { + this.recipients = recipients; + return this; + } + + public Builder subject(String subject) { + this.subject = subject; + return this; + } + + public Builder starting(String starting) { + this.starting = starting; + return this; + } + + public Builder message(String message) { + this.message = message; + return this; + } + + public Builder closing(String closing) { + this.closing = closing; + return this; + } + + public Builder footer(String footer) { + this.footer = footer; + return this; + } + + public Builder creationDate(Date creationDate) { + this.creationDate = creationDate; + return this; + } + + public Email build() { + Email created = new Email(this); + return created; + } + } +} diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Privilege.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Privilege.java index 8b7a5a98..bf09ebc6 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Privilege.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Privilege.java @@ -20,8 +20,6 @@ package de.rwth.dbis.acis.bazaar.service.dal.entities; -import jodd.vtor.constraint.Min; - /** * @author Adam Gavronek * @since 2/17/2015 @@ -32,7 +30,7 @@ public class Privilege extends EntityBase { private final PrivilegeEnum name; - public Privilege(Builder builder) { + private Privilege(Builder builder) { Id = builder.id; this.name = builder.name; } @@ -58,7 +56,6 @@ public Builder(PrivilegeEnum privilege) { this.name = privilege; } - public Builder id(int id) { this.id = id; return this; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/ProjectContributors.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/ProjectContributors.java index e66cc5d8..68a3489b 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/ProjectContributors.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/ProjectContributors.java @@ -115,8 +115,7 @@ public Builder attachmentCreator(List attachmentCreator) { } public ProjectContributors build() { - ProjectContributors created = new ProjectContributors(this); - return created; + return new ProjectContributors(this); } } } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/ProjectFollower.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/ProjectFollower.java index cb6dfc0a..d8afbb9a 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/ProjectFollower.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/ProjectFollower.java @@ -5,7 +5,7 @@ public class ProjectFollower extends EntityBase { private final int ProjectId; private final int UserId; - public ProjectFollower(Builder builder) { + private ProjectFollower(Builder builder) { Id = builder.id; ProjectId = builder.projectId; UserId = builder.userId; @@ -28,9 +28,9 @@ public static Builder getBuilder() { } public static class Builder { - public int userId; - public int projectId; - public int id; + int userId; + int projectId; + int id; public Builder userId(int userId) { this.userId = userId; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementCategory.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementCategory.java index f5c39211..3ec139d4 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementCategory.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementCategory.java @@ -30,7 +30,7 @@ public class RequirementCategory extends EntityBase { private final int categoryId; private final int requirementId; - public RequirementCategory(Builder builder) { + private RequirementCategory(Builder builder) { this.id = builder.id; this.categoryId = builder.categoryId; this.requirementId = builder.requirementId; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementContributors.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementContributors.java index e1c4145a..4743f00d 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementContributors.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementContributors.java @@ -95,8 +95,7 @@ public Builder attachmentCreator(List attachmentCreator) { } public RequirementContributors build() { - RequirementContributors created = new RequirementContributors(this); - return created; + return new RequirementContributors(this); } } } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementDeveloper.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementDeveloper.java index ab7bfdfa..19de9333 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementDeveloper.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementDeveloper.java @@ -29,7 +29,7 @@ public class RequirementDeveloper extends EntityBase { private final int RequirementId; private final int UserId; - public RequirementDeveloper(Builder builder) { + private RequirementDeveloper(Builder builder) { Id = builder.id; RequirementId = builder.requirementId; UserId = builder.userId; @@ -52,9 +52,9 @@ public static Builder getBuilder() { } public static class Builder { - public int userId; - public int requirementId; - public int id; + int userId; + int requirementId; + int id; public Builder userId(int userId) { this.userId = userId; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementFollower.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementFollower.java index 0c9bf3fc..0fc5f162 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementFollower.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/RequirementFollower.java @@ -29,7 +29,7 @@ public class RequirementFollower extends EntityBase { private final int RequirementId; private final int UserId; - public RequirementFollower(Builder builder) { + private RequirementFollower(Builder builder) { Id = builder.id; RequirementId = builder.requirementId; UserId = builder.userId; @@ -52,9 +52,9 @@ public static Builder getBuilder() { } public static class Builder { - public int userId; - public int requirementId; - public int id; + int userId; + int requirementId; + int id; public Builder userId(int userId) { this.userId = userId; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Role.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Role.java index 5afff2f4..1c97c8ce 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Role.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Role.java @@ -20,8 +20,6 @@ package de.rwth.dbis.acis.bazaar.service.dal.entities; -import jodd.vtor.constraint.Min; - import java.util.List; /** @@ -37,7 +35,7 @@ public class Role extends EntityBase { private final String name; - public Role(Builder builder) { + private Role(Builder builder) { Id = builder.id; this.privileges = builder.privileges; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Statistic.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Statistic.java index 89b1bb39..44c6409b 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Statistic.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Statistic.java @@ -122,8 +122,7 @@ public Builder numberOfVotes(int numberOfVotes) { } public Statistic build() { - Statistic created = new Statistic(this); - return created; + return new Statistic(this); } } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Vote.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Vote.java index 92d80670..f41a6b70 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Vote.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/entities/Vote.java @@ -31,7 +31,7 @@ public class Vote extends EntityBase { private final int RequirementId; private final int UserId; - public Vote(Builder builder) { + private Vote(Builder builder) { Id = builder.id; this.isUpvote = builder.isUpvote; RequirementId = builder.requirementId; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/helpers/PageInfo.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/helpers/PageInfo.java index cf8fd188..fcd0e0c0 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/helpers/PageInfo.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/helpers/PageInfo.java @@ -53,7 +53,7 @@ public PageInfo(int pageNumber, int pageSize, Map filters, List< this.pageSize = pageSize; this.filters = filters; this.sorts = sorts; - this.search = search != null ? search : new String(); + this.search = search != null ? search : ""; } @Override diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/AttachmentRepository.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/AttachmentRepository.java index d0557485..f40976c6 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/AttachmentRepository.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/AttachmentRepository.java @@ -25,8 +25,6 @@ import de.rwth.dbis.acis.bazaar.service.dal.helpers.PaginationResult; import de.rwth.dbis.acis.bazaar.service.exception.BazaarException; -import java.util.List; - public interface AttachmentRepository extends Repository { PaginationResult findAllByRequirementId(int requirementId, Pageable pageable) throws BazaarException; diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CategoryRepositoryImpl.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CategoryRepositoryImpl.java index a6584bc9..da73e701 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CategoryRepositoryImpl.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/CategoryRepositoryImpl.java @@ -22,7 +22,6 @@ import de.rwth.dbis.acis.bazaar.service.dal.entities.Category; import de.rwth.dbis.acis.bazaar.service.dal.entities.Statistic; -import de.rwth.dbis.acis.bazaar.service.dal.entities.User; import de.rwth.dbis.acis.bazaar.service.dal.helpers.Pageable; import de.rwth.dbis.acis.bazaar.service.dal.helpers.PaginationResult; import de.rwth.dbis.acis.bazaar.service.dal.jooq.tables.records.CategoryRecord; @@ -43,7 +42,6 @@ import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; -import java.util.Map; import static de.rwth.dbis.acis.bazaar.service.dal.jooq.Tables.*; 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 6f09894a..ac164d23 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 @@ -25,8 +25,6 @@ import de.rwth.dbis.acis.bazaar.service.dal.helpers.PaginationResult; import de.rwth.dbis.acis.bazaar.service.exception.BazaarException; -import java.util.List; - /** * @author Adam Gavronek * @since 6/22/2014 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 d1c0b6f2..aee8ba80 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 @@ -22,7 +22,6 @@ import de.rwth.dbis.acis.bazaar.service.dal.entities.Project; import de.rwth.dbis.acis.bazaar.service.dal.entities.Statistic; -import de.rwth.dbis.acis.bazaar.service.dal.entities.User; import de.rwth.dbis.acis.bazaar.service.dal.helpers.PageInfo; import de.rwth.dbis.acis.bazaar.service.dal.helpers.Pageable; import de.rwth.dbis.acis.bazaar.service.dal.helpers.PaginationResult; @@ -43,7 +42,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import static de.rwth.dbis.acis.bazaar.service.dal.jooq.Tables.*; @@ -250,7 +248,8 @@ public PaginationResult findAllPublicAndAuthorized(PageInfo pageable, i // .leftOuterJoin(AUTHORIZATIONS).on(AUTHORIZATIONS.PROJECT_ID.equal(PROJECTS.ID)) // .join(USERS).on(AUTHORIZATIONS.USER_ID.equal(USERS.ID)) // .where(PROJECTS.VISIBILITY.eq(Project.ProjectVisibility.PUBLIC.asChar()) - .where(transformer.getSearchCondition(pageable.getSearch())) + .where(PROJECT.VISIBILITY.isTrue().or(leaderUser.ID.equal(userId)) + .and(transformer.getSearchCondition(pageable.getSearch()))) .orderBy(transformer.getSortFields(pageable.getSorts())) .limit(pageable.getPageSize()) .offset(pageable.getOffset()) diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/RepositoryImpl.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/RepositoryImpl.java index 6d6286b1..554c2444 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/RepositoryImpl.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/RepositoryImpl.java @@ -103,7 +103,7 @@ public E delete(int id) throws Exception { public List findAll() throws BazaarException { List entries = null; try { - entries = new ArrayList(); + entries = new ArrayList<>(); List queryResults = jooq.selectFrom(transformer.getTable()).fetchInto(transformer.getRecordClass()); @@ -122,7 +122,7 @@ public List findAll() throws BazaarException { public List findAll(Pageable pageable) throws BazaarException { List entries = null; try { - entries = new ArrayList(); + entries = new ArrayList<>(); List queryResults = jooq.selectFrom(transformer.getTable()) .orderBy(transformer.getSortFields(pageable.getSorts())) @@ -145,7 +145,7 @@ public List findAll(Pageable pageable) throws BazaarException { public List searchAll(String searchTerm, Pageable pageable) throws Exception { List entries = null; try { - entries = new ArrayList(); + entries = new ArrayList<>(); String likeExpression = "%" + searchTerm + "%"; List queryResults = jooq.selectFrom(transformer.getTable()) diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/RequirementRepositoryImpl.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/RequirementRepositoryImpl.java index 4a90db26..f21c8b73 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/RequirementRepositoryImpl.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/RequirementRepositoryImpl.java @@ -24,9 +24,7 @@ import de.rwth.dbis.acis.bazaar.service.dal.helpers.Pageable; import de.rwth.dbis.acis.bazaar.service.dal.helpers.PaginationResult; import de.rwth.dbis.acis.bazaar.service.dal.helpers.UserVote; -import de.rwth.dbis.acis.bazaar.service.dal.jooq.tables.records.AttachmentRecord; import de.rwth.dbis.acis.bazaar.service.dal.jooq.tables.records.RequirementRecord; -import de.rwth.dbis.acis.bazaar.service.dal.transform.AttachmentTransformer; import de.rwth.dbis.acis.bazaar.service.dal.transform.RequirementTransformer; import de.rwth.dbis.acis.bazaar.service.dal.transform.UserTransformer; import de.rwth.dbis.acis.bazaar.service.exception.BazaarException; @@ -344,7 +342,7 @@ public Requirement findById(int id, int userId) throws Exception { if (userId != 1) { requirement.setFollower((Integer) queryResult.getValues(isFollower).get(0) == 0 ? false : true); requirement.setDeveloper((Integer) queryResult.getValues(isDeveloper).get(0) == 0 ? false : true); - requirement.setContributor(((BigDecimal) queryResult.getValues(isContributor).get(0)).equals(new BigDecimal(0)) ? false : true); + requirement.setContributor(queryResult.getValues(isContributor).get(0).equals(new BigDecimal(0)) ? false : true); } } catch (BazaarException be) { diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/UserRepositoryImpl.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/UserRepositoryImpl.java index 88d41244..67ac36cd 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/UserRepositoryImpl.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/repositories/UserRepositoryImpl.java @@ -49,7 +49,7 @@ * @since 6/23/2014 */ public class UserRepositoryImpl extends RepositoryImpl implements UserRepository { - final byte ONE = 1; + private final byte ONE = 1; /** * @param jooq DSLContext for JOOQ connection diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/AttachmentTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/AttachmentTransformer.java index 5201118a..2dd5dd4c 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/AttachmentTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/AttachmentTransformer.java @@ -52,7 +52,7 @@ public AttachmentRecord createRecord(Attachment entity) { @Override public Attachment getEntityFromTableRecord(AttachmentRecord record) { - Attachment entity = Attachment.getBuilder() + return Attachment.getBuilder() .id(record.getId()) .requirementId(record.getRequirementId()) .name(record.getName()) @@ -63,7 +63,6 @@ public Attachment getEntityFromTableRecord(AttachmentRecord record) { .creationDate(record.getCreationDate()) .lastUpdatedDate(record.getLastUpdatedDate()) .build(); - return entity; } @Override @@ -94,7 +93,7 @@ public Map getUpdateMap(final Attachment entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(ATTACHMENT.CREATION_DATE.asc()); + return Collections.singletonList(ATTACHMENT.CREATION_DATE.asc()); } return null; } @@ -109,7 +108,7 @@ public Collection getFilterConditions(Map f return new ArrayList<>(); } - public Attachment cleanEntry(Attachment attachment) { + private Attachment cleanEntry(Attachment attachment) { if (attachment.getName() != null) { attachment.setName(EmojiParser.parseToAliases(attachment.getName())); } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CategoryFollowerTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CategoryFollowerTransformer.java index aa657465..4315be8d 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CategoryFollowerTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CategoryFollowerTransformer.java @@ -53,7 +53,7 @@ public Map getUpdateMap(final CategoryFollower entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(CATEGORY_FOLLOWER_MAP.ID.asc()); + return Collections.singletonList(CATEGORY_FOLLOWER_MAP.ID.asc()); } return null; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CategoryTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CategoryTransformer.java index 12c316e8..f290bfa9 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CategoryTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/CategoryTransformer.java @@ -100,71 +100,76 @@ public Map getUpdateMap(final Category entry) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(CATEGORY.NAME.asc()); + return Collections.singletonList(CATEGORY.NAME.asc()); } List> sortFields = new ArrayList<>(); for (Pageable.SortField sort : sorts) { - if (sort.getField().equals("name")) { - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(CATEGORY.NAME.asc()); - break; - case DESC: - sortFields.add(CATEGORY.NAME.desc()); - break; - default: - sortFields.add(CATEGORY.NAME.asc()); - break; - } - } else if (sort.getField().equals("date")) { - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(CATEGORY.CREATION_DATE.asc()); - break; - case DESC: - sortFields.add(CATEGORY.CREATION_DATE.desc()); - break; - default: - sortFields.add(CATEGORY.CREATION_DATE.desc()); - break; - } - } else if (sort.getField().equals("requirement")) { - - Field requirementCount = DSL.select(DSL.count()) - .from(Requirement.REQUIREMENT) - .leftJoin(RequirementCategoryMap.REQUIREMENT_CATEGORY_MAP).on(Requirement.REQUIREMENT.ID.equal(RequirementCategoryMap.REQUIREMENT_CATEGORY_MAP.REQUIREMENT_ID)) - .where(RequirementCategoryMap.REQUIREMENT_CATEGORY_MAP.CATEGORY_ID.equal(CATEGORY.ID)) - .asField("requirementCount"); - - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(requirementCount.asc()); - break; - case DESC: - sortFields.add(requirementCount.desc()); - break; - default: - sortFields.add(requirementCount.desc()); - break; - } - } else if (sort.getField().equals("follower")) { - - Field followerCount = DSL.select(DSL.count()) - .from(CategoryFollowerMap.CATEGORY_FOLLOWER_MAP) - .where(CategoryFollowerMap.CATEGORY_FOLLOWER_MAP.CATEGORY_ID.equal(CATEGORY.ID)) - .asField("followerCount"); - - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(followerCount.asc()); - break; - case DESC: - sortFields.add(followerCount.desc()); - break; - default: - sortFields.add(followerCount.desc()); - break; - } + switch (sort.getField()) { + case "name": + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(CATEGORY.NAME.asc()); + break; + case DESC: + sortFields.add(CATEGORY.NAME.desc()); + break; + default: + sortFields.add(CATEGORY.NAME.asc()); + break; + } + break; + case "date": + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(CATEGORY.CREATION_DATE.asc()); + break; + case DESC: + sortFields.add(CATEGORY.CREATION_DATE.desc()); + break; + default: + sortFields.add(CATEGORY.CREATION_DATE.desc()); + break; + } + break; + case "requirement": + + Field requirementCount = DSL.select(DSL.count()) + .from(Requirement.REQUIREMENT) + .leftJoin(RequirementCategoryMap.REQUIREMENT_CATEGORY_MAP).on(Requirement.REQUIREMENT.ID.equal(RequirementCategoryMap.REQUIREMENT_CATEGORY_MAP.REQUIREMENT_ID)) + .where(RequirementCategoryMap.REQUIREMENT_CATEGORY_MAP.CATEGORY_ID.equal(CATEGORY.ID)) + .asField("requirementCount"); + + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(requirementCount.asc()); + break; + case DESC: + sortFields.add(requirementCount.desc()); + break; + default: + sortFields.add(requirementCount.desc()); + break; + } + break; + case "follower": + + Field followerCount = DSL.select(DSL.count()) + .from(CategoryFollowerMap.CATEGORY_FOLLOWER_MAP) + .where(CategoryFollowerMap.CATEGORY_FOLLOWER_MAP.CATEGORY_ID.equal(CATEGORY.ID)) + .asField("followerCount"); + + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(followerCount.asc()); + break; + case DESC: + sortFields.add(followerCount.desc()); + break; + default: + sortFields.add(followerCount.desc()); + break; + } + break; } } return sortFields; @@ -181,7 +186,7 @@ public Collection getFilterConditions(Map f return new ArrayList<>(); } - public Category cleanEntry(Category category) { + private Category cleanEntry(Category category) { if (category.getName() != null) { category.setName(EmojiParser.parseToAliases(category.getName())); } 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 ecde5251..51c07244 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 @@ -90,7 +90,7 @@ public Map getUpdateMap(final Comment entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(COMMENT.CREATION_DATE.asc()); + return Collections.singletonList(COMMENT.CREATION_DATE.asc()); } return null; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/PrivilegeTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/PrivilegeTransformer.java index 811b8881..5596213b 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/PrivilegeTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/PrivilegeTransformer.java @@ -75,7 +75,7 @@ public Map getUpdateMap(final Privilege entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(ROLE.ID.asc()); + return Collections.singletonList(ROLE.ID.asc()); } return null; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/ProjectFollowerTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/ProjectFollowerTransformer.java index dede3f53..c0bb5a68 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/ProjectFollowerTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/ProjectFollowerTransformer.java @@ -54,7 +54,7 @@ public Map getUpdateMap(final ProjectFollower entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(PROJECT_FOLLOWER_MAP.ID.asc()); + return Collections.singletonList(PROJECT_FOLLOWER_MAP.ID.asc()); } return null; } 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 353538a1..b6b88e97 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 @@ -43,7 +43,7 @@ public ProjectRecord createRecord(Project entry) { record.setDescription(entry.getDescription()); record.setName(entry.getName()); record.setLeaderId(entry.getLeader().getId()); - record.setVisibility((byte) (entry.getVisibility() == true ? 1 : 0 )); + record.setVisibility((byte) (entry.getVisibility() ? 1 : 0 )); record.setDefaultCategoryId(entry.getDefaultCategoryId()); record.setCreationDate(new java.sql.Timestamp(Calendar.getInstance().getTime().getTime())); return record; @@ -104,70 +104,75 @@ public Map getUpdateMap(final Project entry) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(PROJECT.NAME.asc()); + return Collections.singletonList(PROJECT.NAME.asc()); } List> sortFields = new ArrayList<>(); for (Pageable.SortField sort : sorts) { - if (sort.getField().equals("name")) { - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(PROJECT.NAME.asc()); - break; - case DESC: - sortFields.add(PROJECT.NAME.desc()); - break; - default: - sortFields.add(PROJECT.NAME.asc()); - break; - } - } else if (sort.getField().equals("date")) { - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(PROJECT.CREATION_DATE.asc()); - break; - case DESC: - sortFields.add(PROJECT.CREATION_DATE.desc()); - break; - default: - sortFields.add(PROJECT.CREATION_DATE.desc()); - break; - } - } else if (sort.getField().equals("requirement")) { - - Field requirementCount = DSL.select(DSL.count()) - .from(REQUIREMENT) - .where(REQUIREMENT.PROJECT_ID.equal(PROJECT.ID)) - .asField("requirementCount"); - - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(requirementCount.asc()); - break; - case DESC: - sortFields.add(requirementCount.desc()); - break; - default: - sortFields.add(requirementCount.desc()); - break; - } - } else if (sort.getField().equals("follower")) { - - Field followerCount = DSL.select(DSL.count()) - .from(PROJECT_FOLLOWER_MAP) - .where(PROJECT_FOLLOWER_MAP.PROJECT_ID.equal(PROJECT.ID)) - .asField("followerCount"); - - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(followerCount.asc()); - break; - case DESC: - sortFields.add(followerCount.desc()); - break; - default: - sortFields.add(followerCount.desc()); - break; - } + switch (sort.getField()) { + case "name": + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(PROJECT.NAME.asc()); + break; + case DESC: + sortFields.add(PROJECT.NAME.desc()); + break; + default: + sortFields.add(PROJECT.NAME.asc()); + break; + } + break; + case "date": + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(PROJECT.CREATION_DATE.asc()); + break; + case DESC: + sortFields.add(PROJECT.CREATION_DATE.desc()); + break; + default: + sortFields.add(PROJECT.CREATION_DATE.desc()); + break; + } + break; + case "requirement": + + Field requirementCount = DSL.select(DSL.count()) + .from(REQUIREMENT) + .where(REQUIREMENT.PROJECT_ID.equal(PROJECT.ID)) + .asField("requirementCount"); + + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(requirementCount.asc()); + break; + case DESC: + sortFields.add(requirementCount.desc()); + break; + default: + sortFields.add(requirementCount.desc()); + break; + } + break; + case "follower": + + Field followerCount = DSL.select(DSL.count()) + .from(PROJECT_FOLLOWER_MAP) + .where(PROJECT_FOLLOWER_MAP.PROJECT_ID.equal(PROJECT.ID)) + .asField("followerCount"); + + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(followerCount.asc()); + break; + case DESC: + sortFields.add(followerCount.desc()); + break; + default: + sortFields.add(followerCount.desc()); + break; + } + break; } } return sortFields; @@ -184,7 +189,7 @@ public Collection getFilterConditions(Map f return new ArrayList<>(); } - public Project cleanEntry(Project project) { + private Project cleanEntry(Project project) { if (project.getName() != null) { project.setName(EmojiParser.parseToAliases(project.getName())); } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementCategoryTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementCategoryTransformer.java index dadb276f..a30b9d46 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementCategoryTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementCategoryTransformer.java @@ -76,7 +76,7 @@ public Map getUpdateMap(final RequirementCategory entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(REQUIREMENT_CATEGORY_MAP.ID.asc()); + return Collections.singletonList(REQUIREMENT_CATEGORY_MAP.ID.asc()); } return null; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementDeveloperTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementDeveloperTransformer.java index a55f2486..c28ce74a 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementDeveloperTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementDeveloperTransformer.java @@ -77,7 +77,7 @@ public Map getUpdateMap(final RequirementDeveloper entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(REQUIREMENT_DEVELOPER_MAP.ID.asc()); + return Collections.singletonList(REQUIREMENT_DEVELOPER_MAP.ID.asc()); } return null; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementFollowerTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementFollowerTransformer.java index 1bebd074..68057046 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementFollowerTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RequirementFollowerTransformer.java @@ -77,7 +77,7 @@ public Map getUpdateMap(final RequirementFollower entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(REQUIREMENT_FOLLOWER_MAP.ID.asc()); + return Collections.singletonList(REQUIREMENT_FOLLOWER_MAP.ID.asc()); } return null; } 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 3abd5176..db6bba50 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 @@ -95,100 +95,107 @@ public Map getUpdateMap(final Requirement entry) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(REQUIREMENT.CREATION_DATE.desc()); + return Collections.singletonList(REQUIREMENT.CREATION_DATE.desc()); } List> sortFields = new ArrayList<>(); for (Pageable.SortField sort : sorts) { - if (sort.getField().equals("date")) { - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(REQUIREMENT.CREATION_DATE.asc()); - break; - case DESC: - sortFields.add(REQUIREMENT.CREATION_DATE.desc()); - break; - default: - sortFields.add(REQUIREMENT.CREATION_DATE.desc()); - break; - } - } else if (sort.getField().equals("name")) { - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(REQUIREMENT.NAME.asc()); - break; - case DESC: - sortFields.add(REQUIREMENT.NAME.desc()); - break; - default: - sortFields.add(REQUIREMENT.NAME.asc()); - break; - } - } else if (sort.getField().equals("vote")) { - - Field voteCount = DSL.select(DSL.count(DSL.nullif(VOTE.IS_UPVOTE, 0))) - .from(VOTE) - .where(VOTE.REQUIREMENT_ID.equal(REQUIREMENT.ID)) - .asField("voteCount"); - - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(voteCount.asc()); - break; - case DESC: - sortFields.add(voteCount.desc()); - break; - default: - sortFields.add(voteCount.desc()); - break; - } - } else if (sort.getField().equals("comment")) { - - Field commentCount = DSL.select(DSL.count()) - .from(COMMENT) - .where(COMMENT.REQUIREMENT_ID.equal(REQUIREMENT.ID)) - .asField("commentCount"); - - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(commentCount.asc()); - break; - case DESC: - sortFields.add(commentCount.desc()); - break; - default: - sortFields.add(commentCount.desc()); - break; - } - } else if (sort.getField().equals("follower")) { - - Field followerCount = DSL.select(DSL.count()) - .from(REQUIREMENT_FOLLOWER_MAP) - .where(REQUIREMENT_FOLLOWER_MAP.REQUIREMENT_ID.equal(REQUIREMENT.ID)) - .asField("followerCount"); - - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(followerCount.asc()); - break; - case DESC: - sortFields.add(followerCount.desc()); - break; - default: - sortFields.add(followerCount.desc()); - break; - } - } else if (sort.getField().equals("realized")) { - switch (sort.getSortDirection()) { - case ASC: - sortFields.add(REQUIREMENT.REALIZED.asc()); - break; - case DESC: - sortFields.add(REQUIREMENT.REALIZED.desc()); - break; - default: - sortFields.add(REQUIREMENT.REALIZED.desc()); - break; - } + switch (sort.getField()) { + case "date": + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(REQUIREMENT.CREATION_DATE.asc()); + break; + case DESC: + sortFields.add(REQUIREMENT.CREATION_DATE.desc()); + break; + default: + sortFields.add(REQUIREMENT.CREATION_DATE.desc()); + break; + } + break; + case "name": + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(REQUIREMENT.NAME.asc()); + break; + case DESC: + sortFields.add(REQUIREMENT.NAME.desc()); + break; + default: + sortFields.add(REQUIREMENT.NAME.asc()); + break; + } + break; + case "vote": + + Field voteCount = DSL.select(DSL.count(DSL.nullif(VOTE.IS_UPVOTE, 0))) + .from(VOTE) + .where(VOTE.REQUIREMENT_ID.equal(REQUIREMENT.ID)) + .asField("voteCount"); + + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(voteCount.asc()); + break; + case DESC: + sortFields.add(voteCount.desc()); + break; + default: + sortFields.add(voteCount.desc()); + break; + } + break; + case "comment": + + Field commentCount = DSL.select(DSL.count()) + .from(COMMENT) + .where(COMMENT.REQUIREMENT_ID.equal(REQUIREMENT.ID)) + .asField("commentCount"); + + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(commentCount.asc()); + break; + case DESC: + sortFields.add(commentCount.desc()); + break; + default: + sortFields.add(commentCount.desc()); + break; + } + break; + case "follower": + + Field followerCount = DSL.select(DSL.count()) + .from(REQUIREMENT_FOLLOWER_MAP) + .where(REQUIREMENT_FOLLOWER_MAP.REQUIREMENT_ID.equal(REQUIREMENT.ID)) + .asField("followerCount"); + + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(followerCount.asc()); + break; + case DESC: + sortFields.add(followerCount.desc()); + break; + default: + sortFields.add(followerCount.desc()); + break; + } + break; + case "realized": + switch (sort.getSortDirection()) { + case ASC: + sortFields.add(REQUIREMENT.REALIZED.asc()); + break; + case DESC: + sortFields.add(REQUIREMENT.REALIZED.desc()); + break; + default: + sortFields.add(REQUIREMENT.REALIZED.desc()); + break; + } + break; } } return sortFields; @@ -216,7 +223,7 @@ public Collection getFilterConditions(Map f return conditions; } - public Requirement cleanEntity(Requirement requirement) { + private Requirement cleanEntity(Requirement requirement) { if (requirement.getName() != null) { requirement.setName(EmojiParser.parseToAliases(requirement.getName())); } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RoleTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RoleTransformer.java index 8b9ef0a0..0aeb9a01 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RoleTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/RoleTransformer.java @@ -75,7 +75,7 @@ public Map getUpdateMap(final Role entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(ROLE.ID.asc()); + return Collections.singletonList(ROLE.ID.asc()); } return null; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/UserTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/UserTransformer.java index 74adb0e5..2a868282 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/UserTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/UserTransformer.java @@ -48,7 +48,7 @@ public UserRecord createRecord(User entity) { @Override public User getEntityFromTableRecord(UserRecord record) { - User user = User.geBuilder(record.getEmail()) + return User.geBuilder(record.getEmail()) .id(record.getId()) .admin(record.getAdmin() != 0) .firstName(record.getFirstName()) @@ -62,7 +62,6 @@ public User getEntityFromTableRecord(UserRecord record) { .lastUpdatedDate(record.getLastUpdatedDate()) .lastLoginDate(record.getLastLoginDate()) .build(); - return user; } public User getEntityFromQueryResult(de.rwth.dbis.acis.bazaar.service.dal.jooq.tables.User user, Result queryResult) { @@ -128,7 +127,7 @@ public Map getUpdateMap(final User entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(USER.USER_NAME.asc()); + return Collections.singletonList(USER.USER_NAME.asc()); } return null; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/VoteTransformer.java b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/VoteTransformer.java index e9205447..d2777ec7 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/VoteTransformer.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/dal/transform/VoteTransformer.java @@ -80,7 +80,7 @@ public Map getUpdateMap(final Vote entity) { @Override public Collection> getSortFields(List sorts) { if (sorts.isEmpty()) { - return Arrays.asList(VOTE.ID.asc()); + return Collections.singletonList(VOTE.ID.asc()); } return null; } diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/exception/ExceptionHandler.java b/src/main/de/rwth/dbis/acis/bazaar/service/exception/ExceptionHandler.java index 57a88444..676b69bf 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/exception/ExceptionHandler.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/exception/ExceptionHandler.java @@ -21,7 +21,6 @@ package de.rwth.dbis.acis.bazaar.service.exception; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import de.rwth.dbis.acis.bazaar.service.internalization.Localization; 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 16640aae..4851797a 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 @@ -11,7 +11,6 @@ import de.rwth.dbis.acis.bazaar.service.exception.ErrorCode; import de.rwth.dbis.acis.bazaar.service.exception.ExceptionHandler; import de.rwth.dbis.acis.bazaar.service.exception.ExceptionLocation; -import i5.las2peer.api.Service; import i5.las2peer.logging.L2pLogger; @@ -49,9 +48,9 @@ public void sendActivityOverRMI(Date creationDate, Activity.ActivityAction activ activityBuilder = activityBuilder.creationDate(creationDate); activityBuilder = activityBuilder.activityAction(activityAction); - String resourcePath = new String(); + String resourcePath = ""; String parentResourcePath = null; - String frontendResourcePath = new String(); + String frontendResourcePath = ""; int parentDataId = 0; Activity.DataType parentDataTyp = null; @@ -121,8 +120,8 @@ public void sendActivityOverRMI(Date creationDate, Activity.ActivityAction activ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setFilters(filters); - Object result = bazaarService.getContext().invoke(activityTrackerService, "createActivity", new Serializable[]{mapper.writeValueAsString(activity)}); - if (!(result).equals(new Integer(Response.Status.CREATED.getStatusCode()).toString())) { + Object result = bazaarService.getContext().invoke(activityTrackerService, "createActivity", mapper.writeValueAsString(activity)); + if (!(result).equals(Integer.toString(Response.Status.CREATED.getStatusCode()))) { ExceptionHandler.getInstance().throwException(ExceptionLocation.NETWORK, ErrorCode.RMI_ERROR, "ActivityTracker RMI call failed"); } } catch (Exception ex) { diff --git a/src/main/de/rwth/dbis/acis/bazaar/service/notification/EmailDispatcher.java b/src/main/de/rwth/dbis/acis/bazaar/service/notification/EmailDispatcher.java index d192d96a..801dd86b 100644 --- a/src/main/de/rwth/dbis/acis/bazaar/service/notification/EmailDispatcher.java +++ b/src/main/de/rwth/dbis/acis/bazaar/service/notification/EmailDispatcher.java @@ -4,32 +4,42 @@ import de.rwth.dbis.acis.bazaar.service.dal.DALFacade; import de.rwth.dbis.acis.bazaar.service.dal.entities.*; import de.rwth.dbis.acis.bazaar.service.internalization.Localization; +import i5.las2peer.logging.L2pLogger; import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * Created by martin on 15.02.2016. */ public class EmailDispatcher { + private final L2pLogger logger = L2pLogger.getInstance(EmailDispatcher.class.getName()); private String smtpServer; private String emailFromAddress; private BazaarService bazaarService; private String frontendBaseURL; + private String emailSummaryTimePeriodInMinutes; + private Map> notificationSummery; - public EmailDispatcher(BazaarService bazaarService, String smtpServer, String emailFromAddress, String frontendBaseURL) throws Exception { + private ExecutorService executorService = Executors.newCachedThreadPool(); + + public EmailDispatcher(BazaarService bazaarService, String smtpServer, String emailFromAddress, String frontendBaseURL, String emailSummaryTimePeriodInMinutes) throws Exception { this.smtpServer = smtpServer; this.emailFromAddress = emailFromAddress; this.bazaarService = bazaarService; this.frontendBaseURL = frontendBaseURL; + this.notificationSummery = new LinkedHashMap<>(); + this.emailSummaryTimePeriodInMinutes = emailSummaryTimePeriodInMinutes; } - public void sendEmailNotification(Date creationDate, Activity.ActivityAction activityAction, - int dataId, Activity.DataType dataType, int userId) { - DALFacade dalFacade = null; + public void addEmailNotification(Date creationDate, Activity.ActivityAction activityAction, + int dataId, Activity.DataType dataType, int userId, Activity.AdditionalObject additionalObject) { + DALFacade dalFacade; try { dalFacade = bazaarService.getDBConnection(); @@ -47,106 +57,228 @@ public void sendEmailNotification(Date creationDate, Activity.ActivityAction act int requirementId = dalFacade.getAttachmentById(dataId).getRequirementId(); recipients = dalFacade.getRecipientListForRequirement(requirementId); } - // delete the user who created the activity - Iterator recipientsIterator = recipients.iterator(); + + Email email = generateEmail(recipients, creationDate, activityAction, dataId, dataType, additionalObject); + + Iterator recipientsIterator = email.getRecipients().iterator(); while (recipientsIterator.hasNext()) { User recipient = recipientsIterator.next(); if (recipient.getId() == userId) { + // delete the user who created the activity recipientsIterator.remove(); + email.removeRecipient(recipient); + } else if (!notificationSummery.containsKey(recipient.getId()) && !emailSummaryTimePeriodInMinutes.isEmpty()) { + // if user has no notificationsummery: create one + notificationSummery.put(recipient.getId(), new ArrayList<>()); + } else if (!emailSummaryTimePeriodInMinutes.isEmpty()) { + //if user has notificationsummery, add this email to it and remove from recipient + notificationSummery.get(recipient.getId()).add(new Email.Builder(email).recipients(new HashSet<>(Arrays.asList(recipient))).build()); + recipientsIterator.remove(); + email.removeRecipient(recipient); } } - if (!recipients.isEmpty()) { - // generate mail + if (!email.getRecipients().isEmpty()) { + sendEmail(email); + } + } catch (Exception ex) { + logger.warning(ex.getMessage()); + } + } + + private Email generateEmail(List recipients, Date creationDate, Activity.ActivityAction activityAction, + int dataId, Activity.DataType dataType, Activity.AdditionalObject additionalObject) throws Exception { + DALFacade dalFacade = bazaarService.getDBConnection(); + String subject = new String(); + String bodyText = new String(); + String objectName; + String resourcePath = new String(); + String activity = new String(); + if (activityAction == Activity.ActivityAction.CREATE) { + activity = Localization.getInstance().getResourceBundle().getString("email.bodyText.created"); + subject = Localization.getInstance().getResourceBundle().getString("email.subject.New"); + } else if (activityAction == Activity.ActivityAction.UPDATE) { + activity = Localization.getInstance().getResourceBundle().getString("email.bodyText.updated"); + subject = Localization.getInstance().getResourceBundle().getString("email.subject.updated"); + } else if (activityAction == Activity.ActivityAction.REALIZE) { + activity = Localization.getInstance().getResourceBundle().getString("email.bodyText.realized"); + subject = Localization.getInstance().getResourceBundle().getString("email.subject.realized"); + } + + if (dataType == Activity.DataType.PROJECT) { + Project project = additionalObject.getProject(); + objectName = project.getName(); + resourcePath = "projects" + "/" + String.valueOf(dataId); + subject = subject.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.project") + ": " + (objectName.length() > 40 ? objectName.substring(0, 39) : objectName)); + bodyText = bodyText.concat(Localization.getInstance().getResourceBundle().getString("email.bodyText.user") + " " + additionalObject.getUser().getUserName()); + bodyText = bodyText.concat(" " + activity); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.project") + " \"" + objectName + "\""); + bodyText = bodyText.concat("\r\n" + Localization.getInstance().getResourceBundle().getString("email.bodyText.with")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.description") + " \"" + project.getDescription() + "\"."); + } else if (dataType == Activity.DataType.CATEGORY) { + Category category = additionalObject.getCategory(); + objectName = category.getName(); + resourcePath = "projects" + "/" + category.getProjectId() + "/" + "categories" + "/" + String.valueOf(dataId); + subject = subject.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.category") + ": " + (objectName.length() > 40 ? objectName.substring(0, 39) : objectName)); + bodyText = bodyText.concat(Localization.getInstance().getResourceBundle().getString("email.bodyText.user") + " " + additionalObject.getUser().getUserName()); + bodyText = bodyText.concat(" " + activity); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.category") + " \"" + objectName + "\""); + bodyText = bodyText.concat("\r\n" + Localization.getInstance().getResourceBundle().getString("email.bodyText.in")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.project") + " \"" + additionalObject.getProject().getName() + "\""); + bodyText = bodyText.concat("\r\n" + Localization.getInstance().getResourceBundle().getString("email.bodyText.with")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.description") + " \"" + category.getDescription() + "\"."); + } else if (dataType == Activity.DataType.REQUIREMENT) { + Requirement requirement = additionalObject.getRequirement(); + objectName = requirement.getName(); + resourcePath = "projects" + "/" + requirement.getProjectId() + "/" + "categories" + "/" + + requirement.getCategories().get(0).getId() + "/" + "requirements" + "/" + String.valueOf(dataId); + subject = subject.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement") + ": " + (objectName.length() > 40 ? objectName.substring(0, 39) : objectName)); + bodyText = bodyText.concat(Localization.getInstance().getResourceBundle().getString("email.bodyText.user") + " " + additionalObject.getUser().getUserName()); + bodyText = bodyText.concat(" " + activity); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement") + " \"" + objectName + "\""); + bodyText = bodyText.concat("\r\n" + Localization.getInstance().getResourceBundle().getString("email.bodyText.in")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.category") + " \"" + additionalObject.getCategory().getName() + "\""); + bodyText = bodyText.concat("\r\n" + Localization.getInstance().getResourceBundle().getString("email.bodyText.with")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.description") + " \"" + requirement.getDescription() + "\"."); + } else if (dataType == Activity.DataType.COMMENT) { + Comment comment = dalFacade.getCommentById(dataId); + Requirement requirement = additionalObject.getRequirement(); + objectName = requirement.getName(); + resourcePath = "projects" + "/" + requirement.getProjectId() + "/" + "categories" + "/" + + requirement.getCategories().get(0).getId() + "/" + "requirements" + "/" + String.valueOf(requirement.getId()); + subject = subject.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.comment") + " " + + Localization.getInstance().getResourceBundle().getString("email.bodyText.for") + " " + + Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement") + ": " + (objectName.length() > 40 ? objectName.substring(0, 39) : objectName)); + bodyText = bodyText.concat(Localization.getInstance().getResourceBundle().getString("email.bodyText.user") + " " + additionalObject.getUser().getUserName()); + bodyText = bodyText.concat(" " + activity + " " + Localization.getInstance().getResourceBundle().getString("email.bodyText.comment") + " \"" + comment.getMessage() + "\""); + bodyText = bodyText.concat("\r\n" + Localization.getInstance().getResourceBundle().getString("email.bodyText.for")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement") + " \"" + objectName + "\"."); + } else if (dataType == Activity.DataType.ATTACHMENT) { + Attachment attachment = dalFacade.getAttachmentById(dataId); + Requirement requirement = additionalObject.getRequirement(); + objectName = requirement.getName(); + resourcePath = "projects" + "/" + requirement.getProjectId() + "/" + "categories" + "/" + + requirement.getCategories().get(0).getId() + "/" + "requirements" + "/" + String.valueOf(requirement.getId()); + subject = subject.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.attachment") + " " + + Localization.getInstance().getResourceBundle().getString("email.bodyText.for") + " " + + Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement") + ": " + (objectName.length() > 40 ? objectName.substring(0, 39) : objectName)); + bodyText = bodyText.concat(Localization.getInstance().getResourceBundle().getString("email.bodyText.user") + " " + additionalObject.getUser().getUserName()); + bodyText = bodyText.concat(" " + activity); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.the")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.attachment") + " \"" + attachment.getName() + "\""); + bodyText = bodyText.concat("\r\n" + Localization.getInstance().getResourceBundle().getString("email.bodyText.for")); + bodyText = bodyText.concat(" " + Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement") + " \"" + objectName + "\"."); + } + String dataUrl = frontendBaseURL.concat(resourcePath); + + String greeting = Localization.getInstance().getResourceBundle().getString("email.bodyText.greeting"); + String news = Localization.getInstance().getResourceBundle().getString("email.bodyText.news"); + String closing = String.format(Localization.getInstance().getResourceBundle().getString("email.bodyText.nextSummary"), emailSummaryTimePeriodInMinutes) + "\r\n\r\n" + + Localization.getInstance().getResourceBundle().getString("email.bodyText.bestWishes"); + String footer = Localization.getInstance().getResourceBundle().getString("email.bodyText.footer"); + + Email.Builder emailBuilder = new Email.Builder(); + emailBuilder.recipients(new HashSet<>(recipients)); + emailBuilder.subject(subject); + emailBuilder.starting(greeting + "\r\n\r\n" + news); + emailBuilder.message(bodyText + "\r\n" + Localization.getInstance().getResourceBundle().getString("email.bodyText.forDetails") + " " + dataUrl); + emailBuilder.closing(closing); + emailBuilder.footer(footer); + emailBuilder.creationDate(creationDate); + Email email = emailBuilder.build(); + + return email; + } + + public void emptyNotificationSummery() { + DALFacade dalFacade; + try { + dalFacade = bazaarService.getDBConnection(); + Iterator notificationSummeryIterator = notificationSummery.entrySet().iterator(); + while (notificationSummeryIterator.hasNext()) { + Map.Entry pair = (Map.Entry) notificationSummeryIterator.next(); + + User user = dalFacade.getUserById((Integer) pair.getKey()); + List notifications = (List) pair.getValue(); + if (notifications.size() > 0) { + + String greeting = Localization.getInstance().getResourceBundle().getString("email.bodyText.greeting"); + String news = Localization.getInstance().getResourceBundle().getString("email.bodyText.news"); + String closing = String.format(Localization.getInstance().getResourceBundle().getString("email.bodyText.nextSummary"), emailSummaryTimePeriodInMinutes) + "\r\n\r\n" + + Localization.getInstance().getResourceBundle().getString("email.bodyText.bestWishes"); + String footer = Localization.getInstance().getResourceBundle().getString("email.bodyText.footer"); + String subject = Integer.toString(notifications.size()); + if (notifications.size() == 1) { + subject = subject.concat(" " + Localization.getInstance().getResourceBundle().getString("email.subject.singleSummary")); + } else { + subject = subject.concat(" " + Localization.getInstance().getResourceBundle().getString("email.subject.multipleSummary")); + } + + String message = news; + Iterator notificationIterator = notifications.iterator(); + while (notificationIterator.hasNext()) { + Email notification = (Email) notificationIterator.next(); + message = message.concat("\r\n\r\n" + notification.getMessage()); + notificationIterator.remove(); + } + + Email.Builder emailBuilder = new Email.Builder(); + emailBuilder.recipients(new HashSet<>(Arrays.asList(user))); + emailBuilder.subject(subject); + emailBuilder.starting(greeting); + emailBuilder.message(message); + emailBuilder.closing(closing); + emailBuilder.footer(footer); + emailBuilder.creationDate(new Date()); + Email summary = emailBuilder.build(); + sendEmail(summary); + + } else { + notificationSummeryIterator.remove(); + } + } + } catch (Exception ex) { + logger.warning(ex.getMessage()); + } + } + + private void sendEmail(Email mail) { + executorService.execute(() -> { + try { Properties props = System.getProperties(); Session session = Session.getInstance(props, null); Message mailMessage = new MimeMessage(session); mailMessage.setFrom(new InternetAddress(emailFromAddress)); - for (int i = 0; i < recipients.size(); i++) { - if (recipients.get(i).getEMail() != null && !recipients.get(i).getEMail().isEmpty()) - mailMessage.addRecipients(Message.RecipientType.BCC, - InternetAddress.parse(recipients.get(i).getEMail(), false)); - } - // use activityAction and dataType to generate email text - String subject = new String(); - String bodyText = new String(); - String objectName = new String(); - String resourcePath = new String(); - if (dataType == Activity.DataType.PROJECT) { - if (activityAction == Activity.ActivityAction.CREATE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.project.created"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.project.created"); - } else if (activityAction == Activity.ActivityAction.UPDATE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.project.updated"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.project.updated"); - } - Project project = dalFacade.getProjectById(dataId, 0); - objectName = project.getName(); - resourcePath = "projects" + "/" + String.valueOf(dataId); - } else if (dataType == Activity.DataType.CATEGORY) { - if (activityAction == Activity.ActivityAction.CREATE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.category.created"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.category.created"); - } else if (activityAction == Activity.ActivityAction.UPDATE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.category.updated"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.category.updated"); - } - Category category = dalFacade.getCategoryById(dataId, userId); - objectName = category.getName(); - resourcePath = "projects" + "/" + category.getProjectId() + "/" + "categories" + "/" + String.valueOf(dataId); - } else if (dataType == Activity.DataType.REQUIREMENT) { - if (activityAction == Activity.ActivityAction.CREATE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.requirement.created"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement.created"); - } else if (activityAction == Activity.ActivityAction.UPDATE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.requirement.updated"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement.updated"); - } else if (activityAction == Activity.ActivityAction.REALIZE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.requirement.realized"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.requirement.realized"); + for (User receiver : mail.getRecipients()) { + if (receiver.getEMail() != null) { + mailMessage.addRecipients(Message.RecipientType.BCC, InternetAddress.parse(receiver.getEMail(), false)); } - Requirement requirement = dalFacade.getRequirementById(dataId, userId); - objectName = requirement.getName(); - resourcePath = "projects" + "/" + requirement.getProjectId() + "/" + "categories" + "/" + - requirement.getCategories().get(0).getId() + "/" + "requirements" + "/" + String.valueOf(dataId); - } else if (dataType == Activity.DataType.COMMENT) { - if (activityAction == Activity.ActivityAction.CREATE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.comment.created"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.comment.created"); - } else if (activityAction == Activity.ActivityAction.UPDATE) { - subject = Localization.getInstance().getResourceBundle().getString("email.subject.comment.updated"); - bodyText = Localization.getInstance().getResourceBundle().getString("email.bodyText.comment.updated"); - } - Comment comment = dalFacade.getCommentById(dataId); - Requirement requirement = dalFacade.getRequirementById(comment.getRequirementId(), userId); - objectName = requirement.getName(); - resourcePath = "projects" + "/" + requirement.getProjectId() + "/" + "categories" + "/" + - requirement.getCategories().get(0).getId() + "/" + "requirements" + "/" + String.valueOf(requirement.getId()); } - String dataUrl = frontendBaseURL.concat(resourcePath); - objectName = objectName.length() > 40 ? objectName.substring(0, 39) : objectName; - subject = subject.concat(" " + objectName); - mailMessage.setSubject(subject); - String greeting = Localization.getInstance().getResourceBundle().getString("email.bodyText.greeting"); - String footer1 = Localization.getInstance().getResourceBundle().getString("email.bodyText.footer1"); - String footer2 = Localization.getInstance().getResourceBundle().getString("email.bodyText.footer2"); - String text = greeting; + mailMessage.setSubject(mail.getSubject()); + String text = mail.getStarting(); + text = text.concat("\r\n\r\n"); + text = text.concat(mail.getMessage()); text = text.concat("\r\n\r\n"); - text = text.concat(bodyText); - text = text.concat("\r\n" + dataUrl); + text = text.concat(mail.getClosing()); text = text.concat("\r\n\r\n"); - text = text.concat(footer1); - text = text.concat("\r\n"); - text = text.concat(footer2); + text = text.concat(mail.getFooter()); mailMessage.setText(text); mailMessage.setHeader("X-Mailer", "msgsend"); - mailMessage.setSentDate(creationDate); + mailMessage.setSentDate(mail.getCreationDate()); - // send mail Transport.send(mailMessage); + + } catch (Exception ex) { + logger.warning(ex.getMessage()); } - } catch (Exception e) { - //TODO log - } + }); } } 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 5ebda189..a67a9ea2 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 @@ -5,11 +5,12 @@ import i5.las2peer.logging.NodeObserver; import java.util.Date; +import java.util.TimerTask; /** * Created by martin on 15.02.2016. */ -public interface NotificationDispatcher { +public interface NotificationDispatcher extends Runnable { void dispatchNotification(Date creationDate, Activity.ActivityAction activityAction, final NodeObserver.Event mobSOSEvent, int dataId, Activity.DataType dataType, int userId); 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 b80a8777..5784c3bc 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 @@ -14,16 +14,14 @@ import i5.las2peer.logging.NodeObserver; import java.util.Date; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.TimerTask; /** * Created by martin on 15.02.2016. */ -public class NotificationDispatcherImp implements NotificationDispatcher { +public class NotificationDispatcherImp extends TimerTask implements NotificationDispatcher { private L2pLogger logger = L2pLogger.getInstance(NotificationDispatcherImp.class.getName()); - private ExecutorService executorService = Executors.newCachedThreadPool(); private ActivityDispatcher activityDispatcher; private EmailDispatcher emailDispatcher; private BazaarService bazaarService; @@ -44,39 +42,33 @@ public void setEmailDispatcher(EmailDispatcher emailDispatcher) { @Override public void dispatchNotification(final Date creationDate, final Activity.ActivityAction activityAction, final NodeObserver.Event mobSOSEvent, final int dataId, final Activity.DataType dataType, final int userId) { -// executorService.execute(new Runnable() { //TODO: try to run sendActivityOverRMI inside Runnable when las2peer allows this -// public void run() { -// if (activityDispatcher != null) { -// activityDispatcher.sendActivityOverRMI(service, creationDate, activityAction, dataId, dataType, userId); -// } -// } -// }); + // Filters to generate JSON elements FilterProvider filters = new SimpleFilterProvider().addFilter( "ActivityFilter", SimpleBeanPropertyFilter.filterOutAllExcept("id", "name")); - ObjectMapper mapper = new ObjectMapper(); + mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setFilters(filters); + Activity.AdditionalObject additionalObject = generateAdditionalObject(dataType, dataId, userId); + try { - executorService.execute(new Runnable() { - public void run() { - if (emailDispatcher != null && (activityAction == Activity.ActivityAction.CREATE || activityAction == Activity.ActivityAction.UPDATE || - activityAction == Activity.ActivityAction.REALIZE)) { - emailDispatcher.sendEmailNotification(creationDate, activityAction, dataId, dataType, userId); - } - } - }); - Activity.AdditionalObject additionalObject = generateAdditionalObject(dataType, dataId, userId); + if (emailDispatcher != null && (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 || activityAction == Activity.ActivityAction.REALIZE || activityAction == Activity.ActivityAction.DEVELOP || activityAction == Activity.ActivityAction.LEADDEVELOP || activityAction == Activity.ActivityAction.FOLLOW || activityAction == Activity.ActivityAction.VOTE)) { + // dispatch activity activityDispatcher.sendActivityOverRMI(creationDate, activityAction, dataId, dataType, userId, additionalObject); } if (mobSOSEvent != null) { + // dispatch mobSOS log call L2pLogger.logEvent(mobSOSEvent, Context.getCurrent().getMainAgent(), mapper.writeValueAsString(additionalObject)); } } catch (JsonProcessingException e) { @@ -123,4 +115,11 @@ private Activity.AdditionalObject generateAdditionalObject(Activity.DataType dat } return additionalObject; } + + @Override + public void run() { + if (emailDispatcher != null) { + emailDispatcher.emptyNotificationSummery(); + } + } } diff --git a/src/test/de/rwth/dbis/acis/bazaar/service/BazaarRequestParams.java b/src/test/de/rwth/dbis/acis/bazaar/service/BazaarRequestParams.java index 2cf0ca2c..528a0170 100644 --- a/src/test/de/rwth/dbis/acis/bazaar/service/BazaarRequestParams.java +++ b/src/test/de/rwth/dbis/acis/bazaar/service/BazaarRequestParams.java @@ -33,7 +33,7 @@ public class BazaarRequestParams { public Map getQueryParams() { if (queryParams == null) - queryParams = new HashMap(); + queryParams = new HashMap<>(); return queryParams; } diff --git a/src/test/de/rwth/dbis/acis/bazaar/service/security/AnonymUserRightsTest.java b/src/test/de/rwth/dbis/acis/bazaar/service/security/AnonymUserRightsTest.java index da2fb722..7c35099e 100644 --- a/src/test/de/rwth/dbis/acis/bazaar/service/security/AnonymUserRightsTest.java +++ b/src/test/de/rwth/dbis/acis/bazaar/service/security/AnonymUserRightsTest.java @@ -29,13 +29,8 @@ import i5.las2peer.webConnector.client.ClientResponse; import i5.las2peer.webConnector.client.MiniClient; -import org.hamcrest.Matchers; -import org.hamcrest.Matchers.*; import org.junit.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - import java.io.UnsupportedEncodingException; import java.util.HashMap; diff --git a/src/test/de/rwth/dbis/acis/bazaar/service/security/SysAdminRightsTest.java b/src/test/de/rwth/dbis/acis/bazaar/service/security/SysAdminRightsTest.java index a8f5533d..6441016d 100644 --- a/src/test/de/rwth/dbis/acis/bazaar/service/security/SysAdminRightsTest.java +++ b/src/test/de/rwth/dbis/acis/bazaar/service/security/SysAdminRightsTest.java @@ -30,7 +30,6 @@ import i5.las2peer.testing.MockAgentFactory; import i5.las2peer.webConnector.client.ClientResponse; import i5.las2peer.webConnector.client.MiniClient; -import org.hamcrest.Matchers; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -39,10 +38,6 @@ import java.util.HashMap; import java.util.List; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.hamcrest.Matchers.equalTo; - /** * @author Adam Gavronek * @since 2/24/2015 diff --git a/src/test/de/rwth/dbis/acis/bazaar/service/update/UpdateTest.java b/src/test/de/rwth/dbis/acis/bazaar/service/update/UpdateTest.java index 7a815232..ba68f6aa 100644 --- a/src/test/de/rwth/dbis/acis/bazaar/service/update/UpdateTest.java +++ b/src/test/de/rwth/dbis/acis/bazaar/service/update/UpdateTest.java @@ -28,7 +28,6 @@ import i5.las2peer.testing.MockAgentFactory; import i5.las2peer.webConnector.client.ClientResponse; import i5.las2peer.webConnector.client.MiniClient; -import org.hamcrest.Matchers; import org.junit.BeforeClass; import org.junit.Test; @@ -36,9 +35,6 @@ import java.util.HashMap; import java.util.List; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - /** * @author Adam Gavronek * @since 3/13/2015