diff --git a/src/com/dotmarketing/cms/content/submit/util/SubmitContentUtil.java b/src/com/dotmarketing/cms/content/submit/util/SubmitContentUtil.java index 90323f126929..556aac88ff99 100644 --- a/src/com/dotmarketing/cms/content/submit/util/SubmitContentUtil.java +++ b/src/com/dotmarketing/cms/content/submit/util/SubmitContentUtil.java @@ -26,6 +26,7 @@ import com.dotmarketing.portlets.categories.model.Category; import com.dotmarketing.portlets.contentlet.business.ContentletAPI; import com.dotmarketing.portlets.contentlet.business.DotContentletStateException; +import com.dotmarketing.portlets.contentlet.business.DotContentletValidationException; import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.fileassets.business.FileAsset; import com.dotmarketing.portlets.fileassets.business.FileAssetAPI; @@ -102,7 +103,7 @@ public static User getUserFromId(String userId) throws DotDataException{ * @return Map> * @throws DotSecurityException **/ - private static Map> getRelationships(Structure structure, Contentlet contentlet, String parametersOptions, User user) throws DotDataException, DotSecurityException{ + private static Map> getRelationships(Structure structure, Contentlet contentlet, String parametersOptions,List parametersName,List values, User user) throws DotDataException, DotSecurityException{ LanguageAPI lAPI = APILocator.getLanguageAPI(); Map> contentRelationships = new HashMap>(); if(contentlet == null) @@ -122,6 +123,19 @@ private static Map> getRelationships(Structure str } } } + for(int i=0; i < parametersName.size(); i++){ + String fieldname = parametersName.get(i); + String[] fieldValue = values.get(i); + if(fieldname.indexOf(rel.getRelationTypeValue()) != -1){ + List cons = conAPI.findContentletsByIdentifiers(fieldValue, true, lAPI.getDefaultLanguage().getId(), user, true); + if(cons.size()>0){ + if(contentRelationships.containsKey(rel)){ + cons.addAll(contentRelationships.get(rel)); + } + contentRelationships.put(rel, cons); + } + } + } } return contentRelationships; } @@ -454,7 +468,7 @@ public static Contentlet createContent(Structure st, ArrayList cats, S /** * Get the required relationships */ - Map> relationships = SubmitContentUtil.getRelationships(st, contentlet, options, user); + Map> relationships = SubmitContentUtil.getRelationships(st, contentlet, options,parametersName,values, user); /** @@ -471,7 +485,7 @@ public static Contentlet createContent(Structure st, ArrayList cats, S if(fileParameters.size() > 0){ for(Map value : fileParameters){ Field field = (Field)value.get("field"); - java.io.File file = (java.io.File)value.get(field.getVelocityVarName()); + java.io.File file = (java.io.File)value.get("file"); if(file!=null){ try { contentlet.setBinary(field.getVelocityVarName(), file); @@ -479,6 +493,11 @@ public static Contentlet createContent(Structure st, ArrayList cats, S } } + else if(field.isRequired()) { + DotContentletValidationException cve = new DotContentletValidationException("Contentlet's fields are not valid"); + cve.addRequiredField(field); + throw cve; + } } }