Report.kt 2.32 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Media Linker
 * Copyright (C) 2020 Memoriav
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package org.memobase

21
import com.beust.klaxon.Klaxon
22
import java.time.LocalDateTime
23

24
data class FinalReport(
Jonas Waeber's avatar
Jonas Waeber committed
25
    val id: String,
26
27
    val status: String,
    val message: String,
28
29
    val step: String = "media-linker",
    val timestamp: String = LocalDateTime.now().toString()
30
) {
31
32
33
34
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

35
        other as FinalReport
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

        if (id != other.id) return false
        if (status != other.status) return false
        if (message != other.message) return false
        if (step != other.step) return false

        return true
    }

    override fun hashCode(): Int {
        var result = id.hashCode()
        result = 31 * result + status.hashCode()
        result = 31 * result + message.hashCode()
        result = 31 * result + step.hashCode()
        return result
    }
52
}
53
54
55

data class Report(
    val id: String,
56
    val status: String,
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    val generalFailureMessage: String = "",
    val digitalObjectMessage: String = "", // "ok, thumbnail created" oder "ok, no thumbnail"
    val thumbnailMessage: String = ""
) {
    fun toJson(): String {
        val message =
            if (generalFailureMessage != "") {
                generalFailureMessage
            } else {
                (if (digitalObjectMessage != "") "DIGITAL OBJECT: $digitalObjectMessage" else "") +
                        (if (thumbnailMessage != "") " -- THUMBNAIL: $thumbnailMessage" else "")
            }
        val finalReport = FinalReport(this.id, this.status, message)
        return Klaxon().toJsonString(finalReport)
    }
}