-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into remove-partial-publishing
- Loading branch information
Showing
29 changed files
with
801 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Part of NDLA taxonomy-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.taxonomy.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
public enum Grade { | ||
One(1), | ||
Two(2), | ||
Three(3), | ||
Four(4), | ||
Five(5); | ||
|
||
private final int value; | ||
|
||
Grade(int value) { | ||
this.value = value; | ||
} | ||
|
||
@JsonValue | ||
public int toInt() { | ||
return value; | ||
} | ||
|
||
public static Grade fromInt(Integer value) { | ||
return switch (value) { | ||
case 1 -> One; | ||
case 2 -> Two; | ||
case 3 -> Three; | ||
case 4 -> Four; | ||
case 5 -> Five; | ||
default -> throw new IllegalArgumentException("Unexpected grade value: " + value + ". Must be 1-5."); | ||
}; | ||
} | ||
} |
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,36 @@ | ||
/* | ||
* Part of NDLA taxonomy-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.taxonomy.domain; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public class GradeAverage { | ||
public GradeAverage(double averageValue, int count) { | ||
this.averageValue = averageValue; | ||
this.count = count; | ||
} | ||
|
||
double averageValue; | ||
int count; | ||
|
||
public static GradeAverage fromGrades(Collection<Optional<Grade>> grades) { | ||
var existing = grades.stream().flatMap(Optional::stream).toList(); | ||
var count = existing.size(); | ||
var avg = existing.stream().mapToInt(Grade::toInt).average().orElse(0.0); | ||
return new GradeAverage(avg, count); | ||
} | ||
|
||
public double getAverageValue() { | ||
return averageValue; | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
} |
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,24 @@ | ||
/* | ||
* Part of NDLA taxonomy-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.taxonomy.domain; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
|
||
public class GradeConverter implements AttributeConverter<Grade, Integer> { | ||
@Override | ||
public Integer convertToDatabaseColumn(Grade grade) { | ||
if (grade == null) return null; | ||
return grade.toInt(); | ||
} | ||
|
||
@Override | ||
public Grade convertToEntityAttribute(Integer integer) { | ||
if (integer == null) return null; | ||
return Grade.fromInt(integer); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/no/ndla/taxonomy/domain/NullOrUndefined.java
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,20 @@ | ||
/* | ||
* Part of NDLA taxonomy-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.taxonomy.domain; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** An annotation to indicate that a field can be null or undefined in the generated typescript. */ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
public @interface NullOrUndefined {} |
31 changes: 31 additions & 0 deletions
31
src/main/java/no/ndla/taxonomy/domain/QualityEvaluationDTODeserializer.java
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,31 @@ | ||
/* | ||
* Part of NDLA taxonomy-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.taxonomy.domain; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.Optional; | ||
import no.ndla.taxonomy.service.dtos.QualityEvaluationDTO; | ||
|
||
public class QualityEvaluationDTODeserializer extends UpdateOrDelete.Deserializer<QualityEvaluationDTO> { | ||
private Optional<String> getNote(JsonNode node) { | ||
var hasNote = node.has("note"); | ||
var noteNode = node.get("note"); | ||
if (hasNote && noteNode.isTextual()) { | ||
return Optional.of(node.get("note").asText()); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
protected QualityEvaluationDTO deserializeInner(JsonNode node) { | ||
var gradeInt = node.get("grade").asInt(); | ||
var grade = Grade.fromInt(gradeInt); | ||
var note = getNote(node); | ||
return new QualityEvaluationDTO(grade, note); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/no/ndla/taxonomy/domain/QualityEvaluationDTOSerializer.java
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,22 @@ | ||
/* | ||
* Part of NDLA taxonomy-api | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.taxonomy.domain; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import java.io.IOException; | ||
import no.ndla.taxonomy.service.dtos.QualityEvaluationDTO; | ||
|
||
public class QualityEvaluationDTOSerializer extends UpdateOrDelete.Serializer<QualityEvaluationDTO> { | ||
@Override | ||
protected void serializeInner( | ||
QualityEvaluationDTO value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) | ||
throws IOException { | ||
jsonGenerator.writeObject(value); | ||
} | ||
} |
Oops, something went wrong.