Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit 0503794

Browse files
committed
Merge pull request #11 from zazi/master
added content schema serializer
2 parents cdb34bf + 74b372d commit 0503794

File tree

9 files changed

+342
-25
lines changed

9 files changed

+342
-25
lines changed

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@
4444
<slf4j-api.version>1.7.12</slf4j-api.version>
4545
<jena.version>2.13.0</jena.version>
4646
<version.guava>18.0</version.guava>
47-
<version.jackson>2.5.0</version.jackson>
47+
<version.jackson>2.5.3</version.jackson>
4848
<junit.version>4.12</junit.version>
4949
<version.apache.commons>3.4</version.apache.commons>
5050
<version.maven.plugin.version>2.1</version.maven.plugin.version>
5151
<version.maven.plugin.jar>2.6</version.maven.plugin.jar>
5252
<version.maven.plugin.site>3.4</version.maven.plugin.site>
5353
<version.maven.plugin.deploy>2.8.2</version.maven.plugin.deploy>
54+
<version.jsonassert>1.2.3</version.jsonassert>
5455
</properties>
5556

5657
<build>
@@ -251,6 +252,12 @@
251252
<artifactId>commons-lang3</artifactId>
252253
<version>${version.apache.commons}</version>
253254
</dependency>
255+
<dependency>
256+
<groupId>org.skyscreamer</groupId>
257+
<artifactId>jsonassert</artifactId>
258+
<version>${version.jsonassert}</version>
259+
<scope>test</scope>
260+
</dependency>
254261
</dependencies>
255262

256263
</project>

src/main/java/org/dswarm/common/model/Attribute.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ public boolean equals(final Object o) {
6262

6363
final Attribute attribute = (Attribute) o;
6464

65-
if (!uri.equals(attribute.uri)) {
65+
return uri.equals(attribute.uri);
6666

67-
return false;
68-
}
69-
70-
return true;
7167
}
7268

7369
@Override

src/main/java/org/dswarm/common/model/AttributePath.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,8 @@ public boolean equals(final Object o) {
6464

6565
final AttributePath that = (AttributePath) o;
6666

67-
if (attributes != null ? !attributes.equals(that.attributes) : that.attributes != null) {
67+
return !(attributes != null ? !attributes.equals(that.attributes) : that.attributes != null);
6868

69-
return false;
70-
}
71-
72-
return true;
7369
}
7470

7571
@Override

src/main/java/org/dswarm/common/model/ContentSchema.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535

3636
import com.fasterxml.jackson.annotation.JsonProperty;
3737
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
38+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
3839

3940
import org.dswarm.common.model.deserializer.ContentSchemaDeserializer;
41+
import org.dswarm.common.model.serializer.ContentSchemaSerializer;
4042

