summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service')
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AppService.java61
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AppServiceImpl.java106
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AuditService.java37
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AuditServiceImpl.java50
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/BroadcastService.java36
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/BroadcastServiceImpl.java250
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/DataAccessService.java80
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/DataAccessServiceImpl.java594
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ElementLinkService.java290
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ElementMapService.java1029
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/FnMenuService.java46
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/FnMenuServiceImpl.java161
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LdapService.java31
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LdapServiceImpl.java267
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java36
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java205
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostDroolsService.java34
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostDroolsServiceImpl.java186
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostSearchService.java37
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostSearchServiceImpl.java207
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java36
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java74
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java50
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java171
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceNonSpringImpl.java122
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileService.java34
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java116
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/WebServiceCallService.java26
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/WebServiceCallServiceImpl.java189
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/FusionService.java27
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/ServiceLocator.java27
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/ServiceLocatorImpl.java105
32 files changed, 4720 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AppService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AppService.java
new file mode 100644
index 00000000..55180fd7
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AppService.java
@@ -0,0 +1,61 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+
+import org.openecomp.portalsdk.core.domain.App;
+
+/**
+ * Defines methods to fetch App domain objects.
+ *
+ * Very thin interface; Portal defines a much richer interface.
+ */
+public interface AppService {
+
+ /**
+ * Gets all apps defined in the table.
+ *
+ * @return List of apps.
+ */
+ List<App> getApps();
+
+ /**
+ * Gets the app with the specified ID.
+ *
+ * @param appId
+ * @return App with the specified ID.
+ */
+ App getApp(Long appId);
+
+ /**
+ * Gets the singleton entry - applications should have exactly 1 row in the
+ * FN_APP table.
+ */
+ App getDefaultApp();
+
+ /**
+ * Fetches the application name once from database
+ * and keep refers to the same name later on as required.
+ * @return Default Application Name
+ */
+ String getDefaultAppName();
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AppServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AppServiceImpl.java
new file mode 100644
index 00000000..b06b36fc
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AppServiceImpl.java
@@ -0,0 +1,106 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+
+import org.openecomp.portalsdk.core.domain.App;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("appService")
+@Transactional
+public class AppServiceImpl implements AppService{
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppServiceImpl.class);
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ /**
+ * Loads the appName once from database and
+ * keep refers to it as required.
+ */
+ private static String defaultAppName = "";
+
+ /*
+ * (non-Javadoc)
+ * @see org.openecomp.portalsdk.core.service.AppService#getApps()
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<App> getApps() {
+ return getDataAccessService().getList(App.class, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.openecomp.portalsdk.service.AppService#getApp(long)
+ */
+ @Override
+ public App getApp(Long appId) {
+ return (App)getDataAccessService().getDomainObject(App.class, appId, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.openecomp.portalsdk.service.AppService#getApp()
+ */
+ @Override
+ public App getDefaultApp() {
+ return getApp(1L);
+ }
+
+ /**
+ * Gets the data access service.
+ * @return DataAccessService
+ */
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+ /**
+ * Sets the data access service.
+ * @param dataAccessService
+ */
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+ /**
+ * Fetches the application name once from database
+ * and keep refers to the same name later on as required.
+ * @return Default Application Name
+ */
+ @Override
+ public String getDefaultAppName() {
+ if (AppServiceImpl.defaultAppName==null || AppServiceImpl.defaultAppName=="") {
+ App app = getApp(1L);
+ if (app!=null) {
+ AppServiceImpl.defaultAppName = app.getName();
+ } else {
+ logger.warn(EELFLoggerDelegate.errorLogger, ("Unable to locate the app information from the database."));
+ }
+ }
+ return AppServiceImpl.defaultAppName;
+ }
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AuditService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AuditService.java
new file mode 100644
index 00000000..b228d1b1
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AuditService.java
@@ -0,0 +1,37 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.HashMap;
+
+import org.openecomp.portalsdk.core.domain.AuditLog;
+
+public interface AuditService {
+ /**
+ *
+ * Update log data in database
+ *
+ * @param auditLog
+ * @param additionalParams
+ */
+
+ @SuppressWarnings("rawtypes")
+ void logActivity(AuditLog auditLog, HashMap additionalParams);
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AuditServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AuditServiceImpl.java
new file mode 100644
index 00000000..433cd2ac
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AuditServiceImpl.java
@@ -0,0 +1,50 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.HashMap;
+
+import org.openecomp.portalsdk.core.domain.AuditLog;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("auditService")
+@Transactional
+public class AuditServiceImpl implements AuditService {
+ public AuditServiceImpl() {}
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @SuppressWarnings("rawtypes")
+ public void logActivity(AuditLog auditLog, HashMap additionalParams) {
+ getDataAccessService().saveDomainObject(auditLog, additionalParams);
+ }
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/BroadcastService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/BroadcastService.java
new file mode 100644
index 00000000..66315b92
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/BroadcastService.java
@@ -0,0 +1,36 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.openecomp.portalsdk.core.domain.BroadcastMessage;
+
+@SuppressWarnings("rawtypes")
+public interface BroadcastService {
+ HashMap getBcModel(HttpServletRequest request);
+ Hashtable getBroadcastMessages();
+ void loadMessages();
+ BroadcastMessage getBroadcastMessage(HttpServletRequest request);
+ void saveBroadcastMessage(BroadcastMessage broadcastMessage);
+ void removeBroadcastMessage(BroadcastMessage broadcastMessage);
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/BroadcastServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/BroadcastServiceImpl.java
new file mode 100644
index 00000000..92a77507
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/BroadcastServiceImpl.java
@@ -0,0 +1,250 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.openecomp.portalsdk.core.domain.BroadcastMessage;
+import org.openecomp.portalsdk.core.domain.Lookup;
+import org.openecomp.portalsdk.core.service.support.FusionService;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.openecomp.portalsdk.core.web.support.AppUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.ServletRequestBindingException;
+import org.springframework.web.bind.ServletRequestUtils;
+
+@SuppressWarnings("rawtypes")
+@Service("broadcastService")
+@Transactional
+public class BroadcastServiceImpl extends FusionService implements BroadcastService {
+
+ public BroadcastServiceImpl() {
+ }
+
+ @Autowired
+ private DataAccessService dataAccessService;
+ private static Hashtable broadcastMessages = new Hashtable();
+
+ @SuppressWarnings("unchecked")
+ public void loadMessages() {
+ List messageLocations = AppUtils.getLookupListNoCache("fn_lu_message_location", "message_location_id", "message_location_descr", "", "message_location_id");
+
+ for (int i=0; i < messageLocations.size(); i++) {
+ Lookup location = (Lookup)messageLocations.get(i);
+ String locationId = location.getValue();
+
+ broadcastMessages.put(locationId, getPersistedBroadcastMessages(locationId));
+ }
+ }
+
+ public HashMap getBcModel(HttpServletRequest request){
+ HashMap bcModel = new HashMap();
+
+ List items = null;
+ int messageId = ServletRequestUtils.getIntParameter(request, "message_id", 0);
+ String task = ServletRequestUtils.getStringParameter(request, "task", "get");
+
+ // delete or toggle activation on the selected record (if applicable)
+ if (messageId != 0 && (task.equals("delete") || task.equals("toggleActive"))) {
+ BroadcastMessage message = (BroadcastMessage)getDataAccessService().getDomainObject(BroadcastMessage.class, new Long(messageId), null);
+
+ if (task.equals("delete")) {
+ getDataAccessService().deleteDomainObject(message, null);
+ }
+ else if (task.equals("toggleActive")) {
+ HashMap additionalParams = new HashMap();
+ additionalParams.put(Parameters.PARAM_HTTP_REQUEST, request);
+
+ message.setActive(new Boolean(!message.getActive().booleanValue()));
+ getDataAccessService().saveDomainObject(message, additionalParams);
+ }
+ loadMessages();
+ }
+
+ items = getDataAccessService().getList(BroadcastMessage.class, null);
+ Collections.sort(items);
+ bcModel.put("messagesList", packageMessages(items));
+
+ List locations = AppUtils.getLookupList("fn_lu_message_location", "message_location_id", "message_location_descr", "", "message_location_id");
+ bcModel.put("messageLocations", locations);
+
+ if ("true".equals(SystemProperties.getProperty(SystemProperties.CLUSTERED))) {
+ List sites = AppUtils.getLookupList("fn_lu_broadcast_site", "broadcast_site_cd", "broadcast_site_descr", "", "broadcast_site_descr");
+ bcModel.put("broadcastSites", sites);
+ }
+
+ return bcModel;
+ }
+
+ @SuppressWarnings("unchecked")
+ private HashMap packageMessages(List messages) {
+ HashMap messagesList = new HashMap();
+ Set locationMessages = null;
+
+ Integer previousLocationId = null;
+
+ for (int i=0; i < messages.size(); i++) {
+ BroadcastMessage message = (BroadcastMessage)messages.get(i);
+
+ if (!message.getLocationId().equals(previousLocationId)) {
+ if (previousLocationId != null) {
+ messagesList.put(previousLocationId.toString(), locationMessages);
+ }
+
+ locationMessages = new TreeSet();
+ previousLocationId = message.getLocationId();
+ }
+
+ locationMessages.add(message);
+ }
+
+ if (previousLocationId != null) {
+ messagesList.put(previousLocationId.toString(), locationMessages);
+ }
+
+ return messagesList;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private List getPersistedBroadcastMessages(String locationId) {
+ HashMap params = new HashMap();
+
+
+
+ params.put("location_id", new Integer(locationId));
+
+ Calendar calInstanceToday = Calendar.getInstance();
+ calInstanceToday.set(Calendar.HOUR, 0);
+ calInstanceToday.set(Calendar.MINUTE, 0);
+ calInstanceToday.set(Calendar.SECOND, 0);
+ params.put("today_date", calInstanceToday.getTime());
+
+ return getDataAccessService().executeNamedQuery("broadcastMessages", params, null);
+ }
+
+ public Hashtable getBroadcastMessages() {
+ return broadcastMessages;
+ }
+
+ public static List getBroadcastMessages(String locationId) {
+ return (List)broadcastMessages.get(locationId);
+ }
+
+ public static String displayMessages(String locationId) {
+ return displayServerMessages(locationId, null);
+ }
+
+ public static String displayServerMessages(String locationId, String siteCd) {
+ StringBuffer html = new StringBuffer();
+
+ List messages = getBroadcastMessages(locationId);
+
+ for (int i=0; i < messages.size(); i++) {
+ BroadcastMessage message = (BroadcastMessage)messages.get(i);
+
+ if ((message.getSiteCd() == null) || ((message.getSiteCd() != null) && message.getSiteCd().equals(siteCd))) {
+ html.append("<li class=\"broadcastMessage\">")
+ .append(message.getMessageText());
+ }
+ }
+
+ if (html.length() > 0) {
+ html.insert(0, "<ul class=\"broadcastMessageList\">");
+ html.append("</ul>");
+ }
+
+ return html.toString();
+ }
+
+ public static boolean hasMessages(String locationId) {
+ return hasServerMessages(locationId, null);
+ }
+
+ public static boolean hasServerMessages(String locationId, String siteCd) {
+ List messages = getBroadcastMessages(locationId);
+
+ boolean messagesExist = !((messages == null) || messages.size() == 0);
+
+ if (siteCd == null) {
+ return messagesExist;
+ }
+ else {
+ for (int i=0; i < messages.size(); i++) {
+ BroadcastMessage message = (BroadcastMessage)messages.get(i);
+
+ if ((message.getSiteCd() == null) || message.getSiteCd().equals(siteCd)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ dataAccessService = dataAccessService;
+ }
+
+ public BroadcastMessage getBroadcastMessage(HttpServletRequest request) {
+ long messageId = ServletRequestUtils.getLongParameter(request, "message_id", 0);
+
+ BroadcastMessage message = new BroadcastMessage();
+ if(messageId!=0)
+ message = (BroadcastMessage)getDataAccessService().getDomainObject(BroadcastMessage.class, new Long(messageId), null);
+
+ if (message.getLocationId() == null) {
+ try {
+ message.setLocationId(new Integer(ServletRequestUtils.getStringParameter(request, "message_location_id")));
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ } catch (ServletRequestBindingException e) {
+ e.printStackTrace();
+ }
+ message.setActive(Boolean.TRUE);
+ }
+
+ return message;
+ }
+
+ @Override
+ public void saveBroadcastMessage(BroadcastMessage broadcastMessage) {
+ dataAccessService.saveDomainObject(broadcastMessage, null);
+ }
+
+ @Override
+ public void removeBroadcastMessage(BroadcastMessage broadcastMessage) {
+ dataAccessService.deleteDomainObject(broadcastMessage, null);
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/DataAccessService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/DataAccessService.java
new file mode 100644
index 00000000..26892b88
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/DataAccessService.java
@@ -0,0 +1,80 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.FetchMode;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.ProjectionList;
+import org.openecomp.portalsdk.core.domain.support.DomainVo;
+
+@SuppressWarnings("rawtypes")
+public interface DataAccessService {
+
+ // generic view, save, delete methods
+ DomainVo getDomainObject(Class domainClass, Serializable id, HashMap additionalParams);
+ void deleteDomainObject(DomainVo domainObject, HashMap additionalParams);
+ void deleteDomainObjects(Class domainClass, String whereClause, HashMap additionalParams);
+ void saveDomainObject(DomainVo domainObject, HashMap additionalParams);
+
+ // generic get list method(s)
+ List getList(Class domainClass, HashMap additionalParams);
+ List getList(Class domainClass, String filter, String orderBy, HashMap additionalParams);
+ List getList(Class domainClass, String filter, int fromIndex, int toIndex, String orderBy, HashMap additionalParams);
+ List<?> getList(Class<?> domainClass, ProjectionList projectionsList , List<Criterion> restrictionsList , List<Order> orderByList);
+ public List<?> getList(Class<?> domainClass, ProjectionList projectionsList, List<Criterion> restrictionsList, List<Order> orderByList,HashMap<String,FetchMode> fetchModeMap);
+
+ List getLookupList(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy, HashMap additionalParams);
+
+ // generic native-SQL execution methods
+ List executeSQLQuery(String sql, Class domainClass, HashMap additionalParams);
+ List executeSQLQuery(String sql, Class domainClass, Integer fromIndex, Integer toIndex,HashMap additionalParams);
+
+ // generic HQL execution methods
+ List executeQuery(String hql, HashMap additionalParams);
+ List executeQuery(String hql, Integer fromIndex, Integer toIndex, HashMap additionalParams);
+
+ // generic named query execution methods
+ List executeNamedQuery(String queryName, Integer fromIndex, Integer toIndex, HashMap additionalParams);
+ List executeNamedQuery(String queryName, Map params, HashMap additionalParams);
+ List executeNamedQuery(String queryName, Map params, Integer fromIndex, Integer toIndex, HashMap additionalParams);
+
+ //with Where Clause for RAPTOR ZK
+ List executeNamedQueryWithOrderBy(Class entity, String queryName, Map params, String _orderBy, boolean asc, Integer fromIndex, Integer toIndex, HashMap additionalParams);
+ List executeNamedCountQuery(Class entity, String queryName, String whereClause, Map params);
+ List executeNamedQuery(Class entity, String queryName, String whereClause, Map params, Integer fromIndex, Integer toIndex, HashMap additionalParams);
+ List executeNamedQueryWithOrderBy(Class entity, String queryName, String whereClause, Map params, String _orderBy, boolean asc, Integer fromIndex, Integer toIndex, HashMap additionalParams);
+
+ // generic update query execution method
+ int executeUpdateQuery(String sql, HashMap additionalParams) throws RuntimeException;
+
+ // generic named update query execution method
+ int executeNamedUpdateQuery(String queryName, Map params, HashMap additionalParams) throws RuntimeException;
+
+ // synchronizes the local updates with the database (and vice versa)
+ void synchronize(HashMap additionalParams);
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/DataAccessServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/DataAccessServiceImpl.java
new file mode 100644
index 00000000..9c52b1b4
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/DataAccessServiceImpl.java
@@ -0,0 +1,594 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Criteria;
+import org.hibernate.FetchMode;
+import org.hibernate.Query;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.ProjectionList;
+import org.openecomp.portalsdk.core.domain.Lookup;
+import org.openecomp.portalsdk.core.domain.support.DomainVo;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.service.support.FusionService;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Provides implementations of methods in {@link DataAccessService}.
+ */
+@Transactional
+public class DataAccessServiceImpl extends FusionService implements DataAccessService {
+
+ @Autowired
+ private SessionFactory sessionFactory;
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DataAccessServiceImpl.class);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#getDomainObject(java.lang.
+ * Class, java.io.Serializable, java.util.HashMap)
+ */
+ @Override
+ public DomainVo getDomainObject(Class domainClass, Serializable id, HashMap additionalParams) {
+ DomainVo vo = null;
+ Session session = sessionFactory.getCurrentSession();
+ logger.info(EELFLoggerDelegate.debugLogger, "Getting " + domainClass.getName() + " record for id - " + id.toString());
+ vo = (DomainVo) session.get(domainClass, id);
+
+ if (vo == null) {
+ try {
+ vo = (DomainVo) domainClass.newInstance();
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "An error occured while instantiating a class of " + domainClass.getName() + e.getMessage());
+ }
+ }
+ return vo;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ */
+ @Override
+ public void deleteDomainObject(DomainVo domainObject, HashMap additionalParams) {
+ Session session = sessionFactory.getCurrentSession();
+ session.delete(domainObject);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#deleteDomainObjects(java.
+ * lang.Class, java.lang.String, java.util.HashMap)
+ */
+ @Override
+ public void deleteDomainObjects(Class domainClass, String whereClause, HashMap additionalParams) {
+ int rowsAffected = 0;
+ Session session = sessionFactory.getCurrentSession();
+
+ StringBuffer sql = new StringBuffer("delete from ");
+
+ sql.append(domainClass.getName()).append(" where ").append(whereClause);
+
+ rowsAffected = session.createQuery(sql.toString()).executeUpdate();
+ /* return rowsAffected; */
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#saveDomainObject
+ */
+ @Override
+ public void saveDomainObject(DomainVo vo, HashMap additionalParams) {
+ Integer userId = 1;
+ if (additionalParams != null) {
+ // look for a passed user id
+ // userId = (Integer)additionalParams.get(Parameters.PARAM_USERID);
+ Object uid = additionalParams.get(Parameters.PARAM_USERID);
+ if (uid instanceof Integer) {
+ userId = (Integer) uid;
+ } else if (uid instanceof Long) {
+ userId = ((Long) uid).intValue();
+ }
+ // if (userId == null) {
+ // look for a passed request to get the user id from
+ // userId = new
+ // Integer(UserUtils.getUserId((HttpServletRequest)additionalParams.get(Parameters.PARAM_HTTP_REQUEST)));
+ // }
+ }
+ _update(vo, userId);
+ }
+
+ /**
+ * Creates or updates the specified virtual object. Uses the specified user
+ * ID as the creator and modifier if a new object is created; uses ID only
+ * as modifier if an object already exists.
+ *
+ * @param vo
+ * @param userId
+ * Ignored if value is zero.
+ */
+ protected final void _update(DomainVo vo, int userId) {
+ Date timestamp = new Date();
+
+ Session session = sessionFactory.getCurrentSession();
+
+ if (vo.getId() == null || vo.getId().intValue() == 0) { // add new
+ vo.setCreated(timestamp);
+ vo.setModified(timestamp);
+
+ if (userId != 0
+ && userId != Integer.parseInt(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID))) {
+ vo.setCreatedId(new Long(userId));
+ vo.setModifiedId(new Long(userId));
+ }
+ } else { // update existing
+ vo.setModified(timestamp);
+
+ if (userId != 0
+ && userId != Integer.parseInt(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID))) {
+ vo.setModifiedId(new Long(userId));
+ }
+ }
+
+ session.saveOrUpdate(vo);
+ }
+
+ /**
+ * generic get list method
+ *
+ * @param domainClass
+ * @param filterClause
+ * @param fromIndex
+ * @param toIndex
+ * @param orderBy
+ * @return
+ */
+ private List getListCommon(Class domainClass, String filterClause, Integer fromIndex, Integer toIndex,
+ String orderBy) {
+ List list = null;
+ String className = domainClass.getName();
+ Session session = sessionFactory.getCurrentSession();
+
+ if (logger.isInfoEnabled()) {
+ logger.info(EELFLoggerDelegate.debugLogger, "Getting " + className.toLowerCase() + " records"
+ + ((fromIndex != null) ? " from rows " + fromIndex.toString() + " to " + toIndex.toString() : "")
+ + "...");
+ if (filterClause != null && filterClause.length() > 0)
+ logger.info(EELFLoggerDelegate.debugLogger, "Filtering " + className + " by: " + filterClause);
+ }
+
+ list = session.createQuery("from " + className + Utilities.nvl(filterClause, "")
+ + ((orderBy != null) ? " order by " + orderBy : "")).list();
+ list = (fromIndex != null) ? list.subList(fromIndex.intValue() - 1, toIndex.intValue()) : list;
+
+ if (orderBy == null && list != null)
+ Collections.sort(list);
+
+ return list;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#getList(java.lang.Class,
+ * java.util.HashMap)
+ */
+ @Override
+ public List getList(Class domainClass, HashMap additionalParams) {
+ return getListCommon(domainClass, null, null, null, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#getList(java.lang.Class,
+ * java.lang.String, java.lang.String, java.util.HashMap)
+ */
+ @Override
+ public List getList(Class domainClass, String filter, String orderBy, HashMap additionalParams) {
+ return getListCommon(domainClass, filter, null, null, orderBy);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#getList(java.lang.Class,
+ * java.lang.String, int, int, java.lang.String, java.util.HashMap)
+ */
+ @Override
+ public List getList(Class domainClass, String filter, int fromIndex, int toIndex, String orderBy,
+ HashMap additionalParams) {
+ return getListCommon(domainClass, filter, new Integer(fromIndex), new Integer(toIndex), orderBy);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#getList(java.lang.Class,
+ * org.hibernate.criterion.ProjectionList, java.util.List, java.util.List)
+ */
+ @Override
+ public List<?> getList(Class<?> domainClass, ProjectionList projectionsList, List<Criterion> restrictionsList,
+ List<Order> orderByList) {
+
+ Session session = sessionFactory.getCurrentSession();
+
+ Criteria criteria = session.createCriteria(domainClass);
+
+ if (projectionsList != null) {
+ criteria.setProjection(projectionsList);
+ }
+
+ if (restrictionsList != null && !restrictionsList.isEmpty()) {
+ for (Criterion criterion : restrictionsList)
+ criteria.add(criterion);
+ }
+
+ if (orderByList != null && !orderByList.isEmpty()) {
+ for (Order order : orderByList)
+ criteria.addOrder(order);
+ }
+ /*
+ * if(fetchModeMap!=null){ Iterator<String> itr =
+ * fetchModeMap.keySet().iterator(); String key=null;
+ * while(itr.hasNext()){ key = itr.next();
+ * criteria.setFetchMode(key,fetchModeMap.get(key)); } }
+ */
+ return criteria.list();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#getLookupList(java.lang.
+ * String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String, java.util.HashMap)
+ */
+ @Override
+ public List getLookupList(String dbTable, String dbValueCol, String dbLabelCol, String dbFilter, String dbOrderBy,
+ HashMap additionalParams) {
+ if (logger.isInfoEnabled())
+ logger.info(EELFLoggerDelegate.debugLogger, "Retrieving " + dbTable + " lookup list...");
+ String dbOrderByCol = dbOrderBy;
+
+ Session session = sessionFactory.getCurrentSession();
+
+ // default the orderBy if null;
+ if (Utilities.nvl(dbOrderBy).length() == 0) {
+ dbOrderByCol = dbLabelCol;
+ dbOrderBy = dbLabelCol;
+ } else {
+ if (dbOrderBy.lastIndexOf(" ") > -1) {
+ dbOrderByCol = dbOrderBy.substring(0, dbOrderBy.lastIndexOf(" "));
+ }
+ }
+
+ StringBuffer sql = new StringBuffer();
+
+ sql.append("select distinct ").append(dbLabelCol).append(" as lab, ").append(dbValueCol).append(" as val, ")
+ .append(dbOrderByCol).append(" as sortOrder ").append("from ").append(dbTable).append(" ")
+ .append((Utilities.nvl(dbFilter).length() == 0) ? "" : (" where " + dbFilter)).append(" order by ")
+ .append(dbOrderBy);
+
+ List list = null;
+ try {
+ list = session.createSQLQuery(sql.toString()).addEntity(Lookup.class).list();
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.debugLogger, "Failed to create SQL lookup query for [" + sql + "]" + e.getMessage());
+ }
+ return list;
+ }
+
+ /*
+ * methods accepting a Map of additional params to passed to the DAO (for
+ * extensibility, just in case)
+ */
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeSQLQuery(java.lang.
+ * String, java.lang.Class, java.util.HashMap)
+ */
+ @Override
+ public List executeSQLQuery(String sql, Class domainClass, HashMap additionalParams) {
+ return executeSQLQuery(sql, domainClass, null, null, additionalParams);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeSQLQuery(java.lang.
+ * String, java.lang.Class, java.lang.Integer, java.lang.Integer,
+ * java.util.HashMap)
+ */
+ @Override
+ public List executeSQLQuery(String sql, Class domainClass, Integer fromIndex, Integer toIndex,
+ HashMap additionalParams) {
+ Session session = sessionFactory.getCurrentSession();
+
+ SQLQuery query = session.createSQLQuery(sql).addEntity(domainClass.getName().toLowerCase(), domainClass);
+
+ if (fromIndex != null && toIndex != null) {
+ query.setFirstResult(fromIndex.intValue());
+ int pageSize = (toIndex.intValue() - fromIndex.intValue()) + 1;
+ query.setMaxResults(pageSize);
+ }
+
+ return query.list();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeQuery(java.lang.
+ * String, java.util.HashMap)
+ */
+ @Override
+ public List executeQuery(String sql, HashMap additionalParams) {
+ return executeQuery(sql, null, null, additionalParams);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeQuery(java.lang.
+ * String, java.lang.Integer, java.lang.Integer, java.util.HashMap)
+ */
+ @Override
+ public List executeQuery(String sql, Integer fromIndex, Integer toIndex, HashMap additionalParams) {
+ Session session = sessionFactory.getCurrentSession();
+
+ Query query = session.createQuery(sql);
+
+ if (fromIndex != null && toIndex != null) {
+ query.setFirstResult(fromIndex.intValue());
+ int pageSize = (toIndex.intValue() - fromIndex.intValue()) + 1;
+ query.setMaxResults(pageSize);
+ }
+
+ return query.list();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeNamedQuery(java.lang
+ * .String, java.lang.Integer, java.lang.Integer, java.util.HashMap)
+ */
+ @Override
+ public List executeNamedQuery(String queryName, Integer fromIndex, Integer toIndex, HashMap additionalParams) {
+ return executeNamedQuery(queryName, null, fromIndex, toIndex, additionalParams);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeNamedQuery(java.lang
+ * .String, java.util.Map, java.util.HashMap)
+ */
+ @Override
+ public List executeNamedQuery(String queryName, Map params, HashMap additionalParams) {
+ return executeNamedQuery(queryName, params, null, null, additionalParams);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeNamedQuery(java.lang
+ * .String, java.util.Map, java.lang.Integer, java.lang.Integer,
+ * java.util.HashMap)
+ */
+ @Override
+ public List executeNamedQuery(String queryName, Map params, Integer fromIndex, Integer toIndex,
+ HashMap additionalParams) {
+ Session session = sessionFactory.getCurrentSession();
+ Query query = session.getNamedQuery(queryName);
+ bindQueryParameters(query, params);
+ if (fromIndex != null && toIndex != null) {
+ query.setFirstResult(fromIndex.intValue());
+ int pageSize = (toIndex.intValue() - fromIndex.intValue()) + 1;
+ query.setMaxResults(pageSize);
+ }
+ return query.list();
+ }
+
+ /**
+ * Stores parameters into the query using String keys from the map. Gives
+ * special treatment to map values of Collection and array type.
+ *
+ * @param query
+ * Query with parameters
+ * @param params
+ * Map of String to Object.
+ */
+ private void bindQueryParameters(Query query, Map params) {
+ if (params != null) {
+ for (Iterator i = params.entrySet().iterator(); i.hasNext();) {
+ Map.Entry entry = (Map.Entry) i.next();
+
+ Object parameterValue = entry.getValue();
+
+ if (!(parameterValue instanceof Collection) && !(parameterValue instanceof Object[])) {
+ query.setParameter((String) entry.getKey(), parameterValue);
+ } else if (parameterValue instanceof Collection) {
+ query.setParameterList((String) entry.getKey(), (Collection) parameterValue);
+ } else if (parameterValue instanceof Object[]) {
+ query.setParameterList((String) entry.getKey(), (Object[]) parameterValue);
+ }
+ }
+ }
+ }
+
+ // With Where Clause & RAPTOR's ZK
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.portalsdk.core.service.DataAccessService#
+ * executeNamedQueryWithOrderBy(java.lang.Class, java.lang.String,
+ * java.util.Map, java.lang.String, boolean, java.lang.Integer,
+ * java.lang.Integer, java.util.HashMap)
+ */
+ @Override
+ public List executeNamedQueryWithOrderBy(Class entity, String queryName, Map params, String _orderBy, boolean asc,
+ Integer fromIndex, Integer toIndex, HashMap additionalParams) {
+ // TODO Auto-generated method stub
+ logger.info(EELFLoggerDelegate.debugLogger, "Not implemented");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeNamedCountQuery(java
+ * .lang.Class, java.lang.String, java.lang.String, java.util.Map)
+ */
+ @Override
+ public List executeNamedCountQuery(Class entity, String queryName, String whereClause, Map params) {
+ // TODO Auto-generated method stub
+ logger.info(EELFLoggerDelegate.debugLogger, "Not implemented");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeNamedQuery(java.lang
+ * .Class, java.lang.String, java.lang.String, java.util.Map,
+ * java.lang.Integer, java.lang.Integer, java.util.HashMap)
+ */
+ @Override
+ public List executeNamedQuery(Class entity, String queryName, String whereClause, Map params, Integer fromIndex,
+ Integer toIndex, HashMap additionalParams) {
+ // TODO Auto-generated method stub
+ logger.info(EELFLoggerDelegate.debugLogger, "Not implemented");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.portalsdk.core.service.DataAccessService#
+ * executeNamedQueryWithOrderBy(java.lang.Class, java.lang.String,
+ * java.lang.String, java.util.Map, java.lang.String, boolean,
+ * java.lang.Integer, java.lang.Integer, java.util.HashMap)
+ */
+ @Override
+ public List executeNamedQueryWithOrderBy(Class entity, String queryName, String whereClause, Map params,
+ String _orderBy, boolean asc, Integer fromIndex, Integer toIndex, HashMap additionalParams) {
+ // TODO Auto-generated method stub
+ logger.info(EELFLoggerDelegate.debugLogger, "Not implemented");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#getList(java.lang.Class,
+ * org.hibernate.criterion.ProjectionList, java.util.List, java.util.List,
+ * java.util.HashMap)
+ */
+ @Override
+ public List<?> getList(Class<?> domainClass, ProjectionList projectionsList, List<Criterion> restrictionsList,
+ List<Order> orderByList, HashMap<String, FetchMode> fetchModeMap) {
+ // TODO Auto-generated method stub
+ logger.info(EELFLoggerDelegate.debugLogger, "Not implemented");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeUpdateQuery(java.
+ * lang.String, java.util.HashMap)
+ */
+ @Override
+ public int executeUpdateQuery(String sql, HashMap additionalParams) throws RuntimeException {
+ // TODO Auto-generated method stub
+ logger.info(EELFLoggerDelegate.debugLogger, "Not implemented");
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.openecomp.portalsdk.core.service.DataAccessService#executeNamedUpdateQuery(
+ * java.lang.String, java.util.Map, java.util.HashMap)
+ */
+ @Override
+ public int executeNamedUpdateQuery(String queryName, Map params, HashMap additionalParams) throws RuntimeException {
+ // TODO Auto-generated method stub
+ logger.info(EELFLoggerDelegate.debugLogger, "Not implemented");
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.portalsdk.core.service.DataAccessService#synchronize(java.util.
+ * HashMap)
+ */
+ @Override
+ public void synchronize(HashMap additionalParams) {
+ // TODO Auto-generated method stub
+ logger.info(EELFLoggerDelegate.debugLogger, "Not implemented");
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ElementLinkService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ElementLinkService.java
new file mode 100644
index 00000000..0cd90dc7
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ElementLinkService.java
@@ -0,0 +1,290 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.openecomp.portalsdk.core.util.YamlUtils;
+
+public class ElementLinkService {
+
+ /**
+ * Builds renderable model of element links in the network map. Parses YAML
+ * files with metadata and builds input for JoinJS to render in the browser
+ * as SVG.
+ *
+ * @param args
+ * arg 0 - realPath; arg 1 - callFlowName; arg 2 - callFlowStep.
+ * @return Renderable model of element links
+ * @throws Exception
+ */
+ public String buildElementLinkYaml(String[] args) throws Exception {
+ String relFilePath;
+ if (args[1].startsWith("custom"))
+ relFilePath = SystemProperties.getProperty("customCallFlow_path");
+ else
+ relFilePath = SystemProperties.getProperty("element_map_file_path");
+ final String yamlDirPath = new File(args[0], relFilePath).getPath();
+
+ String callFlowBusinessYml = "";
+ String callFlowStep = "";
+
+ if (args != null && args.length > 0) {
+ if (args[1] != null)
+ callFlowBusinessYml = args[1] + ".yml";
+ if (args[2] != null)
+ callFlowStep = args[2];
+ }
+
+ ElementLinkService mapper = new ElementLinkService();
+ String linkYaml = mapper.createLinkFile(yamlDirPath, callFlowBusinessYml, callFlowStep);
+ return linkYaml;
+ }
+
+ /*
+ * public String main2(String[] args) throws Exception {
+ *
+ * String filePath = SystemProperties.getProperty("element_map_file_path") +
+ * File.separator; String callFlowBusinessYml = ""; String callFlowStep =
+ * "";
+ *
+ * if (args != null && args.length > 0) {
+ *
+ * if (args[0] != null) { callFlowBusinessYml = args[0] + "-Override.yml"; }
+ *
+ * if (args[1] != null) { callFlowStep = args[1]; } }
+ *
+ * ElementLinkService mapper = new ElementLinkService();
+ *
+ * return mapper.createLinkFileAdditional(filePath, callFlowBusinessYml,
+ * callFlowStep); }
+ */
+
+ public static void main(String[] args) throws Exception {
+
+ String filePath = "\\D2Platform\\war\\WEB-INF\\resources\\trisim_files";
+ String callFlowBusinessYml = "call_flow_hc-origination-termination-to-volteue-3.3.16-Override.yml";
+
+ ElementLinkService mapper = new ElementLinkService();
+
+ // System.out.print(mapper.createLinkFile(filePath, networkToscaYml,
+ // networkToscaUeYml, networkLayoutYml, callFlowBusinessYml,"Step_1"));
+ System.out.print(mapper.createLinkFileAdditional(filePath, callFlowBusinessYml, "Step_2"));
+ }
+
+ @SuppressWarnings("unchecked")
+ protected String createLinkFile(String resourceFilePath, String callFLowBsFileName, String callFlowStep)
+ throws Exception {
+
+ Map<String, Object> callFlowBs = YamlUtils.readYamlFile(resourceFilePath, callFLowBsFileName);
+
+ List<Map<String, Object>> callSteps = (List<Map<String, Object>>) callFlowBs.get("callSequenceSteps");
+ String callFlowName = (String) callFlowBs.get("shortName");
+ return addLinks(resourceFilePath, callFlowName, callSteps, callFlowStep);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ protected String createLinkFileAdditional(String resourceFilePath, String callFLowBsFileName, String callFlowStep)
+ throws Exception {
+
+ // Map<String, Object> callFlowBs =
+ // YamlUtils.readYamlFile(resourceFilePath, callFLowBsFileName);
+
+ // return YamlUtils.returnYaml(callFlowBs);
+
+ Map<String, Object> callFlowBs;
+
+ try {
+ callFlowBs = YamlUtils.readYamlFile(resourceFilePath, callFLowBsFileName);
+
+ List<Map<String, Object>> callSteps = (List<Map<String, Object>>) callFlowBs.get("callSequenceSteps");
+ String callFlowName = (String) callFlowBs.get("shortName");
+ return addLinksAdditional(resourceFilePath, callFlowName, callSteps, callFlowStep);
+
+ } catch (Exception e) {
+
+ return "";
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ protected String addLinks(String filePath, String callFlowName, List<Map<String, Object>> callSteps,
+ String callFlowStep) throws IOException {
+
+ Map<String, List<String>> checkDuplicateMap = new HashMap<String, List<String>>();
+
+ for (Map<String, Object> callStep : callSteps) {
+
+ if (((String) callStep.get("name")).split(":")[0].trim().replace(" ", "_").equals(callFlowStep)) {
+
+ // String callFlowStepName = callFlowName + "_" +
+ // ((String)callStep.get("name")).split("-")[0].trim().replace("
+ // ", "_")+".yml";
+
+ List<Map<String, Object>> links = new ArrayList<Map<String, Object>>();
+
+ List<Map<String, Object>> subSteps = (List<Map<String, Object>>) callStep.get("subSteps");
+
+ for (Map<String, Object> subStep : subSteps) {
+ Map<String, Object> link = new HashMap<String, Object>();
+
+ String source = (String) subStep.get("source_tosca_id");
+ String destination = (String) subStep.get("destination_tosca_id");
+
+ if ((checkDuplicateMap.get(source) == null || checkDuplicateMap.get(source).isEmpty()
+ || !checkDuplicateMap.get(source).contains(destination)) && !source.equals(destination)) {
+ if (checkDuplicateMap.get(destination) == null) {
+ List<String> toscaList = new ArrayList<String>();
+ checkDuplicateMap.put(destination, toscaList);
+ }
+
+ if (checkDuplicateMap.get(source) == null) {
+ List<String> toscaList = new ArrayList<String>();
+ checkDuplicateMap.put(source, toscaList);
+ }
+
+ List<String> toscaSourceList = checkDuplicateMap.get(destination);
+ toscaSourceList.add(source);
+
+ List<String> toscaDestinationList = checkDuplicateMap.get(source);
+ toscaDestinationList.add(destination);
+
+ link.put("s", source);
+ link.put("d", destination);
+ links.add(link);
+
+ /*
+ * may be needed in future but nnot currently
+ *
+ * if((String) subStep.get("link_visibility")!=null){
+ * if(((String)
+ * subStep.get("link_visibility")).equals("No")){
+ *
+ * } }else{
+ *
+ * links.add(link); }
+ */
+
+ }
+
+ }
+
+ Map<String, Object> callFlowUI = new HashMap<String, Object>();
+ callFlowUI.put("linkList", links);
+
+ return YamlUtils.returnYaml(callFlowUI);
+
+ // YamlUtils.writeYamlFile(filePath, callFlowStepName,
+ // callFlowUI);
+ }
+
+ }
+ return "";
+ }
+
+ protected String addLinksAdditional(String filePath, String callFlowName, List<Map<String, Object>> callSteps,
+ String callFlowStep) throws IOException {
+
+ for (Map<String, Object> callStep : callSteps) {
+
+ if (((String) callStep.get("name")).split(":")[0].trim().replace(" ", "_").equals(callFlowStep)) {
+
+ // String callFlowStepName = callFlowName + "_" +
+ // ((String)callStep.get("name")).split("-")[0].trim().replace("
+ // ", "_")+".yml";
+
+ Map<String, Object> callFlowUI = new HashMap<String, Object>();
+ try {
+ List<Map<String, Object>> links = addLinkVertices(callStep);
+ callFlowUI.put("linkList", links);
+ } catch (Exception e) {
+ }
+ try {
+ List<String> activeIds = addActiveNodes(callStep);
+ callFlowUI.put("activeIds", activeIds);
+ } catch (Exception e) {
+ }
+ try {
+ List<Map<String, Object>> disconnectLinks = addDisconnectLinks(callStep);
+ callFlowUI.put("disconnectLinks", disconnectLinks);
+ } catch (Exception e) {
+ }
+
+ return YamlUtils.returnYaml(callFlowUI);
+ }
+ }
+
+ return "";
+ }
+
+ @SuppressWarnings("unchecked")
+ List<String> addActiveNodes(Map<String, Object> callStep) {
+ List<String> activeIds = (List<String>) callStep.get("activeIds");
+ return activeIds;
+ }
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> addDisconnectLinks(Map<String, Object> callStep) {
+ List<Map<String, Object>> disconnectLinks = (List<Map<String, Object>>) callStep.get("disconnectLinks");
+ return disconnectLinks;
+ }
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> addLinkVertices(Map<String, Object> callStep) {
+ List<Map<String, Object>> links = new ArrayList<Map<String, Object>>();
+
+ List<Map<String, Object>> vertices = (List<Map<String, Object>>) callStep.get("vertices");
+
+ for (int i = 0; i < vertices.size() - 1; i++) {
+ Map<String, Object> vertex = (Map<String, Object>) vertices.get(i);
+ Map<String, Object> vertexNext = (Map<String, Object>) vertices.get(i + 1);
+
+ Integer sourceX = (Integer) vertex.get("x");
+ Integer sourceY = (Integer) vertex.get("y");
+ String sourceD = (String) vertex.get("D");
+ String sourceL = (vertex.get("L") != null) ? (String) vertex.get("L") : "-";
+
+ if (sourceX == -999) // there is a break in the linkage
+ continue;
+
+ Integer destinationX = (Integer) vertexNext.get("x");
+ Integer destinationY = (Integer) vertexNext.get("y");
+ String destinationD = (String) vertexNext.get("D");
+
+ if (destinationX == -999) // there is a break in the linkage
+ continue;
+
+ Map<String, Object> link = new HashMap<String, Object>();
+
+ link.put("s", sourceX + "," + sourceY + "," + sourceD + "," + sourceL);
+ link.put("d", destinationX + "," + destinationY + "," + destinationD);
+ links.add(link);
+ }
+ return links;
+ }
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ElementMapService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ElementMapService.java
new file mode 100644
index 00000000..8213a5ba
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ElementMapService.java
@@ -0,0 +1,1029 @@
+/*-
+ * ================================================================================
+ * ECOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.commons.lang.StringUtils;
+import org.openecomp.portalsdk.core.domain.support.Container;
+import org.openecomp.portalsdk.core.domain.support.Domain;
+import org.openecomp.portalsdk.core.domain.support.Element;
+import org.openecomp.portalsdk.core.domain.support.ElementDetails;
+import org.openecomp.portalsdk.core.domain.support.Layout;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.openecomp.portalsdk.core.util.YamlUtils;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.nodes.Tag;
+import org.yaml.snakeyaml.representer.Representer;
+
+public class ElementMapService {
+
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ElementMapService.class);
+
+ /**
+ *
+ * @param contextRealPath
+ * @param layout
+ * @return
+ * @throws Exception
+ */
+ private String convertToYAML(String contextRealPath, Layout layout) throws Exception {
+
+ // Used to build image file relative URLs
+ final String iconRelPath = SystemProperties.getProperty("element_map_icon_path"); // "static/img/map/icons/";
+
+ Map<String, Domain> resultAICDomain = layout.domainRowCol;
+ Map<String, List<Domain>> domainMap = new HashMap<String, List<Domain>>();
+ List<Domain> domainList = new ArrayList<Domain>();
+ for (Domain d : resultAICDomain.values()) {
+ d.setWidth(10 * d.computeSize().getWidth());
+ d.setHeight(10 * d.computeSize().getHeight());
+ d.setLeft(10 * d.getP().getX());
+ d.setTop(10 * d.getP().getY());
+
+ List<Container> containerList = new ArrayList<Container>();
+ for (Container c : d.getContainerRowCol().values()) {
+ c.setWidth(10 * c.computeSize().getWidth());
+ c.setHeight(10 * c.computeSize().getHeight());
+ c.setLeft(10 * c.getP().getX());
+ c.setTop(10 * c.getP().getY());
+ Element ue = (Element) c.getElementRowCol().values().toArray()[0];
+ if (ue.getName().equals("ue1") || ue.getName().equals("ue2") || ue.getName().equals("ue3")
+ || ue.getName().equals("ue4") || ue.getName().equals("ue5") || ue.getName().equals("ue6")) {
+ c.setVisibilityType("invisible");
+ }
+
+ if (c.getContainerRowCol() != null) {
+ List<Container> innerContainerList = new ArrayList<Container>();
+ for (Container innerC : c.getContainerRowCol().values()) {
+ innerC.setName(innerC.getName());
+ innerC.setWidth(10 * innerC.computeSize().getWidth());
+ innerC.setHeight(10 * innerC.computeSize().getHeight());
+ innerC.setLeft(10 * innerC.getP().getX());
+ innerC.setTop(10 * innerC.getP().getY());
+
+ if (innerC.getElementRowCol() != null) {
+ List<Element> innerContainerEList = new ArrayList<Element>();
+ for (Element ele : innerC.getElementRowCol().values()) {
+ // ele.setName(ele.getName());
+ ele.setWidth(10 * ele.computeSize().getWidth());
+ ele.setHeight(10 * ele.computeSize().getHeight());
+ ele.setLeft(10 * ele.getP().getX());
+ ele.setTop(10 * ele.getP().getY() - 10);
+ ele.setImgFileName(iconRelPath + "/" + ele.getImgFileName());
+ if (ele.getBorderType().equals("V"))
+ ele.setBorderType("dashed");
+ else
+ ele.setBorderType("solid");
+ innerContainerEList.add(ele);
+ }
+ innerC.setElementList(innerContainerEList);
+ }
+ innerContainerList.add(innerC);
+ }
+ c.setInnerCList(innerContainerList);
+ }
+
+ if (c.getElementRowCol() != null) {
+ List<Element> elementList = new ArrayList<Element>();
+ for (Element e : c.getElementRowCol().values()) {
+ // e.setName(e.getName());
+ e.setWidth(10 * e.computeSize().getWidth());
+ e.setHeight(10 * e.computeSize().getHeight());
+ e.setLeft(10 * e.getP().getX());
+ e.setTop(10 * e.getP().getY() - 10);
+ e.setImgFileName(iconRelPath + "/" + e.getImgFileName());
+
+ if (e.getBorderType().equals("V"))
+ e.setBorderType("dashed");
+ else
+ e.setBorderType("solid");
+
+ if (e.getName().equals("ue1") || e.getName().equals("ue2") || e.getName().equals("ue3")
+ || e.getName().equals("ue4") || e.getName().equals("ue5") || e.getName().equals("ue6"))
+ e.setBgColor("white");
+ elementList.add(e);
+ }
+ c.setElementList(elementList);
+ }
+ containerList.add(c);
+ }
+ d.setContainerList(containerList);
+ domainList.add(d);
+
+ }
+ domainMap.put("domainList", domainList);
+
+ List<Domain> collapsedDomains = new ArrayList<Domain>();
+
+ // nline
+ for (Domain collapsed : layout.getCollapsedDomainsNewList()) {
+ collapsed.setWidth(10 * collapsed.computeSize().getWidth());
+ collapsed.setHeight(10 * collapsed.computeSize().getHeight());
+ collapsed.setLeft(10 * collapsed.getP().getX());
+ collapsed.setTop(10 * collapsed.getP().getY());
+ // nline
+ collapsed.setNewXafterColl(10 * collapsed.getNewXafterColl());
+ collapsed.setYafterColl(10 * collapsed.getYafterColl());
+ collapsedDomains.add(collapsed);
+ }
+
+ domainMap.put("collapsedDomainList", collapsedDomains);
+
+ Representer representer = new Representer();
+ representer.addClassTag(Domain.class, Tag.MAP);
+
+ Yaml yaml = new Yaml(representer);
+ String output = yaml.dump(domainMap);
+
+ return output;
+
+ }
+
+ private static HashMap<String, Object> toscaElementsMap = new HashMap<String, Object>();
+ private static HashMap<String, Element> elementMap = new HashMap<String, Element>();
+ private static HashMap<String, Element> miscElementMap = new HashMap<String, Element>();
+ private static HashMap<String, Container> outercontainers = new HashMap<String, Container>();
+ private static HashMap<String, Container> innercontainers = new HashMap<String, Container>();
+ private static HashMap<String, Domain> domainMap = new HashMap<String, Domain>();
+
+ private static String filePath = SystemProperties.getProperty("element_map_file_path");
+ private static String networkToscaYml = null;// "NetworkMap_topology_composition.yml";
+ private static String networkLayoutYml = null;// "network_map_layout.yml";
+
+ /**
+ * Builds renderable model of elements in the network map. Parses YAML files
+ * with metadata and builds input for JoinJS to render in the browser as
+ * SVG.
+ *
+ * @param args
+ * arg 0 - collapsedDomains; arg 1 - expandedDomains; arg 2 -
+ * context real path; arg 3 - contentFileName; arg 4 -
+ * layoutFileName
+ * @return Renderable model of elements
+ * @throws Exception
+ */
+ public String buildElementMapYaml(String args[]) throws Exception {
+
+ final String yamlDirPath = new File(args[2], filePath).getPath();
+ if (args != null && args.length > 4) {
+ if (args[3] != null)
+ networkToscaYml = args[3] + ".yml";
+ if (args[4] != null)
+ networkLayoutYml = args[4] + ".yml";
+ }
+
+ Map<String, Object> toscaYaml = YamlUtils.readYamlFile(yamlDirPath, networkToscaYml);
+ Map<String, Object> networkMapLayoutYaml = YamlUtils.readYamlFile(yamlDirPath, networkLayoutYml);
+
+ toscaElementsMap = new HashMap<String, Object>();
+ elementMap = new HashMap<String, Element>();
+ domainMap = new HashMap<String, Domain>();
+ outercontainers = new HashMap<String, Container>();
+ innercontainers = new HashMap<String, Container>();
+ miscElementMap = new HashMap<String, Element>();
+
+ if (toscaYaml != null) {
+ for (String key : toscaYaml.keySet()) {
+ if ("topology_template".equalsIgnoreCase(key) && toscaYaml.get(key) instanceof HashMap) {
+ HashMap<String, Object> toscaTopologyDetails = (HashMap<String, Object>) toscaYaml.get(key);
+
+ for (String detailsKey : toscaTopologyDetails.keySet()) {
+
+ if ("node_templates".equalsIgnoreCase(detailsKey)
+ && toscaTopologyDetails.get(detailsKey) instanceof HashMap) {
+
+ toscaElementsMap = (HashMap<String, Object>) toscaTopologyDetails.get(detailsKey);
+
+ // for (String toscaElementKey :
+ // toscaElementsMap.keySet()) {
+ //// System.out.println("Element - "+ "key :" +
+ //// toscaElementKey);
+ // }
+
+ }
+ }
+ }
+
+ }
+ }
+
+ if (networkMapLayoutYaml != null) {
+ if (networkMapLayoutYaml.containsKey("toscaNetworkMapElementStyleList")
+ && networkMapLayoutYaml.get("toscaNetworkMapElementStyleList") instanceof ArrayList) {
+
+ ArrayList<Object> elementlist = (ArrayList<Object>) networkMapLayoutYaml
+ .get("toscaNetworkMapElementStyleList");
+ String elementName;
+ String elementID;
+ String imgPath;
+ String row;
+ String column;
+ String mapKey;
+ int i = 0;
+
+ if (elementlist != null) {
+ for (Object eachElement : elementlist) {
+ // System.out.println("toscaNetworkMapElementStyleList
+ // Container : " +eachElement);
+ if (eachElement != null && eachElement instanceof HashMap) {
+ HashMap<String, String> elementDetails = (HashMap<String, String>) eachElement;
+ if (elementDetails != null) {
+ elementName = "NA" + i;
+ elementID = "NA" + i;
+ imgPath = "NA" + i;
+ row = "0";
+ column = "0";
+ for (String detailsKey : elementDetails.keySet()) {
+ if ("tosca_id".equalsIgnoreCase(detailsKey))
+ elementName = elementDetails.get(detailsKey).toString();
+ if ("id".equalsIgnoreCase(detailsKey)) {
+ elementID = String.valueOf(elementDetails.get(detailsKey));
+ }
+ if ("row".equalsIgnoreCase(detailsKey)) {
+ row = String.valueOf(elementDetails.get(detailsKey));
+ }
+ if ("column".equalsIgnoreCase(detailsKey)) {
+ column = String.valueOf(elementDetails.get(detailsKey));
+ }
+ if ("icon".equalsIgnoreCase(detailsKey))
+ imgPath = elementDetails.get(detailsKey).toString();
+ }
+
+ if (elementMap.containsKey(elementName.concat("/").concat(row).concat(column))) {
+ if (elementMap.containsKey(elementName.concat("/").concat(String.valueOf(i))
+ .concat(String.valueOf(i)))) {
+ mapKey = elementName;
+ } else
+ mapKey = elementName.concat("/").concat(String.valueOf(i))
+ .concat(String.valueOf(i));
+
+ } else
+ mapKey = elementName.concat("/").concat(row).concat(column);
+
+ elementMap.put(mapKey, fetchElementObject(elementID, elementName, imgPath));
+ }
+ }
+ i++;
+ }
+ }
+
+ for (String elementkey : elementMap.keySet()) {
+ Element c = (Element) elementMap.get(elementkey);
+ // System.out.println("Element - "+ "key :" +elementkey +" -
+ // " + "value :" + c.getName());
+ }
+
+ if (!elementMap.isEmpty()) {
+ miscElementMap = new HashMap<String, Element>(elementMap);
+ }
+ }
+
+ if (networkMapLayoutYaml.containsKey("containerStyleList")
+ && networkMapLayoutYaml.get("containerStyleList") instanceof ArrayList) {
+
+ ArrayList<Object> containerstylelist = (ArrayList<Object>) networkMapLayoutYaml
+ .get("containerStyleList");
+ String containerName;
+ String containerID;
+ String domain;
+ String row;
+ String column;
+ String mapKey;
+ int i = 0;
+
+ if (containerstylelist != null) {
+ // Inner Containers
+ for (Object eachContainer : containerstylelist) {
+ if (eachContainer != null && eachContainer instanceof HashMap) {
+ HashMap<String, String> containerDetails = (HashMap<String, String>) eachContainer;
+ if (containerDetails != null) {
+ containerName = "NA" + i;
+ containerID = "NA" + i;
+ domain = "NA" + i;
+ row = "0";
+ column = "0";
+
+ for (String detailsKey : containerDetails.keySet()) {
+ if ("logical_group_name".equalsIgnoreCase(detailsKey))
+ containerName = containerDetails.get(detailsKey).toString();
+ if ("id".equalsIgnoreCase(detailsKey)) {
+ containerID = String.valueOf(containerDetails.get(detailsKey));
+ }
+ if ("domain".equalsIgnoreCase(detailsKey)) {
+ domain = containerDetails.get(detailsKey).toString();
+ }
+ if ("row".equalsIgnoreCase(detailsKey)) {
+ row = String.valueOf(containerDetails.get(detailsKey));
+ }
+ if ("column".equalsIgnoreCase(detailsKey)) {
+ column = String.valueOf(containerDetails.get(detailsKey));
+ }
+ }
+ if (containerName.contains("/")) {
+
+ if (innercontainers.containsKey(
+ (domain + ":" + containerName).concat("/").concat(row).concat(column))) {
+ if (elementMap.containsKey((domain + ":" + containerName).concat("/")
+ .concat(String.valueOf(i)).concat(String.valueOf(i)))) {
+ mapKey = (domain + ":" + containerName);
+ } else
+ mapKey = (domain + ":" + containerName).concat("/")
+ .concat(String.valueOf(i)).concat(String.valueOf(i));
+
+ } else
+ mapKey = (domain + ":" + containerName).concat("/").concat(row).concat(column);
+
+ innercontainers.put(mapKey,
+ fetchContainerObject(containerID,
+ containerName.substring(containerName.indexOf("/") + 1), true,
+ containerName, domain));
+ }
+ }
+ }
+ i++;
+ }
+
+ // OuterContainers
+ i = 0;
+ for (Object eachContainer : containerstylelist) {
+ if (eachContainer != null && eachContainer instanceof HashMap) {
+ HashMap<String, String> containerDetails = (HashMap<String, String>) eachContainer;
+ if (containerDetails != null) {
+ containerName = "NA" + i;
+ containerID = "NA" + i;
+ domain = "NA" + i;
+ row = "0";
+ column = "0";
+
+ for (String detailsKey : containerDetails.keySet()) {
+ if ("logical_group_name".equalsIgnoreCase(detailsKey))
+ containerName = containerDetails.get(detailsKey).toString();
+ if ("id".equalsIgnoreCase(detailsKey)) {
+ containerID = String.valueOf(containerDetails.get(detailsKey));
+ }
+ if ("domain".equalsIgnoreCase(detailsKey)) {
+ domain = containerDetails.get(detailsKey).toString();
+ }
+ if ("row".equalsIgnoreCase(detailsKey)) {
+ row = String.valueOf(containerDetails.get(detailsKey));
+ }
+ if ("column".equalsIgnoreCase(detailsKey)) {
+ column = String.valueOf(containerDetails.get(detailsKey));
+ }
+ }
+ if (!containerName.contains("/")) {
+ if (outercontainers.containsKey(
+ (domain + ":" + containerName).concat("/").concat(row).concat(column))) {
+ if (outercontainers.containsKey((domain + ":" + containerName).concat("/")
+ .concat(String.valueOf(i)).concat(String.valueOf(i)))) {
+ mapKey = (domain + ":" + containerName);
+ } else
+ mapKey = (domain + ":" + containerName).concat("/")
+ .concat(String.valueOf(i)).concat(String.valueOf(i));
+
+ } else
+ mapKey = (domain + ":" + containerName).concat("/").concat(row).concat(column);
+ outercontainers.put(mapKey, fetchContainerObject(containerID, containerName, false,
+ containerName, domain));
+ }
+ // else innercontainers.put(domain +":"+
+ // containerName,
+ // fetchContainerObject(containerID,containerName.substring(containerName.indexOf("/")+1),false,containerName,domain));
+
+ }
+ }
+ i++;
+ }
+ }
+
+ for (String innerContainerkey : innercontainers.keySet()) {
+ Container c = (Container) innercontainers.get(innerContainerkey);
+ }
+
+ for (String outerContainerkey : outercontainers.keySet()) {
+ Container c = (Container) outercontainers.get(outerContainerkey);
+ }
+
+ }
+
+ if (networkMapLayoutYaml.containsKey("domainList")
+ && networkMapLayoutYaml.get("domainList") instanceof ArrayList) {
+
+ ArrayList<Object> domainlist = (ArrayList<Object>) networkMapLayoutYaml.get("domainList");
+ String domainName;
+ String domainID;
+ String row;
+ String column;
+ String mapKey;
+ int i = 0;
+
+ if (domainlist != null) {
+
+ HashMap<String, String> domainStagingMap = new HashMap<String, String>();
+ for (Object eachDomain : domainlist) {
+ // System.out.println("domainlist Container : "
+ // +eachDomain);
+ if (eachDomain != null && eachDomain instanceof HashMap) {
+ HashMap<String, String> domainDetails = (HashMap<String, String>) eachDomain;
+ if (domainDetails != null) {
+ domainName = "NA" + i;
+ domainID = "NA" + i;
+ row = "0";
+ column = "0";
+ for (String detailsKey : domainDetails.keySet()) {
+ if ("name".equalsIgnoreCase(detailsKey))
+ domainName = domainDetails.get(detailsKey).toString();
+ if ("id".equalsIgnoreCase(detailsKey)) {
+ domainID = String.valueOf(domainDetails.get(detailsKey));
+ }
+ if ("row".equalsIgnoreCase(detailsKey)) {
+ row = String.valueOf(domainDetails.get(detailsKey));
+ }
+ if ("column".equalsIgnoreCase(detailsKey)) {
+ column = String.valueOf(domainDetails.get(detailsKey));
+ }
+ }
+
+ if (domainStagingMap.containsKey(row.concat(column))) {
+ mapKey = domainName;
+ } else
+ mapKey = row.concat(column);
+
+ domainStagingMap.put(mapKey, domainID + "%" + domainName);
+ }
+ }
+ i++;
+ }
+
+ if (domainStagingMap != null && !domainStagingMap.isEmpty()) {
+ for (String domainsKey : new TreeSet<String>(domainStagingMap.keySet())) {
+ String value = domainStagingMap.get(domainsKey);
+ if (value.contains("%")) {
+ domainMap.put(domainsKey, fetchDomainObject(value.substring(0, value.indexOf("%")),
+ value.substring(value.indexOf("%") + 1)));
+ }
+ }
+ }
+ }
+
+ // for (String domainkey : domainMap.keySet()) {
+ // Domain c = (Domain) domainMap.get(domainkey);
+ // System.out.println("Domain - "+ "key :" +domainkey +" - "
+ // + "value :" + c.getName());
+ // }
+ }
+
+ }
+
+ Layout dynamicLayout = new Layout(domainMap, 2, 10, 1, 5);
+ dynamicLayout.computeDomainPositionsModified();
+
+ /*
+ * Map<String, Domain> resultAICDomain2 = dynamicLayout.domainRowCol;
+ * for (String key : resultAICDomain2.keySet()) { if
+ * (resultAICDomain2.get(key).getP() != null) {
+ * System.out.println(resultAICDomain2.get(key).name+" "+"x:"+
+ * resultAICDomain2.get(key).getP().getX()+","+"y:"+
+ * resultAICDomain2.get(key).getP().getY()+","+"width:"+
+ * resultAICDomain2.get(key).computeSize().getWidth()
+ * +","+"height:"+resultAICDomain2.get(key).computeSize(). getHeight());
+ *
+ * } }
+ */
+
+ ElementMapService cm2 = new ElementMapService();
+ try {
+
+ if (args != null && args.length > 0) {
+
+ if (args[0] != null) {
+ String collapsedDomains[] = args[0].split(",");
+ for (String collapsedDomain : collapsedDomains)
+ // dynamicLayout.collapseDomainModified(collapsedDomain);
+ dynamicLayout.collapseDomainNew(collapsedDomain);
+ }
+
+ if (args[1] != null) {
+ String expandedDomains[] = args[1].split(",");
+ for (String expandedDomain : expandedDomains)
+ // dynamicLayout.uncollapseDomainNew(expandedDomain);
+ dynamicLayout.uncollapseDomainNew1(expandedDomain);
+ }
+
+ return cm2.convertToYAML(args[2], dynamicLayout);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "buildElementMapYaml failed", e);
+ }
+
+ return "";
+ }
+
+ private static int computeRows(Set<String> keys) {
+ int i = 0;
+ if (keys != null && !keys.isEmpty()) {
+ for (String s : keys) {
+ String r = s.substring(0, 1);
+ if (StringUtils.isNumeric(r)) {
+ int j = Integer.parseInt(r);
+ if (i <= j) {
+ i = j;
+ }
+
+ }
+ }
+
+ return i + 1;
+ }
+
+ return 1;
+ }
+
+ private static int computeColumns(Set<String> keys) {
+ int i = 0;
+ if (keys != null && !keys.isEmpty()) {
+ for (String s : keys) {
+ String r = s.substring(1, 2);
+ if (StringUtils.isNumeric(r)) {
+ int j = Integer.parseInt(r);
+ if (i <= j) {
+ i = j;
+ }
+
+ }
+ }
+
+ return i + 1;
+ }
+
+ return 1;
+ }
+
+ private static Container fetchContainerObject(String id, String name, boolean isInner, String logicalGroupName,
+ String domain) {
+ Map<String, Element> containerElementsMap = new HashMap<String, Element>();
+
+ containerElementsMap = fetchElementsMapForContainer(name, isInner, logicalGroupName, domain);
+ int rows = 1;
+ int columns = 1;
+
+ if (isInner) {
+
+ if (containerElementsMap != null && !containerElementsMap.isEmpty()) {
+ rows = computeRows(containerElementsMap.keySet());
+ columns = computeColumns(containerElementsMap.keySet());
+ }
+
+ Container thisContainer = new Container(id, name, rows, columns, 1, 4, 8, 12, 1, 2);
+ thisContainer.setElements(containerElementsMap);
+ // thisContainer.setVisibilityType("");
+
+ return thisContainer;
+ } else {
+ Map<String, Container> innerContainersMap = fetchInnerContainersMapForOuter(name, isInner, logicalGroupName,
+ domain);
+
+ if (innerContainersMap != null && !innerContainersMap.isEmpty()) {
+ if (containerElementsMap != null && !containerElementsMap.isEmpty()) {
+ Set<String> keys = new HashSet<String>(innerContainersMap.keySet());
+ keys.addAll(containerElementsMap.keySet());
+ rows = computeRows(keys);
+ columns = computeColumns(keys);
+ } else {
+ rows = computeRows(innerContainersMap.keySet());
+ columns = computeColumns(innerContainersMap.keySet());
+ }
+ } else if (containerElementsMap != null && !containerElementsMap.isEmpty()) {
+ rows = computeRows(containerElementsMap.keySet());
+ columns = computeColumns(containerElementsMap.keySet());
+ }
+
+ Container thisContainer = new Container(id, name, rows, columns, 2, 6, 2, 5, 0, 0);
+ thisContainer.setElements(containerElementsMap);
+ thisContainer.setInnerContainer(innerContainersMap);
+
+ if (containerElementsMap != null && !containerElementsMap.isEmpty()) {
+ for (Element thisElement : containerElementsMap.values()) {
+ if (thisElement.getId() != null
+ ) {
+ thisContainer.setVisibilityType("invisible");
+ }
+ }
+ }
+ return thisContainer;
+ }
+
+ }
+
+ private static Domain fetchDomainObject(String id, String name) {
+ HashMap<String, Container> domainContainersMap = fetchContainersForDomain(name);
+
+ int rows = 1;
+ int columns = 1;
+ if (domainContainersMap != null && !domainContainersMap.isEmpty()) {
+ rows = computeRows(domainContainersMap.keySet());
+ columns = computeColumns(domainContainersMap.keySet());
+ }
+
+ double domainWidth = 11;
+ Domain thisDomain;
+
+ if (domainMap != null && !domainMap.isEmpty()) {
+ int domainsCountSoFar = domainMap.size();
+ switch (domainsCountSoFar) {
+ case 1: {
+ domainWidth = 12.1;
+ break;
+ }
+ case 2: {
+ domainWidth = 13.3;
+ break;
+ }
+ case 3: {
+ domainWidth = 14.5;
+ break;
+ }
+ case 4: {
+ domainWidth = 15.6;
+ break;
+ }
+ default: {
+ domainWidth = 11;
+ break;
+ }
+ }
+
+ for (String domainsKey : new TreeSet<String>(domainMap.keySet())) {
+ Domain eachDomain = domainMap.get(domainsKey);
+ domainWidth += eachDomain.computeSize().getWidth();
+ }
+ thisDomain = new Domain(id, name, 2, 2, domainWidth, 10, 3, rows, columns);
+ } else {
+
+ thisDomain = new Domain(id, name, 2, 1, 11, 10, 3, rows, columns);
+ }
+
+ // Domain thisDomain = new Domain(id, name, 2, 1, leftPosition, 10, 3,
+ // rows, columns);
+ thisDomain.setContainers(domainContainersMap);
+
+ thisDomain.computeConatinerPositions();
+ if (domainContainersMap != null && !domainContainersMap.isEmpty()) {
+ for (Container thisContainer : domainContainersMap.values()) {
+ thisContainer.computeSize();
+ thisContainer.computeElementPositions();
+ Map<String, Element> resultElementMap = thisContainer.elementRowCol;
+ for (String key : resultElementMap.keySet()) {
+ if (resultElementMap.get(key) == null || resultElementMap.get(key).getP() == null) {
+ // System.out.println("culprit " +key);
+ }
+ /*
+ * System.out.println(resultElementMap.get(key).name+" "
+ * +"x:"+resultElementMap.get(key).getP().getX()+","+"y:"+
+ * resultElementMap.get(key).getP().getY()+","+"width:"+
+ * resultElementMap.get(key).computeSize().getWidth()
+ * +","+"height:"+resultElementMap.get(key).computeSize().
+ * getHeight());
+ */
+
+ }
+
+ HashMap<String, Container> innerContainersMap = (HashMap<String, Container>) thisContainer
+ .getContainerRowCol();
+ if (innerContainersMap != null && !innerContainersMap.isEmpty()) {
+ for (Container thisInnerContainer : innerContainersMap.values()) {
+ // thisInnerContainer.computeSize();
+ thisInnerContainer.computeElementPositions();
+ /*
+ * Map<String,Element> resultInnerElementMap =
+ * thisContainer.elementRowCol; for (String key :
+ * resultElementMap.keySet()) { //
+ * System.out.println(resultElementMap.get(key).name+" "
+ * +"x:"+resultElementMap.get(key).getP().getX()+","+
+ * "y:"+
+ * resultElementMap.get(key).getP().getY()+","+"width:"+
+ * resultElementMap.get(key).computeSize().getWidth()
+ * +","+"height:"+resultElementMap.get(key).computeSize(
+ * ).getHeight());
+ *
+ * }
+ */
+ }
+ }
+ }
+ }
+
+ return thisDomain;
+ }
+
+ private static HashMap<String, Container> fetchContainersForDomain(String domain) {
+ HashMap<String, Container> domainContainersMap = new HashMap<String, Container>();
+
+ domainContainersMap = fetchFromOuterContainers(domain);
+
+ return domainContainersMap;
+
+ }
+
+ private static Element fetchElementObject(String id, String name, String imgPath) {
+ String bgColor = "bgColor";
+ String logical_group;
+ String display_longname;
+ String display_shortname;
+ String description;
+ String primary_function;
+ String key_interfaces;
+ String location;
+ String vendor;
+ String vendor_shortname;
+ String enclosingContainer;
+ String borderType;
+ String network_function;
+
+ if (toscaElementsMap.containsKey(name)) {
+
+ if (toscaElementsMap.get(name) != null && toscaElementsMap.get(name) instanceof HashMap) {
+ HashMap<String, Object> toscaElementDetails = (HashMap<String, Object>) toscaElementsMap.get(name);
+
+ for (String detailsKey : toscaElementDetails.keySet()) {
+ if ("properties".equalsIgnoreCase(detailsKey)
+ && toscaElementDetails.get(detailsKey) instanceof HashMap) {
+ HashMap<String, String> elementDetails = (HashMap<String, String>) toscaElementDetails
+ .get(detailsKey);
+
+ if (elementDetails != null) {
+ logical_group = elementDetails.get("logical_group") == null ? ""
+ : elementDetails.get("logical_group").toString();
+ display_longname = elementDetails.get("display_longname") == null ? ""
+ : elementDetails.get("display_longname").toString();
+ display_shortname = elementDetails.get("display_shortname") == null ? ""
+ : elementDetails.get("display_shortname").toString();
+ description = elementDetails.get("description") == null ? ""
+ : elementDetails.get("description").toString();
+ primary_function = elementDetails.get("primary_function") == null ? ""
+ : elementDetails.get("primary_function").toString();
+ key_interfaces = elementDetails.get("key_interfaces") == null ? ""
+ : elementDetails.get("key_interfaces").toString();
+ location = elementDetails.get("location") == null ? ""
+ : elementDetails.get("location").toString();
+ vendor = elementDetails.get("vendor") == null ? ""
+ : elementDetails.get("vendor").toString();
+ vendor_shortname = elementDetails.get("vendor_shortname") == null ? ""
+ : elementDetails.get("vendor_shortname").toString();
+ enclosingContainer = logical_group.replace("/", "-");
+ network_function = elementDetails.get("network_function");
+ borderType = elementDetails.get("network_function") == null ? "P"
+ : elementDetails.get("network_function").toString().toUpperCase();
+ bgColor = elementDetails.get("background_color") == null ? "bgColor"
+ : elementDetails.get("background_color").toString();
+
+ ElementDetails details = new ElementDetails(logical_group, display_longname, description,
+ primary_function, network_function, key_interfaces, location, vendor,
+ vendor_shortname, enclosingContainer);
+
+ return new Element(name, display_shortname, imgPath, bgColor, borderType, details);
+ }
+
+ }
+ }
+
+ }
+
+ // Element(id, name, imgPath, bgColor, logical_group,
+ // display_longname,
+ // description, primary_function, key_interfaces, location, vendor,
+ // vendor_shortname);
+ } else {
+ return new Element(id, name);
+ }
+
+ return new Element(id, name);
+ }
+
+ private static String fetchDomainNameOfElement(String name) {
+ if (toscaElementsMap.containsKey(name)) {
+
+ if (toscaElementsMap.get(name) != null && toscaElementsMap.get(name) instanceof HashMap) {
+ HashMap<String, Object> toscaElementDetails = (HashMap<String, Object>) toscaElementsMap.get(name);
+
+ for (String detailsKey : toscaElementDetails.keySet()) {
+ if ("properties".equalsIgnoreCase(detailsKey)
+ && toscaElementDetails.get(detailsKey) instanceof HashMap) {
+ HashMap<String, String> elementDetails = (HashMap<String, String>) toscaElementDetails
+ .get(detailsKey);
+
+ if (elementDetails != null) {
+ return elementDetails.get("domain") == null ? "" : elementDetails.get("domain").toString();
+ }
+
+ }
+ }
+
+ }
+
+ } else {
+ return "";
+ }
+
+ return "";
+ }
+
+ private static HashMap<String, Container> fetchInnerContainersMapForOuter(String name, boolean isInner,
+ String logicalGroupName, String domain) {
+ return fetchInnerContainersMap(name, logicalGroupName, domain);
+ }
+
+ private static HashMap<String, Element> fetchElementsMapForContainer(String name, boolean isInner,
+ String logicalGroupName, String domain) {
+ return fetchElementsMap(logicalGroupName, domain);
+ }
+
+ private static HashMap<String, Container> fetchInnerContainersMap(String name, String logicalGroupName,
+ String domain) {
+ HashMap<String, Container> containersMap = new HashMap<String, Container>();
+ String rowColumnKey = "";
+ int count = 0;
+
+ if (innercontainers != null && !innercontainers.isEmpty()) {
+ for (String key : innercontainers.keySet()) {
+
+ Container eachContainer = innercontainers.get(key);
+
+ if (key.toUpperCase().contains((domain + ":" + name).toUpperCase())) {
+ if (key.contains("/")) {
+ rowColumnKey = key.substring(key.lastIndexOf("/") + 1);
+ }
+
+ if (rowColumnKey.isEmpty() || containersMap.containsKey(rowColumnKey)) {
+ count = 0;
+ while (count <= 9) {
+ if (containersMap.containsKey(String.valueOf(count).concat(String.valueOf(count)))) {
+ count++;
+ } else {
+ rowColumnKey = String.valueOf(count).concat(String.valueOf(count));
+ break;
+ }
+ }
+
+ }
+
+ containersMap.put(rowColumnKey, eachContainer);
+ }
+
+ }
+ }
+ return containersMap.isEmpty() ? null : containersMap;
+
+ }
+
+ private static HashMap<String, Container> fetchFromOuterContainers(String domain) {
+ HashMap<String, Container> thisContainersMap = new HashMap<String, Container>();
+ String rowColumnKey = "";
+ int count = 0;
+
+ if (outercontainers != null && !outercontainers.isEmpty()) {
+ for (String key : outercontainers.keySet()) {
+ Container eachContainer = outercontainers.get(key);
+
+ if (key.toUpperCase().contains((domain + ":").toUpperCase())) {
+ if (key.contains("/")) {
+ rowColumnKey = key.substring(key.lastIndexOf("/") + 1);
+ }
+
+ if (rowColumnKey.isEmpty() || thisContainersMap.containsKey(rowColumnKey)) {
+ count = 0;
+ while (count <= 9) {
+ if (thisContainersMap.containsKey(String.valueOf(count).concat(String.valueOf(count)))) {
+ count++;
+ } else {
+ rowColumnKey = String.valueOf(count).concat(String.valueOf(count));
+ break;
+ }
+ }
+
+ }
+
+ thisContainersMap.put(rowColumnKey, eachContainer);
+ }
+ }
+
+ }
+
+ // Misc Elements Containers
+
+ if (miscElementMap != null && !miscElementMap.isEmpty()) {
+ for (String key : miscElementMap.keySet()) {
+ Element eachElement = miscElementMap.get(key);
+ String elementName = eachElement.getName();
+ String domainName = fetchDomainNameOfElement(elementName);
+
+ if (domain.equalsIgnoreCase(domainName)) {
+ Container eachContainer = new Container(domainName + ":" + elementName, elementName, 1, 1, 3, 6, 2,
+ 5, 0, 0);
+ count = 0;
+ while (count <= 9) {
+ if (thisContainersMap.containsKey(String.valueOf(count).concat(String.valueOf(count)))) {
+ count++;
+ } else {
+ rowColumnKey = String.valueOf(count).concat(String.valueOf(count));
+ break;
+ }
+ }
+
+ thisContainersMap.put(rowColumnKey, eachContainer);
+ }
+
+ }
+
+ }
+
+ return thisContainersMap.isEmpty() ? null : thisContainersMap;
+ }
+
+ private static HashMap<String, Container> addOuterContainersForMiscElements(String domain) {
+ HashMap<String, Container> containerElementsMap = new HashMap<String, Container>();
+ if (miscElementMap != null && !miscElementMap.isEmpty()) {
+ for (String key : miscElementMap.keySet()) {
+ Element eachElement = miscElementMap.get(key);
+ String elementName = eachElement.getName();
+ String domainName = fetchDomainNameOfElement(elementName);
+
+ if (domain.equalsIgnoreCase(domainName)) {
+ Container newContainer = new Container(domainName + ":" + elementName, elementName, 1, 1, 3, 6, 2,
+ 5, 0, 0);
+ containerElementsMap.put(domainName + ":" + elementName, newContainer);
+ }
+
+ }
+
+ }
+ return containerElementsMap.isEmpty() ? null : containerElementsMap;
+ }
+
+ private static HashMap<String, Element> fetchElementsMap(String logicalGroupName, String domain) {
+ HashMap<String, Element> innerElementMap = new HashMap<String, Element>();
+ String rowColumnKey = "";
+ int count = 0;
+
+ if (elementMap != null && !elementMap.isEmpty()) {
+ for (String key : elementMap.keySet()) {
+ Element eachElement = elementMap.get(key);
+
+ String elementName = eachElement.getId();
+ String elementLogicalGroup = eachElement.details == null ? "" : eachElement.details.logical_group;
+ if (elementLogicalGroup.equalsIgnoreCase(logicalGroupName)
+ && domain.equalsIgnoreCase(fetchDomainNameOfElement(elementName))) {
+ if (key.contains("/")) {
+ rowColumnKey = key.substring(key.indexOf("/") + 1);
+ }
+
+ if (rowColumnKey.isEmpty() || innerElementMap.containsKey(rowColumnKey)) {
+ count = 0;
+ while (count <= 9) {
+ if (innerElementMap.containsKey(String.valueOf(count).concat(String.valueOf(count)))) {
+ count++;
+ } else {
+ rowColumnKey = String.valueOf(count).concat(String.valueOf(count));
+ break;
+ }
+ }
+
+ }
+
+ innerElementMap.put(rowColumnKey, eachElement);
+ miscElementMap.remove(key);
+ }
+
+ }
+ }
+
+ return innerElementMap.isEmpty() ? null : innerElementMap;
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/FnMenuService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/FnMenuService.java
new file mode 100644
index 00000000..040c9d26
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/FnMenuService.java
@@ -0,0 +1,46 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.openecomp.portalsdk.core.domain.Menu;
+import org.openecomp.portalsdk.core.domain.MenuData;
+import org.openecomp.portalsdk.core.domain.RoleFunction;
+
+/**
+ * Description: this java class is an interface of services for Admin to add/edit/delete menu items from FN_MENU
+ */
+public interface FnMenuService {
+ List<MenuData> getFnMenuItems();
+ void saveFnMenuData(MenuData domainFnMenu);
+ void saveFnMenu(Menu domainFnMenu);
+ void removeMenuItem(MenuData domainFnMenu);
+ MenuData getMenuItemRow(Long id);
+ Menu getMenuItem(Long id);
+ List<Long> getParentId(String label);
+ @SuppressWarnings("rawtypes")
+ List<List> getParentList();
+ List<RoleFunction> getFunctionCDList();
+ void removeMenuItem(Menu domainFnMenu);
+ Map<String, List<MenuData>> setMenuDataStructure(List<List<MenuData>> childItemList, List<MenuData> parentList, Set<MenuData> menuResult) throws Exception;
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/FnMenuServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/FnMenuServiceImpl.java
new file mode 100644
index 00000000..ca73339d
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/FnMenuServiceImpl.java
@@ -0,0 +1,161 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.openecomp.portalsdk.core.domain.FnMenu;
+import org.openecomp.portalsdk.core.domain.Menu;
+import org.openecomp.portalsdk.core.domain.MenuData;
+import org.openecomp.portalsdk.core.domain.Role;
+import org.openecomp.portalsdk.core.domain.RoleFunction;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Description: this java class is an implementation of services for Admin to add/edit/delete menu items from FN_MENU
+ */
+
+@Service("fnMenuService")
+@Transactional
+public class FnMenuServiceImpl implements FnMenuService{
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @SuppressWarnings("unchecked")
+ public List<MenuData> getFnMenuItems() {
+ //List msgDB = getDataAccessService().getList(Profile.class, null);
+ return getDataAccessService().getList(MenuData.class, null, "1", null);
+
+ }
+
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+
+ @Override
+ public void saveFnMenuData(MenuData domainFnMenu) {
+ // TODO Auto-generated method stub
+ getDataAccessService().saveDomainObject(domainFnMenu, null);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<Long> getParentId(String label) {
+ // TODO Auto-generated method stub
+ //List<String> functioCDlist = new ArrayList<String>();
+ //functioCDlist.add("Mahdy1");
+ //functioCDlist.add("Mahdy2");
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("paramLabel", label);
+ return getDataAccessService().executeNamedQuery("IdForLabelList", params, null);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public List<List> getParentList() {
+ // TODO Auto-generated method stub
+ //List<String> functioCDlist = new ArrayList<String>();
+ //functioCDlist.add("Mahdy1");
+ //functioCDlist.add("Mahdy2");
+ return getDataAccessService().executeNamedQuery("parentList", null, null);
+
+ //return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<RoleFunction> getFunctionCDList() {
+ // TODO Auto-generated method stub
+ //List<String> functioCDlist = new ArrayList<String>();
+ //functioCDlist.add("Mahdy1");
+ //functioCDlist.add("Mahdy2");
+ return getDataAccessService().executeNamedQuery("functionCDlist", null, null);
+
+ //return null;
+ }
+
+ @Override
+ public void removeMenuItem(MenuData domainFnMenu) {
+ getDataAccessService().deleteDomainObject(domainFnMenu, null);
+ }
+
+ @Override
+ public void removeMenuItem(Menu domainFnMenu) {
+ getDataAccessService().deleteDomainObject(domainFnMenu, null);
+ }
+
+ public MenuData getMenuItemRow(Long id) {
+ return (MenuData)getDataAccessService().getDomainObject(MenuData.class, id, null);
+ }
+
+ @Override
+ public Menu getMenuItem(Long id) {
+ return (Menu)getDataAccessService().getDomainObject(Menu.class, id, null);
+ }
+
+ @Override
+ public void saveFnMenu(Menu domainFnMenu) {
+ // TODO Auto-generated method stub
+ getDataAccessService().saveDomainObject(domainFnMenu, null);
+
+ }
+ @Override
+ public Map<String, List<MenuData>> setMenuDataStructure(List<List<MenuData>> childItemList, List<MenuData> parentList, Set<MenuData> menuResult) throws Exception{
+ for(MenuData menu: menuResult){
+ MenuData parentData = new MenuData();
+ parentData.setLabel(menu.getLabel());
+ parentData.setAction(menu.getAction());
+ parentData.setImageSrc(menu.getImageSrc());
+ parentList.add(parentData);
+ List<MenuData> tempList = new ArrayList<MenuData>();
+ for(Object o:menu.getChildMenus()){
+ MenuData m = (MenuData)o;
+ MenuData data = new MenuData();
+ data.setLabel(m.getLabel());
+ data.setAction(m.getAction());
+ data.setImageSrc(m.getImageSrc());
+ tempList.add(data);
+ }
+ childItemList.add(tempList);
+ }
+ return null;
+ }
+
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LdapService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LdapService.java
new file mode 100644
index 00000000..9c790eb2
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LdapService.java
@@ -0,0 +1,31 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import org.openecomp.portalsdk.core.command.support.SearchResult;
+import org.openecomp.portalsdk.core.domain.support.DomainVo;
+
+
+public interface LdapService {
+
+ // search POST for users based on the criteria selected in the Request
+ SearchResult searchPost(DomainVo searchCriteria, String sortBy1, String sortBy2, String sortBy3, int pageNo, int dataSize, int userId) throws Exception;
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LdapServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LdapServiceImpl.java
new file mode 100644
index 00000000..ba43e45f
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LdapServiceImpl.java
@@ -0,0 +1,267 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+
+import org.openecomp.portalsdk.core.command.support.SearchResult;
+import org.openecomp.portalsdk.core.domain.User;
+import org.openecomp.portalsdk.core.domain.support.DomainVo;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.service.support.FusionService;
+import org.openecomp.portalsdk.core.service.support.ServiceLocator;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("ldapService")
+@Transactional
+public class LdapServiceImpl extends FusionService implements LdapService {
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LdapServiceImpl.class);
+ @Autowired
+ private ServiceLocator serviceLocator;
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public SearchResult searchPost(DomainVo searchCriteria, String sortBy1, String sortBy2, String sortBy3,
+ int pageNo, int dataSize, int userId) throws Exception {
+
+ // initialize the directory context to access POST
+ DirContext dirContext = serviceLocator.getDirContext(SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY),
+ SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL),
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL));
+
+ SearchResult searchResult = new SearchResult();
+
+ try {
+
+ String[] postAttributes = {"nickname","givenName","initials","sn","employeeNumber","mail","telephoneNumber",
+ "departmentNumber","a1","street","roomNumber","l","st","postalCode","zip4","physicalDeliveryOfficeName","bc",
+ "friendlyCountryName","bd","bdname","bu","buname","jtname","mgrid","a2","compcode","compdesc",
+ "costcenter","silo","b2"};
+
+ SearchControls searchControls = new SearchControls();
+ searchControls.setTimeLimit(5000);
+ searchControls.setReturningAttributes(postAttributes);
+
+ StringBuffer filterClause = new StringBuffer("(&(objectClass=*)");
+
+ User user = (User)searchCriteria;
+
+ if(Utilities.nvl(user.getFirstName()).length() > 0) {
+ filterClause.append("(givenName=").append(user.getFirstName()).append("*)");
+ }
+ if(Utilities.nvl(user.getLastName()).length() > 0) {
+ filterClause.append("(sn=").append(user.getLastName()).append("*)");
+ }
+ if(Utilities.nvl(user.getHrid()).length() > 0) {
+ filterClause.append("(employeeNumber=").append(user.getHrid()).append("*)");
+ }
+ if(Utilities.nvl(user.getOrgManagerUserId()).length() > 0) {
+ filterClause.append("(mgrid=").append(user.getOrgManagerUserId()).append("*)");
+ }
+ if(Utilities.nvl(user.getOrgCode()).length() > 0) {
+ filterClause.append("(departmentNumber=").append(user.getOrgCode()).append("*)");
+ }
+ if(Utilities.nvl(user.getEmail()).length() > 0) {
+ filterClause.append("(mail=").append(user.getEmail()).append("*)");
+ }
+ if(Utilities.nvl(user.getOrgUserId()).length() > 0) {
+ filterClause.append("(a1=").append(user.getOrgUserId()).append("*)");
+ }
+ filterClause.append("(c3=N)"); // this has been added to filter CP09 entries on the LDAP server that are duplicates of existing individuals
+ filterClause.append(")");
+
+ List list = new ArrayList();
+ if (!filterClause.toString().equals("(&(objectClass=*))")) {
+ NamingEnumeration e = dirContext.search(SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL) + "/" +
+ SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL),
+ filterClause.toString(),
+ searchControls);
+
+ list = processResults(e);
+ }
+
+ Collections.sort(list);
+
+ searchResult = new SearchResult(list);
+ searchResult.setPageNo(pageNo);
+ if(dataSize >= 0) {
+ searchResult.setDataSize(dataSize);
+ }
+ else {
+ searchResult.setDataSize(list.size());
+ } // else
+
+ }
+ catch(NamingException ne) {
+ logger.error(EELFLoggerDelegate.errorLogger,ne.getMessage());
+ }
+ finally {
+ dirContext.close();
+ }
+
+ return searchResult;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private ArrayList processResults(NamingEnumeration e) throws NamingException {
+ ArrayList results = new ArrayList();
+ int count = 0;
+
+ while (e.hasMore()) {
+ javax.naming.directory.SearchResult searchResult = (javax.naming.directory.SearchResult)e.next();
+ results.add(processAttributes(searchResult.getAttributes()));
+ count++;
+
+ if(count > Integer.parseInt(SystemProperties.getProperty(SystemProperties.POST_MAX_RESULT_SIZE))) {
+ break;
+ }
+
+ }
+
+ return results;
+ }
+
+ @SuppressWarnings("rawtypes")
+ private DomainVo processAttributes(Attributes resultAttributes) throws NamingException {
+ User user = new User();
+
+ try {
+ if (resultAttributes == null) {
+ // System.out.println("This result has no attributes");
+ } else {
+ for (NamingEnumeration e = resultAttributes.getAll(); e.hasMore();) { //why the nested loop?
+ Attribute attribute = (Attribute)e.next();
+ for (NamingEnumeration ie = attribute.getAll(); ie.hasMore();) {
+ if (attribute.getID().equalsIgnoreCase("nickname")) {
+ user.setFirstName((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("initials")) {
+ user.setMiddleInitial((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("sn")) {
+ user.setLastName((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("employeeNumber")) {
+ user.setHrid((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("mail")) {
+ user.setEmail((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("telephoneNumber")) {
+ user.setPhone((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("departmentNumber")) {
+ user.setOrgCode((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("a1")) {
+ user.setOrgUserId((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("street")) {
+ user.setAddress1((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("roomNumber")) {
+ user.setAddress2((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("l")) {
+ user.setCity((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("st")) {
+ user.setState((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("postalCode")) {
+ user.setZipCode((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("zip4")) {
+ user.setZipCodeSuffix((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("physicalDeliveryOfficeName")) {
+ user.setLocationClli((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("bc")) {
+ user.setBusinessCountryCode((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("friendlyCountryName")) {
+ user.setBusinessCountryName((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("bd")) {
+ user.setDepartment((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("bdname")) {
+ user.setDepartmentName((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("jtname")) {
+ user.setJobTitle((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("mgrid")) {
+ user.setOrgManagerUserId((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("a2")) {
+ user.setCommandChain((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("compcode")) {
+ user.setCompanyCode((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("compdesc")) {
+ user.setCompany((String) ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("bu")) {
+ user.setBusinessUnit((String)ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("buname")) {
+ user.setBusinessUnitName((String)ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("silo")) {
+ user.setSiloStatus((String)ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("costcenter")) {
+ user.setCostCenter((String)ie.next());
+ }
+ else if (attribute.getID().equalsIgnoreCase("b2")) {
+ user.setFinancialLocCode((String)ie.next());
+ }
+ else { //we don't care about returned attribute, let's move on
+ ie.next();
+ }
+
+ }
+ }
+ }
+ } catch (NamingException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "An error occurred while processing the following user from POST with an ORGUSERID of " + user.getOrgUserId() + e.getMessage());
+ } finally {
+ return user;
+ }
+
+ }
+
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java
new file mode 100644
index 00000000..4f004108
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java
@@ -0,0 +1,36 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+
+import java.util.*;
+
+import org.openecomp.portalsdk.core.command.*;
+
+
+public interface LoginService {
+
+ // validate user exists in the system
+ @SuppressWarnings("rawtypes")
+ LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams) throws Exception;
+
+ @SuppressWarnings("rawtypes")
+ LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams, boolean matchPassword) throws Exception;
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java
new file mode 100644
index 00000000..e0a4b7c6
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java
@@ -0,0 +1,205 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.openecomp.portalsdk.core.command.LoginBean;
+import org.openecomp.portalsdk.core.domain.Role;
+import org.openecomp.portalsdk.core.domain.User;
+import org.openecomp.portalsdk.core.domain.UserApp;
+import org.openecomp.portalsdk.core.menu.MenuBuilder;
+import org.openecomp.portalsdk.core.service.support.FusionService;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.openecomp.portalsdk.core.web.support.AppUtils;
+import org.openecomp.portalsdk.core.web.support.UserUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("loginService")
+@Transactional
+public class LoginServiceImpl extends FusionService implements LoginService {
+
+ @SuppressWarnings("unused")
+ private MenuBuilder menuBuilder;
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @SuppressWarnings("rawtypes")
+ public LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams ) throws Exception {
+ return findUser(bean, menuPropertiesFilename, additionalParams, true);
+ }
+
+ @SuppressWarnings("rawtypes")
+ public LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams, boolean matchPassword) throws Exception {
+ User user = null;
+ User userCopy = null;
+
+ if (bean.getUserid() != null && bean.getUserid() != null) {
+ user = (User)findUser(bean);
+ }
+ else {
+ if (matchPassword)
+ user = (User)findUser(bean.getLoginId(), bean.getLoginPwd());
+ else
+ user = (User)findUserWithoutPwd(bean.getLoginId());
+ }
+
+ if (user != null) {
+
+ // raise an error if the application is locked and the user does not have system administrator privileges
+ if (AppUtils.isApplicationLocked() && !UserUtils.hasRole(user, SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID))) {
+ bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_APPLICATION_LOCKED);
+ }
+
+ // raise an error if the user is inactive
+ if (!user.getActive()) {
+ bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE);
+ }
+
+ // raise an error if no active roles exist for the user
+// boolean hasActiveRole = false;
+// Iterator roles = user.getRoles().iterator();
+// while (roles.hasNext()) {
+// Role role = (Role)roles.next();
+// if (role.getActive()) {
+// hasActiveRole = true;
+// break;
+// }
+// }
+
+// if (!hasActiveRole) {
+// bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE);
+// }
+ if (!userHasActiveRoles(user)) {
+ bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE);
+ }
+ // only login the user if no errors have occurred
+ if (bean.getLoginErrorMessage() == null) {
+
+ // this will be a snapshot of the user's information as retrieved from the database
+ userCopy = (User)user.clone();
+
+ // update the last logged in date for the user
+ user.setLastLoginDate(new Date());
+ getDataAccessService().saveDomainObject(user, additionalParams);
+
+ // update the audit log of the user
+ //Check for the client device type and set log attributes appropriately
+
+
+ // save the above changes to the User and their audit trail
+
+
+
+
+ // create the application menu based on the user's privileges
+ Set appMenu = getMenuBuilder().getMenu(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME),dataAccessService);
+ bean.setMenu(appMenu != null?appMenu:new HashSet());
+ Set businessDirectMenu = getMenuBuilder().getMenu(SystemProperties.getProperty(SystemProperties.BUSINESS_DIRECT_MENU_SET_NAME),dataAccessService);
+ bean.setBusinessDirectMenu(businessDirectMenu != null?businessDirectMenu:new HashSet());
+
+ bean.setUser(userCopy);
+ }
+
+ }
+
+ return bean;
+ }
+
+ private boolean userHasActiveRoles(User user) {
+ boolean hasActiveRole = false;
+ Iterator roles = user.getRoles().iterator();
+ while (roles.hasNext()) {
+ Role role = (Role)roles.next();
+ if (role.getActive()) {
+ hasActiveRole = true;
+ break;
+ }
+ }
+ return hasActiveRole;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public User findUser(String loginId, String password) {
+ List list = null;
+
+ StringBuffer criteria = new StringBuffer();
+ criteria.append(" where login_id = '").append(loginId).append("'")
+ .append(" and login_pwd = '").append(password).append("'");
+
+ list = getDataAccessService().getList(User.class, criteria.toString(), null, null);
+
+ return (list == null || list.size() == 0) ? null : (User)list.get(0);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private User findUserWithoutPwd(String loginId) {
+ List list = null;
+
+ StringBuffer criteria = new StringBuffer();
+ criteria.append(" where login_id = '").append(loginId).append("'");
+
+ list = getDataAccessService().getList(User.class, criteria.toString(), null, null);
+
+ return (list == null || list.size() == 0) ? null : (User)list.get(0);
+ }
+
+ @SuppressWarnings("rawtypes")
+ public User findUser(LoginBean bean) {
+ List list = null;
+
+ StringBuffer criteria = new StringBuffer();
+ criteria.append(" where org_user_id = '").append(bean.getUserid()).append("'");
+
+ list = getDataAccessService().getList(User.class, criteria.toString(), null, null);
+
+ return (list == null || list.size() == 0) ? null : (User)list.get(0);
+ }
+
+
+ public MenuBuilder getMenuBuilder() {
+ return new MenuBuilder();
+ }
+
+
+ public void setMenuBuilder(MenuBuilder menuBuilder) {
+ this.menuBuilder = menuBuilder;
+ }
+
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostDroolsService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostDroolsService.java
new file mode 100644
index 00000000..596ebed2
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostDroolsService.java
@@ -0,0 +1,34 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+
+import org.openecomp.portalsdk.core.command.PostDroolsBean;
+
+public interface PostDroolsService {
+
+ String execute(String droolsFile, String className, String selectedRules);
+
+ List<PostDroolsBean> fetchDroolBeans();
+
+ String retrieveClass(String droolsFile);
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostDroolsServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostDroolsServiceImpl.java
new file mode 100644
index 00000000..658de264
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostDroolsServiceImpl.java
@@ -0,0 +1,186 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.DirectoryIteratorException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.kie.api.io.ResourceType;
+import org.kie.internal.KnowledgeBase;
+import org.kie.internal.KnowledgeBaseFactory;
+import org.kie.internal.builder.KnowledgeBuilder;
+import org.kie.internal.builder.KnowledgeBuilderFactory;
+import org.kie.internal.definition.KnowledgePackage;
+import org.kie.internal.io.ResourceFactory;
+import org.kie.internal.runtime.StatefulKnowledgeSession;
+import org.openecomp.portalsdk.core.command.PostDroolsBean;
+import org.openecomp.portalsdk.core.drools.DroolsRuleService;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * TODO REFACTOR
+ *
+ */
+@Service("postDroolsService")
+@Transactional
+public class PostDroolsServiceImpl implements PostDroolsService{
+
+ static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PostDroolsServiceImpl.class);
+
+ @Override
+ public String execute(String droolsFile, String className, String selectedRules) {
+ logger.info(EELFLoggerDelegate.applicationLogger, "Executing Drools...");
+ String resultsString = executeDemoRules(droolsFile, className, selectedRules);
+ return resultsString;
+ }
+
+
+ public List<PostDroolsBean> fetchDroolBeans() {
+
+ List<PostDroolsBean> beanList = new ArrayList<PostDroolsBean>();
+ Path path = FileSystems.getDefault().getPath(SystemProperties.getProperty(SystemProperties.FILES_PATH));
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(path,"*.{drl}")) {
+ for (Path entry: stream) {
+
+ PostDroolsBean postDroolsBean = new PostDroolsBean();
+ String fileName = entry.getName(entry.getNameCount()-1).toString();
+ postDroolsBean.setDroolsFile(fileName);//sample populated
+ postDroolsBean.setClassName(retrieveClass(fileName));
+ //postDroolsBean.setSelectedRules("[\"NJ\",\"NY\",\"KY\"]");
+ beanList.add(postDroolsBean);
+ }
+ } catch (DirectoryIteratorException ex) {
+ logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage());
+ } catch (IOException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ }
+ return beanList;
+ }
+
+ @Override
+ public String retrieveClass(String fileName) {
+ String resultsString = "";
+ try {
+ // load up the knowledge base
+ final KnowledgeBuilder kbuilder = loadKBuilder(fileName);
+ final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
+ return pkgs.iterator().next().getFactTypes().iterator().next().getFactClass().getName();
+
+ } catch (Throwable t) {
+ logger.error(EELFLoggerDelegate.errorLogger, t.getMessage());
+ }
+
+ return resultsString;
+ }
+
+ protected static KnowledgeBuilder loadKBuilder(String fileName) {
+ final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ // this will parse and compile in one step
+ kbuilder.add(ResourceFactory.newFileResource(SystemProperties.getProperty(SystemProperties.FILES_PATH) + File.separator + fileName),
+ //kbuilder.add(ResourceFactory.newClassPathResource(SystemProperties.getProperty(SystemProperties.FILES_PATH) + File.separator + drl_file_path, DroolsRuleService.class),
+ ResourceType.DRL);
+ // kbuilder.add(ResourceFactory.newClassPathResource("rules.drl",DroolsRuleService.class),
+ // ResourceType.DRL);
+
+ // Check the builder for errors
+ if (kbuilder.hasErrors()) {
+
+ logger.error(EELFLoggerDelegate.errorLogger, kbuilder.getErrors().toString());
+
+ throw new RuntimeException("Unable to compile \".drl\".");
+
+ }
+ return kbuilder;
+ }
+
+
+ @SuppressWarnings({ "deprecation", "unchecked" })
+ public static String executeDemoRules(String fileName, String className, String ruleValue) {
+ String resultsString = "";
+ try {
+ // load up the knowledge base
+ // KieServices ks = KieServices.Factory.get();
+ // KieContainer kContainer = ks.getKieClasspathContainer();
+ // KieSession kSession = kContainer.newKieSession("ksession-rules");
+
+ final KnowledgeBuilder kbuilder = loadKBuilder(fileName);
+
+ // get the compiled packages (which are serializable)
+
+ final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
+
+ // add the packages to a knowledgebase (deploy the knowledge
+ // packages).
+
+ final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+
+ kbase.addKnowledgePackages(pkgs);
+
+ final StatefulKnowledgeSession kSession = kbase.newStatefulKnowledgeSession();
+
+ ObjectMapper mapper = new ObjectMapper();
+ if(ruleValue == null || ruleValue.equals("")) {
+ resultsString = "Please enter valid rule";
+ return resultsString;
+ }
+ List<String> selectedRules = mapper.readValue(ruleValue, List.class);
+ List<String> ruleResponse = new ArrayList<String>();
+
+ for(String rule : selectedRules){
+ Class<DroolsRuleService> clazz = (Class<DroolsRuleService>) Class.forName(className);
+ DroolsRuleService droolsIntroduction =clazz.newInstance();
+ droolsIntroduction.init(rule);
+ kSession.insert(droolsIntroduction);
+ kSession.fireAllRules();
+ ruleResponse.add(droolsIntroduction.getResultsString());
+ }
+
+ resultsString = mapper.writeValueAsString(ruleResponse);
+
+// kSession.insert(new DroolsRuleService("KY"));
+// kSession.fireAllRules();
+//
+// kSession.setGlobal("age", "25");
+// kSession.insert(new DroolsRuleService("NY"));
+// kSession.fireAllRules();
+ } catch (Throwable t) {
+ logger.error(EELFLoggerDelegate.errorLogger, t.getMessage());
+ }
+
+ return resultsString;
+ }
+
+
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostSearchService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostSearchService.java
new file mode 100644
index 00000000..cde9a370
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostSearchService.java
@@ -0,0 +1,37 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.openecomp.portalsdk.core.command.PostSearchBean;
+
+public interface PostSearchService {
+
+ /**
+ * Imports the selected users in the search results as new users.
+ *
+ * @param request
+ * @param postSearch
+ * @return the number of users successfully imported
+ */
+ int process(HttpServletRequest request, PostSearchBean postSearch);
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostSearchServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostSearchServiceImpl.java
new file mode 100644
index 00000000..f2877d4d
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/PostSearchServiceImpl.java
@@ -0,0 +1,207 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.openecomp.portalsdk.core.FusionObject.Parameters;
+import org.openecomp.portalsdk.core.command.PostSearchBean;
+import org.openecomp.portalsdk.core.domain.Lookup;
+import org.openecomp.portalsdk.core.domain.Role;
+import org.openecomp.portalsdk.core.domain.User;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("postSearchService")
+@Transactional
+public class PostSearchServiceImpl implements PostSearchService {
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PostSearchServiceImpl.class);
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public int process(HttpServletRequest request, PostSearchBean postSearch) {
+ HashMap additionalParams = new HashMap();
+ additionalParams.put(Parameters.PARAM_HTTP_REQUEST, request);
+ int numUsersImported = 0;
+
+ if (postSearch.getSelected() != null) {
+ // sort the selected users for quick validation
+
+ Arrays.sort(postSearch.getSelected());
+ // import the users that have been selected
+ for (int i = 0; i < postSearch.getPostOrgUserId().length; i++) {
+ if (Arrays.binarySearch(postSearch.getSelected(), postSearch.getPostOrgUserId()[i]) >= 0) {
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "Adding ORGUSERID - " + postSearch.getPostOrgUserId()[i]);
+ logger.debug(EELFLoggerDelegate.auditLogger,
+ "Import new user from webphone " + postSearch.getPostOrgUserId()[i]);
+
+ User user = new User();
+ user.setLastName(postSearch.getPostLastName()[i]);
+ user.setFirstName(postSearch.getPostFirstName()[i]);
+
+ if (postSearch.getPostHrid() != null && postSearch.getPostHrid().length > 0) {
+ user.setHrid(postSearch.getPostHrid()[i]);
+ }
+
+ if (postSearch.getPostPhone() != null && postSearch.getPostPhone().length > 0) {
+ user.setPhone(postSearch.getPostPhone()[i]);
+ }
+
+ if (postSearch.getPostEmail() != null && postSearch.getPostEmail().length > 0) {
+ user.setEmail(postSearch.getPostEmail()[i]);
+ }
+
+ if (postSearch.getPostOrgUserId() != null && postSearch.getPostOrgUserId().length > 0) {
+ user.setOrgUserId(postSearch.getPostOrgUserId()[i]);
+ user.setLoginId(postSearch.getPostOrgUserId()[i]);
+ }
+
+ if (postSearch.getPostAddress1() != null && postSearch.getPostAddress1().length > 0) {
+ user.setAddress1(postSearch.getPostAddress1()[i]);
+ }
+
+ if (postSearch.getPostAddress2() != null && postSearch.getPostAddress2().length > 0) {
+ user.setAddress2(postSearch.getPostAddress2()[i]);
+ }
+
+ if (postSearch.getPostCity() != null && postSearch.getPostCity().length > 0) {
+ user.setCity(postSearch.getPostCity()[i]);
+ }
+
+ if (postSearch.getPostState() != null && postSearch.getPostState().length > 0) {
+ user.setState(postSearch.getPostState()[i]);
+ }
+
+ if (postSearch.getPostZipCode() != null && postSearch.getPostZipCode().length > 0) {
+ user.setZipCode(postSearch.getPostZipCode()[i]);
+ }
+
+ if (postSearch.getPostLocationClli() != null && postSearch.getPostLocationClli().length > 0) {
+ user.setLocationClli(postSearch.getPostLocationClli()[i]);
+ }
+
+ if (postSearch.getPostBusinessCountryCode() != null
+ && postSearch.getPostBusinessCountryCode().length > 0) {
+ user.setBusinessCountryCode(postSearch.getPostBusinessCountryCode()[i]);
+ }
+
+ if (postSearch.getPostBusinessCountryName() != null
+ && postSearch.getPostBusinessCountryName().length > 0) {
+
+ // find the country cd for the indicated country
+ List countries = dataAccessService.getLookupList("fn_lu_country", "country_cd", "country",
+ "country = '" + postSearch.getPostBusinessCountryName()[i] + "'", null, null);
+
+ if (countries != null && countries.size() == 1) {
+ Lookup country = (Lookup) countries.get(0);
+ user.setCountry(country.getValue());
+ } else {
+ logger.info(EELFLoggerDelegate.debugLogger,
+ "No countries or more than one country was found matching the country returned from WEBPHONE. "
+ + "Therefore, no country was set for this user.");
+ }
+
+ }
+
+ if (postSearch.getPostDepartment() != null && postSearch.getPostDepartment().length > 0) {
+ user.setDepartment(postSearch.getPostDepartment()[i]);
+ }
+
+ if (postSearch.getPostDepartmentName() != null && postSearch.getPostDepartmentName().length > 0) {
+ user.setDepartmentName(postSearch.getPostDepartmentName()[i]);
+ }
+
+ if (postSearch.getPostBusinessUnit() != null && postSearch.getPostBusinessUnit().length > 0) {
+ user.setBusinessUnit(postSearch.getPostBusinessUnit()[i]);
+ }
+
+ if (postSearch.getPostBusinessUnitName() != null
+ && postSearch.getPostBusinessUnitName().length > 0) {
+ user.setBusinessUnitName(postSearch.getPostBusinessUnitName()[i]);
+ }
+
+ if (postSearch.getPostJobTitle() != null && postSearch.getPostJobTitle().length > 0) {
+ user.setJobTitle(postSearch.getPostJobTitle()[i]);
+ }
+
+ if (postSearch.getPostOrgManagerUserId() != null
+ && postSearch.getPostOrgManagerUserId().length > 0) {
+ user.setOrgManagerUserId(postSearch.getPostOrgManagerUserId()[i]);
+ }
+
+ if (postSearch.getPostCommandChain() != null && postSearch.getPostCommandChain().length > 0) {
+ user.setCommandChain(postSearch.getPostCommandChain()[i]);
+ }
+
+ if (postSearch.getPostCompanyCode() != null && postSearch.getPostCompanyCode().length > 0) {
+ user.setCompanyCode(postSearch.getPostCompanyCode()[i]);
+ }
+
+ if (postSearch.getPostCompany() != null && postSearch.getPostCompany().length > 0) {
+ user.setCompany(postSearch.getPostCompany()[i]);
+ }
+
+ if (postSearch.getPostCostCenter() != null && postSearch.getPostCostCenter().length > 0) {
+ user.setCostCenter(postSearch.getPostCostCenter()[i]);
+ }
+
+ if (postSearch.getPostSiloStatus() != null && postSearch.getPostSiloStatus().length > 0) {
+ user.setSiloStatus(postSearch.getPostSiloStatus()[i]);
+ }
+
+ if (postSearch.getPostFinancialLocCode() != null
+ && postSearch.getPostFinancialLocCode().length > 0) {
+ user.setFinancialLocCode(postSearch.getPostFinancialLocCode()[i]);
+ }
+
+ user.setActive(true);
+
+ try {
+ dataAccessService.saveDomainObject(user, additionalParams);
+ Role role = (Role) dataAccessService.getDomainObject(Role.class,
+ Long.valueOf(SystemProperties.getProperty(SystemProperties.POST_DEFAULT_ROLE_ID)),
+ null);
+ user.addRole(role);
+ numUsersImported++;
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "process: saveDomainObject failed on user " + user.getLoginId(), e);
+ }
+ }
+ }
+
+ }
+
+ return numUsersImported;
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java
new file mode 100644
index 00000000..61bd3b6e
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java
@@ -0,0 +1,36 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+
+import org.openecomp.portalsdk.core.domain.Profile;
+import org.openecomp.portalsdk.core.domain.User;
+
+
+public interface ProfileService {
+ List<Profile> findAll();
+
+ Profile getProfile(int id);
+
+ User getUser(String id);
+
+ void saveUser(User user);
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java
new file mode 100644
index 00000000..2d6fcfee
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java
@@ -0,0 +1,74 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+
+import org.openecomp.portalsdk.core.dao.ProfileDao;
+import org.openecomp.portalsdk.core.domain.Profile;
+import org.openecomp.portalsdk.core.domain.User;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("profileService")
+@Transactional
+public class ProfileServiceImpl implements ProfileService{
+
+ @Autowired
+ private ProfileDao profileDao;
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @SuppressWarnings("unchecked")
+ public List<Profile> findAll() {
+ //List msgDB = getDataAccessService().getList(Profile.class, null);
+ return getDataAccessService().getList(Profile.class, null);
+ }
+
+ public User getUser(String userId){
+ return (User) getDataAccessService().getDomainObject(User.class, Long.parseLong(userId), null);
+ }
+
+ public void saveUser(User user){
+
+ getDataAccessService().saveDomainObject(user, null);
+ }
+
+
+ public Profile getProfile(int id) {
+ return profileDao.getProfile(id);
+ }
+
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java
new file mode 100644
index 00000000..01367ecd
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java
@@ -0,0 +1,50 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+
+import org.openecomp.portalsdk.core.domain.Role;
+import org.openecomp.portalsdk.core.domain.RoleFunction;
+
+
+public interface RoleService {
+ List<RoleFunction> getRoleFunctions();
+
+ List<Role> getAvailableChildRoles(Long roleId);
+
+ Role getRole(Long id);
+
+ void saveRole(Role domainRole);
+
+ void deleteRole(Role domainRole);
+
+ List<Role> getAvailableRoles();
+
+ List<Role> getActiveRoles();
+
+ RoleFunction getRoleFunction(String code);
+
+ void saveRoleFunction(RoleFunction domainRoleFunction);
+
+ void deleteRoleFunction(RoleFunction domainRoleFunction);
+
+ void deleteDependcyRoleRecord(Long id);
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java
new file mode 100644
index 00000000..2e780998
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java
@@ -0,0 +1,171 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.sql.DataSource;
+
+import org.openecomp.portalsdk.core.domain.Role;
+import org.openecomp.portalsdk.core.domain.RoleFunction;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("roleService")
+@Transactional
+public class RoleServiceImpl implements RoleService {
+
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleServiceImpl.class);
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ DataSource dataSource;
+
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
+ @Autowired
+ public void setDataSource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<RoleFunction> getRoleFunctions() {
+ // List msgDB = getDataAccessService().getList(Profile.class, null);
+ return getDataAccessService().getList(RoleFunction.class, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Role> getAvailableChildRoles(Long roleId) {
+ List<Role> availableChildRoles = (List<Role>) getDataAccessService().getList(Role.class, null);
+ if (roleId == null || roleId == 0) {
+ return availableChildRoles;
+ }
+
+ Role currentRole = (Role) getDataAccessService().getDomainObject(Role.class, roleId, null);
+ Set<Role> allParentRoles = new TreeSet<Role>();
+ allParentRoles = getAllParentRolesAsList(currentRole, allParentRoles);
+
+ Iterator<Role> availableChildRolesIterator = availableChildRoles.iterator();
+ while (availableChildRolesIterator.hasNext()) {
+ Role role = availableChildRolesIterator.next();
+ if (!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) {
+ availableChildRolesIterator.remove();
+ }
+ }
+ return availableChildRoles;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Set<Role> getAllParentRolesAsList(Role role, Set<Role> allParentRoles) {
+ Set<Role> parentRoles = role.getParentRoles();
+ allParentRoles.addAll(parentRoles);
+ Iterator<Role> parentRolesIterator = parentRoles.iterator();
+ while (parentRolesIterator.hasNext()) {
+ getAllParentRolesAsList(parentRolesIterator.next(), allParentRoles);
+ }
+ return allParentRoles;
+ }
+
+ public RoleFunction getRoleFunction(String code) {
+ return (RoleFunction) getDataAccessService().getDomainObject(RoleFunction.class, code, null);
+ }
+
+ public void saveRoleFunction(RoleFunction domainRoleFunction) {
+ getDataAccessService().saveDomainObject(domainRoleFunction, null);
+ }
+
+ public void deleteRoleFunction(RoleFunction domainRoleFunction) {
+ getDataAccessService().deleteDomainObject(domainRoleFunction, null);
+ }
+
+ public Role getRole(Long id) {
+ return (Role) getDataAccessService().getDomainObject(Role.class, id, null);
+ }
+
+ public void saveRole(Role domainRole) {
+ getDataAccessService().saveDomainObject(domainRole, null);
+ }
+
+ public void deleteRole(Role domainRole) {
+ getDataAccessService().deleteDomainObject(domainRole, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Role> getAvailableRoles() {
+ return getDataAccessService().getList(Role.class, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<Role> getActiveRoles() {
+ String filter = " where active_yn = 'Y' ";
+ return getDataAccessService().getList(Role.class, filter, null, null);
+ }
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+ @Override
+ public void deleteDependcyRoleRecord(Long id) {
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ conn = getDataSource().getConnection();
+ stmt = conn.createStatement();
+ String sql = "delete from fn_user_role where role_id = '" + id + "'";
+ stmt.executeUpdate(sql);
+ stmt.close();
+ conn.close();
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "deleteDependcyRoleRecord failed", e);
+ } finally {
+ try {
+ if (stmt != null)
+ stmt.close();
+ } catch (SQLException se2) {
+ logger.error(EELFLoggerDelegate.errorLogger, "deleteDependcyRoleRecord failed", se2);
+ }
+ try {
+ if (conn != null)
+ conn.close();
+ } catch (SQLException se) {
+ logger.error(EELFLoggerDelegate.errorLogger, "deleteDependcyRoleRecord failed", se);
+ }
+ }
+
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceNonSpringImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceNonSpringImpl.java
new file mode 100644
index 00000000..a7374d0c
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceNonSpringImpl.java
@@ -0,0 +1,122 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+/*package org.openecomp.portalsdk.core.service;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import org.openecomp.portalsdk.core.domain.Role;
+import org.openecomp.portalsdk.core.domain.RoleFunction;
+
+@Service("roleService")
+@Transactional
+public class RoleServiceNonSpringImpl implements RoleService{
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @SuppressWarnings("unchecked")
+ public List<RoleFunction> getRoleFunctions() {
+ //List msgDB = getDataAccessService().getList(Profile.class, null);
+ return getDataAccessService().getList(RoleFunction.class, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Role> getAvailableChildRoles(Long roleId) {
+ List<Role> availableChildRoles = (List<Role>)getDataAccessService().getList(Role.class,null);
+ if(roleId==null || roleId==0){
+ return availableChildRoles;
+ }
+
+ Role currentRole = (Role)getDataAccessService().getDomainObject(Role.class,roleId,null);
+ Set<Role> allParentRoles = new TreeSet<Role>();
+ allParentRoles = getAllParentRolesAsList(currentRole, allParentRoles);
+
+
+ Iterator<Role> availableChildRolesIterator = availableChildRoles.iterator();
+ while (availableChildRolesIterator.hasNext()) {
+ Role role = availableChildRolesIterator.next();
+ if(!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)){
+ availableChildRolesIterator.remove();
+ }
+ }
+ return availableChildRoles;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Set<Role> getAllParentRolesAsList(Role role, Set<Role> allParentRoles) {
+ Set<Role> parentRoles = role.getParentRoles();
+ allParentRoles.addAll(parentRoles);
+ Iterator<Role> parentRolesIterator = parentRoles.iterator();
+ while (parentRolesIterator.hasNext()) {
+ getAllParentRolesAsList(parentRolesIterator.next(),allParentRoles);
+ }
+ return allParentRoles;
+ }
+
+ public RoleFunction getRoleFunction(String code) {
+ return (RoleFunction)getDataAccessService().getDomainObject(RoleFunction.class, code, null);
+ }
+
+ public void saveRoleFunction(RoleFunction domainRoleFunction) {
+ getDataAccessService().saveDomainObject(domainRoleFunction, null);
+ }
+
+ public void deleteRoleFunction(RoleFunction domainRoleFunction) {
+ getDataAccessService().deleteDomainObject(domainRoleFunction, null);
+ }
+
+ public Role getRole(Long id) {
+ return (Role)getDataAccessService().getDomainObject(Role.class, id, null);
+ }
+
+ public void saveRole(Role domainRole) {
+ getDataAccessService().saveDomainObject(domainRole, null);
+ }
+
+ public void deleteRole(Role domainRole) {
+ getDataAccessService().deleteDomainObject(domainRole, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Role> getAvailableRoles() {
+ return getDataAccessService().getList(Role.class, null);
+ }
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+
+
+}
+*/ \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileService.java
new file mode 100644
index 00000000..b844fb0c
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileService.java
@@ -0,0 +1,34 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+
+import org.openecomp.portalsdk.core.domain.User;
+
+
+public interface UserProfileService {
+ List<User> findAll();
+ User getUser(String id);
+ User getUserByLoginId(String loginId);
+ void saveUser(User user);
+ public List<User> findAllUserWithOnOffline(String originOrgUserId);
+ List<User> findAllActive();
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java
new file mode 100644
index 00000000..2d134725
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java
@@ -0,0 +1,116 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.SortedSet;
+
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+import org.openecomp.portalsdk.core.domain.Role;
+import org.openecomp.portalsdk.core.domain.User;
+import org.openecomp.portalsdk.core.domain.support.CollaborateList;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("userProfileService")
+@Transactional
+public class UserProfileServiceImpl implements UserProfileService{
+
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ public List<User> findAll() {
+ return getDataAccessService().getList(User.class, null);
+ }
+
+ public User getUser(String userId){
+ return (User) getDataAccessService().getDomainObject(User.class, Long.parseLong(userId), null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public User getUserByLoginId(String loginId){
+ User user=null;
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion criterion1= Restrictions.eq("loginId",loginId);
+ restrictionsList.add(criterion1);
+ List<User> users = (List<User>) getDataAccessService().getList(User.class,null, restrictionsList, null);
+ if(users!=null && users.size()==1)
+ user = users.get(0);
+ return user;
+ }
+
+ public void saveUser(User user){
+
+ getDataAccessService().saveDomainObject(user, null);
+ }
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<User> findAllUserWithOnOffline(String originOrgUserId) {
+ HashSet<String> onlineUser = CollaborateList.getInstance().getAllUserName();
+ List<User> users = getDataAccessService().getList(User.class, null);
+ for(User u:users){
+ if(onlineUser.contains(u.getOrgUserId()))
+ u.setOnline(true);
+ if(u.getOrgUserId()!=null){
+ if(originOrgUserId.compareTo(u.getOrgUserId()) > 0) {
+ u.setChatId(originOrgUserId + "-" + u.getOrgUserId());
+ } else u.setChatId(u.getOrgUserId() + "-" + originOrgUserId );
+ }
+ }
+ return users;
+
+ }
+
+ public List<User> findAllActive() {
+ List<User> users = getDataAccessService().getList(User.class, null);
+ Iterator<User> itr = users.iterator();
+ while(itr.hasNext()){
+ User u = (User) itr.next();
+ if(!u.getActive())
+ itr.remove();//if not active remove user from list
+ else {
+ SortedSet<Role> roles = u.getRoles();
+ Iterator<Role> itrRoles = roles.iterator();
+ while(itrRoles.hasNext()){
+ Role role = (Role) itrRoles.next();
+ if(!role.getActive())
+ u.removeRole(role.getId());//if not active remove role from list
+ }
+ }
+ }
+ return users;
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/WebServiceCallService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/WebServiceCallService.java
new file mode 100644
index 00000000..a7a5ad07
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/WebServiceCallService.java
@@ -0,0 +1,26 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+
+public interface WebServiceCallService {
+ public boolean verifyRESTCredential(String secretKey, String requestAppName, String requestPassword)throws Exception;
+ /*public String get(String restURL, String restPath);*/
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/WebServiceCallServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/WebServiceCallServiceImpl.java
new file mode 100644
index 00000000..557af2dd
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/WebServiceCallServiceImpl.java
@@ -0,0 +1,189 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service;
+
+import java.util.List;
+
+import org.openecomp.portalsdk.core.domain.App;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("webServiceCallService")
+@Transactional
+public class WebServiceCallServiceImpl implements WebServiceCallService{
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @Autowired
+ AppService appService;
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WebServiceCallServiceImpl.class);
+
+ /**
+ * Verify REST Credential
+ * @return true if the credential is accepted; else false.
+ */
+ @Override
+ public boolean verifyRESTCredential(String secretKey, String requestAppName, String requestPassword)throws Exception {
+ App app = appService.getDefaultApp();
+ if (app!=null) {
+ String encriptedPwdDB = app.getAppPassword();
+ String appUserName = app.getUsername();
+ String decreptedPwd = CipherUtil.decrypt(encriptedPwdDB, secretKey==null?SystemProperties.getProperty(SystemProperties.Decryption_Key):secretKey);
+ if(decreptedPwd.equals(requestPassword) && appUserName.equals(requestAppName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Getting App information from FN_APP table
+ * @return App domain object, or null if not found.
+ */
+ public App findApp(){
+ List<?> list = null;
+ StringBuffer criteria = new StringBuffer();
+ criteria.append(" where id = 1");
+ list = getDataAccessService().getList(App.class, criteria.toString(), null, null);
+ return (list == null || list.size() == 0) ? null : (App) list.get(0);
+ }
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
+
+ /*/
+ @Override
+ public String get(String restURL, String restPath) {
+ String appUserName = "";
+ String appUebKey = "";
+ String decreptedPwd = "";
+ String appName = "";
+ String inputLine = "";
+ String serviceName = "";
+ String loginId = "";
+ StringBuffer jsonResponse = new StringBuffer();
+
+ StopWatch stopWatch = new StopWatch("WebServiceCallServiceImpl.get");
+ stopWatch.start();
+ try {
+ logger.info(EELFLoggerDelegate.metricsLogger, "WebServiceCallServiceImpl.get (" + restPath + ") operation is started.");
+ logger.debug(EELFLoggerDelegate.debugLogger, "WebServiceCallServiceImpl.get (" + restPath + ") operation is started.");
+ loginId = MDC.get("LoginId");
+ appUebKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY);
+ App app = appService.getDefaultApp();
+ if (app!=null) {
+ appName = app.getName();
+ appUserName = app.getUsername();
+ try{
+ decreptedPwd = CipherUtil.decrypt(app.getAppPassword(), SystemProperties.getProperty(SystemProperties.Decryption_Key));
+ } catch(Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred in WebServiceCallServiceImpl.get while decrypting the password. Details: " + e.getMessage());
+ }
+ } else {
+ logger.warn(EELFLoggerDelegate.errorLogger, "Unable to locate the app information from the database.");
+ appName = SystemProperties.SERVICE_NAME;
+ }
+
+ //Create the connection object
+ URL obj = new URL(restURL + restPath);
+ HttpURLConnection con = (HttpURLConnection) obj.openConnection();
+ con.setRequestMethod("GET");
+ con.setConnectTimeout(3000);
+ con.setReadTimeout(8000);
+
+ //add request header
+ con.setRequestProperty("username", appUserName);
+ con.setRequestProperty("password", decreptedPwd);
+ con.setRequestProperty("uebkey", appUebKey);
+ con.setRequestProperty(SystemProperties.LOGIN_ID, loginId);
+ con.setRequestProperty(SystemProperties.USERAGENT_NAME, appName);
+ con.setRequestProperty(SystemProperties.ECOMP_REQUEST_ID, MDC.get(MDC_KEY_REQUEST_ID));
+
+ //set MDC context for outgoing audit logging
+ serviceName = String.format("%s:%s.%s", appName, SystemProperties.ECOMP_PORTAL_BE, restPath);
+ MDC.put(Configuration.MDC_SERVICE_NAME, serviceName);
+ MDC.put(Configuration.MDC_REMOTE_HOST, restURL);
+ MDC.put(SystemProperties.MDC_APPNAME, appName);
+ MDC.put(SystemProperties.MDC_REST_PATH, restPath);
+ MDC.put(SystemProperties.MDC_REST_METHOD, "GET");
+
+ int responseCode = con.getResponseCode();
+ logger.info(EELFLoggerDelegate.errorLogger, "Received the response code '" + responseCode + "' while getting the '" + restPath + "' for user: " + loginId);
+
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(con.getInputStream()));
+
+ while ((inputLine = in.readLine()) != null) {
+ jsonResponse.append(inputLine);
+ }
+ in.close();
+
+ logSecurityMessage(RESULT_ENUM.SUCCESS);
+ logger.debug(EELFLoggerDelegate.debugLogger, restPath + " response: " + jsonResponse.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, "WebServiceCallServiceImpl.get (" + restPath + ") operation is started.");
+ } catch(UrlAccessRestrictedException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Authentication exception occurred in WebServiceCallServiceImpl.get (" + restPath + "). Details: " + e.getMessage());
+ logSecurityMessage(RESULT_ENUM.FAILURE);
+ } catch(Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred in WebServiceCallServiceImpl.get (" + restPath + "). Details: " + e.getMessage());
+ logSecurityMessage(RESULT_ENUM.FAILURE);
+ } finally {
+ if (stopWatch.isRunning()) stopWatch.stop();
+ MDC.put(SystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms");
+ logger.info(EELFLoggerDelegate.metricsLogger, "WebServiceCallServiceImpl.get (" + restPath + ") operation is completed.");
+
+ //clear the temporary MDC context values
+ MDC.remove(SystemProperties.MDC_TIMER);
+ MDC.remove(SystemProperties.MDC_REST_METHOD);
+ MDC.remove(SystemProperties.MDC_REST_PATH);
+ MDC.remove(SystemProperties.MDC_APPNAME);
+ MDC.remove(Configuration.MDC_REMOTE_HOST);
+ MDC.remove(Configuration.MDC_SERVICE_NAME);
+ }
+
+ return jsonResponse.toString();
+ }
+
+ //Handles all the outgoing rest/ueb messages.
+ public void logSecurityMessage(RESULT_ENUM isSuccess) {
+ String additionalInfo = "";
+ String protocol = "HTTP";
+ String loginId = MDC.get("LoginId");
+ additionalInfo = String.format("Rest API=%s, Rest Method=%s, App-Name=%s, Request-URL=%s",
+ MDC.get(SystemProperties.MDC_REST_PATH), MDC.get(SystemProperties.MDC_REST_METHOD),
+ MDC.get(SystemProperties.MDC_APPNAME), MDC.get(Configuration.MDC_REMOTE_HOST));
+
+ logger.info(EELFLoggerDelegate.auditLogger, AuditLogFormatter.getInstance().createMessage(
+ protocol, SecurityEventTypeEnum.OUTGOING_REST_MESSAGE.name(), loginId, SystemProperties.SERVICE_NAME,
+ isSuccess.name(), additionalInfo));
+ }
+ /**/
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/FusionService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/FusionService.java
new file mode 100644
index 00000000..34649ee1
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/FusionService.java
@@ -0,0 +1,27 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service.support;
+
+
+import org.openecomp.portalsdk.core.FusionObject;
+
+public class FusionService implements FusionObject {
+ /** Logger for this class and subclasses */
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/ServiceLocator.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/ServiceLocator.java
new file mode 100644
index 00000000..5858c3fa
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/ServiceLocator.java
@@ -0,0 +1,27 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service.support;
+
+import javax.naming.directory.DirContext;
+
+
+public interface ServiceLocator {
+ DirContext getDirContext(String initialContextFactory, String providerUrl, String securityPrincipal);
+}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/ServiceLocatorImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/ServiceLocatorImpl.java
new file mode 100644
index 00000000..97f4875d
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/support/ServiceLocatorImpl.java
@@ -0,0 +1,105 @@
+/*-
+ * ================================================================================
+ * eCOMP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+package org.openecomp.portalsdk.core.service.support;
+
+import java.util.*;
+
+import javax.naming.*;
+import javax.naming.directory.*;
+import javax.naming.ldap.*;
+
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.stereotype.Service;
+
+/**
+ * This class implements the J2EE service locator pattern. It provides lookup
+ * facilities for various services. Currenttly LDAP (pre-v3) is supported
+ */
+@Service("serviceLocator")
+public class ServiceLocatorImpl implements ServiceLocator {
+
+ //private static ServiceLocator locator; // The singleton instance
+
+ private Context context; // JNDI context (not currently in use)
+ private Context rootContext; // Java env root context (not currently in use)
+ private DirContext dirContext; // LDAP DIR context
+ private InitialLdapContext ldapContext; // LDAP context LDAPv3-style (not currently in use)
+
+
+ // cannot directly instantiate
+ public ServiceLocatorImpl() {}
+
+ /*public static ServiceLocator getLocator() {
+ if (locator == null)
+ locator = new ServiceLocator();
+ return locator;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException();
+ }*/
+
+
+ // Get an LDAP directory context
+ public DirContext getDirContext(String initialContextFactory, String providerUrl, String securityPrincipal) {
+
+ if (dirContext == null) {
+
+ Properties properties = new Properties();
+ properties.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
+ properties.put(Context.PROVIDER_URL, providerUrl);
+ properties.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
+
+ try {
+ dirContext = new InitialDirContext(properties);
+ }
+ catch (NamingException ne) {
+ logger.error(EELFLoggerDelegate.errorLogger, "An error has occurred while creating an Initial Directory Context: " + ne.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger, "Explanation: " + ne.getExplanation());
+ }
+ }
+
+ return dirContext;
+ }
+
+ // Get an LDAP directory context - LDAPv3-style
+ /*public InitialLdapContext getLdapContext() { //throws NamingException {
+ if (ldapContext == null) {
+ Properties properties = new Properties();
+ // @todo - need to parameterize context factoy class and url
+ properties.put(Context.INITIAL_CONTEXT_FACTORY, AttLdap.DIR_INITIAL_CONTEXT_FACTORY);
+ properties.put(Context.PROVIDER_URL, AttLdap.DIR_PROVIDER_URL);
+ properties.put(Context.SECURITY_PRINCIPAL, AttLdap.DIR_SECURITY_PRINCIPAL);
+ Control[] ctrl = null;
+ try {
+ ldapContext = new InitialLdapContext(properties, ctrl);
+ }
+ catch (NamingException ne) {
+ // MJ FIX log exception?
+ }
+ }
+ return ldapContext;
+ }*/
+
+
+ /** Logger for this class and subclasses */
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ServiceLocatorImpl.class);
+
+}