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