-
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 pull request 'release_1.1.6' (#10) from release_1.1.6 into master
- Loading branch information
Showing
24 changed files
with
142 additions
and
26 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
29 changes: 29 additions & 0 deletions
29
module-core/src/main/java/io/goobi/vocabulary/api/MaintenanceController.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,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); | ||
} | ||
} | ||
} |
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
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
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
5 changes: 5 additions & 0 deletions
5
module-core/src/main/java/io/goobi/vocabulary/model/jpa/Identifiable.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,5 @@ | ||
package io.goobi.vocabulary.model.jpa; | ||
|
||
public interface Identifiable { | ||
long getId(); | ||
} |
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
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
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
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
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
1 change: 0 additions & 1 deletion
1
module-core/src/main/java/io/goobi/vocabulary/service/exchange/DTOMapperImpl.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
83 changes: 83 additions & 0 deletions
83
module-core/src/main/java/io/goobi/vocabulary/service/manager/MaintenanceManager.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,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(); | ||
} | ||
} |
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
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
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