Search in sources :

Example 26 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project cas by apereo.

the class ConfigurationMetadataGenerator method execute.

/**
 * Execute.
 *
 * @throws Exception the exception
 */
public void execute() throws Exception {
    final File jsonFile = new File(buildDir, "classes/java/main/META-INF/spring-configuration-metadata.json");
    final ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    final TypeReference<Map<String, Set<ConfigurationMetadataProperty>>> values = new TypeReference<Map<String, Set<ConfigurationMetadataProperty>>>() {
    };
    final Map<String, Set> jsonMap = mapper.readValue(jsonFile, values);
    final Set<ConfigurationMetadataProperty> properties = jsonMap.get("properties");
    final Set<ConfigurationMetadataProperty> groups = jsonMap.get("groups");
    final Set<ConfigurationMetadataProperty> collectedProps = new HashSet<>();
    final Set<ConfigurationMetadataProperty> collectedGroups = new HashSet<>();
    properties.stream().filter(p -> NESTED_TYPE_PATTERN.matcher(p.getType()).matches()).forEach(Unchecked.consumer(p -> {
        final Matcher matcher = NESTED_TYPE_PATTERN.matcher(p.getType());
        final boolean indexBrackets = matcher.matches();
        final String typeName = matcher.group(1);
        final String typePath = buildTypeSourcePath(typeName);
        parseCompilationUnit(collectedProps, collectedGroups, p, typePath, typeName, indexBrackets);
    }));
    properties.addAll(collectedProps);
    groups.addAll(collectedGroups);
    final Set<ConfigurationMetadataHint> hints = processHints(properties, groups);
    jsonMap.put("properties", properties);
    jsonMap.put("groups", groups);
    jsonMap.put("hints", hints);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    final PrettyPrinter pp = new DefaultPrettyPrinter();
    mapper.writer(pp).writeValue(jsonFile, jsonMap);
}
Also used : ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Arrays(java.util.Arrays) SneakyThrows(lombok.SneakyThrows) VoidVisitorAdapter(com.github.javaparser.ast.visitor.VoidVisitorAdapter) Reflections(org.reflections.Reflections) StringUtils(org.apache.commons.lang3.StringUtils) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) LiteralStringValueExpr(com.github.javaparser.ast.expr.LiteralStringValueExpr) ClassUtils(org.apache.commons.lang3.ClassUtils) QueryType(org.apereo.services.persondir.support.QueryType) Matcher(java.util.regex.Matcher) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) CompilationUnit(com.github.javaparser.ast.CompilationUnit) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Resource(org.springframework.core.io.Resource) ValueHint(org.springframework.boot.configurationmetadata.ValueHint) Unchecked(org.jooq.lambda.Unchecked) Collection(java.util.Collection) Set(java.util.Set) AbstractLdapProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) Collectors(java.util.stream.Collectors) PasswordPolicyProperties(org.apereo.cas.configuration.model.core.authentication.PasswordPolicyProperties) ClasspathHelper(org.reflections.util.ClasspathHelper) Modifier(com.github.javaparser.ast.Modifier) Serializable(java.io.Serializable) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Predicate(com.google.common.base.Predicate) Pattern(java.util.regex.Pattern) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) TypeElementsScanner(org.reflections.scanners.TypeElementsScanner) RequiresModule(org.apereo.cas.configuration.support.RequiresModule) HashMap(java.util.HashMap) PrincipalTransformationProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalTransformationProperties) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) HashSet(java.util.HashSet) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) StreamSupport(java.util.stream.StreamSupport) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) LinkedHashSet(java.util.LinkedHashSet) RelaxedNames(org.springframework.boot.bind.RelaxedNames) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) RequiredProperty(org.apereo.cas.configuration.support.RequiredProperty) CaseCanonicalizationMode(org.apereo.services.persondir.util.CaseCanonicalizationMode) File(java.io.File) SubTypesScanner(org.reflections.scanners.SubTypesScanner) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) ReflectionUtils(org.springframework.util.ReflectionUtils) LdapSearchEntryHandlersProperties(org.apereo.cas.configuration.model.support.ldap.LdapSearchEntryHandlersProperties) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) PrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter) JavaParser(com.github.javaparser.JavaParser) InputStream(java.io.InputStream) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Matcher(java.util.regex.Matcher) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) PrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) TypeReference(com.fasterxml.jackson.core.type.TypeReference) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 27 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project cytoscape-impl by cytoscape.

the class CyTransformerWriterImpl method write.

