Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improvement or ApsEntity validation

  • Loading branch information...
commit f2bd968db0a22cc6a2711730aac8b1a77f848b1d 1 parent 731aa53
@eugeniosant eugeniosant authored
View
23 src/main/java/com/agiletec/aps/system/common/entity/model/ApsEntity.java
@@ -33,6 +33,7 @@
import com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface;
import com.agiletec.aps.system.common.entity.parse.IApsEntityDOM;
import com.agiletec.aps.system.services.category.Category;
+import com.agiletec.aps.system.services.group.IGroupManager;
/**
* This class represents an entity.
@@ -342,17 +343,25 @@ public void setEntityDOM(IApsEntityDOM entityDom) {
this._entityDom = entityDom;
}
- public List<FieldError> validate() {
+ public List<FieldError> validate(IGroupManager groupManager) {
List<FieldError> errors = new ArrayList<FieldError>();
try {
- /*
- if (null == this.getDescr() || this.getDescr().trim().length() == 0) {
- errors.add(new FieldError("description", FieldError.ErrorCode.MANDATORY));
+ if (null != this.getMainGroup() && null == groupManager.getGroup(this.getMainGroup())) {
+ FieldError error = new FieldError("mainGroup", FieldError.INVALID);
+ error.setMessage("Invalid main group - " + this.getMainGroup());
+ errors.add(error);
}
- if (null == this.getMainGroup() || this.getMainGroup().trim().length() == 0) {
- errors.add(new FieldError("mainGroup", FieldError.ErrorCode.MANDATORY));
+ if (null != this.getGroups()) {
+ Iterator<String> groupsIter = this.getGroups().iterator();
+ while (groupsIter.hasNext()) {
+ String groupName = groupsIter.next();
+ if (null == groupManager.getGroup(groupName)) {
+ FieldError error = new FieldError("extraGroup", FieldError.INVALID);
+ error.setMessage("Invalid extra group - " + groupName);
+ errors.add(error);
+ }
+ }
}
- */
if (null != this.getAttributeList()) {
List<AttributeInterface> attributes = this.getAttributeList();
for (int i = 0; i < attributes.size(); i++) {
View
17 src/main/java/com/agiletec/aps/system/common/entity/model/AttributeFieldError.java
@@ -26,6 +26,23 @@ public String getFieldCode() {
return fieldCode;
}
+ public String getFullMessage() {
+ StringBuffer buffer = new StringBuffer(this.getAttributePositionMessage());
+ buffer.append(" : ");
+ if (null != this.getMessageKey()) {
+ buffer.append(this.getMessageKey());
+ } else if (null != this.getMessage()) {
+ buffer.append(this.getMessage());
+ } else {
+ buffer.append(this.getErrorCode());
+ }
+ return buffer.toString();
+ }
+
+ public String getAttributePositionMessage() {
+ return this.getTracer().getPositionMessage(this.getAttribute());
+ }
+
public AttributeTracer getTracer() {
return _tracer;
}
View
28 src/main/java/com/agiletec/aps/system/common/entity/model/AttributeTracer.java
@@ -21,8 +21,8 @@
import com.agiletec.aps.system.services.lang.Lang;
/**
- * This class implements the 'tracer' for the jAPS Attributes. This class is
- * used, with the singles attributes, to trace the position inside 'composite'
+ * This class implements the 'tracer' for the Entando Attributes. This class is
+ * used, with the singles attributes, to trace the position inside any 'complex'
* attributes. This class is involved during the update and validation process
* of the Attribute and, furthermore, it guarantees the correct construction of
* the form in the content edit interface.
@@ -99,6 +99,30 @@ public String getFormFieldName(AttributeInterface attribute) {
return formFieldName.toString();
}
+ public String getPositionMessage(AttributeInterface attribute) {
+ StringBuffer buffer = new StringBuffer("Attribute ");
+ if (this.isMonoListElement()) {
+ if (this.isCompositeElement()) {
+ buffer.append(this.getParentAttribute().getName())
+ .append(" - element ").append(String.valueOf(this.getListIndex() + 1))
+ .append(" - Included Attribute ").append(attribute.getName());
+ } else {
+ buffer.append(attribute.getName()).append(" - element ")
+ .append(String.valueOf(this.getListIndex() + 1));
+ }
+ } else if (this.isCompositeElement()) {
+ buffer.append(this.getParentAttribute().getName())
+ .append(" - Included Attribute ").append(attribute.getName());
+ } else if (this.isListElement()) {
+ buffer.append(attribute.getName())
+ .append(" - lang ").append(this.getListLang().getDescr())
+ .append(" - element ").append(String.valueOf(this.getListIndex() + 1));
+ } else {
+ buffer.append(attribute.getName());
+ }
+ return buffer.toString();
+ }
+
public Lang getLang() {
return _lang;
}
View
3  src/main/java/com/agiletec/aps/system/common/entity/model/IApsEntity.java
@@ -24,6 +24,7 @@
import com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface;
import com.agiletec.aps.system.common.entity.parse.IApsEntityDOM;
import com.agiletec.aps.system.services.category.Category;
+import com.agiletec.aps.system.services.group.IGroupManager;
/**
* This class represents an Entity.
@@ -195,6 +196,6 @@
*/
public void disableAttributes(String disablingCode);
- public List<FieldError> validate();
+ public List<FieldError> validate(IGroupManager groupManager);
}
View
97 src/main/java/com/agiletec/aps/system/common/entity/model/JAXBEntity.java
@@ -17,6 +17,7 @@
*/
package com.agiletec.aps.system.common.entity.model;
+import com.agiletec.aps.system.ApsSystemUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
@@ -49,56 +50,68 @@
public JAXBEntity() {}
public JAXBEntity(IApsEntity mainEntity, String langCode) {
- this.setDescr(mainEntity.getDescr());
- this.setId(mainEntity.getId());
- this.setMainGroup(mainEntity.getMainGroup());
- this.setTypeCode(mainEntity.getTypeCode());
- this.setTypeDescr(mainEntity.getTypeDescr());
- this.setGroups(mainEntity.getGroups());
- this.setCategories(mainEntity.getCategories());
- List<AttributeInterface> attributes = mainEntity.getAttributeList();
- if (null == attributes || attributes.size() == 0) {
- return;
- }
- for (int i = 0; i < attributes.size(); i++) {
- AttributeInterface attribute = attributes.get(i);
- DefaultJAXBAttribute jaxrAttribute = attribute.getJAXBAttribute(langCode);
- if (null != jaxrAttribute) {
- this.getAttributes().add(jaxrAttribute);
+ try {
+ this.setDescr(mainEntity.getDescr());
+ this.setId(mainEntity.getId());
+ this.setMainGroup(mainEntity.getMainGroup());
+ this.setTypeCode(mainEntity.getTypeCode());
+ this.setTypeDescr(mainEntity.getTypeDescr());
+ this.setGroups(mainEntity.getGroups());
+ this.setCategories(mainEntity.getCategories());
+ List<AttributeInterface> attributes = mainEntity.getAttributeList();
+ if (null == attributes || attributes.size() == 0) {
+ return;
+ }
+ for (int i = 0; i < attributes.size(); i++) {
+ AttributeInterface attribute = attributes.get(i);
+ DefaultJAXBAttribute jaxrAttribute = attribute.getJAXBAttribute(langCode);
+ if (null != jaxrAttribute) {
+ this.getAttributes().add(jaxrAttribute);
+ }
}
+ } catch (Throwable t) {
+ ApsSystemUtils.logThrowable(t, this, "JAXBEntity");
+ throw new RuntimeException("Error creating JAXBEntity", t);
}
}
public IApsEntity buildEntity(IApsEntity prototype, ICategoryManager categoryManager) {
- prototype.setDescr(this.getDescr());
- prototype.setId(this.getId());
- prototype.setMainGroup(this.getMainGroup());
- prototype.setTypeCode(this.getTypeCode());
- prototype.setTypeDescr(this.getTypeDescr());
- if (null != this.getGroups() && !this.getGroups().isEmpty()) {
- Iterator<String> iter = this.getGroups().iterator();
- while (iter.hasNext()) {
- prototype.addGroup(iter.next());
+ try {
+ prototype.setDescr(this.getDescr());
+ prototype.setId(this.getId());
+ prototype.setMainGroup(this.getMainGroup());
+ prototype.setTypeCode(this.getTypeCode());
+ prototype.setTypeDescr(this.getTypeDescr());
+ if (null != this.getGroups() && !this.getGroups().isEmpty()) {
+ Iterator<String> iter = this.getGroups().iterator();
+ while (iter.hasNext()) {
+ prototype.addGroup(iter.next());
+ }
}
- }
- if (null != this.getCategories() && !this.getCategories().isEmpty()) {
- Iterator<String> iter = this.getCategories().iterator();
- while (iter.hasNext()) {
- String categoryCode = iter.next();
- Category category = categoryManager.getCategory(categoryCode);
- if (null != category) prototype.addCategory(category);
+ if (null != this.getCategories() && !this.getCategories().isEmpty()) {
+ Iterator<String> iter = this.getCategories().iterator();
+ while (iter.hasNext()) {
+ String categoryCode = iter.next();
+ Category category = categoryManager.getCategory(categoryCode);
+ if (null != category) {
+ prototype.addCategory(category);
+ }
+ }
}
- }
- if (null == this.getAttributes()) {
- return prototype;
- }
- for (int i = 0; i < this.getAttributes().size(); i++) {
- DefaultJAXBAttribute jaxrAttribute = this.getAttributes().get(i);
- AttributeInterface attribute = (AttributeInterface) prototype.getAttribute(jaxrAttribute.getName());
- if (null != attribute && null != jaxrAttribute
- && attribute.getType().equals(jaxrAttribute.getType())) {
- attribute.valueFrom(jaxrAttribute);
+ if (null == this.getAttributes()) {
+ return prototype;
+ }
+ for (int i = 0; i < this.getAttributes().size(); i++) {
+ DefaultJAXBAttribute jaxrAttribute = this.getAttributes().get(i);
+ AttributeInterface attribute = (AttributeInterface) prototype.getAttribute(jaxrAttribute.getName());
+ if (null != attribute && null != jaxrAttribute
+ && attribute.getType().equals(jaxrAttribute.getType())) {
+ attribute.valueFrom(jaxrAttribute);
+ }
}
+ } catch (Throwable t) {
+ ApsSystemUtils.logThrowable(t, this, "buildEntity");
+ throw new RuntimeException("Error creating Entity", t);
}
return prototype;
}
View
151 src/main/java/org/entando/entando/plugins/jacms/aps/system/services/api/ApiContentInterface.java
@@ -1,20 +1,20 @@
/*
-*
-* Copyright 2012 Entando S.r.l. (http://www.entando.com) All rights reserved.
-*
-* This file is part of Entando software.
-* Entando is a free software;
-* you can redistribute it and/or modify it
-* under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation; version 2.
-*
-* See the file License for the specific language governing permissions
-* and limitations under the License
-*
-*
-*
-* Copyright 2012 Entando S.r.l. (http://www.entando.com) All rights reserved.
-*
-*/
+ *
+ * Copyright 2012 Entando S.r.l. (http://www.entando.com) All rights reserved.
+ *
+ * This file is part of Entando software.
+ * Entando is a free software;
+ * you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation; version 2.
+ *
+ * See the file License for the specific language governing permissions
+ * and limitations under the License
+ *
+ *
+ *
+ * Copyright 2012 Entando S.r.l. (http://www.entando.com) All rights reserved.
+ *
+ */
package org.entando.entando.plugins.jacms.aps.system.services.api;
import java.util.ArrayList;
@@ -33,24 +33,24 @@
import com.agiletec.aps.system.ApsSystemUtils;
import com.agiletec.aps.system.SystemConstants;
+import com.agiletec.aps.system.common.entity.model.AttributeFieldError;
+import com.agiletec.aps.system.common.entity.model.AttributeTracer;
import com.agiletec.aps.system.common.entity.model.EntitySearchFilter;
+import com.agiletec.aps.system.common.entity.model.FieldError;
import com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface;
-import com.agiletec.aps.system.common.util.EntityAttributeIterator;
import com.agiletec.aps.system.exception.ApsSystemException;
import com.agiletec.aps.system.services.category.ICategoryManager;
import com.agiletec.aps.system.services.group.IGroupManager;
import com.agiletec.aps.system.services.page.IPageManager;
import com.agiletec.aps.system.services.user.IUserManager;
import com.agiletec.aps.system.services.user.UserDetails;
+
import com.agiletec.plugins.jacms.aps.system.services.cache.ICmsCacheWrapperManager;
import com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer;
import com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentAuthorizationHelper;
import com.agiletec.plugins.jacms.aps.system.services.content.helper.IContentListHelper;
import com.agiletec.plugins.jacms.aps.system.services.content.model.Content;
import com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO;
-import com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink;
-import com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute;
-import com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute;
import com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel;
import com.agiletec.plugins.jacms.aps.system.services.dispenser.IContentDispenser;
import com.agiletec.plugins.jacms.aps.system.services.resource.IResourceManager;
@@ -59,11 +59,11 @@
* @author E.Santoboni
*/
public class ApiContentInterface extends AbstractCmsApiInterface {
-
+
public List<String> getContents(Properties properties) throws Throwable {
return this.extractContents(properties);
}
-
+
protected List<String> extractContents(Properties properties) throws Throwable {
List<String> contentsId = null;
try {
@@ -78,7 +78,7 @@
}
return contentsId;
}
-
+
protected ApiContentListBean buildSearchBean(Properties properties) throws ApiException, Throwable {
ApiContentListBean bean = null;
try {
@@ -134,7 +134,7 @@ public String getContentsToHtml(Properties properties) throws Throwable {
}
return render.toString();
}
-
+
public JAXBContent getContent(Properties properties) throws ApiException, Throwable {
JAXBContent jaxbContent = null;
String id = properties.getProperty("id");
@@ -157,7 +157,7 @@ public JAXBContent getContent(Properties properties) throws ApiException, Throwa
}
return jaxbContent;
}
-
+
public String getContentToHtml(Properties properties) throws ApiException, Throwable {
String render = null;
String id = properties.getProperty("id");
@@ -237,16 +237,16 @@ protected Integer checkModel(String modelId, Content content) throws ApiExceptio
}
return modelIdInteger;
}
-
+
public StringApiResponse addContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbContent.getTypeCode();
- Content masterContentType = (Content) this.getContentManager().getEntityPrototype(typeCode);
- if (null == masterContentType) {
+ Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
+ if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist");
}
- Content content = (Content) jaxbContent.buildEntity(masterContentType, this.getCategoryManager());
+ Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
if (null != content.getId() && null != this.getContentManager().loadContentVO(content.getId())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + content.getId() + "' already exists");
}
@@ -260,21 +260,21 @@ public StringApiResponse addContent(JAXBContent jaxbContent, Properties properti
}
return response;
}
-
+
public StringApiResponse updateContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbContent.getTypeCode();
- Content masterContentType = (Content) this.getContentManager().getEntityPrototype(typeCode);
- if (null == masterContentType) {
+ Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
+ if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist");
}
- Content content = (Content) jaxbContent.buildEntity(masterContentType, this.getCategoryManager());
+ Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
Content masterContent = this.getContentManager().loadContent(content.getId(), false);
if (null == masterContent) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + content.getId() + "' does not exist");
} else if (!masterContent.getMainGroup().equals(content.getMainGroup())) {
- throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
+ throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
"Invalid main group " + content.getMainGroup() + " not equals then master " + masterContent.getMainGroup());
}
response = this.validateAndSaveContent(content, properties);
@@ -287,7 +287,7 @@ public StringApiResponse updateContent(JAXBContent jaxbContent, Properties prope
}
return response;
}
-
+
private StringApiResponse validateAndSaveContent(Content content, Properties properties) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
try {
@@ -296,10 +296,9 @@ private StringApiResponse validateAndSaveContent(Content content, Properties pro
user = this.getUserManager().getGuestUser();
}
if (!this.getContentAuthorizationHelper().isAuth(user, content)) {
- throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
+ throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
"Content groups makes the new content not allowed for user " + user.getUsername());
}
- //todo checkRequiredAttribute
List<ApiError> errors = this.validate(content);
if (errors.size() > 0) {
response.addErrors(errors);
@@ -327,32 +326,18 @@ private StringApiResponse validateAndSaveContent(Content content, Properties pro
private List<ApiError> validate(Content content) throws ApsSystemException {
List<ApiError> errors = new ArrayList<ApiError>();
try {
- if (null == content.getMainGroup() || null == this.getGroupManager().getGroup(content.getMainGroup())) {
- errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid main group - " + content.getMainGroup()));
+ if (null == content.getMainGroup()) {
+ errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Main group null"));
}
- if (null != content.getGroups()) {
- Iterator<String> groupsIter = content.getGroups().iterator();
- while (groupsIter.hasNext()) {
- String groupName = groupsIter.next();
- if (null == this.getGroupManager().getGroup(groupName)) {
- errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid extra group - " + groupName));
- }
- }
- }
- EntityAttributeIterator iterator = new EntityAttributeIterator(content);
- while (iterator.hasNext()) {
- AttributeInterface attribute = (AttributeInterface) iterator.next();
- if (attribute instanceof AbstractResourceAttribute) {
- //nothing to do
- } else if (attribute instanceof LinkAttribute) {
- SymbolicLink symbLink = ((LinkAttribute) attribute).getSymbolicLink();
- if (null != symbLink) {
- if (null != symbLink.getContentDest() && null == this.getContentManager().loadContentVO(symbLink.getContentDest())) {
- errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid link to content " + symbLink.getContentDest()));
- }
- if (null != symbLink.getPageDest() && null == this.getPageManager().getPage(symbLink.getPageDest())) {
- errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid link to page " + symbLink.getPageDest()));
- }
+ List<FieldError> fieldErrors = content.validate(this.getGroupManager());
+ if (null != fieldErrors) {
+ for (int i = 0; i < fieldErrors.size(); i++) {
+ FieldError fieldError = fieldErrors.get(i);
+ if (fieldError instanceof AttributeFieldError) {
+ AttributeFieldError attributeError = (AttributeFieldError) fieldError;
+ errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, attributeError.getFullMessage()));
+ } else {
+ errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, fieldError.getMessage()));
}
}
}
@@ -362,7 +347,7 @@ private StringApiResponse validateAndSaveContent(Content content, Properties pro
}
return errors;
}
-
+
public StringApiResponse deleteContent(Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
@@ -376,7 +361,7 @@ public StringApiResponse deleteContent(Properties properties) throws Throwable {
user = this.getUserManager().getGuestUser();
}
if (!this.getContentAuthorizationHelper().isAuth(user, masterContent)) {
- throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
+ throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
"Content groups makes the new content not allowed for user " + user.getUsername());
}
List<String> references = ((ContentUtilizer) this.getContentManager()).getContentUtilizers(id);
@@ -387,7 +372,7 @@ public StringApiResponse deleteContent(Properties properties) throws Throwable {
ContentRecordVO record = this.getContentManager().loadContentVO(reference);
if (null != record) {
found = true;
- response.addError(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR,
+ response.addError(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR,
"Content " + id + " referenced to content " + record.getId() + " - '" + record.getDescr() + "'"));
}
}
@@ -414,57 +399,59 @@ public StringApiResponse deleteContent(Properties properties) throws Throwable {
}
return response;
}
-
-
-
+
protected IContentListHelper getContentListHelper() {
return _contentListHelper;
}
+
public void setContentListHelper(IContentListHelper contentListHelper) {
this._contentListHelper = contentListHelper;
}
-
+
protected IUserManager getUserManager() {
return _userManager;
}
+
public void setUserManager(IUserManager userManager) {
this._userManager = userManager;
}
-
+
protected ICategoryManager getCategoryManager() {
return _categoryManager;
}
+
public void setCategoryManager(ICategoryManager categoryManager) {
this._categoryManager = categoryManager;
}
-
+
protected IGroupManager getGroupManager() {
return _groupManager;
}
+
public void setGroupManager(IGroupManager groupManager) {
this._groupManager = groupManager;
}
-
+
protected IPageManager getPageManager() {
return _pageManager;
}
+
public void setPageManager(IPageManager pageManager) {
this._pageManager = pageManager;
}
-
+
protected IResourceManager getResourceManager() {
return _resourceManager;
}
+
public void setResourceManager(IResourceManager resourceManager) {
this._resourceManager = resourceManager;
}
-
-
-
-
+
protected IContentAuthorizationHelper getContentAuthorizationHelper() {
return _contentAuthorizationHelper;
}
+
public void setContentAuthorizationHelper(IContentAuthorizationHelper contentAuthorizationHelper) {
this._contentAuthorizationHelper = contentAuthorizationHelper;
}
@@ -472,6 +459,7 @@ public void setContentAuthorizationHelper(IContentAuthorizationHelper contentAut
protected ICmsCacheWrapperManager getCmsCacheWrapperManager() {
return _cmsCacheWrapperManager;
}
+
public void setCmsCacheWrapperManager(ICmsCacheWrapperManager cmsCacheWrapperManager) {
this._cmsCacheWrapperManager = cmsCacheWrapperManager;
}
@@ -479,6 +467,7 @@ public void setCmsCacheWrapperManager(ICmsCacheWrapperManager cmsCacheWrapperMan
protected IContentDispenser getContentDispenser() {
return _contentDispenser;
}
+
public void setContentDispenser(IContentDispenser contentDispenser) {
this._contentDispenser = contentDispenser;
}
@@ -486,6 +475,7 @@ public void setContentDispenser(IContentDispenser contentDispenser) {
public String getItemsStartElement() {
return _itemsStartElement;
}
+
public void setItemsStartElement(String itemsStartElement) {
this._itemsStartElement = itemsStartElement;
}
@@ -493,6 +483,7 @@ public void setItemsStartElement(String itemsStartElement) {
public String getItemStartElement() {
return _itemStartElement;
}
+
public void setItemStartElement(String itemStartElement) {
this._itemStartElement = itemStartElement;
}
@@ -500,6 +491,7 @@ public void setItemStartElement(String itemStartElement) {
public String getItemEndElement() {
return _itemEndElement;
}
+
public void setItemEndElement(String itemEndElement) {
this._itemEndElement = itemEndElement;
}
@@ -507,18 +499,16 @@ public void setItemEndElement(String itemEndElement) {
public String getItemsEndElement() {
return _itemsEndElement;
}
+
public void setItemsEndElement(String itemsEndElement) {
this._itemsEndElement = itemsEndElement;
}
-
private IContentListHelper _contentListHelper;
private IUserManager _userManager;
private ICategoryManager _categoryManager;
-
private IGroupManager _groupManager;
private IPageManager _pageManager;
private IResourceManager _resourceManager;
-
private IContentAuthorizationHelper _contentAuthorizationHelper;
private ICmsCacheWrapperManager _cmsCacheWrapperManager;
private IContentDispenser _contentDispenser;
@@ -526,5 +516,4 @@ public void setItemsEndElement(String itemsEndElement) {
private String _itemStartElement = "<li>";
private String _itemEndElement = "</li>";
private String _itemsEndElement = "</ul>";
-
}
View
20 src/test/java/com/agiletec/plugins/jacms/aps/system/services/content/TestValidateContent.java
@@ -20,10 +20,12 @@
import java.util.List;
import com.agiletec.aps.BaseTestCase;
+import com.agiletec.aps.system.SystemConstants;
import com.agiletec.aps.system.common.entity.model.FieldError;
import com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute;
import com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute;
import com.agiletec.aps.system.services.group.Group;
+import com.agiletec.aps.system.services.group.IGroupManager;
import com.agiletec.plugins.jacms.aps.system.JacmsSystemConstants;
import com.agiletec.plugins.jacms.aps.system.services.content.model.Content;
import com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink;
@@ -44,7 +46,7 @@ public void testValidate_1() throws Throwable {
String insertedDescr = "XXX Prova Validazione XXX";
try {
Content content = this.createNewVoid("ART", insertedDescr, Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
- List<FieldError> errors = content.validate();
+ List<FieldError> errors = content.validate(this._groupManager);
assertNotNull(errors);
assertEquals(1, errors.size());
FieldError error = errors.get(0);
@@ -56,7 +58,7 @@ public void testValidate_1() throws Throwable {
monolist.addAttribute();
assertEquals(1, monolist.getAttributes().size());
- errors = content.validate();
+ errors = content.validate(this._groupManager);
assertEquals(2, errors.size());
error = errors.get(0);
assertEquals("it_Titolo", error.getFieldCode());//Verifica obbligatorietà attributo "Titolo"
@@ -80,7 +82,7 @@ public void testValidate_2() throws Throwable {
MonoListAttribute linksCorrelati = (MonoListAttribute) content.getAttribute("LinkCorrelati");
LinkAttribute linkAttribute = (LinkAttribute) linksCorrelati.addAttribute();
- List<FieldError> errors = content.validate();
+ List<FieldError> errors = content.validate(this._groupManager);
assertNotNull(errors);
assertEquals(1, errors.size());
FieldError error = errors.get(0);
@@ -93,7 +95,7 @@ public void testValidate_2() throws Throwable {
symbolicLink.setDestinationToContent("EVN103");//Contenuto di coach
linkAttribute.setSymbolicLink(symbolicLink);
- errors = content.validate();
+ errors = content.validate(this._groupManager);
assertNotNull(errors);
assertEquals(1, errors.size());
error = errors.get(0);
@@ -111,7 +113,7 @@ public void testValidate_3() throws Throwable {
ITextAttribute emailAttribute = (ITextAttribute) content.getAttribute("email");
emailAttribute.setText("wrongEmailAddress", null);
- List<FieldError> errors = content.validate();
+ List<FieldError> errors = content.validate(this._groupManager);
assertEquals(1, errors.size());
FieldError error = errors.get(0);
assertEquals("email", error.getFieldCode());
@@ -131,21 +133,21 @@ public void testValidate_4() throws Throwable {
ITextAttribute textAttribute = (ITextAttribute) content.getAttribute("Titolo");
textAttribute.setText(shortTitle, "it");
- List<FieldError> errors = content.validate();
+ List<FieldError> errors = content.validate(this._groupManager);
assertEquals(1, errors.size());
FieldError error = errors.get(0);
assertEquals("it_Titolo", error.getFieldCode());
assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
textAttribute.setText(longTitle, "it");
- errors = content.validate();
+ errors = content.validate(this._groupManager);
assertEquals(1, errors.size());
error = errors.get(0);
assertEquals("it_Titolo", error.getFieldCode());
assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
textAttribute.setText(shortTitle, "en");
- errors = content.validate();
+ errors = content.validate(this._groupManager);
assertEquals(2, errors.size());
error = errors.get(0);
assertEquals("it_Titolo", error.getFieldCode());
@@ -171,11 +173,13 @@ private Content createNewVoid(String contentType, String insertedDescr, String s
private void init() throws Exception {
try {
this._contentManager = (IContentManager) this.getService(JacmsSystemConstants.CONTENT_MANAGER);
+ this._groupManager = (IGroupManager) this.getService(SystemConstants.GROUP_MANAGER);
} catch (Throwable t) {
throw new Exception(t);
}
}
private IContentManager _contentManager = null;
+ private IGroupManager _groupManager = null;
}
Please sign in to comment.
Something went wrong with that request. Please try again.