From 8e9c0653dd6c6862123c9609ae34e1206d86456e Mon Sep 17 00:00:00 2001 From: talig Date: Wed, 20 Dec 2017 14:30:43 +0200 Subject: Add collaboration feature Issue-ID: SDC-767 Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795 Signed-off-by: talig --- .../sdc/common/session/SessionContext.java | 8 ++++ .../sdc/common/session/SessionContextProvider.java | 10 +++++ .../session/SessionContextProviderFactory.java | 32 ++++++++++++++ .../org/openecomp/sdc/common/session/User.java | 13 ++++++ .../session/impl/AsdcSessionContextProvider.java | 50 ++++++++++++++++++++++ .../impl/SessionContextProviderFactoryImpl.java | 33 ++++++++++++++ .../src/main/resources/factoryConfiguration.json | 3 ++ 7 files changed, 149 insertions(+) create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/resources/factoryConfiguration.json (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src') diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java new file mode 100644 index 0000000000..a1b410c90c --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java @@ -0,0 +1,8 @@ +package org.openecomp.sdc.common.session; + +public interface SessionContext { + + User getUser(); + + String getTenant(); +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java new file mode 100644 index 0000000000..8efbbd10eb --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java @@ -0,0 +1,10 @@ +package org.openecomp.sdc.common.session; + +public interface SessionContextProvider { + + void create(String user); + + SessionContext get(); + + void close(); +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java new file mode 100644 index 0000000000..cfa6a346c9 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.common.session; + +import org.openecomp.core.factory.api.AbstractComponentFactory; +import org.openecomp.core.factory.api.AbstractFactory; + +public abstract class SessionContextProviderFactory + extends AbstractComponentFactory { + + public static SessionContextProviderFactory getInstance() { + return AbstractFactory.getInstance(SessionContextProviderFactory.class); + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java new file mode 100644 index 0000000000..5319a0bf56 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java @@ -0,0 +1,13 @@ +package org.openecomp.sdc.common.session; + +public class User { + private final String userId; + + public User(String userId) { + this.userId = userId; + } + + public String getUserId() { + return userId; + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java new file mode 100644 index 0000000000..53a40a163f --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java @@ -0,0 +1,50 @@ +package org.openecomp.sdc.common.session.impl; + +import org.openecomp.sdc.common.session.SessionContext; +import org.openecomp.sdc.common.session.SessionContextProvider; +import org.openecomp.sdc.common.session.User; + +public class AsdcSessionContextProvider implements SessionContextProvider { + + private static final ThreadLocal threadUserId = new ThreadLocal<>(); + + @Override + public void create(String userId) { + threadUserId.set(userId); + } + + @Override + public SessionContext get() { + if (threadUserId.get() == null) { + throw new RuntimeException("UserId was not set for this thread"); + } + + return new AsdcSessionContext(new User(threadUserId.get()), "dox"); + } + + @Override + public void close() { + threadUserId.remove(); + } + + private static class AsdcSessionContext implements SessionContext { + + private final User user; + private final String tenant; + + private AsdcSessionContext(User user, String tenant) { + this.user = user; + this.tenant = tenant; + } + + @Override + public User getUser() { + return user; + } + + @Override + public String getTenant() { + return tenant; + } + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java new file mode 100644 index 0000000000..635aa5b6ed --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 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.sdc.common.session.impl; + +import org.openecomp.sdc.common.session.SessionContextProvider; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; + +public class SessionContextProviderFactoryImpl extends SessionContextProviderFactory { + private static final SessionContextProvider INSTANCE = new AsdcSessionContextProvider(); + + @Override + public SessionContextProvider createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/resources/factoryConfiguration.json new file mode 100644 index 0000000000..cd1637a80e --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/resources/factoryConfiguration.json @@ -0,0 +1,3 @@ +{ + "org.openecomp.sdc.common.session.SessionContextProviderFactory": "org.openecomp.sdc.common.session.impl.SessionContextProviderFactoryImpl" +} \ No newline at end of file -- cgit 1.2.3-korg