-
Notifications
You must be signed in to change notification settings - Fork 3
Implementation of data exchange with Comet #234
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
Open
DimitriDiantos
wants to merge
11
commits into
development
Choose a base branch
from
Implementation_of_data_exchange_with_comet
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ca496af
Task #233 Creating of the project with the Java 17
5fee878
Task #233 creating of the import target selection page.
f5f2c78
Task #233 implement the perform finish method.
de0d3e3
Task #233 fix the error of editing domain.
0e2acea
Task #233 update the insert's method.
d95f92a
Task #234 implementation of the comet data container.
560a9d6
Task #234 using of TreeNode as the data structure.
a8a77a0
Task #234 Fix the issues of importing of the mass parameter.
c2bcb2f
Task #213 Fix problems of the Equipement mass and Equipement mass
9ce83b3
Task #233 code cleaning and updating.
f8779bc
Task #234 Remove unused classes.
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
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
195 changes: 195 additions & 0 deletions
195
....cefx.ui/src/de/dlr/sc/virsat/model/extension/cefx/ui/importWizards/CometDataFetcher.java
This file contains hidden or 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,195 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008-2019 German Aerospace Center (DLR), Simulation and Software Technology, Germany. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
|
||
package de.dlr.sc.virsat.model.extension.cefx.ui.importWizards; | ||
|
||
import cdp4common.engineeringmodeldata.ElementDefinition; | ||
import cdp4common.engineeringmodeldata.ElementUsage; | ||
import cdp4common.engineeringmodeldata.EngineeringModel; | ||
import cdp4common.engineeringmodeldata.Iteration; | ||
import cdp4common.engineeringmodeldata.Parameter; | ||
import cdp4common.engineeringmodeldata.ParameterSwitchKind; | ||
import cdp4common.engineeringmodeldata.ParameterValueSet; | ||
import cdp4common.sitedirectorydata.DomainOfExpertise; | ||
import cdp4dal.Session; | ||
import cdp4dal.SessionImpl; | ||
import cdp4dal.dal.Credentials; | ||
import cdp4servicesdal.CdpServicesDal; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.MessageBox; | ||
import org.eclipse.swt.widgets.Tree; | ||
import org.eclipse.swt.widgets.TreeItem; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.security.GeneralSecurityException; | ||
import java.util.Optional; | ||
|
||
/** | ||
* The CometDataFetcher class is responsible for fetching and populating | ||
* data from a COMET system into a SWT Tree widget. | ||
*/ | ||
public class CometDataFetcher { | ||
|
||
private final Credentials credentials; | ||
private final Session session; | ||
private final URI uri; | ||
|
||
/** | ||
* Constructs a new CometDataFetcher instance. | ||
* | ||
* @param url The URL of the COMET system. | ||
* @param username The username for authentication. | ||
* @param password The password for authentication. | ||
*/ | ||
public CometDataFetcher(String url, String username, String password) { | ||
this.uri = URI.create(url); | ||
CdpServicesDal dal = new CdpServicesDal(); | ||
this.credentials = new Credentials(username, password, this.uri, null); | ||
this.session = new SessionImpl(dal, this.credentials); | ||
} | ||
|
||
/** | ||
* Initiates the process to fetch data and populate the provided Tree. | ||
*/ | ||
public void fetchData(Tree tree) { | ||
new Thread(() -> { | ||
try { | ||
openSession(); | ||
Display.getDefault().asyncExec(() -> populateTreeWithIteration(tree)); | ||
} catch (IOException e) { | ||
// Handle I/O exceptions, such as network issues | ||
handleException(e, tree); | ||
} catch (GeneralSecurityException e) { | ||
// Handle security-related exceptions, such as authentication failures | ||
handleException(e, tree); | ||
} catch (RuntimeException e) { | ||
// Handle any other runtime exceptions that might occur | ||
handleException(e, tree); | ||
} | ||
}).start(); | ||
} | ||
|
||
/** | ||
* Opens the session for communication with the COMET system. | ||
*/ | ||
public void openSession() throws IOException, GeneralSecurityException { | ||
session.open().join(); | ||
} | ||
|
||
/** | ||
* Populates the provided Tree with data from the selected iteration | ||
* of the engineering model. | ||
* | ||
* @param tree The SWT Tree widget to populate. | ||
*/ | ||
private void populateTreeWithIteration(Tree tree) { | ||
var siteDirectory = session.getAssembler().retrieveSiteDirectory(); | ||
var model = siteDirectory.getModel().get(0); | ||
|
||
var iterationIid = model.getIterationSetup().get(0).getIterationIid(); | ||
var domainOfExpertiseIid = model.getActiveDomain().get(0).getIid(); | ||
|
||
EngineeringModel engineeringModel = new EngineeringModel(model.getEngineeringModelIid(), session.getAssembler().getCache(), uri); | ||
Iteration iteration = new Iteration(iterationIid, session.getAssembler().getCache(), uri); | ||
iteration.setContainer(engineeringModel); | ||
|
||
DomainOfExpertise domainOfExpertise = new DomainOfExpertise(domainOfExpertiseIid, session.getAssembler().getCache(), uri); | ||
|
||
session.read(iteration, domainOfExpertise).join(); | ||
|
||
Optional<Iteration> openIteration = session.getOpenIterations().keySet().stream().findFirst(); | ||
|
||
if (openIteration.isPresent()) { | ||
openIteration.get().getElement().stream() | ||
.filter(this::isTopLevelElement) // Filter for the top-level element | ||
.findFirst() | ||
.ifPresent(element -> { | ||
TreeItem topLevelItem = new TreeItem(tree, SWT.NONE); | ||
topLevelItem.setText(element.getName()); | ||
addChildren(topLevelItem, element); | ||
topLevelItem.setExpanded(true); | ||
}); | ||
} else { | ||
showErrorMessage(tree, "No open iteration found."); | ||
} | ||
} | ||
|
||
/** | ||
* Custom method to determine if an ElementDefinition is a top-level element. | ||
* A top-level element is typically not referenced by any other elements. | ||
*/ | ||
private boolean isTopLevelElement(ElementDefinition element) { | ||
return element.referencingElementUsages().isEmpty(); | ||
} | ||
|
||
|
||
|
||
|
||
/** | ||
* Recursively adds child elements of a parent ElementDefinition to a TreeItem. | ||
*/ | ||
private void addChildren(TreeItem parentItem, ElementDefinition parentElement) { | ||
parentElement.getParameter().stream() | ||
.filter(parameter -> "mass".equalsIgnoreCase(parameter.getParameterType().getName()) | ||
|| "mass margin".equalsIgnoreCase(parameter.getParameterType().getName())) | ||
.forEach(parameter -> { | ||
String value = fetchParameterValue(parameter); | ||
if (value != null) { // Ensure we only add valid manual values | ||
TreeItem item = new TreeItem(parentItem, SWT.NONE); | ||
item.setText(parameter.getParameterType().getName() + ": " + value + " kg"); | ||
} | ||
}); | ||
|
||
for (ElementUsage usage : parentElement.getContainedElement()) { | ||
TreeItem usageItem = new TreeItem(parentItem, SWT.NONE); | ||
usageItem.setText(usage.getName()); | ||
addChildren(usageItem, usage.getElementDefinition()); | ||
} | ||
} | ||
|
||
/** | ||
* Fetches the value of the specified Parameter. | ||
* | ||
*/ | ||
private String fetchParameterValue(Parameter parameter) { | ||
try { | ||
ParameterValueSet valueSet = parameter.getValueSet().get(0); | ||
|
||
if (valueSet.getValueSwitch() == ParameterSwitchKind.MANUAL) { | ||
return valueSet.getManual().get(0); | ||
} | ||
} catch (Exception e) { | ||
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. Maybe don't catch Exceptions here? But the specified exception that is thrown here? |
||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Displays an error message in a MessageBox. | ||
*/ | ||
private void showErrorMessage(Tree tree, String message) { | ||
Display.getDefault().asyncExec(() -> { | ||
MessageBox messageBox = new MessageBox(tree.getShell(), SWT.ICON_ERROR); | ||
messageBox.setMessage(message); | ||
messageBox.open(); | ||
}); | ||
} | ||
|
||
/** | ||
* Handles exceptions by printing the stack trace and displaying an error message. | ||
*/ | ||
private void handleException(Exception e, Tree tree) { | ||
e.printStackTrace(); | ||
showErrorMessage(tree, "An error occurred: " + e.getMessage()); | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
At least the API also has an attribute "topLevel" -> I guess the SDK should also have it than? That would be more robust I guess?
http://sc-010266l.intra.dlr.de:5000/EngineeringModel/33edade4-698c-4a91-8413-b9d192214c21/iteration/54bd5c12-3f03-420a-8ac1-07cad2de5bf4