/
GenericRelationship.java
139 lines (113 loc) · 3.93 KB
/
GenericRelationship.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Copyright (C) 2010-2016 Structr GmbH
*
* This file is part of Structr <http://structr.org>.
*
* Structr is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Structr is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Structr. If not, see <http://www.gnu.org/licenses/>.
*/
package org.structr.core.entity;
//~--- JDK imports ------------------------------------------------------------
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.structr.api.graph.Relationship;
import org.structr.common.PropertyView;
import org.structr.common.SecurityContext;
import org.structr.common.View;
import org.structr.common.error.ErrorBuffer;
import org.structr.common.error.FrameworkException;
import org.structr.core.app.StructrApp;
import org.structr.core.graph.ModificationQueue;
import org.structr.core.graph.NodeInterface;
import org.structr.core.property.PropertyKey;
import org.structr.core.property.PropertyMap;
import org.structr.core.property.SourceId;
import org.structr.core.property.TargetId;
//~--- classes ----------------------------------------------------------------
/**
* A generic relationship entity that will be instantiated when an anonymous
* relationship is encountered.
*
*
*
*/
public class GenericRelationship extends ManyToMany<NodeInterface, NodeInterface> {
public static final SourceId startNodeId = new SourceId("startNodeId");
public static final TargetId endNodeId = new TargetId("endNodeId");
public static final View uiView = new View(GenericRelationship.class, PropertyView.Ui,
startNodeId, endNodeId, sourceId, targetId
);
public GenericRelationship() {}
public GenericRelationship(SecurityContext securityContext, Relationship dbRelationship) {
init(securityContext, dbRelationship, GenericRelationship.class);
}
@Override
public Iterable<PropertyKey> getPropertyKeys(String propertyView) {
Set<PropertyKey> keys = new LinkedHashSet<>();
keys.addAll((Set<PropertyKey>) super.getPropertyKeys(propertyView));
keys.add(startNodeId);
keys.add(endNodeId);
if (dbRelationship != null) {
for (String key : dbRelationship.getPropertyKeys()) {
keys.add(StructrApp.getConfiguration().getPropertyKeyForDatabaseName(entityType, key));
}
}
return keys;
}
@Override
public boolean onCreation(SecurityContext securityContext, ErrorBuffer errorBuffer) throws FrameworkException {
return true;
}
@Override
public boolean onModification(SecurityContext securityContext, ErrorBuffer errorBuffer, final ModificationQueue modificationQueue) throws FrameworkException {
return true;
}
@Override
public boolean onDeletion(SecurityContext securityContext, ErrorBuffer errorBuffer, PropertyMap properties) throws FrameworkException {
return true;
}
@Override
public boolean isValid(ErrorBuffer errorBuffer) {
return true;
}
@Override
public Class<NodeInterface> getSourceType() {
return NodeInterface.class;
}
@Override
public Class<NodeInterface> getTargetType() {
return NodeInterface.class;
}
@Override
public String name() {
return "GENERIC";
}
// @Override
// public SourceId getSourceIdProperty() {
// return startNodeId;
// }
//
// @Override
// public TargetId getTargetIdProperty() {
// return endNodeId;
// }
@Override
public Object invokeMethod(String methodName, Map<String, Object> parameters, final boolean throwExceptionForUnknownMethods) throws FrameworkException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isInternal() {
return false;
}
}