-/*******************************************************************************\r
- * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.project.management;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Properties;\r
-\r
-import org.eclipse.equinox.p2.metadata.VersionedId;\r
-import org.simantics.db.ServerEx;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.LifecycleSupport;\r
-\r
-/**\r
- * Database agent installs ontologies and \r
- *\r
- * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
- */\r
-public class DatabaseAgent {\r
-\r
- ServerEx server;\r
- BundlePool bundlePool;\r
- \r
- /**\r
- * Create a new agent.\r
- * \r
- * @param server\r
- * @param bundlePool\r
- * @throws DatabaseException\r
- */\r
- public DatabaseAgent(ServerEx server, BundlePool bundlePool) {\r
- this.server = server;\r
- this.bundlePool = bundlePool;\r
- }\r
- \r
- /**\r
- * Get a snapshot of database current profile\r
- * \r
- * @return database specification\r
- * @throws DatabaseException\r
- */\r
- public DatabaseSpec getSpecification() throws DatabaseException {\r
- // Create session\r
- Properties props = new Properties();\r
- Session session = server.createSession(props);\r
- try {\r
- return session.syncRequest( DatabaseSpec.QUERY );\r
- } finally {\r
- // Close session\r
- session.getService(LifecycleSupport.class).close();\r
- }\r
- }\r
- \r
- /**\r
- * Perform install operation to \r
- * @param spec\r
- * @throws DatabaseException\r
- */\r
- public void perform(DatabaseSpec spec) throws DatabaseException {\r
-\r
- // 1. Validate Spec\r
- \r
- \r
- }\r
- \r
- public List<Problem> validate(DatabaseSpec spec) {\r
- ArrayList<Problem> result = new ArrayList<Problem>();\r
- \r
- // 1. Ontology exists for all features\r
- for (ProjectSpec ps : spec.projects) {\r
- for (FeatureSpec fs : ps.features) {\r
- /*IVersionedId vid =*/ VersionedId.parse(fs.versionedId);\r
- // Now use BundlePool to find out ontologies\r
-// bundlePool.getMetadataRepository()\r
- }\r
- }\r
- \r
- return result;\r
- }\r
-\r
- \r
- static class Problem {\r
- // Cost of the problem. 0-100\r
- public int severity;\r
- public String msg;\r
- }\r
-\r
- static class OntologyVersionConflict {\r
- \r
- }\r
- \r
-}\r
-\r
+/*******************************************************************************
+ * 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 <toni.kalajainen@vtt.fi>
+ */
+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<Problem> validate(DatabaseSpec spec) {
+ ArrayList<Problem> result = new ArrayList<Problem>();
+
+ // 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 {
+
+ }
+
+}
+