]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.project/src/org/simantics/project/management/DatabaseAgent.java
Support ontology install option trueWhenDeployed also during development
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / DatabaseAgent.java
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
7  *
8  * Contributors:
9  *     VTT Technical Research Centre of Finland - initial API and implementation
10  *******************************************************************************/
11 package org.simantics.project.management;
12
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Properties;
16
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;
22
23 /**
24  * Database agent installs ontologies and   
25  *
26  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
27  */
28 public class DatabaseAgent {
29
30         ServerEx server;
31         BundlePool bundlePool;
32         
33         /**
34          * Create a new agent.
35          * 
36          * @param server
37          * @param bundlePool
38          * @throws DatabaseException
39          */
40         public DatabaseAgent(ServerEx server, BundlePool bundlePool) {
41                 this.server = server;
42                 this.bundlePool = bundlePool;
43         }
44         
45         /**
46          * Get a snapshot of database current profile
47          * 
48          * @return database specification
49          * @throws DatabaseException
50          */
51         public DatabaseSpec getSpecification() throws DatabaseException {
52                 // Create session
53                 Properties props = new Properties();
54                 Session session = server.createSession(props);
55                 try {
56                         return session.syncRequest( DatabaseSpec.QUERY );
57                 } finally {
58                         // Close session
59                         session.getService(LifecycleSupport.class).close();
60                 }
61         }
62         
63         /**
64          * Perform install operation to 
65          * @param spec
66          * @throws DatabaseException
67          */
68         public void perform(DatabaseSpec spec) throws DatabaseException {
69
70                 // 1. Validate Spec
71                 
72                 
73         }
74         
75         public List<Problem> validate(DatabaseSpec spec) {
76                 ArrayList<Problem> result = new ArrayList<Problem>();
77                 
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()
84                         }
85                 }
86                 
87                 return result;
88         }
89
90         
91         static class Problem {
92                 // Cost of the problem. 0-100
93                 public int severity;
94                 public String msg;
95         }
96
97         static class OntologyVersionConflict {
98                 
99         }
100         
101 }
102