Skip to content

Commit

Permalink
Issue 11596 reindex (#11602)
Browse files Browse the repository at this point in the history
* #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
  • Loading branch information
oarrietadotcms committed May 17, 2017
1 parent 2a54310 commit bf3c288
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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<ContentType> findAll() throws DotDataException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static DataTypes getDataType (String value) {
if (type.value.equals(value))
return type;
}
return null;
return SYSTEM;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}*/
}


Expand Down

0 comments on commit bf3c288

Please sign in to comment.