Skip to content

Commit

Permalink
Add to prepare image
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbonte21 committed Sep 8, 2023
1 parent 4a47ac3 commit b039a89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ on:
- development
- master
- lineageondemand
- rawquerymigration

jobs:
build:
Expand Down
29 changes: 22 additions & 7 deletions webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.apache.commons.collections4.MapUtils.emptyIfNull;
import static org.apache.atlas.AtlasErrorCode.BAD_REQUEST;
import static org.apache.atlas.AtlasErrorCode.DEPRECATED_API;
import static org.apache.atlas.authorize.AtlasPrivilege.*;
Expand All @@ -93,6 +94,10 @@ public class EntityREST {
public static final String PREFIX_ATTR_ = "attr_";
public static final String QUALIFIED_NAME = "qualifiedName";
private static final int HUNDRED_THOUSAND = 100000;
private static final int TWO_MILLION = HUNDRED_THOUSAND * 10 * 2;
private static final Set<String> ATTRS_WITH_TWO_MILLION_LIMIT = new HashSet<String>() {{
add("rawQueryText");
}};


private final AtlasTypeRegistry typeRegistry;
Expand Down Expand Up @@ -899,15 +904,25 @@ public EntityMutationResponse createOrUpdate(AtlasEntitiesWithExtInfo entities,
}

public static void validateAttributeLength(final List<AtlasEntity> entities) throws AtlasBaseException {
//Predicate to check attribute value exceeding length
Predicate<Map.Entry<String, Object>> predicateOfAttributeLengthExceedingLimit = attribute ->
attribute.getValue() instanceof String && ((String) attribute.getValue()).length() > HUNDRED_THOUSAND;
List<String> errorMessages = new ArrayList<>();

for (final AtlasEntity atlasEntity : entities) {
Set<String> attributeKeys = org.apache.commons.collections4.MapUtils.emptyIfNull(atlasEntity.getAttributes())
.entrySet().stream().filter(predicateOfAttributeLengthExceedingLimit).map(Map.Entry::getKey).collect(Collectors.toSet());
if (!attributeKeys.isEmpty()) {
throw new AtlasBaseException("Attribute(s) " + String.join(",", attributeKeys) + " exceeds limit of "+HUNDRED_THOUSAND+" characters");
for (Map.Entry<String, Object> attribute : atlasEntity.getAttributes().entrySet()) {

if (attribute.getValue() instanceof String && ((String) attribute.getValue()).length() > HUNDRED_THOUSAND) {

if (ATTRS_WITH_TWO_MILLION_LIMIT.contains(attribute.getKey())) {
if (((String) attribute.getValue()).length() > TWO_MILLION) {
errorMessages.add("Attribute " + attribute.getKey() + " exceeds limit of " + TWO_MILLION + " characters");
}
} else {
errorMessages.add("Attribute " + attribute.getKey() + " exceeds limit of " + HUNDRED_THOUSAND + " characters");
}
}
}

if (errorMessages.size() > 0) {
throw new AtlasBaseException(AtlasType.toJson(errorMessages));
}
}
}
Expand Down

0 comments on commit b039a89

Please sign in to comment.