Skip to content

Commit

Permalink
Merge pull request 'release_1.1.6' (#10) from release_1.1.6 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Oct 25, 2024
2 parents 494e9d9 + 319fe30 commit 8a09acd
Show file tree
Hide file tree
Showing 24 changed files with 142 additions and 26 deletions.
4 changes: 2 additions & 2 deletions module-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server-core</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<name>Vocabulary-Server-Core</name>
<description>Spring Boot based RESTful web service for vocabulary management</description>
<packaging>jar</packaging>
Expand All @@ -26,7 +26,7 @@
<dependency>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server-exchange</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.goobi.vocabulary.api;

import io.goobi.vocabulary.service.manager.MaintenanceManager;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/maintenance")
public class MaintenanceController {
private final MaintenanceManager maintenanceManager;

public MaintenanceController(MaintenanceManager maintenanceManager) {
this.maintenanceManager = maintenanceManager;
}

@GetMapping("/selfcheck")
public ResponseEntity<String> selfCheck() {
String status = maintenanceManager.testAllData();
if (status.contains("FAIL")) {
return ResponseEntity.internalServerError()
.body(status);
} else {
return ResponseEntity.ok()
.body(status);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
})
@Getter
@Setter
public class FieldDefinitionEntity {
public class FieldDefinitionEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Table(name = "field_instance")
@Getter
@Setter
public class FieldInstanceEntity {
public class FieldInstanceEntity implements Identifiable {
private static final int MAX_LANGUAGE_LENGTH = 3;

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Table(name = "field_translation")
@Getter
@Setter
public class FieldTranslationEntity {
public class FieldTranslationEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Table(name = "field_type")
@Getter
@Setter
public class FieldTypeEntity {
public class FieldTypeEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Table(name = "field_value")
@Getter
@Setter
public class FieldValueEntity {
public class FieldValueEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.goobi.vocabulary.model.jpa;

public interface Identifiable {
long getId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Table(name = "language")
@Getter
@Setter
public class LanguageEntity {
public class LanguageEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Table(name = "selectable_value")
@Getter
@Setter
public class SelectableValueEntity {
public class SelectableValueEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
})
@Getter
@Setter
public class TranslationDefinitionEntity {
public class TranslationDefinitionEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Table(name = "vocabulary")
@Getter
@Setter
public class VocabularyEntity {
public class VocabularyEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Getter
@Setter
// Naming this class `Record` led to wrong behavior because of the introduction of Java records and some Spring Boot JPA logic
public class VocabularyRecordEntity {
public class VocabularyRecordEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Table(name = "vocabulary_schema")
@Getter
@Setter
public class VocabularySchemaEntity {
public class VocabularySchemaEntity implements Identifiable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import io.goobi.vocabulary.model.jpa.FieldTypeEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.lang.NonNull;

import java.util.Optional;

public interface FieldTypeRepository extends CrudRepository<FieldTypeEntity, Long> {
public interface FieldTypeRepository extends ListCrudRepository<FieldTypeEntity, Long> {
Page<FieldTypeEntity> findAll(Pageable pageable);

Optional<FieldTypeEntity> findByName(@NonNull String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import io.goobi.vocabulary.model.jpa.LanguageEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.lang.NonNull;

import java.util.Optional;

public interface LanguageRepository extends CrudRepository<LanguageEntity, Long> {
public interface LanguageRepository extends ListCrudRepository<LanguageEntity, Long> {
Optional<LanguageEntity> findByAbbreviation(@NonNull String abbreviation);

Page<LanguageEntity> findAll(Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.lang.NonNull;

import java.util.List;
import java.util.Optional;

public interface VocabularyRecordRepository extends CrudRepository<VocabularyRecordEntity, Long> {
public interface VocabularyRecordRepository extends ListCrudRepository<VocabularyRecordEntity, Long> {
@Override
Optional<VocabularyRecordEntity> findById(Long aLong);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.goobi.vocabulary.service.exchange;

import io.goobi.vocabulary.api.assemblers.RecordAssembler;
import io.goobi.vocabulary.exception.EntityNotFoundException;
import io.goobi.vocabulary.exception.MissingAttributeException;
import io.goobi.vocabulary.exchange.FieldDefinition;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package io.goobi.vocabulary.service.manager;

import io.goobi.vocabulary.exception.VocabularyException;
import io.goobi.vocabulary.model.jpa.FieldTypeEntity;
import io.goobi.vocabulary.model.jpa.VocabularyEntity;
import io.goobi.vocabulary.model.jpa.VocabularyRecordEntity;
import io.goobi.vocabulary.model.jpa.VocabularySchemaEntity;
import io.goobi.vocabulary.repositories.FieldTypeRepository;
import io.goobi.vocabulary.repositories.VocabularyRecordRepository;
import io.goobi.vocabulary.repositories.VocabularyRepository;
import io.goobi.vocabulary.repositories.VocabularySchemaRepository;
import io.goobi.vocabulary.validation.Validator;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
public class MaintenanceManager {
private final FieldTypeRepository fieldTypeRepository;
private final VocabularyRepository vocabularyRepository;
private final VocabularySchemaRepository vocabularySchemaRepository;
private final VocabularyRecordRepository vocabularyRecordRepository;

private final Validator<FieldTypeEntity> fieldTypeValidator;
private final Validator<VocabularyEntity> vocabularyValidator;
private final Validator<VocabularySchemaEntity> vocabularySchemaValidator;
private final Validator<VocabularyRecordEntity> vocabularyRecordValidator;

public MaintenanceManager(FieldTypeRepository fieldTypeRepository, VocabularyRepository vocabularyRepository, VocabularySchemaRepository vocabularySchemaRepository, VocabularyRecordRepository vocabularyRecordRepository, Validator<FieldTypeEntity> fieldTypeValidator, Validator<VocabularyEntity> vocabularyValidator, Validator<VocabularySchemaEntity> vocabularySchemaValidator, Validator<VocabularyRecordEntity> vocabularyRecordValidator) {
this.fieldTypeRepository = fieldTypeRepository;
this.vocabularyRepository = vocabularyRepository;
this.vocabularyValidator = vocabularyValidator;
this.vocabularySchemaRepository = vocabularySchemaRepository;
this.vocabularyRecordRepository = vocabularyRecordRepository;
this.fieldTypeValidator = fieldTypeValidator;
this.vocabularySchemaValidator = vocabularySchemaValidator;
this.vocabularyRecordValidator = vocabularyRecordValidator;
}

public String testAllData() {
List<String> selfCheckResults = new LinkedList<>();

selfCheckResults.add(selfTest("Types", fieldTypeRepository, fieldTypeValidator));
selfCheckResults.add(selfTest("Vocabularies", vocabularyRepository, vocabularyValidator));
selfCheckResults.add(selfTest("Vocabulary Schemas", vocabularySchemaRepository, vocabularySchemaValidator));
selfCheckResults.add(selfTest("Vocabulary Records", vocabularyRecordRepository, vocabularyRecordValidator));

return String.join("\n", selfCheckResults);
}


private <Entity> String selfTest(String entityName, ListCrudRepository<Entity, Long> repo, Validator<Entity> validator) {
List<String> errors = new LinkedList<>();
for (Entity entity : repo.findAll()) {
try {
validator.validate(entity);
} catch (VocabularyException e) {
errors.add(dumpException(e, 1));
}
}
if (errors.isEmpty()) {
return entityName + ": OK";
} else {
return entityName + ": FAIL"
+ String.join("", errors);
}
}

private String dumpException(VocabularyException ex, int level) {
StringBuilder s = new StringBuilder();
s.append('\n')
.append("\t".repeat(level))
.append(ex.getMessage());
if (ex.getCauses() != null) {
for (VocabularyException c : ex.getCauses()) {
s.append(dumpException(c, level + 1));
}
}
return s.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package io.goobi.vocabulary.validation;

import io.goobi.vocabulary.exception.VocabularyException;
import io.goobi.vocabulary.model.jpa.Identifiable;
import lombok.Setter;

import java.util.LinkedList;
import java.util.List;

import static io.goobi.vocabulary.exception.VocabularyException.ErrorCode.GenericValidation;

public class BaseValidator<T> implements Validator<T> {
public class BaseValidator<T extends Identifiable> implements Validator<T> {
private final String name;
@Setter
private List<ValidationMethod<T>> validations;
Expand All @@ -28,7 +29,7 @@ public final void validate(T t) throws VocabularyException {
}
}
if (!errors.isEmpty()) {
throw new VocabularyException(GenericValidation, errors, null, (params) -> "Validation error");
throw new VocabularyException(GenericValidation, errors, null, (params) -> "Validation error [" + t.getId() + "]");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void checkRequiredFieldsExistence(VocabularyRecordEntity vocabularyRecor
.map(FieldDefinitionEntity::getName)
.collect(Collectors.joining(","))
),
params -> "Missing required fields: " + params.get("missingFields")
params -> "Missing required fields: " + params.get("missingFieldNames")
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static io.goobi.vocabulary.exception.VocabularyException.ErrorCode.SchemaValidationMainFieldIsNotRequired;
import static io.goobi.vocabulary.exception.VocabularyException.ErrorCode.SchemaValidationMissingMainField;
import static io.goobi.vocabulary.exception.VocabularyException.ErrorCode.SchemaValidationNoDefinitions;
import static io.goobi.vocabulary.exception.VocabularyException.ErrorCode.SchemaValidationTitleFieldsAreNotRequired;
import static io.goobi.vocabulary.exception.VocabularyException.ErrorCode.SchemaValidationTooManyMainFields;

@Service
Expand Down
2 changes: 1 addition & 1 deletion module-exchange/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server-exchange</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<name>Vocabulary Exchange</name>
<description>Vocabulary data exchange classes</description>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<name>Vocabulary-Server</name>
<packaging>pom</packaging>
<description>RESTful webservice for vocabulary management</description>
Expand Down

0 comments on commit 8a09acd

Please sign in to comment.