@Override
public void write(OutputStream stream, NamedTransformer<?, ?>... namedTransformers) throws IOException {
    JsonGenerator generator = factory.createGenerator(stream);
    try {
        generator.setPrettyPrinter(new DefaultPrettyPrinter());
        generator.writeStartArray();
        try {
            for (NamedTransformer<?, ?> namedTransformer : namedTransformers) {
                write(generator, namedTransformer);
            }
        } finally {
            generator.writeEndArray();
        }
    } finally {
        generator.close();
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 28 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project hippo by NHS-digital-website.

the class OdsUtils method main.

public static void main(String[] args) throws IOException {
    OdsUtils util = new OdsUtils();
    int offSet = 1;
    List<Organisation> finalList = new ArrayList();
    while (true) {
        String str = util.extracted(String.valueOf(offSet)).toString().trim();
        System.out.println("Value is " + str.length());
        List<Organisation> tempList = util.jsonFomart(str);
        System.out.println("Value is tempList " + tempList.size());
        if (tempList != null && tempList.size() > 0) {
            finalList.addAll(tempList);
            offSet += 1000;
            System.out.println("Value of offSet is " + offSet);
            System.out.println("Size of finalList is " + finalList.size());
        } else {
            break;
        }
    }
    ObjectMapper objectMapper = new ObjectMapper();
    // Set pretty printing of json
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    ObjectWriter writer = objectMapper.writer(new DefaultPrettyPrinter());
    writer.writeValue(new File("ODS_JSON.json"), finalList);
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 29 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project cxf by apache.

the class Java2SwaggerMojo method generateSwaggerPayLoad.

private void generateSwaggerPayLoad() throws MojoExecutionException {
    if (outputFile == null && project != null) {
        // Put the json in target/generated/json
        // put the yaml in target/generated/yaml
        final String name;
        if (outputFileName != null) {
            name = outputFileName;
        } else if (resourceClasses.size() == 1) {
            name = resourceClasses.iterator().next().getSimpleName();
        } else {
            name = "swagger";
        }
        outputFile = (project.getBuild().getDirectory() + "/generated/" + payload.toLowerCase() + "/" + name + "." + payload.toLowerCase()).replace("/", File.separator);
    }
    FileUtils.mkDir(new File(outputFile).getParentFile());
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
        if ("json".equals(this.payload)) {
            ObjectWriter jsonWriter = mapper.writer(new DefaultPrettyPrinter());
            writer.write(jsonWriter.writeValueAsString(swagger));
        } else if ("yaml".equals(this.payload)) {
            writer.write(Yaml.pretty().writeValueAsString(swagger));
        }
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    // with the enclosing project
    if (attachSwagger && outputFile != null) {
        File jsonFile = new File(outputFile);
        if (jsonFile.exists()) {
            if (classifier != null) {
                projectHelper.attachArtifact(project, payload.toLowerCase(), classifier, jsonFile);
            } else {
                projectHelper.attachArtifact(project, payload.toLowerCase(), jsonFile);
            }
        }
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileWriter(java.io.FileWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 30 with DefaultPrettyPrinter

use of com.fasterxml.jackson.core.util.DefaultPrettyPrinter in project ambry by linkedin.

the class AccountUpdateTool method editAccounts.

/**
 * Edit accounts in a text editor and upload them to zookeeper.
 * @param accountNames the name of the accounts to edit.
 * @param ignoreSnapshotVersion if {@code true}, don't verify the snapshot version.
 * @throws IOException
 * @throws InterruptedException
 */
void editAccounts(Collection<String> accountNames, boolean ignoreSnapshotVersion) throws IOException, InterruptedException, AccountServiceException {
    Path accountJsonPath = Files.createTempFile("account-update-", ".json");
    List<Account> accounts = accountNames.stream().map(accountName -> Optional.ofNullable(accountService.getAccountByName(accountName)).orElseThrow(() -> new IllegalArgumentException("Could not find account: " + accountName))).collect(Collectors.toList());
    try (BufferedWriter writer = Files.newBufferedWriter(accountJsonPath)) {
        new ObjectMapper().writer(new DefaultPrettyPrinter()).writeValue(writer, accounts);
    }
    ToolUtils.editFile(accountJsonPath);
    System.out.println("The following account metadata will be uploaded:");
    try (Stream<String> lines = Files.lines(accountJsonPath)) {
        lines.forEach(System.out::println);
    }
    if (ToolUtils.yesNoPrompt("Do you want to update these accounts?")) {
        updateAccountsFromFile(accountJsonPath.toAbsolutePath().toString(), ignoreSnapshotVersion);
    } else {
        System.out.println("Not updating any accounts");
    }
    Files.delete(accountJsonPath);
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) Map(java.util.Map) OptionParser(joptsimple.OptionParser) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) OptionSet(joptsimple.OptionSet) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Utils(com.github.ambry.utils.Utils) IOException(java.io.IOException) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) Collectors(java.util.stream.Collectors) AccountUtils(com.github.ambry.account.AccountUtils) HelixAccountServiceConfig(com.github.ambry.config.HelixAccountServiceConfig) ArgumentAcceptingOptionSpec(joptsimple.ArgumentAcceptingOptionSpec) ToolUtils(com.github.ambry.tools.util.ToolUtils) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) JSONArray(org.json.JSONArray) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BufferedWriter(java.io.BufferedWriter)

Aggregations

DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)42 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 IOException (java.io.IOException)9 File (java.io.File)7 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)6 DefaultIndenter (com.fasterxml.jackson.core.util.DefaultIndenter)6 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)6 OpenAPI (io.swagger.v3.oas.models.OpenAPI)6 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)4 PrettyPrinter (com.fasterxml.jackson.core.PrettyPrinter)3 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)3 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)3 SpecFilter (io.swagger.v3.core.filter.SpecFilter)3 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)3 BufferedWriter (java.io.BufferedWriter)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3