Commit a513b3c8 authored by 0Tyler's avatar 0Tyler

document controller

parent 74e04ce0
<component name="ArtifactManager">
<artifact type="jar" name="iotgateway.cloud:jar">
<output-path>$PROJECT_DIR$/out/artifacts/iotgateway_cloud_jar</output-path>
<root id="archive" name="iotgateway.cloud.jar">
<element id="directory" name="META-INF">
<element id="file-copy" path="$PROJECT_DIR$/META-INF/MANIFEST.MF" />
</element>
<element id="library" level="project" name="Gradle: org.springframework:spring-webmvc:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-orm:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: antlr:antlr:2.7.7" />
<element id="library" level="project" name="Gradle: ch.qos.logback:logback-classic:1.2.3" />
<element id="library" level="project" name="Gradle: ch.qos.logback:logback-core:1.2.3" />
<element id="library" level="project" name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.9.0" />
<element id="library" level="project" name="Gradle: com.fasterxml.jackson.core:jackson-core:2.9.8" />
<element id="library" level="project" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.9.8" />
<element id="library" level="project" name="Gradle: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.8" />
<element id="library" level="project" name="Gradle: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.8" />
<element id="library" level="project" name="Gradle: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.8" />
<element id="library" level="project" name="Gradle: com.fasterxml:classmate:1.4.0" />
<element id="library" level="project" name="Gradle: com.h2database:h2:1.4.199" />
<element id="library" level="project" name="Gradle: com.zaxxer:HikariCP:3.2.0" />
<element id="library" level="project" name="Gradle: javax.activation:javax.activation-api:1.2.0" />
<element id="library" level="project" name="Gradle: javax.annotation:javax.annotation-api:1.3.2" />
<element id="library" level="project" name="Gradle: javax.persistence:javax.persistence-api:2.2" />
<element id="library" level="project" name="Gradle: javax.transaction:javax.transaction-api:1.3" />
<element id="library" level="project" name="Gradle: javax.validation:validation-api:2.0.1.Final" />
<element id="library" level="project" name="Gradle: javax.xml.bind:jaxb-api:2.3.1" />
<element id="library" level="project" name="Gradle: net.bytebuddy:byte-buddy:1.9.12" />
<element id="library" level="project" name="Gradle: org.apache.logging.log4j:log4j-api:2.11.2" />
<element id="library" level="project" name="Gradle: org.apache.logging.log4j:log4j-to-slf4j:2.11.2" />
<element id="library" level="project" name="Gradle: org.apache.tomcat.embed:tomcat-embed-core:9.0.17" />
<element id="library" level="project" name="Gradle: org.apache.tomcat.embed:tomcat-embed-el:9.0.17" />
<element id="library" level="project" name="Gradle: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.17" />
<element id="library" level="project" name="Gradle: org.aspectj:aspectjweaver:1.9.2" />
<element id="library" level="project" name="Gradle: org.dom4j:dom4j:2.1.1" />
<element id="library" level="project" name="Gradle: org.hibernate.common:hibernate-commons-annotations:5.0.4.Final" />
<element id="library" level="project" name="Gradle: org.hibernate.validator:hibernate-validator:6.0.16.Final" />
<element id="library" level="project" name="Gradle: org.hibernate:hibernate-core:5.3.9.Final" />
<element id="library" level="project" name="Gradle: org.javassist:javassist:3.23.1-GA" />
<element id="library" level="project" name="Gradle: org.jboss.logging:jboss-logging:3.3.2.Final" />
<element id="library" level="project" name="Gradle: org.jboss:jandex:2.0.5.Final" />
<element id="library" level="project" name="Gradle: org.mapstruct:mapstruct:1.3.0.Final" />
<element id="library" level="project" name="Gradle: org.slf4j:jul-to-slf4j:1.7.26" />
<element id="library" level="project" name="Gradle: org.slf4j:slf4j-api:1.7.26" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-autoconfigure:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-devtools:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-starter-aop:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-starter-data-jpa:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-starter-jdbc:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-starter-json:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-starter-logging:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-starter-tomcat:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-starter-web:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot-starter:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.boot:spring-boot:2.1.4.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.data:spring-data-commons:2.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework.data:spring-data-jpa:2.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-aop:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-aspects:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-beans:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-context:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-core:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-expression:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-jcl:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-jdbc:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-tx:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.springframework:spring-web:5.1.6.RELEASE" />
<element id="library" level="project" name="Gradle: org.yaml:snakeyaml:1.23" />
<element id="module-output" name="iotgateway.cloud.main" />
</root>
</artifact>
</component>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -15,8 +15,6 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compile project(':gateway')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
......@@ -14,6 +14,7 @@ buildscript {
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
......@@ -37,7 +38,6 @@ dependencies {
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
......@@ -45,3 +45,15 @@ dependencies {
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
jar {
enabled = true
}
bootJar {
enabled = false
classifier = 'boot'
manifest {
attributes 'Start-Class': 'edu.prlab.tyler.iotgateway.cloud.CloudApplication'
attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
}
}
\ No newline at end of file
package edu.prlab.tyler.iotgateway.cloud;
import edu.prlab.tyler.iotgateway.cloud.pojo.Document;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
public class CloudApplication {
......
package edu.prlab.tyler.iotgateway.cloud.controllers;
import edu.prlab.tyler.iotgateway.cloud.pojo.Document;
import edu.prlab.tyler.iotgateway.cloud.services.DocumentService;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@RestController
@RequestMapping("/document")
public class DocumentController {
private DocumentService documentService;
public DocumentController(DocumentService documentService) {
this.documentService = documentService;
}
@PostMapping
public ResponseEntity<Document> uploadFile(@RequestPart MultipartFile file) throws IOException {
System.out.println(file.getName());
return documentService.add(file)
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.noContent().build());
}
// @GetMapping("/{id}")
// public ResponseEntity<InputStreamResource> getFile(@PathVariable(value = "id") Long id) {
// return
// }
}
......@@ -4,10 +4,7 @@ import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.services.PrivacyChoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
......@@ -33,4 +30,11 @@ public class GatewayController {
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.noContent().build());
}
@GetMapping("/choice/{udn}")
public ResponseEntity<Iterable<PrivacyChoice>> readPrivacyChoiceByDevice(@PathVariable String udn) {
return Optional.ofNullable(privacyChoiceService.readPrivacyChoiceByDevice(udn))
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.noContent().build());
}
}
package edu.prlab.tyler.iotgateway.cloud.pojo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Document {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
private String fileName;
}
......@@ -6,10 +6,7 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
@Data
@Builder
......@@ -23,6 +20,7 @@ public class Model {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
@Column(length=1024)
private String url;
private String description;
}
package edu.prlab.tyler.iotgateway.cloud.pojo.privacy;
import edu.prlab.tyler.iotgateway.cloud.pojo.Document;
import edu.prlab.tyler.iotgateway.cloud.pojo.device.Device;
import lombok.AllArgsConstructor;
import lombok.Builder;
......@@ -31,4 +32,8 @@ public class PrivacyPolicyReport {
@JoinColumn(name = "policy_id")
@ElementCollection(targetClass = PrivacyPolicy.class)
private List<PrivacyPolicy> policies ;
@OneToOne
@JoinColumn(name = "document_id")
private Document document;
}
package edu.prlab.tyler.iotgateway.cloud.repositories;
import edu.prlab.tyler.iotgateway.cloud.pojo.Document;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DocumentRepository extends CrudRepository<Document, Long> {
}
package edu.prlab.tyler.iotgateway.cloud.repositories;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyChoice;
import edu.prlab.tyler.iotgateway.cloud.pojo.privacy.PrivacyContent;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface PrivacyChoiceRepository extends CrudRepository<PrivacyChoice, Long> {
Optional<Iterable<PrivacyChoice>> findPrivacyChoicesByPrivacyContent(PrivacyContent privacyContent);
}
package edu.prlab.tyler.iotgateway.cloud.services;
import edu.prlab.tyler.iotgateway.cloud.pojo.Document;
import edu.prlab.tyler.iotgateway.cloud.repositories.DocumentRepository;
import edu.prlab.tyler.iotgateway.cloud.services.storage.StorageService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.Optional;
@Service
public class DocumentService {
private DocumentRepository documentRepository;
private StorageService storageService;
public DocumentService(DocumentRepository repository,
StorageService storageService) {
this.documentRepository = repository;
this.storageService = storageService;
}
public Optional<Document> add(MultipartFile file) {
return Optional.ofNullable(storageService.store(file))
.map(filename -> Document.builder()
.fileName(filename)
.build())
.map(document->documentRepository.save(document));
}
}
......@@ -5,10 +5,20 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.stream.StreamSupport;
@Service
public class PrivacyChoiceService extends CrudService<PrivacyChoice, Long>{
@Autowired
public PrivacyChoiceService(CrudRepository<PrivacyChoice, Long> repository) {
super(repository);
}
public Iterable<PrivacyChoice> readPrivacyChoiceByDevice(String udn) {
return ()-> StreamSupport.stream(readll().spliterator(),false)
.filter(choice->choice.getPrivacyContent().getDevice().getUdn().equals(udn))
.iterator();
}
}
package edu.prlab.tyler.iotgateway.cloud.services.storage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.stream.Stream;
@Service
public class StorageService {
private final Path rootLocation;
@Autowired
public StorageService(@Value("${storage.location}") String rootLocation) {
this.rootLocation = Paths.get(rootLocation);
}
@PostConstruct
public void init() {
try {
deleteAll();
Files.createDirectories(rootLocation);
} catch (IOException e) {
throw new RuntimeException("Could not initialize storage location", e);
}
}
public String store(MultipartFile file) {
String filename = StringUtils.cleanPath(file.getOriginalFilename());
try {
if (file.isEmpty()) {
throw new RuntimeException("Failed to store empty file " + filename);
}
if (filename.contains("..")) {
// This is a security check
throw new RuntimeException(
"Cannot store file with relative path outside current directory "
+ filename);
}
try (InputStream inputStream = file.getInputStream()) {
Files.copy(inputStream, this.rootLocation.resolve(filename),
StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
throw new RuntimeException("Failed to store file " + filename, e);
}
return filename;
}
public Stream<Path> loadAll() {
try {
return Files.walk(this.rootLocation, 1)
.filter(path -> !path.equals(this.rootLocation))
.map(this.rootLocation::relativize);
} catch (IOException e) {
throw new RuntimeException("Failed to read stored files", e);
}
}
public Path load(String filename) {
return rootLocation.resolve(filename);
}
public Resource loadAsResource(String filename) {
try {
Path file = load(filename);
Resource resource = new UrlResource(file.toUri());
if (resource.exists() || resource.isReadable()) {
return resource;
} else {
throw new RuntimeException(
"Could not read file: " + filename);
}
} catch (MalformedURLException e) {
throw new RuntimeException("Could not read file: " + filename, e);
}
}
public void deleteAll() {
FileSystemUtils.deleteRecursively(rootLocation.toFile());
}
}
......@@ -5,4 +5,8 @@ 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
spring.jpa.generate-ddl=true
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
storage.location=./uploads
\ No newline at end of file
......@@ -209,5 +209,16 @@ public class CloudHttpApiTest {
new TypeReference<Iterable<PrivacyChoice>>(){});
Assert.assertNotNull(privacyChoices);
result = mvc.perform(MockMvcRequestBuilders
.get("/choice/"+device.getUdn())
.accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(print())
.andExpect(status().isOk())
.andReturn();
privacyChoices = mapper.readValue(result.getResponse().getContentAsString(),
new TypeReference<Iterable<PrivacyChoice>>(){});
Assert.assertNotNull(privacyChoices);
}
}
buildscript {
ext {
springBootVersion = '2.1.4.RELEASE'
web3jQuorumVersion = '4.0.6'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
ext {
springBootVersion = '2.1.4.RELEASE'
web3jQuorumVersion = '4.0.6'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'edu.prlab.tyler.iotgateway'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.web3j:quorum:${web3jQuorumVersion}"
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.2")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
}
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.web3j:quorum:${web3jQuorumVersion}"
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.2")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.2")
}
\ No newline at end of file
#Fri Apr 19 15:42:32 CST 2019
gradle.version=5.2.1
#Thu May 16 18:00:30 CST 2019
gradle.version=4.10.3
......@@ -12,6 +12,7 @@ buildscript {
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
......@@ -19,25 +20,34 @@ group = 'edu.prlab.tyler.iotgateway'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
implementation project(":cloud")
implementation project(":contract")
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
jar {
enabled = true
}
bootJar {
enabled = false
classifier = 'boot'
manifest {
attributes 'Start-Class': 'edu.prlab.tyler.iotgateway.gateway.GatewayApplication'
attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
}
}
\ No newline at end of file
server.port=8080
iotgateway.cloud.address = http://127.0.0.1:8081
\ No newline at end of file
......@@ -8,5 +8,5 @@ rootProject.name = 'gateway'
include ":cloud"
project(":cloud").projectDir = file("../cloud")
include ":contract"
project(":contract").projectDir = file("../contract")
\ No newline at end of file
//include ":contract"
//project(":contract").projectDir = file("../contract")
\ No newline at end of file
......@@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.domain.EntityScan;
import javax.persistence.Entity;
@SpringBootApplication
@EntityScan(basePackages = "edu.prlab.tyler.iotgateway")
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
......
rootProject.name = 'iotgateway'
include ':gateway'
include ':cloud'
include ':contract'
\ No newline at end of file
include ':gateway', ':cloud', ':contract'
\ No newline at end of file
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