Skip to content

Commit 6137d31

Browse files
authored
added de- and serialisation for blobby resource (#1180)
1 parent ee83645 commit 6137d31

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

portability-types-common/src/main/java/org/datatransferproject/types/common/models/ContainerResource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonSubTypes;
2020
import com.fasterxml.jackson.annotation.JsonTypeInfo;
21+
import org.datatransferproject.types.common.models.blob.BlobbyStorageContainerResource;
2122
import org.datatransferproject.types.common.models.calendar.CalendarContainerResource;
2223
import org.datatransferproject.types.common.models.mail.MailContainerResource;
2324
import org.datatransferproject.types.common.models.media.MediaContainerResource;
@@ -46,6 +47,7 @@
4647
@JsonSubTypes.Type(SocialActivityContainerResource.class),
4748
@JsonSubTypes.Type(IdOnlyContainerResource.class),
4849
@JsonSubTypes.Type(DateRangeContainerResource.class),
49-
@JsonSubTypes.Type(MusicContainerResource.class)
50+
@JsonSubTypes.Type(MusicContainerResource.class),
51+
@JsonSubTypes.Type(BlobbyStorageContainerResource.class)
5052
})
5153
public abstract class ContainerResource extends DataModel {}

portability-types-common/src/main/java/org/datatransferproject/types/common/models/blob/DigitalDocumentWrapper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.datatransferproject.types.common.models.blob;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import java.util.Map;
57
import org.datatransferproject.types.common.models.DataModel;
68

79
/**
@@ -10,6 +12,7 @@
1012
* this class represent DTP specific data that doesn't fit into the schema.org representation.
1113
*/
1214
public class DigitalDocumentWrapper extends DataModel {
15+
1316
private final DtpDigitalDocument dtpDigitalDocument;
1417
private final String originalEncodingFormat;
1518
// This isn't in the schema.org spec and is only needed to store the bytes DTP will transfer
@@ -37,4 +40,10 @@ public String getCachedContentId() {
3740
public String getOriginalEncodingFormat() {
3841
return originalEncodingFormat;
3942
}
43+
44+
@JsonIgnore
45+
@Override
46+
public Map<String, Integer> getCounts() {
47+
return super.getCounts();
48+
}
4049
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2022 The Data Transfer Project Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.datatransferproject.types.common.models.blob;
18+
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import com.google.common.collect.ImmutableList;
21+
import com.google.common.truth.Truth;
22+
import org.datatransferproject.types.common.models.ContainerResource;
23+
import org.junit.jupiter.api.Test;
24+
25+
class BlobbyStorageContainerResourceTest {
26+
27+
@Test
28+
public void verifySerializeDeserialize() throws Exception {
29+
ObjectMapper objectMapper = new ObjectMapper();
30+
objectMapper.registerSubtypes(BlobbyStorageContainerResource.class);
31+
32+
DigitalDocumentWrapper documentWrapper = new DigitalDocumentWrapper(
33+
new DtpDigitalDocument("doc-name", "2020-02-02", "UTF-8"), "UTF-8", "123456");
34+
BlobbyStorageContainerResource containerResource = new BlobbyStorageContainerResource("name",
35+
"id", ImmutableList.of(documentWrapper), ImmutableList.of());
36+
String serialized = objectMapper.writeValueAsString(containerResource);
37+
38+
ContainerResource deserializedModel = objectMapper.readValue(serialized,
39+
ContainerResource.class);
40+
41+
Truth.assertThat(deserializedModel).isNotNull();
42+
Truth.assertThat(deserializedModel).isInstanceOf(BlobbyStorageContainerResource.class);
43+
BlobbyStorageContainerResource deserialized = (BlobbyStorageContainerResource) deserializedModel;
44+
Truth.assertThat(deserialized.getFiles()).hasSize(1);
45+
Truth.assertThat(deserialized.getFolders()).isEmpty();
46+
}
47+
}

0 commit comments

Comments
 (0)