Added oparent to sdc main
[sdc.git] / openecomp-be / lib / openecomp-core-lib / openecomp-zusammen-lib / openecomp-zusammen-api / src / main / java / org / openecomp / core / zusammen / api / ZusammenUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.core.zusammen.api;
21
22 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
23 import com.amdocs.zusammen.datatypes.Id;
24 import com.amdocs.zusammen.datatypes.SessionContext;
25 import com.amdocs.zusammen.datatypes.UserInfo;
26 import com.amdocs.zusammen.datatypes.item.Action;
27 import com.amdocs.zusammen.datatypes.item.Info;
28 import org.openecomp.sdc.common.session.SessionContextProviderFactory;
29 import org.openecomp.sdc.datatypes.model.ElementType;
30 import org.openecomp.types.ElementPropertyName;
31
32 public class ZusammenUtil {
33
34   private ZusammenUtil() {
35     throw new IllegalStateException("Utility class");
36   }
37
38   public static SessionContext createSessionContext() {
39     org.openecomp.sdc.common.session.SessionContext asdcSessionContext =
40         SessionContextProviderFactory.getInstance().createInterface().get();
41
42     return createSessionContext(asdcSessionContext.getUser().getUserId(), asdcSessionContext
43         .getTenant());
44   }
45
46   private static SessionContext createSessionContext(String user, String tenant) {
47     SessionContext sessionContext = new SessionContext();
48     sessionContext.setUser(new UserInfo(user));
49     sessionContext.setTenant(tenant);
50     return sessionContext;
51   }
52
53   public static ZusammenElement buildStructuralElement(ElementType elementType, Action action) {
54     return buildStructuralElement(elementType.name(), action);
55   }
56
57
58   public static ZusammenElement buildStructuralElement(String elementType, Action action) {
59     ZusammenElement element = buildElement(null, action);
60     Info info = new Info();
61     info.setName(elementType);
62     info.addProperty(ElementPropertyName.elementType.name(), elementType);
63     element.setInfo(info);
64     return element;
65   }
66
67   public static ZusammenElement buildElement(Id elementId, Action action) {
68     ZusammenElement element = new ZusammenElement();
69     element.setElementId(elementId);
70     element.setAction(action);
71     return element;
72   }
73 }