1 /*******************************************************************************
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * VTT Technical Research Centre of Finland - initial API and implementation
10 *******************************************************************************/
11 package org.simantics.project.management;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Properties;
17 import org.eclipse.equinox.p2.metadata.VersionedId;
18 import org.simantics.db.ServerEx;
19 import org.simantics.db.Session;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.service.LifecycleSupport;
24 * Database agent installs ontologies and
26 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
28 public class DatabaseAgent {
31 BundlePool bundlePool;
38 * @throws DatabaseException
40 public DatabaseAgent(ServerEx server, BundlePool bundlePool) {
42 this.bundlePool = bundlePool;
46 * Get a snapshot of database current profile
48 * @return database specification
49 * @throws DatabaseException
51 public DatabaseSpec getSpecification() throws DatabaseException {
53 Properties props = new Properties();
54 Session session = server.createSession(props);
56 return session.syncRequest( DatabaseSpec.QUERY );
59 session.getService(LifecycleSupport.class).close();
64 * Perform install operation to
66 * @throws DatabaseException
68 public void perform(DatabaseSpec spec) throws DatabaseException {
75 public List<Problem> validate(DatabaseSpec spec) {
76 ArrayList<Problem> result = new ArrayList<Problem>();
78 // 1. Ontology exists for all features
79 for (ProjectSpec ps : spec.projects) {
80 for (FeatureSpec fs : ps.features) {
81 /*IVersionedId vid =*/ VersionedId.parse(fs.versionedId);
82 // Now use BundlePool to find out ontologies
83 // bundlePool.getMetadataRepository()
91 static class Problem {
92 // Cost of the problem. 0-100
97 static class OntologyVersionConflict {