-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2743 from DamnClin/cypress-module
Cypress module
- Loading branch information
Showing
31 changed files
with
309 additions
and
862 deletions.
There are no files selected for viewing
71 changes: 3 additions & 68 deletions
71
src/main/java/tech/jhipster/lite/common/domain/JsonUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
...ech/jhipster/lite/generator/client/common/application/ClientCommonApplicationService.java
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
...ain/java/tech/jhipster/lite/generator/client/common/domain/ClientCommonDomainService.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/main/java/tech/jhipster/lite/generator/client/common/domain/ClientCommonService.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...h/jhipster/lite/generator/client/common/infrastructure/ClientCommonBeanConfiguration.java
This file was deleted.
Oops, something went wrong.
15 changes: 8 additions & 7 deletions
15
...h/jhipster/lite/generator/client/tools/cypress/application/CypressApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
src/main/java/tech/jhipster/lite/generator/client/tools/cypress/domain/Cypress.java
This file was deleted.
Oops, something went wrong.
99 changes: 0 additions & 99 deletions
99
...n/java/tech/jhipster/lite/generator/client/tools/cypress/domain/CypressDomainService.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.