diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/normalizer/ApsAppJsonNormalizer.java b/src/main/java/com/inteligr8/maven/aps/modeling/normalizer/ApsAppJsonNormalizer.java index f5c7db3..5b306e5 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/normalizer/ApsAppJsonNormalizer.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/normalizer/ApsAppJsonNormalizer.java @@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.inteligr8.maven.aps.modeling.util.ApsModelArrayNodeSorter; +import com.inteligr8.maven.aps.modeling.util.ArrayNodeObjectSorter; import com.inteligr8.maven.aps.modeling.util.ModelUtil; /** @@ -66,20 +66,27 @@ public class ApsAppJsonNormalizer implements ApsFileNormalizer { // remove system-level and non-functional fields from models for (JsonNode _jsonModel : jsonModels) { ObjectNode jsonModel = (ObjectNode)_jsonModel; - - int fields = jsonModel.size(); - jsonModel.remove(Arrays.asList("lastUpdated")); -// jsonModel.remove(Arrays.asList("createdBy", "createdByFullName", "lastUpdatedBy", "lastUpdatedByFullName", "lastUpdated")); - if (jsonModel.size() < fields) - changed = true; + changed = this.transformModel(jsonModel) || changed; } // sort the models for better 'diff' support - if (this.enableSorting) - changed = ApsModelArrayNodeSorter.getInstance().sort(jsonModels, "name") || changed; + if (this.enableSorting) { + boolean sorted = ArrayNodeObjectSorter.getInstance().sort(jsonModels, "name"); + this.logger.trace("Sorted App models: {}: {}", modelName, sorted); + changed = sorted || changed; + } if (changed) ModelUtil.getInstance().writeJson(descriptor, file, this.enableSorting); } + private boolean transformModel(ObjectNode jsonModel) { + this.logger.trace("Removing excess App model meta-data: {}", jsonModel.get("name")); + + int fields = jsonModel.size(); + jsonModel.remove(Arrays.asList("lastUpdated")); +// jsonModel.remove(Arrays.asList("createdBy", "createdByFullName", "lastUpdatedBy", "lastUpdatedByFullName", "lastUpdated")); + return jsonModel.size() < fields; + } + } diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/normalizer/ApsProcessJsonNormalizer.java b/src/main/java/com/inteligr8/maven/aps/modeling/normalizer/ApsProcessJsonNormalizer.java index ea9aca2..b64c972 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/normalizer/ApsProcessJsonNormalizer.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/normalizer/ApsProcessJsonNormalizer.java @@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.inteligr8.maven.aps.modeling.util.ApsModelArrayNodeSorter; +import com.inteligr8.maven.aps.modeling.util.ArrayNodeObjectSorter; import com.inteligr8.maven.aps.modeling.util.ModelUtil; /** diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/util/ApsModelArrayNodeSorter.java b/src/main/java/com/inteligr8/maven/aps/modeling/util/ApsModelArrayNodeSorter.java deleted file mode 100644 index 11c49c3..0000000 --- a/src/main/java/com/inteligr8/maven/aps/modeling/util/ApsModelArrayNodeSorter.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.inteligr8.maven.aps.modeling.util; - -import com.fasterxml.jackson.databind.node.ArrayNode; - -public class ApsModelArrayNodeSorter extends ArrayNodeObjectSorter { - - private static ApsModelArrayNodeSorter INSTANCE = new ApsModelArrayNodeSorter(); - - public static ApsModelArrayNodeSorter getInstance() { - return INSTANCE; - } - - - - protected ApsModelArrayNodeSorter() { - } - - public boolean sort(ArrayNode arrayNode, String jsonObjectFieldName) { - return this.sort(arrayNode, new ObjectNodeComparator(jsonObjectFieldName)); - } - -} diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/util/ApsModelListMapSorter.java b/src/main/java/com/inteligr8/maven/aps/modeling/util/ApsModelListMapSorter.java deleted file mode 100644 index 212a048..0000000 --- a/src/main/java/com/inteligr8/maven/aps/modeling/util/ApsModelListMapSorter.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.inteligr8.maven.aps.modeling.util; - -import java.util.List; -import java.util.Map; - -public class ApsModelListMapSorter extends ListMapSorter { - - private static ApsModelListMapSorter INSTANCE = new ApsModelListMapSorter(); - - public static ApsModelListMapSorter getInstance() { - return INSTANCE; - } - - - - protected ApsModelListMapSorter() { - } - - public boolean sort(List> jsonArrayAsMap, String jsonObjectFieldName) { - return this.sort(jsonArrayAsMap, new MapComparator(jsonObjectFieldName)); - } - -} diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/util/ArrayNodeObjectSorter.java b/src/main/java/com/inteligr8/maven/aps/modeling/util/ArrayNodeObjectSorter.java index b68297e..e976dbf 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/util/ArrayNodeObjectSorter.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/util/ArrayNodeObjectSorter.java @@ -1,3 +1,17 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ package com.inteligr8.maven.aps.modeling.util; import java.util.Comparator; @@ -5,10 +19,18 @@ import java.util.Comparator; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; +/** + * A singleton class that provides JSON array sorting methods. + * + * @author brian@inteligr8.com + */ public class ArrayNodeObjectSorter { private static ArrayNodeObjectSorter INSTANCE = new ArrayNodeObjectSorter(); + /** + * @return A singleton instance of this class. + */ public static ArrayNodeObjectSorter getInstance() { return INSTANCE; } @@ -17,7 +39,32 @@ public class ArrayNodeObjectSorter { protected ArrayNodeObjectSorter() { } + + /** + * This method sorts the JSON object elements of the JSON array by the + * value of the specified field in the JSON objects. + * + * If a JSON object has the specified field, its value is subject to the + * standard comparison. If it doesn't have a value, then it will sort to + * the end of the array. + * + * @param arrayNode A JSON array of JSON objects. + * @param jsonObjectFieldName A field in the JSON object elements. + * @return true if any elements were moved/sorted; false if unchanged. + * @see com.inteligr8.maven.aps.modeling.util.ObjectNodeComparator + */ + public boolean sort(ArrayNode arrayNode, String jsonObjectFieldName) { + return this.sort(arrayNode, new ObjectNodeComparator(jsonObjectFieldName)); + } + /** + * This method sorts the JSON node elements of the JSON array using the + * specified comparator. + * + * @param arrayNode A JSON array of JSON objects. + * @param comparator A JSON node comparator. + * @return true if any elements were moved/sorted; false if unchanged. + */ public boolean sort(ArrayNode arrayNode, Comparator comparator) { if (arrayNode.isEmpty()) return false; diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/util/ListMapSorter.java b/src/main/java/com/inteligr8/maven/aps/modeling/util/ListMapSorter.java index ae8b909..5a2ea5b 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/util/ListMapSorter.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/util/ListMapSorter.java @@ -1,12 +1,72 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ package com.inteligr8.maven.aps.modeling.util; import java.util.Comparator; import java.util.List; import java.util.Map; -public class ListMapSorter { +/** + * A singleton class that provides list of maps sorting methods. + * + * @author brian@inteligr8.com + */ +public class ListMapSorter { - public boolean sort(List> listOfMaps, Comparator> comparator) { + private static ListMapSorter INSTANCE = new ListMapSorter(); + + /** + * @return A singleton instance of this class. + */ + public static ListMapSorter getInstance() { + return INSTANCE; + } + + + + protected ListMapSorter() { + } + + /** + * This method sorts the maps in the list by the value of the specified key + * in the maps. + * + * If a map has the specified key, its value is subject to the standard + * comparison. If it doesn't have a value, then it will sort to the end of + * the array. + * + * @param The type of value in the maps. + * @param listOfMaps A list of maps. + * @param mapKey A key in the maps. + * @return true if any maps were moved/sorted; false if unchanged. + * @see com.inteligr8.maven.aps.modeling.util.MapComparator + */ + public boolean sort(List> listOfMaps, String mapKey) { + return this.sort(listOfMaps, new MapComparator(mapKey)); + } + + /** + * This method sorts the maps of the list using the specified comparator. + * + * @param The type of key in the maps. + * @param The type of value in the maps. + * @param listOfMaps A list of maps. + * @param comparator A map comparator. + * @return true if any maps were moved/sorted; false if unchanged. + */ + public boolean sort(List> listOfMaps, Comparator> comparator) { if (listOfMaps.isEmpty()) return false;