-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODINV-1012: Implementation for Validation for NatureContentTerms add…
…ed for Instance. Tests added. (#715) * MODINV-1012: Implementation for Validation for NatureContentTerms added for Instance. Tests added. * MODINV-1012: Documentation added. * MODINV-1012: Documentation added. * MODINV-1012: Tests added. (cherry picked from commit 2019a17)
- Loading branch information
1 parent
cdec7ba
commit a8d77b0
Showing
6 changed files
with
281 additions
and
3 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
48 changes: 48 additions & 0 deletions
48
src/main/java/org/folio/inventory/dataimport/util/ValidationUtil.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,48 @@ | ||
package org.folio.inventory.dataimport.util; | ||
|
||
import org.folio.inventory.domain.instances.Instance; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Util for detailed validation different entities. | ||
*/ | ||
public class ValidationUtil { | ||
|
||
private ValidationUtil() { | ||
} | ||
|
||
/** | ||
* Validate fields inside the Instance entity. Validation based on checking if specific fields were mapped as UUIDs. | ||
* If not - then the list with errors will be returned. | ||
* Example: "Value 'invalid not UUID value' is not a UUID for someFieldName field" | ||
* @param instance target Instance for validation | ||
* @return ArrayList with errors when the needed fields are NOT as UUID. | ||
*/ | ||
public static List<String> validateUUIDs(Instance instance) { | ||
ArrayList<String> errorMessages = new ArrayList<>(); | ||
|
||
//TODO: This will be extended for different fields and entities.That's why there are so many methods just for 1 field. | ||
// Branch for it extending validation: MODINV-1012-extended | ||
validateField(errorMessages, instance.getNatureOfContentTermIds(), "natureOfContentTermIds"); | ||
|
||
return errorMessages; | ||
} | ||
|
||
private static void validateField(List<String> errorMessages, List<String> values, String fieldName) { | ||
values.stream() | ||
.filter(value -> !isUUID(value)) | ||
.forEach(value -> errorMessages.add(String.format("Value '%s' is not a UUID for %s field", value, fieldName))); | ||
} | ||
|
||
private static boolean isUUID(String value) { | ||
try { | ||
UUID.fromString(value); | ||
return true; | ||
} catch (Exception ex) { | ||
return false; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.