diff options
Diffstat (limited to 'ecomp-sdk')
7 files changed, 209 insertions, 46 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/dao/hibernate/ModelOperationsCommon.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/dao/hibernate/ModelOperationsCommon.java index 139128b4..596646f9 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/dao/hibernate/ModelOperationsCommon.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/dao/hibernate/ModelOperationsCommon.java @@ -59,6 +59,7 @@ import org.onap.portalsdk.core.dao.support.FusionDao; import org.onap.portalsdk.core.domain.Lookup; import org.onap.portalsdk.core.domain.support.DomainVo; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.NamedQueryBuilder; import org.onap.portalsdk.core.util.SystemProperties; public abstract class ModelOperationsCommon extends FusionDao { @@ -343,22 +344,21 @@ public abstract class ModelOperationsCommon extends FusionDao { } @SuppressWarnings("rawtypes") - protected final List _executeNamedQueryWithOrderBy(Class entity, String queryName, String whereClause, Map params, - String _orderBy, boolean asc, Integer fromIndex, Integer toIndex) { + protected final List _executeNamedQueryWithOrderBy(NamedQueryBuilder namedQuery) { Session session = getSessionFactory().getCurrentSession(); - Query query = session.getNamedQuery(queryName); - bindQueryParameters(query, params); + Query query = session.getNamedQuery(namedQuery.getQueryName()); + bindQueryParameters(query, namedQuery.getParams()); String queryStr = query.getQueryString(); - queryStr = String.format(queryStr, _orderBy, asc ? "ASC" : "DESC"); + queryStr = String.format(queryStr, namedQuery.get_orderBy(), namedQuery.isAsc() ? "ASC" : "DESC"); StringBuilder modifiedSql = new StringBuilder(" select * from (" + queryStr + " ) al "); - if (whereClause != null && whereClause.length() > 0) - modifiedSql.append("where " + whereClause); + if (namedQuery.getWhereClause() != null && namedQuery.getWhereClause().length() > 0) + modifiedSql.append("where " + namedQuery.getWhereClause()); SQLQuery sqlQuery = session.createSQLQuery(modifiedSql.toString()); - bindQueryParameters(sqlQuery, params); - sqlQuery.addEntity("reportSearch", entity); - if (fromIndex != null && toIndex != null) { - sqlQuery.setFirstResult(fromIndex.intValue()); - int pageSize = (toIndex.intValue() - fromIndex.intValue()) + 1; + bindQueryParameters(sqlQuery, namedQuery.getParams()); + sqlQuery.addEntity("reportSearch", namedQuery.getEntity()); + if (namedQuery.getFromIndex() != null && namedQuery.getToIndex() != null) { + sqlQuery.setFirstResult(namedQuery.getFromIndex().intValue()); + int pageSize = (namedQuery.getToIndex().intValue() - namedQuery.getFromIndex().intValue()) + 1; sqlQuery.setMaxResults(pageSize); } return sqlQuery.list(); diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/ElementMapService.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/ElementMapService.java index f8a547db..210e494d 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/ElementMapService.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/ElementMapService.java @@ -49,11 +49,7 @@ import java.util.TreeSet; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; -import org.onap.portalsdk.core.domain.support.Container; -import org.onap.portalsdk.core.domain.support.Domain; -import org.onap.portalsdk.core.domain.support.Element; -import org.onap.portalsdk.core.domain.support.ElementDetails; -import org.onap.portalsdk.core.domain.support.Layout; +import org.onap.portalsdk.core.domain.support.*; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.core.util.YamlUtils; @@ -734,9 +730,7 @@ public class ElementMapService { String bgColor = elementDetails.get("background_color") == null ? "bgColor" : elementDetails.get("background_color"); - ElementDetails details = new ElementDetails(logical_group, display_longname, description, - primary_function, network_function, key_interfaces, location, vendor, - vendor_shortname, enclosingContainer); + ElementDetails details = new ElementDetails.ElementDetailsBuilder().setLogical_group(logical_group).setDisplay_longname(display_longname).setDescription(description).setPrimary_function(primary_function).setNetwork_function(network_function).setKey_interfaces(key_interfaces).setLocation(location).setVendor(vendor).setVendor_shortname(vendor_shortname).setEnclosingContainer(enclosingContainer).createElementDetails(); return new Element(name, display_shortname, imgPath, bgColor, borderType, details); } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/NamedQueryBuilder.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/NamedQueryBuilder.java new file mode 100644 index 00000000..57623ef5 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/NamedQueryBuilder.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.portalsdk.core.util; + +import java.util.Map; + +public class NamedQueryBuilder { + public Class getEntity() { + return entity; + } + + public NamedQueryBuilder setEntity(Class entity) { + this.entity = entity; + return this; + } + + public String getQueryName() { + return queryName; + } + + public NamedQueryBuilder setQueryName(String queryName) { + this.queryName = queryName; + return this; + } + + public String getWhereClause() { + return whereClause; + } + + public NamedQueryBuilder setWhereClause(String whereClause) { + this.whereClause = whereClause; + return this; + } + + public Map getParams() { + return params; + } + + public NamedQueryBuilder setParams(Map params) { + this.params = params; + return this; + } + + public String get_orderBy() { + return _orderBy; + } + + public NamedQueryBuilder set_orderBy(String _orderBy) { + this._orderBy = _orderBy; + return this; + } + + public boolean isAsc() { + return asc; + } + + public NamedQueryBuilder setAsc(boolean asc) { + this.asc = asc; + return this; + } + + public Integer getFromIndex() { + return fromIndex; + } + + public NamedQueryBuilder setFromIndex(Integer fromIndex) { + this.fromIndex = fromIndex; + return this; + } + + public Integer getToIndex() { + return toIndex; + } + + public NamedQueryBuilder setToIndex(Integer toIndex) { + this.toIndex = toIndex; + return this; + } + + private Class entity; + private String queryName; + private String whereClause; + private Map params; + private String _orderBy; + boolean asc; + private Integer fromIndex; + private Integer toIndex; +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementMapServiceTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementMapServiceTest.java index 8a4639b1..f0e4304c 100644 --- a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementMapServiceTest.java +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementMapServiceTest.java @@ -52,12 +52,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.onap.portalsdk.core.domain.support.Container; -import org.onap.portalsdk.core.domain.support.Domain; -import org.onap.portalsdk.core.domain.support.Element; -import org.onap.portalsdk.core.domain.support.ElementDetails; -import org.onap.portalsdk.core.domain.support.Layout; -import org.onap.portalsdk.core.domain.support.Position; +import org.onap.portalsdk.core.domain.support.*; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.core.util.YamlUtils; import org.powermock.api.mockito.PowerMockito; @@ -242,7 +237,7 @@ public class ElementMapServiceTest { String domain = "Test Domain"; String name = "Test Container"; - ElementDetails elementDetails = new ElementDetails(logicalName,"test","test","test","test","test","test","test","test","test"); + ElementDetails elementDetails = new ElementDetails.ElementDetailsBuilder().setLogical_group(logicalName).setDisplay_longname("test").setDescription("test").setPrimary_function("test").setNetwork_function("test").setKey_interfaces("test").setLocation("test").setVendor("test").setVendor_shortname("test").setEnclosingContainer("test").createElementDetails(); element.setDetails(elementDetails); Field field = elementMapService.getClass().getDeclaredField("elementMap"); @@ -287,7 +282,7 @@ public class ElementMapServiceTest { String domain = "Test Domain"; String name = "Test Container"; - ElementDetails elementDetails = new ElementDetails(logicalName,"test","test","test","test","test","test","test","test","test"); + ElementDetails elementDetails = new ElementDetails.ElementDetailsBuilder().setLogical_group(logicalName).setDisplay_longname("test").setDescription("test").setPrimary_function("test").setNetwork_function("test").setKey_interfaces("test").setLocation("test").setVendor("test").setVendor_shortname("test").setEnclosingContainer("test").createElementDetails(); element.setDetails(elementDetails); Field field = elementMapService.getClass().getDeclaredField("elementMap"); diff --git a/ecomp-sdk/epsdk-domain/src/main/java/org/onap/portalsdk/core/domain/support/ElementDetails.java b/ecomp-sdk/epsdk-domain/src/main/java/org/onap/portalsdk/core/domain/support/ElementDetails.java index 61fc6497..7d8de316 100644 --- a/ecomp-sdk/epsdk-domain/src/main/java/org/onap/portalsdk/core/domain/support/ElementDetails.java +++ b/ecomp-sdk/epsdk-domain/src/main/java/org/onap/portalsdk/core/domain/support/ElementDetails.java @@ -49,21 +49,91 @@ public class ElementDetails { String vendor; String vendor_shortname; String enclosingContainer; + + + public static class ElementDetailsBuilder{ + private String logical_group; + private String display_longname; + private String description; + private String primary_function; + private String network_function; + private String key_interfaces; + private String location; + private String vendor; + private String vendor_shortname; + private String enclosingContainer; + - public ElementDetails(String logical_group, String display_longname, String description, String primary_function, - String network_function, String key_interfaces, String location, String vendor, String vendor_shortname, - String enclosingContainer) { + public ElementDetailsBuilder setLogical_group(String logical_group) { + this.logical_group = logical_group; + return this; + } - this.logical_group = logical_group; - this.display_longname = display_longname; - this.description = description; - this.primary_function = primary_function; - this.network_function = network_function; - this.key_interfaces = key_interfaces; - this.location = location; - this.vendor = vendor; - this.vendor_shortname = vendor_shortname; - this.enclosingContainer = enclosingContainer; + public ElementDetailsBuilder setDisplay_longname(String display_longname) { + this.display_longname = display_longname; + return this; + } + + public ElementDetailsBuilder setDescription(String description) { + this.description = description; + return this; + } + + public ElementDetailsBuilder setPrimary_function(String primary_function) { + this.primary_function = primary_function; + return this; + } + + public ElementDetailsBuilder setNetwork_function(String network_function) { + this.network_function = network_function; + return this; + } + + public ElementDetailsBuilder setKey_interfaces(String key_interfaces) { + this.key_interfaces = key_interfaces; + return this; + } + + public ElementDetailsBuilder setLocation(String location) { + this.location = location; + return this; + } + + public ElementDetailsBuilder setVendor(String vendor) { + this.vendor = vendor; + return this; + } + + public ElementDetailsBuilder setVendor_shortname(String vendor_shortname) { + this.vendor_shortname = vendor_shortname; + return this; + } + + public ElementDetailsBuilder setEnclosingContainer(String enclosingContainer) { + this.enclosingContainer = enclosingContainer; + return this; + } + + public ElementDetails createElementDetails() { + + return new ElementDetails(this); + } + + } + + + private ElementDetails(ElementDetailsBuilder builder){ + + logical_group = builder.logical_group; + display_longname = builder.display_longname; + description = builder.description; + primary_function = builder.primary_function; + network_function = builder.network_function; + key_interfaces = builder.key_interfaces; + location = builder.location; + vendor = builder.vendor; + vendor_shortname = builder.vendor_shortname; + enclosingContainer = builder.enclosingContainer; } public String getLogical_group() { diff --git a/ecomp-sdk/epsdk-domain/src/test/java/org/onap/portalsdk/core/domain/support/ElementDetailsTest.java b/ecomp-sdk/epsdk-domain/src/test/java/org/onap/portalsdk/core/domain/support/ElementDetailsTest.java index d6b9c11b..62149054 100644 --- a/ecomp-sdk/epsdk-domain/src/test/java/org/onap/portalsdk/core/domain/support/ElementDetailsTest.java +++ b/ecomp-sdk/epsdk-domain/src/test/java/org/onap/portalsdk/core/domain/support/ElementDetailsTest.java @@ -40,12 +40,11 @@ package org.onap.portalsdk.core.domain.support; import static org.junit.Assert.assertEquals; import org.junit.Test; -import org.onap.portalsdk.core.domain.support.ElementDetails; public class ElementDetailsTest { public ElementDetails mockElementDetails(){ - ElementDetails elementDetails = new ElementDetails("test","test","test","test","test","test","test","test","test","test"); + ElementDetails elementDetails = new ElementDetails.ElementDetailsBuilder().setLogical_group("test").setDisplay_longname("test").setDescription("test").setPrimary_function("test").setNetwork_function("test").setKey_interfaces("test").setLocation("test").setVendor("test").setVendor_shortname("test").setEnclosingContainer("test").createElementDetails(); elementDetails.setLogical_group("test"); @@ -56,7 +55,7 @@ public class ElementDetailsTest { public void elementDetailsTest(){ ElementDetails elementDetails = mockElementDetails(); - ElementDetails elementDetails1 = new ElementDetails("test","test","test","test","test","test","test","test","test","test"); + ElementDetails elementDetails1 = new ElementDetails.ElementDetailsBuilder().setLogical_group("test").setDisplay_longname("test").setDescription("test").setPrimary_function("test").setNetwork_function("test").setKey_interfaces("test").setLocation("test").setVendor("test").setVendor_shortname("test").setEnclosingContainer("test").createElementDetails(); elementDetails1.setLogical_group("test"); assertEquals(elementDetails.getLogical_group(), elementDetails1.getLogical_group()); diff --git a/ecomp-sdk/epsdk-domain/src/test/java/org/onap/portalsdk/core/domain/support/ElementTest.java b/ecomp-sdk/epsdk-domain/src/test/java/org/onap/portalsdk/core/domain/support/ElementTest.java index bf58de1a..a3cfb4b1 100644 --- a/ecomp-sdk/epsdk-domain/src/test/java/org/onap/portalsdk/core/domain/support/ElementTest.java +++ b/ecomp-sdk/epsdk-domain/src/test/java/org/onap/portalsdk/core/domain/support/ElementTest.java @@ -43,7 +43,6 @@ import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; -import org.onap.portalsdk.core.domain.support.Element; public class ElementTest { @@ -51,7 +50,7 @@ public class ElementTest { @Before public void setUp() { - details= new ElementDetails("logical_group", "display_longname", "description", "primary_function", "network_function", "key_interfaces", "location", "vendor", "vendor_shortname", "enclosingContainer"); + details= new ElementDetails.ElementDetailsBuilder().setLogical_group("logical_group").setDisplay_longname("display_longname").setDescription("description").setPrimary_function("primary_function").setNetwork_function("network_function").setKey_interfaces("key_interfaces").setLocation("location").setVendor("vendor").setVendor_shortname("vendor_shortname").setEnclosingContainer("enclosingContainer").createElementDetails(); } public Element mockElement(){ |