diff --git a/src/fr/devinsy/statoolinfos/io/JSONFile.java b/src/fr/devinsy/statoolinfos/io/JSONFile.java index e6fde88..ffa9249 100644 --- a/src/fr/devinsy/statoolinfos/io/JSONFile.java +++ b/src/fr/devinsy/statoolinfos/io/JSONFile.java @@ -22,16 +22,20 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Categories; import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Organizations; import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.Services; -import fr.devinsy.statoolinfos.properties.PathPropertyUtils; +import fr.devinsy.statoolinfos.properties.PathProperty; +import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringsUtils; @@ -79,7 +83,7 @@ public class JSONFile lines.appendln("{ \"federation\" : "); - lines.addAll(PathPropertyUtils.toJSON(federation)); + lines.addAll(toJSON(federation)); lines.removeLast(); lines.appendln(","); @@ -87,7 +91,7 @@ public class JSONFile for (Organization organization : federation.getOrganizations()) { - lines.addAll(PathPropertyUtils.toJSON(organization)); + lines.addAll(toJSON(organization)); lines.removeLast(); lines.appendln(","); @@ -95,7 +99,7 @@ public class JSONFile for (Service service : organization.getServices()) { - lines.addAll(PathPropertyUtils.toJSON(service)); + lines.addAll(toJSON(service)); lines.appendln(","); } if (!organization.getServices().isEmpty()) @@ -141,7 +145,7 @@ public class JSONFile for (Organization organization : organizations) { - lines.addAll(PathPropertyUtils.toJSON(organization)); + lines.addAll(toJSON(organization)); lines.append(","); } if (!organizations.isEmpty()) @@ -174,7 +178,7 @@ public class JSONFile for (Service service : services) { - lines.addAll(PathPropertyUtils.toJSON(service)); + lines.addAll(toJSON(service)); lines.append(","); } if (!services.isEmpty()) @@ -186,4 +190,94 @@ public class JSONFile StringsUtils.writeToFile(file, lines); } + + /** + * To JSON. + * + * @param properties + * the properties + * @return the string list + */ + public static StringList toJSON(final PathPropertyList properties) + { + StringList result; + + result = new StringList(); + + result.append("{"); + + if (properties != null) + { + boolean firstDone = false; + for (PathProperty property : properties) + { + if (StringUtils.isNotBlank(property.getValue())) + { + firstDone = true; + result.append("\""); + result.append(StringEscapeUtils.escapeJson(property.getPath())); + result.append("\" : \""); + result.append(StringEscapeUtils.escapeJson(property.getValue())); + result.append("\""); + result.append(","); + } + } + if (firstDone) + { + result.removeLast(); + } + } + result.append("}"); + + // + return result; + } + + /** + * To JSON. + * + * @param properties + * the properties + * @return the string list + */ + public static StringList toJSON(final Service service) + { + StringList result; + + result = toJSON((PathPropertyList) service); + + // + result.removeLast(); + result.append(","); + + // + String organizationName; + if (service.getOrganization() == null) + { + organizationName = ""; + } + else + { + organizationName = service.getOrganization().getName(); + } + result.append("\""); + result.append("organization.name"); + result.append("\" : \""); + result.append(organizationName); + result.append("\""); + result.append(","); + + // + Categories categories = HtmlizerContext.instance().getCategories(); + result.append("\""); + result.append("software.categories"); + result.append("\" : \""); + result.append(StringEscapeUtils.escapeJson(categories.findBySoftware(service.getSoftwareName()).toString())); + result.append("\""); + + result.append("}"); + + // + return result; + } } diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyUtils.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyUtils.java index 58b45ec..cd64ff6 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyUtils.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyUtils.java @@ -30,7 +30,6 @@ import java.net.URL; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -300,48 +299,6 @@ public class PathPropertyUtils } } - /** - * To JSON. - * - * @param properties - * the properties - * @return the string list - */ - public static StringList toJSON(final PathPropertyList properties) - { - StringList result; - - result = new StringList(); - - result.append("{"); - - if (properties != null) - { - boolean firstDone = false; - for (PathProperty property : properties) - { - if (StringUtils.isNotBlank(property.getValue())) - { - firstDone = true; - result.append("\""); - result.append(StringEscapeUtils.escapeJson(property.getPath())); - result.append("\" : \""); - result.append(StringEscapeUtils.escapeJson(property.getValue())); - result.append("\""); - result.append(","); - } - } - if (firstDone) - { - result.removeLast(); - } - } - result.append("}"); - - // - return result; - } - /** * Value of. *