2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.core.zusammen.plugin;
19 import com.amdocs.zusammen.datatypes.Id;
20 import com.amdocs.zusammen.datatypes.SessionContext;
21 import com.amdocs.zusammen.datatypes.Space;
22 import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
23 import com.amdocs.zusammen.sdk.collaboration.types.CollaborationElement;
24 import com.amdocs.zusammen.utils.fileutils.FileUtils;
25 import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
27 import java.io.ByteArrayInputStream;
28 import java.nio.ByteBuffer;
30 public class ZusammenPluginUtil {
32 public static String getSpaceName(SessionContext context, Space space) {
35 return ZusammenPluginConstants.PUBLIC_SPACE;
37 return ZusammenPluginUtil.getPrivateSpaceName(context);
39 throw new IllegalArgumentException(String.format("Space %s is not supported.", space));
43 public static String getPrivateSpaceName(SessionContext context) {
44 return context.getUser().getUserName();
47 public static ElementEntity getElementEntity(CollaborationElement element) {
48 ElementEntity elementEntity = new ElementEntity(element.getId());
49 elementEntity.setNamespace(element.getNamespace());
50 elementEntity.setParentId(element.getParentId() == null
51 ? ZusammenPluginConstants.ROOT_ELEMENTS_PARENT_ID
52 : element.getParentId());
53 elementEntity.setInfo(element.getInfo());
54 elementEntity.setRelations(element.getRelations());
55 if (element.getData() != null) {
56 elementEntity.setData(ByteBuffer.wrap(FileUtils.toByteArray(element.getData())));
58 if (element.getSearchableData() != null) {
59 elementEntity.setSearchableData(
60 ByteBuffer.wrap(FileUtils.toByteArray(element.getSearchableData())));
62 if (element.getVisualization() != null) {
63 elementEntity.setVisualization(
64 ByteBuffer.wrap(FileUtils.toByteArray(element.getVisualization())));
69 public static CollaborationElement getCollaborationElement(
70 ElementEntityContext elementEntityContext, ElementEntity elementEntity) {
72 ZusammenPluginConstants.ROOT_ELEMENTS_PARENT_ID.equals(elementEntity.getParentId())
74 : elementEntity.getParentId();
75 CollaborationElement element = new CollaborationElement(elementEntityContext.getItemId(),
76 elementEntityContext.getVersionId(), elementEntity.getNamespace(), elementEntity.getId());
78 element.setParentId(parentId);
79 element.setInfo(elementEntity.getInfo());
80 element.setRelations(elementEntity.getRelations());
82 if (elementEntity.getData() != null) {
83 element.setData(new ByteArrayInputStream(elementEntity.getData().array()));
85 if (elementEntity.getSearchableData() != null) {
86 element.setSearchableData(
87 new ByteArrayInputStream(elementEntity.getSearchableData().array()));
89 if (elementEntity.getVisualization() != null) {
90 element.setVisualization(new ByteArrayInputStream(elementEntity.getVisualization().array()));
92 element.setSubElements(elementEntity.getSubElementIds());