Skip to content

Commit

Permalink
added de- and serialisation for blobby resource (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
xokker authored Nov 16, 2022
1 parent ee83645 commit 6137d31
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.datatransferproject.types.common.models.blob.BlobbyStorageContainerResource;
import org.datatransferproject.types.common.models.calendar.CalendarContainerResource;
import org.datatransferproject.types.common.models.mail.MailContainerResource;
import org.datatransferproject.types.common.models.media.MediaContainerResource;
Expand Down Expand Up @@ -46,6 +47,7 @@
@JsonSubTypes.Type(SocialActivityContainerResource.class),
@JsonSubTypes.Type(IdOnlyContainerResource.class),
@JsonSubTypes.Type(DateRangeContainerResource.class),
@JsonSubTypes.Type(MusicContainerResource.class)
@JsonSubTypes.Type(MusicContainerResource.class),
@JsonSubTypes.Type(BlobbyStorageContainerResource.class)
})
public abstract class ContainerResource extends DataModel {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.datatransferproject.types.common.models.blob;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import org.datatransferproject.types.common.models.DataModel;

/**
Expand All @@ -10,6 +12,7 @@
* this class represent DTP specific data that doesn't fit into the schema.org representation.
*/
public class DigitalDocumentWrapper extends DataModel {

private final DtpDigitalDocument dtpDigitalDocument;
private final String originalEncodingFormat;
// This isn't in the schema.org spec and is only needed to store the bytes DTP will transfer
Expand Down Expand Up @@ -37,4 +40,10 @@ public String getCachedContentId() {
public String getOriginalEncodingFormat() {
return originalEncodingFormat;
}

@JsonIgnore
@Override
public Map<String, Integer> getCounts() {
return super.getCounts();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2022 The Data Transfer Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.datatransferproject.types.common.models.blob;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.truth.Truth;
import org.datatransferproject.types.common.models.ContainerResource;
import org.junit.jupiter.api.Test;

class BlobbyStorageContainerResourceTest {

@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerSubtypes(BlobbyStorageContainerResource.class);

DigitalDocumentWrapper documentWrapper = new DigitalDocumentWrapper(
new DtpDigitalDocument("doc-name", "2020-02-02", "UTF-8"), "UTF-8", "123456");
BlobbyStorageContainerResource containerResource = new BlobbyStorageContainerResource("name",
"id", ImmutableList.of(documentWrapper), ImmutableList.of());
String serialized = objectMapper.writeValueAsString(containerResource);

ContainerResource deserializedModel = objectMapper.readValue(serialized,
ContainerResource.class);

Truth.assertThat(deserializedModel).isNotNull();
Truth.assertThat(deserializedModel).isInstanceOf(BlobbyStorageContainerResource.class);
BlobbyStorageContainerResource deserialized = (BlobbyStorageContainerResource) deserializedModel;
Truth.assertThat(deserialized.getFiles()).hasSize(1);
Truth.assertThat(deserialized.getFolders()).isEmpty();
}
}

0 comments on commit 6137d31

Please sign in to comment.