1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.document;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.adapter.ActionFactory;
21 * Abstract base class for adding documents.
23 * If import target is an document, a new version of a document is created.
25 * Document version creation has two modes:
26 * FLAT: new version is added to the same library as the old document.
27 * TREE: new version replaces the old document in the library, and old document is moved under the new document.
30 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
33 public abstract class AddDocumentAction implements ActionFactory {
35 private Resource relation;
37 public AddDocumentAction(ReadGraph graph, String relationUri) throws DatabaseException {
38 relation = graph.getResource(relationUri);
42 protected Resource getRelation() {
46 protected void linkDocument(WriteGraph graph, Resource target, Resource newDocument) throws DatabaseException{
47 DocumentResource doc = DocumentResource.getInstance(graph);
49 if (graph.isInstanceOf(target, doc.Document)) {
50 // adding a new revision
51 DocumentVersionUtils.createNewVersion(graph, target, newDocument, relation);
55 graph.claim(target, relation, newDocument);
56 FileDocumentUtil.createUniqueName(graph, newDocument);