diff options
author | 2019-03-25 14:44:57 +0900 | |
---|---|---|
committer | 2019-03-25 14:45:25 +0900 | |
commit | a29a7bebca92aee498f60aca9c2476dcf81e6010 (patch) | |
tree | 94e748c74f9368dc6d760fe611363a2ef14d782c | |
parent | 832f01cfe2d7ca3b8b77f132ebed8c4e75fcff9c (diff) |
Sonar fix too many method param
+ implement builder pattern to reduce too many method param
Issue-ID: USECASEUI-250
Change-Id: I0fc34d51826cfe0f85e4a24b11136b5e192c63a3
Signed-off-by: Arindam Mondal <arind.mondal@samsung.com>
6 files changed, 155 insertions, 41 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java b/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java index 36ad68b5..fb8d388e 100755 --- a/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java +++ b/server/src/main/java/org/onap/usecaseui/server/bean/PerformanceHeader.java @@ -83,6 +83,128 @@ public class PerformanceHeader implements Serializable { @Column(name = "measurementInterval")
private String measurementInterval;
+
+ /** */
+ public static class PerformanceHeaderBuilder {
+ private String sourceId;
+ private String version;
+ private String eventName;
+ private String domain;
+ private String eventId;
+ private String eventType;
+ private String nfcNamingCode;
+ private String nfNamingCode;
+ private String sourceName;
+ private String reportingEntityId;
+ private String reportingEntityName;
+ private String priority;
+ private String startEpochMicrosec;
+ private String lastEpochMicroSec;
+ private String sequence;
+ private String measurementsForVfScalingVersion;
+ private String measurementInterval;
+ private Date createTime;
+ private Date updateTime;
+
+ public PerformanceHeaderBuilder setSourceId(String sourceId) {
+ this.sourceId = sourceId;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setEventName(String eventName) {
+ this.eventName = eventName;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setDomain(String domain) {
+ this.domain = domain;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setEventId(String eventId) {
+ this.eventId = eventId;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setEventType(String eventType) {
+ this.eventType = eventType;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setNfcNamingCode(String nfcNamingCode) {
+ this.nfcNamingCode = nfcNamingCode;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setNfNamingCode(String nfNamingCode) {
+ this.nfNamingCode = nfNamingCode;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setSourceName(String sourceName) {
+ this.sourceName = sourceName;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setReportingEntityId(String reportingEntityId) {
+ this.reportingEntityId = reportingEntityId;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setReportingEntityName(String reportingEntityName) {
+ this.reportingEntityName = reportingEntityName;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setPriority(String priority) {
+ this.priority = priority;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setStartEpochMicrosec(String startEpochMicrosec) {
+ this.startEpochMicrosec = startEpochMicrosec;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setLastEpochMicroSec(String lastEpochMicroSec) {
+ this.lastEpochMicroSec = lastEpochMicroSec;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setSequence(String sequence) {
+ this.sequence = sequence;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setMeasurementsForVfScalingVersion(String measurementsForVfScalingVersion) {
+ this.measurementsForVfScalingVersion = measurementsForVfScalingVersion;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setMeasurementInterval(String measurementInterval) {
+ this.measurementInterval = measurementInterval;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ return this;
+ }
+
+ public PerformanceHeaderBuilder setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ return this;
+ }
+
+ public PerformanceHeader createPerformanceHeader() {
+ return new PerformanceHeader(this);
+ }
+ }
public PerformanceHeader() {
}
@@ -91,24 +213,24 @@ public class PerformanceHeader implements Serializable { this.sourceId = sourceId;
}
- public PerformanceHeader(String version, String eventName, String domain, String eventId, String eventType, String nfcNamingCode, String nfNamingCode, String sourceId, String sourceName, String reportingEntityId, String reportingEntityName, String priority, String startEpochMicrosec, String lastEpochMicroSec, String sequence, String measurementsForVfScalingVersion, String measurementInterval, Date createTime, Date updateTime) {
- this.version = version;
- this.eventName = eventName;
- this.domain = domain;
- this.eventId = eventId;
- this.eventType = eventType;
- this.nfcNamingCode = nfcNamingCode;
- this.nfNamingCode = nfNamingCode;
- this.sourceId = sourceId;
- this.sourceName = sourceName;
- this.reportingEntityId = reportingEntityId;
- this.reportingEntityName = reportingEntityName;
- this.priority = priority;
- this.startEpochMicrosec = startEpochMicrosec;
- this.lastEpochMicroSec = lastEpochMicroSec;
- this.sequence = sequence;
- this.measurementsForVfScalingVersion = measurementsForVfScalingVersion;
- this.measurementInterval = measurementInterval;
+ public PerformanceHeader(PerformanceHeaderBuilder builder) {
+ this.version = builder.version;
+ this.eventName = builder.eventName;
+ this.domain = builder.domain;
+ this.eventId = builder.eventId;
+ this.eventType = builder.eventType;
+ this.nfcNamingCode = builder.nfcNamingCode;
+ this.nfNamingCode = builder.nfNamingCode;
+ this.sourceId = builder.sourceId;
+ this.sourceName = builder.sourceName;
+ this.reportingEntityId = builder.reportingEntityId;
+ this.reportingEntityName = builder.reportingEntityName;
+ this.priority = builder.priority;
+ this.startEpochMicrosec = builder.startEpochMicrosec;
+ this.lastEpochMicroSec = builder.lastEpochMicroSec;
+ this.sequence = builder.sequence;
+ this.measurementsForVfScalingVersion = builder.measurementsForVfScalingVersion;
+ this.measurementInterval = builder.measurementInterval;
}
public String getVersion() {
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java b/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java index 6b7eecca..0ef97ce0 100755 --- a/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/PerformanceController.java @@ -78,7 +78,7 @@ public class PerformanceController { @RequestParam(required = false) String sourceName, @RequestParam(required = false) String startTime,@RequestParam(required = false) String endTime) throws JsonProcessingException, ParseException { Page<PerformanceHeader> pa = new Page<PerformanceHeader>(); - PerformanceHeader performanceHeader = new PerformanceHeader(); + PerformanceHeader performanceHeader = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); performanceHeader.setSourceName(sourceName); performanceHeader.setStartEpochMicrosec(!UuiCommonUtil.isNotNullOrEmpty(startTime)?null:new SimpleDateFormat(Constant.DATE_FORMAT).parse(startTime).getTime()+""); performanceHeader.setLastEpochMicroSec(!UuiCommonUtil.isNotNullOrEmpty(endTime)?null:new SimpleDateFormat(Constant.DATE_FORMAT).parse(endTime).getTime()+""); @@ -125,7 +125,7 @@ public class PerformanceController { @RequestMapping(value = {"/performance/getSourceNames/{currentPage}/{pageSize}"},method = RequestMethod.GET, produces = "application/json") public String getPerformanceSourceNames(@PathVariable String currentPage,@PathVariable String pageSize, @RequestParam(required = false) String sourceName) throws JsonProcessingException{ - PerformanceHeader performanceHeader = new PerformanceHeader(); + PerformanceHeader performanceHeader = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); Page<PerformanceHeader> page = new Page<PerformanceHeader>(); Set<String> names = new HashSet<String>(); performanceHeader.setSourceName(sourceName); @@ -133,7 +133,7 @@ public class PerformanceController { if(!UuiCommonUtil.isNotNullOrEmpty(page)){ page = new Page<>(); List<PerformanceHeader> list = new ArrayList<>(); - performanceHeader = new PerformanceHeader(); + performanceHeader = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); list.add(performanceHeader); page.setList(list); diff --git a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java index df003bd3..1d51e2e8 100644 --- a/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/DmaapSubscriber.java @@ -31,10 +31,7 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; import org.glassfish.jersey.client.ClientConfig; -import org.onap.usecaseui.server.bean.AlarmsHeader; -import org.onap.usecaseui.server.bean.AlarmsInformation; -import org.onap.usecaseui.server.bean.PerformanceHeader; -import org.onap.usecaseui.server.bean.PerformanceInformation; +import org.onap.usecaseui.server.bean.*; import org.onap.usecaseui.server.constant.Constant; import org.onap.usecaseui.server.service.AlarmsHeaderService; import org.onap.usecaseui.server.service.AlarmsInformationService; @@ -236,7 +233,7 @@ public class DmaapSubscriber implements Runnable { } public void performanceProcess(Map<String, Object> maps) { - PerformanceHeader performance_header = new PerformanceHeader(); + PerformanceHeader performance_header = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); performance_header.setId(UuiCommonUtil.getUUID()); List<PerformanceInformation> performance_informations = new ArrayList<>(); maps.forEach((ek1, ev1) -> { diff --git a/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java b/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java index 24d1242e..09ac14b3 100644 --- a/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/bean/PerformanceHeaderTest.java @@ -34,10 +34,7 @@ public class PerformanceHeaderTest implements Serializable { @Test public void testGetPerformanceHeader() throws Exception { - PerformanceHeader ph = new PerformanceHeader("version", "eventName", "domain", "eventId", "eventType", "nfcNamingCode", "nfNamingCode", - "sourceId", "sourceName", "reportingEntityId", "reportingEntityName", "priority", - "startEpochMicrosec", "lastEpochMicroSec", "sequence", "measurementsForVfScalingVersion", - "measurementInterval", DateUtils.now(), DateUtils.now()); + PerformanceHeader ph = new PerformanceHeader.PerformanceHeaderBuilder().setVersion("version").setEventName("eventName").setDomain("domain").setEventId("eventId").setEventType("eventType").setNfcNamingCode("nfcNamingCode").setNfNamingCode("nfNamingCode").setSourceId("sourceId").setSourceName("sourceName").setReportingEntityId("reportingEntityId").setReportingEntityName("reportingEntityName").setPriority("priority").setStartEpochMicrosec("startEpochMicrosec").setLastEpochMicroSec("lastEpochMicroSec").setSequence("sequence").setMeasurementsForVfScalingVersion("measurementsForVfScalingVersion").setMeasurementInterval("measurementInterval").setCreateTime(DateUtils.now()).setUpdateTime(DateUtils.now()).createPerformanceHeader(); ph.getVersion(); ph.getEventName(); ph.getDomain(); @@ -60,7 +57,7 @@ public class PerformanceHeaderTest implements Serializable { @Test public void testSetPerformanceHeader() throws Exception { - PerformanceHeader ph = new PerformanceHeader("sourceId"); + PerformanceHeader ph = new PerformanceHeader.PerformanceHeaderBuilder().setSourceId("sourceId").createPerformanceHeader(); ph.setVersion(""); ph.setEventName(""); ph.setDomain(""); diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java index bccf73b1..1c62abcb 100755 --- a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java @@ -60,7 +60,7 @@ public class PerformanceControllerTest { String priority="Normal"; String startTime="1521678529000"; String endTime="1521680329000"; - PerformanceHeader header = new PerformanceHeader(); + PerformanceHeader header = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); controller.getPerformanceData(currentPage+"",pageSize+"",sourceName,startTime,endTime); diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java index 8c630625..f2958d4b 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/PerformanceHeaderServiceImplTest.java @@ -19,8 +19,6 @@ import org.junit.Test; import org.junit.Before; import org.junit.After; import org.onap.usecaseui.server.bean.PerformanceHeader; -import org.onap.usecaseui.server.service.impl.PerformanceHeaderServiceImpl; -import org.onap.usecaseui.server.util.DateUtils; import java.util.*; import java.io.*; @@ -85,7 +83,7 @@ public class PerformanceHeaderServiceImplTest { } @Mock public List<PerformanceHeader> list() { - PerformanceHeader ph = new PerformanceHeader(); + PerformanceHeader ph = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); return Arrays.asList(ph); } @Mock @@ -139,7 +137,7 @@ public class PerformanceHeaderServiceImplTest { public void testSavePerformanceHeader() throws Exception { try { PerformanceHeader ph = null; - PerformanceHeader phNew = new PerformanceHeader(); + PerformanceHeader phNew = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); performanceHeaderServiceImpl.savePerformanceHeader(ph); performanceHeaderServiceImpl.savePerformanceHeader(phNew); } catch (Exception e) { @@ -151,7 +149,7 @@ public class PerformanceHeaderServiceImplTest { public void testUpdatePerformanceHeader() throws Exception { try { PerformanceHeader ph = null; - PerformanceHeader phNew = new PerformanceHeader(); + PerformanceHeader phNew = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); performanceHeaderServiceImpl.updatePerformanceHeader(ph); performanceHeaderServiceImpl.updatePerformanceHeader(phNew); } catch (Exception e) { @@ -168,7 +166,7 @@ public class PerformanceHeaderServiceImplTest { } }; try { - PerformanceHeader ph = new PerformanceHeader(); + PerformanceHeader ph = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); ph.setVersion(""); ph.setEventName(""); ph.setDomain(""); @@ -190,7 +188,7 @@ public class PerformanceHeaderServiceImplTest { ph.setLastEpochMicroSec("");; performanceHeaderServiceImpl.getAllCount(ph, 1, 1); - PerformanceHeader phNew = new PerformanceHeader(); + PerformanceHeader phNew = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); performanceHeaderServiceImpl.getAllCount(phNew, 1, 1); performanceHeaderServiceImpl.getAllCount(null, 1, 1); } catch (Exception e) { @@ -201,7 +199,7 @@ public class PerformanceHeaderServiceImplTest { @Test public void testQueryPerformanceHeader() throws Exception { try { - PerformanceHeader ph = new PerformanceHeader(); + PerformanceHeader ph = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); ph.setVersion(""); ph.setEventName(""); ph.setDomain(""); @@ -223,7 +221,7 @@ public class PerformanceHeaderServiceImplTest { ph.setLastEpochMicroSec("");; performanceHeaderServiceImpl.queryPerformanceHeader(ph, 1, 10); - PerformanceHeader phNew = new PerformanceHeader(); + PerformanceHeader phNew = new PerformanceHeader.PerformanceHeaderBuilder().createPerformanceHeader(); performanceHeaderServiceImpl.queryPerformanceHeader(phNew, 1, 1); performanceHeaderServiceImpl.queryPerformanceHeader(null, 1, 1); } catch (Exception e) { |