-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd8b9b6
commit d7449ab
Showing
12 changed files
with
212 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
backend/src/main/kotlin/project/namjun/kim/robster/analysis/AnalysisMapping.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package project.namjun.kim.robster.analysis | ||
|
||
data class AnalysisMapping( | ||
var id: String, | ||
var id: String?, | ||
var status: Boolean, | ||
var message: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
backend/src/main/kotlin/project/namjun/kim/robster/analysis/FileStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package project.namjun.kim.robster.analysis | ||
|
||
import org.springframework.core.io.Resource | ||
import org.springframework.web.multipart.MultipartFile | ||
|
||
interface FileStorage { | ||
fun storeFile(file: MultipartFile): String | ||
fun loadFile(path: String): Resource | ||
fun getFileHash(path: String): String | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/src/main/kotlin/project/namjun/kim/robster/analysis/FileStorageImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package project.namjun.kim.robster.analysis | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.core.io.Resource | ||
import org.springframework.stereotype.Service | ||
import org.springframework.web.multipart.MultipartFile | ||
import java.io.InputStream | ||
import java.nio.file.FileAlreadyExistsException | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
import java.security.MessageDigest | ||
|
||
@Service | ||
class FileStorageImpl: FileStorage { | ||
@Value("\${robster.storage}") | ||
lateinit var storage: String | ||
|
||
override fun storeFile(file: MultipartFile): String { | ||
val rootLocation: Path = Paths.get(this.storage) | ||
val filename: String = calculateHash(file.inputStream) | ||
try { | ||
Files.copy(file.inputStream, rootLocation.resolve(filename)) | ||
} catch (e: FileAlreadyExistsException) { | ||
|
||
} | ||
return Paths.get(this.storage, filename).toString() | ||
} | ||
|
||
override fun loadFile(path: String): Resource { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getFileHash(path: String): String { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
fun calculateHash(stream: InputStream): String { | ||
return MessageDigest | ||
.getInstance("SHA-256") | ||
.digest(stream.readAllBytes()) | ||
.fold("", { str, it -> str + "%02x".format(it) }) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/main/kotlin/project/namjun/kim/robster/cluster/Cluster.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package project.namjun.kim.robster.cluster | ||
|
||
import org.springframework.data.mongodb.core.mapping.Field | ||
|
||
data class Cluster ( | ||
@Field("_id") | ||
var id: String, | ||
|
||
@Field("time") | ||
var time: String | ||
) |
55 changes: 55 additions & 0 deletions
55
backend/src/main/kotlin/project/namjun/kim/robster/cluster/ClusterController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package project.namjun.kim.robster.cluster | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.data.mongodb.core.MongoTemplate | ||
import org.springframework.data.mongodb.core.find | ||
import org.springframework.data.mongodb.core.query.Criteria | ||
import org.springframework.data.mongodb.core.query.Query | ||
import org.springframework.data.mongodb.core.query.isEqualTo | ||
import org.springframework.web.bind.annotation.* | ||
import project.namjun.kim.robster.report.Report | ||
|
||
@RestController | ||
@RequestMapping("/cluster") | ||
class ClusterController { | ||
|
||
@Autowired | ||
private lateinit var mongoTemplate: MongoTemplate | ||
|
||
@GetMapping("/model/hash/{modelHash}") | ||
fun clusterModelByHash(@PathVariable("modelHash") modelHash: String): List<Cluster>? { | ||
val query: Query = Query() | ||
.addCriteria( | ||
Criteria.where("models").elemMatch( | ||
Criteria.where("hash").isEqualTo(modelHash) | ||
) | ||
) | ||
query.fields().include("_id", "time") | ||
|
||
return this.mongoTemplate.find(query, "reports") | ||
} | ||
|
||
@GetMapping("/model/type/{modelType}") | ||
fun clusterModelByType(@PathVariable("modelType") modelType: String): List<Cluster>? { | ||
val query: Query = Query() | ||
.addCriteria( | ||
Criteria.where("models").elemMatch( | ||
Criteria.where("type").isEqualTo(modelType) | ||
) | ||
) | ||
|
||
return this.mongoTemplate.find(query, "reports") | ||
} | ||
|
||
@GetMapping("/method/type/{methodType}") | ||
fun clusterMethodByType(@PathVariable("methodType") methodType: String): List<Cluster>? { | ||
val query: Query = Query() | ||
.addCriteria( | ||
Criteria.where("methods").elemMatch( | ||
Criteria.where("type").isEqualTo(methodType) | ||
) | ||
) | ||
|
||
return this.mongoTemplate.find(query, "reports") | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/src/main/kotlin/project/namjun/kim/robster/report/Report.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package project.namjun.kim.robster.report | ||
|
||
import org.springframework.data.mongodb.core.mapping.Document | ||
import org.springframework.data.mongodb.core.mapping.Field | ||
|
||
@Document(collection="reports") | ||
data class Report( | ||
@Field("_id") | ||
var id: String, | ||
|
||
@Field("time") | ||
var time: String, | ||
|
||
@Field("models") | ||
var models: List<Model>, | ||
|
||
@Field("keywords") | ||
var keywords: List<Keyword>, | ||
|
||
@Field("methods") | ||
var methods: List<Method> | ||
) | ||
|
||
data class Node( | ||
var name: String, | ||
var index: Int = 0 | ||
) | ||
|
||
data class Model( | ||
var type: String, | ||
var path: String, | ||
var hash: String, | ||
var structure: List<Node> | ||
) | ||
|
||
data class Keyword( | ||
var keyword: String, | ||
var path: String | ||
) | ||
|
||
data class Method( | ||
var type: String, | ||
var method: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
backend/src/main/kotlin/project/namjun/kim/robster/report/ReportRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package project.namjun.kim.robster.report | ||
|
||
import org.springframework.data.mongodb.repository.MongoRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface ReportRepository: MongoRepository<Report, String> { | ||
fun getReportById(reportId: String): Report | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
robster.analyzer.host=localhost | ||
robster.analyzer.port=50051 | ||
robster.engine.host=localhost | ||
robster.engine.port=50051 | ||
robster.storage=D:\\storage | ||
|
||
spring.data.mongodb.uri=mongodb://localhost:27017 | ||
spring.data.mongodb.database=robster | ||
|
||
spring.servlet.multipart.max-file-size=2GB | ||
spring.servlet.multipart.max-request-size=2GB |