X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fmanagement%2FDatabaseAgent.java;fp=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fmanagement%2FDatabaseAgent.java;h=afdf3b71f4bec7d8253179f6a9ae0112417a570b;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.project/src/org/simantics/project/management/DatabaseAgent.java b/bundles/org.simantics.project/src/org/simantics/project/management/DatabaseAgent.java new file mode 100644 index 000000000..afdf3b71f --- /dev/null +++ b/bundles/org.simantics.project/src/org/simantics/project/management/DatabaseAgent.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.project.management; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.equinox.p2.metadata.VersionedId; +import org.simantics.db.ServerEx; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.LifecycleSupport; + +/** + * Database agent installs ontologies and + * + * @author Toni Kalajainen + */ +public class DatabaseAgent { + + ServerEx server; + BundlePool bundlePool; + + /** + * Create a new agent. + * + * @param server + * @param bundlePool + * @throws DatabaseException + */ + public DatabaseAgent(ServerEx server, BundlePool bundlePool) { + this.server = server; + this.bundlePool = bundlePool; + } + + /** + * Get a snapshot of database current profile + * + * @return database specification + * @throws DatabaseException + */ + public DatabaseSpec getSpecification() throws DatabaseException { + // Create session + Properties props = new Properties(); + Session session = server.createSession(props); + try { + return session.syncRequest( DatabaseSpec.QUERY ); + } finally { + // Close session + session.getService(LifecycleSupport.class).close(); + } + } + + /** + * Perform install operation to + * @param spec + * @throws DatabaseException + */ + public void perform(DatabaseSpec spec) throws DatabaseException { + + // 1. Validate Spec + + + } + + public List validate(DatabaseSpec spec) { + ArrayList result = new ArrayList(); + + // 1. Ontology exists for all features + for (ProjectSpec ps : spec.projects) { + for (FeatureSpec fs : ps.features) { + /*IVersionedId vid =*/ VersionedId.parse(fs.versionedId); + // Now use BundlePool to find out ontologies +// bundlePool.getMetadataRepository() + } + } + + return result; + } + + + static class Problem { + // Cost of the problem. 0-100 + public int severity; + public String msg; + } + + static class OntologyVersionConflict { + + } + +} +