diff --git a/.gradle/4.6/fileContent/annotation-processors.bin b/.gradle/4.6/fileContent/annotation-processors.bin index 024f0d2..f9301a7 100644 Binary files a/.gradle/4.6/fileContent/annotation-processors.bin and b/.gradle/4.6/fileContent/annotation-processors.bin differ diff --git a/.gradle/4.6/fileContent/fileContent.lock b/.gradle/4.6/fileContent/fileContent.lock index d7b4775..c9a712e 100644 Binary files a/.gradle/4.6/fileContent/fileContent.lock and b/.gradle/4.6/fileContent/fileContent.lock differ diff --git a/.gradle/4.6/fileHashes/fileHashes.bin b/.gradle/4.6/fileHashes/fileHashes.bin index 0154569..bebc113 100644 Binary files a/.gradle/4.6/fileHashes/fileHashes.bin and b/.gradle/4.6/fileHashes/fileHashes.bin differ diff --git a/.gradle/4.6/fileHashes/fileHashes.lock b/.gradle/4.6/fileHashes/fileHashes.lock index b5a693c..e8a4fae 100644 Binary files a/.gradle/4.6/fileHashes/fileHashes.lock and b/.gradle/4.6/fileHashes/fileHashes.lock differ diff --git a/.gradle/4.6/fileHashes/resourceHashesCache.bin b/.gradle/4.6/fileHashes/resourceHashesCache.bin index 4c78093..e6c2228 100644 Binary files a/.gradle/4.6/fileHashes/resourceHashesCache.bin and b/.gradle/4.6/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/4.6/taskHistory/taskHistory.bin b/.gradle/4.6/taskHistory/taskHistory.bin index f3b3d70..6b36265 100644 Binary files a/.gradle/4.6/taskHistory/taskHistory.bin and b/.gradle/4.6/taskHistory/taskHistory.bin differ diff --git a/.gradle/4.6/taskHistory/taskHistory.lock b/.gradle/4.6/taskHistory/taskHistory.lock index c6837d8..0cec1c7 100644 Binary files a/.gradle/4.6/taskHistory/taskHistory.lock and b/.gradle/4.6/taskHistory/taskHistory.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 6167c6c..15e214d 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 87da60b..7fcdb16 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..152f65b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM openjdk:8-jdk-alpine +VOLUME /tmp +ARG DEPENDENCY=target/dependency + +COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib +COPY ${DEPENDENCY}/META-INF /app/META-INF +COPY ${DEPENDENCY}/BOOT-INF/classes /app + +ENTRYPOINT ["java","-cp","app:app/lib/*","org.kpmp.Application"] diff --git a/README.md b/README.md index 8293daf..2420aa6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,39 @@ -# stateManagerService +# State Manager Service + +This is intended to be a service available to other services and applications inside of KPMP. It is not a stand-alone website, so there is only a Java project for the service layer. -The state manager service will do the work to keep track of the state of packages as they travel from the data lake to the knowledge environment. +It will run inside the dataLake network which is created by orion when running on a developer machine, or by the dataLakeProxyServer when running on our production-like and production instances. + +## Set up on your local machine + +- Change directory to heavens-docker/orion +- docker-compose -f docker-compose.dev.yml up -d +- Change directory to heavens-docker/stateManager +- docker-compose -f docker-compose.dev.yml up -d + +At this point you should be able to interact with the service by hitting endpoints at http://localhost:3060 + +As you are working on changes, you should make sure to run ./gradlew build docker in order to create new docker images locally to be used inside docker. After rebuilding the image, you will need to restart the docker container in order to pick up your changes. + +When you are done with your local changes, you will need to push the latest image to cloud.docker.com + +1) docker login +2) Provide username/password (see another developer for these values) +3) docker push kingstonduo/state-manager-service // This will push to the 'latest' tag which we are using on our local development machines +4) docker image ls +5) Find the image you just built (should be at the top of the list) and grab the hash +6) docker tag kingstonduo/state-manager-service: // Where hash is the value you just grabbed, and x.x is the release version you are working on +7) docker push kingstonduo/state-manager-service: + +## Set up in dev, qa or prod + +- Pull down the stateManagerService project at http://github.com/KPMP +- Change directory to heavens-docker/dataLakeProxyServer +- docker-compose up -d +- Change directory to heavens-docker/ara +- docker-compose up -d +- Change directory to heavens-docker/orion +- docker-compose -f docker-compose.shib.yml up -d +- Change directory to heavens-docker/stateManager +- docker-compose -f docker-compose.prod.yml up -d +~ diff --git a/bin/default/application.properties b/bin/default/application.properties new file mode 100644 index 0000000..fb085d6 --- /dev/null +++ b/bin/default/application.properties @@ -0,0 +1,3 @@ +server.port=3060 + +spring.data.mongodb.uri=mongodb://mongodb:27017/dataLake \ No newline at end of file diff --git a/build.gradle b/build.gradle index 805eea3..943bd9a 100644 --- a/build.gradle +++ b/build.gradle @@ -23,8 +23,8 @@ apply plugin: 'io.spring.dependency-management' apply plugin: 'com.palantir.docker' jar { - baseName='stateManagerService' - version= '0.1' + baseName='state-manager-service' + version= '1.0' } repositories { @@ -38,7 +38,7 @@ dependencies { compile 'org.springframework.boot:spring-boot-starter-web' compile 'org.apache.commons:commons-compress:1.17' compile 'org.springframework.boot:spring-boot-starter-test' - compile 'org.springframework.data:spring-data-mongodb:2.0.8.RELEASE' + compile 'org.springframework.data:spring-data-mongodb' compile 'org.springframework.boot:spring-boot-starter-data-mongodb' testCompile 'org.springframework.boot:spring-boot-starter-test' testCompile 'org.mockito:mockito-core' diff --git a/src/main/java/org/kpmp/WebConfig.java b/src/main/java/org/kpmp/WebConfig.java index 5b35388..23a5150 100755 --- a/src/main/java/org/kpmp/WebConfig.java +++ b/src/main/java/org/kpmp/WebConfig.java @@ -1,13 +1,17 @@ package org.kpmp; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -@EnableAutoConfiguration(exclude = {}) +@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, + DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) public class WebConfig implements WebMvcConfigurer { @Override diff --git a/src/main/java/org/kpmp/stateManager/State.java b/src/main/java/org/kpmp/stateManager/State.java new file mode 100644 index 0000000..c2f9cf2 --- /dev/null +++ b/src/main/java/org/kpmp/stateManager/State.java @@ -0,0 +1,58 @@ +package org.kpmp.stateManager; + +import java.util.Date; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +@Document(collection = "state") +public class State { + + @Id + private String id; + private String packageId; + private String state; + private String codicil; + private Date stateChangeDate; + + public Date getStateChangeDate() { + return stateChangeDate; + } + + public void setStateChangeDate(Date stateChangeDate) { + this.stateChangeDate = stateChangeDate; + } + + public String getCodicil() { + return codicil; + } + + public void setCodicil(String codicil) { + this.codicil = codicil; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getPackageId() { + return packageId; + } + + public void setPackageId(String packageId) { + this.packageId = packageId; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + +} diff --git a/src/main/java/org/kpmp/stateManager/StateController.java b/src/main/java/org/kpmp/stateManager/StateController.java new file mode 100644 index 0000000..8faa822 --- /dev/null +++ b/src/main/java/org/kpmp/stateManager/StateController.java @@ -0,0 +1,35 @@ +package org.kpmp.stateManager; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class StateController { + + private StateService stateService; + private static final Log log = LogFactory.getLog(StateController.class); + + @Autowired + public StateController(StateService stateService) { + this.stateService = stateService; + } + + @RequestMapping(value = "/v1/state", method = RequestMethod.POST) + public @ResponseBody String setState(@RequestBody State state, HttpServletRequest request) { + log.info("URI: " + request.getRequestURI() + " | PKGID: " + state.getPackageId() + " | MSG: Saving new state: " + + state.getState()); + state.setStateChangeDate(new Date()); + return stateService.setState(state); + } + +} diff --git a/src/main/java/org/kpmp/stateManager/StateRepository.java b/src/main/java/org/kpmp/stateManager/StateRepository.java new file mode 100644 index 0000000..9a8b115 --- /dev/null +++ b/src/main/java/org/kpmp/stateManager/StateRepository.java @@ -0,0 +1,10 @@ +package org.kpmp.stateManager; + +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface StateRepository extends MongoRepository { + + @SuppressWarnings("unchecked") + public State save(State state); + +} diff --git a/src/main/java/org/kpmp/stateManager/StateService.java b/src/main/java/org/kpmp/stateManager/StateService.java new file mode 100644 index 0000000..7de7b50 --- /dev/null +++ b/src/main/java/org/kpmp/stateManager/StateService.java @@ -0,0 +1,21 @@ +package org.kpmp.stateManager; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class StateService { + + private StateRepository stateRepository; + + @Autowired + public StateService(StateRepository stateRepository) { + this.stateRepository = stateRepository; + } + + public String setState(State state) { + State savedState = stateRepository.save(state); + return savedState.getId(); + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..fb085d6 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,3 @@ +server.port=3060 + +spring.data.mongodb.uri=mongodb://mongodb:27017/dataLake \ No newline at end of file diff --git a/src/test/java/org/kpmp/stateManager/StateControllerTest.java b/src/test/java/org/kpmp/stateManager/StateControllerTest.java new file mode 100644 index 0000000..a42f14b --- /dev/null +++ b/src/test/java/org/kpmp/stateManager/StateControllerTest.java @@ -0,0 +1,47 @@ +package org.kpmp.stateManager; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class StateControllerTest { + + @Mock + private StateService stateService; + private StateController controller; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + controller = new StateController(stateService); + } + + @After + public void tearDown() throws Exception { + controller = null; + } + + @Test + public void testSetState() { + State state = mock(State.class); + when(stateService.setState(state)).thenReturn("id"); + String stateId = controller.setState(state, mock(HttpServletRequest.class)); + + assertEquals("id", stateId); + verify(stateService).setState(state); + verify(state).setStateChangeDate(any(Date.class)); + } + +} diff --git a/src/test/java/org/kpmp/stateManager/StateServiceTest.java b/src/test/java/org/kpmp/stateManager/StateServiceTest.java new file mode 100644 index 0000000..e23a591 --- /dev/null +++ b/src/test/java/org/kpmp/stateManager/StateServiceTest.java @@ -0,0 +1,44 @@ +package org.kpmp.stateManager; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class StateServiceTest { + + @Mock + private StateRepository stateRepository; + private StateService service; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + service = new StateService(stateRepository); + } + + @After + public void tearDown() throws Exception { + service = null; + } + + @Test + public void testSetState() { + State state = mock(State.class); + State returnState = mock(State.class); + when(returnState.getId()).thenReturn("id"); + when(stateRepository.save(state)).thenReturn(returnState); + + String stateId = service.setState(state); + + assertEquals("id", stateId); + verify(stateRepository).save(state); + } + +} diff --git a/src/test/java/org/kpmp/stateManager/StateTest.java b/src/test/java/org/kpmp/stateManager/StateTest.java new file mode 100644 index 0000000..1cb7eee --- /dev/null +++ b/src/test/java/org/kpmp/stateManager/StateTest.java @@ -0,0 +1,58 @@ +package org.kpmp.stateManager; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class StateTest { + + private State state; + + @Before + public void setUp() throws Exception { + state = new State(); + } + + @After + public void tearDown() throws Exception { + state = null; + } + + @Test + public void testSetStateChangeDate() { + Date stateChangeDate = new Date(); + + state.setStateChangeDate(stateChangeDate); + + assertEquals(stateChangeDate, state.getStateChangeDate()); + } + + @Test + public void testSetCodicil() { + state.setCodicil("codicil"); + assertEquals("codicil", state.getCodicil()); + } + + @Test + public void testSetState() { + state.setState("new state"); + assertEquals("new state", state.getState()); + } + + @Test + public void testSetPackageId() { + state.setPackageId("packageId"); + assertEquals("packageId", state.getPackageId()); + } + + @Test + public void testId() throws Exception { + state.setId("id"); + assertEquals("id", state.getId()); + } + +}