From f7873bd71f369fe3cab58e8e1113410ee5172b22 Mon Sep 17 00:00:00 2001 From: Jonathan Gamba Date: Thu, 4 May 2017 14:18:53 -0600 Subject: [PATCH 1/5] Changed cache provider to CaffineCache (#11490) (cherry picked from commit 0956e55) --- .../it-dotmarketing-config.properties | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/dotCMS/src/integration-test/resources/it-dotmarketing-config.properties b/dotCMS/src/integration-test/resources/it-dotmarketing-config.properties index 8a847c86b6fe..cf274c7649f7 100644 --- a/dotCMS/src/integration-test/resources/it-dotmarketing-config.properties +++ b/dotCMS/src/integration-test/resources/it-dotmarketing-config.properties @@ -504,15 +504,17 @@ ES_URL_ENDPOINT=http://localhost:9200/ asset.cache.control.max.days=30 ##################### dotCMS Cache Configuration ##################### -cache.default.chain=com.dotmarketing.business.cache.provider.guava.GuavaCache -cache.velocitymemoryonlycache.chain=com.dotmarketing.business.cache.provider.guava.GuavaCache -cache.contentletcache.chain=com.dotmarketing.business.cache.provider.guava.GuavaCache,com.dotmarketing.business.cache.provider.h22.H22Cache -cache.velocitycache.chain=com.dotmarketing.business.cache.provider.guava.GuavaCache,com.dotmarketing.business.cache.provider.h22.H22Cache +cache.default.chain =com.dotmarketing.business.cache.provider.caffine.CaffineCache +cache.contentletcache.chain =com.dotmarketing.business.cache.provider.caffine.CaffineCache,com.dotmarketing.business.cache.provider.h22.H22Cache +cache.velocitycache.chain =com.dotmarketing.business.cache.provider.caffine.CaffineCache,com.dotmarketing.business.cache.provider.h22.H22Cache +#cache.default.chain=com.dotmarketing.business.cache.provider.hazelcast.HazelCastEmbeddedProvider +#cache.default.chain=com.dotmarketing.business.cache.provider.hazelcast.HazelCastClientProvider + +CACHE_INVALIDATION_TRANSPORT_CLASS=com.dotcms.cache.transport.HazelCastCacheTransport + ## Default Caching Settings cache.default.size=1000 -cache.livecache.size=1000 -cache.workingcache.size=1000 ## Region Specific Guava cache setting Settings cache.concurrencylevel=32 @@ -533,11 +535,14 @@ cache.pushedassetscache.size=5000 cache.structurecache.size=500 cache.templatecache.size=500 cache.translatedquerycache.size=5000 -cache.velocityuservtlcache.size=500 cache.versioncache.size=50000 cache.versioninfocache.size=50000 cache.workflowactioncache.size=10000 cache.workflowtaskcache.size=10000 +cache.shorty.size=25000 +cache.identifier404cache.size=5000 +cache.virtuallinkscache.size=25000 +cache.velocitycache.size=1000 #Available cache regions @@ -558,9 +563,6 @@ cache.workflowtaskcache.size=10000 #cache.dotcmsrolekeycache.size=1000 #cache.dotcmsrootrolescache.size=1000 #cache.dotcmsuserrolecache.size=1000 -#cache.fieldscache.size=1000 -#cache.fieldsvarcache.size=1000 -#cache.filecache.size=1000 #cache.foldercache.size=1000 #cache.hostaliascache.size=1000 #cache.hostcache.size=1000 @@ -572,7 +574,6 @@ cache.workflowtaskcache.size=10000 #cache.newnotificationcache.size=1000 #cache.plugincache.size=1000 #cache.propertycache.size=1000 -#cache.ratingcache.size=1000 #cache.relationshipcachebyinode.size=1000 #cache.relationshipcachebyname.size=1000 #cache.ruleactionscache.size=1000 @@ -585,10 +586,6 @@ cache.workflowtaskcache.size=10000 #cache.useremaildotcmscache.size=1000 #cache.userproxycache.size=1000 #cache.velocitycache.size=1000 -#cache.velocitymemoryonlycache.size=1000 -#cache.velocitymenucache.size=1000 -#cache.velocitymisscache.size=1000 -#cache.virtuallinkscache.size=1000 #cache.workflowcache.size=1000 #cache.workflowstepcache.size=1000 From 8f04a282fab03b7067c0b792e636e318ec8b0e63 Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Fri, 5 May 2017 11:13:27 -0400 Subject: [PATCH 2/5] #11497 sending field variables --- .../contenttype/business/FieldAPIImpl.java | 6 +- .../business/FieldFactoryImpl.java | 1 - .../transform/field/DbFieldTransformer.java | 6 +- .../transform/field/JsonFieldTransformer.java | 66 +++++++------------ 4 files changed, 34 insertions(+), 45 deletions(-) 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 3f49ed021f8f..d6c5de8aea3a 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java @@ -224,7 +224,11 @@ public Field byContentTypeAndVar(ContentType type, String fieldVar) throws DotDa @Override public Field byContentTypeIdAndVar(String id, String fieldVar) throws DotDataException { - return fac.byContentTypeIdFieldVar(id, fieldVar); + try { + return APILocator.getContentTypeAPI(APILocator.systemUser()).find(id).fieldMap().get(fieldVar); + } catch (Exception e) { + throw new DotDataException(e); + } } @Override 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 0f3395f251d8..1de1a604f2f9 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java @@ -7,7 +7,6 @@ import java.util.Set; import java.util.TreeSet; import java.util.UUID; -import java.util.stream.Stream; import com.dotcms.contenttype.business.sql.FieldSql; import com.dotcms.contenttype.exception.DotDataValidationException; 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 e908c09d2600..f41d523845c3 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 @@ -179,8 +179,10 @@ public String typeName() { } }; - - return new ImplClassFieldTransformer(field).from(); + Field newField = new ImplClassFieldTransformer(field).from(); + //hydrate field variables + newField.fieldVariables(); + return newField; } diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldTransformer.java b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldTransformer.java index 38dc6cb5838b..d2c6454706b6 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldTransformer.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldTransformer.java @@ -8,17 +8,14 @@ import com.dotcms.contenttype.model.field.Field; import com.dotcms.contenttype.model.field.FieldVariable; import com.dotcms.contenttype.model.field.ImmutableFieldVariable; -import com.dotcms.contenttype.transform.JsonHelper; import com.dotcms.contenttype.transform.JsonTransformer; -import com.dotcms.contenttype.transform.SerialWrapper; import com.dotcms.repackage.com.google.common.collect.ImmutableList; +import com.dotcms.repackage.org.apache.commons.collections.map.HashedMap; import com.dotmarketing.business.DotStateException; import com.dotmarketing.util.json.JSONArray; import com.dotmarketing.util.json.JSONException; import com.dotmarketing.util.json.JSONObject; import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; public class JsonFieldTransformer implements FieldTransformer, JsonTransformer { @@ -39,8 +36,7 @@ public JsonFieldTransformer(String json) { JSONObject jo = new JSONObject(json); if (jo.has("fields")) { l = fromJsonArray(jo.getJSONArray("fields")); - } - else{ + } else { l.add(fromJsonStr(json)); } } catch (Exception e) { @@ -74,14 +70,12 @@ private List fromJsonArray(JSONArray jarr) List fields = new ArrayList<>(); for (int i = 0; i < jarr.length(); i++) { JSONObject jo = jarr.getJSONObject(i); - jo.remove("acceptedDataTypes"); Field f = fromJsonStr(jo.toString()); if (jo.has("fieldVariables")) { String varStr = jo.getJSONArray("fieldVariables").toString(); List vars = mapper.readValue(varStr, mapper.getTypeFactory().constructCollectionType(List.class, ImmutableFieldVariable.class)); - f.constructFieldVariables(vars); } fields.add(f); @@ -114,21 +108,7 @@ public List asList() throws DotStateException { @Override public JSONObject jsonObject() { - try { - JSONObject jo = new JSONObject(mapper.writeValueAsString(from())); - jo.remove("acceptedDataTypes"); - //jo.remove("iDate"); - jo.remove("dbColumn"); - - - return jo; - - - - - } catch (JSONException | JsonProcessingException e) { - throw new DotStateException(e); - } + return new JSONObject(mapObject()); } @Override @@ -142,28 +122,32 @@ public JSONArray jsonArray() { } public List> mapList() { - List> list = new ArrayList>(); - for (Field field : asList()) { - list.add(new JsonFieldTransformer(field).mapObject()); - } - return list; + List> list = new ArrayList>(); + for (Field field : asList()) { + list.add(new JsonFieldTransformer(field).mapObject()); + } + return list; } public Map mapObject() { - try { - Map map = mapper.readValue( - mapper.writeValueAsString(from()), - new TypeReference>(){} - ); - - map.remove("acceptedDataTypes"); - map.remove("iDate"); - map.remove("dbColumn"); - - return map; - } catch (IOException e) { - throw new DotStateException(e); + try { + Field f = from(); + Map field = mapper.convertValue(f, HashedMap.class); + List> vars = new ArrayList<>(); + for (FieldVariable fieldVar : f.fieldVariables()) { + Map var = mapper.convertValue(fieldVar, HashedMap.class); + var.remove("clazz"); + var.remove("userId"); + vars.add(var); } + field.put("fieldVariables", vars); + field.remove("acceptedDataTypes"); + field.remove("dbColumn"); + + return field; + } catch (Exception e) { + throw new DotStateException(e); + } } } From bf9821dd47c9718a4e1e0e1eb48dcba490f2e64d Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Fri, 5 May 2017 11:31:14 -0400 Subject: [PATCH 3/5] #11497 sending field variables --- .../transform/field/JsonFieldTransformer.java | 13 +--- .../field/JsonFieldVariableTransformer.java | 73 +++++++++++-------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldTransformer.java b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldTransformer.java index d2c6454706b6..e57d86b927a0 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldTransformer.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldTransformer.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -10,7 +11,6 @@ import com.dotcms.contenttype.model.field.ImmutableFieldVariable; import com.dotcms.contenttype.transform.JsonTransformer; import com.dotcms.repackage.com.google.common.collect.ImmutableList; -import com.dotcms.repackage.org.apache.commons.collections.map.HashedMap; import com.dotmarketing.business.DotStateException; import com.dotmarketing.util.json.JSONArray; import com.dotmarketing.util.json.JSONException; @@ -132,15 +132,8 @@ public List> mapList() { public Map mapObject() { try { Field f = from(); - Map field = mapper.convertValue(f, HashedMap.class); - List> vars = new ArrayList<>(); - for (FieldVariable fieldVar : f.fieldVariables()) { - Map var = mapper.convertValue(fieldVar, HashedMap.class); - var.remove("clazz"); - var.remove("userId"); - vars.add(var); - } - field.put("fieldVariables", vars); + Map field = mapper.convertValue(f, HashMap.class); + field.put("fieldVariables", new JsonFieldVariableTransformer(f.fieldVariables()).mapList()); field.remove("acceptedDataTypes"); field.remove("dbColumn"); diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldVariableTransformer.java b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldVariableTransformer.java index 04f5c6f929e4..a9d05d892bf1 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldVariableTransformer.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/transform/field/JsonFieldVariableTransformer.java @@ -2,12 +2,16 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import com.dotcms.contenttype.model.field.Field; import com.dotcms.contenttype.model.field.FieldVariable; import com.dotcms.repackage.com.google.common.collect.ImmutableList; import com.dotmarketing.business.DotStateException; +import com.dotmarketing.util.json.JSONArray; +import com.dotmarketing.util.json.JSONObject; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -15,11 +19,8 @@ public class JsonFieldVariableTransformer { - private static final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion( - Include.NON_NULL - ).configure( - DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false - ); + private static final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(Include.NON_NULL) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); final List list; @@ -33,18 +34,18 @@ public JsonFieldVariableTransformer(List list) { } public JsonFieldVariableTransformer(String json) { - List l = new ArrayList<>(); - l.add(fromJsonStr(json)); - this.list = ImmutableList.copyOf(l); + List l = new ArrayList<>(); + l.add(fromJsonStr(json)); + this.list = ImmutableList.copyOf(l); } private FieldVariable fromJsonStr(String input) throws DotStateException { - try { - return (FieldVariable) mapper.readValue(input, FieldVariable.class); - } catch (Exception e) { - throw new DotStateException(e); - } + try { + return (FieldVariable) mapper.readValue(input, FieldVariable.class); + } catch (Exception e) { + throw new DotStateException(e); + } } @@ -58,28 +59,36 @@ public List asList() throws DotStateException { public List> mapList() { - List> list = new ArrayList>(); - for (FieldVariable fieldVariable : asList()) { - list.add(new JsonFieldVariableTransformer(fieldVariable).mapObject()); - } - return list; + List> list = new ArrayList>(); + for (FieldVariable fieldVariable : asList()) { + list.add(new JsonFieldVariableTransformer(fieldVariable).mapObject()); + } + return list; } public Map mapObject() { - try { - Map map = mapper.readValue( - mapper.writeValueAsString(from()), - new TypeReference>(){} - ); - - map.remove("modDate"); - map.remove("name"); - map.remove("userId"); - - return map; - } catch (IOException e) { - throw new DotStateException(e); - } + + Map map = mapper.convertValue(this.from(), HashMap.class); + map.remove("clazz"); + map.remove("modDate"); + map.remove("name"); + map.remove("userId"); + + return map; + + } + + + public JSONObject jsonObject() { + return new JSONObject(mapObject()); + } + + public JSONArray jsonArray() { + JSONArray jarr = new JSONArray(); + for (FieldVariable var : asList()) { + jarr.add(new JsonFieldVariableTransformer(var).jsonObject()); + } + return jarr; } } From 94f0680ff23bca5d90e17a90defe48ada0cac999 Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Fri, 5 May 2017 11:54:48 -0400 Subject: [PATCH 4/5] #11497 reverting properties --- dotCMS/src/main/resources/dotmarketing-config.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dotCMS/src/main/resources/dotmarketing-config.properties b/dotCMS/src/main/resources/dotmarketing-config.properties index 542f9b8d0d5b..300a73390eb2 100644 --- a/dotCMS/src/main/resources/dotmarketing-config.properties +++ b/dotCMS/src/main/resources/dotmarketing-config.properties @@ -512,10 +512,10 @@ asset.cache.control.max.days=30 cache.default.chain =com.dotmarketing.business.cache.provider.caffine.CaffineCache cache.contentletcache.chain =com.dotmarketing.business.cache.provider.caffine.CaffineCache,com.dotmarketing.business.cache.provider.h22.H22Cache cache.velocitycache.chain =com.dotmarketing.business.cache.provider.caffine.CaffineCache,com.dotmarketing.business.cache.provider.h22.H22Cache -#cache.default.chain=com.dotmarketing.business.cache.provider.hazelcast.HazelCastEmbeddedProvider -#cache.default.chain=com.dotmarketing.business.cache.provider.hazelcast.HazelCastClientProvider +#cache.default.chain=com.dotmarketing.business.cache.provider.hazelcast.HazelcastCacheProviderEmbedded +#cache.default.chain=com.dotmarketing.business.cache.provider.hazelcast.HazelcastCacheProviderClient -CACHE_INVALIDATION_TRANSPORT_CLASS=com.dotcms.cache.transport.HazelCastCacheTransport +CACHE_INVALIDATION_TRANSPORT_CLASS=com.dotcms.cache.transport.HazelcastCacheTransportEmbedded ## Default Caching Settings From 5e79c3034be419a723c6f1e18be4d6a03baed4ab Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Fri, 5 May 2017 15:27:27 -0400 Subject: [PATCH 5/5] #11497 now returning ResponseEntityView --- .../JsonContentTypeTransformer.java | 24 +++++++++++++++++-- .../v1/contenttype/ContentTypeResource.java | 5 ++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/transform/contenttype/JsonContentTypeTransformer.java b/dotCMS/src/main/java/com/dotcms/contenttype/transform/contenttype/JsonContentTypeTransformer.java index c0f1826008a8..96bad91afb84 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/transform/contenttype/JsonContentTypeTransformer.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/transform/contenttype/JsonContentTypeTransformer.java @@ -1,14 +1,14 @@ package com.dotcms.contenttype.transform.contenttype; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.dotcms.contenttype.model.field.Field; import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.contenttype.model.type.ContentTypeBuilder; -import com.dotcms.contenttype.transform.JsonHelper; import com.dotcms.contenttype.transform.JsonTransformer; -import com.dotcms.contenttype.transform.SerialWrapper; import com.dotcms.contenttype.transform.field.JsonFieldTransformer; import com.dotcms.repackage.com.google.common.collect.ImmutableList; import com.dotmarketing.beans.Host; @@ -140,7 +140,27 @@ public JSONArray jsonArray() { return jarr; } + public List> mapList() { + List> list = new ArrayList>(); + for (ContentType type : asList()) { + list.add(new JsonContentTypeTransformer(type).mapObject()); + } + return list; + } + + public Map mapObject() { + try { + ContentType type = from(); + Map typeMap = mapper.convertValue(type, HashMap.class); + typeMap.put("fields", new JsonFieldTransformer(type.fields()).mapList()); + typeMap.remove("acceptedDataTypes"); + typeMap.remove("dbColumn"); + return typeMap; + } catch (Exception e) { + throw new DotStateException(e); + } + } } diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contenttype/ContentTypeResource.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contenttype/ContentTypeResource.java index 1776e48a2e47..f05cfc7dc66e 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contenttype/ContentTypeResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contenttype/ContentTypeResource.java @@ -76,7 +76,7 @@ public final Response saveType(@Context final HttpServletRequest req, final Stri retTypes.add(APILocator.getContentTypeAPI(user, true).save(type, type.fields())); } - return Response.ok(new ResponseEntityView(new JsonContentTypeTransformer(retTypes).jsonArray().toString())).build(); + return Response.ok(new ResponseEntityView(new JsonContentTypeTransformer(retTypes).mapObject())).build(); } @@ -112,7 +112,6 @@ public Response deleteType(@PathParam("id") final String id, @Context final Http joe.put("deleted", type.id()); - Response response = Response.ok(joe.toString()).build(); return response; } @@ -131,7 +130,7 @@ public Response getType(@PathParam("id") final String id, @Context final HttpSer Response response = Response.status(404).build(); try { ContentType type = tapi.find(id); - response = Response.ok(new JsonContentTypeTransformer(type).jsonObject().toString()).build(); + response = Response.ok(new ResponseEntityView(new JsonContentTypeTransformer(type).mapObject())).build(); } catch (NotFoundInDbException nfdb2) { // nothing to do here, will throw a 404 }