Skip to content

Commit

Permalink
Merge pull request #2743 from DamnClin/cypress-module
Browse files Browse the repository at this point in the history
Cypress module
  • Loading branch information
pascalgrimaud authored Jul 23, 2022
2 parents 70c81a2 + d87dd18 commit d0fd707
Show file tree
Hide file tree
Showing 31 changed files with 309 additions and 862 deletions.
71 changes: 3 additions & 68 deletions src/main/java/tech/jhipster/lite/common/domain/JsonUtils.java
Original file line number Diff line number Diff line change
@@ -1,85 +1,20 @@
package tech.jhipster.lite.common.domain;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.PrettyPrinter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import tech.jhipster.lite.error.domain.GeneratorException;

public class JsonUtils {

private static ObjectMapper objectMapper = null;
private static PrettyPrinter customPrettyPrinter = null;

private JsonUtils() {
// Cannot be instantiated
}

public static ObjectMapper getObjectMapper() {
if (objectMapper != null) {
return objectMapper;
}
objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
customPrettyPrinter = new CustomPrettyPrinter();
return objectMapper;
}

public static String addValueInArray(String fieldName, String value, String jsonContent) {
ObjectNode rootNode;
ObjectMapper objectMapper = getObjectMapper();
try {
rootNode = objectMapper.readValue(jsonContent, ObjectNode.class);
} catch (JsonProcessingException e) {
throw new GeneratorException("Cannot read json content : " + e.getMessage());
}

ArrayNode arrayNode;
if (rootNode.has(fieldName)) {
if (rootNode.get(fieldName).getNodeType() == JsonNodeType.ARRAY) {
arrayNode = ((ArrayNode) rootNode.get(fieldName));
} else {
throw new GeneratorException("Cannot add value in field: is not an array");
}
} else {
arrayNode = objectMapper.createArrayNode();
rootNode.set(fieldName, arrayNode);
}
arrayNode.add(value);

try {
return objectMapper.writer(customPrettyPrinter).writeValueAsString(rootNode);
} catch (JsonProcessingException e) {
throw new GeneratorException("Cannot serialize node : " + e.getMessage());
}
return JsonUtilsHolder.objectMapper;
}

private static class CustomPrettyPrinter extends DefaultPrettyPrinter {

@Override
public DefaultPrettyPrinter createInstance() {
return new CustomPrettyPrinter();
}

@Override
public void writeObjectFieldValueSeparator(JsonGenerator g) throws IOException {
g.writeRaw(": ");
}

@Override
public void beforeArrayValues(JsonGenerator g) throws IOException {
g.writeRaw("");
}
private static class JsonUtilsHolder {

@Override
public void writeEndArray(JsonGenerator g, int nrOfValues) throws IOException {
g.writeRaw(']');
}
private static ObjectMapper objectMapper = new ObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package tech.jhipster.lite.generator.client.tools.cypress.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.generator.client.tools.cypress.domain.CypressService;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.client.tools.cypress.domain.CypressModuleFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class CypressApplicationService {

private final CypressService cypressService;
private final CypressModuleFactory factory;

public CypressApplicationService(CypressService cypressService) {
this.cypressService = cypressService;
public CypressApplicationService() {
factory = new CypressModuleFactory();
}

public void init(Project project) {
cypressService.init(project);
public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return factory.buildModule(properties);
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit d0fd707

Please sign in to comment.