Skip to content

Commit

Permalink
Added data type to partitions and slices
Browse files Browse the repository at this point in the history
  • Loading branch information
slaurenz committed Mar 3, 2022
1 parent 91a6321 commit bba6ebf
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import eu.europa.ec.dgc.revocationdistribution.dto.PartitionChunksJsonItemDto;
import eu.europa.ec.dgc.revocationdistribution.model.SliceType;
import java.time.ZonedDateTime;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Expand Down Expand Up @@ -106,6 +109,13 @@ public class PartitionEntity {
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "UTC")
private ZonedDateTime expired;

/**
* The type of the binary data e.g. BLOOMFILTER or VARHASHLIST
*/
@Column(name = "data_type")
@Enumerated(EnumType.STRING)
private SliceType dataType;

/**
* The hashes of the chunk.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
package eu.europa.ec.dgc.revocationdistribution.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import eu.europa.ec.dgc.revocationdistribution.model.SliceType;
import java.time.ZonedDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Expand Down Expand Up @@ -60,7 +63,7 @@ public class SliceEntity {
private String kid;

/**
* Id .
* Id.
*/
@Column(name = "partition_id")
private String id;
Expand All @@ -72,7 +75,7 @@ public class SliceEntity {
private String chunk;

/**
* chunk of slice.
* hash of slice.
*/
@Column(name = "hash")
private String hash;
Expand All @@ -97,6 +100,13 @@ public class SliceEntity {
@Column(name = "slice_binary_data")
private byte[] binaryData;

/**
* The type of the binary data e.g. BLOOMFILTER or VARHASHLIST
*/
@Column(name = "data_type")
@Enumerated(EnumType.STRING)
private SliceType dataType;

/**
* Indicates if the slice needs to be deleted on etag change.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public enum SliceType {
BLOOMFILTER,
HASHLIST
VARHASHLIST
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import eu.europa.ec.dgc.revocationdistribution.mapper.VectorViewMapper;
import eu.europa.ec.dgc.revocationdistribution.model.ChangeList;
import eu.europa.ec.dgc.revocationdistribution.model.ChangeListItem;
import eu.europa.ec.dgc.revocationdistribution.model.SliceType;
import eu.europa.ec.dgc.revocationdistribution.repository.CoordinateViewRepository;
import eu.europa.ec.dgc.revocationdistribution.repository.KidViewRepository;
import eu.europa.ec.dgc.revocationdistribution.repository.PartitionRepository;
Expand Down Expand Up @@ -313,7 +314,8 @@ private void generatePartition(List<ChunkMetaViewDto> entities,
chunksJson.put(mve.getChunk(), chunkItemsMap);

saveSlice(mve.getKid(), id, mve.getChunk(), sliceDataDto.getMetaData().getHash(),
mve.getLastUpdated(), mve.getExpired(), sliceDataDto.getBinaryData());
mve.getLastUpdated(), mve.getExpired(), sliceCalculationService.getSliceType(),
sliceDataDto.getBinaryData());

x = mve.getX();
y = mve.getY();
Expand All @@ -331,7 +333,7 @@ private void generatePartition(List<ChunkMetaViewDto> entities,
}

private void saveSlice(String kid, String id, String chunk, String hash,
ZonedDateTime lastUpdated, ZonedDateTime expired, byte[] binaryData) {
ZonedDateTime lastUpdated, ZonedDateTime expired, SliceType dataType, byte[] binaryData) {

SliceEntity sliceEntity = new SliceEntity();

Expand All @@ -342,6 +344,7 @@ private void saveSlice(String kid, String id, String chunk, String hash,
sliceEntity.setHash(hash);
sliceEntity.setLastUpdated(lastUpdated);
sliceEntity.setExpired(expired);
sliceEntity.setDataType(dataType);
sliceEntity.setBinaryData(binaryData);
sliceEntity.setToBeDeleted(false);

Expand All @@ -364,6 +367,7 @@ private void savePartition(String kid, String id, String x, String y, String z,
partitionEntity.setZ(z);
partitionEntity.setLastUpdated(lastUpdated);
partitionEntity.setExpired(expired);
partitionEntity.setDataType(SliceType.BLOOMFILTER);
partitionEntity.setChunks(chunksJson);
partitionEntity.setToBeDeleted(false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
package eu.europa.ec.dgc.revocationdistribution.service;

import eu.europa.ec.dgc.revocationdistribution.dto.SliceDataDto;
import eu.europa.ec.dgc.revocationdistribution.model.SliceType;

public interface SliceCalculation {

SliceType getSliceType();

SliceDataDto calculateSlice(String[] hashes);


}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class SliceCalculationBloomFilterImpl implements SliceCalculation {
private final DgcConfigProperties properties;
private final HelperFunctions helperFunctions;


@Override
public SliceType getSliceType() {
return SliceType.BLOOMFILTER;
}

@Override
public SliceDataDto calculateSlice(String[] hashes) {
if (hashes.length <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class SliceCalculationHashListImpl implements SliceCalculation {
private final HelperFunctions helperFunctions;
private static final int NUMBER_OF_BYTES_TO_STORE = 2;

@Override
public SliceType getSliceType() {
return SliceType.VARHASHLIST;
}

@Override
public SliceDataDto calculateSlice(String[] hashes) {
if (hashes.length <= 0) {
Expand All @@ -56,7 +61,7 @@ public SliceDataDto calculateSlice(String[] hashes) {

SliceDataDto sliceDataDto = new SliceDataDto();

sliceDataDto.getMetaData().setType(SliceType.HASHLIST.name());
sliceDataDto.getMetaData().setType(SliceType.VARHASHLIST.name());
sliceDataDto.getMetaData().setVersion(properties.getHashList().getVersion());

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS partitions
expired timestamp with time zone,
lastupdated timestamp with time zone,
to_be_deleted boolean,
data_type text COLLATE pg_catalog."default",
chunks_json_data jsonb,
CONSTRAINT partitions_pkey PRIMARY KEY (db_id)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CREATE TABLE IF NOT EXISTS slices
expired timestamp with time zone,
lastupdated timestamp with time zone,
to_be_deleted boolean,
data_type text COLLATE pg_catalog."default",
slice_binary_data bytea,
CONSTRAINT slices_pkey PRIMARY KEY (db_id)
)
Expand Down

0 comments on commit bba6ebf

Please sign in to comment.