55import java .util .Collections ;
66import java .util .Comparator ;
77import java .util .Date ;
8+ import java .util .HashMap ;
89import java .util .List ;
10+ import java .util .Map ;
911import java .util .Set ;
1012import java .util .stream .Collectors ;
1113
@@ -200,9 +202,12 @@ public void validate(CampaignReferenceDto campaignReferenceDto) {
200202 validate (getByUuid (campaignReferenceDto .getUuid ()));
201203 }
202204
203- private void validate (CampaignDto campaignDto ) {
205+ protected void validate (CampaignDto campaignDto ) {
204206 final List <CampaignDashboardElement > campaignDashboardElements = campaignDto .getCampaignDashboardElements ();
205207 if (campaignDashboardElements != null ) {
208+
209+ final Map <String , Boolean > oneSubTabIsNotNullOrEmptyMap = new HashMap <>();
210+
206211 for (CampaignDashboardElement cde : campaignDashboardElements ) {
207212 final String diagramId = cde .getDiagramId ();
208213 if (diagramId == null ) {
@@ -212,8 +217,8 @@ private void validate(CampaignDto campaignDto) {
212217 CampaignDashboardElement .DIAGRAM_ID ,
213218 campaignDto .getName ()));
214219 } else if (!campaignDiagramDefinitionFacade .exists (diagramId )) {
215- throw new ValidationRuntimeException (
216- I18nProperties .getValidationError (Validations .campaignDashboardChartIdDoesNotExist , diagramId , campaignDto .getName ()));
220+ throw new ValidationRuntimeException (
221+ I18nProperties .getValidationError (Validations .campaignDashboardChartIdDoesNotExist , diagramId , campaignDto .getName ()));
217222 }
218223
219224 if (cde .getTabId () == null ) {
@@ -222,6 +227,26 @@ private void validate(CampaignDto campaignDto) {
222227 .getValidationError (Validations .campaignDashboardChartValueNull , CampaignDashboardElement .TAB_ID , campaignDto .getName ()));
223228 }
224229
230+ if (cde .getSubTabId () == null || cde .getSubTabId ().isEmpty ()) {
231+ if (oneSubTabIsNotNullOrEmptyMap .containsKey (cde .getTabId ()) && oneSubTabIsNotNullOrEmptyMap .get (cde .getTabId ())) {
232+ throw new ValidationRuntimeException (
233+ I18nProperties .getValidationError (
234+ Validations .campaignDashboardChartValueNull ,
235+ CampaignDashboardElement .SUB_TAB_ID ,
236+ campaignDto .getName ()));
237+ }
238+ oneSubTabIsNotNullOrEmptyMap .put (cde .getTabId (), false );
239+ } else {
240+ if (oneSubTabIsNotNullOrEmptyMap .containsKey (cde .getTabId ()) && !oneSubTabIsNotNullOrEmptyMap .get (cde .getTabId ())) {
241+ throw new ValidationRuntimeException (
242+ I18nProperties .getValidationError (
243+ Validations .campaignDashboardChartValueNull ,
244+ CampaignDashboardElement .SUB_TAB_ID ,
245+ campaignDto .getName ()));
246+ }
247+ oneSubTabIsNotNullOrEmptyMap .put (cde .getTabId (), true );
248+ }
249+
225250 if (cde .getOrder () == null ) {
226251 throw new ValidationRuntimeException (
227252 I18nProperties
@@ -239,8 +264,17 @@ private void validate(CampaignDto campaignDto) {
239264 I18nProperties
240265 .getValidationError (Validations .campaignDashboardChartValueNull , CampaignDashboardElement .WIDTH , campaignDto .getName ()));
241266 }
242-
243267 }
268+
269+ campaignDto .getCampaignFormMetas ().forEach (campaignFormMetaReferenceDto -> {
270+ if (campaignFormMetaReferenceDto == null || campaignFormMetaReferenceDto .getUuid () == null ) {
271+ throw new ValidationRuntimeException (
272+ I18nProperties .getValidationError (
273+ Validations .campaignDashboardDataFormValueNull ,
274+ CampaignDto .CAMPAIGN_FORM_METAS ,
275+ campaignDto .getName ()));
276+ }
277+ });
244278 }
245279 }
246280
@@ -292,6 +326,9 @@ public List<CampaignDashboardElement> getCampaignDashboardElements(String campai
292326 if (cde .getTabId () == null ) {
293327 cde .setTabId (StringUtils .EMPTY );
294328 }
329+ if (cde .getSubTabId () == null ) {
330+ cde .setSubTabId (StringUtils .EMPTY );
331+ }
295332 if (cde .getOrder () == null ) {
296333 cde .setOrder (0 );
297334 }
0 commit comments