aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenUtil.java
blob: a6595699f5877e6a7dde04326b29c5814f14084a (plain)
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
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */
package org.openecomp.core.zusammen.api;

import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.UserInfo;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.Info;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
import org.openecomp.sdc.datatypes.model.ElementType;
import org.openecomp.types.ElementPropertyName;

public class ZusammenUtil {

    private ZusammenUtil() {
        throw new IllegalStateException("Utility class");
    }

    public static SessionContext createSessionContext() {
        org.openecomp.sdc.common.session.SessionContext asdcSessionContext = SessionContextProviderFactory.getInstance().createInterface().get();
        return createSessionContext(asdcSessionContext.getUser().getUserId(), asdcSessionContext.getTenant());
    }

    private static SessionContext createSessionContext(String user, String tenant) {
        SessionContext sessionContext = new SessionContext();
        sessionContext.setUser(new UserInfo(user));
        sessionContext.setTenant(tenant);
        return sessionContext;
    }

    public static ZusammenElement buildStructuralElement(ElementType elementType, Action action) {
        return buildStructuralElement(elementType.name(), action);
    }

    public static ZusammenElement buildStructuralElement(String elementType, Action action) {
        ZusammenElement element = buildElement(null, action);
        Info info = new Info();
        info.setName(elementType);
        info.addProperty(ElementPropertyName.elementType.name(), elementType);
        element.setInfo(info);
        return element;
    }

    public static ZusammenElement buildElement(Id elementId, Action action) {
        ZusammenElement element = new ZusammenElement();
        element.setElementId(elementId);
        element.setAction(action);
        return element;
    }
}