Skip to content
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

Update AasUtils to v3.0 (asString, resolve, sameAs) #179

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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