4143
/**
4244
* Created by tgaengler on 29/07/14.
4345
*/
4446
@JsonDeserialize(using = ContentSchemaDeserializer.class)
47+
@JsonSerialize(using = ContentSchemaSerializer.class)
4548
public class ContentSchema {
4649

4750
@JsonProperty("record_identifier_attribute_path")
@@ -88,18 +91,13 @@ public boolean equals(final Object o) {
8891

8992
final ContentSchema that = (ContentSchema) o;
9093

91-
if (keyAttributePaths != null ? !keyAttributePaths.equals(that.keyAttributePaths) : that.keyAttributePaths != null) {
92-
return false;
93-
}
94-
if (recordIdentifierAttributePath != null ? !recordIdentifierAttributePath.equals(that.recordIdentifierAttributePath)
95-
: that.recordIdentifierAttributePath != null) {
96-
return false;
97-
}
98-
if (valueAttributePath != null ? !valueAttributePath.equals(that.valueAttributePath) : that.valueAttributePath != null) {
99-
return false;
100-
}
94+
return !(keyAttributePaths != null ? !keyAttributePaths.equals(that.keyAttributePaths) : that.keyAttributePaths != null) && !(
95+
recordIdentifierAttributePath != null ?
96+
!recordIdentifierAttributePath.equals(that.recordIdentifierAttributePath) :
97+
that.recordIdentifierAttributePath != null) && !(valueAttributePath != null ?
98+
!valueAttributePath.equals(that.valueAttributePath) :
99+
that.valueAttributePath != null);
101100

102-
return true;
103101
}
104102

105103
@Override

src/main/java/org/dswarm/common/model/deserializer/ContentSchemaDeserializer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.dswarm.common.model.AttributePath;
4747
import org.dswarm.common.model.ContentSchema;
4848
import org.dswarm.common.model.util.AttributePathUtil;
49+
import org.dswarm.common.model.util.ContentSchemaUtil;
4950

5051
/**
5152
* Created by tgaengler on 29/07/14.
@@ -72,15 +73,15 @@ public ContentSchema deserialize(final JsonParser jp, final DeserializationConte
7273
return null;
7374
}
7475

75-
final JsonNode recordIdentifierAttributePathNode = node.get("record_identifier_attribute_path");
76+
final JsonNode recordIdentifierAttributePathNode = node.get(ContentSchemaUtil.RECORD_IDENTIFIER_ATTRIBUTE_PATH);
7677
final AttributePath recordIdentifierAttributePath = AttributePathUtil.parseAttributePathNode(recordIdentifierAttributePathNode, attributeMap,
7778
attributePathMap);
7879

79-
final JsonNode keyAttributePathsNode = node.get("key_attribute_paths");
80+
final JsonNode keyAttributePathsNode = node.get(ContentSchemaUtil.KEY_ATTRIBUTE_PATHS);
8081
final LinkedList<AttributePath> keyAttributePaths = AttributePathUtil.parseAttributePathsNode(keyAttributePathsNode, attributeMap,
8182
attributePathMap);
8283

83-
final JsonNode valueAttributePathNode = node.get("value_attribute_path");
84+
final JsonNode valueAttributePathNode = node.get(ContentSchemaUtil.VALUE_ATTRIBUTE_PATH);
8485
final AttributePath valueAttributePath = AttributePathUtil.parseAttributePathNode(valueAttributePathNode, attributeMap, attributePathMap);
8586

8687
return new ContentSchema(recordIdentifierAttributePath, keyAttributePaths, valueAttributePath);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2013 – 2015 SLUB Dresden & Avantgarde Labs GmbH (<code@dswarm.org>)
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+
* http://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.dswarm.common.model.serializer;
18+
19+
import java.io.IOException;
20+
import java.util.LinkedList;
21+
22+
import com.fasterxml.jackson.core.JsonGenerator;
23+
import com.fasterxml.jackson.databind.JsonSerializer;
24+
import com.fasterxml.jackson.databind.SerializerProvider;
25+
26+
import org.dswarm.common.model.AttributePath;
27+
import org.dswarm.common.model.ContentSchema;
28+
import org.dswarm.common.model.util.ContentSchemaUtil;
29+
30+
/**
31+
* @author tgaengler
32+
*/
33+
public class ContentSchemaSerializer extends JsonSerializer<ContentSchema> {
34+
35+
@Override
36+
public void serialize(final ContentSchema contentSchema, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
37+
throws IOException {
38+
39+
if(contentSchema == null) {
40+
41+
return;
42+
}
43+
44+
jsonGenerator.writeStartObject();
45+
46+
final AttributePath recordIdentifierAttributePath = contentSchema.getRecordIdentifierAttributePath();
47+
48+
if(recordIdentifierAttributePath != null) {
49+
50+
jsonGenerator.writeFieldName(ContentSchemaUtil.RECORD_IDENTIFIER_ATTRIBUTE_PATH);
51+
jsonGenerator.writeString(recordIdentifierAttributePath.toString());
52+
}
53+
54+
final LinkedList<AttributePath> keyAttributePaths = contentSchema.getKeyAttributePaths();
55+
56+
if(keyAttributePaths != null) {
57+
58+
jsonGenerator.writeFieldName(ContentSchemaUtil.KEY_ATTRIBUTE_PATHS);
59+
jsonGenerator.writeStartArray();
60+
61+
for(final AttributePath kexAttributePath : keyAttributePaths) {
62+
63+
jsonGenerator.writeString(kexAttributePath.toString());
64+
}
65+
66+
jsonGenerator.writeEndArray();
67+
}
68+
69+
final AttributePath valueAttributePath = contentSchema.getValueAttributePath();
70+
71+
if(valueAttributePath != null) {
72+
73+
jsonGenerator.writeFieldName(ContentSchemaUtil.VALUE_ATTRIBUTE_PATH);
74+
jsonGenerator.writeString(valueAttributePath.toString());
75+
}
76+
77+
jsonGenerator.writeEndObject();
78+
}
79+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2013 – 2015 SLUB Dresden & Avantgarde Labs GmbH (<code@dswarm.org>)
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+
* http://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.dswarm.common.model.util;
18+
19+
/**
20+
* @author tgaengler
21+
*/
22+
public final class ContentSchemaUtil {
23+
24+
public static final String RECORD_IDENTIFIER_ATTRIBUTE_PATH = "record_identifier_attribute_path";
25+
public static final String KEY_ATTRIBUTE_PATHS = "key_attribute_paths";
26+
public static final String VALUE_ATTRIBUTE_PATH = "value_attribute_path";
27+
}

0 commit comments

Comments
 (0)