X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fmanagement%2FProjectSpec.java;fp=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fmanagement%2FProjectSpec.java;h=18296ac376d233df7c56b12d079bdc227c991128;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.project/src/org/simantics/project/management/ProjectSpec.java b/bundles/org.simantics.project/src/org/simantics/project/management/ProjectSpec.java new file mode 100644 index 000000000..18296ac37 --- /dev/null +++ b/bundles/org.simantics.project/src/org/simantics/project/management/ProjectSpec.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * 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.Collections; +import java.util.List; +import java.util.TreeMap; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.project.ontology.ProjectResource; + +/** + * Project specification. + * + * @author Toni Kalajainen + */ +public class ProjectSpec { + + /** Display Name */ + String name; + + /** Project database unique identifier */ + String URI; + + /** Feature specification of the project. The list is sorted by versionedId */ + List features; + transient List features_read_only_view; + transient int hash; + + /** + * Create a new project specification + * + * @param name optional Name + * @param URI project unique identifier + * @param features features of the project + */ + public ProjectSpec(String name, String URI, List features) { + this.name = name; + this.URI = URI; + TreeMap sortedList = new TreeMap(); + for (FeatureSpec fs : features) sortedList.put(fs.versionedId, fs); + this.features = new ArrayList(sortedList.values()); + this.features_read_only_view = Collections.unmodifiableList(this.features); + hash = URI.hashCode(); + for (FeatureSpec fs : this.features) { + hash = 13*hash + fs.hashCode(); + } + } + + public String getName() { + return name; + } + + public String getURI() { + return URI; + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) return false; + if (obj instanceof ProjectSpec == false) return false; + if (obj==this) return true; + ProjectSpec other = (ProjectSpec) obj; + if (!other.URI.equals(URI)) return false; + if (other.features.size() != features.size()) return false; + int c = features.size(); + for (int i=0; i getFeatures() { + return features; + } + + /** A query that reads all bundles from the database, result ordered by URI */ + static Read> QUERY = new Read>() { + @Override + public List perform(ReadGraph g) throws DatabaseException { + ProjectResource pr = ProjectResource.getInstance(g); + Layer0 L0 = Layer0.getInstance(g); + Resource root = g.getResource("http://Projects"); + TreeMap result = new TreeMap(); + TreeMap features = new TreeMap(); + for (Resource r : g.getObjects(root, L0.ConsistsOf) ) { + String URI = g.getURI( r ); + String name = g.getPossibleRelatedValue(r, L0.HasName); + + features.clear(); + for (Resource r2 : g.getObjects(r, pr.HasFeature)) { + FeatureSpec spec = new FeatureSpec(); + spec.versionedId = g.getPossibleRelatedValue(r2, pr.HasGroupId, Bindings.STRING); + spec.name = g.getPossibleRelatedValue(r2, L0.HasName, Bindings.STRING); + Boolean b = g.getPossibleRelatedValue(r2, pr.IsRequired, Bindings.BOOLEAN); + spec.required = b!=null ? b : true; + features.put(spec.versionedId, spec); + } + + ProjectSpec spec = new ProjectSpec(name, URI, new ArrayList(features.values())); + result.put(URI, spec); + } + return new ArrayList(result.values()); + } + }; + + +} +