-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update AasUtils to v3.0 (asString, resolve, sameAs) (#179)
* 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
1 parent
f1bdbab
commit e818238
Showing
7 changed files
with
683 additions
and
190 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...va/org/eclipse/digitaltwin/aas4j/v3/dataformat/core/internal/util/GetChildrenVisitor.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,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()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../org/eclipse/digitaltwin/aas4j/v3/dataformat/core/internal/util/GetIdentifierVisitor.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,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); | ||
} | ||
} |
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
Oops, something went wrong.