-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.layer0.migration;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.PossibleObjectWithType;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.common.utils.ListUtils;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.Instances;\r
-import org.simantics.layer0.Layer0;\r
-\r
-public class OrderedSetToListMigrationStep implements MigrationStep {\r
- \r
- final ArrayList<OrderedSetToListMapping> rules;\r
- \r
- private class OrderedSetToListMapping {\r
- public Resource entityType, orderedSet, orderedSetRelation, list, listRelation;\r
- }\r
- \r
- public OrderedSetToListMigrationStep(ReadGraph graph, Resource step) throws DatabaseException {\r
- rules = new ArrayList<OrderedSetToListMapping>();\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- for(Resource change : ListUtils.toList(graph, step)) {\r
- String entityType = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_entityType, Bindings.STRING);\r
- String orderedSet = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_orderedSetType, Bindings.STRING);\r
- String orderedSetRelation = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_orderedSetRelation, Bindings.STRING);\r
- String list = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_listType, Bindings.STRING);\r
- String listRelation = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_listRelation, Bindings.STRING);\r
- \r
- if(orderedSet != null && orderedSetRelation != null && list != null && listRelation != null) {\r
- OrderedSetToListMapping mapping = new OrderedSetToListMapping();\r
- mapping.entityType = graph.getResource(entityType);\r
- mapping.orderedSet = graph.getResource(orderedSet);\r
- mapping.orderedSetRelation = graph.getResource(orderedSetRelation);\r
- mapping.list = graph.getResource(list);\r
- mapping.listRelation = graph.getResource(listRelation);\r
- rules.add(mapping);\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException {\r
- final Resource resource = MigrationUtils.getResource(monitor, session, state);\r
- \r
- if(resource != null) {\r
- session.syncRequest(new WriteRequest() {\r
- \r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- for(OrderedSetToListMapping mapping : rules) {\r
- Instances entityFinder = graph.adapt(mapping.entityType, Instances.class);\r
- for(Resource entity : entityFinder.find(graph, resource)) {\r
- Resource orderedSet = graph.syncRequest(new PossibleObjectWithType(entity, mapping.orderedSetRelation, mapping.orderedSet));\r
- if(orderedSet != null) {\r
- Collection<Resource> list = OrderedSetUtils.toList(graph, orderedSet);\r
- graph.deny(entity, mapping.orderedSetRelation, orderedSet);\r
- graph.claim(entity, mapping.listRelation, ListUtils.create(graph, mapping.list, list));\r
- }\r
- }\r
-\r
- } \r
- }\r
- });\r
- }\r
- \r
- }\r
-\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * 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.db.layer0.migration;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.PossibleObjectWithType;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.ListUtils;
+import org.simantics.db.common.utils.OrderedSetUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.Instances;
+import org.simantics.layer0.Layer0;
+
+public class OrderedSetToListMigrationStep implements MigrationStep {
+
+ final ArrayList<OrderedSetToListMapping> rules;
+
+ private class OrderedSetToListMapping {
+ public Resource entityType, orderedSet, orderedSetRelation, list, listRelation;
+ }
+
+ public OrderedSetToListMigrationStep(ReadGraph graph, Resource step) throws DatabaseException {
+ rules = new ArrayList<OrderedSetToListMapping>();
+ Layer0 L0 = Layer0.getInstance(graph);
+ for(Resource change : ListUtils.toList(graph, step)) {
+ String entityType = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_entityType, Bindings.STRING);
+ String orderedSet = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_orderedSetType, Bindings.STRING);
+ String orderedSetRelation = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_orderedSetRelation, Bindings.STRING);
+ String list = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_listType, Bindings.STRING);
+ String listRelation = graph.getPossibleRelatedValue(change, L0.OrderedSetToListMigrationStep_listRelation, Bindings.STRING);
+
+ if(orderedSet != null && orderedSetRelation != null && list != null && listRelation != null) {
+ OrderedSetToListMapping mapping = new OrderedSetToListMapping();
+ mapping.entityType = graph.getResource(entityType);
+ mapping.orderedSet = graph.getResource(orderedSet);
+ mapping.orderedSetRelation = graph.getResource(orderedSetRelation);
+ mapping.list = graph.getResource(list);
+ mapping.listRelation = graph.getResource(listRelation);
+ rules.add(mapping);
+ }
+ }
+ }
+
+ @Override
+ public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException {
+ final Resource resource = MigrationUtils.getResource(monitor, session, state);
+
+ if(resource != null) {
+ session.syncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ for(OrderedSetToListMapping mapping : rules) {
+ Instances entityFinder = graph.adapt(mapping.entityType, Instances.class);
+ for(Resource entity : entityFinder.find(graph, resource)) {
+ Resource orderedSet = graph.syncRequest(new PossibleObjectWithType(entity, mapping.orderedSetRelation, mapping.orderedSet));
+ if(orderedSet != null) {
+ Collection<Resource> list = OrderedSetUtils.toList(graph, orderedSet);
+ graph.deny(entity, mapping.orderedSetRelation, orderedSet);
+ graph.claim(entity, mapping.listRelation, ListUtils.create(graph, mapping.list, list));
+ }
+ }
+
+ }
+ }
+ });
+ }
+
+ }
+
+
+}