Skip to content
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

KPMP-4885_get-message-table #101

Merged
merged 7 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main/java/org/kpmp/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.ArrayList;
import java.util.List;

import org.kpmp.atlasMessage.AtlasMessage;
import org.kpmp.atlasMessage.AtlasMessageService;
import org.kpmp.autocomplete.AutocompleteResult;
import org.kpmp.autocomplete.AutocompleteService;
import org.kpmp.cellType.CellTypeHierarchy;
Expand Down Expand Up @@ -44,14 +46,15 @@ public class Query implements GraphQLQueryResolver {

private RPExpressionDataService rpExpressionDataService;
private ParticipantService participantService;
private AtlasMessageService atlasMessageService;
private Logger logger = LoggerFactory.getLogger(Query.class);

@Autowired
public Query(AutocompleteService autocompleteService, CellTypeService cellTypeService,
UmapDataService umapService, GeneExpressionSummaryService geneExpressionSummaryService,
DataSummaryService dataSummaryService, ClusterHierarchyService clusterHierarchyService,
RTExpressionDataService rtExpressionDataService, RPExpressionDataService rpExpressionDataService,
ParticipantService participantService) {
ParticipantService participantService, AtlasMessageService atlasMessageService) {

this.autocompleteService = autocompleteService;
this.cellTypeService = cellTypeService;
Expand All @@ -62,6 +65,7 @@ public Query(AutocompleteService autocompleteService, CellTypeService cellTypeSe
this.rtExpressionDataService = rtExpressionDataService;
this.rpExpressionDataService = rpExpressionDataService;
this.participantService = participantService;
this.atlasMessageService = atlasMessageService;
}

public List<AutocompleteResult> autocomplete(String searchTerm) throws IOException, Exception {
Expand Down Expand Up @@ -213,4 +217,13 @@ public AtlasRepoSummaryResult getAtlasSummaryRows() throws Exception {
throw e;
}
}

public List<AtlasMessage> getAtlasMessages() throws Exception {
try{
return atlasMessageService.getAtlasMessage();
}catch (Exception e){
logger.error("Unable to get Atlas Message data: ", e.getMessage());
throw e;
}
}
}
60 changes: 60 additions & 0 deletions src/main/java/org/kpmp/atlasMessage/AtlasMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.kpmp.atlasMessage;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "atlas_messages")
public class AtlasMessage implements Serializable {
@Id
private int id;
private String message;
private String application;
private Date startDate;
private Date endDate;

public int getId() {
return this.id;
}

public void setId(int id) {
this.id = id;
}

public String getMessage() {
return this.message;
}

public void setMessage(String message) {
this.message = message;
}

public String getApplication() {
return this.application;
}

public void setApplication(String application) {
this.application = application;
}

public Date getStartDate() {
return this.startDate;
}

public void setStartDate(Date startDate) {
this.startDate = startDate;
}

public Date getEndDate() {
return this.endDate;
}

public void setEndDate(Date endDate) {
this.endDate = endDate;
}

}
16 changes: 16 additions & 0 deletions src/main/java/org/kpmp/atlasMessage/AtlasMessageRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.kpmp.atlasMessage;


import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
interface AtlasMessageRepository extends CrudRepository<AtlasMessage, List>{
@Cacheable("messageByStartDate")
@Query(value = "SELECT * FROM atlas_messages am WHERE start_date <= CURRENT_DATE() AND end_date >= CURRENT_DATE() ORDER BY start_date DESC", nativeQuery = true)
List<AtlasMessage> getAtlasMessages();
}
23 changes: 23 additions & 0 deletions src/main/java/org/kpmp/atlasMessage/AtlasMessageService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.kpmp.atlasMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class AtlasMessageService {
private AtlasMessageRepository atlasMessageRepo;

@Autowired
public AtlasMessageService(AtlasMessageRepository atlasMessageRepo){
this.atlasMessageRepo = atlasMessageRepo;
}

public List<AtlasMessage> getAtlasMessage(){
return atlasMessageRepo.getAtlasMessages();
}

}
8 changes: 8 additions & 0 deletions src/main/resources/knowledge_environment.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ type Query {
getTotalParticipantFilesCount(redcapId: String): ParticipantRepoDataTypeInformation
getTissueTypeSummaryData: [ParticipantTissueTypeSummary]
getAtlasSummaryRows: AtlasRepoSummaryResult
getAtlasMessages: [AtlasMessages]
}

type AtlasMessages {
id: Int
message: String
startDate: String
endDate: String
}

