CommonWidget class DB constraints

Java Bean Validation SR 380 annotations added to classes

Issue-ID: PORTAL-637
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Change-Id: I64741f835deb8aed14ad8d716d21bb4c1901b55f
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CommonWidget.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CommonWidget.java
index 3fbdc3e..9027787 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CommonWidget.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/CommonWidget.java
@@ -44,6 +44,11 @@
 import javax.persistence.Id;
 import javax.persistence.Table;
 
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
 import org.hibernate.validator.constraints.SafeHtml;
 import org.onap.portalsdk.core.domain.support.DomainVo;
 import com.fasterxml.jackson.annotation.JsonInclude;
@@ -54,6 +59,9 @@
 @Entity 
 @Table(name="fn_common_widget_data")
 @JsonInclude(JsonInclude.Include.NON_NULL)
+@NoArgsConstructor
+@Getter
+@Setter
 public class CommonWidget extends DomainVo{
 
 	private static final long serialVersionUID = 7897021982887364557L;
@@ -64,22 +72,28 @@
 	private Long id;
 
 	@Column(name = "category")
+	@Size(max = 32)
 	@SafeHtml
 	public String category;
 	
 	@Column(name = "href")
+	@Size(max = 512)
 	@SafeHtml
 	public String href;
 
 	@Column(name = "title")
+	@Size(max = 256)
 	@SafeHtml
 	public String title;
 	
 	@Column(name = "content")
+	@Size(max = 4096)
 	@SafeHtml
 	public String content;
 
 	@Column(name = "event_date")
+	@Size(max = 10)
+	@Pattern(regexp = "([1-2][0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])")
 	@SafeHtml
 	public String eventDate;
 	
@@ -87,10 +101,6 @@
 	public Integer sortOrder;
 
 
-	public CommonWidget(){
-
-	}
-
 	public CommonWidget(String category, String href, String title, String content, String eventDate, Integer sortOrder){
 		this.category = category;
 		this.href = href;
@@ -100,63 +110,4 @@
 		this.sortOrder = sortOrder;
 	}
 
-	public String getCategory() {
-		return category;
-	}
-
-	public void setCategory(String category) {
-		this.category = category;
-	}
-
-	public String getHref() {
-		return href;
-	}
-
-	public void setHref(String href) {
-		this.href = href;
-	}
-
-	public String getTitle() {
-		return title;
-	}
-
-	public void setTitle(String title) {
-		this.title = title;
-	}
-
-	public Integer getSortOrder() {
-		return sortOrder;
-	}
-
-	public void setSortOrder(Integer sortOrder) {
-		this.sortOrder = sortOrder;
-	}
-
-	public static long getSerialversionuid() {
-		return serialVersionUID;
-	}
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {		
-		this.id = id;
-	}
-
-	public String getContent() {
-		return content;
-	}
-
-	public void setContent(String content) {
-		this.content = content;
-	}
-
-	public String getEventDate() {
-		return eventDate;
-	}
-
-	public void setEventDate(String eventDate) {
-		this.eventDate = eventDate;
-	}	
 }
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java
index 3466785..c905e8d 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java
@@ -182,8 +182,8 @@
 	@Test
 	public void saveWidgetDataBulkIfCategoryNullTest() {
 		PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<>();
-		ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"1\"");
-		ecpectedPortalRestResponse.setResponse(null);
+		ecpectedPortalRestResponse.setMessage("ERROR");
+		ecpectedPortalRestResponse.setResponse("Category is not valid");
 		ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
 
 		CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta();
@@ -280,8 +280,8 @@
 	@Test
 	public void saveWidgetDataDateErrorTest() {
 		PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<>();
-		ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"1\"");
-		ecpectedPortalRestResponse.setResponse(null);
+		ecpectedPortalRestResponse.setMessage("ERROR");
+		ecpectedPortalRestResponse.setResponse("Category is not valid");
 		ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
 		CommonWidget commonWidget = new CommonWidget();
 		commonWidget.setId((long) 1);
diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java
index ff588da..297abef 100644
--- a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java
+++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java
@@ -146,8 +146,8 @@
 	@Test
 	public void saveWidgetDataBulkExceptionTest() {
 		PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<String>();
-		ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"date\"");
-		ecpectedPortalRestResponse.setResponse(null);
+		ecpectedPortalRestResponse.setMessage("ERROR");
+		ecpectedPortalRestResponse.setResponse("Category is not valid");
 		ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
 		CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta();
 		commonWidgetMeta.setCategory("test");
@@ -270,8 +270,8 @@
 	@Test
 	public void saveWidgetDataExceptionTest() {
 		PortalRestResponse<String> ecpectedPortalRestResponse = new PortalRestResponse<String>();
-		ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"date\"");
-		ecpectedPortalRestResponse.setResponse(null);
+		ecpectedPortalRestResponse.setMessage("ERROR");
+		ecpectedPortalRestResponse.setResponse("Category is not valid");
 		ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
 		CommonWidget commonWidget = new CommonWidget();
 		commonWidget.setCategory("test");