summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java142
-rw-r--r--ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicCleanUp.java5
-rw-r--r--ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java35
3 files changed, 91 insertions, 91 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
index 139f69a2..acf94bae 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/service/OnBoardingApiServiceImpl.java
@@ -38,7 +38,6 @@
package org.onap.portalapp.service;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -46,7 +45,6 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
@@ -81,7 +79,6 @@ import org.onap.portalsdk.core.web.support.UserUtils;
import org.slf4j.MDC;
import org.springframework.context.ApplicationContext;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -107,10 +104,10 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
private RestApiRequestBuilder restApiRequestBuilder;
private AppService appServiceImpl;
- private static final String isAccessCentralized = PortalApiProperties
+ private static final String IS_ACCESS_CENTRALIZED = PortalApiProperties
.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED);
- private static final String isCentralized = "remote";
+ private static final String IS_CENTRALIZED = "remote";
private static String portalApiVersion = "/v3";
public OnBoardingApiServiceImpl() {
@@ -118,7 +115,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
// that was caused by a spurious Spring annotation on this class.
ApplicationContext appContext = AppContextManager.getAppContext();
if (appContext == null)
- throw new RuntimeException("OnBoardingApiServiceImpl ctor failed to get appContext");
+ throw new IllegalStateException("OnBoardingApiServiceImpl ctor failed to get appContext");
roleService = appContext.getBean(RoleService.class);
userProfileService = appContext.getBean(UserProfileService.class);
loginStrategy = appContext.getBean(LoginStrategy.class);
@@ -127,7 +124,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
userService = appContext.getBean(UserService.class);
appServiceImpl = appContext.getBean(AppService.class);
- if(isCentralized.equals(isAccessCentralized)){
+ if(IS_CENTRALIZED.equals(IS_ACCESS_CENTRALIZED)){
restApiRequestBuilder = appContext.getBean(RestApiRequestBuilder.class);
}
}
@@ -148,7 +145,17 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
user.setPhone(userJson.getPhone());
user.setOrgUserId(userJson.getOrgUserId());
user.setActive(userJson.isActive());
-// user.setRoles(new TreeSet(userJson.getRoles()));
+ }
+
+ private void saveUserExtension(User user)
+ {
+ if (adminAuthExtensionServiceImpl != null) {
+ try {
+ adminAuthExtensionServiceImpl.saveUserExtension(user);
+ } catch (Exception ex) {
+ logger.error("pushUser: saveUserExtension failed", ex);
+ }
+ }
}
@Override
@@ -156,7 +163,6 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
if (logger.isDebugEnabled())
logger.debug(EELFLoggerDelegate.debugLogger, "pushUser was invoked: {}", userJson);
User user = new User();
- String response = "";
try {
// Set input attributes to the object obout to be saved
setCurrentAttributes(user, userJson);
@@ -185,17 +191,9 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
roles.add(convertToRole(epRole));
}
user.setRoles(roles);
- if (adminAuthExtensionServiceImpl != null) {
- try {
- adminAuthExtensionServiceImpl.saveUserExtension(user);
- } catch (Exception ex) {
- logger.error("pushUser: saveUserExtension failed", ex);
- }
- }
- response = "push user success.";
- response = JSONUtil.convertResponseToJSON(response);
+ saveUserExtension(user);
} catch (Exception e) {
- response = "OnboardingApiService.pushUser failed";
+ String response = "OnboardingApiService.pushUser failed";
logger.error(EELFLoggerDelegate.errorLogger, response, e);
throw new PortalAPIException(response, e);
} finally {
@@ -230,7 +228,17 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
roleFunction.setAction(rolefun.getAction());
return roleFunction;
}
-
+
+ private void editUserExtension(User domainUser)
+ {
+ if (adminAuthExtensionServiceImpl != null) {
+ try {
+ adminAuthExtensionServiceImpl.editUserExtension(domainUser);
+ } catch (Exception ex) {
+ logger.error("editUser: editUserExtension failed", ex);
+ }
+ }
+ }
@Override
public void editUser(String loginId, EcompUser userJson) throws PortalAPIException {
@@ -239,7 +247,6 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
logger.debug(EELFLoggerDelegate.debugLogger, "OnboardingApi editUser was invoked with loginID {}, JSON {}",
loginId, userJson);
User editUser = new User();
- String response = "";
try {
setCurrentAttributes(editUser, userJson);
if (editUser.getOrgUserId() != null) {
@@ -266,25 +273,15 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
domainUser.setRoles(roles);
// After successful edit, call the admin auth extension
- if (adminAuthExtensionServiceImpl != null) {
- try {
- adminAuthExtensionServiceImpl.editUserExtension(domainUser);
- } catch (Exception ex) {
- logger.error("editUser: editUserExtension failed", ex);
- }
- }
+ editUserExtension(domainUser);
- response = "edit user success.";
- response = JSONUtil.convertResponseToJSON(response);
} catch (Exception e) {
- response = "OnboardingApiService.editUser failed";
+ String response = "OnboardingApiService.editUser failed";
logger.error(EELFLoggerDelegate.errorLogger, response, e);
throw new PortalAPIException(response, e);
} finally {
MDC.remove(SystemProperties.MDC_TIMER);
}
-
- // return response;
}
@Override
@@ -294,14 +291,14 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: {}", loginId);
User user = null;
- if (isCentralized.equals(isAccessCentralized)) {
+ if (IS_CENTRALIZED.equals(IS_ACCESS_CENTRALIZED)) {
String responseString = restApiRequestBuilder.getViaREST(portalApiVersion+"/user/" + loginId, true,
loginId);
user = userService.userMapper(responseString);
}
else{
user = userProfileService.getUserByLoginId(loginId);
- user.getRoles().removeIf(role -> (role.getActive() == false));
+ user.getRoles().removeIf(role -> (!role.getActive()));
}
if (user == null) {
logger.info(EELFLoggerDelegate.debugLogger, "User + " + loginId + " doesn't exist");
@@ -326,20 +323,20 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
@Override
public List<EcompUser> getUsers() throws PortalAPIException {
- String users_List = "";
+ String usersList = "";
try {
- if (isCentralized.equals(isAccessCentralized)) {
- List<EcompUser> UsersList = new ArrayList<>();
+ if (IS_CENTRALIZED.equals(IS_ACCESS_CENTRALIZED)) {
+ List<EcompUser> ecompUsers;
List<EcompUser> finalUsersList = new ArrayList<>();
- users_List = restApiRequestBuilder.getViaREST(portalApiVersion + "/users", true, null);
+ usersList = restApiRequestBuilder.getViaREST(portalApiVersion + "/users", true, null);
ObjectMapper mapper = new ObjectMapper();
- UsersList = mapper.readValue(users_List,
+ ecompUsers = mapper.readValue(usersList,
TypeFactory.defaultInstance().constructCollectionType(List.class, EcompUser.class));
- for (EcompUser userString : UsersList) {
+ for (EcompUser userString : ecompUsers) {
EcompUser ecompUser = mapper.convertValue(userString, EcompUser.class);
finalUsersList.add(ecompUser);
}
- return UsersList;
+ return ecompUsers;
}
else {
List<User> users = userProfileService.findAllActive();
@@ -351,7 +348,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
} catch (Exception e) {
String response = "OnboardingApiService.getUsers failed";
logger.error(EELFLoggerDelegate.errorLogger, response, e);
- if (users_List.equals("")) {
+ if (usersList.isEmpty()) {
throw new PortalAPIException("Application is Inactive");
} else {
throw new PortalAPIException(response, e);
@@ -374,9 +371,19 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
}
}
+ private void saveUserRoleExtension(Set<Role> roles, User user)
+ {
+ if (adminAuthExtensionServiceImpl != null) {
+ try {
+ adminAuthExtensionServiceImpl.saveUserRoleExtension(roles, user);
+ } catch (Exception ex) {
+ logger.error("pushUserRole: saveUserRoleExtension failed", ex);
+ }
+ }
+ }
+
@Override
public void pushUserRole(String loginId, List<EcompRole> rolesJson) throws PortalAPIException {
- String response = "";
try {
if (logger.isDebugEnabled())
logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: {}, roles Json {}", loginId,
@@ -397,26 +404,23 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
logger.debug(EELFLoggerDelegate.debugLogger, "push user role success.");
// After successful creation, call admin auth extension
- if (adminAuthExtensionServiceImpl != null) {
- try {
- adminAuthExtensionServiceImpl.saveUserRoleExtension(roles, user);
- } catch (Exception ex) {
- logger.error("pushUserRole: saveUserRoleExtension failed", ex);
- }
- }
- response = "push user role success.";
- response = JSONUtil.convertResponseToJSON(response);
-
+ saveUserRoleExtension(roles,user);
} catch (Exception e) {
- response = "OnboardingApiService.pushUserRole failed";
+ String response = "OnboardingApiService.pushUserRole failed";
logger.error(EELFLoggerDelegate.errorLogger, response, e);
throw new PortalAPIException(response, e);
} finally {
MDC.remove(SystemProperties.MDC_TIMER);
}
-
}
+ private static void addRoles2Ecomp(SortedSet<Role> currentRoles,List<EcompRole> ecompRoles)
+ {
+ if (currentRoles != null && ecompRoles!=null)
+ for (Role role : currentRoles)
+ ecompRoles.add(UserUtils.convertToEcompRole(role));
+ }
+
@Override
public List<EcompRole> getUserRoles(String loginId) throws PortalAPIException {
if (logger.isDebugEnabled())
@@ -424,7 +428,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
List<EcompRole> ecompRoles = new ArrayList<>();
try {
- if (isCentralized.equals(isAccessCentralized)) {
+ if (IS_CENTRALIZED.equals(IS_ACCESS_CENTRALIZED)) {
User user = null;
String responseString = restApiRequestBuilder.getViaREST(portalApiVersion+"/user/" + loginId, true,
loginId);
@@ -432,19 +436,15 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
SortedSet<Role> currentRoles = null;
if (user != null) {
currentRoles = user.getRoles();
- if (currentRoles != null)
- for (Role role : currentRoles)
- ecompRoles.add(UserUtils.convertToEcompRole(role));
+ addRoles2Ecomp(currentRoles,ecompRoles);
}
} else {
User user = userProfileService.getUserByLoginId(loginId);
SortedSet<Role> currentRoles = null;
if (user != null) {
currentRoles = user.getRoles();
- currentRoles.removeIf(role -> (role.getActive() == false));
- if (currentRoles != null)
- for (Role role : currentRoles)
- ecompRoles.add(UserUtils.convertToEcompRole(role));
+ currentRoles.removeIf(role -> (!role.getActive()));
+ addRoles2Ecomp(currentRoles,ecompRoles);
}
}
return ecompRoles;
@@ -486,13 +486,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
try {
String appUser = request.getHeader("username");
String password = request.getHeader("password");
- // System.out.println("username = " + appUser);
- // System.out.println("password = " + password);
- boolean flag = securityService.verifyRESTCredential(null, appUser, password);
- // System.out.println("username = " + appUser);
- // System.out.println("password = " + password);
- return flag;
-
+ return securityService.verifyRESTCredential(null, appUser, password);
} catch (Exception e) {
String response = "OnboardingApiService.isAppAuthenticated failed";
logger.error(EELFLoggerDelegate.errorLogger, response, e);
@@ -500,11 +494,11 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
}
}
- public String getSessionTimeOuts() throws Exception {
+ public String getSessionTimeOuts() {
return PortalTimeoutHandler.gatherSessionExtensions();
}
- public void updateSessionTimeOuts(String sessionMap) throws Exception {
+ public void updateSessionTimeOuts(String sessionMap) {
PortalTimeoutHandler.updateSessionExtensions(sessionMap);
}
@@ -514,7 +508,7 @@ public class OnBoardingApiServiceImpl implements IPortalRestAPIService, IPortalR
}
@Override
- public Map<String, String> getAppCredentials() throws PortalAPIException{
+ public Map<String, String> getAppCredentials() {
Map<String, String> credentialsMap = new HashMap<>();
String appName = null;
String appUserName = null;
diff --git a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicCleanUp.java b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicCleanUp.java
index aab04eaf..72ce5f67 100644
--- a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicCleanUp.java
+++ b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicCleanUp.java
@@ -42,12 +42,13 @@ import java.util.Date;
public class MusicCleanUp {
private static volatile MusicCleanUp musicCleanUp = new MusicCleanUp();
+
+ private Date lastCleanUpTime = new Date();
+
// private constructor restricted to this class itself
private MusicCleanUp(){
}
- private Date lastCleanUpTime = new Date();
-
public static MusicCleanUp getInstance(){
return musicCleanUp;
}
diff --git a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java
index 15c3bb0c..2e17d0c1 100644
--- a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java
+++ b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java
@@ -68,11 +68,18 @@ public class MusicUtil {
private static String cleanUpFreq = MusicProperties.getProperty(MusicProperties.MUSIC_CLEAN_UP_FREQUENCY);
private static String musicSerializeCompress = MusicProperties.getProperty(MusicProperties.MUSIC_SERIALIZE_COMPRESS);
private static String musicEnable = MusicProperties.getProperty(MusicProperties.MUSIC_ENABLE);
+ private static final String FAILED_2_READ_PROPERTY_FILE = "Failed to read property file ";
+ private static final String TRUE = "true";
public static boolean isSessionMetaAttr(String key){
return sessionAttrNameSet.contains(key);
}
+ //hide public constructor
+ private MusicUtil()
+ {
+ }
+
@SuppressWarnings("unchecked")
public static <T> T musicRestResponseDataParsing(ResultSet rs, String attributeName) throws Exception{
logger.debug(EELFLoggerDelegate.debugLogger, "musicRestResponseDataParsing: start");
@@ -87,7 +94,7 @@ public class MusicUtil {
}
@SuppressWarnings("unchecked")
- public static <T> T musicDeserialize (ByteBuffer byteBuf) throws Exception{
+ public static <T> T musicDeserialize (ByteBuffer byteBuf) throws IOException, ClassNotFoundException {
logger.debug(EELFLoggerDelegate.debugLogger, "musicDeserialize: start");
ByteArrayInputStream byteArr = new ByteArrayInputStream(byteBuf.array());
ObjectInputStream ois = null;
@@ -100,7 +107,7 @@ public class MusicUtil {
return (T) ois.readObject();
}
- public static ByteBuffer musicSerialize (Object value) throws Exception{
+ public static ByteBuffer musicSerialize (Object value) {
logger.debug(EELFLoggerDelegate.debugLogger, "musicSerialize: start");
ByteArrayOutputStream bo = new ByteArrayOutputStream();
try {
@@ -121,7 +128,7 @@ public class MusicUtil {
return ByteBuffer.wrap(bo.toByteArray());
}
- public static MusicSession parseMetaData (Row row) throws Exception{
+ public static MusicSession parseMetaData (Row row) {
logger.debug(EELFLoggerDelegate.debugLogger, "parseMetaData: start");
if(row==null)
@@ -157,34 +164,34 @@ public class MusicUtil {
public static boolean isMusicSerializeCompress(){
if(musicSerializeCompress==null){
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + MusicProperties.MUSIC_SERIALIZE_COMPRESS +" fall back to eventual put");
+ logger.error(EELFLoggerDelegate.errorLogger, FAILED_2_READ_PROPERTY_FILE + MusicProperties.MUSIC_SERIALIZE_COMPRESS +" fall back to eventual put");
return false;
}
- return musicSerializeCompress.trim().equalsIgnoreCase("true");
+ return TRUE.equalsIgnoreCase(musicSerializeCompress.trim());
}
public static boolean isAtomicPut(){
if(atomicPut==null){
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + MusicProperties.MUSIC_ATOMIC_PUT +" fall back to eventual put");
+ logger.error(EELFLoggerDelegate.errorLogger, FAILED_2_READ_PROPERTY_FILE + MusicProperties.MUSIC_ATOMIC_PUT +" fall back to eventual put");
return false;
}
- return atomicPut.trim().equalsIgnoreCase("true");
+ return TRUE.equalsIgnoreCase(atomicPut.trim());
}
public static boolean isAtomicGet(){
if(atomicGet==null){
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + MusicProperties.MUSIC_ATOMIC_GET +" fall back to eventual get");
+ logger.error(EELFLoggerDelegate.errorLogger, FAILED_2_READ_PROPERTY_FILE + MusicProperties.MUSIC_ATOMIC_GET +" fall back to eventual get");
return false;
}
- return atomicGet.trim().equalsIgnoreCase("true");
+ return TRUE.equalsIgnoreCase(atomicGet.trim());
}
public static boolean isCached(){
if(cached==null){
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + MusicProperties.MUSIC_CACHE +" fall back to non cache");
+ logger.error(EELFLoggerDelegate.errorLogger, FAILED_2_READ_PROPERTY_FILE + MusicProperties.MUSIC_CACHE +" fall back to non cache");
return false;
}
- return cached.trim().equalsIgnoreCase("true");
+ return TRUE.equalsIgnoreCase(cached.trim());
}
public static int convertHoursToMillSec(int hour){
@@ -211,9 +218,7 @@ public class MusicUtil {
public static boolean isMusicEnable(){
if(musicEnable==null)
return false;
- if(musicEnable.equals("true"))
- return true;
- else
- return false;
+
+ return TRUE.equals(musicEnable);
}
}