Skip to content

Commit

Permalink
Update AasUtils to v3.0 (asString, resolve, sameAs) (#179)
Browse files Browse the repository at this point in the history
* update AasUtils to v3.0 (asString, resolve, sameAs)
* change default behavior of AasUtils.sameAs(...) to not compare referredSemanticId and add method overload taking additional parameter
* add more unit tests for AasUtilsTest.java (#212)
* address review comments: fix copyright & test cases

---------

Co-authored-by: emildinchev <74680648+emildinchev@users.noreply.github.com>
  • Loading branch information
mjacoby and emildinchev authored Dec 7, 2023
1 parent f1bdbab commit e818238
Show file tree
Hide file tree
Showing 7 changed files with 683 additions and 190 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
*
* 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.dataformat.core.internal.util;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.visitor.AssetAdministrationShellElementVisitor;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.Environment;
import org.eclipse.digitaltwin.aas4j.v3.model.Referable;
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList;

public class GetChildrenVisitor implements AssetAdministrationShellElementVisitor {

private final List<Referable> children = new ArrayList<>();
private Environment environment;

public GetChildrenVisitor() {
}

public void reset() {
children.clear();
}

public GetChildrenVisitor(Environment environment) {
this.environment = environment;
}

public List<Referable> getChildren() {
return children;
}

@Override
public void visit(Environment environment) {
children.addAll(environment.getAssetAdministrationShells());
children.addAll(environment.getConceptDescriptions());
children.addAll(environment.getSubmodels());
}

@Override
public void visit(AssetAdministrationShell assetAdministrationShell) {
List<String> submodelIds = assetAdministrationShell.getSubmodels().stream()
.map(x -> x.getKeys().get(x.getKeys().size() - 1).getValue())
.collect(Collectors.toList());
if (environment != null) {
children.addAll(environment.getSubmodels().stream()
.filter(x -> submodelIds.contains(x.getId()))
.collect(Collectors.toList()));
}
}

@Override
public void visit(Submodel submodel) {
children.addAll(submodel.getSubmodelElements());
}

@Override
public void visit(SubmodelElementCollection submodelElementCollection) {
children.addAll(submodelElementCollection.getValue());
}

@Override
public void visit(SubmodelElementList submodelElementList) {
children.addAll(submodelElementList.getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
*
* 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.dataformat.core.internal.util;

import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.visitor.AssetAdministrationShellElementVisitor;
import org.eclipse.digitaltwin.aas4j.v3.model.Identifiable;
import org.eclipse.digitaltwin.aas4j.v3.model.Referable;

public class GetIdentifierVisitor implements AssetAdministrationShellElementVisitor {

private String identifier;

public static String getIdentifier(Referable referable) {
GetIdentifierVisitor visitor = new GetIdentifierVisitor();
visitor.visit(referable);
return visitor.getIdentifier();
}

public String getIdentifier() {
return identifier;
}

@Override
public void visit(Referable referable) {
if (referable != null) {
identifier = referable.getIdShort();
}
AssetAdministrationShellElementVisitor.super.visit(referable);
}

@Override
public void visit(Identifiable identifiable) {
if (identifiable != null) {
identifier = identifiable.getId();
}
AssetAdministrationShellElementVisitor.super.visit(identifiable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList;

public interface AssetAdministrationShellElementVisitor {

Expand Down Expand Up @@ -171,6 +172,8 @@ public default void visit(SubmodelElement submodelElement) {
visit((Capability) submodelElement);
} else if (SubmodelElementCollection.class.isAssignableFrom(type)) {
visit((SubmodelElementCollection) submodelElement);
} else if (SubmodelElementList.class.isAssignableFrom(type)) {
visit((SubmodelElementList) submodelElement);
} else if (Operation.class.isAssignableFrom(type)) {
visit((Operation) submodelElement);
} else if (EventElement.class.isAssignableFrom(type)) {
Expand Down Expand Up @@ -231,8 +234,8 @@ public default void visit(Capability capability) {
public default void visit(ConceptDescription conceptDescription) {
}

public default void visit(DataSpecificationContent dataSpecificationContent) {
}
public default void visit(DataSpecificationContent dataSpecificationContent) {
}

public default void visit(Entity entity) {
}
Expand Down Expand Up @@ -297,6 +300,9 @@ public default void visit(Submodel submodel) {
public default void visit(SubmodelElementCollection submodelElementCollection) {
}

public default void visit(SubmodelElementList submodelElementList) {
}

public default void visit(Resource resource) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId;
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList;

public interface AssetAdministrationShellElementWalkerVisitor extends AssetAdministrationShellElementVisitor {

Expand Down Expand Up @@ -129,7 +130,7 @@ public default void visit(HasSemantics hasSemantics) {
return;
}
visit(hasSemantics.getSemanticId());
hasSemantics.getSupplementalSemanticIds().forEach(x->visit(x));
hasSemantics.getSupplementalSemanticIds().forEach(x -> visit(x));
AssetAdministrationShellElementVisitor.super.visit(hasSemantics);
}

Expand Down Expand Up @@ -208,36 +209,36 @@ public default void visit(Referable referable) {
}

@Override
public default void visit(LangStringNameType langString){
if (langString == null){
public default void visit(LangStringNameType langString) {
if (langString == null) {
return;
}
AssetAdministrationShellElementVisitor.super.visit(langString);
};
}

@Override
public default void visit(LangStringPreferredNameTypeIec61360 langString){
if (langString == null){
public default void visit(LangStringPreferredNameTypeIec61360 langString) {
if (langString == null) {
return;
}
AssetAdministrationShellElementVisitor.super.visit(langString);
};
}

@Override
public default void visit(LangStringDefinitionTypeIec61360 langString){
if (langString == null){
public default void visit(LangStringDefinitionTypeIec61360 langString) {
if (langString == null) {
return;
}
AssetAdministrationShellElementVisitor.super.visit(langString);
};
}

@Override
public default void visit(LangStringTextType langString){
if (langString == null){
public default void visit(LangStringTextType langString) {
if (langString == null) {
return;
}
AssetAdministrationShellElementVisitor.super.visit(langString);
};
}

@Override
public default void visit(Reference reference) {
Expand Down Expand Up @@ -315,6 +316,15 @@ public default void visit(SubmodelElementCollection submodelElementCollection) {
AssetAdministrationShellElementVisitor.super.visit(submodelElementCollection);
}

@Override
public default void visit(SubmodelElementList submodelElementList) {
if (submodelElementList == null) {
return;
}
submodelElementList.getValue().forEach(x -> visit(x));
AssetAdministrationShellElementVisitor.super.visit(submodelElementList);
}

@Override
public default void visit(Operation operation) {
if (operation == null) {
Expand Down
Loading

0 comments on commit e818238

Please sign in to comment.