]> gerrit.simantics Code Review - simantics/district.git/blob
118c8a74745c32934432cd4cb990c7d52042e120
[simantics/district.git] /
1 package org.simantics.district.network.ui.techtype.requests;
2
3 import java.util.UUID;
4
5 import org.simantics.Simantics;
6 import org.simantics.db.Resource;
7 import org.simantics.db.WriteGraph;
8 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
9 import org.simantics.db.common.request.WriteRequest;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.request.PossibleActiveModel;
12 import org.simantics.district.network.ontology.DistrictNetworkResource;
13 import org.simantics.layer0.Layer0;
14
15 public final class WriteTechTypeTableRequest extends WriteRequest {
16         private final String data;
17         private final Resource componentType;
18
19         public WriteTechTypeTableRequest(Resource componentType, String data) {
20                 this.data = data;
21                 this.componentType = componentType;
22         }
23
24         @Override
25         public void perform(WriteGraph graph) throws DatabaseException {
26                 Layer0 L0 = Layer0.getInstance(graph);
27                 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
28
29                 Resource model = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
30                 if (model == null)
31                         throw new DatabaseException("No active model for storing tech type data");
32
33                 Resource ttt = graph.syncRequest(new PossibleTechTypeTable(model, componentType), TransientCacheListener.instance());
34
35                 if (ttt == null) {
36                         ttt = graph.newResource();
37                         graph.claim(ttt, L0.InstanceOf, DN.TechType_TechTypeTable);
38                         graph.claimLiteral(ttt, L0.HasName, UUID.randomUUID().toString());
39                         graph.claim(model, L0.ConsistsOf, ttt);
40                         graph.claim(ttt, DN.TechType_TechTypeTable_HasComponentType, componentType);
41                 }
42
43                 graph.claimLiteral(ttt, DN.TechType_TechTypeTable_HasData, data);
44         }
45 }