From bf3c288ffaf7fb589ee5fdc4c0744fb00d8bf41d Mon Sep 17 00:00:00 2001 From: Oscar Arrieta Date: Wed, 17 May 2017 07:46:39 -0600 Subject: [PATCH] Issue 11596 reindex (#11602) * #11596: Fallback to dbById() search * #11596: Return SYSTEM dataType if the value is not found * #11596: Commenting out the check on Field.java for now --- .../business/ContentTypeFactoryImpl.java | 61 ++++++++++++------- .../contenttype/model/field/DataTypes.java | 2 +- .../dotcms/contenttype/model/field/Field.java | 4 +- 3 files changed, 41 insertions(+), 26 deletions(-) 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 636e21748df5..4c0082d4338a 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java @@ -1,15 +1,5 @@ package com.dotcms.contenttype.business; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - -import org.elasticsearch.indices.IndexMissingException; - import com.dotcms.contenttype.business.sql.ContentTypeSql; import com.dotcms.contenttype.exception.NotFoundInDbException; import com.dotcms.contenttype.model.field.Field; @@ -46,6 +36,16 @@ import com.dotmarketing.util.UtilMethods; import com.dotmarketing.util.VelocityUtil; +import org.elasticsearch.indices.IndexMissingException; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + public class ContentTypeFactoryImpl implements ContentTypeFactory { final ContentTypeSql contentTypeSql; @@ -56,20 +56,35 @@ public ContentTypeFactoryImpl() { this.cache = CacheLocator.getContentTypeCache2(); } - @Override - public ContentType find(String id) throws DotDataException { - ContentType type = cache.byVarOrInode(id); - if (type == null) { - type = LocalTransaction.wrapReturn(() -> { - ContentType t = (UUIDUtil.isUUID(id)) ? dbById(id) : dbByVar(id); - t.fieldMap(); - return t; - }); - Logger.debug(this.getClass(), "found type by db:" + type.name()); - cache.add(type); + @Override + public ContentType find(String id) throws DotDataException { + ContentType type = cache.byVarOrInode(id); + if (type == null) { + type = LocalTransaction.wrapReturn(() -> { + ContentType t; + /* + 1. If the if has UUID format lets try to find the ContentType by id. + 2. If not let's try to find it by var name. + 3. If the id is a really old inode, it will not have the UUID format but still need to catch that case. + */ + if ( UUIDUtil.isUUID(id) ){ + t = dbById(id); + } else { + try { + t = dbByVar(id); + } catch (NotFoundInDbException e){ + t = dbById(id); + } + + } + t.fieldMap(); + return t; + }); + Logger.debug(this.getClass(), "found type by db:" + type.name()); + cache.add(type); + } + return type; } - return type; - } @Override public List findAll() throws DotDataException { 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 67b7780e7f73..6431e6662c20 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 @@ -33,7 +33,7 @@ public static DataTypes getDataType (String value) { if (type.value.equals(value)) return type; } - return null; + return SYSTEM; } } diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/model/field/Field.java b/dotCMS/src/main/java/com/dotcms/contenttype/model/field/Field.java index af9bcc906036..e0ac44301581 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/model/field/Field.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/model/field/Field.java @@ -62,10 +62,10 @@ public abstract class Field implements FieldIf, Serializable { @Value.Check public void check() { - if (iDate().after(legacyFieldDate)) { + /*if (iDate().after(legacyFieldDate)) { Preconditions.checkArgument(acceptedDataTypes().contains(dataType()), this.getClass().getSimpleName() + " must have DataType:" + acceptedDataTypes()); - } + }*/ }