use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.
the class Neo4JModelResource method resolve.
/**
* Resolve proxy object.
*
* @param proxyObject
* resolve proxy object
* @param <T>
* type
* @throws InvocationException
* when called with a null object
* @throws DBException
* on database issues
*
* @return returns the resolved objects
*/
@Override
@SuppressWarnings("unchecked")
public <T extends EObject> T resolve(final T proxyObject) throws InvocationException, DBException {
if (proxyObject == null) {
throw new InvocationException("Object reference is null, cannot resolve.");
}
if (proxyObject.eIsProxy()) {
try (Transaction tx = this.graphDatabaseService.beginTx()) {
final Node realNode = ModelGraphFactory.findNode(this.graphDatabaseService, proxyObject);
if (realNode == null) {
throw new DBException(String.format("Object '%s' has no representing node.", ModelGraphFactory.getIdentification(proxyObject)));
}
final Map<Node, EObject> nodesToCreatedObjects = new HashMap<>();
this.queryModelFacility.readContainedNodesRecursively(realNode, nodesToCreatedObjects);
final EObject realObject = nodesToCreatedObjects.get(realNode);
for (final EAttribute attribute : proxyObject.eClass().getEAllAttributes()) {
proxyObject.eSet(attribute, realObject.eGet(attribute));
}
for (final EReference reference : proxyObject.eClass().getEAllReferences()) {
if (reference.isMany()) {
final EList<EObject> manyReference = (EList<EObject>) realObject.eGet(reference);
((EList<EObject>) proxyObject.eGet(reference)).addAll(manyReference);
} else {
final EObject singleReference = (EObject) realObject.eGet(reference);
((EObject) proxyObject).eSet(reference, singleReference);
}
}
tx.success();
} catch (final TransactionFailureException ex) {
Neo4JModelResource.LOGGER.error("Cannot create transaction to resolve data.");
}
return proxyObject;
} else {
return proxyObject;
}
}
use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.
the class QueryModelFacility method scanSingleContainmentReference.
private void scanSingleContainmentReference(final Relationship relationship, final Map<Node, EObject> nodesToCreatedObjects) throws DBException {
final Node targetNode = relationship.getEndNode();
if (!nodesToCreatedObjects.containsKey(targetNode)) {
if (ModelGraphFactory.isProxyNode(targetNode)) {
throw new DBException(String.format("Proxy object in the containment hierarchy is an internal error. Relationship %s and node %s", relationship.getProperty(ModelProviderUtil.REF_NAME), targetNode.getProperty(ModelGraphFactory.EMF_INTERNAL_ID)));
} else {
final EObject targetObject = ModelObjectFactory.createObject(targetNode, this.factories);
this.scanContainmentReferences(targetNode, nodesToCreatedObjects);
nodesToCreatedObjects.put(targetNode, targetObject);
}
}
}
use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.
the class TEntryEventSequence method execute.
@Override
protected void execute(final UserSessionCollectionModel entryCallSequenceModel) throws DBException {
// Resets the current usage model
final UsageModel model = this.usageModelProvider.getAndLockModelRootNode(UsageModel.class, UsagemodelPackage.Literals.USAGE_MODEL);
int numberOfUserGroups = model.getUsageScenario_UsageModel().size();
TEntryEventSequence.LOGGER.debug("EntryEventSequence found: numberOfUserGroups before: {}", numberOfUserGroups);
// Executes the user behavior modeling procedure
final UserBehaviorTransformation behaviorModeling = new UserBehaviorTransformation(entryCallSequenceModel, numberOfUserGroups, this.varianceOfUserGroups, this.closedWorkload, this.thinkTime, this.repositoryLookupModel, this.correspondenceModel);
try {
behaviorModeling.modelUserBehavior();
model.getUsageScenario_UsageModel().clear();
model.getUserData_UsageModel().clear();
final UsageModel newModel = behaviorModeling.getPcmUsageModel();
model.getUsageScenario_UsageModel().addAll(newModel.getUsageScenario_UsageModel());
model.getUserData_UsageModel().addAll(newModel.getUserData_UsageModel());
numberOfUserGroups = model.getUsageScenario_UsageModel().size();
TEntryEventSequence.LOGGER.debug("Model changed: numberOfUserGroups after: {}", numberOfUserGroups);
} catch (final IOException e) {
e.printStackTrace();
}
// Sets the new usage model within iObserve
this.usageModelProvider.clearResource();
try {
this.usageModelProvider.storeModelPartition(model);
} catch (final DBException e) {
e.printStackTrace();
}
this.outputPort.send(behaviorModeling.getPcmUsageModel());
this.outputPortSnapshot.send(false);
}
use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.
the class ModelGraphFactory method deleteLinkedProxyNodes.
/**
* Delete proxy nodes connected to the sourceNode, iff they have only the relationship to the
* sourceNode. Else delete the relationship.
*
* @param sourceNode
* source node
* @throws DBException
* on db errors
*/
private static void deleteLinkedProxyNodes(final Node sourceNode) throws DBException {
for (final Relationship relationship : sourceNode.getRelationships(Direction.OUTGOING)) {
final Node targetNode = relationship.getEndNode();
if (ModelGraphFactory.isProxyNode(targetNode)) {
final Iterator<Relationship> proxyRelationships = targetNode.getRelationships(Direction.INCOMING).iterator();
/**
* check for more than one incoming.
*/
if (proxyRelationships.hasNext()) {
proxyRelationships.next();
if (proxyRelationships.hasNext()) {
/**
* two incoming, remove just the relationship.
*/
relationship.delete();
} else {
/**
* one relationship; delete relationship and node.
*/
relationship.delete();
targetNode.delete();
}
} else {
throw new DBException("There is an relationship form a -> b, but b has no incoming relationship. Consistency error.");
}
}
}
}
use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.
the class PrivacyViolationDetectionServiceMain method createTeetimeConfiguration.
@Override
protected PipelineConfiguration createTeetimeConfiguration() throws ConfigurationException {
/**
* load models.
*/
try {
final ModelImporter modelHandler = new ModelImporter(this.parameterConfiguration.getModelInitDirectory());
/**
* initialize database.
*/
final IModelResource<CorrespondenceModel> correspondenceModelResource = this.loadResourceAndInitDB(CorrespondencePackage.eINSTANCE, modelHandler.getCorrespondenceModel());
final IModelResource<Repository> repositoryModelResource = this.loadResourceAndInitDB(RepositoryPackage.eINSTANCE, modelHandler.getRepositoryModel());
final IModelResource<ResourceEnvironment> resourceEnvironmentModelResource = this.loadResourceAndInitDB(ResourceenvironmentPackage.eINSTANCE, modelHandler.getResourceEnvironmentModel());
final IModelResource<System> systemModelResource = this.loadResourceAndInitDB(SystemPackage.eINSTANCE, modelHandler.getSystemModel());
final IModelResource<Allocation> allocationModelResource = this.loadResourceAndInitDB(AllocationPackage.eINSTANCE, modelHandler.getAllocationModel());
final IModelResource<DataProtectionModel> privacyModelResource = this.loadResourceAndInitDB(PrivacyPackage.eINSTANCE, modelHandler.getPrivacyModel());
return new PipelineConfiguration(this.kiekerConfiguration, correspondenceModelResource, repositoryModelResource, resourceEnvironmentModelResource, systemModelResource, allocationModelResource, privacyModelResource, this.parameterConfiguration.getWarningFile(), this.parameterConfiguration.getAlarmsFile(), this.parameterConfiguration.getModelDumpDirectory());
} catch (final DBException | IOException e) {
throw new ConfigurationException(e);
}
}
Aggregations