/******************************************************************************* * Copyright (c) 2007, 2010 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.tests.api.request.misc; import org.junit.Test; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.adaption.AdaptionService; import org.simantics.db.common.adaption.SimpleAdapter; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ServiceException; import org.simantics.db.exception.ValidationException; import org.simantics.db.request.Read; import org.simantics.db.services.adaption.AdaptionService2; import org.simantics.db.testing.base.ExistingDatabaseTest; import org.simantics.layer0.Layer0; public class SyncAsyncSyncTest7 extends ExistingDatabaseTest { @Test public void test() throws Exception { Session session = getSession(); AdaptionService2 adaptionService = new AdaptionService2(); Layer0 b = Layer0.getInstance(session); adaptionService.addAdapter(b.Entity, String.class, new SimpleAdapter() { @Override public String adapt(ReadGraph g, Resource r) throws ValidationException, ServiceException { return "SIMPLE"; } }); session.registerService(AdaptionService.class, adaptionService); session.syncRequest(new Read() { @Override public String perform(ReadGraph graph) throws DatabaseException { // Assert.isTrue(path.length > 0); // String[] namePath = new String[path.length]; // String description = ""; // int version = 0; // for (int i = 0; i < namePath.length; i++) { // String name = g.getRelatedValue(path[i], g.getBuiltins().HasName); // Assert.isTrue(name != null); // Assert.isTrue(name.length() > 0); // namePath[i] = name; // // Layer0 b = Layer0.getInstance(g); // // if (i == namePath.length - 1) { // if (g.isInstanceOf(path[i], b.Project2)) { // version = 2; // StringBuilder desc = new StringBuilder(); // boolean first = true; // for (Resource pf : g.getObjects(path[i], b.HasFeature)) { // if (!first) { // desc.append(", "); // } // first = false; // String d = null; // try { return graph.adapt(graph.getRootLibrary(), String.class); // } catch (AdaptionException e) { // d = GraphUtils.getReadableName(g, pf.get()); // } // desc.append(d); // } // description = desc.toString(); // } // } } }); } }