Commit d0cc8caf authored by 0Tyler's avatar 0Tyler

getPrivacyPolicyChoices function change

parent 3cae3858
This diff is collapsed.
...@@ -34,11 +34,13 @@ repositories { ...@@ -34,11 +34,13 @@ repositories {
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
runtimeOnly 'com.h2database:h2' runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
......
...@@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class CloudApplication { public class CloudApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(CloudApplication.class, args); SpringApplication.run(CloudApplication.class, args);
} }
......
package edu.prlab.tyler.iotgateway.cloud.pojo.privacy; package edu.prlab.tyler.iotgateway.cloud.pojo.privacy;
import com.fasterxml.jackson.annotation.JsonIgnore;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.p3p.Access; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.p3p.Access;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.p3p.Collector; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.p3p.Collector;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.p3p.Dispute; import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.p3p.Dispute;
......
server.port=8081 server.port=8081
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
\ No newline at end of file
...@@ -7,7 +7,6 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; ...@@ -7,7 +7,6 @@ import org.springframework.boot.autoconfigure.domain.EntityScan;
import javax.persistence.Entity; import javax.persistence.Entity;
@SpringBootApplication @SpringBootApplication
@EntityScan("edu.prlab.tyler.iotgateway")
public class GatewayApplication { public class GatewayApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args); SpringApplication.run(GatewayApplication.class, args);
......
...@@ -40,7 +40,7 @@ public class PrivacyService { ...@@ -40,7 +40,7 @@ public class PrivacyService {
} }
public Optional<PrivacyChoiceResponse> setPrivacyPolicyChoice(PrivacyChoice privacyChoice) { public Optional<PrivacyChoiceResponse> setPrivacyPolicyChoice(PrivacyChoice privacyChoice) {
System.out.println(privacyChoice.toString()); System.out.println("setPrivacyPolicyChoice : " + privacyChoice.toString());
return Optional.of(privacyChoice) return Optional.of(privacyChoice)
.map(choice -> template.postForObject(cloudAddress + "/choice", choice, PrivacyChoice.class)) .map(choice -> template.postForObject(cloudAddress + "/choice", choice, PrivacyChoice.class))
.flatMap(choice -> Optional.of(privacyChoiceIndexRepository.save(PrivacyChoiceIndex.builder() .flatMap(choice -> Optional.of(privacyChoiceIndexRepository.save(PrivacyChoiceIndex.builder()
...@@ -62,13 +62,29 @@ public class PrivacyService { ...@@ -62,13 +62,29 @@ public class PrivacyService {
public Iterable<PrivacyChoiceResponse> getPrivacyPolicyChoices() { public Iterable<PrivacyChoiceResponse> getPrivacyPolicyChoices() {
return () -> StreamSupport.stream( return () -> StreamSupport.stream(
template.exchange(cloudAddress + "/choice", HttpMethod.GET, null, template.exchange(cloudAddress + "/choice", HttpMethod.GET, null,
new ParameterizedTypeReference<Iterable<PrivacyChoice>>() { }).getBody().spliterator(), new ParameterizedTypeReference<Iterable<PrivacyChoice>>() {
}).getBody().spliterator(),
false) false)
.map(choice -> privacyChoiceIndexRepository.findById(choice.getId()) .map(choice -> privacyChoiceIndexRepository.findById(choice.getId())
.map(choiceIndex -> PrivacyChoiceResponse.builder() .map(choiceIndex -> PrivacyChoiceResponse.builder()
.id(choiceIndex.getId()) .id(choiceIndex.getId())
.localDateTime(choiceIndex.getLocalDateTime()) .localDateTime(choiceIndex.getLocalDateTime())
.privacyContent(choice.getPrivacyContent()) .privacyContent(choice.getPrivacyContent())
.build()).get()).iterator(); .build())
.orElseGet(() -> new PrivacyChoiceResponse())
).iterator();
} }
// private PrivacyChoiceResponse getPrivacyChoiceResponse(PrivacyChoice choice) {
// return privacyChoiceIndexRepository.findById(choice.getId())
// .map(choiceIndex -> PrivacyChoiceResponse.builder()
// .id(choiceIndex.getId())
// .localDateTime(choiceIndex.getLocalDateTime())
// .privacyContent(choice.getPrivacyContent())
// .build())
// .orElseGet(() -> {
// System.out.println(choice.getId() + "is not found");
// return new PrivacyChoiceResponse();
// });
// }
} }
...@@ -123,5 +123,13 @@ public class GatewayHttpApiTest { ...@@ -123,5 +123,13 @@ public class GatewayHttpApiTest {
.andExpect(status().isOk()) .andExpect(status().isOk())
.andReturn(); .andReturn();
Assert.assertNotNull(result); Assert.assertNotNull(result);
result = mvc.perform(MockMvcRequestBuilders
.get("/choice")
.accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(print())
.andExpect(status().isOk())
.andReturn();
Assert.assertNotNull(result);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment