-/*\r
- * ============LICENSE_START========================================================================\r
- * ONAP : tr-069-adapter\r
- * =================================================================================================\r
- * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
- * =================================================================================================\r
- * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
- * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
- * may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
- * either express or implied. See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ===============LICENSE_END=======================================================================\r
- */\r
-\r
-package org.commscope.tr069adapter.acs.requestprocessor.impl;\r
-\r
-import com.fasterxml.uuid.EthernetAddress;\r
-import com.fasterxml.uuid.Generators;\r
-import com.fasterxml.uuid.impl.TimeBasedGenerator;\r
-\r
-import java.util.Optional;\r
-import java.util.UUID;\r
-\r
-import org.commscope.tr069adapter.acs.common.exception.SessionConcurrentAccessException;\r
-import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;\r
-import org.commscope.tr069adapter.acs.common.utils.ErrorCode;\r
-import org.commscope.tr069adapter.acs.requestprocessor.dao.SessionRepository;\r
-import org.commscope.tr069adapter.acs.requestprocessor.dto.SessionDTO;\r
-import org.commscope.tr069adapter.acs.requestprocessor.dto.SessionState;\r
-import org.commscope.tr069adapter.acs.requestprocessor.entity.SessionManagerEntity;\r
-import org.commscope.tr069adapter.acs.requestprocessor.util.SessionManagerUtility;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.stereotype.Component;\r
-\r
-@Component\r
-public class SessionManager {\r
-\r
- private static final Logger logger = LoggerFactory.getLogger(SessionManager.class);\r
-\r
- @Autowired\r
- SessionRepository sessionRepository;\r
-\r
- /**\r
- * @param deviceId\r
- * @return\r
- * @throws SessionManagerException\r
- */\r
- public SessionDTO getSession(String deviceId) {\r
- SessionManagerEntity session = null;\r
- Optional<SessionManagerEntity> optionalSessionData = sessionRepository.findById(deviceId);\r
- if (optionalSessionData.isPresent()) {\r
- session = optionalSessionData.get();\r
- }\r
- return SessionManagerUtility.convertToDTO(session);\r
- }\r
-\r
- /**\r
- * @param sessionId\r
- * @return\r
- * @throws SessionManagerException\r
- */\r
- public SessionDTO getSessionBySessionId(String sessionId) throws SessionManagerException {\r
-\r
- SessionManagerEntity sessionManagerEntity = sessionRepository.findBySessionId(sessionId);\r
- if (sessionManagerEntity == null || SessionState.TERMINATED\r
- .equals(SessionState.getByValue(sessionManagerEntity.getState()))) {\r
- throw new SessionManagerException(ErrorCode.SESSION_EXPIRED, sessionId);\r
- }\r
- return SessionManagerUtility.convertToDTO(sessionManagerEntity);\r
- }\r
-\r
- /**\r
- * @param session\r
- * @return\r
- * @throws SessionManagerException\r
- */\r
- public SessionDTO createSession(SessionDTO session) throws SessionManagerException {\r
- if (session == null) {\r
- SessionManagerException sme = new SessionManagerException(ErrorCode.SESSION_CREATION_ERROR,\r
- "Session object cannot be null");\r
- logger.error(sme.getMessage());\r
- throw sme;\r
- }\r
- logger.debug("Creating a new session for the device");\r
- return SessionManagerUtility\r
- .convertToDTO(sessionRepository.save(SessionManagerUtility.convertToEntity(session)));\r
- }\r
-\r
- /**\r
- * @param dto\r
- * @return\r
- * @throws SessionManagerException\r
- */\r
- public SessionDTO updateSession(SessionDTO dto) {\r
- return SessionManagerUtility\r
- .convertToDTO(sessionRepository.save(SessionManagerUtility.convertToEntity(dto)));\r
- }\r
-\r
- /**\r
- * @param deviceId\r
- * @throws SessionConcurrentAccessException\r
- */\r
- public void deleteSession(String deviceId) {\r
- sessionRepository.deleteById(deviceId);\r
- }\r
-\r
- /**\r
- * @param deviceId\r
- * @return\r
- * @throws SessionManagerException\r
- */\r
- public SessionDTO getLockedSession(String deviceId) {\r
- logger.debug("Acquiring the session lock for the device");\r
- return SessionManagerUtility.convertToDTO(sessionRepository.findByDeviceId(deviceId));\r
- }\r
-\r
- /**\r
- * @return\r
- */\r
- public String generateUniqueSessionID() {\r
- EthernetAddress addr = EthernetAddress.fromInterface();\r
- TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(addr);\r
- UUID uuid = uuidGenerator.generate();\r
- return uuid.toString();\r
- }\r
-\r
-}\r
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : tr-069-adapter
+ * =================================================================================================
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.
+ * =================================================================================================
+ * This tr-069-adapter software file is distributed by CommScope Inc 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
+ *
+ * This file 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.commscope.tr069adapter.acs.requestprocessor.impl;
+
+import com.fasterxml.uuid.EthernetAddress;
+import com.fasterxml.uuid.Generators;
+import com.fasterxml.uuid.impl.TimeBasedGenerator;
+
+import java.util.Optional;
+import java.util.UUID;
+
+import org.commscope.tr069adapter.acs.common.exception.SessionConcurrentAccessException;
+import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;
+import org.commscope.tr069adapter.acs.common.utils.ErrorCode;
+import org.commscope.tr069adapter.acs.requestprocessor.dao.SessionRepository;
+import org.commscope.tr069adapter.acs.requestprocessor.dto.SessionDTO;
+import org.commscope.tr069adapter.acs.requestprocessor.dto.SessionState;
+import org.commscope.tr069adapter.acs.requestprocessor.entity.SessionManagerEntity;
+import org.commscope.tr069adapter.acs.requestprocessor.util.SessionManagerUtility;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SessionManager {
+
+ private static final Logger logger = LoggerFactory.getLogger(SessionManager.class);
+
+ @Autowired
+ SessionRepository sessionRepository;
+
+ /**
+ * @param deviceId
+ * @return
+ * @throws SessionManagerException
+ */
+ public SessionDTO getSession(String deviceId) {
+ SessionManagerEntity session = null;
+ Optional<SessionManagerEntity> optionalSessionData = sessionRepository.findById(deviceId);
+ if (optionalSessionData.isPresent()) {
+ session = optionalSessionData.get();
+ }
+ return SessionManagerUtility.convertToDTO(session);
+ }
+
+ /**
+ * @param sessionId
+ * @return
+ * @throws SessionManagerException
+ */
+ public SessionDTO getSessionBySessionId(String sessionId) throws SessionManagerException {
+
+ SessionManagerEntity sessionManagerEntity = sessionRepository.findBySessionId(sessionId);
+ if (sessionManagerEntity == null || SessionState.TERMINATED
+ .equals(SessionState.getByValue(sessionManagerEntity.getState()))) {
+ throw new SessionManagerException(ErrorCode.SESSION_EXPIRED, sessionId);
+ }
+ return SessionManagerUtility.convertToDTO(sessionManagerEntity);
+ }
+
+ /**
+ * @param session
+ * @return
+ * @throws SessionManagerException
+ */
+ public SessionDTO createSession(SessionDTO session) throws SessionManagerException {
+ if (session == null) {
+ SessionManagerException sme = new SessionManagerException(ErrorCode.SESSION_CREATION_ERROR,
+ "Session object cannot be null");
+ String smeMessage = sme.getMessage().replaceAll("[\n|\r|\t]", "_");
+ logger.error(smeMessage);
+ throw sme;
+ }
+ logger.debug("Creating a new session for the device");
+ return SessionManagerUtility
+ .convertToDTO(sessionRepository.save(SessionManagerUtility.convertToEntity(session)));
+ }
+
+ /**
+ * @param dto
+ * @return
+ * @throws SessionManagerException
+ */
+ public SessionDTO updateSession(SessionDTO dto) {
+ return SessionManagerUtility
+ .convertToDTO(sessionRepository.save(SessionManagerUtility.convertToEntity(dto)));
+ }
+
+ /**
+ * @param deviceId
+ * @throws SessionConcurrentAccessException
+ */
+ public void deleteSession(String deviceId) {
+ sessionRepository.deleteById(deviceId);
+ }
+
+ /**
+ * @param deviceId
+ * @return
+ * @throws SessionManagerException
+ */
+ public SessionDTO getLockedSession(String deviceId) {
+ logger.debug("Acquiring the session lock for the device");
+ return SessionManagerUtility.convertToDTO(sessionRepository.findByDeviceId(deviceId));
+ }
+
+ /**
+ * @return
+ */
+ public String generateUniqueSessionID() {
+ EthernetAddress addr = EthernetAddress.fromInterface();
+ TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(addr);
+ UUID uuid = uuidGenerator.generate();
+ return uuid.toString();
+ }
+
+}