@Test(expected = IllegalArgumentException.class) public void remove_patch_fails() throws Exception { mapping.convertOperation(road, PatchOperation.remove("/partitionPath")); }
@Override public PatchOperation convertOperation(Road road, PatchOperation modelOperation) { checkArgument(isAddOrReplace(modelOperation), "You can only change the value of partitionPath"); checkArgument(modelOperation.getValue() instanceof String, "partitionPath must be a string"); checkArgument(StringUtils.isNotBlank((CharSequence) modelOperation.getValue()) || modelOperation.getValue() == null, "partitionPath cannot be blank, it must be null or have a value"); Path path = KeyPathParser.parse((String) modelOperation.getValue()); Map<Integer, SchemaVersion> schemas = road.getSchemas(); Integer latestSchemaVersion = schemas .values() .stream() .filter(not(SchemaVersion::isDeleted)) .map(SchemaVersion::getVersion) .max(Integer::compareTo) .orElse(null); if (latestSchemaVersion != null) { try { new KeyPathValidator(path, schemas.get(latestSchemaVersion).getSchema()).validate(); } catch (InvalidKeyPathException e) { throw new IllegalArgumentException(String.format( "partitionPath '%s' not compatible with latest schema (version %d).", path, latestSchemaVersion), e); } } return PatchOperation.replace("/partitionPath", modelOperation.getValue()); }
PartitionPathPatchMapping extends PatchMapping { @Override public PatchOperation convertOperation(Road road, PatchOperation modelOperation) { checkArgument(isAddOrReplace(modelOperation), "You can only change the value of partitionPath"); checkArgument(modelOperation.getValue() instanceof String, "partitionPath must be a string"); checkArgument(StringUtils.isNotBlank((CharSequence) modelOperation.getValue()) || modelOperation.getValue() == null, "partitionPath cannot be blank, it must be null or have a value"); Path path = KeyPathParser.parse((String) modelOperation.getValue()); Map<Integer, SchemaVersion> schemas = road.getSchemas(); Integer latestSchemaVersion = schemas .values() .stream() .filter(not(SchemaVersion::isDeleted)) .map(SchemaVersion::getVersion) .max(Integer::compareTo) .orElse(null); if (latestSchemaVersion != null) { try { new KeyPathValidator(path, schemas.get(latestSchemaVersion).getSchema()).validate(); } catch (InvalidKeyPathException e) { throw new IllegalArgumentException(String.format( "partitionPath '%s' not compatible with latest schema (version %d).", path, latestSchemaVersion), e); } } return PatchOperation.replace("/partitionPath", modelOperation.getValue()); } }
PartitionPathPatchMapping extends PatchMapping { @Override public PatchOperation convertOperation(Road road, PatchOperation modelOperation) { checkArgument(isAddOrReplace(modelOperation), "You can only change the value of partitionPath"); checkArgument(modelOperation.getValue() instanceof String, "partitionPath must be a string"); checkArgument(StringUtils.isNotBlank((CharSequence) modelOperation.getValue()) || modelOperation.getValue() == null, "partitionPath cannot be blank, it must be null or have a value"); Path path = KeyPathParser.parse((String) modelOperation.getValue()); Map<Integer, SchemaVersion> schemas = road.getSchemas(); Integer latestSchemaVersion = schemas .values() .stream() .filter(not(SchemaVersion::isDeleted)) .map(SchemaVersion::getVersion) .max(Integer::compareTo) .orElse(null); if (latestSchemaVersion != null) { try { new KeyPathValidator(path, schemas.get(latestSchemaVersion).getSchema()).validate(); } catch (InvalidKeyPathException e) { throw new IllegalArgumentException(String.format( "partitionPath '%s' not compatible with latest schema (version %d).", path, latestSchemaVersion), e); } } return PatchOperation.replace("/partitionPath", modelOperation.getValue()); }  }
PartitionPathPatchMapping extends PatchMapping { @Override public PatchOperation convertOperation(Road road, PatchOperation modelOperation) { checkArgument(isAddOrReplace(modelOperation), "You can only change the value of partitionPath"); checkArgument(modelOperation.getValue() instanceof String, "partitionPath must be a string"); checkArgument(StringUtils.isNotBlank((CharSequence) modelOperation.getValue()) || modelOperation.getValue() == null, "partitionPath cannot be blank, it must be null or have a value"); Path path = KeyPathParser.parse((String) modelOperation.getValue()); Map<Integer, SchemaVersion> schemas = road.getSchemas(); Integer latestSchemaVersion = schemas .values() .stream() .filter(not(SchemaVersion::isDeleted)) .map(SchemaVersion::getVersion) .max(Integer::compareTo) .orElse(null); if (latestSchemaVersion != null) { try { new KeyPathValidator(path, schemas.get(latestSchemaVersion).getSchema()).validate(); } catch (InvalidKeyPathException e) { throw new IllegalArgumentException(String.format( "partitionPath '%s' not compatible with latest schema (version %d).", path, latestSchemaVersion), e); } } return PatchOperation.replace("/partitionPath", modelOperation.getValue()); }  @Override String getPath(); @Override PatchOperation convertOperation(Road road, PatchOperation modelOperation); }
PartitionPathPatchMapping extends PatchMapping { @Override public PatchOperation convertOperation(Road road, PatchOperation modelOperation) { checkArgument(isAddOrReplace(modelOperation), "You can only change the value of partitionPath"); checkArgument(modelOperation.getValue() instanceof String, "partitionPath must be a string"); checkArgument(StringUtils.isNotBlank((CharSequence) modelOperation.getValue()) || modelOperation.getValue() == null, "partitionPath cannot be blank, it must be null or have a value"); Path path = KeyPathParser.parse((String) modelOperation.getValue()); Map<Integer, SchemaVersion> schemas = road.getSchemas(); Integer latestSchemaVersion = schemas .values() .stream() .filter(not(SchemaVersion::isDeleted)) .map(SchemaVersion::getVersion) .max(Integer::compareTo) .orElse(null); if (latestSchemaVersion != null) { try { new KeyPathValidator(path, schemas.get(latestSchemaVersion).getSchema()).validate(); } catch (InvalidKeyPathException e) { throw new IllegalArgumentException(String.format( "partitionPath '%s' not compatible with latest schema (version %d).", path, latestSchemaVersion), e); } } return PatchOperation.replace("/partitionPath", modelOperation.getValue()); }  @Override String getPath(); @Override PatchOperation convertOperation(Road road, PatchOperation modelOperation);  }