mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-26 09:55:52 +00:00
Small refactor to be able to print correct message when reviewer is invalid (#19810)
This commit is contained in:
parent
e4c34210ec
commit
2cb51f71cd
@ -50,6 +50,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import javax.ws.rs.core.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
@ -193,7 +194,11 @@ public abstract class EntityCsv<T extends EntityInterface> {
|
||||
}
|
||||
|
||||
/** Owner field is in entityType:entityName format */
|
||||
public List<EntityReference> getOwners(CSVPrinter printer, CSVRecord csvRecord, int fieldNumber)
|
||||
public List<EntityReference> getOwners(
|
||||
CSVPrinter printer,
|
||||
CSVRecord csvRecord,
|
||||
int fieldNumber,
|
||||
Function<Integer, String> invalidMessageCreator)
|
||||
throws IOException {
|
||||
if (!processRecord) {
|
||||
return null;
|
||||
@ -207,7 +212,7 @@ public abstract class EntityCsv<T extends EntityInterface> {
|
||||
for (String owner : owners) {
|
||||
List<String> ownerTypes = listOrEmpty(CsvUtil.fieldToEntities(owner));
|
||||
if (ownerTypes.size() != 2) {
|
||||
importFailure(printer, invalidOwner(fieldNumber), csvRecord);
|
||||
importFailure(printer, invalidMessageCreator.apply(fieldNumber), csvRecord);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
EntityReference ownerRef =
|
||||
@ -219,6 +224,16 @@ public abstract class EntityCsv<T extends EntityInterface> {
|
||||
return refs.isEmpty() ? null : refs;
|
||||
}
|
||||
|
||||
public List<EntityReference> getOwners(CSVPrinter printer, CSVRecord csvRecord, int fieldNumber)
|
||||
throws IOException {
|
||||
return getOwners(printer, csvRecord, fieldNumber, EntityCsv::invalidOwner);
|
||||
}
|
||||
|
||||
public List<EntityReference> getReviewers(
|
||||
CSVPrinter printer, CSVRecord csvRecord, int fieldNumber) throws IOException {
|
||||
return getOwners(printer, csvRecord, fieldNumber, EntityCsv::invalidReviewer);
|
||||
}
|
||||
|
||||
/** Owner field is in entityName format */
|
||||
public EntityReference getOwnerAsUser(CSVPrinter printer, CSVRecord csvRecord, int fieldNumber)
|
||||
throws IOException {
|
||||
@ -868,6 +883,11 @@ public abstract class EntityCsv<T extends EntityInterface> {
|
||||
return String.format(FIELD_ERROR_MSG, CsvErrorType.INVALID_FIELD, field + 1, error);
|
||||
}
|
||||
|
||||
public static String invalidReviewer(int field) {
|
||||
String error = "Reviewer should be of format user:userName or team:teamName";
|
||||
return String.format(FIELD_ERROR_MSG, CsvErrorType.INVALID_FIELD, field + 1, error);
|
||||
}
|
||||
|
||||
public static String invalidExtension(int field, String key, String value) {
|
||||
String error =
|
||||
"Invalid key-value pair in extension string: Key = "
|
||||
|
@ -200,7 +200,7 @@ public class GlossaryRepository extends EntityRepository<Glossary> {
|
||||
.withTags(
|
||||
getTagLabels(
|
||||
printer, csvRecord, List.of(Pair.of(7, TagLabel.TagSource.CLASSIFICATION))))
|
||||
.withReviewers(getOwners(printer, csvRecord, 8))
|
||||
.withReviewers(getReviewers(printer, csvRecord, 8))
|
||||
.withOwners(getOwners(printer, csvRecord, 9))
|
||||
.withStatus(getTermStatus(printer, csvRecord))
|
||||
.withExtension(getExtension(printer, csvRecord, 11));
|
||||
|
Loading…
x
Reference in New Issue
Block a user