New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification Module #270
Notification Module #270
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ repos | |
.settings | ||
.gradle | ||
*.log | ||
.idea | ||
!gradle/wrapper/gradle-wrapper.jar | ||
/gradle |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,10 @@ dependencies { | |
[group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'], | ||
// Once we've switched to Java 8 this dep can be removed. | ||
//[group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0'] | ||
[group: 'org.springframework', name:'spring-jms'], | ||
[group: 'org.apache.activemq', name: 'activemq-broker'], | ||
[group: 'com.mockrunner', name: 'mockrunner-jms', version: '1.0.6'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these dependencies should be part of testCompile? |
||
[group: 'com.mockrunner', name: 'mockrunner-jdbc', version: '1.0.6'] | ||
) | ||
testCompile 'junit:junit:4.11', | ||
'junit:junit-dep:4.11', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.apache.fineract.integrationtests; | ||
|
||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
|
||
import com.jayway.restassured.builder.RequestSpecBuilder; | ||
import com.jayway.restassured.builder.ResponseSpecBuilder; | ||
import com.jayway.restassured.http.ContentType; | ||
import com.jayway.restassured.specification.RequestSpecification; | ||
import com.jayway.restassured.specification.ResponseSpecification; | ||
import org.apache.fineract.integrationtests.common.NotificationHelper; | ||
import org.apache.fineract.integrationtests.common.Utils; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
|
||
public class NotificationApiTest { | ||
|
||
private ResponseSpecification responseSpec; | ||
private RequestSpecification requestSpec; | ||
|
||
@Before | ||
public void setUp() { | ||
Utils.initializeRESTAssured(); | ||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); | ||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); | ||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); | ||
} | ||
|
||
@Test | ||
@SuppressWarnings("unchecked") | ||
public void testNotificationRetrieval() { | ||
HashMap<String, Object> response = (HashMap<String, Object>) NotificationHelper.getNotifications(this.requestSpec, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the actual test cases for notifications? You are just verifying the response? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have included the test for sending and receiving of notifications in |
||
this.responseSpec, ""); | ||
System.out.println("Response : " + response.toString()); | ||
Assert.assertNotNull(response); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.apache.fineract.integrationtests.common; | ||
|
||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import com.jayway.restassured.specification.RequestSpecification; | ||
import com.jayway.restassured.specification.ResponseSpecification; | ||
|
||
public class NotificationHelper { | ||
|
||
private final RequestSpecification requestSpec; | ||
private final ResponseSpecification responseSpec; | ||
|
||
private static final String NOTIFICATION_API_URL = "/fineract-provider/api/v1/notifications?" + Utils.TENANT_IDENTIFIER; | ||
|
||
public NotificationHelper(RequestSpecification requestSpec, ResponseSpecification responseSpec) { | ||
this.requestSpec = requestSpec; | ||
this.responseSpec = responseSpec; | ||
} | ||
|
||
public static Object getNotifications(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, | ||
final String jsonReturn) { | ||
final String GET_NOTIFICATIONS_URL = NOTIFICATION_API_URL; | ||
System.out.println("-----------------------------GET NOTIFICATIONS-----------------------------------"); | ||
return Utils.performServerGet(requestSpec, responseSpec, GET_NOTIFICATIONS_URL, ""); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.fineract.notification.api; | ||
|
||
|
||
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper; | ||
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; | ||
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer; | ||
import org.apache.fineract.infrastructure.core.service.Page; | ||
import org.apache.fineract.infrastructure.core.service.SearchParameters; | ||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; | ||
import org.apache.fineract.notification.data.NotificationData; | ||
import org.apache.fineract.notification.service.NotificationReadPlatformService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
@Path("/notifications") | ||
@Component | ||
@Scope("singleton") | ||
public class NotificationApiResource { | ||
|
||
private final PlatformSecurityContext context; | ||
private final NotificationReadPlatformService notificationReadPlatformService; | ||
private final ApiRequestParameterHelper apiRequestParameterHelper; | ||
private final ToApiJsonSerializer<NotificationData> toApiJsonSerializer; | ||
|
||
@Autowired | ||
public NotificationApiResource(PlatformSecurityContext context, | ||
NotificationReadPlatformService notificationReadPlatformService, | ||
ApiRequestParameterHelper apiRequestParameterHelper, | ||
ToApiJsonSerializer<NotificationData> toApiJsonSerializer) { | ||
this.context = context; | ||
this.notificationReadPlatformService = notificationReadPlatformService; | ||
this.apiRequestParameterHelper = apiRequestParameterHelper; | ||
this.toApiJsonSerializer = toApiJsonSerializer; | ||
} | ||
|
||
@GET | ||
@Consumes({MediaType.APPLICATION_JSON}) | ||
@Produces({MediaType.APPLICATION_JSON}) | ||
public String getAllNotifications(@Context final UriInfo uriInfo, @QueryParam("orderBy") final String orderBy, | ||
@QueryParam("limit") final Integer limit, | ||
@QueryParam("offset") final Integer offset, | ||
@QueryParam("sortOrder") final String sortOrder, | ||
@QueryParam("isRead") final boolean isRead) { | ||
|
||
this.context.authenticatedUser(); | ||
final Page<NotificationData> notificationData; | ||
final SearchParameters searchParameters = SearchParameters.forPagination(offset, limit, orderBy, sortOrder); | ||
if (!isRead) { | ||
notificationData = this.notificationReadPlatformService.getAllUnreadNotifications(searchParameters); | ||
} else { | ||
notificationData = this.notificationReadPlatformService.getAllNotifications(searchParameters); | ||
} | ||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper | ||
.process(uriInfo.getQueryParameters()); | ||
return this.toApiJsonSerializer.serialize(settings, notificationData); | ||
} | ||
|
||
@PUT | ||
@Consumes({MediaType.APPLICATION_JSON}) | ||
@Produces({MediaType.APPLICATION_JSON}) | ||
public void update() { | ||
this.context.authenticatedUser(); | ||
this.notificationReadPlatformService.updateNotificationReadStatus(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.fineract.notification.cache; | ||
|
||
|
||
public class CacheNotificationResponseHeader { | ||
|
||
private boolean hasNotifications; | ||
private Long lastFetch; | ||
|
||
public CacheNotificationResponseHeader() { | ||
} | ||
|
||
public CacheNotificationResponseHeader(boolean hasNotifications, Long lastFetch) { | ||
this.hasNotifications = hasNotifications; | ||
this.lastFetch = lastFetch; | ||
} | ||
|
||
public boolean hasNotifications() { | ||
return hasNotifications; | ||
} | ||
|
||
public void setHasNotifications(boolean hasNotifications) { | ||
this.hasNotifications = hasNotifications; | ||
} | ||
|
||
public Long getLastFetch() { | ||
return lastFetch; | ||
} | ||
|
||
public void setLastFetch(Long lastFetch) { | ||
this.lastFetch = lastFetch; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these dependencies should be part of testCompile?