-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding CustomDataspecification Feature and UnitTests #207
Merged
FrankSchnicke
merged 5 commits into
eclipse-aas4j:main
from
sap-contributions:customdataspecification-test
Dec 5, 2023
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
74ffb24
add custom dataspecification
sebbader-sap 67099e4
add successful json test
sebbader-sap 230af98
start xml test
sebbader-sap 7f16113
fix dataspecification behavior for xml
sebbader-sap c33a3aa
move CustomDataSpecification into model
sebbader-sap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...at-core/src/test/java/org/eclipse/digitaltwin/aas4j/v3/model/CustomDataSpecification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2023 SAP SE or an SAP affiliate company. | ||
* | ||
* 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 | ||
* | ||
* http://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.eclipse.digitaltwin.aas4j.v3.model; | ||
|
||
/** | ||
* This interface is needed to test the serialization/deserialization of a custom data specification content. | ||
* See: https://github.com/eclipse-aas4j/aas4j/issues/196 | ||
*/ | ||
public interface CustomDataSpecification extends DataSpecificationContent { | ||
|
||
LangStringNameType getName(); | ||
sebbader-sap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void setName(LangStringNameType name); | ||
|
||
|
||
String getText(); | ||
|
||
void setText(String text); | ||
|
||
|
||
int getPages(); | ||
|
||
void setPages(int pages); | ||
} |
42 changes: 42 additions & 0 deletions
42
.../src/test/java/org/eclipse/digitaltwin/aas4j/v3/model/CustomDataSpecificationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2023 SAP SE or an SAP affiliate company. | ||
* | ||
* 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 | ||
* | ||
* http://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.eclipse.digitaltwin.aas4j.v3.model; | ||
|
||
import org.eclipse.digitaltwin.aas4j.v3.model.builder.ExtendableBuilder; | ||
|
||
/** | ||
* This interface is needed to test the serialization/deserialization of a custom data specification content. | ||
* | ||
* See: https://github.com/eclipse-aas4j/aas4j/issues/196 | ||
*/ | ||
public abstract class CustomDataSpecificationBuilder<T extends CustomDataSpecification, | ||
B extends CustomDataSpecificationBuilder<T, B>> extends ExtendableBuilder<T, B> { | ||
|
||
public B name(LangStringNameType name) { | ||
getBuildingInstance().setName(name); | ||
return getSelf(); | ||
} | ||
|
||
public B text(String text) { | ||
getBuildingInstance().setText(text); | ||
return getSelf(); | ||
} | ||
|
||
public B pages(int pages) { | ||
getBuildingInstance().setPages(pages); | ||
return getSelf(); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
.../src/test/java/org/eclipse/digitaltwin/aas4j/v3/model/DefaultCustomDataSpecification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2023 SAP SE or an SAP affiliate company. | ||
* | ||
* 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 | ||
* | ||
* http://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.eclipse.digitaltwin.aas4j.v3.model; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* This interface is needed to test the serialization/deserialization of a custom data specification content. | ||
* See: https://github.com/eclipse-aas4j/aas4j/issues/196 | ||
*/ | ||
public class DefaultCustomDataSpecification implements CustomDataSpecification { | ||
private LangStringNameType name; | ||
private String text; | ||
private int pages; | ||
|
||
public LangStringNameType getName() { | ||
return name; | ||
} | ||
|
||
public void setName(LangStringNameType name) { | ||
this.name = name; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
|
||
public int getPages() { | ||
return pages; | ||
}; | ||
public void setPages(int pages) { | ||
this.pages = pages; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.name, this.text, this.pages); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} else if (obj == null) { | ||
return false; | ||
} else if (this.getClass() != obj.getClass()) { | ||
return false; | ||
} else { | ||
DefaultCustomDataSpecification other = (DefaultCustomDataSpecification) obj; | ||
return Objects.equals(this.name, other.name) && | ||
Objects.equals(this.text, other.text) && | ||
Objects.equals(this.pages, other.pages); | ||
} | ||
} | ||
|
||
/** | ||
* This builder class can be used to construct a DefaultCustomDataSpecificationContent. | ||
*/ | ||
public static class Builder extends CustomDataSpecificationBuilder<DefaultCustomDataSpecification, | ||
Builder> { | ||
|
||
@Override | ||
protected DefaultCustomDataSpecification.Builder getSelf() { | ||
return this; | ||
} | ||
|
||
@Override | ||
protected DefaultCustomDataSpecification newBuildingInstance() { | ||
return new DefaultCustomDataSpecification(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,18 @@ | |
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultDataSpecificationIec61360; | ||
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent; | ||
|
||
import java.io.IOException; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
public class EmbeddedDataSpecificationsDeserializer extends JsonDeserializer<DataSpecificationIec61360> { | ||
public class EmbeddedDataSpecificationsDeserializer extends JsonDeserializer<DataSpecificationContent> { | ||
|
||
private static final String PROP_DATA_SPECIFICATION_CONTENT = "dataSpecificationIec61360"; | ||
|
||
@Override | ||
public DataSpecificationIec61360 deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
public DataSpecificationContent deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
ObjectNode node = DeserializationHelper.getRootObjectNode(parser); | ||
if (node == null) { | ||
return null; | ||
|
@@ -41,13 +42,23 @@ public DataSpecificationIec61360 deserialize(JsonParser parser, DeserializationC | |
} | ||
|
||
|
||
private DataSpecificationIec61360 createEmbeddedDataSpecificationsFromContent(JsonParser parser, JsonNode node) throws IOException { | ||
JsonNode nodeContent = node.get(PROP_DATA_SPECIFICATION_CONTENT); | ||
return createDefaultDataSpecificationIec61360FromNode(parser, nodeContent); | ||
} | ||
private DataSpecificationContent createEmbeddedDataSpecificationsFromContent(JsonParser parser, JsonNode node) throws IOException { | ||
String class_name = node.fieldNames().next(); | ||
Set<Class<?>> subtypes = ReflectionHelper.SUBTYPES.get(DataSpecificationContent.class); | ||
Iterator<Class<?>> iter = subtypes.iterator(); | ||
while (iter.hasNext()) { | ||
Class clazz = iter.next(); | ||
if (clazz.getSimpleName().toLowerCase().contains(class_name.toLowerCase())) { | ||
try { | ||
JsonNode nodeContent = node.get(class_name); | ||
return (DataSpecificationContent) DeserializationHelper.createInstanceFromNode(parser, nodeContent, clazz); | ||
} catch (Exception e) { | ||
// do nothing | ||
} | ||
} | ||
}; | ||
|
||
private DataSpecificationIec61360 createDefaultDataSpecificationIec61360FromNode(JsonParser parser, JsonNode nodeContent) throws IOException { | ||
return DeserializationHelper.createInstanceFromNode(parser, nodeContent, DefaultDataSpecificationIec61360.class); | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. throw exception |
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to model