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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* Copyright © 2016-2017 European Support Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openecomp.core.zusammen.plugin.main;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.Space;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.ItemVersion;
import com.amdocs.zusammen.datatypes.item.ItemVersionData;
import com.amdocs.zusammen.datatypes.response.Response;
import com.amdocs.zusammen.plugin.statestore.cassandra.StateStoreImpl;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
import com.amdocs.zusammen.sdk.state.types.StateElement;
import org.openecomp.core.zusammen.plugin.ZusammenPluginUtil;
import org.openecomp.core.zusammen.plugin.collaboration.ElementPrivateStore;
import org.openecomp.core.zusammen.plugin.collaboration.impl.ElementPrivateStoreImpl;
import org.openecomp.core.zusammen.plugin.dao.ElementRepository;
import org.openecomp.core.zusammen.plugin.dao.ElementRepositoryFactory;
import org.openecomp.core.zusammen.plugin.dao.VersionDao;
import org.openecomp.core.zusammen.plugin.dao.VersionDaoFactory;
import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
import org.openecomp.core.zusammen.plugin.dao.types.VersionDataElement;
import org.openecomp.core.zusammen.plugin.dao.types.VersionEntity;
import java.util.Collection;
import java.util.Date;
import java.util.stream.Collectors;
import static org.openecomp.core.zusammen.plugin.ZusammenPluginUtil.convertToItemVersion;
import static org.openecomp.core.zusammen.plugin.ZusammenPluginUtil.getSpaceName;
public class CassandraStateStorePluginImpl extends StateStoreImpl {
private ElementPrivateStore elementPrivateStore = new ElementPrivateStoreImpl();
@Override
public Response<Collection<ItemVersion>> listItemVersions(SessionContext context, Space space,
Id itemId) {
String spaceName = getSpaceName(context, space);
return new Response<>(getVersionDao(context).list(context, spaceName, itemId).stream()
.map(versionEntity -> getItemVersion(context, spaceName, itemId, versionEntity))
.collect(Collectors.toList()));
}
@Override
public Response<Boolean> isItemVersionExist(SessionContext context, Space space, Id itemId,
Id versionId) {
return new Response<>(
getVersionDao(context).get(context, getSpaceName(context, space), itemId, versionId)
.isPresent());
}
@Override
public Response<ItemVersion> getItemVersion(SessionContext context, Space space, Id itemId,
Id versionId) {
String spaceName = getSpaceName(context, space);
return new Response<>(getVersionDao(context).get(context, spaceName, itemId, versionId)
.map(versionEntity -> getItemVersion(context, spaceName, itemId, versionEntity))
.orElse(null));
}
@Override
public Response<Void> createItemVersion(SessionContext context, Space space, Id itemId,
Id baseVersionId, Id versionId, ItemVersionData data,
Date creationTime) {
// done by collaboration store
return new Response(Void.TYPE);
}
@Override
public Response<Void> updateItemVersion(SessionContext context, Space space, Id itemId,
Id versionId, ItemVersionData data,
Date modificationTime) {
// done by collaboration store
return new Response(Void.TYPE);
}
@Override
public Response<Void> deleteItemVersion(SessionContext context, Space space, Id itemId,
Id versionId) {
// done by collaboration store
return new Response(Void.TYPE);
}
@Override
public Response<Void> createElement(SessionContext context, StateElement element) {
ElementEntity elementEntity = new ElementEntity(element.getId());
elementEntity.setNamespace(element.getNamespace());
ElementRepositoryFactory.getInstance().createInterface(context)
.createNamespace(context,
new ElementEntityContext(getSpaceName(context, element.getSpace()),
element.getItemId(), element.getVersionId()), elementEntity);
// create element is done by collaboration store
return new Response(Void.TYPE);
}
@Override
public Response<Void> updateElement(SessionContext context, StateElement element) {
// done by collaboration store
return new Response(Void.TYPE);
}
@Override
public Response<Void> deleteElement(SessionContext context, StateElement element) {
// done by collaboration store
return new Response(Void.TYPE);
}
@Override
public Response<Collection<StateElement>> listElements(SessionContext context,
ElementContext elementContext,
Id elementId) {
return new Response(elementPrivateStore.listSubs(context, elementContext, elementId).stream()
.map(elementEntity -> ZusammenPluginUtil.getStateElement(elementContext, elementEntity))
.collect(Collectors.toList()));
}
@Override
public Response<StateElement> getElement(SessionContext context, ElementContext elementContext,
Id elementId) {
return new Response(elementPrivateStore.get(context, elementContext, elementId)
.map(elementEntity -> ZusammenPluginUtil
.getStateElement(elementContext, elementEntity))
.orElse
(null));
}
private ItemVersion getItemVersion(SessionContext context, String spaceName, Id itemId,
VersionEntity versionEntity) {
ItemVersionData itemVersionData = getElementRepository(context)
.get(context, new ElementEntityContext(spaceName, itemId, versionEntity.getId(), null),
new VersionDataElement())
.map(ZusammenPluginUtil::convertToVersionData)
.orElseThrow(() -> new IllegalStateException("Version must have data"));
return convertToItemVersion(versionEntity, itemVersionData);
}
protected VersionDao getVersionDao(SessionContext context) {
return VersionDaoFactory.getInstance().createInterface(context);
}
protected ElementRepository getElementRepository(SessionContext context) {
return ElementRepositoryFactory.getInstance().createInterface(context);
}
}
|