type AtlasRepoSummaryResult {
Expand Down
28 changes: 27 additions & 1 deletion src/test/java/org/kpmp/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.kpmp.atlasMessage.AtlasMessage;
import org.kpmp.atlasMessage.AtlasMessageService;
import org.kpmp.autocomplete.AutocompleteResult;
import org.kpmp.autocomplete.AutocompleteService;
import org.kpmp.cellType.CellTypeHierarchy;
Expand Down Expand Up @@ -65,6 +70,8 @@ public class QueryTest {
private ParticipantService participantService;
@Mock
private ParticipantTissueTypeSummary participantTissueTypeSummary;
@Mock
private AtlasMessageService atlasMessageService;

@Mock
private RPExpressionDataService rpExpressionDataService;
Expand All @@ -73,7 +80,8 @@ public class QueryTest {
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
query = new Query(autocompleteService, cellTypeService, umapDataService, geneExpressionService,
dataSummaryService, clusterHierarchyService, rtExpressionDataService, rpExpressionDataService, participantService);
dataSummaryService, clusterHierarchyService, rtExpressionDataService, rpExpressionDataService,
participantService, atlasMessageService);
}

@After
Expand Down Expand Up @@ -299,4 +307,22 @@ public void getParticipantTissueTypeSummary() throws Exception {

assertEquals(expectedResult, tissueSummary);
}

@Test
public void testGetAtlasMessage() throws Exception {
AtlasMessage atlasMessage = new AtlasMessage();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String endDateString = "2023-12-25";
String startDateString = "2023-12-01";
Date endDate = dateFormat.parse(endDateString);
Date startDate = dateFormat.parse(startDateString);
atlasMessage.setId(0);
atlasMessage.setApplication("Explorer");
atlasMessage.setEndDate(endDate);
atlasMessage.setStartDate(startDate);
atlasMessage.setMessage("THE END IS NEAR");
List<AtlasMessage> expectedResult = Arrays.asList(new AtlasMessage());
when(atlasMessageService.getAtlasMessage()).thenReturn(expectedResult);
assertEquals(expectedResult, query.getAtlasMessages());
}
}
55 changes: 55 additions & 0 deletions src/test/java/org/kpmp/atlasMessage/AtlasMessageServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.kpmp.atlasMessage;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import java.util.Arrays;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class AtlasMessageServiceTest {
private AtlasMessageService atlasMessageService;
@Mock
private AtlasMessageRepository atlasMessageRepository;
@Mock
private AtlasMessage atlasMessage;
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
atlasMessageService = new AtlasMessageService(atlasMessageRepository);
}

@AfterEach
public void tearDown() throws Exception {
MockitoAnnotations.openMocks(this).close();
atlasMessageService = null;
}

@Test
public void testGetAtlasMessage() throws Exception {
AtlasMessage message = new AtlasMessage();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String endDateString = "2023-12-31";
String startDateString = "2022-12-31";
Date endDate = format.parse(endDateString);
Date startDate = format.parse(startDateString);
message.setApplication("Explorer");
message.setEndDate(endDate);
message.setStartDate(startDate);
message.setId(1);
AtlasMessage message2 = new AtlasMessage();
message2.setApplication(null);
message2.setEndDate(null);
message2.setStartDate(null);
message2.setId(2);
List<AtlasMessage> messageList = Arrays.asList(message, message2);
when(atlasMessageRepository.getAtlasMessages()).thenReturn(messageList);
}
}
62 changes: 62 additions & 0 deletions src/test/java/org/kpmp/atlasMessage/AtlasMessageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.kpmp.atlasMessage;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

public class AtlasMessageTest {
@Mock
private AtlasMessage atlasMessage;
@BeforeEach
public void setUp() throws Exception {
atlasMessage = new AtlasMessage();
}

@AfterEach
public void tearDown() throws Exception {
atlasMessage = null;
}

@Test
public void testGetApplication() throws Exception {
atlasMessage.setApplication("Explorer");
assertEquals("Explorer", atlasMessage.getApplication());
}

@Test
public void testGetId() throws Exception{
atlasMessage.setId(1);
assertEquals(1, atlasMessage.getId());
}

@Test
public void testGetStartDate() throws Exception {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String startDateString = "2023-12-25";
Date startDate = dateFormat.parse(startDateString);
atlasMessage.setStartDate(startDate);
assertEquals(startDate, atlasMessage.getStartDate());
}

@Test
public void testGetEndDate() throws Exception {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String endDateString = "2023-12-25";
Date endDate = dateFormat.parse(endDateString);
atlasMessage.setEndDate(endDate);
assertEquals(endDate, atlasMessage.getEndDate());
}

@Test
public void testGetAtlasMessage() throws Exception {
atlasMessage.setMessage("THE END IS NEAR");
assertEquals("THE END IS NEAR", atlasMessage.getMessage());
}
}