diff --git a/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java b/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java index 773985418b63..6d50dc483245 100644 --- a/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java @@ -2298,6 +2298,10 @@ public List> getMostViewedContent(String structureInode, Dat * An error occurred when updating the contents. */ protected void clearField(String structureInode, Field field) throws DotDataException { + // we are not a db field; + if(field.getFieldContentlet() == null || ! (field.getFieldContentlet().matches("^.*\\d+$"))){ + return; + } Queries queries = getQueries(field); List inodesToFlush = new ArrayList<>(); diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java index 4c0082d4338a..a12ea2c40cc9 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java @@ -381,7 +381,7 @@ private ContentType dbSaveUpdate(final ContentType saveType) throws DotDataExcep } } - FieldAPI fapi = new FieldAPIImpl().instance(); + FieldAPI fapi = APILocator.getContentTypeFieldAPI(); for (Field f : fields) { f = FieldBuilder.builder(f).contentTypeId(retType.id()).build(); try { diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java index 37a5c55b90e3..80ca60eae582 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java @@ -159,6 +159,10 @@ public void delete(Field field, User user) throws DotDataException, DotSecurityE perAPI.checkPermission(type, PermissionLevel.PUBLISH, user); + Field oldField = fac.byId(field.id()); + if(oldField.fixed() || oldField.readOnly()){ + throw new DotDataException("You cannot delete a fixed or read only fiedl"); + } Structure structure = new StructureTransformer(type).asStructure(); com.dotmarketing.portlets.structure.model.Field legacyField = new LegacyFieldTransformer(field).asOldField(); @@ -193,8 +197,9 @@ public void delete(Field field, User user) throws DotDataException, DotSecurityE } // rebuild contentlets indexes - conAPI.reindex(structure); - + if(field.indexed()){ + conAPI.reindex(structure); + } // remove the file from the cache ContentletServices.removeContentletFile(structure); ContentletMapServices.removeContentletMapFile(structure); diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java index a33351e97ae0..6455a26fb897 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java @@ -185,21 +185,20 @@ private Field dbSaveUpdate(final Field throwAwayField) throws DotDataException { Field oldField = null; try { oldField = selectInDb(throwAwayField.id()); + builder.fixed(oldField.fixed()); + builder.readOnly(oldField.readOnly()); + builder.dataType(oldField.dataType()); + } catch (NotFoundInDbException e) { - // this is a new field - } - - - - if (oldField == null) { - // assign a db column if we need to - if (throwAwayField.dbColumn() == null) { - builder.dbColumn(nextAvailableColumn(throwAwayField)); - } - // assign an inode if needed + + // assign an inode and db column if needed if (throwAwayField.id() == null) { builder.id(UUID.randomUUID().toString()); } + if( throwAwayField.dbColumn()==null){ + builder.dbColumn(nextAvailableColumn(throwAwayField)); + } + if (throwAwayField.sortOrder() < 0) { // move to the end of the line @@ -213,8 +212,6 @@ private Field dbSaveUpdate(final Field throwAwayField) throws DotDataException { ? suggestVelocityVar(throwAwayField.name(), fieldsAlreadyAdded) : throwAwayField.variable(); builder.variable(tryVar); - builder.fixed(false); - builder.readOnly(false); } @@ -255,7 +252,9 @@ private Field dbSaveUpdate(final Field throwAwayField) throws DotDataException { Field retField = builder.build(); - + if(retField.dbColumn()==null){ + throw new DotDataException("Unable to save field without a DB Column ('field_contentlet')"); + } if (oldField == null) { diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/model/field/DataTypes.java b/dotCMS/src/main/java/com/dotcms/contenttype/model/field/DataTypes.java index 6431e6662c20..04bd7fbcf808 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/model/field/DataTypes.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/model/field/DataTypes.java @@ -1,6 +1,6 @@ package com.dotcms.contenttype.model.field; - +import com.dotmarketing.util.UtilMethods; public enum DataTypes { NONE("none"), @@ -23,11 +23,13 @@ public String toString () { return value; } + public static DataTypes getDataType (String value) { - if (value.isEmpty() || value.contains("_divider") || value.contains("binary") || value.contains("_tab") || value + if (!UtilMethods.isSet(value) || value.contains("_divider") || value.contains("binary") || value.contains("_tab") || value .contains("constant")) { return SYSTEM; } + value = value.replaceAll("[0-9]", ""); DataTypes[] types = DataTypes.values(); for (DataTypes type : types) { if (type.value.equals(value)) diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/model/field/TextAreaField.java b/dotCMS/src/main/java/com/dotcms/contenttype/model/field/TextAreaField.java index cfb8ca94e612..edb25e41a87b 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/model/field/TextAreaField.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/model/field/TextAreaField.java @@ -26,7 +26,7 @@ public Class type() { @Value.Derived @Override public List acceptedDataTypes(){ - return ImmutableList.of(DataTypes.LONG_TEXT); + return ImmutableList.of(DataTypes.LONG_TEXT, DataTypes.SYSTEM, DataTypes.TEXT); } @Value.Default @Override diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/DbFieldTransformer.java b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/DbFieldTransformer.java index f41d523845c3..d2b91fa82d90 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/DbFieldTransformer.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/DbFieldTransformer.java @@ -94,8 +94,7 @@ public String defaultValue() { @Override public DataTypes dataType() { - String dbType = map.get("field_contentlet").toString().replaceAll("[0-9]", ""); - return DataTypes.getDataType(dbType); + return DataTypes.getDataType((String) map.get("field_contentlet")); } @Override diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/LegacyFieldTransformer.java b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/LegacyFieldTransformer.java index 8c72d315cd88..83883b36dda9 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/LegacyFieldTransformer.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/LegacyFieldTransformer.java @@ -7,6 +7,7 @@ import org.elasticsearch.common.Nullable; +import com.dotcms.contenttype.model.field.BinaryField; import com.dotcms.contenttype.model.field.DataTypes; import com.dotcms.contenttype.model.field.Field; import com.dotcms.contenttype.model.field.FieldBuilder; @@ -98,10 +99,11 @@ private static com.dotmarketing.portlets.structure.model.Field transformToOld(Fi } private static String buildLegacyFieldContent(Field field){ - String fieldContent = field.dbColumn(); - if(field.typeName().endsWith("BinaryField")){ - fieldContent = "binary" + field.sortOrder(); - } + String fieldContent = (field instanceof BinaryField) + ? fieldContent = "binary" + field.sortOrder() + : (field.dbColumn() !=null) + ? field.dbColumn() + : " system_field"; return fieldContent; } diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/personas/business/PersonaFactoryImpl.java b/dotCMS/src/main/java/com/dotmarketing/portlets/personas/business/PersonaFactoryImpl.java index 5405e8d352d5..a836d3d760e2 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/personas/business/PersonaFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/personas/business/PersonaFactoryImpl.java @@ -74,8 +74,8 @@ public void createDefualtPersonaStructure() throws DotDataException { dc.addParam(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_NAME); dc.addParam(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_DESCRIPTION); dc.addParam(Structure.STRUCTURE_TYPE_PERSONA); - dc.addParam(false); - dc.addParam(false); + dc.addParam(true); + dc.addParam(true); dc.addParam(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_VARNAME); dc.addParam(Host.SYSTEM_HOST); dc.addParam(FolderAPI.SYSTEM_FOLDER); diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/structure/action/EditFieldAction.java b/dotCMS/src/main/java/com/dotmarketing/portlets/structure/action/EditFieldAction.java index 4f4966952c2d..d20605e34cf5 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/structure/action/EditFieldAction.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/structure/action/EditFieldAction.java @@ -10,7 +10,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import com.dotcms.contenttype.model.field.FieldBuilder; import com.dotcms.contenttype.model.field.LegacyFieldTypes; +import com.dotcms.contenttype.transform.field.LegacyFieldTransformer; import com.dotcms.repackage.com.google.common.annotations.VisibleForTesting; import com.dotcms.repackage.javax.portlet.ActionRequest; import com.dotcms.repackage.javax.portlet.ActionResponse; @@ -346,43 +348,18 @@ private boolean _saveField(ActionForm form, ActionRequest req, ActionResponse re field.setSortOrder(sortOrder + 1); field.setFixed(false); field.setReadOnly(false); + field.setFieldContentlet(dataType); - String fieldVelocityName = VelocityUtil.convertToVelocityVariable(fieldForm.getFieldName(), false); - int found = 0; - if (VelocityUtil.isNotAllowedVelocityVariableName(fieldVelocityName)) { - found++; - } - String velvar; - for (Field f : fields) { - velvar = f.getVelocityVarName(); - if (velvar != null) { - if (fieldVelocityName.equals(velvar)) { - found++; - } else if (velvar.contains(fieldVelocityName)) { - String number = velvar.substring(fieldVelocityName.length()); - if (RegEX.contains(number, "^[0-9]+$")) { - found++; - } - } - } - } - if (found > 0) { - fieldVelocityName = fieldVelocityName + Integer.toString(found); - } + } - if(!validateInternalFieldVelocityVarName(fieldVelocityName)){ - fieldVelocityName+="1"; - } + com.dotcms.contenttype.model.field.Field newField = new LegacyFieldTransformer(field).from(); + APILocator.getContentTypeFieldAPI().save(newField, user); - field.setVelocityVarName(fieldVelocityName); - } + - boolean isUpdating = UtilMethods.isSet(field.getInode()); - // saves this field - FieldFactory.saveField(field); - if(isUpdating) { + if(UtilMethods.isSet(field.getInode())) { ActivityLogger.logInfo(ActivityLogger.class, "Update Field Action", "User " + _getUser(req).getUserId() + "/" + _getUser(req).getFirstName() + " modified field " + field.getFieldName() + " to " + structure.getName() + " Structure.", HostUtil.hostNameUtil(req, _getUser(req))); } else { diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/structure/model/Field.java b/dotCMS/src/main/java/com/dotmarketing/portlets/structure/model/Field.java index d7416c0c6edf..eb13aaa9e980 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/structure/model/Field.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/structure/model/Field.java @@ -1,6 +1,7 @@ package com.dotmarketing.portlets.structure.model; import java.util.Date; + import java.util.HashMap; import java.util.Map; @@ -12,10 +13,20 @@ import com.dotmarketing.exception.DotHibernateException; import com.dotmarketing.portlets.structure.factories.FieldFactory; import com.dotmarketing.util.UtilMethods; - +/** + * + * @deprecated use {@link com.dotcms.contenttype.model.field.Field} + * + */ +@Deprecated public class Field extends Inode implements FieldIf { - + /** + * + * @deprecated + * + */ + @Deprecated public enum FieldType { BUTTON("button"), @@ -66,6 +77,12 @@ public static FieldType getFieldType (String value) { } + /** + * + * @deprecated + * + */ + @Deprecated public enum DataType { BOOL("bool"),